[Patch] go-pear usability
| From: | Tias | Date: | Sun, 04 Mar 2007 17:05:59 +0000 |
| Subject: | [Patch] go-pear usability | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-45793@lists.php.net to get a copy of this message | ||
Hello pear-dev and go-pear maintainers,
Go-pear is such an amazingly great and conceptually simple thing. I
decided to enhance it, so that even more people can follow those easy
steps and install pear.
Attached is a patch that makes (the webfrontend of) go-pear more user friendly:
It enhances the usability of go-pear by making the menu work in clear stages,
by ordering the config page more intuitively, by allowing the selection of pfc packages individually
and by reporting config errors inline with the config form.
The changes are (in order of reading the patch file):
* show configuration errors inline in configuration page
* choose PFC packages individually
* more verbose error reporting of config errors
* menu generation, with stages in color
* immediat permission check on proposed default prefix dir
Some minor changes include:
* Include short description of pfc packages
* Some duplicate code removed
* Some css/html fixes
* webfrontend file linking fix
This patch, and a image-less example of how the go-pear config page looks like
now, can also be seen at: http://tias.ulyssis.org/patch/pear/go-pear/
Next I plan to make the installation more robust: allow an aborted
installation (eg php limit error, download timeout) to continue without
starting all over.
Feel free to contact me,
Greetings,
Tias
--- ../cvs/pearweb/public_html/go-pear 2007-01-24 01:53:36.000000000 +0100 +++ go-pear.php 2007-03-04 17:02:29.000000000 +0100 @@ -192,19 +192,19 @@ $installer_packages[] = 'PEAR_Frontend_Web-alpha'; } $pfc_packages = array( - 'MDB2', + 'MDB2' => 'database abstraction layer.', ); $config_desc = array( - 'prefix' => 'Installation prefix', + 'prefix' => 'Installation prefix ($prefix)', + 'temp_dir' => 'Temporary files directory', 'bin_dir' => 'Binaries directory', 'php_dir' => 'PHP code directory ($php_dir)', 'doc_dir' => 'Documentation base directory', 'data_dir' => 'Data base directory', 'test_dir' => 'Tests base directory', - 'temp_dir' => 'Temporary files directory' ); if(!WEBINSTALLER && WINDOWS){ $config_desc['php_bin'] = 'php.exe path'; @@ -247,8 +247,19 @@ exit(); } } + // If welcome, just welcome + if (!isset($_GET['step'])) { + $_GET['step'] = 'Welcome'; + /* clean up old sessions datas */ + session_destroy(); + } + if ($_GET['step'] == 'Welcome') { + displayHTML('Welcome'); + exit(); + } + if (!isset($_SESSION['go-pear']) || isset($_GET['restart'])) { $_SESSION['go-pear'] = array( 'http_proxy' => $http_proxy, 'config' => array( @@ -264,49 +275,67 @@ 'cache_ttl' => 300, 'webfrontend_file' => '$prefix/index.php', ), 'install_pfc' => true, + 'install_optional_packages' => array(), 'DHTML' => true, ); } - if (!isset($_GET['step'])) { - $_GET['step'] = 'Welcome'; - /* clean up old sessions datas */ - session_destroy(); - } + // save submited values if ($_GET['step'] == 'install') { $_SESSION['go-pear']['http_proxy'] = strip_magic_quotes($_POST['proxy']['host']).':'.strip_magic_quotes($_POST['proxy']['port']); if ($_SESSION['go-pear']['http_proxy'] == ':') { $_SESSION['go-pear']['http_proxy'] = ''; }; - $www_errors = array(); + $config_errors = array(); foreach($_POST['config'] as $key => $value) { $_POST['config'][$key] = strip_magic_quotes($value); if($key!='cache_ttl'){ if ( empty($_POST['config'][$key]) ) { if (WEBINSTALLER && $key!='php_bin' ) { - $www_errors[$key] = 'Please fill this path, you can use $prefix, $php_dir or a full path.'; + $config_errors[$key] = 'Please fill this path, you can use $prefix, $php_dir or a full path.'; } } } } - if( sizeof($www_errors)>0){ + if( sizeof($config_errors)>0){ $_GET['step'] = 'config'; } $_SESSION['go-pear']['config'] = $_POST['config']; $_SESSION['go-pear']['install_pfc'] = (isset($_POST['install_pfc']) && $_POST['install_pfc'] == 'on'); + // webinstaller allows to choose pfc packages individually + foreach ($pfc_packages as $key => $value) { + $pos = array_search($key, $_SESSION['go-pear']['install_optional_packages']); + if (isset($_POST[$key]) && $_POST[$key] == 'on' && $pos === false) { + $_SESSION['go-pear']['install_optional_packages'][] = $key; + } + if (!isset($_POST[$key]) && $pos !== false) { + unset($_SESSION['go-pear']['install_optional_packages'][$pos]); + } + } $_SESSION['go-pear']['DHTML'] = isset($_POST['BCmode']) ? false : true; } + // export session values $http_proxy = $_SESSION['go-pear']['http_proxy']; + $GLOBALS['config_vars'] = array_keys($config_desc); + array_unshift($GLOBALS['config_vars'], ''); + unset($GLOBALS['config_vars'][0]); // make indices run from 1... foreach($_SESSION['go-pear']['config'] as $var => $value) { $$var = $value; } $install_pfc = $_SESSION['go-pear']['install_pfc']; + $install_optional_packages = $_SESSION['go-pear']['install_optional_packages']; + + if ($_GET['step'] == 'config') { + displayHTML('config'); + exit(); + } + // Anything past this step has something to do with the installation } if (!WEBINSTALLER) { $tty = WINDOWS ? @fopen('\con', 'r') : @fopen('/dev/tty', 'r'); @@ -329,10 +358,10 @@ Go-pear will install the 'pear' command and all the files needed by it. This command is your tool for PEAR installation and maintenance. $local -Go-pear also lets you download and install the PEAR packages bundled -with PHP: " . implode(', ', $pfc_packages) . ". +Go-pear also lets you download and install the following optional PEAR +packages: " . implode(', ', array_keys($pfc_packages)) . ". If you wish to abort, press Control-C now, or press Enter to continue: "; @@ -365,28 +394,8 @@ $first = key($config_vars); end($config_vars); $last = key($config_vars); -if (WEBINSTALLER) { - if ( isset($www_errors) && sizeof($www_errors) ) { - displayHTML('config'); - exit(); - } else { - if (isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'] == true && $_GET['step'] == 'install') { - $_GET['step'] = 'preinstall'; - } - if ($_GET['step'] != 'install' && $_GET['step'] != 'install-progress') { - displayHTML($_GET['step']); - exit; - } - if ($_GET['step'] == 'install-progress') { - displayHTMLHeader(); - echo "Starting installation ...<br/>"; - } - ob_start(); - } -} - $progress = 0; /* * Checks PHP SAPI version under windows/CLI @@ -505,81 +514,145 @@ } } } +#### +# Installation stuff +#### + +// expand all subvars in the config vars foreach ($config_vars as $n => $var) { for ($m = 1; $m <= count($config_vars); $m++) { $var2 = $config_vars[$m]; $$var = str_replace('$'.$var2, $$var2, $$var); } } - -#### -# Temp stuff -#### -if (!empty($temp_dir)) { - $_found = temp_dir($temp_dir); -} else { - $_found = temp_dir(); -} - -if (!$_found) { + // temp dir stuff (separate for windows bugs) + if (!empty($temp_dir)) { + $_found = temp_dir($temp_dir); + } else { + $_found = temp_dir(); + } + if (!$_found) { + if (!WEBINSTALLER) { print " ****************************************************************************** FATAL ERROR! We cannot initialize the temp directory. Please be sure to give full write access to this directory and the install directory. "; + if (!empty($temp_dir)) { + print "'$temp_dir' was given."; + } + exit(); - if (!empty($temp_dir)) { - print "'$temp_dir' was given."; + } else { // WEBINSTALLER + if (!is_dir($temp_dir)) { + $config_errors['temp_dir'] = 'FATAL ERROR! This directory does not exist and we can not create it. Create the directory manually or make sure we have full permission in its parent directory.'; + if (!WINDOWS) { + $config_errors['temp_dir'] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>mkdir '.dirname($temp_dir).' && chmod 0777 '.dirname($temp_dir).'</tt></p>'; + } + } else { // is_dir(temp_dir) + $config_errors['temp_dir'] = 'FATAL ERROR! This directory exists, but we have no write permission in it.'; + if (!WINDOWS) { + $config_errors['temp_dir'] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>chmod 0777 '.$temp_dir.'</tt></p>'; + } + } + } } - exit(); -} + chdir($ptmp); // strange variable -$foo = $ptmp; - -$ptmp = tempnam($ptmp, 'gope'); + // check every dir, existence and permissions + foreach ($config_vars as $var) { + if (!preg_match('/_dir$/', $var) || $var == 'temp_dir') { + continue; + } -if (WINDOWS) { - $ptmp = str_replace($foo,'',$ptmp); - $foo = str_replace("\\\\",'/',$foo); - $s = substr($ptmp,0,1); - if($s == "\\" || $s == '/' ){ - $ptmp = $foo . '/' . substr($ptmp,1); - } else { - $ptmp = $foo . '/' . $ptmp; + $dir = $$var; + if (!@is_dir($dir)) { + if (!mkdir_p($dir)) { + if (!WEBINSTALLER) { + $root = WINDOWS ? 'administrator' : 'root'; + bail("Unable to create {$config_desc[$var]} $dir. +Run this script as $root or pick another location.\n"); + } else { // WEBINSTALLER + $config_errors[$var] = 'ERROR! This directory does not exist and we can not create it. Create the directory manually or make sure we have full permission in its parent directory.'; + if (!WINDOWS) { + $config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>mkdir '.dirname($dir).' && chmod 0777 '.dirname($dir).'</tt></p>'; + } + } + } + } + if (@is_dir($dir) && !is_writable($dir)) { + $config_errors[$var] = 'ERROR! This directory exists, but we have no write permission in it.'; + if (!WINDOWS) { + $config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>chmod 0777 '.$dir.'</tt></p>'; + } + } } -} -rm_rf($ptmp); -mkdir_p($ptmp, 0700); -$ok = @chdir($ptmp); - -foreach ($config_vars as $var) { - $dir = $$var; + // check every file, existence and permissions + foreach ($config_vars as $var) { + if (!preg_match('/_file$/', $var)) { + continue; + } - if (!preg_match('/_dir$/', $var)) { - continue; + $file = $$var; + $dir = dirname($file); + if (!file_exists($file) && !is_writable($dir)) { + if (!WEBINSTALLER) { + $root = WINDOWS ? 'administrator' : 'root'; + bail("Unable to create {$config_desc[$var]} $file. +Run this script as $root or pick another location.\n"); + } else { // WEBINSTALLER + $config_errors[$var] = 'ERROR! This file does not exist and we can not create it. Make sure we have full permission in its parent directory.'; + if (!WINDOWS) { + $config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>chmod 0777 '.$dir.'</tt></p>'; + } + } + } elseif (file_exists($file) && !is_writable($file)) { + $config_errors[$var] = 'ERROR! This file exists, but we have no write permission on it.'; + if (!WINDOWS) { + $config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>chmod 0777 '.$file.'</tt></p>'; + } + } } - if (!@is_dir($dir)) { - if (!mkdir_p($dir)) { - $root = WINDOWS ? 'administrator' : 'root'; - bail("Unable to create {$config_desc[$var]} $dir. -Run this script as $root or pick another location.\n"); +if (WEBINSTALLER) { + if ( isset($config_errors) && sizeof($config_errors) ) { + displayHTML('config'); + exit(); + } else { + if (isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'] == true && $_GET['step'] == 'install') { + $_GET['step'] = 'preinstall'; + } + if ($_GET['step'] != 'install' && $_GET['step'] != 'install-progress') { + displayHTML($_GET['step']); + exit; } + if ($_GET['step'] == 'install-progress') { + displayHTMLHeader(); + echo "Starting installation ...<br/>"; + } + ob_start(); } } if (!WEBINSTALLER) { $msg = "The following PEAR packages are bundled with PHP: " . - implode(', ', $pfc_packages); + implode(', ', array_keys($pfc_packages)); print "\n" . wordwrap($msg, 75) . ".\n"; print "Would you like to install these as well? [Y/n] : "; $install_pfc = !stristr(fgets($tty, 1024), "n"); + $install_optional_packages = array(); print "\n"; } #### @@ -617,11 +690,18 @@ print "Downloading uncompressed packages\n"; }; if ($install_pfc) { - $to_install = array_merge($installer_packages, $pfc_packages); + $to_install = array_merge($installer_packages, array_keys($pfc_packages)); } else { $to_install = $installer_packages; + + // webinstaller allows to choose pfc packages individually + foreach ($pfc_packages as $pkg => $desc) { + if (in_array($pkg, $install_optional_packages)) { + array_push($to_install, $pkg); + } + } } displayHTMLProgress($progress = 5); @@ -645,9 +725,9 @@ } } } -foreach ($installer_packages as $pkg) { +foreach ($to_install as $pkg) { $pkg_basename = substr($pkg, 0, strpos($pkg, '-')); if (isset($local_dir[$pkg_basename])) { echo str_pad("Using local package: $pkg", max(38,21+strlen($pkg)+4), '.'); copy(dirname(__FILE__) . '/go-pear-bundle/' . $local_dir[$pkg_basename], $local_dir[$pkg_basename]); @@ -708,22 +788,12 @@ download_url($url, 'Console/Getopt.php', $http_proxy); echo "(remote) "; } print "ok\n"; +// No duplicate Console_Getopt -print 'Bootstrapping: Console_Getopt.........'; -$r = 'RELEASE_' . ereg_replace('[^A-Za-z0-9]', '_', substr(substr($tarball['Console_Getopt'], 15), 0, -4)); -$url = "http://cvs.php.net/viewcvs.cgi/pear-core/Console/Getopt.php?view=co&pathrev=PEAR_1_4"; -mkdir('Console', 0700); -if (in_array('Getopt.php', $local_dir)) { - copy(dirname(__FILE__).'/go-pear-bundle/Getopt.php', 'Console/Getopt.php'); - echo "(local) "; -} else { - download_url($url, 'Console/Getopt.php', $http_proxy); - echo "(remote) "; -} -print "ok\n"; - +/* +// Following code block seems useless, pfc packages are in to_install, which are handled similarely a bit higher (even when using $install_pfc) if ($install_pfc) { foreach ($pfc_packages as $pkg) { foreach($local_dir as $file) { if (substr($file, 0, strlen($pkg)) == $pkg) { @@ -743,8 +813,9 @@ print "ok\n"; displayHTMLProgress($progress += round(65 / count($to_install))); } } +*/ displayHTMLProgress($progress = 70); PEAR::setErrorHandling(PEAR_ERROR_DIE, "\n%s\n"); @@ -1006,8 +1077,9 @@ //print "\nconnecting to $phost:$pport\n"; } if (!$fp) { bail("download of $url failed: $errstr ($errno)\n"); + // If valid URL but error, no CURL extentions installed } if (empty($proxy)) { $path = $tmp['path']; } else { @@ -1164,11 +1236,12 @@ $ok = mkdir_p(dirname($dir), $mode); } if ($ok) { $ok = @mkdir($dir, $mode); - if (!$ok) { - print "mkdir failed: <$dir>\n"; - } + // This is handled in the caller function (eg. webfrontend or not) + //if (!$ok) { + // print "mkdir failed: <$dir>\n"; + //} } return $ok; } @@ -1216,9 +1289,9 @@ } } /* try it really, is_writable is buggy with openbasedir */ - $fh = fopen(realpath($default) . "/test","wb"); + $fh = @fopen(realpath($default) . "/test","wb"); if ($fh) { $ptmp = $default; return true; } else { @@ -1481,9 +1554,12 @@ .green { color: #006600; } .red { - color: #006600; + color: #ff0000; + } + .grey { + color: #a9a9a9; } span.headline { font-family: verdana,arial,helvetica,sans-serif; @@ -1603,8 +1679,12 @@ form { margin-bottom : 0; } + hr { + text-align: left; + width: 80%; + } --> </style> <meta name="description" content="This is the Web Interface of the PEAR Installer" /> </head> @@ -1639,9 +1719,9 @@ <td align="left" valign="middle" width="20"> </td> <td align="left" valign="middle"> - <span class="Headline">Go-PEAR</span> + <span class="Headline">Go-PEAR Installer</span> </td> </tr> <tr bgcolor="#003300"><td colspan="3"></td></tr> @@ -1661,23 +1741,43 @@ <td bgcolor="#f0f0f0" width="100"> <table width="200" border="0" cellpadding="4" cellspacing="0"> <tr valign="top"> <td style="font-size: 90%" align="left" width="200"> - <br><br> - <img src="<?php echo basename(__FILE__); ?>?action=img&img=smallpear" border="0"> - <a href="<?php echo basename(__FILE__); ?>?step=Welcome&restart=1" <?php if ($page == 'Welcome') echo ' class="green"'; ?>> - Welcome to Go-PEAR - </a><br/> - - <img src="<?php echo basename(__FILE__); ?>?action=img&img=smallpear" border="0"> - <a href="<?php echo basename(__FILE__); ?>?step=config" <?php if ($page == 'config') echo ' class="green"'; ?>> - Configuration - </a><br/> - - <img src="<?php echo basename(__FILE__); ?>?action=img&img=smallpear" border="0"> -<?php if ($page == 'install') echo '<span class="green">'; ?> - Complete installation<br/> -<?php if ($page == 'install') echo '</span>'; ?> + <p><br /> + <?php + $menus = array('Welcome' => 'Welcome to Go-PEAR', + 'config' => 'Configuration', + 'preinstall' => 'Installation', + 'install' => 'Completed'); + $after_current = false; + + // Menu robustness (a bit low, but better then never) + if ($page == 'error') { + $_GET['last'] = $_GET['step']; + $after_current = true; + } elseif (!array_key_exists($page, $menus)) { + $page = 'Welcome'; + } + + foreach ($menus as $menu => $descr) { + print('<img src="'.basename(__FILE__).'?action=img&img=smallpear" border="0">'); + + if (!$after_current) { + $class = ''; + if ($page == $menu) { + $class = 'green'; + } + if (!isSet($_GET['last'])) { $_GET['last'] = $page; } + print('<a href="'.basename(__FILE__).'?step='.$menu.'&last='.$_GET['last'].'" class="'.$class.'">'.$descr.'</a><br />'); + + if ($_GET['last'] == $menu) { + $after_current = true; + } + } else { + print('<span class="grey">'.$descr.'</span><br />'); + } + } + ?> </td> </tr> </table> @@ -1703,9 +1803,9 @@ if (preg_match('/ok$/', $value)) { $value = preg_replace('/(ok)$/', '<span class="green">\1</span>', $value); } if (preg_match('/failed$/', $value)) { - $value = preg_replace('/(failed)$/', '<span style="color: #ff0000">\1</span>', $value); + $value = preg_replace('/(failed)$/', '<span class="red">\1</span>', $value); } if (preg_match('/^install ok:/', $value)) { $value = preg_replace('/^(install ok:)/', '<span class="green">\1</span>', $value); } @@ -1716,16 +1816,18 @@ echo nl2br($value); } elseif ($page == 'Welcome') { ?> <span class="title">Welcome to go-pear <?php echo GO_PEAR_VER; ?>!</span><br/> - <br/> - Go-pear will install the Web Frontend of the PEAR Installer and all the needed <br/> - files. This frontend is your tool for PEAR installation and maintenance.<br/> - <br/> - Go-pear also lets you download and install the PEAR packages bundled<br/> - with PHP: <?php echo implode(', ', $GLOBALS['pfc_packages']); ?>.<br/> - <br/> - <a href="<?php echo basename(__FILE__); ?>?step=config" class="green">Next >></a> + <p> + Go-pear will install Pear, its Web Frontend and all the needed files. This<br/> + frontend is your tool for PEAR installation and maintenance. + </p> + <p> + Go-pear also lets you download and install the following optional PEAR<br/> + packages: <?php echo implode(', ', array_keys($GLOBALS['pfc_packages'])); ?>. + </p> + + <a href="<?php echo basename(__FILE__); ?>?step=config&restart=1" class="green">Next >></a> <?php } elseif ($page == 'config') { if (!empty($GLOBALS['http_proxy'])) { list($proxy_host, $proxy_port) = explode(':', $GLOBALS['http_proxy']); @@ -1733,102 +1835,156 @@ $proxy_host = $proxy_port = ''; } ?> <form action="<?php echo basename(__FILE__);?>?step=install" method="post"> - <span class="title">Configuration</span><br/> - <br/> - HTTP proxy (host:port): - <input type="text" name="proxy[host]" value="<?php echo $proxy_host;?>"> - <input type="text" name="proxy[port]" value="<?php echo $proxy_port;?>" size="6"> - <br/><br/><hr/><br/> - Below is a suggested file layout for your new PEAR installation. <br/> - <br/> - <table border="0"> - <TR> - <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD> - <TD> + <!-- Packages stuff --> + <span class="title">Packages</span> + <p> + The following PEAR packages will be installed. You can select some optional<br /> + packages to be installed by go-pear too:<br /> + </p> + <table border="0" width="80%"> + <tr> + <th> </th><th>Package</th><th width="65%">Description</th> + </tr><tr> + <td>(required)</td><td>PEAR core</td><td>The PEAR core packages.</td> + </tr><tr> + <td>(required)</td><td>Web Installer</td><td>The PEAR Web Installer and its dependencies.</td> + </tr> + <?php + foreach ($GLOBALS['pfc_packages'] as $var => $descr) { + $checked = ''; + if (in_array($var, $GLOBALS['install_optional_packages'])) { $checked = ' checked'; } + printf('<tr><td align="center"><input type="checkbox" name="%s"%s></td><td>%s</td><td>%s</td></tr>', + $var, + $checked, + $var, + $descr); + } + //<input type="checkbox" name="install_pfc" <?php if($GLOBALS['install_pfc']) ?\>> Install those too<br/> + ?> + </table> + <hr /> + + <!-- Configuration stuff --> + <span class="title">Configuration</span> + <p> + Below is a suggested file layout for your new PEAR installation. + </p> + + <!-- + <p> + <table border="0"> + <tr> + <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></td> + <td> <span class="green"> <b>Note:</b> Make sure that PHP has the permission to access the specified<br/> - directories.<br/><br/> + directories. </span> - </TD> - </TR> + </td> + </tr> </table> - <TABLE border="0"> + </p> + --> + + <table border="0" width="80%"> <?php - // Display error messages - if (isset($GLOBALS['www_errors']) && sizeof($GLOBALS['www_errors']) ) { - $www_errors = $GLOBALS['www_errors']; - echo "<tr><td>"; - echo '<span class="red">ERROR(S):</span>'; - echo "</td></tr>"; - foreach ($www_errors as $n => $var) { - echo "<tr><td>"; - echo '<span class="red">'.$GLOBALS['config_desc'][$n].': </span>'; - echo "</td><td>"; - echo '<span class="red">'.$www_errors[$n].'</span>'; - echo "<br>\n"; - echo "</td></tr>\n"; + foreach ($GLOBALS['config_vars'] as $n => $var) { + $error_class = ''; + if (is_array($GLOBALS['config_errors']) && array_key_exists($var, $GLOBALS['config_errors'])) { + // www_error for this var + $error_class = ' class="red"'; } - } - foreach ($GLOBALS['config_vars'] as $n => $var) { - printf('<tr><td>%d. %s</td><td><input type="text" name="config[%s]" value="%s"></td></tr>', + printf('<tr><td>%d. %s</td><td><input type="text" name="config[%s]" value="%s"%s></td></tr>', $n, $GLOBALS['config_desc'][$var], $var, - $GLOBALS[$var]); + $_SESSION['go-pear']['config'][$var], + $error_class); + + // prefix dir, check perm (uses GLOBALS: resolved subvars) + if ($n == 1 && is_dir($GLOBALS[$var]) && !is_writable($GLOBALS[$var])) { + $error = '<em>WARNING!</em> No permission to create subdirectories in this prefix dir. Unless you fix this, the default configuration will not work.'; + if (!WINDOWS) { + $error .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>chmod 0777 '.$GLOBALS[$var].'</tt></p>'; + } + print('<tr><td colspan="2" class="green">'.$error.'</td></tr>'); + } + + + if (is_array($GLOBALS['config_errors']) && array_key_exists($var, $GLOBALS['config_errors'])) { + // www_error for this var + print('<tr><td colspan="2" class="red">'.$GLOBALS['config_errors'][$var].'</td></tr>'); + } } ?> - </TABLE> - <br/><hr/><br/> - The following PEAR packages are common ones, and can be installed<br/> - by go-pear too: <br/> -<?php echo implode(', ', $GLOBALS['pfc_packages']);?>.<br/> - <input type="checkbox" name="install_pfc" <?php if($GLOBALS['install_pfc']) ?>> Install those too<br/> - <br/><br/> - <table border="0"> - <TR> - <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD> - <TD> - <span class="green"> - <b>Note:</b> Installation might take some time, because go-pear has to download<br/> - all needed files from pear.php.net. Just be patient and wait for the next<br/> - page to load.<br/> - </span> - </TD> - </TR> </table> - <br> - <input type="checkbox" name="BCmode" id="BCmode" checked> Compatibility-Mode for old non-DOM Browsers<br/> + </p> + <hr /> + + <!-- Optional stuff --> + <span class="title">Optional:</span> + + <ul> + <p> + <li />HTTP proxy (host:port) + <input type="text" name="proxy[host]" value="<?php echo $proxy_host;?>"> : <input type="text" name="proxy[port]" value="<?php echo $proxy_port;?>" size="6"> + </p> + + <p> + <li />Compatibility-Mode for old non-DOM Browsers <input type="checkbox" name="BCmode" id="BCmode" checked> <script type="text/javascript"> <!-- if (document.getElementById('BCmode')) { document.getElementById('BCmode').checked = 0; }; // --> </script> + </p> + </ul> <?php if (WINDOWS && phpversion() == '4.1.1') { ?> + <p> <table border="0"> - <TR> - <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD> - <TD> + <tr> + <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></td> + <td> <span style="color: #ff0000"> <b>Warning:</b> Your PHP version (4.1.1) might be imcompatible with go-pear due to a bug<br/> in your PHP binary. If the installation crashes you might want to update your PHP version.</br> </span> - </TD> - </TR> + </td> + </tr> </table> + </p> <?php } ?> - <br/> + <hr /> + <!-- Closing note --> + <p> + <table border="0"> + <tr> + <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></td> + <td> + <span class="green"> + <b>Note:</b> Installation might take some time, because go-pear has to<br/> + download all needed files from pear.php.net. Just be patient and wait for<br/> + the next page to load.<br/> + </span> + </td> + </tr> + </table> + </p> + <input type="submit" value="Install" onClick="javascript: submitButton.value='Downloading and installing ... please wait ...'" name="submitButton"> </form> + <?php } elseif ($page == 'install') { ?> <span class="title">Installation Complete - Summary</span><br/> @@ -2011,8 +2167,9 @@ function displayHTMLInstallationSummary($data = '') { $next = NULL; $prefix = dirname($GLOBALS['webfrontend_file']); + $suffix = basename($GLOBALS['webfrontend_file']); $doc_root = strip_magic_quotes($_SERVER['DOCUMENT_ROOT']); $file_dir = dirname(__FILE__); if ( WINDOWS ) { $prefix = str_replace('/', '\\', strtolower($prefix)); @@ -2020,32 +2177,43 @@ $file_dir = str_replace('/', '\\', strtolower($file_dir)); } if ($doc_root && substr($prefix, 0, strlen($doc_root)) == $doc_root) { - $next = substr($prefix, strlen($doc_root)).'/index.php'; + $next = substr($prefix, strlen($doc_root)).'/'.$suffix; + // need leading / (prefix - docroot = path from docroot) + if (substr($next, 0, 1) != '/') { + $next = '/'.$next; + } } else if ($file_dir && substr($prefix, 0, strlen($file_dir)) == $file_dir) { - $next = substr($prefix, strlen($file_dir)).'/index.php'; + $next = substr($prefix, strlen($file_dir)).'/'.$suffix; + // strip leading / (prefix - file_dir = path from go-pear file) + if (substr($next, 0, 1) == '/') { + $next = substr($next, 1, strlen($next)); + } } if ($data) { echo "<br/>".$data; } ?> - <br/> + <p> + <span class="title">Installation Completed !</span> + </p> + <table border="0"> - <TR> - <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD> - <TD> + <tr> + <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></td> + <td> <span class="green"> <b>Note:</b> To use PEAR without any problems you need to add your<br/> PEAR Installation path (<?php echo $GLOBALS['php_dir']; ?>)<br> to your <a href="http://www.php.net/manual/en/configuration.directives.php#ini.include_path">include_path</a>.<br/> <br/> Using a .htaccess file or directly edit httpd.conf would be working solutions<br/> for Apache running servers, too.<br/> </span> - </TD> - </TR> + </td> + </tr> </table> <br/> For more information about PEAR, see:<br/> <a href="http://pear.php.net/faq.php" target="_new" class="green">PEAR FAQ</a><br/> @@ -2056,18 +2224,18 @@ <?php if ($next === NULL) { ?> <table border="0"> - <TR> - <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD> - <TD> + <tr> + <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></td> + <td> <span style="color: #ff0000"> <b>Warning:</b> Go-PEAR was not able to determine the URL to the newly<br/> installed Web Frontend of the PEAR Installer. Please access it manually.<br/> Since you specified the prefix, you should know how to do so.<br/> </span> - </TD> - </TR> + </td> + </tr> </table> <?php } else { if ($_GET['step'] == 'install-progress') { @@ -2503,4 +2671,6 @@ "; } return true; } + +?>
--- ../cvs/pearweb/public_html/go-pear 2007-01-24 01:53:36.000000000 +0100 +++ go-pear.php 2007-03-04 17:02:29.000000000 +0100 @@ -192,19 +192,19 @@ $installer_packages[] = 'PEAR_Frontend_Web-alpha'; } $pfc_packages = array( - 'MDB2', + 'MDB2' => 'database abstraction layer.', ); $config_desc = array( - 'prefix' => 'Installation prefix', + 'prefix' => 'Installation prefix ($prefix)', + 'temp_dir' => 'Temporary files directory', 'bin_dir' => 'Binaries directory', 'php_dir' => 'PHP code directory ($php_dir)', 'doc_dir' => 'Documentation base directory', 'data_dir' => 'Data base directory', 'test_dir' => 'Tests base directory', - 'temp_dir' => 'Temporary files directory' ); if(!WEBINSTALLER && WINDOWS){ $config_desc['php_bin'] = 'php.exe path'; @@ -247,8 +247,19 @@ exit(); } } + // If welcome, just welcome + if (!isset($_GET['step'])) { + $_GET['step'] = 'Welcome'; + /* clean up old sessions datas */ + session_destroy(); + } + if ($_GET['step'] == 'Welcome') { + displayHTML('Welcome'); + exit(); + } + if (!isset($_SESSION['go-pear']) || isset($_GET['restart'])) { $_SESSION['go-pear'] = array( 'http_proxy' => $http_proxy, 'config' => array( @@ -264,49 +275,67 @@ 'cache_ttl' => 300, 'webfrontend_file' => '$prefix/index.php', ), 'install_pfc' => true, + 'install_optional_packages' => array(), 'DHTML' => true, ); } - if (!isset($_GET['step'])) { - $_GET['step'] = 'Welcome'; - /* clean up old sessions datas */ - session_destroy(); - } + // save submited values if ($_GET['step'] == 'install') { $_SESSION['go-pear']['http_proxy'] = strip_magic_quotes($_POST['proxy']['host']).':'.strip_magic_quotes($_POST['proxy']['port']); if ($_SESSION['go-pear']['http_proxy'] == ':') { $_SESSION['go-pear']['http_proxy'] = ''; }; - $www_errors = array(); + $config_errors = array(); foreach($_POST['config'] as $key => $value) { $_POST['config'][$key] = strip_magic_quotes($value); if($key!='cache_ttl'){ if ( empty($_POST['config'][$key]) ) { if (WEBINSTALLER && $key!='php_bin' ) { - $www_errors[$key] = 'Please fill this path, you can use $prefix, $php_dir or a full path.'; + $config_errors[$key] = 'Please fill this path, you can use $prefix, $php_dir or a full path.'; } } } } - if( sizeof($www_errors)>0){ + if( sizeof($config_errors)>0){ $_GET['step'] = 'config'; } $_SESSION['go-pear']['config'] = $_POST['config']; $_SESSION['go-pear']['install_pfc'] = (isset($_POST['install_pfc']) && $_POST['install_pfc'] == 'on'); + // webinstaller allows to choose pfc packages individually + foreach ($pfc_packages as $key => $value) { + $pos = array_search($key, $_SESSION['go-pear']['install_optional_packages']); + if (isset($_POST[$key]) && $_POST[$key] == 'on' && $pos === false) { + $_SESSION['go-pear']['install_optional_packages'][] = $key; + } + if (!isset($_POST[$key]) && $pos !== false) { + unset($_SESSION['go-pear']['install_optional_packages'][$pos]); + } + } $_SESSION['go-pear']['DHTML'] = isset($_POST['BCmode']) ? false : true; } + // export session values $http_proxy = $_SESSION['go-pear']['http_proxy']; + $GLOBALS['config_vars'] = array_keys($config_desc); + array_unshift($GLOBALS['config_vars'], ''); + unset($GLOBALS['config_vars'][0]); // make indices run from 1... foreach($_SESSION['go-pear']['config'] as $var => $value) { $$var = $value; } $install_pfc = $_SESSION['go-pear']['install_pfc']; + $install_optional_packages = $_SESSION['go-pear']['install_optional_packages']; + + if ($_GET['step'] == 'config') { + displayHTML('config'); + exit(); + } + // Anything past this step has something to do with the installation } if (!WEBINSTALLER) { $tty = WINDOWS ? @fopen('\con', 'r') : @fopen('/dev/tty', 'r'); @@ -329,10 +358,10 @@ Go-pear will install the 'pear' command and all the files needed by it. This command is your tool for PEAR installation and maintenance. $local -Go-pear also lets you download and install the PEAR packages bundled -with PHP: " . implode(', ', $pfc_packages) . ". +Go-pear also lets you download and install the following optional PEAR +packages: " . implode(', ', array_keys($pfc_packages)) . ". If you wish to abort, press Control-C now, or press Enter to continue: "; @@ -365,28 +394,8 @@ $first = key($config_vars); end($config_vars); $last = key($config_vars); -if (WEBINSTALLER) { - if ( isset($www_errors) && sizeof($www_errors) ) { - displayHTML('config'); - exit(); - } else { - if (isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'] == true && $_GET['step'] == 'install') { - $_GET['step'] = 'preinstall'; - } - if ($_GET['step'] != 'install' && $_GET['step'] != 'install-progress') { - displayHTML($_GET['step']); - exit; - } - if ($_GET['step'] == 'install-progress') { - displayHTMLHeader(); - echo "Starting installation ...<br/>"; - } - ob_start(); - } -} - $progress = 0; /* * Checks PHP SAPI version under windows/CLI @@ -505,81 +514,145 @@ } } } +#### +# Installation stuff +#### + +// expand all subvars in the config vars foreach ($config_vars as $n => $var) { for ($m = 1; $m <= count($config_vars); $m++) { $var2 = $config_vars[$m]; $$var = str_replace('$'.$var2, $$var2, $$var); } } - -#### -# Temp stuff -#### -if (!empty($temp_dir)) { - $_found = temp_dir($temp_dir); -} else { - $_found = temp_dir(); -} - -if (!$_found) { + // temp dir stuff (separate for windows bugs) + if (!empty($temp_dir)) { + $_found = temp_dir($temp_dir); + } else { + $_found = temp_dir(); + } + if (!$_found) { + if (!WEBINSTALLER) { print " ****************************************************************************** FATAL ERROR! We cannot initialize the temp directory. Please be sure to give full write access to this directory and the install directory. "; + if (!empty($temp_dir)) { + print "'$temp_dir' was given."; + } + exit(); - if (!empty($temp_dir)) { - print "'$temp_dir' was given."; + } else { // WEBINSTALLER + if (!is_dir($temp_dir)) { + $config_errors['temp_dir'] = 'FATAL ERROR! This directory does not exist and we can not create it. Create the directory manually or make sure we have full permission in its parent directory.'; + if (!WINDOWS) { + $config_errors['temp_dir'] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>mkdir '.dirname($temp_dir).' && chmod 0777 '.dirname($temp_dir).'</tt></p>'; + } + } else { // is_dir(temp_dir) + $config_errors['temp_dir'] = 'FATAL ERROR! This directory exists, but we have no write permission in it.'; + if (!WINDOWS) { + $config_errors['temp_dir'] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>chmod 0777 '.$temp_dir.'</tt></p>'; + } + } + } } - exit(); -} + chdir($ptmp); // strange variable -$foo = $ptmp; - -$ptmp = tempnam($ptmp, 'gope'); + // check every dir, existence and permissions + foreach ($config_vars as $var) { + if (!preg_match('/_dir$/', $var) || $var == 'temp_dir') { + continue; + } -if (WINDOWS) { - $ptmp = str_replace($foo,'',$ptmp); - $foo = str_replace("\\\\",'/',$foo); - $s = substr($ptmp,0,1); - if($s == "\\" || $s == '/' ){ - $ptmp = $foo . '/' . substr($ptmp,1); - } else { - $ptmp = $foo . '/' . $ptmp; + $dir = $$var; + if (!@is_dir($dir)) { + if (!mkdir_p($dir)) { + if (!WEBINSTALLER) { + $root = WINDOWS ? 'administrator' : 'root'; + bail("Unable to create {$config_desc[$var]} $dir. +Run this script as $root or pick another location.\n"); + } else { // WEBINSTALLER + $config_errors[$var] = 'ERROR! This directory does not exist and we can not create it. Create the directory manually or make sure we have full permission in its parent directory.'; + if (!WINDOWS) { + $config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>mkdir '.dirname($dir).' && chmod 0777 '.dirname($dir).'</tt></p>'; + } + } + } + } + if (@is_dir($dir) && !is_writable($dir)) { + $config_errors[$var] = 'ERROR! This directory exists, but we have no write permission in it.'; + if (!WINDOWS) { + $config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>chmod 0777 '.$dir.'</tt></p>'; + } + } } -} -rm_rf($ptmp); -mkdir_p($ptmp, 0700); -$ok = @chdir($ptmp); - -foreach ($config_vars as $var) { - $dir = $$var; + // check every file, existence and permissions + foreach ($config_vars as $var) { + if (!preg_match('/_file$/', $var)) { + continue; + } - if (!preg_match('/_dir$/', $var)) { - continue; + $file = $$var; + $dir = dirname($file); + if (!file_exists($file) && !is_writable($dir)) { + if (!WEBINSTALLER) { + $root = WINDOWS ? 'administrator' : 'root'; + bail("Unable to create {$config_desc[$var]} $file. +Run this script as $root or pick another location.\n"); + } else { // WEBINSTALLER + $config_errors[$var] = 'ERROR! This file does not exist and we can not create it. Make sure we have full permission in its parent directory.'; + if (!WINDOWS) { + $config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>chmod 0777 '.$dir.'</tt></p>'; + } + } + } elseif (file_exists($file) && !is_writable($file)) { + $config_errors[$var] = 'ERROR! This file exists, but we have no write permission on it.'; + if (!WINDOWS) { + $config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>chmod 0777 '.$file.'</tt></p>'; + } + } } - if (!@is_dir($dir)) { - if (!mkdir_p($dir)) { - $root = WINDOWS ? 'administrator' : 'root'; - bail("Unable to create {$config_desc[$var]} $dir. -Run this script as $root or pick another location.\n"); +if (WEBINSTALLER) { + if ( isset($config_errors) && sizeof($config_errors) ) { + displayHTML('config'); + exit(); + } else { + if (isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'] == true && $_GET['step'] == 'install') { + $_GET['step'] = 'preinstall'; + } + if ($_GET['step'] != 'install' && $_GET['step'] != 'install-progress') { + displayHTML($_GET['step']); + exit; } + if ($_GET['step'] == 'install-progress') { + displayHTMLHeader(); + echo "Starting installation ...<br/>"; + } + ob_start(); } } if (!WEBINSTALLER) { $msg = "The following PEAR packages are bundled with PHP: " . - implode(', ', $pfc_packages); + implode(', ', array_keys($pfc_packages)); print "\n" . wordwrap($msg, 75) . ".\n"; print "Would you like to install these as well? [Y/n] : "; $install_pfc = !stristr(fgets($tty, 1024), "n"); + $install_optional_packages = array(); print "\n"; } #### @@ -617,11 +690,18 @@ print "Downloading uncompressed packages\n"; }; if ($install_pfc) { - $to_install = array_merge($installer_packages, $pfc_packages); + $to_install = array_merge($installer_packages, array_keys($pfc_packages)); } else { $to_install = $installer_packages; + + // webinstaller allows to choose pfc packages individually + foreach ($pfc_packages as $pkg => $desc) { + if (in_array($pkg, $install_optional_packages)) { + array_push($to_install, $pkg); + } + } } displayHTMLProgress($progress = 5); @@ -645,9 +725,9 @@ } } } -foreach ($installer_packages as $pkg) { +foreach ($to_install as $pkg) { $pkg_basename = substr($pkg, 0, strpos($pkg, '-')); if (isset($local_dir[$pkg_basename])) { echo str_pad("Using local package: $pkg", max(38,21+strlen($pkg)+4), '.'); copy(dirname(__FILE__) . '/go-pear-bundle/' . $local_dir[$pkg_basename], $local_dir[$pkg_basename]); @@ -708,22 +788,12 @@ download_url($url, 'Console/Getopt.php', $http_proxy); echo "(remote) "; } print "ok\n"; +// No duplicate Console_Getopt -print 'Bootstrapping: Console_Getopt.........'; -$r = 'RELEASE_' . ereg_replace('[^A-Za-z0-9]', '_', substr(substr($tarball['Console_Getopt'], 15), 0, -4)); -$url = "http://cvs.php.net/viewcvs.cgi/pear-core/Console/Getopt.php?view=co&pathrev=PEAR_1_4"; -mkdir('Console', 0700); -if (in_array('Getopt.php', $local_dir)) { - copy(dirname(__FILE__).'/go-pear-bundle/Getopt.php', 'Console/Getopt.php'); - echo "(local) "; -} else { - download_url($url, 'Console/Getopt.php', $http_proxy); - echo "(remote) "; -} -print "ok\n"; - +/* +// Following code block seems useless, pfc packages are in to_install, which are handled similarely a bit higher (even when using $install_pfc) if ($install_pfc) { foreach ($pfc_packages as $pkg) { foreach($local_dir as $file) { if (substr($file, 0, strlen($pkg)) == $pkg) { @@ -743,8 +813,9 @@ print "ok\n"; displayHTMLProgress($progress += round(65 / count($to_install))); } } +*/ displayHTMLProgress($progress = 70); PEAR::setErrorHandling(PEAR_ERROR_DIE, "\n%s\n"); @@ -1006,8 +1077,9 @@ //print "\nconnecting to $phost:$pport\n"; } if (!$fp) { bail("download of $url failed: $errstr ($errno)\n"); + // If valid URL but error, no CURL extentions installed } if (empty($proxy)) { $path = $tmp['path']; } else { @@ -1164,11 +1236,12 @@ $ok = mkdir_p(dirname($dir), $mode); } if ($ok) { $ok = @mkdir($dir, $mode); - if (!$ok) { - print "mkdir failed: <$dir>\n"; - } + // This is handled in the caller function (eg. webfrontend or not) + //if (!$ok) { + // print "mkdir failed: <$dir>\n"; + //} } return $ok; } @@ -1216,9 +1289,9 @@ } } /* try it really, is_writable is buggy with openbasedir */ - $fh = fopen(realpath($default) . "/test","wb"); + $fh = @fopen(realpath($default) . "/test","wb"); if ($fh) { $ptmp = $default; return true; } else { @@ -1481,9 +1554,12 @@ .green { color: #006600; } .red { - color: #006600; + color: #ff0000; + } + .grey { + color: #a9a9a9; } span.headline { font-family: verdana,arial,helvetica,sans-serif; @@ -1603,8 +1679,12 @@ form { margin-bottom : 0; } + hr { + text-align: left; + width: 80%; + } --> </style> <meta name="description" content="This is the Web Interface of the PEAR Installer" /> </head> @@ -1639,9 +1719,9 @@ <td align="left" valign="middle" width="20"> </td> <td align="left" valign="middle"> - <span class="Headline">Go-PEAR</span> + <span class="Headline">Go-PEAR Installer</span> </td> </tr> <tr bgcolor="#003300"><td colspan="3"></td></tr> @@ -1661,23 +1741,43 @@ <td bgcolor="#f0f0f0" width="100"> <table width="200" border="0" cellpadding="4" cellspacing="0"> <tr valign="top"> <td style="font-size: 90%" align="left" width="200"> - <br><br> - <img src="<?php echo basename(__FILE__); ?>?action=img&img=smallpear" border="0"> - <a href="<?php echo basename(__FILE__); ?>?step=Welcome&restart=1" <?php if ($page == 'Welcome') echo ' class="green"'; ?>> - Welcome to Go-PEAR - </a><br/> - - <img src="<?php echo basename(__FILE__); ?>?action=img&img=smallpear" border="0"> - <a href="<?php echo basename(__FILE__); ?>?step=config" <?php if ($page == 'config') echo ' class="green"'; ?>> - Configuration - </a><br/> - - <img src="<?php echo basename(__FILE__); ?>?action=img&img=smallpear" border="0"> -<?php if ($page == 'install') echo '<span class="green">'; ?> - Complete installation<br/> -<?php if ($page == 'install') echo '</span>'; ?> + <p><br /> + <?php + $menus = array('Welcome' => 'Welcome to Go-PEAR', + 'config' => 'Configuration', + 'preinstall' => 'Installation', + 'install' => 'Completed'); + $after_current = false; + + // Menu robustness (a bit low, but better then never) + if ($page == 'error') { + $_GET['last'] = $_GET['step']; + $after_current = true; + } elseif (!array_key_exists($page, $menus)) { + $page = 'Welcome'; + } + + foreach ($menus as $menu => $descr) { + print('<img src="'.basename(__FILE__).'?action=img&img=smallpear" border="0">'); + + if (!$after_current) { + $class = ''; + if ($page == $menu) { + $class = 'green'; + } + if (!isSet($_GET['last'])) { $_GET['last'] = $page; } + print('<a href="'.basename(__FILE__).'?step='.$menu.'&last='.$_GET['last'].'" class="'.$class.'">'.$descr.'</a><br />'); + + if ($_GET['last'] == $menu) { + $after_current = true; + } + } else { + print('<span class="grey">'.$descr.'</span><br />'); + } + } + ?> </td> </tr> </table> @@ -1703,9 +1803,9 @@ if (preg_match('/ok$/', $value)) { $value = preg_replace('/(ok)$/', '<span class="green">\1</span>', $value); } if (preg_match('/failed$/', $value)) { - $value = preg_replace('/(failed)$/', '<span style="color: #ff0000">\1</span>', $value); + $value = preg_replace('/(failed)$/', '<span class="red">\1</span>', $value); } if (preg_match('/^install ok:/', $value)) { $value = preg_replace('/^(install ok:)/', '<span class="green">\1</span>', $value); } @@ -1716,16 +1816,18 @@ echo nl2br($value); } elseif ($page == 'Welcome') { ?> <span class="title">Welcome to go-pear <?php echo GO_PEAR_VER; ?>!</span><br/> - <br/> - Go-pear will install the Web Frontend of the PEAR Installer and all the needed <br/> - files. This frontend is your tool for PEAR installation and maintenance.<br/> - <br/> - Go-pear also lets you download and install the PEAR packages bundled<br/> - with PHP: <?php echo implode(', ', $GLOBALS['pfc_packages']); ?>.<br/> - <br/> - <a href="<?php echo basename(__FILE__); ?>?step=config" class="green">Next >></a> + <p> + Go-pear will install Pear, its Web Frontend and all the needed files. This<br/> + frontend is your tool for PEAR installation and maintenance. + </p> + <p> + Go-pear also lets you download and install the following optional PEAR<br/> + packages: <?php echo implode(', ', array_keys($GLOBALS['pfc_packages'])); ?>. + </p> + + <a href="<?php echo basename(__FILE__); ?>?step=config&restart=1" class="green">Next >></a> <?php } elseif ($page == 'config') { if (!empty($GLOBALS['http_proxy'])) { list($proxy_host, $proxy_port) = explode(':', $GLOBALS['http_proxy']); @@ -1733,102 +1835,156 @@ $proxy_host = $proxy_port = ''; } ?> <form action="<?php echo basename(__FILE__);?>?step=install" method="post"> - <span class="title">Configuration</span><br/> - <br/> - HTTP proxy (host:port): - <input type="text" name="proxy[host]" value="<?php echo $proxy_host;?>"> - <input type="text" name="proxy[port]" value="<?php echo $proxy_port;?>" size="6"> - <br/><br/><hr/><br/> - Below is a suggested file layout for your new PEAR installation. <br/> - <br/> - <table border="0"> - <TR> - <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD> - <TD> + <!-- Packages stuff --> + <span class="title">Packages</span> + <p> + The following PEAR packages will be installed. You can select some optional<br /> + packages to be installed by go-pear too:<br /> + </p> + <table border="0" width="80%"> + <tr> + <th> </th><th>Package</th><th width="65%">Description</th> + </tr><tr> + <td>(required)</td><td>PEAR core</td><td>The PEAR core packages.</td> + </tr><tr> + <td>(required)</td><td>Web Installer</td><td>The PEAR Web Installer and its dependencies.</td> + </tr> + <?php + foreach ($GLOBALS['pfc_packages'] as $var => $descr) { + $checked = ''; + if (in_array($var, $GLOBALS['install_optional_packages'])) { $checked = ' checked'; } + printf('<tr><td align="center"><input type="checkbox" name="%s"%s></td><td>%s</td><td>%s</td></tr>', + $var, + $checked, + $var, + $descr); + } + //<input type="checkbox" name="install_pfc" <?php if($GLOBALS['install_pfc']) ?\>> Install those too<br/> + ?> + </table> + <hr /> + + <!-- Configuration stuff --> + <span class="title">Configuration</span> + <p> + Below is a suggested file layout for your new PEAR installation. + </p> + + <!-- + <p> + <table border="0"> + <tr> + <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></td> + <td> <span class="green"> <b>Note:</b> Make sure that PHP has the permission to access the specified<br/> - directories.<br/><br/> + directories. </span> - </TD> - </TR> + </td> + </tr> </table> - <TABLE border="0"> + </p> + --> + + <table border="0" width="80%"> <?php - // Display error messages - if (isset($GLOBALS['www_errors']) && sizeof($GLOBALS['www_errors']) ) { - $www_errors = $GLOBALS['www_errors']; - echo "<tr><td>"; - echo '<span class="red">ERROR(S):</span>'; - echo "</td></tr>"; - foreach ($www_errors as $n => $var) { - echo "<tr><td>"; - echo '<span class="red">'.$GLOBALS['config_desc'][$n].': </span>'; - echo "</td><td>"; - echo '<span class="red">'.$www_errors[$n].'</span>'; - echo "<br>\n"; - echo "</td></tr>\n"; + foreach ($GLOBALS['config_vars'] as $n => $var) { + $error_class = ''; + if (is_array($GLOBALS['config_errors']) && array_key_exists($var, $GLOBALS['config_errors'])) { + // www_error for this var + $error_class = ' class="red"'; } - } - foreach ($GLOBALS['config_vars'] as $n => $var) { - printf('<tr><td>%d. %s</td><td><input type="text" name="config[%s]" value="%s"></td></tr>', + printf('<tr><td>%d. %s</td><td><input type="text" name="config[%s]" value="%s"%s></td></tr>', $n, $GLOBALS['config_desc'][$var], $var, - $GLOBALS[$var]); + $_SESSION['go-pear']['config'][$var], + $error_class); + + // prefix dir, check perm (uses GLOBALS: resolved subvars) + if ($n == 1 && is_dir($GLOBALS[$var]) && !is_writable($GLOBALS[$var])) { + $error = '<em>WARNING!</em> No permission to create subdirectories in this prefix dir. Unless you fix this, the default configuration will not work.'; + if (!WINDOWS) { + $error .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br /> +<tt>chmod 0777 '.$GLOBALS[$var].'</tt></p>'; + } + print('<tr><td colspan="2" class="green">'.$error.'</td></tr>'); + } + + + if (is_array($GLOBALS['config_errors']) && array_key_exists($var, $GLOBALS['config_errors'])) { + // www_error for this var + print('<tr><td colspan="2" class="red">'.$GLOBALS['config_errors'][$var].'</td></tr>'); + } } ?> - </TABLE> - <br/><hr/><br/> - The following PEAR packages are common ones, and can be installed<br/> - by go-pear too: <br/> -<?php echo implode(', ', $GLOBALS['pfc_packages']);?>.<br/> - <input type="checkbox" name="install_pfc" <?php if($GLOBALS['install_pfc']) ?>> Install those too<br/> - <br/><br/> - <table border="0"> - <TR> - <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD> - <TD> - <span class="green"> - <b>Note:</b> Installation might take some time, because go-pear has to download<br/> - all needed files from pear.php.net. Just be patient and wait for the next<br/> - page to load.<br/> - </span> - </TD> - </TR> </table> - <br> - <input type="checkbox" name="BCmode" id="BCmode" checked> Compatibility-Mode for old non-DOM Browsers<br/> + </p> + <hr /> + + <!-- Optional stuff --> + <span class="title">Optional:</span> + + <ul> + <p> + <li />HTTP proxy (host:port) + <input type="text" name="proxy[host]" value="<?php echo $proxy_host;?>"> : <input type="text" name="proxy[port]" value="<?php echo $proxy_port;?>" size="6"> + </p> + + <p> + <li />Compatibility-Mode for old non-DOM Browsers <input type="checkbox" name="BCmode" id="BCmode" checked> <script type="text/javascript"> <!-- if (document.getElementById('BCmode')) { document.getElementById('BCmode').checked = 0; }; // --> </script> + </p> + </ul> <?php if (WINDOWS && phpversion() == '4.1.1') { ?> + <p> <table border="0"> - <TR> - <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD> - <TD> + <tr> + <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></td> + <td> <span style="color: #ff0000"> <b>Warning:</b> Your PHP version (4.1.1) might be imcompatible with go-pear due to a bug<br/> in your PHP binary. If the installation crashes you might want to update your PHP version.</br> </span> - </TD> - </TR> + </td> + </tr> </table> + </p> <?php } ?> - <br/> + <hr /> + <!-- Closing note --> + <p> + <table border="0"> + <tr> + <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></td> + <td> + <span class="green"> + <b>Note:</b> Installation might take some time, because go-pear has to<br/> + download all needed files from pear.php.net. Just be patient and wait for<br/> + the next page to load.<br/> + </span> + </td> + </tr> + </table> + </p> + <input type="submit" value="Install" onClick="javascript: submitButton.value='Downloading and installing ... please wait ...'" name="submitButton"> </form> + <?php } elseif ($page == 'install') { ?> <span class="title">Installation Complete - Summary</span><br/> @@ -2011,8 +2167,9 @@ function displayHTMLInstallationSummary($data = '') { $next = NULL; $prefix = dirname($GLOBALS['webfrontend_file']); + $suffix = basename($GLOBALS['webfrontend_file']); $doc_root = strip_magic_quotes($_SERVER['DOCUMENT_ROOT']); $file_dir = dirname(__FILE__); if ( WINDOWS ) { $prefix = str_replace('/', '\\', strtolower($prefix)); @@ -2020,32 +2177,43 @@ $file_dir = str_replace('/', '\\', strtolower($file_dir)); } if ($doc_root && substr($prefix, 0, strlen($doc_root)) == $doc_root) { - $next = substr($prefix, strlen($doc_root)).'/index.php'; + $next = substr($prefix, strlen($doc_root)).'/'.$suffix; + // need leading / (prefix - docroot = path from docroot) + if (substr($next, 0, 1) != '/') { + $next = '/'.$next; + } } else if ($file_dir && substr($prefix, 0, strlen($file_dir)) == $file_dir) { - $next = substr($prefix, strlen($file_dir)).'/index.php'; + $next = substr($prefix, strlen($file_dir)).'/'.$suffix; + // strip leading / (prefix - file_dir = path from go-pear file) + if (substr($next, 0, 1) == '/') { + $next = substr($next, 1, strlen($next)); + } } if ($data) { echo "<br/>".$data; } ?> - <br/> + <p> + <span class="title">Installation Completed !</span> + </p> + <table border="0"> - <TR> - <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD> - <TD> + <tr> + <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></td> + <td> <span class="green"> <b>Note:</b> To use PEAR without any problems you need to add your<br/> PEAR Installation path (<?php echo $GLOBALS['php_dir']; ?>)<br> to your <a href="http://www.php.net/manual/en/configuration.directives.php#ini.include_path">include_path</a>.<br/> <br/> Using a .htaccess file or directly edit httpd.conf would be working solutions<br/> for Apache running servers, too.<br/> </span> - </TD> - </TR> + </td> + </tr> </table> <br/> For more information about PEAR, see:<br/> <a href="http://pear.php.net/faq.php" target="_new" class="green">PEAR FAQ</a><br/> @@ -2056,18 +2224,18 @@ <?php if ($next === NULL) { ?> <table border="0"> - <TR> - <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD> - <TD> + <tr> + <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></td> + <td> <span style="color: #ff0000"> <b>Warning:</b> Go-PEAR was not able to determine the URL to the newly<br/> installed Web Frontend of the PEAR Installer. Please access it manually.<br/> Since you specified the prefix, you should know how to do so.<br/> </span> - </TD> - </TR> + </td> + </tr> </table> <?php } else { if ($_GET['step'] == 'install-progress') { @@ -2503,4 +2671,6 @@ "; } return true; } + +?>