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.39 2007/03/27 21:04:30 tias 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.                                 'Structures_Graph'
  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.             if ($_GET['command'== 'install'{
  141.                 // also install dependencies
  142.                 $opts['onlyreqdeps'= true;
  143.             }
  144.  
  145.             $command $_GET["command"];
  146.             if (strpos($_GET['pkg']'\\\\'!== false{
  147.                 $_GET['pkg'stripslashes($_GET['pkg']);
  148.             }
  149.             $params = array($_GET["pkg"]);
  150.             $cmd = PEAR_Command::factory($command$config);
  151.             $ok $cmd->run($command$opts$params);
  152.  
  153.             // success
  154.             if (USE_DHTML_PROGRESS && isset($_GET['dhtml'])) {
  155.                 echo '<script language="javascript">';
  156.                 if ($_GET["command"== "uninstall"{
  157.                     printf(' parent.deleteVersion(\'%s\'); ',  $_GET["pkg"]);
  158.                     printf(' parent.displayInstall(\'%s\'); '$_GET["pkg"]);
  159.                     printf(' parent.hideDelete(\'%s\'); ',     $_GET["pkg"]);
  160.                 else {
  161.                     printf(' parent.newestVersion(\'%s\'); ',  $_GET["pkg"]);
  162.                     printf(' parent.hideInstall(\'%s\'); ',    $_GET["pkg"]);
  163.                     printf(' parent.displayDelete(\'%s\'); ',  $_GET["pkg"]);
  164.                 }
  165.                 echo '</script>';
  166.                 $html sprintf('<img src="%s?img=install_ok" border="0">'$_SERVER['PHP_SELF']);
  167.                 echo $js.$html;
  168.                 exit;
  169.             }
  170.  
  171.             if (isset($_GET['redirect']&& $_GET['redirect'== 'info'{
  172.                 $URL .= '?command=remote-info&pkg='.$_GET["pkg"];
  173.             elseif (isset($_GET['redirect']&& $_GET['redirect'== 'search'{
  174.                 $URL .= '?command=search&userDialogResult=get&0='.$_GET["0"].'&1='.$_GET["1"];
  175.             else {
  176.                 $URL .= '?command=list-all&mode=installed';
  177.                 // following doesn't work:
  178.                 //$URL .= '?command=list-all&pageID='.$_GET['pageID'].'#'.$_GET["pkg"];
  179.             }
  180.             Header("Location: ".$URL);
  181.             exit;
  182.         case 'run-scripts' :
  183.             $command $_GET["command"];
  184.             $params = array($_GET["pkg"]);
  185.             $cmd = PEAR_Command::factory($command$config);
  186.             $ok $cmd->run($command$opts$params);
  187.             exit;
  188.         case 'remote-info':
  189.             $command $_GET["command"];
  190.             $params = array($_GET["pkg"]);
  191.             $cmd = PEAR_Command::factory($command$config);
  192.             $ok $cmd->run($command$opts$params);
  193.  
  194.             exit;
  195.         case 'search':
  196.             list($name$description$ui->userDialog('search',
  197.                 array('Package Name''Package Info')// Prompts
  198.                 array()array()// Types, Defaults
  199.                 'Package Search''pkgsearch' // Title, Icon
  200.                 );
  201.  
  202.             $command $_GET["command"];
  203.             $params = array($name$description);
  204.             $cmd = PEAR_Command::factory($command$config);
  205.             $ok $cmd->run($command$opts$params);
  206.  
  207.             exit;
  208.         case 'config-show':
  209.             $params = array();
  210.             $command $_GET["command"];
  211.             $cmd = PEAR_Command::factory($command$config);
  212.             $res $cmd->run($command$opts$params);
  213.  
  214.             // if this code is reached, the config vars are submitted
  215.             $ui->startSession();
  216.             $set = PEAR_Command::factory('config-set'$config);
  217.             foreach($GLOBALS['_PEAR_Frontend_Web_Config'as $var => $value{
  218.                 if ($var == 'Filename'{
  219.                     continue; // I hate obscure bugs
  220.                 }
  221.                 if ($value != $config->get($var)) {
  222.                     $res $set->run('config-set'$optsarray($var$value));
  223.                     $config->set($var$value);
  224.                 }
  225.             }
  226.  
  227.             $ui->finishOutput('Save Config Changes'array('link' =>
  228.                 $_SERVER['PHP_SELF''?command='.$command,
  229.                 'text' => '<p>Configuration saved succesfully ! Back to config.</p>'));
  230.             exit;
  231.         case 'list-all':
  232.             $command $_GET["command"];
  233.             $params = array();
  234.             if (isset($_GET["mode"]))
  235.                 $opts['mode'$_GET["mode"];
  236.             $cmd = PEAR_Command::factory($command$config);
  237.             $ok $cmd->run($command$opts$params);
  238.  
  239.             exit;
  240.         case 'channel-info':
  241.             $command $_GET["command"];
  242.             $params = array();
  243.             if (isset($_GET["chan"]))
  244.                 $params[$_GET["chan"];
  245.             $cmd = PEAR_Command::factory($command$config);
  246.             $ok $cmd->run($command$opts$params);
  247.  
  248.             exit;
  249.         case 'channel-discover':
  250.             $command $_GET["command"];
  251.             $params = array();
  252.             if (isset($_GET["chan"]))
  253.                 $params[$_GET["chan"];
  254.             $cmd = PEAR_Command::factory($command$config);
  255.             $ui->startSession();
  256.             $ok $cmd->run($command$opts$params);
  257.  
  258.             $ui->finishOutput('Channel Discovery'array('link' =>
  259.                 $_SERVER['PHP_SELF''?command=channel-info&chan=' urlencode($_GET['chan']),
  260.                 'text' => 'Click Here for ' htmlspecialchars($_GET['chan']' Information'));
  261.             exit;
  262.         case 'channel-delete':
  263.             $command $_GET["command"];
  264.             $params = array();
  265.             if (isset($_GET["chan"]))
  266.                 $params[$_GET["chan"];
  267.             $cmd = PEAR_Command::factory($command$config);
  268.             $ui->startSession();
  269.             $ok $cmd->run($command$opts$params);
  270.  
  271.             $ui->finishOutput('Channel Deletion');
  272.             exit;
  273.         case 'list-channels':
  274.             $command $_GET["command"];
  275.             $params = array();
  276.             $cmd = PEAR_Command::factory($command$config);
  277.             $ok $cmd->run($command$opts$params);
  278.  
  279.             exit;
  280.         case 'update-channels':
  281.             // update every channel manually,
  282.             // fixes bug PEAR/#10275 (XML_RPC dependency)
  283.             // will be fixed in next pear release
  284.             $reg &$config->getRegistry();
  285.             $channels $reg->getChannels();
  286.             $command 'channel-update';
  287.             $cmd = PEAR_Command::factory($command$config);
  288.  
  289.             $success = true;
  290.             $ui->startSession();
  291.             foreach ($channels as $channel{
  292.                 if ($channel->getName(!= '__uri'{
  293.                     $success &= $cmd->run($command$opts,
  294.                                           array($channel->getName()));
  295.                 }
  296.             }
  297.             $ui->finishOutput('Update Channel List'array('link' =>
  298.                 $_SERVER['PHP_SELF''?command=list-channels',
  299.                 'text' => 'Click here to list all channels'));
  300.             exit;
  301.         case 'show-last-error':
  302.             $GLOBALS['_PEAR_Frontend_Web_log'$_SESSION['_PEAR_Frontend_Web_LastError_log'];
  303.             $ui->displayError($_SESSION['_PEAR_Frontend_Web_LastError']'Error''error'true);
  304.             exit;
  305.         default:
  306.             $command $_GET["command"];
  307.             $cmd = PEAR_Command::factory($command$config);
  308.             $res $cmd->run($command$opts$params);
  309.  
  310.             $URL .= '?command='.$_GET["command"];
  311.             header("Location: ".$URL);
  312.             exit;
  313.     }
  314. }
  315.  
  316. $ui->displayStart();
  317. ?>

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