function processAction($action) { $this->debug("Action: {$action['action']} on {$action['path']}"); switch ($action['action']) { case 'M': // modified // modified case 'A': // added. /* how to handle moves?? */ // is it a file or directory? if ($this->isDir($action['path'])) { if (!file_exists($this->target . $action['path'])) { require_once 'System.php'; System::mkdir(array('-p', $this->target . $action['path'])); } return; } $this->writeFile($this->target . $action['path'], svn_cat($this->repos . $action['path'], $this->rev)); return; case 'D': // deleted. if (file_exists($this->target . $action['path'])) { require_once 'System.php'; System::rm($this->target . $action['path']); } return; case 'R': // replaced???? return; } }
/** * Build an extension from source. Runs "phpize" in the source * directory, but compiles in a temporary directory * (/var/tmp/pear-build-USER/PACKAGE-VERSION). * * @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or * a PEAR_PackageFile object * * @param mixed $callback callback function used to report output, * see PEAR_Builder::_runCommand for details * * @return array an array of associative arrays with built files, * format: * array( array( 'file' => '/path/to/ext.so', * 'php_api' => YYYYMMDD, * 'zend_mod_api' => YYYYMMDD, * 'zend_ext_api' => YYYYMMDD ), * ... ) * * @access public * * @see PEAR_Builder::_runCommand */ function build($descfile, $callback = null) { $this->current_callback = $callback; if (PEAR_OS == "Windows") { return $this->_build_win32($descfile, $callback); } if (PEAR_OS != 'Unix') { return $this->raiseError("building extensions not supported on this platform"); } if (is_object($descfile)) { $pkg = $descfile; $descfile = $pkg->getPackageFile(); if (is_a($pkg, 'PEAR_PackageFile_v1')) { $dir = dirname($descfile); } else { $dir = $pkg->_config->get('temp_dir') . '/' . $pkg->getName(); // automatically delete at session end $this->addTempFile($dir); } } else { $pf =& new PEAR_PackageFile($this->config); $pkg =& $pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pkg)) { return $pkg; } $dir = dirname($descfile); } $old_cwd = getcwd(); if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) { return $this->raiseError("could not chdir to {$dir}"); } $vdir = $pkg->getPackage() . '-' . $pkg->getVersion(); if (is_dir($vdir)) { chdir($vdir); } $dir = getcwd(); $this->log(2, "building in {$dir}"); putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH')); $err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback')); if (PEAR::isError($err)) { return $err; } if (!$err) { return $this->raiseError("`phpize' failed"); } // {{{ start of interactive part $configure_command = "{$dir}/configure"; $configure_options = $pkg->getConfigureOptions(); if ($configure_options) { foreach ($configure_options as $o) { $default = array_key_exists('default', $o) ? $o['default'] : null; list($r) = $this->ui->userDialog('build', array($o['prompt']), array('text'), array($default)); if (substr($o['name'], 0, 5) == 'with-' && ($r == 'yes' || $r == 'autodetect')) { $configure_command .= " --{$o['name']}"; } else { $configure_command .= " --{$o['name']}=" . trim($r); } } } // }}} end of interactive part // FIXME make configurable if (!($user = getenv('USER'))) { $user = '******'; } $build_basedir = "/var/tmp/pear-build-{$user}"; $build_dir = "{$build_basedir}/{$vdir}"; $inst_dir = "{$build_basedir}/install-{$vdir}"; $this->log(1, "building in {$build_dir}"); if (is_dir($build_dir)) { System::rm(array('-rf', $build_dir)); } if (!System::mkDir(array('-p', $build_dir))) { return $this->raiseError("could not create build dir: {$build_dir}"); } $this->addTempFile($build_dir); if (!System::mkDir(array('-p', $inst_dir))) { return $this->raiseError("could not create temporary install dir: {$inst_dir}"); } $this->addTempFile($inst_dir); if (getenv('MAKE')) { $make_command = getenv('MAKE'); } else { $make_command = 'make'; } $to_run = array($configure_command, $make_command, "{$make_command} INSTALL_ROOT=\"{$inst_dir}\" install", "find \"{$inst_dir}\" | xargs ls -dils"); if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) { return $this->raiseError("could not chdir to {$build_dir}"); } putenv('PHP_PEAR_VERSION=1.7.2'); foreach ($to_run as $cmd) { $err = $this->_runCommand($cmd, $callback); if (PEAR::isError($err)) { chdir($old_cwd); return $err; } if (!$err) { chdir($old_cwd); return $this->raiseError("`{$cmd}' failed"); } } if (!($dp = opendir("modules"))) { chdir($old_cwd); return $this->raiseError("no `modules' directory found"); } $built_files = array(); $prefix = exec("php-config --prefix"); $this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files); chdir($old_cwd); return $built_files; }
/** * Build an extension from source. Runs "phpize" in the source * directory, but compiles in a temporary directory * (/var/tmp/pear-build-USER/PACKAGE-VERSION). * * @param string $descfile path to XML package description file * * @param mixed $callback callback function used to report output, * see PEAR_Builder::_runCommand for details * * @return array an array of associative arrays with built files, * format: * array( array( 'file' => '/path/to/ext.so', * 'php_api' => YYYYMMDD, * 'zend_mod_api' => YYYYMMDD, * 'zend_ext_api' => YYYYMMDD ), * ... ) * * @access public * * @see PEAR_Builder::_runCommand * @see PEAR_Common::infoFromDescriptionFile */ function build($descfile, $callback = null) { if (PEAR_OS == "Windows") { return $this->_build_win32($descfile, $callback); } if (PEAR_OS != 'Unix') { return $this->raiseError("building extensions not supported on this platform"); } if (PEAR::isError($info = $this->infoFromDescriptionFile($descfile))) { return $info; } $dir = dirname($descfile); $old_cwd = getcwd(); if (!@chdir($dir)) { return $this->raiseError("could not chdir to {$dir}"); } $vdir = "{$info['package']}-{$info['version']}"; if (is_dir($vdir)) { chdir($vdir); } $dir = getcwd(); $this->log(2, "building in {$dir}"); $this->current_callback = $callback; putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH')); $err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback')); if (PEAR::isError($err)) { return $err; } if (!$err) { return $this->raiseError("`phpize' failed"); } // {{{ start of interactive part $configure_command = "{$dir}/configure"; if (isset($info['configure_options'])) { foreach ($info['configure_options'] as $o) { list($r) = $this->ui->userDialog('build', array($o['prompt']), array('text'), array(@$o['default'])); if (substr($o['name'], 0, 5) == 'with-' && ($r == 'yes' || $r == 'autodetect')) { $configure_command .= " --{$o['name']}"; } else { $configure_command .= " --{$o['name']}=" . trim($r); } } } // }}} end of interactive part // FIXME make configurable if (!($user = getenv('USER'))) { $user = '******'; } $build_basedir = "/var/tmp/pear-build-{$user}"; $build_dir = "{$build_basedir}/{$info['package']}-{$info['version']}"; $inst_dir = "{$build_basedir}/install-{$info['package']}-{$info['version']}"; $this->log(1, "building in {$build_dir}"); if (is_dir($build_dir)) { System::rm('-rf', $build_dir); } if (!System::mkDir(array('-p', $build_dir))) { return $this->raiseError("could not create build dir: {$build_dir}"); } $this->addTempFile($build_dir); if (!System::mkDir(array('-p', $inst_dir))) { return $this->raiseError("could not create temporary install dir: {$inst_dir}"); } $this->addTempFile($inst_dir); if (getenv('MAKE')) { $make_command = getenv('MAKE'); } else { $make_command = 'make'; } $to_run = array($configure_command, $make_command, "{$make_command} INSTALL_ROOT=\"{$inst_dir}\" install", "find \"{$inst_dir}\" -ls"); if (!@chdir($build_dir)) { return $this->raiseError("could not chdir to {$build_dir}"); } putenv('PHP_PEAR_VERSION=1.3.5'); foreach ($to_run as $cmd) { $err = $this->_runCommand($cmd, $callback); if (PEAR::isError($err)) { chdir($old_cwd); return $err; } if (!$err) { chdir($old_cwd); return $this->raiseError("`{$cmd}' failed"); } } if (!($dp = opendir("modules"))) { chdir($old_cwd); return $this->raiseError("no `modules' directory found"); } $built_files = array(); $prefix = exec("php-config --prefix"); $this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files); chdir($old_cwd); return $built_files; }
/** * Build an extension from source. Runs "phpize" in the source * directory, but compiles in a temporary directory * (/var/tmp/pear-build-USER/PACKAGE-VERSION). * * @param string $descfile path to XML package description file * * @param mixed $callback callback function used to report output, * see PEAR_Builder::_runCommand for details * * @return array an array of associative arrays with built files, * format: * array( array( 'file' => '/path/to/ext.so', * 'php_api' => YYYYMMDD, * 'zend_mod_api' => YYYYMMDD, * 'zend_ext_api' => YYYYMMDD ), * ... ) * * @access public * * @see PEAR_Builder::_runCommand * @see PEAR_Common::infoFromDescriptionFile */ function build($descfile, $callback = null) { if (PEAR_OS == "Windows") { return $this->_build_win32($descfile, $callback); } if (PEAR_OS != 'Unix') { return $this->raiseError("building extensions not supported on this platform"); } if (PEAR::isError($info = $this->infoFromDescriptionFile($descfile))) { return $info; } $dir = dirname($descfile); $old_cwd = getcwd(); if (!@chdir($dir)) { return $this->raiseError("could not chdir to {$dir}"); } $vdir = "{$info['package']}-{$info['version']}"; if (is_dir($vdir)) { chdir($vdir); } $dir = getcwd(); $this->log(2, "building in {$dir}"); $this->current_callback = $callback; $err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback')); if (PEAR::isError($err)) { return $err; } if (!$err) { return $this->raiseError("`phpize' failed"); } // {{{ start of interactive part $configure_command = "{$dir}/configure"; if (isset($info['configure_options'])) { foreach ($info['configure_options'] as $o) { list($r) = $this->ui->userDialog('build', array($o['prompt']), array('text'), array(@$o['default'])); if (substr($o['name'], 0, 5) == 'with-' && ($r == 'yes' || $r == 'autodetect')) { $configure_command .= " --{$o['name']}"; } else { $configure_command .= " --{$o['name']}=" . trim($r); } } } // }}} end of interactive part // FIXME make configurable if (!($user = getenv('USER'))) { $user = '******'; } $build_basedir = "/var/tmp/pear-build-{$user}"; $build_dir = "{$build_basedir}/{$info['package']}-{$info['version']}"; $this->log(1, "building in {$build_dir}"); if (is_dir($build_dir)) { System::rm("-rf {$build_dir}"); } if (!System::mkDir("-p {$build_dir}")) { return $this->raiseError("could not create build dir: {$build_dir}"); } $this->addTempFile($build_dir); if (getenv('MAKE')) { $make_command = getenv('MAKE'); } else { $make_command = 'make'; } $to_run = array($configure_command, $make_command); if (!@chdir($build_dir)) { return $this->raiseError("could not chdir to {$build_dir}"); } foreach ($to_run as $cmd) { $err = $this->_runCommand($cmd, $callback); if (PEAR::isError($err)) { chdir($old_cwd); return $err; } if (!$err) { chdir($old_cwd); return $this->raiseError("`{$cmd}' failed"); } } if (!($dp = opendir("modules"))) { chdir($old_cwd); return $this->raiseError("no `modules' directory found"); } $built_files = array(); while ($ent = readdir($dp)) { if ($ent[0] == '.' || substr($ent, -3) == '.la') { continue; } // harvest! if (@copy("modules/{$ent}", "{$dir}/{$ent}")) { $built_files[] = array('file' => "{$dir}/{$ent}", 'php_api' => $this->php_api_version, 'zend_mod_api' => $this->zend_module_api_no, 'zend_ext_api' => $this->zend_extension_api_no); $this->log(1, "{$ent} copied to {$dir}/{$ent}"); } else { chdir($old_cwd); return $this->raiseError("failed copying {$ent} to {$dir}"); } } closedir($dp); chdir($old_cwd); return $built_files; }
/** * Remove Language * * @param string $langID language ID * @param bool $force (unused) * * @return true|PEAR_Error * @access public */ function removeLang($langID, $force = false) { include_once 'System.php'; foreach ((array) $this->_domains as $domain => $path) { if (is_dir($fp = $path . '/' . $langID)) { if (PEAR::isError($e = System::rm(array('-rf', $fp))) || !$e) { return $e ? $e : PEAR::raiseError(sprintf('Could not remove language "%s" from domain "%s" ' . 'in path "%s" (probably insufficient permissions)', $langID, $domain, $path), TRANSLATION2_ERROR); } } } return true; }
$pear_rest = new pear_rest(PEAR_REST_DIR); } else { $pear_rest = new pear_rest(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'rest'); } } include_once "DB.php"; include_once "DB/storage.php"; if (empty($dbh)) { $options = array('persistent' => false, 'portability' => DB_PORTABILITY_ALL); $dbh =& DB::connect(PEAR_DATABASE_DSN, $options); $dbh->query('SET NAMES utf8'); } ob_end_clean(); PEAR::setErrorHandling(PEAR_ERROR_DIE); require_once 'System.php'; System::rm(array('-r', $pear_rest->_restdir)); System::mkdir(array('-p', $pear_rest->_restdir)); chmod($pear_rest->_restdir, 0777); echo "Generating Category REST...\n"; foreach (category::listAll() as $category) { echo " {$category['name']}..."; $pear_rest->saveCategoryREST($category['name']); echo "done\n"; } $pear_rest->saveAllCategoriesREST(); echo "Generating Maintainer REST...\n"; $maintainers = $dbh->getAll('SELECT * FROM users', array(), DB_FETCHMODE_ASSOC); foreach ($maintainers as $maintainer) { echo " {$maintainer['handle']}..."; $pear_rest->saveMaintainerREST($maintainer['handle']); echo "done\n";
/** * PEAR_Common destructor * * @access private */ function _PEAR_Common() { // doesn't work due to bug #14744 //$tempfiles = $this->_tempfiles; $tempfiles =& $GLOBALS['_PEAR_Common_tempfiles']; while ($file = array_shift($tempfiles)) { if (@is_dir($file)) { if (!class_exists('System')) { require_once 'System.php'; } System::rm(array('-rf', $file)); } elseif (file_exists($file)) { unlink($file); } } }
function deleteMaintainerREST($handle) { require_once 'System.php'; $mdir = $this->_restdir . DIRECTORY_SEPARATOR . 'm'; if (is_dir($mdir . DIRECTORY_SEPARATOR . $handle)) { System::rm(array('-r', $mdir . DIRECTORY_SEPARATOR . $handle)); } }
/** * Removes geotargeting folder and all its subfolders - as it is not needed anymore * after moving its configuration to main folder * */ function deleteGeotargetingConfigFiles() { $geotargetingDir = MAX_PATH . '/var/plugins/config/geotargeting'; if (System::rm(array('-rf', $geotargetingDir)) !== true) { return false; } return true; }
/** * Handle uploaded plugin * * @return string HTML or error message * */ function MONITOR_plugin_upload($plugin = '') { global $_CONF, $_MONITOR_CONF, $_TABLES; $retval = ''; if ($plugin == '' || $_MONITOR_CONF['repository'] == '') { return; } $url = "https://api.github.com/repos/{$_MONITOR_CONF['repository']}/" . $plugin . '/releases'; //Get last release for this plugin $releases = MONITOR_curlRequestOnGitApi($url); $version = $releases[0]['tag_name']; $path_admin = $_CONF['path_html'] . substr($_CONF['site_admin_url'], strlen($_CONF['site_url']) + 1) . '/'; $upload_success = false; //Download the zip file from repository $source = "https://codeload.github.com/{$_MONITOR_CONF['repository']}/{$plugin}/zip/{$version}"; $destination = fopen($_CONF['path_data'] . $plugin . '.zip', 'w+'); set_time_limit(0); // unlimited max execution time $options = array(CURLOPT_FILE => $destination, CURLOPT_TIMEOUT => 28800, CURLOPT_URL => $source, CURLOPT_USERAGENT => $_MONITOR_CONF['repository'], CURLOPT_SSL_VERIFYPEER => false); $ch = curl_init(); curl_setopt_array($ch, $options); $result = curl_exec($ch); curl_close($ch); $plugin_file = $_CONF['path_data'] . $plugin . '.zip'; // Name the plugin file if (!file_exists($plugin_file)) { COM_errorLog('MONITOR - Download failed for Plugin: ' . $plugin); return 'Download failed for Plugin: ' . $plugin; } else { chmod($plugin_file, 0755); } require_once $_CONF['path_system'] . 'classes/unpacker.class.php'; $archive = new unpacker($plugin_file, 'application/x-zip'); if ($archive == false) { return 72; } COM_errorLog('MONITOR - Download ' . $plugin . ' plugin: ok'); $pi_did_exist = false; // plugin directory already existed $pi_had_entry = false; // plugin had an entry in the database $pi_was_enabled = false; // plugin was enabled $alternate = false; if (file_exists($_CONF['path'] . 'plugins/' . $plugin)) { $pi_did_exist = true; // plugin directory already exists $pstatus = DB_query("SELECT pi_name, pi_enabled FROM {$_TABLES['plugins']} WHERE pi_name = '{$plugin}'"); $A = DB_fetchArray($pstatus); if (isset($A['pi_name'])) { $pi_had_entry = true; $pi_was_enabled = $A['pi_enabled'] == 1; } if ($pi_was_enabled) { // disable temporarily while we move the files around DB_change($_TABLES['plugins'], 'pi_enabled', 0, 'pi_name', $plugin); COM_errorLog('MONITOR - Disable Plugin: ' . $plugin); } require_once 'System.php'; $plugin_dir = $_CONF['path'] . 'plugins/' . $plugin; if (file_exists($plugin_dir . '.previous')) { @System::rm('-rf ' . $plugin_dir . '.previous'); } if (file_exists($plugin_dir)) { rename($plugin_dir, $plugin_dir . '.previous'); COM_errorLog('MONITOR - Rename: ' . $plugin_dir . ' to ' . $plugin_dir . '.previous'); } $public_dir = $_CONF['path_html'] . $plugin; if (file_exists($public_dir . '.previous')) { @System::rm('-rf ' . $public_dir . '.previous'); } if (file_exists($public_dir)) { rename($public_dir, $public_dir . '.previous'); COM_errorLog('MONITOR - Rename: ' . $public_dir . ' to ' . $public_dir . '.previous'); } $admin_dir = $path_admin . 'plugins/' . $plugin; if (file_exists($admin_dir . '.previous')) { @System::rm('-rf ' . $admin_dir . '.previous'); } if (file_exists($admin_dir)) { rename($admin_dir, $admin_dir . '.previous'); COM_errorLog('MONITOR - Rename: ' . $admin_dir . ' to ' . $admin_dir . '.previous'); } } $upload_success = false; // Extract the uploaded archive to the data directory $upload_success = $archive->unpack($_CONF['path_data']); if (!$upload_success) { //Try alternative unzip unset($archive); require_once 'Archive/Zip.php'; $archive = new Archive_Zip($plugin_file); if ($archive == false) { return 72; } $params = array('add_path' => $_CONF['path_data']); $extract = $archive->extract($params); if (is_array($extract)) { $upload_success = true; } $alternate = true; } if (!$upload_success) { COM_errorLog("MONITOR - Can't unzip the archive. Update for {$plugin_dir} plugin failed! Please check the archive in your data folder. Could be an OS issue during unzip."); if (file_exists($plugin_dir . '.previous')) { rename($plugin_dir . '.previous', $plugin_dir); COM_errorLog('MONITOR - Rename: ' . $plugin_dir . '.previous' . ' to ' . $plugin_dir); } if (file_exists($public_dir . '.previous')) { rename($public_dir . '.previous', $public_dir); COM_errorLog('MONITOR - Rename: ' . $public_dir . '.previous' . ' to ' . $public_dir); } if (file_exists($admin_dir . '.previous')) { rename($admin_dir . '.previous', $admin_dir); COM_errorLog('MONITOR - Rename: ' . $admin_dir . '.previous' . ' to ' . $admin_dir); } if ($pi_was_enabled) { DB_change($_TABLES['plugins'], 'pi_enabled', 1, 'pi_name', $plugin); COM_errorLog('MONITOR - Enable Plugin: ' . $plugin); } return 72; exit; } else { //Move files to plugins directory COM_errorLog('MONITOR - Plugin update: ' . $plugin); if (!$alternate) { $folder_name = $archive->getdir(); } else { $listcontent = $archive->listContent(); $folder_name = $listcontent[0]['filename']; if (substr($folder_name, -1) == '/') { $folder_name = substr($folder_name, 0, -1); } } if ($folder_name == '') { exit; } $srcDir = $_CONF['path_data'] . $folder_name; $destDir = $_CONF['path'] . 'plugins/' . $plugin; //Move from data folder to plugins folder rename($srcDir, $destDir); $plg_path = $_CONF['path'] . 'plugins/' . $plugin . '/'; if (file_exists($plg_path . 'public_html')) { rename($plg_path . 'public_html', $_CONF['path_html'] . $plugin); COM_errorLog('MONITOR - Move ' . $plg_path . 'public_html to ' . $_CONF['path_html'] . $plugin); } else { COM_errorLog('MONITOR - ' . $plg_path . 'public_html does not exist'); } if (file_exists($plg_path . 'admin')) { rename($plg_path . 'admin', $path_admin . 'plugins/' . $plugin); COM_errorLog('MONITOR - Move ' . $plg_path . 'admin to ' . $path_admin . 'plugins/' . $plugin); } else { COM_errorLog('MONITOR - ' . $plg_path . 'admin does not exist'); } unset($archive); // Collect some garbage // cleanup when uploading a new version if ($pi_did_exist) { $plugin_dir = $_CONF['path'] . 'plugins/' . $plugin; if (file_exists($plugin_dir . '.previous')) { @System::rm('-rf ' . $plugin_dir . '.previous'); } $public_dir = $_CONF['path_html'] . $plugin; if (file_exists($public_dir . '.previous')) { @System::rm('-rf ' . $public_dir . '.previous'); } $admin_dir = $path_admin . 'plugins/' . $plugin; if (file_exists($admin_dir . '.previous')) { @System::rm('-rf ' . $admin_dir . '.previous'); } if ($pi_was_enabled) { DB_change($_TABLES['plugins'], 'pi_enabled', 1, 'pi_name', $plugin); COM_errorLog('MONITOR - Enable Plugin: ' . $plugin); } } $msg_with_plugin_name = false; if ($pi_did_exist) { if ($pi_was_enabled) { // check if we have to perform an update $pi_version = DB_getItem($_TABLES['plugins'], 'pi_version', "pi_name = '{$plugin}'"); $code_version = PLG_chkVersion($plugin); COM_errorLog('MONITOR - Reading' . $plugin . ' plugin installed version: ' . $pi_version . ' and code version: ' . $code_version); if (!empty($code_version) && $code_version != $pi_version) { /** * At this point, we would have to call PLG_upgrade(). * However, we've loaded the plugin's old functions.inc * (in lib-common.php). We can't load the new one here * now since that would result in duplicate function * definitions. Solution: Trigger a reload (with the new * functions.inc) and continue there. */ $url = $_CONF['site_admin_url'] . '/plugins/monitor/index.php' . '?action=continue_upgrade' . '&codeversion=' . urlencode($code_version) . '&piversion=' . urlencode($pi_version) . '&plugin_update=' . urlencode($plugin); COM_errorLog('MONITOR - Update Plugin ' . $plugin . ' from version: ' . $pi_version . ' to code version: ' . $code_version); echo COM_refresh($url); exit; } else { $msg = 98; // successfully uploaded } } else { $msg = 98; // successfully uploaded } } elseif (file_exists($plg_path . 'autoinstall.php')) { // if the plugin has an autoinstall.php, install it now if (plugin_autoinstall($plugin)) { PLG_pluginStateChange($plugin, 'installed'); $msg = 44; // successfully installed } else { $msg = 72; // an error occured while installing the plugin } } else { $msg = 98; // successfully uploaded } } return $msg; }
function setupTempStuff() { if (!($this->ptmp = System::mktemp(array('-d')))) { $this->show("System's Tempdir failed, trying to use \$prefix/tmp ..."); $res = System::mkDir(array($this->prefix . '/tmp')); if (!$res) { return PEAR::raiseError('mkdir ' . $this->prefix . '/tmp ... failed'); } $_temp = tempnam($this->prefix . '/tmp', 'gope'); System::rm(array('-rf', $_temp)); System::mkdir(array('-p', '-m', '0700', $_temp)); $this->ptmp = $this->prefix . '/tmp'; $ok = @chdir($this->ptmp); if (!$ok) { // This should not happen, really ;) $this->bail('chdir ' . $this->ptmp . ' ... failed'); } print "ok\n"; // Adjust TEMPDIR envvars if (!isset($_ENV)) { $_ENV = array(); } $_ENV['TMPDIR'] = $_ENV['TEMP'] = $this->prefix . '/tmp'; } return @chdir($this->ptmp); }
/** * Build an extension from source. Runs "phpize" in the source * directory, but compiles in a temporary directory * (TMPDIR/pear-build-USER/PACKAGE-VERSION). * * @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or * a PEAR_PackageFile object * * @param mixed $callback callback function used to report output, * see PEAR_Builder::_runCommand for details * * @return array an array of associative arrays with built files, * format: * array( array( 'file' => '/path/to/ext.so', * 'php_api' => YYYYMMDD, * 'zend_mod_api' => YYYYMMDD, * 'zend_ext_api' => YYYYMMDD ), * ... ) * * @access public * * @see PEAR_Builder::_runCommand */ function build($descfile, $callback = null) { if (preg_match('/(\\/|\\\\|^)([^\\/\\\\]+)?php(.+)?$/', $this->config->get('php_bin'), $matches)) { if (isset($matches[2]) && strlen($matches[2]) && trim($matches[2]) != trim($this->config->get('php_prefix'))) { $this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') . ' appears to have a prefix ' . $matches[2] . ', but' . ' config variable php_prefix does not match'); } if (isset($matches[3]) && strlen($matches[3]) && trim($matches[3]) != trim($this->config->get('php_suffix'))) { $this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') . ' appears to have a suffix ' . $matches[3] . ', but' . ' config variable php_suffix does not match'); } } $this->current_callback = $callback; if (PEAR_OS == "Windows") { return $this->_build_win32($descfile, $callback); } if (PEAR_OS != 'Unix') { return $this->raiseError("building extensions not supported on this platform"); } if (is_object($descfile)) { $pkg = $descfile; $descfile = $pkg->getPackageFile(); if (is_a($pkg, 'PEAR_PackageFile_v1')) { $dir = dirname($descfile); } else { $dir = $pkg->_config->get('temp_dir') . '/' . $pkg->getName(); // automatically delete at session end $this->addTempFile($dir); } } else { $pf =& new PEAR_PackageFile($this->config); $pkg =& $pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pkg)) { return $pkg; } $dir = dirname($descfile); } // Find config. outside of normal path - e.g. config.m4 foreach (array_keys($pkg->getInstallationFileList()) as $item) { if (stristr(basename($item), 'config.m4') && dirname($item) != '.') { $dir .= DIRECTORY_SEPARATOR . dirname($item); break; } } $old_cwd = getcwd(); if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) { return $this->raiseError("could not chdir to {$dir}"); } $vdir = $pkg->getPackage() . '-' . $pkg->getVersion(); if (is_dir($vdir)) { chdir($vdir); } $dir = getcwd(); $this->log(2, "building in {$dir}"); putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH')); $err = $this->_runCommand($this->config->get('php_prefix') . "phpize" . $this->config->get('php_suffix'), array(&$this, 'phpizeCallback')); if (PEAR::isError($err)) { return $err; } if (!$err) { print "If the command failed with 'phpize: not found' then you need to install php5-dev package"; print "You can do it by running 'apt-get install php5-dev' as a root user"; return $this->raiseError("`phpize' failed"); } // {{{ start of interactive part $configure_command = "{$dir}/configure"; $configure_options = $pkg->getConfigureOptions(); if ($configure_options) { foreach ($configure_options as $o) { $default = array_key_exists('default', $o) ? $o['default'] : null; list($r) = $this->ui->userDialog('build', array($o['prompt']), array('text'), array($default)); if (substr($o['name'], 0, 5) == 'with-' && ($r == 'yes' || $r == 'autodetect')) { $configure_command .= " --{$o['name']}"; } else { $configure_command .= " --{$o['name']}=" . trim($r); } } } // }}} end of interactive part // FIXME make configurable if (!($user = getenv('USER'))) { $user = '******'; } $tmpdir = $this->config->get('temp_dir'); $build_basedir = System::mktemp(' -t "' . $tmpdir . '" -d "pear-build-' . $user . '"'); $build_dir = "{$build_basedir}/{$vdir}"; $inst_dir = "{$build_basedir}/install-{$vdir}"; $this->log(1, "building in {$build_dir}"); if (is_dir($build_dir)) { System::rm(array('-rf', $build_dir)); } if (!System::mkDir(array('-p', $build_dir))) { return $this->raiseError("could not create build dir: {$build_dir}"); } $this->addTempFile($build_dir); if (!System::mkDir(array('-p', $inst_dir))) { return $this->raiseError("could not create temporary install dir: {$inst_dir}"); } $this->addTempFile($inst_dir); $make_command = getenv('MAKE') ? getenv('MAKE') : 'make'; $to_run = array($configure_command, $make_command, "{$make_command} INSTALL_ROOT=\"{$inst_dir}\" install", "find \"{$inst_dir}\" | xargs ls -dils"); if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) { return $this->raiseError("could not chdir to {$build_dir}"); } putenv('PHP_PEAR_VERSION=1.9.4'); foreach ($to_run as $cmd) { $err = $this->_runCommand($cmd, $callback); if (PEAR::isError($err)) { chdir($old_cwd); return $err; } if (!$err) { chdir($old_cwd); return $this->raiseError("`{$cmd}' failed"); } } if (!($dp = opendir("modules"))) { chdir($old_cwd); return $this->raiseError("no `modules' directory found"); } $built_files = array(); $prefix = exec($this->config->get('php_prefix') . "php-config" . $this->config->get('php_suffix') . " --prefix"); $this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files); chdir($old_cwd); return $built_files; }
/** * PEAR_Common destructor * * @access private */ function _PEAR_Common() { // doesn't work due to bug #14744 //$tempfiles = $this->_tempfiles; $tempfiles =& $GLOBALS['_PEAR_Common_tempfiles']; while ($file = array_shift($tempfiles)) { if (@is_dir($file)) { System::rm("-rf {$file}"); } elseif (file_exists($file)) { unlink($file); } } }
// Zip $archive->extract(array('add_path' => $_CONF['path'] . 'data/', 'by_name' => $dirname . '/admin/install.php')); } else { // Tarball $archive->extractList(array($dirname . '/admin/install.php'), $_CONF['path'] . 'data/'); } $plugin_inst = $_CONF['path'] . 'data/' . $dirname . '/admin/install.php'; $fdata = ''; $fhandle = @fopen($plugin_inst, 'r'); if ($fhandle) { $fdata = fread($fhandle, filesize($plugin_inst)); fclose($fhandle); } // Remove the plugin from data/ require_once 'System.php'; @System::rm('-rf ' . $_CONF['path'] . 'data/' . $dirname); /** * One time I wanted to install a muffler on my car and * needed to match up the outside diameter of the car's * exhaust pipe to the inside diameter of the muffler. * Unfortunately, when I went to the auto parts store they * didn't have a coupling adapter that would perfectly * match the two pipes, only a bunch of smaller adapters. * I ended up using about 4 small adapters to step down * one size at a time to the size of the muffler's input. * * It's kind of like this regular expression: * */ $fdata = preg_replace('/\\n/', '', $fdata); $fdata = preg_replace('/ /', '', $fdata);
/** * Handle uploaded plugin * * @return string HTML: redirect or main plugin screen + error message * */ function plugin_upload() { global $_CONF, $_TABLES; $retval = ''; $path_admin = $_CONF['path_html'] . substr($_CONF['site_admin_url'], strlen($_CONF['site_url']) + 1) . '/'; $upload_success = false; // If an error occured while uploading the file. $error_msg = plugin_getUploadError($_FILES['plugin']); if (!empty($error_msg)) { $retval .= plugin_main($error_msg); } else { require_once $_CONF['path_system'] . 'classes/unpacker.class.php'; $plugin_file = $_CONF['path_data'] . $_FILES['plugin']['name']; // Name the plugin file $archive = new unpacker($_FILES['plugin']['tmp_name'], $_FILES['plugin']['type']); $tmp = $archive->getlist(); // Grab the contents of the tarball to see what the plugin name is $dirname = preg_replace('/\\/.*$/', '', $tmp[0]['filename']); if (empty($dirname)) { // If $dirname is blank it's probably because the user uploaded a non Tarball file. $retval = COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=100'); } else { $pi_did_exist = false; // plugin directory already existed $pi_had_entry = false; // plugin had an entry in the database $pi_was_enabled = false; // plugin was enabled if (file_exists($_CONF['path'] . 'plugins/' . $dirname)) { $pi_did_exist = true; // plugin directory already exists $pstatus = DB_query("SELECT pi_name, pi_enabled FROM {$_TABLES['plugins']} WHERE pi_name = '{$dirname}'"); $A = DB_fetchArray($pstatus); if (isset($A['pi_name'])) { $pi_had_entry = true; $pi_was_enabled = $A['pi_enabled'] == 1; } if ($pi_was_enabled) { // disable temporarily while we move the files around DB_change($_TABLES['plugins'], 'pi_enabled', 0, 'pi_name', $dirname); } require_once 'System.php'; $plugin_dir = $_CONF['path'] . 'plugins/' . $dirname; if (file_exists($plugin_dir . '.previous')) { @System::rm('-rf ' . $plugin_dir . '.previous'); } if (file_exists($plugin_dir)) { rename($plugin_dir, $plugin_dir . '.previous'); } $public_dir = $_CONF['path_html'] . $dirname; if (file_exists($public_dir . '.previous')) { @System::rm('-rf ' . $public_dir . '.previous'); } if (file_exists($public_dir)) { rename($public_dir, $public_dir . '.previous'); } $admin_dir = $path_admin . 'plugins/' . $dirname; if (file_exists($admin_dir . '.previous')) { @System::rm('-rf ' . $admin_dir . '.previous'); } if (file_exists($admin_dir)) { rename($admin_dir, $admin_dir . '.previous'); } } /** * Install the plugin * This doesn't work if the public_html & public_html/admin/plugins directories aren't 777 */ // Extract the tarball to data so we can get the $pi_name name from admin/install.php $archive->unpack($_CONF['path'] . 'data/', array($dirname . '/admin/install.php')); $plugin_inst = $_CONF['path'] . 'data/' . $dirname . '/admin/install.php'; $fdata = ''; $fhandle = @fopen($plugin_inst, 'r'); if ($fhandle) { $fdata = fread($fhandle, filesize($plugin_inst)); fclose($fhandle); } // Remove the plugin from data/ require_once 'System.php'; @System::rm('-rf ' . $_CONF['path'] . 'data/' . $dirname); /** * One time I wanted to install a muffler on my car and * needed to match up the outside diameter of the car's * exhaust pipe to the inside diameter of the muffler. * Unfortunately, when I went to the auto parts store they * didn't have a coupling adapter that would perfectly * match the two pipes, only a bunch of smaller adapters. * I ended up using about 4 small adapters to step down * one size at a time to the size of the muffler's input. * * It's kind of like this regular expression: * */ $fdata = preg_replace('/\\n/', '', $fdata); $fdata = preg_replace('/ /', '', $fdata); $pi_name = preg_replace('/^.*\\$pi\\_name=\'/', '', $fdata); $pi_name = preg_replace('/\'.*$/', '', $pi_name); // Some plugins don't have $pi_name set in their install.php file, // This means our regex won't work and we should just use $dirname if (preg_match('/\\<\\?php/', $pi_name) || preg_match('/--/', $pi_name)) { $pi_name = $dirname; } elseif (empty($pi_name)) { $pi_name = $dirname; } // Extract the uploaded archive to the plugins directory $upload_success = $archive->unpack($_CONF['path'] . 'plugins/'); $plg_path = $_CONF['path'] . 'plugins/' . $pi_name . '/'; if ($upload_success) { if (file_exists($plg_path . 'public_html')) { rename($plg_path . 'public_html', $_CONF['path_html'] . $pi_name); } if (file_exists($plg_path . 'admin')) { rename($plg_path . 'admin', $path_admin . 'plugins/' . $pi_name); } } unset($archive); // Collect some garbage // cleanup when uploading a new version if ($pi_did_exist) { $plugin_dir = $_CONF['path'] . 'plugins/' . $dirname; if (file_exists($plugin_dir . '.previous')) { @System::rm('-rf ' . $plugin_dir . '.previous'); } $public_dir = $_CONF['path_html'] . $dirname; if (file_exists($public_dir . '.previous')) { @System::rm('-rf ' . $public_dir . '.previous'); } $admin_dir = $path_admin . 'plugins/' . $dirname; if (file_exists($admin_dir . '.previous')) { @System::rm('-rf ' . $admin_dir . '.previous'); } if ($pi_was_enabled) { DB_change($_TABLES['plugins'], 'pi_enabled', 1, 'pi_name', $dirname); } } $msg_with_plugin_name = false; if ($pi_did_exist) { if ($pi_was_enabled) { // check if we have to perform an update $pi_version = DB_getItem($_TABLES['plugins'], 'pi_version', "pi_name = '{$dirname}'"); $code_version = PLG_chkVersion($dirname); if (!empty($code_version) && $code_version != $pi_version) { /** * At this point, we would have to call PLG_upgrade(). * However, we've loaded the plugin's old functions.inc * (in lib-common.php). We can't load the new one here * now since that would result in duplicate function * definitions. Solution: Trigger a reload (with the new * functions.inc) and continue there. */ $url = $_CONF['site_admin_url'] . '/plugins.php' . '?mode=continue_upgrade' . '&codeversion=' . urlencode($code_version) . '&piversion=' . urlencode($pi_version) . '&plugin=' . urlencode($dirname); echo COM_refresh($url); exit; } else { $msg = 98; // successfully uploaded } } else { $msg = 98; // successfully uploaded } } elseif (file_exists($plg_path . 'autoinstall.php')) { // if the plugin has an autoinstall.php, install it now if (plugin_autoinstall($pi_name)) { PLG_pluginStateChange($pi_name, 'installed'); $msg = 44; // successfully installed } else { $msg = 72; // an error occured while installing the plugin } } else { $msg = 98; // successfully uploaded } $url = $_CONF['site_admin_url'] . '/plugins.php?msg=' . $msg; if ($msg_with_plugin_name) { $url .= '&plugin=' . $dirname; } $retval = COM_refresh($url); } } return $retval; }
/** * Remove temporary files created my mkTemp. This function is executed * at script shutdown time * * @access private */ function _removeTmpFiles() { if (count($GLOBALS['_System_temp_files'])) { $delete = $GLOBALS['_System_temp_files']; array_unshift($delete, '-r'); System::rm($delete); } }
/** * Overloading of the __destruct method, ensure to remove the SSH_ASKPASS * script if created. */ public function __destruct() { if ($this->ssh_askpass_scripts !== null && is_file($this->ssh_askpass_scripts)) { System::rm($this->ssh_askpass_scripts); } }
$commandcontents = str_replace(array('$fp = @fopen("PEAR/Task/$taskfile.php", \'r\', true);'), array('$fp = @fopen("phar://' . $outputFile . '/PEAR/Task/$taskfile.php", \'r\', true);'), $commandcontents); $commandcontents = replaceVersion($commandcontents, ''); $commandcontents = $creator->tokenMagicRequire($commandcontents, 'a.php'); $creator->addString($commandcontents, 'PEAR/PackageFile/v2.php'); $creator->addMagicRequireCallback(array($creator, 'limitedSmartMagicRequire')); $creator->addMagicRequireCallback('replaceVersion'); $creator->addFile($tardir . '/tmp/PEAR/Command.php', 'PEAR/Command.php'); $creator->clearMagicRequire(); $creator->addMagicRequireCallback(array($creator, 'tokenMagicRequire')); $creator->addMagicRequireCallback('replaceVersion'); $ignores = array('*PEAR/Frontend.php', '*PEAR/PackageFile/v2.php', '*PEAR/Command.php'); $creator->addDir($tardir . '/tmp/PEAR', $ignores, array('*PEAR/*'), false, $tardir . '/tmp'); $creator->addFile($tardir . '/tmp/PEAR.php', 'PEAR.php'); $creator->addFile($tardir . '/tmp/PEAR5.php', 'PEAR5.php'); $creator->addFile($tardir . '/tmp/System.php', 'System.php'); $creator->addFile($tardir . '/tmp/OS/Guess.php', 'OS/Guess.php'); // Other packages $creator->addFile($tardir . '/tmp/Archive/Tar.php', 'Archive/Tar.php'); $creator->addFile($tardir . '/tmp/Util.php', 'XML/Util.php'); $creator->addFile($tardir . '/tmp/Console/Getopt.php', 'Console/Getopt.php'); $creator->addFile($tardir . '/tmp/Structures/Graph.php', 'Structures/Graph.php'); $creator->addFile($tardir . '/tmp/Structures/Graph/Node.php', 'Structures/Graph/Node.php'); $creator->addFile($tardir . '/tmp/Structures/Graph/Manipulator/AcyclicTest.php', 'Structures/Graph/Manipulator/AcyclicTest.php'); $creator->addFile($tardir . '/tmp/Structures/Graph/Manipulator/TopologicalSorter.php', 'Structures/Graph/Manipulator/TopologicalSorter.php'); // Include Start scripts specifically since they are never in the releases $creator->addFile(__DIR__ . '/PEAR/Start.php', 'PEAR/Start.php'); $creator->addFile(__DIR__ . '/PEAR/Start/CLI.php', 'PEAR/Start/CLI.php'); $creator->useSHA1Signature(); $creator->savePhar(__DIR__ . DIRECTORY_SEPARATOR . $outputFile); System::rm(array("-rf", "{$tardir}/tmp"));
if (isset($_SERVER['argv']) && $_SERVER['argv'][1] == 'pear') { $rest_path = '/var/lib/pearweb/rest'; } else { $rest_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'rest'; } include_once 'DB.php'; if (empty($dbh)) { $options = array('persistent' => false, 'portability' => DB_PORTABILITY_ALL); $dbh =& DB::connect(PEAR_DATABASE_DSN, $options); } $pear_rest = new pearweb_Channel_REST_Generator($rest_path, $dbh); } ob_end_clean(); PEAR::setErrorHandling(PEAR_ERROR_DIE); require_once 'System.php'; System::rm(array('-r', $rest_path)); System::mkdir(array('-p', $rest_path)); chmod($rest_path, 0777); echo "Generating Category REST...\n"; include_once 'pear-database-category.php'; foreach (category::listAll() as $category) { echo " {$category['name']}..."; $pear_rest->saveCategoryREST($category['name']); echo "done\n"; } $pear_rest->saveAllCategoriesREST(); echo "Generating Maintainer REST...\n"; $maintainers = $dbh->getAll('SELECT users.* FROM users, karma WHERE users.handle = karma.user AND (karma.level = "pear.dev" OR karma.level = "pear.admin")', array(), DB_FETCHMODE_ASSOC); foreach ($maintainers as $maintainer) { echo " {$maintainer['handle']}...";
public function deleteMaintainerREST($handle) { require_once 'System.php'; $dir = $this->getMaintainerDirectory() . $handle; if (is_dir($dir)) { System::rm(array('-r', $dir)); } }
/** * DELETE method handler * * @param array general parameter passing array * @return bool true on success */ function DELETE($options) { $path = $this->base . "/" . $options["path"]; if (!file_exists($path)) { return "404 Not found"; } if (is_dir($path)) { $query = "DELETE FROM properties WHERE path LIKE '" . $this->_slashify($options["path"]) . "%'"; mysql_query($query); System::rm("-rf {$path}"); } else { unlink($path); } $query = "DELETE FROM properties WHERE path = '{$options['path']}'"; mysql_query($query); return "204 No Content"; }