Source for file CMS3_PackageManager.php
Documentation is available at CMS3_PackageManager.php
// CMS3 - A Three Content Management System.
// Copyright (C) 2007 Jop... (Jonas F. Jensen).
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*This file defines CMS3_PackageManager
* @author Jonas F. Jensen <jopsen@gmail.com>
* @copyright 2007 Jonas F. Jensen.
* @license http://www.gnu.org/licenses/gpl.txt
*PackageManager provides the logic for installation and removal of packages.
*This plugin doesn't provide any user interface only API interface for package operations.
*Verifies and installs a package
//TODO detect some of the worst errors and log them
//Check to see if the package exists
$PackagePath =
$this->Owner->GetCMS3Path() .
"data/PackageManager/packages/" .
$PluginID .
".c3p";
//make sure theres a temp dir
//If our tmp dir exists clean it
shell_exec("cp " .
$PackagePath .
" /tmp/" .
$PluginID .
".c3p");
//Lets extract the package:
shell_exec("cd /tmp/C3pkg/; tar -xvf ../" .
$PluginID .
".c3p");
//Lets extract the data from package
$InstalledFiles =
shell_exec("cd " .
$this->Owner->GetCMS3Path() .
"; tar -xvf /tmp/C3pkg/data.tar");
//Load all of the shared files of the plugin
$Shared =
scandir($this->Owner->GetCMS3Path() .
"share/" .
$PluginID .
"/");
foreach($Shared as $SharedInterface){
if($SharedInterface !=
"." &&
$SharedInterface !=
".."){
//Use output control to avoid problems from bad plugins
require_once($this->GetCMS3Path() .
"share/".
$PluginID .
"/" .
$SharedInterface);
//Check if the plugin implements IInstall
$Plugin =
$this->Owner->LoadPlugin($PluginID);
$IResult =
$Plugin->Install() ?
"The installations script was succesfully executed.\n" :
"There was error during execution of the installation script, please take a look at the system log.\n";
return $IResult .
$InstalledFiles;
//TODO fix this when implementing remote repositories
return "Package not found.";
*Verifies the integrity of a (.c3p) package, not installed plugin
*@param string PluginID PluginID of the package to be verify
*@return bool True if signature is correct.
//TODO detect some of the worst errors and log them
//Check to see if the package exists
$PackagePath =
$this->Owner->GetCMS3Path() .
"data/PackageManager/packages/" .
$PluginID .
".c3p";
//make sure theres a temp dir
//If our tmp dir exists clean it
shell_exec("cp " .
$PackagePath .
" /tmp/" .
$PluginID .
".c3p");
//Lets extract the package:
shell_exec("cd /tmp/C3pkg/; tar -xvf ../" .
$PluginID .
".c3p");
//Lets verify the signature
system("gpg --verify /tmp/C3pkg/data.tar.sig", $out); //Out is an output variable
//We have to use a little more direct system commands here, since gpg isn't very happy about the this kind of interaction
//It would be better to bind into a gpg library
It seams gpg won't give you the commandline result text result, which mean that we have to rely on the program return.
The message printed in commandline ends up in php's log file, this could probably be done more nicely, perhaps detect how signed it
But for now it's okay that we just receive a boolean result... More advanced features would probably require a C wrapper application...
//TODO interact more with GPG, but for now this is find, since complete GPG, signature import etc. is a big task
//TODO fix this when implementing remote repositories
*Verify the integrity of an installed plugin
*@param string PluginID Id of the plugin you wish to verify
*@return string Returns a sha1sum result, or false if master signature was invalid.
//Check to see if the plugin is installed
$CkPath =
$this->Owner->GetCMS3Path() .
"data/PackageManager/checksums/" .
$PluginID;
$SigPath =
$this->Owner->GetCMS3Path() .
"data/PackageManager/checksums/" .
$PluginID .
".sig";
system("gpg --verify " .
$SigPath, $out); //Out is an output variable
//TODO analyze output from sha1sum
return $out ==
0 ?
shell_exec("cd " .
$this->Owner->GetCMS3Path() .
"; sha1sum --check " .
$CkPath) :
false;
return "Plugin not found.";
*Remove an installed plugin
*Note: if this one returns false, you can't be sure that haft of the package is removed or system perhaps broken.
*@param string PluginID PluginID of the package to remove
*@return bool True if package removed correctly
//Get paths of PackageManager files:
$CkPath =
$this->Owner->GetCMS3Path() .
"data/PackageManager/checksums/" .
$PluginID;
$SigPath =
$this->Owner->GetCMS3Path() .
"data/PackageManager/checksums/" .
$PluginID .
".sig";
//Test if the plugin implements IRemove
$Plugin =
$this->Owner->GetPlugin($PluginID);
this part of the PackageManager isn't very strong, it can only handle packages that comply with standarts
//execute the deletion of the plugin
$cmd =
"cd " .
$this->Owner->GetCMS3Path() .
"; rm -R */" .
$PluginID .
"/ " .
$CkPath .
" " .
$SigPath;
//Log any errors, system might be broke on next http request
$this->Owner->Log($this->GetPluginID(), "Could not remove plugin:" .
$PluginID .
" error while removing files with following command:\n" .
$cmd);
$this->Owner->Log($this->GetPluginID(), "Could not remove plugin:" .
$PluginID .
" it wasn't installed by package manager.");
*Upload a third party package to local repository
$Dest =
$this->Owner->GetCMS3Path() .
"data/PackageManager/packages/" .
$PackageName .
".c3p";
//Check if the file is uploaded or stored otherwise
return copy($PackagePath, $Dest);
*List all the installed plugins that can be deleted or verified
$InChecksum =
scandir($this->Owner->GetCMS3Path() .
"data/PackageManager/checksums/");
foreach($InChecksum as $Checksum){
if($Checksum !=
"." &&
$Checksum !=
".." &&
substr($Checksum, -
4 , 4) !=
".sig"){
*List all the packages that are available for installation in local package repository
//Don't list plugins already installed
$InChecksum =
scandir($this->Owner->GetCMS3Path() .
"data/PackageManager/packages/");
foreach($InChecksum as $Checksum){
if($Checksum !=
"." &&
$Checksum !=
".." &&
!in_array($Checksum,$InstalledPlugins)){
$Packages[] =
substr($Checksum, 0 , -
4);
//Implementation of IPlugin
* Gets the pluginID of the plugin.
} // end of CMS3_PackageManager
Documentation generated on Mon, 30 Apr 2007 01:59:05 +0200 by phpDocumentor 1.3.1