1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
|
<?php
/**
+----------------------------------------------------------------------+
| PHP Version 4 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2003 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_02.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Christian Dickmann <dickmann@php.net> |
| Pierre-Alain Joye <pajoye@php.net> |
| Tias Guns <tias@ulyssis.org> |
+----------------------------------------------------------------------+
* Web-based PEAR Frontend, include this file to display the fontend.
* This file does the basic configuration, handles all requests and calls
* the needed commands.
*
* @category pear
* @package PEAR_Frontend_Web
* @author Christian Dickmann <dickmann@php.net>
* @author Pierre-Alain Joye <pajoye@php.net>
* @author Tias Guns <tias@ulyssis.org>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/2_02.txt PHP License 2.02
* @version CVS: $Id: pearfrontendweb.php,v 1.69 2008/08/02 16:22:35 tias Exp $
* @link http://pear.php.net/package/PEAR_Frontend_Web
* @since File available since Release 0.1
*/
/**
* This is PEAR_Frontend_Web
*/
define('PEAR_Frontend_Web',1);
@session_start();
/**
* base frontend class
*/
require_once 'PEAR/Frontend.php';
require_once 'PEAR/Command.php';
// for the open_basedir prisoners, don't allow PEAR to search for a temp dir (would use /tmp), see bug #13167
putenv('TMPDIR='.dirname(__FILE__).'/temp');
// set $pear_user_config if it isn't set yet
// finds an existing file, or proposes the default location
if (!isset($pear_user_config) || $pear_user_config == '') {
if (OS_WINDOWS) {
$conf_name = 'pear.ini';
} else {
$conf_name = 'pear.conf';
}
// default backup config: the one from the installer (if available).
$install_config = '@pear_install_config@'; // filled in on install
// TODO: doesn't work yet ! There is no way to find the system config
if (file_exists($install_config)) {
$pear_user_config = $install_config;
} else {
// find other config file location
$default_config_dirs = array(
substr(dirname(__FILE__), 0, strrpos(dirname(__FILE__), DIRECTORY_SEPARATOR)), // strip eg PEAR from .../example/PEAR(/pearfrontendweb.php)
dirname($_SERVER['SCRIPT_FILENAME']),
PEAR_CONFIG_SYSCONFDIR,
);
// set the default: __FILE__ without PEAR/
$pear_user_config = $default_config_dirs[0].DIRECTORY_SEPARATOR.$conf_name;
$found = false;
foreach ($default_config_dirs as $confdir) {
if (file_exists($confdir.DIRECTORY_SEPARATOR.$conf_name)) {
$pear_user_config = $confdir.DIRECTORY_SEPARATOR.$conf_name;
$found = true;
break;
}
}
if (!$found) {
print('<p><b>Warning:</b> Can not find config file, please specify the $pear_user_config variable in '.$_SERVER['PHP_SELF'].'</p>');
}
}
unset($conf_name, $default_config_dirs, $confdir);
}
require_once 'PEAR/Registry.php';
require_once 'PEAR/Config.php';
// moving this here allows startup messages and errors to work properly
PEAR_Frontend::setFrontendClass('PEAR_Frontend_Web');
// Init PEAR Installer Code and WebFrontend
$GLOBALS['_PEAR_Frontend_Web_config'] = &PEAR_Config::singleton($pear_user_config, '');
$config = &$GLOBALS['_PEAR_Frontend_Web_config'];
if (PEAR::isError($config)) {
die('<b>Error:</b> '.$config->getMessage());
}
$ui = &PEAR_Command::getFrontendObject();
if (PEAR::isError($ui)) {
die('<b>Error:</b> '.$ui->getMessage());
}
$ui->setConfig($config);
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ui, "displayFatalError"));
// Cient requests an Image/Stylesheet/Javascript
// outputFrontendFile() does exit()
if (isset($_GET["css"])) {
$ui->outputFrontendFile($_GET["css"], 'css');
}
if (isset($_GET["js"])) {
$ui->outputFrontendFile($_GET["js"], 'js');
}
if (isset($_GET["img"])) {
$ui->outputFrontendFile($_GET["img"], 'image');
}
$verbose = $config->get("verbose");
$cmdopts = array();
$opts = array();
$params = array();
// create $pear_user_config if it doesn't exit yet
if (!file_exists($pear_user_config)) {
// I think PEAR_Frontend_Web is running for the first time!
// Create config and install it properly ...
$ui->outputBegin(null);
print('<h3>Preparing PEAR_Frontend_Web for its first time use...</h3>');
// find pear_dir:
if (!isset($pear_dir) || !file_exists($pear_dir)) {
// __FILE__ is eg .../example/PEAR/pearfrontendweb.php
$pear_dir = dirname(__FILE__); // eg .../example/PEAR
}
if (substr($pear_dir, -1) == DIRECTORY_SEPARATOR) {
$pear_dir = substr($pear_dir, 0, -1); // strip trailing /
}
// extract base_dir from pear_dir
$dir = substr($pear_dir, 0, strrpos($pear_dir, DIRECTORY_SEPARATOR)); // eg .../example
$dir .= DIRECTORY_SEPARATOR;
if (!is_dir($dir)) {
PEAR::raiseError('Can not find a base installation directory of PEAR ('.$dir.' doesn\'t work), so we can\'t create a config for it. Please supply it in the variable \'$pear_dir\'. The $pear_dir must have at least the subdirectory PEAR/ and be writable by this frontend.');
die();
}
print('Saving config file ('.$pear_user_config.')...');
// First of all set some config-vars:
// Tries to be compatible with go-pear
if (!isset($pear_dir)) {
$pear_dir = $dir.'PEAR'; // default (go-pear compatible)
}
$cmd = PEAR_Command::factory('config-set', $config);
$ok = $cmd->run('config-set', array(), array('php_dir', $pear_dir));
$ok = $cmd->run('config-set', array(), array('doc_dir', $pear_dir.'/docs'));
$ok = $cmd->run('config-set', array(), array('ext_dir', $dir.'ext'));
$ok = $cmd->run('config-set', array(), array('bin_dir', $dir.'bin'));
$ok = $cmd->run('config-set', array(), array('data_dir', $pear_dir.'/data'));
$ok = $cmd->run('config-set', array(), array('test_dir', $pear_dir.'/test'));
$ok = $cmd->run('config-set', array(), array('temp_dir', $dir.'temp'));
$ok = $cmd->run('config-set', array(), array('download_dir', $dir.'temp/download'));
$ok = $cmd->run('config-set', array(), array('cache_dir', $pear_dir.'/cache'));
$ok = $cmd->run('config-set', array(), array('cache_ttl', 300));
$ok = $cmd->run('config-set', array(), array('default_channel', 'pear.php.net'));
$ok = $cmd->run('config-set', array(), array('preferred_mirror', 'pear.php.net'));
print('Checking package registry...');
// Register packages
$packages = array(
'Archive_Tar',
'Console_Getopt',
'HTML_Template_IT',
'PEAR',
'PEAR_Frontend_Web',
'Structures_Graph'
);
$reg = &$config->getRegistry();
if (!file_exists($pear_dir.'/.registry')) {
PEAR::raiseError('Directory "'.$pear_dir.'/.registry" does not exist. please check your installation');
}
foreach($packages as $pkg) {
$info = $reg->packageInfo($pkg);
foreach($info['filelist'] as $fileName => $fileInfo) {
if($fileInfo['role'] == "php") {
$info['filelist'][$fileName]['installed_as'] =
str_replace('{dir}',$dir, $fileInfo['installed_as']);
}
}
$reg->updatePackage($pkg, $info, false);
}
print('<p><em>PEAR_Frontend_Web configured succesfully !</em></p>');
$msg = sprintf('<p><a href="%s">Click here to continue</a></p>',
$_SERVER['PHP_SELF']);
print($msg);
$ui->outputEnd(null);
die();
}
// Check _isProtected() override (disables the 'not protected' warning)
if (isset($pear_frontweb_protected) && $pear_frontweb_protected === true) {
$GLOBALS['_PEAR_Frontend_Web_protected'] = true;
}
$cache_dir = $config->get('cache_dir');
if (!is_dir($cache_dir)) {
include_once 'System.php';
if (!System::mkDir('-p', $cache_dir)) {
PEAR::raiseError('Directory "'.$cache_dir.'" does not exist and cannot be created. Please check your installation');
}
}
if (isset($_GET['command']) && !is_null($_GET['command'])) {
$command = $_GET['command'];
} else {
$command = 'list';
}
// Prepare and begin output
$ui->outputBegin($command);
// Handle some different Commands
switch ($command) {
case 'install':
case 'uninstall':
case 'upgrade':
if ($_GET['command'] == 'install') {
// also install dependencies
$opts['onlyreqdeps'] = true;
if (isset($_GET['force']) && $_GET['force'] == 'on') {
$opts['force'] = true;
}
}
if (strpos($_GET['pkg'], '\\\\') !== false) {
$_GET['pkg'] = stripslashes($_GET['pkg']);
}
$params = array($_GET["pkg"]);
$cmd = PEAR_Command::factory($command, $config);
$ok = $cmd->run($command, $opts, $params);
$reg = &$config->getRegistry();
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$err = $reg->parsePackageName($_GET['pkg']);
PEAR::staticPopErrorHandling(); // reset error handling
if (!PEAR::isError($err)) {
$ui->finishOutput('Back', array('link' => $_SERVER['PHP_SELF'].'?command=info&pkg='.$_GET['pkg'],
'text' => 'View package information'));
}
break;
case 'run-scripts' :
$params = array($_GET['pkg']);
$cmd = PEAR_Command::factory($command, $config);
$ok = $cmd->run($command, $opts, $params);
break;
case 'info':
case 'remote-info':
$reg = &$config->getRegistry();
// we decide what it is:
$pkg = $reg->parsePackageName($_GET['pkg']);
if ($reg->packageExists($pkg['package'], $pkg['channel'])) {
$command = 'info';
} else {
$command = 'remote-info';
}
$params = array(strtolower($_GET['pkg']));
$cmd = PEAR_Command::factory($command, $config);
$ok = $cmd->run($command, $opts, $params);
break;
case 'search':
if (!isset($_POST['search']) || $_POST['search'] == '') {
// unsubmited, show forms
$ui->outputSearch();
} else {
if ($_POST['channel'] == 'all') {
$opts['allchannels'] = true;
} else {
$opts['channel'] = $_POST['channel'];
}
$opts['channelinfo'] = true;
// submited, do search
switch ($_POST['search']) {
case 'name':
$params = array($_POST['input']);
break;
case 'description':
$params = array($_POST['input'], $_POST['input']);
break;
default:
PEAR::raiseError('Can\'t search for '.$_POST['search']);
break;
}
$cmd = PEAR_Command::factory($command, $config);
$ok = $cmd->run($command, $opts, $params);
}
break;
case 'config-show':
$cmd = PEAR_Command::factory($command, $config);
$res = $cmd->run($command, $opts, $params);
// if this code is reached, the config vars are submitted
$set = PEAR_Command::factory('config-set', $config);
foreach($GLOBALS['_PEAR_Frontend_Web_Config'] as $var => $value) {
if ($var == 'Filename') {
continue; // I hate obscure bugs
}
if ($value != $config->get($var)) {
print('Saving '.$var.'... ');
$res = $set->run('config-set', $opts, array($var, $value));
$config->set($var, $value);
}
}
print('<p><b>Config saved succesfully!</b></p>');
$ui->finishOutput('Back', array('link' => $_SERVER['PHP_SELF'].'?command='.$command, 'text' => 'Back to the config'));
break;
case 'list-files':
$params = array($_GET['pkg']);
$cmd = PEAR_Command::factory($command, $config);
$res = $cmd->run($command, $opts, $params);
break;
case 'list-docs':
if (!isset($_GET['pkg'])) {
PEAR::raiseError('The webfrontend-command list-docs needs at least one \'pkg\' argument.');
break;
}
require_once('PEAR/Frontend/Web/Docviewer.php');
$reg = $config->getRegistry();
$pkg = $reg->parsePackageName($_GET['pkg']);
$docview = new PEAR_Frontend_Web_Docviewer($ui);
$docview->outputListDocs($pkg['package'], $pkg['channel']);
break;
case 'doc-show':
if (!isset($_GET['pkg']) || !isset($_GET['file'])) {
PEAR::raiseError('The webfrontend-command list-docs needs one \'pkg\' and one \'file\' argument.');
break;
}
require_once('PEAR/Frontend/Web/Docviewer.php');
$reg = $config->getRegistry();
$pkg = $reg->parsePackageName($_GET['pkg']);
$docview = new PEAR_Frontend_Web_Docviewer($ui);
$docview->outputDocShow($pkg['package'], $pkg['channel'], $_GET['file']);
break;
case 'list-all':
// Deprecated, use 'list-categories' is used instead
if (isset($_GET['chan']) && $_GET['chan'] != '') {
$opts['channel'] = $_GET['chan'];
}
$opts['channelinfo'] = true;
$cmd = PEAR_Command::factory($command, $config);
$res = $cmd->run($command, $opts, $params);
break;
case 'list-categories':
case 'list-packages':
if (isset($_GET['chan']) && $_GET['chan'] != '') {
$opts['channel'] = $_GET['chan'];
} else {
// show 'table of contents' before all channel output
$ui->outputTableOfChannels();
$opts['allchannels'] = true;
}
if (isset($_GET['opt']) && $_GET['opt'] == 'packages') {
$opts['packages'] = true;
}
$cmd = PEAR_Command::factory($command, $config);
$res = $cmd->run($command, $opts, $params);
break;
case 'list-category':
if (isset($_GET['chan']) && $_GET['chan'] != '') {
$opts['channel'] = $_GET['chan'];
}
$params = array($_GET['cat']);
$cmd = PEAR_Command::factory($command, $config);
$res = $cmd->run($command, $opts, $params);
break;
case 'list':
$opts['allchannels'] = true;
$opts['channelinfo'] = true;
$cmd = PEAR_Command::factory($command, $config);
$res = $cmd->run($command, $opts, $params);
break;
case 'list-upgrades':
$opts['channelinfo'] = true;
$cmd = PEAR_Command::factory($command, $config);
$res = $cmd->run($command, $opts, $params);
$ui->outputUpgradeAll();
break;
case 'upgrade-all':
$cmd = PEAR_Command::factory($command, $config);
$ok = $cmd->run($command, $opts, $params);
$ui->finishOutput('Back', array('link' => $_SERVER['PHP_SELF'].'?command=list',
'text' => 'Click here to go back'));
break;
case 'channel-info':
if (isset($_GET['chan']))
$params[] = $_GET['chan'];
$cmd = PEAR_Command::factory($command, $config);
$ok = $cmd->run($command, $opts, $params);
break;
case 'channel-discover':
if (isset($_GET['chan']) && $_GET['chan'] != '')
$params[] = $_GET['chan'];
$cmd = PEAR_Command::factory($command, $config);
$ui->startSession();
$ok = $cmd->run($command, $opts, $params);
$ui->finishOutput('Channel Discovery', array('link' =>
$_SERVER['PHP_SELF'] . '?command=channel-info&chan=' . urlencode($_GET['chan']),
'text' => 'Click Here for ' . htmlspecialchars($_GET['chan']) . ' Information'));
break;
case 'channel-delete':
if (isset($_GET["chan"]))
$params[] = $_GET["chan"];
$cmd = PEAR_Command::factory($command, $config);
$ok = $cmd->run($command, $opts, $params);
$ui->finishOutput('Delete Channel', array('link' =>
$_SERVER['PHP_SELF'] . '?command=list-channels',
'text' => 'Click here to list all channels'));
break;
case 'list-channels':
$cmd = PEAR_Command::factory($command, $config);
$ok = $cmd->run($command, $opts, $params);
break;
case 'channel-update':
if (isset($_GET['chan'])) {
$params = array($_GET['chan']);
}
$cmd = PEAR_Command::factory($command, $config);
$ok = $cmd->run($command, $opts, $params);
break;
case 'update-channels':
// update every channel manually,
// fixes bug PEAR/#10275 (XML_RPC dependency)
// will be fixed in next pear release
$reg = &$config->getRegistry();
$channels = $reg->getChannels();
$command = 'channel-update';
$cmd = PEAR_Command::factory($command, $config);
$success = true;
$ui->startSession();
foreach ($channels as $channel) {
if ($channel->getName() != '__uri') {
$success &= $cmd->run($command, $opts,
array($channel->getName()));
}
}
$ui->finishOutput('Update Channel List', array('link' =>
$_SERVER['PHP_SELF'] . '?command=list-channels',
'text' => 'Click here to list all channels'));
break;
default:
$cmd = PEAR_Command::factory($command, $config);
$res = $cmd->run($command, $opts, $params);
break;
}
$ui->outputEnd($command);
?> |
Partager