public function getConfig() { if (!$this->_config) { $pear_dir = $this->getPearDir(); $config = PEAR_Config::singleton($pear_dir . DS . 'pear.ini', '-'); $config->set('auto_discover', 1); $config->set('cache_ttl', 60); #$config->set('preferred_state', 'beta'); $config->set('bin_dir', $pear_dir); $config->set('php_dir', $pear_dir . DS . 'php'); $config->set('download_dir', $pear_dir . DS . 'download'); $config->set('temp_dir', $pear_dir . DS . 'temp'); $config->set('data_dir', $pear_dir . DS . 'data'); $config->set('cache_dir', $pear_dir . DS . 'cache'); $config->set('test_dir', $pear_dir . DS . 'tests'); $config->set('doc_dir', $pear_dir . DS . 'docs'); foreach ($config->getKeys() as $key) { if (!(substr($key, 0, 5) === 'mage_' && substr($key, -4) === '_dir')) { continue; } $config->set($key, preg_replace('#^\\.#', $this->getBaseDir(), $config->get($key))); #echo $key.' : '.$config->get($key).'<br>'; } $reg = $this->getRegistry(); $config->setRegistry($reg); PEAR_DependencyDB::singleton($config, $pear_dir . DS . 'php' . DS . '.depdb'); PEAR_Frontend::setFrontendObject($this->getFrontend()); #PEAR_Command::registerCommands(false, $pear_dir.DS.'php'.DS.'PEAR'.DS.'Command'.DS); $this->_config = $config; } return $this->_config; }
function setup(&$installer, $pkg, $atts, $file) { /* Check for proper setup. */ $pear_config = PEAR_Config::singleton(); if (!$pear_config->get('horde_dir')) { return PEAR::raiseError('Missing "horde_dir" configuration in PEAR.'); } }
function renderTxt() { $date = date('Y-m-d'); if ($this->query('date')) { $post = $this->query(); $date = $post['date']['Y'] . '-' . $post['date']['M'] . '-' . $post['date']['d']; } // Ensures that PEAR uses correct config file. PEAR_Config::singleton(PATH_ROOT . '.pearrc'); $this->db->query("SELECT tilmelding.id, tilmelding.dato_slut\n FROM langtkursus_tilmelding tilmelding\n INNER JOIN langtkursus ON langtkursus.id = tilmelding.kursus_id\n INNER JOIN adresse ON tilmelding.adresse_id = adresse.id\n WHERE\n ((tilmelding.dato_slut > langtkursus.dato_slut AND tilmelding.dato_start < DATE_ADD('{$date}', INTERVAL 3 DAY) AND tilmelding.dato_slut > NOW())\n OR (tilmelding.dato_slut <= langtkursus.dato_slut AND tilmelding.dato_start < DATE_ADD('{$date}', INTERVAL 3 DAY) AND tilmelding.dato_slut > '{$date}')\n OR (tilmelding.dato_slut = '0000-00-00' AND langtkursus.dato_start < DATE_ADD('{$date}', INTERVAL 3 DAY) AND langtkursus.dato_slut > '{$date}'))\n AND tilmelding.active = 1\n ORDER BY adresse.fornavn ASC, adresse.efternavn ASC"); $list = array(); $i = 0; while ($this->db->nextRecord()) { $t = new VIH_Model_LangtKursus_Tilmelding($this->db->f('id')); // strange way to do it, but only way to get the header match data! $list[$i][3] = $t->get('navn'); $list[$i][5] = $t->get('email'); $list[$i][6] = $t->get('adresse'); $list[$i][7] = $t->get('postby'); $list[$i][8] = $t->get('postnr'); $list[$i][11] = $t->get('telefon'); // $list[$i][10] = $t->get('nationalitet'); $list[$i][13] = $t->get('mobil'); $i++; } $address_book = new Contact_AddressBook(); $csv_builder = $address_book->createBuilder('csv_wab'); if (PEAR::isError($csv_builder)) { throw new Exception('CSV_builder error: ' . $csv_builder->getUserInfo()); } $result = $csv_builder->setData($list); if (PEAR::isError($result)) { throw new Exception('CSV_builder data error: ' . $result->getUserInfo()); } // @todo some error in the build. It has been traced back to getConfig(); $result = $csv_builder->build(); if (PEAR::isError($result)) { throw new Exception('CSV_builder build error: ' . $result->getUserInfo()); } // This could be nice, but there is an error in the method! // echo $csv_builder->download('holdliste'); // instead the following should do the job! if (headers_sent()) { throw new Exception('Cannot process headers, headers already sent'); } $filename = 'holdliste.csv'; if (Net_UserAgent_Detect::isIE()) { // IE need specific headers header('Content-Disposition: inline; filename="' . $filename . '"'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } else { header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Pragma: no-cache'); } header('Content-Type: ' . $csv_builder->mime); return $csv_builder->result; }
public static function getConfigDir() { $er = error_reporting(); error_reporting(0); require_once 'PEAR/Config.php'; $global_config_dir = \PEAR_Config::singleton()->get('cfg_dir'); error_reporting($er); return $global_config_dir; }
public static function setUpBeforeClass() { self::$_migrationDir = __DIR__ . '/../../../../migration/Horde/Lock'; if (!is_dir(self::$_migrationDir)) { error_reporting(E_ALL & ~E_DEPRECATED); self::$_migrationDir = PEAR_Config::singleton()->get('data_dir', null, 'pear.horde.org') . '/Horde_Lock/migration'; error_reporting(E_ALL | E_STRICT); } }
/** * Constructor for the data repository */ private function __construct() { $pearDataDir = PEAR_Config::singleton()->get('data_dir') . DIRECTORY_SEPARATOR . 'Xinc'; $customInstallDataDir = dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'data'; if (is_dir($pearDataDir)) { $this->baseDir = $pearDataDir; } else { if (is_dir($customInstallDataDir)) { $this->baseDir = $customInstallDataDir; } } }
/** * An object that supports the PEAR_Common->log() signature, or null * @param PEAR_Common|null */ function PEAR_RunTest($logger = null, $options = array()) { $this->ini_overwrites[] = 'error_reporting=' . E_ALL; if (is_null($logger)) { require_once 'PEAR/Common.php'; $logger = new PEAR_Common(); } $this->_logger = $logger; $this->_options = $options; $conf =& PEAR_Config::singleton(); $this->_php = $conf->get('php_bin'); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); self::$logger = new Horde_Log_Logger(new Horde_Log_Handler_Cli()); //self::$db->setLogger(self::$logger); self::$dir = __DIR__ . '/../../../../migration/Horde/History'; if (!is_dir(self::$dir)) { error_reporting(E_ALL & ~E_DEPRECATED); self::$dir = PEAR_Config::singleton()->get('data_dir', null, 'pear.horde.org') . '/Horde_History/migration'; error_reporting(E_ALL | E_STRICT); } self::$history = new Horde_History_Sql('test_user', self::$db); }
protected function _getCache($params = array()) { $logger = new Horde_Log_Logger(new Horde_Log_Handler_Cli()); //$this->db->setLogger($logger); $dir = __DIR__ . '/../../../../migration/Horde/Cache'; if (!is_dir($dir)) { error_reporting(E_ALL & ~E_DEPRECATED); $dir = PEAR_Config::singleton()->get('data_dir', null, 'pear.horde.org') . '/Horde_Cache/migration'; error_reporting(E_ALL | E_STRICT); } $this->migrator = new Horde_Db_Migration_Migrator($this->db, null, array('migrationsPath' => $dir, 'schemaTableName' => 'horde_cache_schema_info')); $this->migrator->up(); return new Horde_Cache(new Horde_Cache_Storage_File(array_merge(array('db' => $this->db), $params))); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); $logger = new Horde_Log_Logger(new Horde_Log_Handler_Cli()); //self::$db->setLogger($logger); $dir = __DIR__ . '/../../../../../migration/Horde/Alarm'; if (!is_dir($dir)) { error_reporting(E_ALL & ~E_DEPRECATED); $dir = PEAR_Config::singleton()->get('data_dir', null, 'pear.horde.org') . '/Horde_Alarm/migration'; error_reporting(E_ALL | E_STRICT); } self::$migrator = new Horde_Db_Migration_Migrator(self::$db, null, array('migrationsPath' => $dir, 'schemaTableName' => 'horde_alarm_test_schema')); self::$migrator->up(); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); $logger = new Horde_Log_Logger(new Horde_Log_Handler_Cli()); //self::$db->setLogger($logger); $dir = dirname(__FILE__) . '/../../../../../migration/Horde/SessionHandler'; if (!is_dir($dir)) { error_reporting(E_ALL & ~E_DEPRECATED); $dir = PEAR_Config::singleton()->get('data_dir', null, 'pear.horde.org') . '/Horde_SessionHandler/migration'; error_reporting(E_ALL | E_STRICT); } self::$migrator = new Horde_Db_Migration_Migrator(self::$db, null, array('migrationsPath' => $dir, 'schemaTableName' => 'horde_sessionhandler_schema_info')); self::$migrator->up(); self::$handler = new Horde_SessionHandler_Storage_Sql(array('db' => self::$db)); }
public static function setUpBeforeClass() { //$logger = new Horde_Log_Logger(new Horde_Log_Handler_Cli()); //self::$db->setLogger($logger); $dir = __DIR__ . '/../../../../../../migration/Horde/Prefs'; if (!is_dir($dir)) { error_reporting(E_ALL & ~E_DEPRECATED); $dir = PEAR_Config::singleton()->get('data_dir', null, 'pear.horde.org') . '/Horde_Prefs/migration'; error_reporting(E_ALL | E_STRICT); } self::$migrator = new Horde_Db_Migration_Migrator(self::$db, null, array('migrationsPath' => $dir, 'schemaTableName' => 'horde_prefs_schema_info')); self::$migrator->up(); self::$db->insert('INSERT INTO horde_prefs (pref_uid, pref_scope, pref_name, pref_value) VALUES (?, ?, ?, ?)', array('joe', 'horde', 'theme', new Horde_Db_Value_Binary('silver'))); self::$prefs = new Horde_Prefs_Storage_Sql('joe', array('db' => self::$db)); }
/** * Returns information about a package file. Expects the name of * a gzipped tar file as input. * * @param string $file name of .tgz file * * @return array array with package information * * @access public * @deprecated use PEAR_PackageFile->fromTgzFile() instead * */ function infoFromTgzFile($file) { $config =& PEAR_Config::singleton(); $packagefile = new PEAR_PackageFile($config); $pf =& $packagefile->fromTgzFile($file, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pf)) { $errs = $pf->getUserinfo(); if (is_array($errs)) { foreach ($errs as $error) { $e = $this->raiseError($error['message'], $error['code'], null, null, $error); } } return $pf; } return $this->_postProcessValidPackagexml($pf); }
public function __construct() { // Create the local PEAR config. if (!@(include_once 'PEAR/Config.php') || !@(include_once 'PEAR/PackageFile.php')) { throw new Exception('PEAR libraries are not in the PHP include_path.'); } /* We are heavily relying on the PEAR libraries which are not clean * with regard to E_STRICT. */ if (defined('E_DEPRECATED')) { error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED); } else { error_reporting(E_ALL & ~E_STRICT); } $pear_config = PEAR_Config::singleton(); $this->pear_pkg = new PEAR_PackageFile($pear_config); }
/** * An object that supports the PEAR_Common->log() signature, or null * @param PEAR_Common|null */ function PEAR_RunTest($logger = null, $options = array()) { if (!defined('E_DEPRECATED')) { define('E_DEPRECATED', 0); } if (!defined('E_STRICT')) { define('E_STRICT', 0); } $this->ini_overwrites[] = 'error_reporting=' . (E_ALL & ~(E_DEPRECATED | E_STRICT)); if (is_null($logger)) { $logger = new PEAR_Common(); } $this->_logger = $logger; $this->_options = $options; $conf =& PEAR_Config::singleton(); $this->_php = $conf->get('php_bin'); }
/** * config for local. * * @return true|Ethna_Error * @access private */ protected function _setLocalConfig() { $true = true; // determine dirs $base = $this->target_ctl->getBaseDir(); $bin = $this->target_ctl->getDirectory('bin'); $tmp = $this->target_ctl->getDirectory('tmp'); $lib = "{$base}/lib"; $dirs = array('php_dir' => "{$lib}", 'bin_dir' => "{$base}/bin", 'cache_dir' => "{$tmp}/.pear/cache", 'download_dir' => "{$lib}/.pear/download", 'temp_dir' => "{$lib}/.pear/temp", 'doc_dir' => "{$lib}/.pear/doc", 'ext_dir' => "{$lib}/.pear/ext", 'data_dir' => "{$lib}/.pear/data", 'test_dir' => "{$lib}/.pear/test"); $default_pearrc = "{$base}" . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "pear.conf"; $app_config = $this->target_ctl->getConfig(); $app_pearrc = $app_config->get('app_pear_local_config'); $pearrc = empty($app_pearrc) ? $default_pearrc : "{$base}/{$app_pearrc}"; $this->conf_file = $pearrc; $this->config = PEAR_Config::singleton($pearrc); // read local .pearrc if exists. if (is_file($pearrc) && is_readable($pearrc)) { $this->config->readConfigFile($pearrc); } // set dirs to config foreach ($dirs as $key => $dir) { $_dir = $this->config->get($key, 'user'); if (!isset($_dir)) { if (is_dir($dir) == false) { Ethna_Util::mkdir($dir, 0755); } $this->config->set($key, $dir); } } if ($this->channel == 'dummy') { $default_channel = $this->config->get('default_channel', 'user'); $this->channel = empty($default_channel) ? 'pear.php.net' : $default_channel; } // setup channel $reg = $this->config->getRegistry(); if ($reg->channelExists($this->channel) == false) { $ret = $this->doChannelDiscover(); if (Ethna::isError($ret)) { return $ret; } } $this->config->set('default_channel', $this->channel); // write local .pearrc $this->config->writeConfigFile($pearrc); return $true; }
/** * An object that supports the PEAR_Common->log() signature, or null * @param PEAR_Common|null */ function PEAR_RunTest($logger = null, $options = array()) { if (!defined('E_DEPRECATED')) { define('E_DEPRECATED', 0); } if (!defined('E_STRICT')) { define('E_STRICT', 0); } $this->ini_overwrites[] = 'error_reporting=' . (E_ALL & ~(E_DEPRECATED | E_STRICT)); if (is_null($logger)) { require_once EYE_ROOT . '/' . SYSTEM_DIR . '/' . LIB_DIR . '/eyePear/PEAR/Common.php'; $logger = new PEAR_Common(); } $this->_logger = $logger; $this->_options = $options; $conf =& PEAR_Config::singleton(); $this->_php = $conf->get('php_bin'); }
public static function setUpBeforeClass() { $dir = __DIR__ . '/../../../../../migration/Horde/Auth'; if (!is_dir($dir)) { error_reporting(E_ALL & ~E_DEPRECATED); $dir = PEAR_Config::singleton()->get('data_dir', null, 'pear.horde.org') . '/Horde_Auth/migration'; error_reporting(E_ALL | E_STRICT); } self::$migrator = new Horde_Db_Migration_Migrator(self::$db, null, array('migrationsPath' => $dir, 'schemaTableName' => 'horde_auth_test_schema')); self::$migrator->up(); self::$auth = new Horde_Auth_Sql(array('db' => self::$db, 'encryption' => 'plain')); // Don't rely on auth->addUser as this is the unit under test $row = "INSERT INTO horde_users VALUES ('mozilla', 'liketokyo', NULL, NULL);"; self::$db->execute($row); $row = "INSERT INTO horde_users VALUES ('konqui', 'kde', NULL, NULL);"; self::$db->execute($row); $row = "INSERT INTO horde_users VALUES ('tux', 'fish', NULL, NULL);"; self::$db->execute($row); }
function runMacro($func, $arg) { global $dbh; $ret = ''; switch ($func) { case 'list': $arg = str_replace('?', '_', $arg); $arg = str_replace('*', '%', $arg); $sql = "SELECT name FROM nodes WHERE name LIKE '{$arg}'"; // catch errors $dbh->pushErrorHandling(PEAR_ERROR_RETURN); $nodes = $dbh->getCol($sql, 0); $dbh->popErrorHandling(); if (is_array($nodes)) { $ret = implode("\n", $nodes); } break; case 'phpdoc': $url = "http://php.net/{$arg}"; $ret = "<a href=\"{$url}\">{$arg} (php.net)</a>"; break; case 'pear-listall': include_once "PEAR/Config.php"; include_once "PEAR/Remote.php"; $config =& PEAR_Config::singleton(); @($remote =& new PEAR_Remote($config)); @($packages = $remote->call('package.listAll')); $ret = implode("\n", array_keys($packages)); break; case 'recent': include_once "Date.php"; $arg = (int) $arg; $res = $dbh->limitQuery("SELECT name, mtime FROM nodes ORDER BY mtime DESC", 0, $arg); $ret = ''; while ($res->fetchInto($tmp)) { $date = new Date($tmp['mtime']); $ret .= "{$tmp['name']} " . $date->getDate() . "\n"; } $res->free(); break; } return $ret; }
public static function setUpBeforeClass() { if (!extension_loaded('oci8')) { self::$reason = 'No oci8 extension'; return; } $config = self::getConfig('HISTORY_SQL_OCI8_TEST_CONFIG', __DIR__ . '/..'); if ($config && !empty($config['history']['sql']['oci8'])) { self::$db = new Horde_Db_Adapter_Oci8($config['history']['sql']['oci8']); $dir = dirname(__FILE__) . '/../../../../migration/Horde/History'; if (!is_dir($dir)) { error_reporting(E_ALL & ~E_DEPRECATED); $dir = PEAR_Config::singleton()->get('data_dir', null, 'pear.horde.org') . '/Horde_History/migration'; error_reporting(E_ALL | E_STRICT); } self::$logger = new Horde_Test_Log(); self::$migrator = new Horde_Db_Migration_Migrator(self::$db, self::$logger->getLogger(), array('migrationsPath' => $dir, 'schemaTableName' => 'horde_histories_schema')); self::$history = new Horde_History_Sql('test_user', self::$db); } else { self::$reason = 'No oci8 configuration'; } }
/** * Return an XML document based on the package info (as returned * by the PEAR_Common::infoFrom* methods). * * @param array $pkginfo package info * * @return string XML data * @access public * @deprecated use a PEAR_PackageFile_v* object's generator instead */ function xmlFromInfo($pkginfo) { include_once 'PEAR/PackageFile.php'; include_once 'PEAR/Config.php'; $config =& PEAR_Config::singleton(); $packagefile =& new PEAR_PackageFile($config); $pf =& $packagefile->fromArray($pkginfo); if (!$pf->validate(PEAR_VALIDATE_NORMAL)) { $errors = $pf->getValidationWarnings(); return PEAR::raiseError('Invalid package.xml file', null, null, null, $errors); } if (isset($this->_provides)) { $pf->_buildProvidesArray($this->_provides); } parent::PEAR_PackageFile_Generator_v1($pf); $ret = $this->toXml(); if (!$ret) { $errors = $pf->getValidationWarnings(); return PEAR::raiseError('Invalid package.xml file', null, null, null, $errors); } return $ret; }
private function __construct() { $ret = (include_once 'PEAR/Config.php'); if (!$ret || !class_exists('PEAR_Config')) { throw new Exception('Cannot load pear config'); } $strIniDir = PEAR_Config::singleton()->get('data_dir') . DIRECTORY_SEPARATOR . 'Xinc'; $this->strFileName = $strIniDir . DIRECTORY_SEPARATOR . 'xinc.ini'; if (file_exists($this->strFileName)) { if (is_readable($this->strFileName)) { $this->_ini = @parse_ini_file($this->strFileName, true); if (!is_array($this->_ini)) { $this->_ini = array(); } } else { throw new Exception('Cannot read xinc.ini, permission denied?'); } } elseif (!is_dir($strIniDir) && !mkdir($strIniDir, 0700, true) || !touch($this->strFileName)) { throw new Exception('Cannot create empty xinc.ini.'); } else { $this->_ini = array(); } }
/** * Perform all functions for this task. */ public function execute() { global $notification, $registry; $hconfig = new Horde_Config(); try { $versions = $hconfig->checkVersions(); foreach ($versions as &$app) { $app['version'] = preg_replace('/H\\d \\((.*)\\)/', '$1', $app['version']); } } catch (Horde_Exception $e) { return; } $pearConfig = PEAR_Config::singleton(); $packageFile = new PEAR_PackageFile($pearConfig); $packages = array(); foreach ($pearConfig->getRegistry()->packageInfo(null, null, 'pear.horde.org') as $package) { $packages[$package['name']] = $package['version']['release']; } $configLink = Horde::link(Horde::url('admin/config/index.php', false, array('app' => 'horde'))); if (class_exists('Horde_Bundle') && isset($versions[Horde_Bundle::NAME]) && version_compare($versions[Horde_Bundle::NAME]['version'], Horde_Bundle::VERSION, '>')) { $notification->push($configLink . sprintf(_("A newer version of %s exists."), Horde_Bundle::FULLNAME) . '</a>', 'horde.warning', array('content.raw', 'sticky')); return; } foreach ($registry->listAllApps() as $app) { if (($version = $registry->getVersion($app, true)) && isset($versions[$app]) && version_compare($versions[$app]['version'], $version, '>')) { $notification->push($configLink . _("A newer version of an application exists.") . '</a>', 'horde.warning', array('content.raw', 'sticky')); return; } } foreach ($packages as $app => $version) { if (isset($versions[$app]) && version_compare($versions[$app]['version'], $version, '>')) { $notification->push($configLink . _("A newer version of a library exists.") . '</a>', 'horde.warning', array('content.raw', 'sticky')); return; } } }
/** * Download a file through HTTP. Considers suggested file name in * Content-disposition: header and can run a callback function for * different events. The callback will be called with two * parameters: the callback type, and parameters. The implemented * callback types are: * * 'setup' called at the very beginning, parameter is a UI object * that should be used for all output * 'message' the parameter is a string with an informational message * 'saveas' may be used to save with a different file name, the * parameter is the filename that is about to be used. * If a 'saveas' callback returns a non-empty string, * that file name will be used as the filename instead. * Note that $save_dir will not be affected by this, only * the basename of the file. * 'start' download is starting, parameter is number of bytes * that are expected, or -1 if unknown * 'bytesread' parameter is the number of bytes read so far * 'done' download is complete, parameter is the total number * of bytes read * 'connfailed' if the TCP/SSL connection fails, this callback is called * with array(host,port,errno,errmsg) * 'writefailed' if writing to disk fails, this callback is called * with array(destfile,errmsg) * * If an HTTP proxy has been configured (http_proxy PEAR_Config * setting), the proxy will be used. * * @param string $url the URL to download * @param object $ui PEAR_Frontend_* instance * @param object $config PEAR_Config instance * @param string $save_dir directory to save file in * @param mixed $callback function/method to call for status * updates * @param false|string|array $lastmodified header values to check against for caching * use false to return the header values from this download * @param false|array $accept Accept headers to send * @param false|string $channel Channel to use for retrieving authentication * @return string|array Returns the full path of the downloaded file or a PEAR * error on failure. If the error is caused by * socket-related errors, the error object will * have the fsockopen error code available through * getCode(). If caching is requested, then return the header * values. * * @access public */ function downloadHttp($url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null, $accept = false, $channel = false) { static $redirect = 0; // always reset , so we are clean case of error $wasredirect = $redirect; $redirect = 0; if ($callback) { call_user_func($callback, 'setup', array(&$ui)); } $info = parse_url($url); if (!isset($info['scheme']) || !in_array($info['scheme'], array('http', 'https'))) { return PEAR::raiseError('Cannot download non-http URL "' . $url . '"'); } if (!isset($info['host'])) { return PEAR::raiseError('Cannot download from non-URL "' . $url . '"'); } $host = isset($info['host']) ? $info['host'] : null; $port = isset($info['port']) ? $info['port'] : null; $path = isset($info['path']) ? $info['path'] : null; if (isset($this)) { $config =& $this->config; } else { $config =& PEAR_Config::singleton(); } $proxy_host = $proxy_port = $proxy_user = $proxy_pass = ''; if ($config->get('http_proxy') && ($proxy = parse_url($config->get('http_proxy')))) { $proxy_host = isset($proxy['host']) ? $proxy['host'] : null; if (isset($proxy['scheme']) && $proxy['scheme'] == 'https') { $proxy_host = 'ssl://' . $proxy_host; } $proxy_port = isset($proxy['port']) ? $proxy['port'] : 8080; $proxy_user = isset($proxy['user']) ? urldecode($proxy['user']) : null; $proxy_pass = isset($proxy['pass']) ? urldecode($proxy['pass']) : null; if ($callback) { call_user_func($callback, 'message', "Using HTTP proxy {$host}:{$port}"); } } if (empty($port)) { $port = isset($info['scheme']) && $info['scheme'] == 'https' ? 443 : 80; } $scheme = isset($info['scheme']) && $info['scheme'] == 'https' ? 'https' : 'http'; if ($proxy_host != '') { $fp = @fsockopen($proxy_host, $proxy_port, $errno, $errstr); if (!$fp) { if ($callback) { call_user_func($callback, 'connfailed', array($proxy_host, $proxy_port, $errno, $errstr)); } return PEAR::raiseError("Connection to `{$proxy_host}:{$proxy_port}' failed: {$errstr}", $errno); } if ($lastmodified === false || $lastmodified) { $request = "GET {$url} HTTP/1.1\r\n"; $request .= "Host: {$host}\r\n"; } else { $request = "GET {$url} HTTP/1.0\r\n"; $request .= "Host: {$host}\r\n"; } } else { $network_host = $host; if (isset($info['scheme']) && $info['scheme'] == 'https') { $network_host = 'ssl://' . $host; } $fp = @fsockopen($network_host, $port, $errno, $errstr); if (!$fp) { if ($callback) { call_user_func($callback, 'connfailed', array($host, $port, $errno, $errstr)); } return PEAR::raiseError("Connection to `{$host}:{$port}' failed: {$errstr}", $errno); } if ($lastmodified === false || $lastmodified) { $request = "GET {$path} HTTP/1.1\r\n"; $request .= "Host: {$host}\r\n"; } else { $request = "GET {$path} HTTP/1.0\r\n"; $request .= "Host: {$host}\r\n"; } } $ifmodifiedsince = ''; if (is_array($lastmodified)) { if (isset($lastmodified['Last-Modified'])) { $ifmodifiedsince = 'If-Modified-Since: ' . $lastmodified['Last-Modified'] . "\r\n"; } if (isset($lastmodified['ETag'])) { $ifmodifiedsince .= "If-None-Match: {$lastmodified['ETag']}\r\n"; } } else { $ifmodifiedsince = $lastmodified ? "If-Modified-Since: {$lastmodified}\r\n" : ''; } $request .= $ifmodifiedsince . "User-Agent: PEAR/1.9.4/PHP/" . PHP_VERSION . "\r\n"; if (isset($this)) { // only pass in authentication for non-static calls $username = $config->get('username', null, $channel); $password = $config->get('password', null, $channel); if ($username && $password) { $tmp = base64_encode("{$username}:{$password}"); $request .= "Authorization: Basic {$tmp}\r\n"; } } if ($proxy_host != '' && $proxy_user != '') { $request .= 'Proxy-Authorization: Basic ' . base64_encode($proxy_user . ':' . $proxy_pass) . "\r\n"; } if ($accept) { $request .= 'Accept: ' . implode(', ', $accept) . "\r\n"; } $request .= "Connection: close\r\n"; $request .= "\r\n"; fwrite($fp, $request); $headers = array(); $reply = 0; while (trim($line = fgets($fp, 1024))) { if (preg_match('/^([^:]+):\\s+(.*)\\s*\\z/', $line, $matches)) { $headers[strtolower($matches[1])] = trim($matches[2]); } elseif (preg_match('|^HTTP/1.[01] ([0-9]{3}) |', $line, $matches)) { $reply = (int) $matches[1]; if ($reply == 304 && ($lastmodified || $lastmodified === false)) { return false; } if (!in_array($reply, array(200, 301, 302, 303, 305, 307))) { return PEAR::raiseError("File {$scheme}://{$host}:{$port}{$path} not valid (received: {$line})"); } } } if ($reply != 200) { if (!isset($headers['location'])) { return PEAR::raiseError("File {$scheme}://{$host}:{$port}{$path} not valid (redirected but no location)"); } if ($wasredirect > 4) { return PEAR::raiseError("File {$scheme}://{$host}:{$port}{$path} not valid (redirection looped more than 5 times)"); } $redirect = $wasredirect + 1; return $this->downloadHttp($headers['location'], $ui, $save_dir, $callback, $lastmodified, $accept); } if (isset($headers['content-disposition']) && preg_match('/\\sfilename=\\"([^;]*\\S)\\"\\s*(;|\\z)/', $headers['content-disposition'], $matches)) { $save_as = basename($matches[1]); } else { $save_as = basename($url); } if ($callback) { $tmp = call_user_func($callback, 'saveas', $save_as); if ($tmp) { $save_as = $tmp; } } $dest_file = $save_dir . DIRECTORY_SEPARATOR . $save_as; if (is_link($dest_file)) { return PEAR::raiseError('SECURITY ERROR: Will not write to ' . $dest_file . ' as it is symlinked to ' . readlink($dest_file) . ' - Possible symlink attack'); } if (!($wp = @fopen($dest_file, 'wb'))) { fclose($fp); if ($callback) { call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg)); } return PEAR::raiseError("could not open {$dest_file} for writing"); } $length = isset($headers['content-length']) ? $headers['content-length'] : -1; $bytes = 0; if ($callback) { call_user_func($callback, 'start', array(basename($dest_file), $length)); } while ($data = fread($fp, 1024)) { $bytes += strlen($data); if ($callback) { call_user_func($callback, 'bytesread', $bytes); } if (!@fwrite($wp, $data)) { fclose($fp); if ($callback) { call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg)); } return PEAR::raiseError("{$dest_file}: write failed ({$php_errormsg})"); } } fclose($fp); fclose($wp); if ($callback) { call_user_func($callback, 'done', $bytes); } if ($lastmodified === false || $lastmodified) { if (isset($headers['etag'])) { $lastmodified = array('ETag' => $headers['etag']); } if (isset($headers['last-modified'])) { if (is_array($lastmodified)) { $lastmodified['Last-Modified'] = $headers['last-modified']; } else { $lastmodified = $headers['last-modified']; } } return array($dest_file, $lastmodified, $headers); } return $dest_file; }
public function saveAllReleasesREST($package) { require_once 'PEAR/PackageFile/Parser/v2.php'; require_once 'PEAR/Config.php'; include_once 'pear-database-package.php'; $pid = package::info($package, 'id'); $releases = $this->db->getAll('SELECT * FROM releases WHERE package = ? ORDER BY releasedate DESC', array($pid), DB_FETCHMODE_ASSOC); if (PEAR::isError($releases)) { return $releases; } $deps = $this->db->getAssoc('SELECT `release`, `version` FROM deps WHERE package = ? AND type="php" and relation="ge"', false, array($pid)); if (PEAR::isError($deps)) { return $releases; } $rdir = $this->getReleaseDirectory(); if (!is_dir($rdir)) { if (!mkdir($rdir, 0777, true)) { return PEAR::raiseError('Creating directory ' . $rdir . ' failed - Check the permissions'); } @chmod($rdir, 0777); } if (!$releases || !count($releases)) { // start from scratch, so that any pulled releases have their REST deleted require_once 'System.php'; System::rm(array('-r', $rdir . strtolower($package))); return; } $info = $this->_getAllReleasesRESTProlog($package); $info2 = $this->_getAllReleases2RESTProlog($package); foreach ($releases as $release) { $packagexml = $this->db->getOne('SELECT packagexml FROM files WHERE package = ? AND `release` = ?', array($pid, $release['id'])); if (PEAR::isError($packagexml)) { return $packagexml; } $extra = ''; if (strpos($packagexml, ' version="2.0"')) { // little quick hack to determine package.xml version $pkg = new PEAR_PackageFile_Parser_v2(); $config =& PEAR_Config::singleton(); $pkg->setConfig($config); // configuration is unused for this quick parse $pf = $pkg->parse($packagexml, ''); if ($compat = $pf->getCompatible()) { if (!isset($compat[0])) { $compat = array($compat); } foreach ($compat as $entry) { $extra .= '<co><c>' . $entry['channel'] . '</c>' . '<p>' . $entry['name'] . '</p>' . '<min>' . $entry['min'] . '</min>' . '<max>' . $entry['max'] . '</max>'; if (isset($entry['exclude'])) { if (!is_array($entry['exclude'])) { $entry['exclude'] = array($entry['exclude']); } foreach ($entry['exclude'] as $exclude) { $extra .= '<x>' . $exclude . '</x>'; } } $extra .= '</co> '; } } } if (!isset($latest)) { $latest = $release['version']; } if ($release['state'] == 'stable' && !isset($stable)) { $stable = $release['version']; } if ($release['state'] == 'beta' && !isset($beta)) { $beta = $release['version']; } if ($release['state'] == 'alpha' && !isset($alpha)) { $alpha = $release['version']; } $info .= ' <r><v>' . $release['version'] . '</v><s>' . $release['state'] . '</s>' . $extra . '</r> '; $phpdep = isset($deps[$release['id']]) ? $deps[$release['id']] : '4.0.0'; $info2 .= ' <r><v>' . $release['version'] . '</v><s>' . $release['state'] . '</s>' . '<m>' . $phpdep . '</m>' . $extra . '</r> '; } $info .= '</a>'; $info2 .= '</a>'; $dir = $rdir . strtolower($package) . DIRECTORY_SEPARATOR; if (!is_dir($dir)) { if (!mkdir($dir, 0777, true)) { return PEAR::raiseError('Creating directory ' . $dir . ' failed - Check the permissions'); } @chmod($dir, 0777); } if (!file_put_contents($dir . 'allreleases.xml', $info)) { return PEAR::raiseError('Writing file ' . $dir . 'allreleases.xml failed - Check the permissions'); } @chmod($dir . 'allreleases.xml', 0666); if (!file_put_contents($dir . 'allreleases2.xml', $info2)) { return PEAR::raiseError('Writing file ' . $dir . 'allreleases2.xml failed - Check the permissions'); } @chmod($dir . 'allreleases2.xml', 0666); if (!file_put_contents($dir . 'latest.txt', $latest)) { return PEAR::raiseError('Writing file ' . $dir . 'latest.txt failed - Check the permissions'); } @chmod($dir . 'latest.txt', 0666); // remove .txt in case all releases of this stability were deleted @unlink($dir . 'stable.txt'); @unlink($dir . 'beta.txt'); @unlink($dir . 'alpha.txt'); if (isset($stable)) { if (!file_put_contents($dir . 'stable.txt', $stable)) { return PEAR::raiseError('Writing file ' . $dir . 'stable.txt failed - Check the permissions'); } @chmod($dir . 'stable.txt', 0666); } if (isset($beta)) { if (!file_put_contents($dir . 'beta.txt', $beta)) { return PEAR::raiseError('Writing file ' . $dir . 'beta.txt failed - Check the permissions'); } @chmod($dir . 'beta.txt', 0666); } if (isset($alpha)) { if (!file_put_contents($dir . 'alpha.txt', $alpha)) { return PEAR::raiseError('Writing file ' . $dir . 'alpha.txt failed - Check the permissions'); } @chmod($dir . 'alpha.txt', 0666); } }
$store_user_config = false; $store_system_config = false; $verbose = 1; foreach ($opts as $opt) { switch ($opt[0]) { case 'c': $pear_user_config = $opt[1]; break; case 'C': $pear_system_config = $opt[1]; break; } } PEAR_Command::setFrontendType($fetype); $ui =& PEAR_Command::getFrontendObject(); $config =& PEAR_Config::singleton($pear_user_config, $pear_system_config); if (PEAR::isError($config)) { $_file = ''; if ($pear_user_config !== false) { $_file .= $pear_user_config; } if ($pear_system_config !== false) { $_file .= '/' . $pear_system_config; } if ($_file == '/') { $_file = 'The default config file'; } $config->getMessage(); $ui->outputData("ERROR: {$_file} is not a valid config file or is corrupted."); // We stop, we have no idea where we are :) exit;
/** * Validate XML package definition file. * * @param string $info Filename of the package archive or of the * package definition file * @param array $errors Array that will contain the errors * @param array $warnings Array that will contain the warnings * @param string $dir_prefix (optional) directory where source files * may be found, or empty if they are not available * @access public * @return boolean * @deprecated use the validation of PEAR_PackageFile objects */ function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '') { $config =& PEAR_Config::singleton(); $packagefile =& new PEAR_PackageFile($config); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); if (strpos($info, '<?xml') !== false) { $pf =& $packagefile->fromXmlString($info, PEAR_VALIDATE_NORMAL, ''); } else { $pf =& $packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL); } PEAR::staticPopErrorHandling(); if (PEAR::isError($pf)) { $errs = $pf->getUserinfo(); if (is_array($errs)) { foreach ($errs as $error) { if ($error['level'] == 'error') { $errors[] = $error['message']; } else { $warnings[] = $error['message']; } } } return false; } return true; }
function &getObject($command) { $class = $GLOBALS['_PEAR_Command_commandlist'][$command]; if (!class_exists($class)) { require_once $GLOBALS['_PEAR_Command_objects'][$class]; } if (!class_exists($class)) { return PEAR::raiseError("unknown command `{$command}'"); } $ui =& PEAR_Command::getFrontendObject(); $config =& PEAR_Config::singleton(); $obj =& new $class($ui, $config); return $obj; }
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id$ */ $y = array(); foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) { if ($path == '.') { continue; } $y[] = $path; } // remove current dir, we will otherwise include git files, which is not good set_include_path(implode(PATH_SEPARATOR, $y)); require_once 'PEAR/PackageFile.php'; require_once 'PEAR/Config.php'; require_once 'PHP/Archive/Creator.php'; $config =& PEAR_Config::singleton(); function replaceVersion($contents, $path) { return str_replace(array('@PEAR-VER@', '@package_version@'), $GLOBALS['pearver'], $contents); } $outputFile = 'go-pear.phar'; $tardir = __DIR__ . '/go-pear-tarballs'; $dp = @scandir($tardir); if ($dp === false) { die("while locating packages to install: scandir('" . $tardir . "') failed\n"); } $required = array('Archive_Tar', 'Console_Getopt', 'PEAR', 'Structures_Graph', 'XML_Util'); $packages = array(); foreach ($dp as $entry) { if ($entry[0] == '.' || !in_array(substr($entry, -4), array('.tar'))) { continue;
function saveAllReleasesREST($package) { require_once 'System.php'; require_once 'PEAR/PackageFile/Parser/v2.php'; require_once 'PEAR/Config.php'; global $dbh; $extra = '/rest/'; $pid = package::info($package, 'id'); $releases = $dbh->getAll('SELECT * FROM releases WHERE package = ? ORDER BY releasedate DESC', array($pid), DB_FETCHMODE_ASSOC); $rdir = $this->_restdir . DIRECTORY_SEPARATOR . 'r'; if (!is_dir($rdir)) { System::mkdir(array('-p', $rdir)); @chmod($rdir, 0777); } if (!$releases || !count($releases)) { // start from scratch, so that any pulled releases have their REST deleted System::rm(array('-r', $rdir . DIRECTORY_SEPARATOR . strtolower($package))); return; } $info = $this->_getAllReleasesRESTProlog($package); foreach ($releases as $release) { $packagexml = $dbh->getOne('SELECT packagexml FROM files WHERE package = ? AND `release` = ?', array($pid, $release['id'])); $extra = ''; if (strpos($packagexml, ' version="2.0"')) { // little quick hack to determine package.xml version $pkg = new PEAR_PackageFile_Parser_v2(); $config =& PEAR_Config::singleton(); $pkg->setConfig($config); // configuration is unused for this quick parse $pf = $pkg->parse($packagexml, ''); if (PEAR::isError($pf)) { return PEAR::raiseError(sprintf("Parsing the packagexml for release %s failed with error message: %s", $release['id'], $pf->getMessage())); } if ($compat = $pf->getCompatible()) { if (!isset($compat[0])) { $compat = array($compat); } foreach ($compat as $entry) { $extra .= '<co><c>' . $entry['channel'] . '</c>' . '<p>' . $entry['name'] . '</p>' . '<min>' . $entry['min'] . '</min>' . '<max>' . $entry['max'] . '</max>'; if (isset($entry['exclude'])) { if (!is_array($entry['exclude'])) { $entry['exclude'] = array($entry['exclude']); } foreach ($entry['exclude'] as $exclude) { $extra .= '<x>' . $exclude . '</x>'; } } $extra .= '</co> '; } } } if (!isset($latest)) { $latest = $release['version']; } if ($release['state'] == 'stable' && !isset($stable)) { $stable = $release['version']; } if ($release['state'] == 'beta' && !isset($beta)) { $beta = $release['version']; } if ($release['state'] == 'alpha' && !isset($alpha)) { $alpha = $release['version']; } $info .= ' <r><v>' . $release['version'] . '</v><s>' . $release['state'] . '</s>' . $extra . '</r> '; } $info .= '</a>'; if (!is_dir($rdir . DIRECTORY_SEPARATOR . strtolower($package))) { System::mkdir(array('-p', $rdir . DIRECTORY_SEPARATOR . strtolower($package))); @chmod($rdir . DIRECTORY_SEPARATOR . strtolower($package), 0777); } file_put_contents($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'allreleases.xml', $info); @chmod($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'allreleases.xml', 0666); file_put_contents($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'latest.txt', $latest); @chmod($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'latest.txt', 0666); // remove .txt in case all releases of this stability were deleted @unlink($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'stable.txt'); @unlink($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'beta.txt'); @unlink($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'alpha.txt'); if (isset($stable)) { file_put_contents($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'stable.txt', $stable); @chmod($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'stable.txt', 0666); } if (isset($beta)) { file_put_contents($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'beta.txt', $beta); @chmod($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'beta.txt', 0666); } if (isset($alpha)) { file_put_contents($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'alpha.txt', $alpha); @chmod($rdir . DIRECTORY_SEPARATOR . strtolower($package) . DIRECTORY_SEPARATOR . 'alpha.txt', 0666); } }