function doSignImport($command, $options, $params) { if (count($params) !== 1) { return $this->raiseError("bad parameter(s), try \"help {$command}\""); } require_once 'PEAR/Gnupg.php'; $gnupg = new PEAR_Gnupg($this->config); $cmd = $gnupg->createGpgCmd(); if (PEAR::isError($cmd)) { return $cmd; } $key = @file_get_contents($params[0]); if ($key === false) { return $this->raiseError("could not load keys from {$key}"); } $cmd .= " --import"; $gpg = popen($cmd, "w"); if (!$gpg) { return $this->raiseError("gpg command failed"); } fwrite($gpg, "{$key}\n"); if (pclose($gpg)) { return $this->raiseError("gpg import failed"); } $this->ui->outputData("Key(s) imported.", $command); return true; }
/** * Create a PEAR_PackageFile_v* from a .tgz archive or package.xml file. * * This method is able to extract information about a package from a .tgz * archive or from a XML package definition file. * * @access public * @param string $info file name * @param int $state package state (one of PEAR_VALIDATE_* constants) * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2 * @uses fromPackageFile() if the file appears to be XML * @uses fromTgzFile() to load all non-XML files */ function &fromAnyFile($info, $state) { if (is_dir($info)) { $dir_name = realpath($info); if (file_exists($dir_name . '/package.xml')) { $fname = $dir_name . '/package.xml'; $info = PEAR_PackageFile::fromPackageFile($dir_name . '/package.xml', $state); } elseif (file_exists($dir_name . '/package2.xml')) { $fname = $dir_name . '/package2.xml'; $info = PEAR_PackageFile::fromPackageFile($dir_name . '/package2.xml', $state); } else { return PEAR::raiseError("No package definition found in '{$info}' directory"); } if (file_exists($dir_name . '/package.sig')) { require_once 'PEAR/Gnupg.php'; $gnupg = new PEAR_Gnupg($this->_config); $result = $gnupg->validateSig($fname, $dir_name . '/package.sig'); if (PEAR::isError($result)) { return $result; } } return $info; } $fp = false; if (is_string($info) && strlen($info) < 255 && (file_exists($info) || ($fp = @fopen($info, 'r')))) { if ($fp) { fclose($fp); } $tmp = substr($info, -4); if ($tmp == '.xml') { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } elseif ($tmp == '.tar' || $tmp == '.tgz') { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } else { $fp = fopen($info, 'r'); $test = fread($fp, 5); fclose($fp); if ($test == '<?xml') { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } else { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } } return $info; } $info = PEAR::raiseError("Cannot open '{$info}' for parsing"); return $info; }