📄 webinstaller.php
字号:
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4; */
// +---------------------------------------------------------------------+
// | PHP version 4.0 |
// +---------------------------------------------------------------------+
// | Copyright (c) 1997-2001 The PHP Group |
// +---------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available 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. |
// +---------------------------------------------------------------------+
// | Authors: Christian Stocker <chregu@phant.ch> |
// +---------------------------------------------------------------------+
/* This class should simplify the task of installing PEAR-packages, if you
* don't have a cgi-php binary on your system or you don't have access to
* the system-wide pear directory.
*
* To use it, make the following php-script:
*
* <?php
* require("PEAR/WebInstaller.php");
* $installer = new PEAR_WebInstaller("/path/to/your/install/dir","http://php.chregu.tv/pear/");
* $installer->start();
* ?>
*
* and put PEAR/WebInstaller.php (this script) anywhere in your include_path.
*
* (http://php.chregu.tv/pear/ is just for testing purposes until this
* system runs on pear.php.net, but feel free to use it till then)
*
* Both parameters are optional. If the install dir is ommitted, the
* installer takes either the system wide pear-directory (mostly
* /usr/local/lib/php on unix), if it's writeable, or else the directory
* the script is started. Be advised, that the directory, where the
* PEAR::Packages will be installed, has to be writeable for the web-server.
*
* The second parameter points to the server/directory where all the
* packages and especially Packages.xml is located. If not given, the
* standard PEAR-Repository is taken (http://pear.php.net/whatever..)
*
* After installation, just add the install-dir to your include_path and
* the packages should work.
*
* If you are System Adminisitrator and want the installed packages to be
* made available for everyone, just copy the files to the systemwide
* pear-dir after installation on the commandline. Or also add the
* install-dir to the systemwide include_path (and maybe don't forget to
* take the writeable off the directory..)
*
* TODO:
* - More Error Detection
* - Grouping of Packages
* - Show installed Packages (from /var/lib/php/packages.lst?)
* - Add possibility to install a package (.tgz) from the local file
* system without a global Packages.xml (useful if no cgi-php
* around and you need this package you downloaded installed :) )
* - Search Function (maybe needed if we have hundreds of packages)
* - Only download Packages.xml, if it actually changed.
*
* This Code is highly experimental.
*/
require_once "PEAR.php";
class PEAR_WebInstaller extends PEAR
{
// {{{ properties
/** stack of elements, gives some sort of XML context */
var $element_stack;
/** name of currently parsed XML element */
var $current_element;
/** array of attributes of the currently parsed XML element */
var $current_attributes = array();
/** assoc with information about a package */
var $pkginfo = array();
/** assoc with information about all packages */
var $AllPackages;
/** URL to the server containing all packages in tgz-Format and the Package.xml */
var $remotedir = "http://php.chregu.tv/pear/";
/* Directory where the to be installed files should be put
per default PEAR_INSTALL_DIR (/usr/local/lib/php) if it's writeable for the webserver,
else current directory, or user defined directory (provided as first parameter in constructor)
The Directory hast to be writeable for the php-module (webserver)
*/
var $installdir;
/** how many seconds we should cache Packages.xml */
var $cachetime = 3600;
var $printlogger = True;
// }}}
// {{{ constructor
function PEAR_Webinstaller($installdir = Null,$remotedir = Null)
{
$this->PEAR();
if ($installdir)
{
$this->installdir = $installdir;
}
else
{
if (is_writeable(PEAR_INSTALL_DIR))
{
$this->installdir = PEAR_INSTALL_DIR;
}
else
{
$this->installdir = getcwd();
}
}
if ($remotedir)
{
$this->remotedir = $remotedir;
}
}
// }}}
// {{{ start()
function start() {
global $HTTP_POST_VARS,$HTTP_GET_VARS;
//print header
$this->header();
$this->loggerStart();
//if some checkboxes for installation were selected, install.
if ($HTTP_GET_VARS["help"]) {
$this->help($HTTP_GET_VARS["help"]);
}
elseif ($HTTP_POST_VARS["InstPack"]) {
$this->installPackages(array_keys($HTTP_POST_VARS["InstPack"]));
}
//else print all modules
else {
$this->printTable();
}
$this->footer();
}
// }}}
// {{{ installPackages()
/* installs the Packages and prints if successfull or not */
function installPackages($packages)
{
require_once "PEAR/Installer.php";
$installer =& new PEAR_Installer();
$installer->phpdir = $this->installdir;
$this->loggerEnd();
print "<TABLE CELLSPACING=0 BORDER=0 CELLPADDING=1>";
print "<TR><TD BGCOLOR=\"#000000\">\n";
print "<TABLE CELLSPACING=1 BORDER=0 CELLPADDING=3 width=100%>\n";
print " <TR BGCOLOR=\"#e0e0e0\">\n";
print " <TH>Package</TH>\n";
print " <TH>Status</TH>\n";
foreach ($packages as $package)
{
if (++$i % 2) {
$bg1 = "#ffffff";
$bg2 = "#f0f0f0";
}
else {
$bg1 = "#f0f0f0";
$bg2 = "#e0e0e0";
}
print " <TR>\n";
print "<TD BGCOLOR=\"$bg1\">";
print $package;
print "</TD>\n";
/*
print "<TD BGCOLOR=\"$bg2\">";
print "Installing ...";
print "</td>";
print " <TR>\n";
print "<TD BGCOLOR=\"$bg1\">";
print " ";
print "</TD>\n";
*/
print "<TD BGCOLOR=\"$bg2\">";
if (PEAR::isError($installer->Install($this->remotedir."/".$package.".tgz"))) {
print "\ninstall failed\n";
}
else {
print "install ok\n";
}
print "</td></tr>\n";
}
print "</td></tr>";
print "</table>";
print "<TABLE CELLSPACING=1 BORDER=0 CELLPADDING=3 width=\"100%\">\n";
print " <TR BGCOLOR=\"$bg1\">\n";
print "<th colspan=\"2\">";
print "<a href=\"$GLOBALS[PHP_SELF]\">Back to the Packages</a>\n";
print "</th></tr></table>";
print"</td></tr></table>";
}
// }}}
// {{{ printTable()
/* Prints a table with all modules available on the server-directory */
function printTable()
{
global $PHP_SELF;
$Packages = $this->getPackages();
if (PEAR::IsError($Packages))
{
if ($this->printlogger) {
$this->logger($Packages->message);
}
else
{
print $Packages->message;
}
return $Packages;
}
$this->loggerEnd();
print "<FORM action=\"$GLOBALS[PHP_SELF]\" method=\"post\">\n";
print "<TABLE CELLSPACING=0 BORDER=0 CELLPADDING=1>";
print "<TR><TD BGCOLOR=\"#000000\">\n";
print "<TABLE CELLSPACING=1 BORDER=0 CELLPADDING=3 width=\"100%\">\n";
print "<tr bgcolor=\"f0f0f0\">";
print "<td COLSPAN=\"6\" ><input type=\"submit\" value=\"Install\"></td>";
print "</tr>";
print " <TR BGCOLOR=\"#e0e0e0\" >\n";
print " <TH>Inst.</TH>\n";
print " <TH>Package</TH>\n";
print " <TH>Summary</TH>\n";
print " <TH>Version</TH>\n";
print " <TH>Release date</TH>\n";
print " <TH>Release notes</TH>\n";
print " </TR>\n";
$i = 0;
ksort($Packages);
foreach ( $Packages as $package) {
if (++$i % 2) {
$bg1 = "#ffffff";
$bg2 = "#f0f0f0";
}
else {
$bg1 = "#f0f0f0";
$bg2 = "#e0e0e0";
}
print "<TR>\n";
print "<TD align=\"middle\" BGCOLOR=\"$bg2\">";
print "<input type=\"checkbox\" name=\"InstPack[".$package["name"]."-".$package["version"]."]\">\n";
print "</TD>\n";
print " <TD BGCOLOR=\"$bg1\">";
print $this->printCell ($package["name"],"http://pear.php.net/pkginfo.php?package=$package[name]");
print "</TD>\n";
print "<TD BGCOLOR=\"$bg2\">";
$this->printCell ($package["summary"]);
print "</TD>\n";
print "<TD BGCOLOR=\"$bg2\">";
$this->printCell ($package["version"],$this->remotedir."/".$package["name"]."-".$package["version"].".tgz");
print "</TD>\n";
print "<TD BGCOLOR=\"$bg2\">";
$this->printCell ($package["release_date"]);
print "</TD>\n";
print "<TD BGCOLOR=\"$bg2\">";
$this->printCell (nl2br($package["release_notes"]));
print "</TD>\n";
print " </TR>\n";
}
print "<tr bgcolor=\"$bg1\">";
print "<td COLSPAN=\"6\" ><input type=\"submit\" value=\"Install\"></td>";
print "</tr>";
print "</TABLE> \n";
print "<TABLE CELLSPACING=1 BORDER=0 CELLPADDING=3 width=\"100%\">\n";
print " <TR BGCOLOR=\"#e0e0e0\">\n";
print "<th align=left width=\"10%\" nowrap>\n";
print "Install Directory: </th><td>$this->installdir";
if (!is_writable($this->installdir))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -