PEAR_Frontend_Web
[ class tree: PEAR_Frontend_Web ] [ index: PEAR_Frontend_Web ] [ all elements ]

Source for file WebInstaller.php

Documentation is available at WebInstaller.php

  1. <?php
  2. /*
  3.   +----------------------------------------------------------------------+
  4.   | PHP Version 4                                                        |
  5.   +----------------------------------------------------------------------+
  6.   | Copyright (c) 1997-2003 The PHP Group                                |
  7.   +----------------------------------------------------------------------+
  8.   | This source file is subject to version 2.02 of the PHP license,      |
  9.   | that is bundled with this package in the file LICENSE, and is        |
  10.   | available at through the world-wide-web at                           |
  11.   | http://www.php.net/license/2_02.txt.                                 |
  12.   | If you did not receive a copy of the PHP license and are unable to   |
  13.   | obtain it through the world-wide-web, please send a note to          |
  14.   | license@php.net so we can mail you a copy immediately.               |
  15.   +----------------------------------------------------------------------+
  16.   | Author: Christian Dickmann <dickmann@php.net>                        |
  17.   |         Pierre-Alain Joye <pajoye@php.net>                           |
  18.   +----------------------------------------------------------------------+
  19.  
  20.   $Id: WebInstaller.php,v 1.32 2005/02/06 21:27:10 cellog Exp $
  21. */
  22. define('PEAR_Frontend_Web',1);
  23.  
  24. if (!isset($_SESSION['_PEAR_Frontend_Web_js'])) {
  25.     $_SESSION['_PEAR_Frontend_Web_js'= false;
  26. }
  27. if (isset($_GET['enableJS']&& $_GET['enableJS'== 1{
  28.     $_SESSION['_PEAR_Frontend_Web_js'= true;
  29. }
  30. define('USE_DHTML_PROGRESS'(@$useDHTML && $_SESSION['_PEAR_Frontend_Web_js']));
  31.  
  32. // Include needed files
  33. require_once 'PEAR/Frontend.php';
  34. require_once 'PEAR/Registry.php';
  35. require_once 'PEAR/Config.php';
  36. require_once 'PEAR/Command.php';
  37.  
  38. if (!isset($pear_user_config)) {
  39.     if (OS_WINDOWS{
  40.         $pear_user_config = PEAR_CONFIG_SYSCONFDIR . '/pear.ini';
  41.     else {
  42.         $pear_user_config = PEAR_CONFIG_SYSCONFDIR . '/pear.conf';
  43.     }
  44. }
  45.  
  46. // moving this here allows startup messages and errors to work properly
  47. PEAR_Frontend::setFrontendClass('PEAR_Frontend_Web');
  48. // Init PEAR Installer Code and WebFrontend
  49. $GLOBALS['_PEAR_Frontend_Web_config'&PEAR_Config::singleton($pear_user_config'');
  50. $config  &$GLOBALS['_PEAR_Frontend_Web_config'];
  51.  
  52. $ui &PEAR_Command::getFrontendObject();
  53. $ui->setConfig($config);
  54.  
  55. PEAR::setErrorHandling(PEAR_ERROR_CALLBACKarray($ui"displayFatalError"));
  56.  
  57. // Cient requests an Image/Stylesheet/Javascript
  58. if (isset($_GET["css"])) {
  59.     $ui->outputFrontendFile($_GET["css"]'css');
  60. }
  61. if (isset($_GET["js"])) {
  62.     $ui->outputFrontendFile($_GET["js"]'js');
  63. }
  64. if (isset($_GET["img"])) {
  65.     $ui->outputFrontendFile($_GET["img"]'image');
  66. }
  67.  
  68. $verbose $config->get("verbose");
  69. $cmdopts = array();
  70. $opts    = array();
  71. $params  = array();
  72.  
  73. $URL 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
  74. $dir substr(dirname(__FILE__)0-strlen('PEAR/PEAR'))// strip PEAR/PEAR
  75.  
  76. $_ENV['TMPDIR'$_ENV['TEMP'$dir.'tmp';
  77.  
  78. if (!file_exists($pear_user_config)) {
  79.     // I think PEAR_Frontend_Web is running for the first time!
  80.     // Install it properly ...
  81.  
  82.     // First of all set some config-vars:
  83.     $cmd = PEAR_Command::factory('config-set'$config);
  84.     $ok $cmd->run('config-set'array()array('php_dir',  $dir.'PEAR'));
  85.     $ok $cmd->run('config-set'array()array('doc_dir',  $dir.'docs'));
  86.     $ok $cmd->run('config-set'array()array('ext_dir',  $dir.'ext'));
  87.     $ok $cmd->run('config-set'array()array('bin_dir',  $dir.'bin'));
  88.     $ok $cmd->run('config-set'array()array('data_dir'$dir.'data'));
  89.     $ok $cmd->run('config-set'array()array('test_dir'$dir.'test'));
  90.     $ok $cmd->run('config-set'array()array('cache_dir'$dir.'cache'));
  91.     $ok $cmd->run('config-set'array()array('cache_ttl'300));
  92.     $ok $cmd->run('config-set'array()array('default_channel''pear.php.net'));
  93.     $ok $cmd->run('config-set'array()array('preferred_mirror''pear.php.net'));
  94.  
  95.     // Register packages
  96.     $packages = array(
  97.                                 'Archive_Tar',
  98.                                 'Console_Getopt',
  99.                                 'HTML_Template_IT',
  100.                                 'Net_UserAgent_Detect',
  101.                                 'Pager',
  102.                                 'PEAR',
  103.                                 'PEAR_Frontend_Web',
  104.                                 'XML_RPC'
  105.                         );
  106.     $reg &$config->getRegistry();
  107.     if (!file_exists($dir.'PEAR/.registry')) {
  108.         PEAR::raiseError('Directory "'.$dir.'PEAR/.registry" does not exist. please check your installation');
  109.     }
  110.  
  111.     foreach($packages as $pkg{
  112.         $info $reg->packageInfo($pkg);
  113.         foreach($info['filelist'as $fileName => $fileInfo{
  114.             if($fileInfo['role'== "php"{
  115.                 $info['filelist'][$fileName]['installed_as'=
  116.                     str_replace('{dir}',$dir$fileInfo['installed_as']);
  117.             }
  118.         }
  119.         $reg->updatePackage($pkg$infofalse);
  120.     }
  121. }
  122.  
  123. // Handle some diffrent Commands
  124. if (isset($_GET["command"])) {
  125.     switch ($_GET["command"]{
  126.         case 'install':
  127.         case 'uninstall':
  128.         case 'upgrade':
  129.             if (USE_DHTML_PROGRESS && isset($_GET['dhtml'])) {
  130.                 PEAR::setErrorHandling(PEAR_ERROR_CALLBACKarray($ui"displayErrorImg"));
  131.             }
  132.  
  133.             $command $_GET["command"];
  134.             if (strpos($_GET['pkg']'\\\\'!== false{
  135.                 $_GET['pkg'stripslashes($_GET['pkg']);
  136.             }
  137.             $params = array($_GET["pkg"]);
  138.             $cmd = PEAR_Command::factory($command$config);
  139.             $ok $cmd->run($command$opts$params);
  140.  
  141.             // success
  142.             if (USE_DHTML_PROGRESS && isset($_GET['dhtml'])) {
  143.                 echo '<script language="javascript">';
  144.                 if ($_GET["command"== "uninstall"{
  145.                     printf(' parent.deleteVersion(\'%s\'); ',  $_GET["pkg"]);
  146.                     printf(' parent.displayInstall(\'%s\'); '$_GET["pkg"]);
  147.                     printf(' parent.hideDelete(\'%s\'); ',     $_GET["pkg"]);
  148.                 else {
  149.                     printf(' parent.newestVersion(\'%s\'); ',  $_GET["pkg"]);
  150.                     printf(' parent.hideInstall(\'%s\'); ',    $_GET["pkg"]);
  151.                     printf(' parent.displayDelete(\'%s\'); ',  $_GET["pkg"]);
  152.                 }
  153.                 echo '</script>';
  154.                 $html sprintf('<img src="%s?img=install_ok" border="0">'$_SERVER['PHP_SELF']);
  155.                 echo $js.$html;
  156.                 exit;
  157.             }
  158.  
  159.             if (isset($_GET['redirect']&& $_GET['redirect'== 'info'{
  160.                 $URL .= '?command=remote-info&pkg='.$_GET["pkg"];
  161.             elseif (isset($_GET['redirect']&& $_GET['redirect'== 'search'{
  162.                 $URL .= '?command=search&userDialogResult=get&0='.$_GET["0"].'&1='.$_GET["1"];
  163.             else {
  164.                 $URL .= '?command=list-all&pageID='.$_GET['pageID'].'#'.$_GET["pkg"];
  165.             }
  166.             Header("Location: ".$URL);
  167.             exit;
  168.         case 'run-scripts' :
  169.             $command $_GET["command"];
  170.             $params = array($_GET["pkg"]);
  171.             $cmd = PEAR_Command::factory($command$config);
  172.             $ok $cmd->run($command$opts$params);
  173.             exit;
  174.         case 'remote-info':
  175.             $command $_GET["command"];
  176.             $params = array($_GET["pkg"]);
  177.             $cmd = PEAR_Command::factory($command$config);
  178.             $ok $cmd->run($command$opts$params);
  179.  
  180.             exit;
  181.         case 'search':
  182.             list($name$description$ui->userDialog('search',
  183.                 array('Package Name''Package Info')// Prompts
  184.                 array()array()// Types, Defaults
  185.                 'Package Search''pkgsearch' // Title, Icon
  186.                 );
  187.  
  188.             $command $_GET["command"];
  189.             $params = array($name$description);
  190.             $cmd = PEAR_Command::factory($command$config);
  191.             $ok $cmd->run($command$opts$params);
  192.  
  193.             exit;
  194.         case 'config-show':
  195.             $command $_GET["command"];
  196.             $cmd = PEAR_Command::factory($command$config);
  197.             $res $cmd->run($command$opts$params);
  198.             foreach($GLOBALS['_PEAR_Frontend_Web_Config'as $var => $value{
  199.                 $command 'config-set';
  200.                 $params = array($var$value);
  201.                 $cmd = PEAR_Command::factory($command$config);
  202.                 $res $cmd->run($command$opts$params);
  203.             }
  204.  
  205.             $URL .= '?command=config-show';
  206.             header("Location: ".$URL);
  207.             exit;
  208.         case 'list-all':
  209.             $command $_GET["command"];
  210.             $params = array();
  211.             if (isset($_GET["mode"]))
  212.                 $opts['mode'$_GET["mode"];
  213.             $cmd = PEAR_Command::factory($command$config);
  214.             $ok $cmd->run($command$opts$params);
  215.  
  216.             exit;
  217.         case 'channel-info':
  218.             $command $_GET["command"];
  219.             $params = array();
  220.             if (isset($_GET["chan"]))
  221.                 $params[$_GET["chan"];
  222.             $cmd = PEAR_Command::factory($command$config);
  223.             $ok $cmd->run($command$opts$params);
  224.  
  225.             exit;
  226.         case 'channel-discover':
  227.             $command $_GET["command"];
  228.             $params = array();
  229.             if (isset($_GET["chan"]))
  230.                 $params[$_GET["chan"];
  231.             $cmd = PEAR_Command::factory($command$config);
  232.             $ui->startSession();
  233.             $ok $cmd->run($command$opts$params);
  234.  
  235.             $ui->finishOutput('Channel Discovery'array('link' =>
  236.                 $_SERVER['PHP_SELF''?command=channel-info&chan=' urlencode($_GET['chan']),
  237.                 'text' => 'Click Here for ' htmlspecialchars($_GET['chan']' Information'));
  238.             exit;
  239.         case 'channel-delete':
  240.             $command $_GET["command"];
  241.             $params = array();
  242.             if (isset($_GET["chan"]))
  243.                 $params[$_GET["chan"];
  244.             $cmd = PEAR_Command::factory($command$config);
  245.             $ui->startSession();
  246.             $ok $cmd->run($command$opts$params);
  247.  
  248.             $ui->finishOutput('Channel Deletion');
  249.             exit;
  250.         case 'list-channels':
  251.             $command $_GET["command"];
  252.             $params = array();
  253.             $cmd = PEAR_Command::factory($command$config);
  254.             $ok $cmd->run($command$opts$params);
  255.  
  256.             exit;
  257.         case 'update-channels':
  258.             $command $_GET["command"];
  259.             $params = array();
  260.             $cmd = PEAR_Command::factory($command$config);
  261.             $ui->startSession();
  262.             $ok $cmd->run($command$opts$params);
  263.  
  264.             $ui->finishOutput('Update Channel List'array('link' =>
  265.                 $_SERVER['PHP_SELF''?command=list-channels',
  266.                 'text' => 'Click here to list all channels'));
  267.             exit;
  268.         case 'show-last-error':
  269.             $GLOBALS['_PEAR_Frontend_Web_log'$_SESSION['_PEAR_Frontend_Web_LastError_log'];
  270.             $ui->displayError($_SESSION['_PEAR_Frontend_Web_LastError']'Error''error'true);
  271.             exit;
  272.         default:
  273.             $command $_GET["command"];
  274.             $cmd = PEAR_Command::factory($command$config);
  275.             $res $cmd->run($command$opts$params);
  276.  
  277.             $URL .= '?command='.$_GET["command"];
  278.             header("Location: ".$URL);
  279.             exit;
  280.     }
  281. }
  282.  
  283. $ui->displayStart();
  284. ?>

Documentation generated on Mon, 11 Mar 2019 14:37:19 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.