예제 #1
0
 /**
  * (non-PHPdoc)
  * @see lib/Faett/Core/Interfaces/Faett_Core_Interfaces_Service#packageInfo($packageName, $channel)
  */
 public function packageInfo($packageName, $channel)
 {
     // store the default channel
     $savechannel = $this->_config->get('default_channel');
     // check if the cannel already exists
     if ($this->_registry->channelExists($channel)) {
         $this->_config->set('default_channel', $channel);
     } else {
         // throw a new exception
         throw Faett_Core_Exceptions_UnknownChannelException::create('Channel ' . $channel . ' does not exist');
     }
     // load the channel from the registry
     $chan = $this->_registry->getChannel($channel);
     // initialize a REST command for checking the channel's state
     $cmd = new PEAR_Command_Remote($this->_ui, $this->_config);
     if (PEAR::isError($e = $cmd->_checkChannelForStatus($channel, $chan))) {
         // reset the default channel
         $this->_config->set('default_channel', $savechannel);
         // throw a new exception
         throw Faett_Core_Exceptions_UnknownChannelStateException::create($e->getMessage());
     }
     // get the channel's base URL
     $base = $chan->getBaseURL('REST1.0', $this->_config->get('preferred_mirror'));
     // check if the channel's server is REST enabled
     $restSupport = $chan->supportsREST($this->_config->get('preferred_mirror'));
     // check if the channel is REST enabled
     if ($restSupport && $base) {
         // load the channel data and the package information
         $rest = $this->_config->getREST('1.0', array());
         $info = $rest->packageInfo($base, $packageName);
     } else {
         $r = $this->_config->getRemote();
         $info = $r->call('package.info', $packageName);
     }
     // check if the package information was loaded successfully
     if (PEAR::isError($info)) {
         // reset the default channel
         $this->_config->set('default_channel', $savechannel);
         // throw a new exception
         throw Faett_Core_Exceptions_PackageInfoException::create($info->getMessage());
     }
     // if no packge name was found log an error message
     if (!isset($info['name'])) {
         // reset the default channel
         $this->_config->set('default_channel', $savechannel);
         // throw a new exception
         throw Faett_Core_Exceptions_PackageInfoException::create('Can\'t find a package name');
     }
     // check if the package is installed
     $installed = $this->_registry->packageInfo($info['name'], null, $channel);
     // if yes, set the information
     $info['installed'] = $installed['version'] ? $installed['version'] : '';
     if (is_array($info['installed'])) {
         $info['installed'] = $info['installed']['release'];
     }
     // return the package information
     return $info;
 }
 /**
  * @deprecated in favor of _getPackageDownloadUrl
  */
 function getPackageDownloadUrl($package, $version = null, $channel = false)
 {
     if ($version) {
         $package .= "-{$version}";
     }
     if ($this === null || $this->_registry === null) {
         $package = "http://pear.php.net/get/{$package}";
     } else {
         $chan = $this->_registry->getChannel($channel);
         $package = "http://" . $chan->getServer() . "/get/{$package}";
     }
     if (!extension_loaded("zlib")) {
         $package .= '?uncompress=yes';
     }
     return $package;
 }
예제 #3
0
파일: v1.php 프로젝트: michabbb/pear-core
 /**
  * Validate XML package definition file.
  *
  * @access public
  * @return boolean
  */
 function validate($state = PEAR_VALIDATE_NORMAL, $nofilechecking = false)
 {
     if (($this->_isValid & $state) == $state) {
         return true;
     }
     $this->_isValid = true;
     $info = $this->_packageInfo;
     if (empty($info['package'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_NAME);
         $this->_packageName = $pn = 'unknown';
     } else {
         $this->_packageName = $pn = $info['package'];
     }
     if (empty($info['summary'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_SUMMARY);
     } elseif (strpos(trim($info['summary']), "\n") !== false) {
         $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_MULTILINE_SUMMARY, array('summary' => $info['summary']));
     }
     if (empty($info['description'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DESCRIPTION);
     }
     if (empty($info['release_license'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_LICENSE);
     }
     if (empty($info['version'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_VERSION);
     }
     if (empty($info['release_state'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_STATE);
     }
     if (empty($info['release_date'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DATE);
     }
     if (empty($info['release_notes'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_NOTES);
     }
     if (empty($info['maintainers'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTAINERS);
     } else {
         $haslead = false;
         $i = 1;
         foreach ($info['maintainers'] as $m) {
             if (empty($m['handle'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTHANDLE, array('index' => $i));
             }
             if (empty($m['role'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTROLE, array('index' => $i, 'roles' => PEAR_Common::getUserRoles()));
             } elseif ($m['role'] == 'lead') {
                 $haslead = true;
             }
             if (empty($m['name'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTNAME, array('index' => $i));
             }
             if (empty($m['email'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTEMAIL, array('index' => $i));
             }
             $i++;
         }
         if (!$haslead) {
             $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_LEAD);
         }
     }
     if (!empty($info['release_deps'])) {
         $i = 1;
         foreach ($info['release_deps'] as $d) {
             if (!isset($d['type']) || empty($d['type'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPTYPE, array('index' => $i, 'types' => PEAR_Common::getDependencyTypes()));
                 continue;
             }
             if (!isset($d['rel']) || empty($d['rel'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPREL, array('index' => $i, 'rels' => PEAR_Common::getDependencyRelations()));
                 continue;
             }
             if (!empty($d['optional'])) {
                 if (!in_array($d['optional'], array('yes', 'no'))) {
                     $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_DEPOPTIONAL, array('index' => $i, 'opt' => $d['optional']));
                 }
             }
             if ($d['rel'] != 'has' && $d['rel'] != 'not' && empty($d['version'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPVERSION, array('index' => $i));
             } elseif (($d['rel'] == 'has' || $d['rel'] == 'not') && !empty($d['version'])) {
                 $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_DEPVERSION_IGNORED, array('index' => $i, 'rel' => $d['rel']));
             }
             if ($d['type'] == 'php' && !empty($d['name'])) {
                 $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_DEPNAME_IGNORED, array('index' => $i, 'name' => $d['name']));
             } elseif ($d['type'] != 'php' && empty($d['name'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPNAME, array('index' => $i));
             }
             if ($d['type'] == 'php' && empty($d['version'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPPHPVERSION, array('index' => $i));
             }
             if ($d['rel'] == 'not' && $d['type'] == 'php') {
                 $this->_validateError(PEAR_PACKAGEFILE_PHP_NO_NOT, array('index' => $i));
             }
             $i++;
         }
     }
     if (!empty($info['configure_options'])) {
         $i = 1;
         foreach ($info['configure_options'] as $c) {
             if (empty($c['name'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_CONFNAME, array('index' => $i));
             }
             if (empty($c['prompt'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_CONFPROMPT, array('index' => $i));
             }
             $i++;
         }
     }
     if (empty($info['filelist'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_FILES);
         $errors[] = 'no files';
     } else {
         foreach ($info['filelist'] as $file => $fa) {
             if (empty($fa['role'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_FILEROLE, array('file' => $file, 'roles' => PEAR_Common::getFileRoles()));
                 continue;
             } elseif (!in_array($fa['role'], PEAR_Common::getFileRoles())) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILEROLE, array('file' => $file, 'role' => $fa['role'], 'roles' => PEAR_Common::getFileRoles()));
             }
             if (preg_match('~/\\.\\.?(/|\\z)|^\\.\\.?/~', str_replace('\\', '/', $file))) {
                 // file contains .. parent directory or . cur directory references
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME, array('file' => $file));
             }
             if (isset($fa['install-as']) && preg_match('~/\\.\\.?(/|\\z)|^\\.\\.?/~', str_replace('\\', '/', $fa['install-as']))) {
                 // install-as contains .. parent directory or . cur directory references
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME, array('file' => $file . ' [installed as ' . $fa['install-as'] . ']'));
             }
             if (isset($fa['baseinstalldir']) && preg_match('~/\\.\\.?(/|\\z)|^\\.\\.?/~', str_replace('\\', '/', $fa['baseinstalldir']))) {
                 // install-as contains .. parent directory or . cur directory references
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME, array('file' => $file . ' [baseinstalldir ' . $fa['baseinstalldir'] . ']'));
             }
         }
     }
     if (isset($this->_registry) && $this->_isValid) {
         $chan = $this->_registry->getChannel('pear.php.net');
         if (PEAR::isError($chan)) {
             $this->_validateError(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $chan->getMessage());
             return $this->_isValid = 0;
         }
         $validator = $chan->getValidationObject();
         $validator->setPackageFile($this);
         $validator->validate($state);
         $failures = $validator->getFailures();
         foreach ($failures['errors'] as $error) {
             $this->_validateError(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $error);
         }
         foreach ($failures['warnings'] as $warning) {
             $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $warning);
         }
     }
     if ($this->_isValid && $state == PEAR_VALIDATE_PACKAGING && !$nofilechecking) {
         if ($this->_analyzePhpFiles()) {
             $this->_isValid = true;
         }
     }
     if ($this->_isValid) {
         return $this->_isValid = $state;
     }
     return $this->_isValid = 0;
 }
예제 #4
0
 function call_epi($method)
 {
     if (!extension_loaded("xmlrpc")) {
         return $this->raiseError("xmlrpc extension is not loaded");
     }
     $server_channel = $this->config->get('default_channel');
     $channel = $this->_registry->getChannel($server_channel);
     if (!PEAR::isError($channel)) {
         $mirror = $this->config->get('preferred_mirror');
         if ($channel->getMirror($mirror)) {
             if ($channel->supports('xmlrpc', $method, $mirror)) {
                 $server_channel = $server_host = $mirror;
                 // use the preferred mirror
                 $server_port = $channel->getPort($mirror);
             } elseif (!$channel->supports('xmlrpc', $method)) {
                 return $this->raiseError("Channel {$server_channel} does not " . "support xml-rpc method {$method}");
             }
         }
         if (!isset($server_host)) {
             if (!$channel->supports('xmlrpc', $method)) {
                 return $this->raiseError("Channel {$server_channel} does not support " . "xml-rpc method {$method}");
             } else {
                 $server_host = $server_channel;
                 $server_port = $channel->getPort();
             }
         }
     } else {
         return $this->raiseError("Unknown channel '{$server_channel}'");
     }
     $params = func_get_args();
     array_shift($params);
     $method = str_replace("_", ".", $method);
     $request = xmlrpc_encode_request($method, $params);
     if ($http_proxy = $this->config->get('http_proxy')) {
         $proxy = parse_url($http_proxy);
         $proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
         $proxy_host = isset($proxy['host']) ? $proxy['host'] : null;
         if (isset($proxy['scheme']) && $proxy['scheme'] == 'https') {
             $proxy_host = 'https://' . $proxy_host;
         }
         $proxy_port = isset($proxy['port']) ? $proxy['port'] : null;
         $proxy_user = isset($proxy['user']) ? urldecode($proxy['user']) : null;
         $proxy_pass = isset($proxy['pass']) ? urldecode($proxy['pass']) : null;
         $fp = @fsockopen($proxy_host, $proxy_port);
         $use_proxy = true;
         if ($channel->getSSL()) {
             $server_host = "https://{$server_host}";
         }
     } else {
         $use_proxy = false;
         $ssl = $channel->getSSL();
         $fp = @fsockopen(($ssl ? 'ssl://' : '') . $server_host, $server_port);
         if (!$fp) {
             $server_host = "{$ssl}{$server_host}";
             // for error-reporting
         }
     }
     if (!$fp && $http_proxy) {
         return $this->raiseError("PEAR_Remote::call: fsockopen(`{$proxy_host}', {$proxy_port}) failed");
     } elseif (!$fp) {
         return $this->raiseError("PEAR_Remote::call: fsockopen(`{$server_host}', {$server_port}) failed");
     }
     $len = strlen($request);
     $req_headers = "Host: {$server_host}:{$server_port}\r\n" . "Content-type: text/xml\r\n" . "Content-length: {$len}\r\n";
     $username = $this->config->get('username');
     $password = $this->config->get('password');
     if ($username && $password) {
         $req_headers .= "Cookie: PEAR_USER={$username}; PEAR_PW={$password}\r\n";
         $tmp = base64_encode("{$username}:{$password}");
         $req_headers .= "Authorization: Basic {$tmp}\r\n";
     }
     if ($this->cache !== null) {
         $maxAge = '?maxAge=' . $this->cache['lastChange'];
     } else {
         $maxAge = '';
     }
     if ($use_proxy && $proxy_host != '' && $proxy_user != '') {
         $req_headers .= 'Proxy-Authorization: Basic ' . base64_encode($proxy_user . ':' . $proxy_pass) . "\r\n";
     }
     if ($this->config->get('verbose') > 3) {
         print "XMLRPC REQUEST HEADERS:\n";
         var_dump($req_headers);
         print "XMLRPC REQUEST BODY:\n";
         var_dump($request);
     }
     if ($use_proxy && $proxy_host != '') {
         $post_string = "POST http://" . $server_host;
         if ($proxy_port > '') {
             $post_string .= ':' . $server_port;
         }
     } else {
         $post_string = "POST ";
     }
     $path = '/' . $channel->getPath('xmlrpc');
     fwrite($fp, $post_string . $path . "{$maxAge} HTTP/1.0\r\n{$req_headers}\r\n{$request}");
     $response = '';
     $line1 = fgets($fp, 2048);
     if (!preg_match('!^HTTP/[0-9\\.]+ (\\d+) (.*)!', $line1, $matches)) {
         return $this->raiseError("PEAR_Remote: invalid HTTP response from XML-RPC server");
     }
     switch ($matches[1]) {
         case "200":
             // OK
             break;
         case "304":
             // Not Modified
             return $this->cache['content'];
         case "401":
             // Unauthorized
             if ($username && $password) {
                 return $this->raiseError("PEAR_Remote ({$server_host}:{$server_port}) " . ": authorization failed", 401);
             } else {
                 return $this->raiseError("PEAR_Remote ({$server_host}:{$server_port}) " . ": authorization required, please log in first", 401);
             }
         default:
             return $this->raiseError("PEAR_Remote ({$server_host}:{$server_port}) : " . "unexpected HTTP response", (int) $matches[1], null, null, "{$matches['1']} {$matches['2']}");
     }
     while (trim(fgets($fp, 2048)) != '') {
     }
     // skip rest of headers
     while ($chunk = fread($fp, 10240)) {
         $response .= $chunk;
     }
     fclose($fp);
     if ($this->config->get('verbose') > 3) {
         print "XMLRPC RESPONSE:\n";
         var_dump($response);
     }
     $ret = xmlrpc_decode($response);
     if (is_array($ret) && isset($ret['__PEAR_TYPE__'])) {
         if ($ret['__PEAR_TYPE__'] == 'error') {
             if (isset($ret['__PEAR_CLASS__'])) {
                 $class = $ret['__PEAR_CLASS__'];
             } else {
                 $class = "PEAR_Error";
             }
             if ($ret['code'] === '') {
                 $ret['code'] = null;
             }
             if ($ret['message'] === '') {
                 $ret['message'] = null;
             }
             if ($ret['userinfo'] === '') {
                 $ret['userinfo'] = null;
             }
             if (strtolower($class) == 'db_error') {
                 $ret = $this->raiseError(PEAR::errorMessage($ret['code']), $ret['code'], null, null, $ret['userinfo']);
             } else {
                 $ret = $this->raiseError($ret['message'], $ret['code'], null, null, $ret['userinfo']);
             }
         }
     } elseif (is_array($ret) && sizeof($ret) == 1 && isset($ret[0]) && is_array($ret[0]) && !empty($ret[0]['faultString']) && !empty($ret[0]['faultCode'])) {
         extract($ret[0]);
         $faultString = "XML-RPC Server Fault: " . str_replace("\n", " ", $faultString);
         return $this->raiseError($faultString, $faultCode);
     } elseif (is_array($ret) && sizeof($ret) == 2 && !empty($ret['faultString']) && !empty($ret['faultCode'])) {
         extract($ret);
         $faultString = "XML-RPC Server Fault: " . str_replace("\n", " ", $faultString);
         return $this->raiseError($faultString, $faultCode);
     }
     return $ret;
 }