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.34 2006/03/02 13:59:02 pajoye 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.                                 'PEAR',
  102.                                 'PEAR_Frontend_Web',
  103.                                 'XML_RPC'
  104.                         );
  105.     $reg &$config->getRegistry();
  106.     if (!file_exists($dir.'PEAR/.registry')) {
  107.         PEAR::raiseError('Directory "'.$dir.'PEAR/.registry" does not exist. please check your installation');
  108.     }
  109.  
  110.     foreach($packages as $pkg{
  111.         $info $reg->packageInfo($pkg);
  112.         foreach($info['filelist'as $fileName => $fileInfo{
  113.             if($fileInfo['role'== "php"{
  114.                 $info['filelist'][$fileName]['installed_as'=
  115.                     str_replace('{dir}',$dir$fileInfo['installed_as']);
  116.             }
  117.         }
  118.         $reg->updatePackage($pkg$infofalse);
  119.     }
  120. }
  121.  
  122. $cache_dir $config->get('cache_dir');
  123. if (!is_dir($cache_dir)) {
  124.     include_once 'System.php';
  125.     if (!System::mkDir('-p'$cache_dir)) {
  126.         PEAR::raiseError('Directory "'.$cache_dir.'" does not exist and cannot be created. Please check your installation');
  127.     }
  128. }
  129.  
  130. // Handle some diffrent Commands
  131. if (isset($_GET["command"])) {
  132.     switch ($_GET["command"]{
  133.         case 'install':
  134.         case 'uninstall':
  135.         case 'upgrade':
  136.             if (USE_DHTML_PROGRESS && isset($_GET['dhtml'])) {
  137.                 PEAR::setErrorHandling(PEAR_ERROR_CALLBACKarray($ui"displayErrorImg"));
  138.             }
  139.  
  140.             $command $_GET["command"];
  141.             if (strpos($_GET['pkg']'\\\\'!== false{
  142.                 $_GET['pkg'stripslashes($_GET['pkg']);
  143.             }
  144.             $params = array($_GET["pkg"]);
  145.             $cmd = PEAR_Command::factory($command$config);
  146.             $ok $cmd->run($command$opts$params);
  147.  
  148.             // success
  149.             if (USE_DHTML_PROGRESS && isset($_GET['dhtml'])) {
  150.                 echo '<script language="javascript">';
  151.                 if ($_GET["command"== "uninstall"{
  152.                     printf(' parent.deleteVersion(\'%s\'); ',  $_GET["pkg"]);
  153.                     printf(' parent.displayInstall(\'%s\'); '$_GET["pkg"]);
  154.                     printf(' parent.hideDelete(\'%s\'); ',     $_GET["pkg"]);
  155.                 else {
  156.                     printf(' parent.newestVersion(\'%s\'); ',  $_GET["pkg"]);
  157.                     printf(' parent.hideInstall(\'%s\'); ',    $_GET["pkg"]);
  158.                     printf(' parent.displayDelete(\'%s\'); ',  $_GET["pkg"]);
  159.                 }
  160.                 echo '</script>';
  161.                 $html sprintf('<img src="%s?img=install_ok" border="0">'$_SERVER['PHP_SELF']);
  162.                 echo $js.$html;
  163.                 exit;
  164.             }
  165.  
  166.             if (isset($_GET['redirect']&& $_GET['redirect'== 'info'{
  167.                 $URL .= '?command=remote-info&pkg='.$_GET["pkg"];
  168.             elseif (isset($_GET['redirect']&& $_GET['redirect'== 'search'{
  169.                 $URL .= '?command=search&userDialogResult=get&0='.$_GET["0"].'&1='.$_GET["1"];
  170.             else {
  171.                 $URL .= '?command=list-all&pageID='.$_GET['pageID'].'#'.$_GET["pkg"];
  172.             }
  173.             Header("Location: ".$URL);
  174.             exit;
  175.         case 'run-scripts' :
  176.             $command $_GET["command"];
  177.             $params = array($_GET["pkg"]);
  178.             $cmd = PEAR_Command::factory($command$config);
  179.             $ok $cmd->run($command$opts$params);
  180.             exit;
  181.         case 'remote-info':
  182.             $command $_GET["command"];
  183.             $params = array($_GET["pkg"]);
  184.             $cmd = PEAR_Command::factory($command$config);
  185.             $ok $cmd->run($command$opts$params);
  186.  
  187.             exit;
  188.         case 'search':
  189.             list($name$description$ui->userDialog('search',
  190.                 array('Package Name''Package Info')// Prompts
  191.                 array()array()// Types, Defaults
  192.                 'Package Search''pkgsearch' // Title, Icon
  193.                 );
  194.  
  195.             $command $_GET["command"];
  196.             $params = array($name$description);
  197.             $cmd = PEAR_Command::factory($command$config);
  198.             $ok $cmd->run($command$opts$params);
  199.  
  200.             exit;
  201.         case 'config-show':
  202.             $command $_GET["command"];
  203.             $cmd = PEAR_Command::factory($command$config);
  204.             $res $cmd->run($command$opts$params);
  205.             foreach($GLOBALS['_PEAR_Frontend_Web_Config'as $var => $value{
  206.                 $command 'config-set';
  207.                 $params = array($var$value);
  208.                 $cmd = PEAR_Command::factory($command$config);
  209.                 $res $cmd->run($command$opts$params);
  210.             }
  211.  
  212.             $URL .= '?command=config-show';
  213.             header("Location: ".$URL);
  214.             exit;
  215.         case 'list-all':
  216.             $command $_GET["command"];
  217.             $params = array();
  218.             if (isset($_GET["mode"]))
  219.                 $opts['mode'$_GET["mode"];
  220.             $cmd = PEAR_Command::factory($command$config);
  221.             $ok $cmd->run($command$opts$params);
  222.  
  223.             exit;
  224.         case 'channel-info':
  225.             $command $_GET["command"];
  226.             $params = array();
  227.             if (isset($_GET["chan"]))
  228.                 $params[$_GET["chan"];
  229.             $cmd = PEAR_Command::factory($command$config);
  230.             $ok $cmd->run($command$opts$params);
  231.  
  232.             exit;
  233.         case 'channel-discover':
  234.             $command $_GET["command"];
  235.             $params = array();
  236.             if (isset($_GET["chan"]))
  237.                 $params[$_GET["chan"];
  238.             $cmd = PEAR_Command::factory($command$config);
  239.             $ui->startSession();
  240.             $ok $cmd->run($command$opts$params);
  241.  
  242.             $ui->finishOutput('Channel Discovery'array('link' =>
  243.                 $_SERVER['PHP_SELF''?command=channel-info&chan=' urlencode($_GET['chan']),
  244.                 'text' => 'Click Here for ' htmlspecialchars($_GET['chan']' Information'));
  245.             exit;
  246.         case 'channel-delete':
  247.             $command $_GET["command"];
  248.             $params = array();
  249.             if (isset($_GET["chan"]))
  250.                 $params[$_GET["chan"];
  251.             $cmd = PEAR_Command::factory($command$config);
  252.             $ui->startSession();
  253.             $ok $cmd->run($command$opts$params);
  254.  
  255.             $ui->finishOutput('Channel Deletion');
  256.             exit;
  257.         case 'list-channels':
  258.             $command $_GET["command"];
  259.             $params = array();
  260.             $cmd = PEAR_Command::factory($command$config);
  261.             $ok $cmd->run($command$opts$params);
  262.  
  263.             exit;
  264.         case 'update-channels':
  265.             $command $_GET["command"];
  266.             $params = array();
  267.             $cmd = PEAR_Command::factory($command$config);
  268.             $ui->startSession();
  269.             $ok $cmd->run($command$opts$params);
  270.  
  271.             $ui->finishOutput('Update Channel List'array('link' =>
  272.                 $_SERVER['PHP_SELF''?command=list-channels',
  273.                 'text' => 'Click here to list all channels'));
  274.             exit;
  275.         case 'show-last-error':
  276.             $GLOBALS['_PEAR_Frontend_Web_log'$_SESSION['_PEAR_Frontend_Web_LastError_log'];
  277. var_dump($_SESSION);
  278.             $ui->displayError($_SESSION['_PEAR_Frontend_Web_LastError']'Error''error'true);
  279.             exit;
  280.         default:
  281.             $command $_GET["command"];
  282.             $cmd = PEAR_Command::factory($command$config);
  283.             $res $cmd->run($command$opts$params);
  284.  
  285.             $URL .= '?command='.$_GET["command"];
  286.             header("Location: ".$URL);
  287.             exit;
  288.     }
  289. }
  290.  
  291. $ui->displayStart();
  292. ?>

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