go-pear 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677
  1. #!/usr/bin/php -q
  2. <?php //; echo; echo "YOU NEED TO RUN THIS SCRIPT WITH PHP!"; echo; echo "Point your webbrowser to it or run: php -q go-pear.php"; echo; exit # -*- PHP -*-
  3. #
  4. # The PEAR installation wizard, both webbased or command line.
  5. #
  6. # Webbased installation:
  7. # 1) Download this file and save it as go-pear.php
  8. # 2) Put go-pear.php on your webserver, where you would put your website
  9. # 3) Open http://yourdomain.example.org/go-pear.php in your browser
  10. # 4) Follow the instructions, done!
  11. #
  12. # Command-line installation (for advanced users):
  13. # 1) Download this file and save it as go-pear.php
  14. # 2) Open a terminal/command prompt and type: php -q go-pear.php
  15. # 3) Follow the instructions, done!
  16. #
  17. # Notes:
  18. # * Get the latest go-pear version from http://pear.php.net/go-pear
  19. # * This installer requires PHP 4.3.0 or newer.
  20. # * On windows, the PHP CLI binary is php.exe, don't forget the -q option if using the CGI binary.
  21. # * The default for the command-line installation is a system-wide configuration file, For a local install use: php -q go-pear.php local
  22. /**
  23. * go-pear is the online PEAR installer: just download it and run it
  24. * (through a browser or command line), it will set up a minimal PEAR
  25. * installation that will be ready for immediate use.
  26. *
  27. * @license http://www.php.net/license/2_02.txt PHP License 2.02
  28. * @version CVS: $Id: go-pear,v 1.119 2009/04/27 20:53:03 cweiske Exp $
  29. * @link http://pear.php.net/package/pearweb_gopear
  30. * @author Tomas V.V.Cox <cox@idecnet.com>
  31. * @author Stig Bakken <ssb@php.net>
  32. * @author Christian Dickmann <dickmann@php.net>
  33. * @author Pierre-Alain Joye <pierre@php.net>
  34. * @author Greg Beaver <cellog@php.net>
  35. * @author Tias Guns <tias@ulyssis.org>
  36. */
  37. $sapi_name = php_sapi_name();
  38. $safe_mode = (bool)ini_get('safe_mode');
  39. if (!$safe_mode) {
  40. set_time_limit(0);
  41. }
  42. @ob_end_clean();
  43. ob_implicit_flush(true);
  44. define('WEBINSTALLER', ($sapi_name != 'cli' && !(substr($sapi_name,0,3)=='cgi' && !isset($_SERVER['GATEWAY_INTERFACE']))));
  45. ini_set('track_errors', true);
  46. ini_set('html_errors', WEBINSTALLER);
  47. ini_set('magic_quotes_runtime', false);
  48. error_reporting( E_ALL & ~E_NOTICE);
  49. define('WINDOWS', (substr(PHP_OS, 0, 3) == 'WIN'));
  50. define('GO_PEAR_VER', '1.1.2');
  51. define('WIN32GUI', !WEBINSTALLER && WINDOWS && $sapi_name=='cli' && which('cscript'));
  52. /*
  53. * See bug #23069
  54. */
  55. if ( WEBINSTALLER && WINDOWS ) {
  56. $php_sapi_name = win32DetectPHPSAPI();
  57. if($php_sapi_name=='cgi'){
  58. $msg = nl2br("
  59. Sorry! The PEAR installer actually does not work on Windows platform
  60. using CGI and Apache. Please install the module SAPI (see
  61. http://www.php.net/manual/en/install.apache.php for the instructions) or
  62. use the CLI (cli\php.exe) in the console.
  63. ");
  64. displayHTML('error', $msg);
  65. }
  66. }
  67. if (WEBINSTALLER && isset($_GET['action']) && $_GET['action'] == 'img' && isset($_GET['img'])) {
  68. switch ($_GET['img'])
  69. {
  70. case 'note':
  71. case 'pearlogo':
  72. case 'smallpear':
  73. showImage($_GET['img']);
  74. exit;
  75. default:
  76. exit;
  77. };
  78. }
  79. // Check if PHP version is sufficient
  80. if (function_exists("version_compare") && version_compare(phpversion(), "4.3.0",'<')) {
  81. die("Sorry! Your PHP version is too old. PEAR and this script requires at
  82. least PHP 4.3.0 for stable operation.
  83. It may be that you have a newer version of PHP installed in your web
  84. server, but an older version installed as the 'php' command. In this
  85. case, you need to rebuilt PHP from source.
  86. If your source is 4.3.x or newer, just make sure you don't run
  87. 'configure' with --disable-cli, rebuilt and copy sapi/cli/php.
  88. Please upgrade PHP to a newer version, and try again. See you then.
  89. ");
  90. }
  91. $gopear_bundle_dir = dirname(__FILE__).'/go-pear-bundle';
  92. $bootstrap_files = array(
  93. 'PEAR.php' => 'http://cvs.php.net/viewvc.cgi/pear-core/PEAR.php?view=co&pathrev=PEAR_1_4',
  94. 'Archive/Tar.php' => 'http://cvs.php.net/viewvc.cgi/pear/Archive_Tar/Archive/Tar.php?view=co&pathrev=RELEASE_1_3_2',
  95. 'Console/Getopt.php' => 'http://cvs.php.net/viewvc.cgi/pear-core/Console/Getopt.php?view=co&pathrev=PEAR_1_4',
  96. );
  97. $bootstrap_pkgs = array( // uses URL like http://pear.php.net/get/%s
  98. 'PEAR',
  99. 'Structures_Graph'
  100. );
  101. $installer_packages = array(
  102. 'PEAR',
  103. 'Structures_Graph-stable',
  104. 'Archive_Tar-stable',
  105. 'Console_Getopt-stable',
  106. );
  107. $pfc_packages = array(
  108. 'PEAR_Frontend_Web-beta' => 'Webbased PEAR Installer',
  109. 'PEAR_Frontend_Gtk2' => 'Graphical PEAR installer based on PHP-Gtk2',
  110. 'MDB2' => 'database abstraction layer.',
  111. );
  112. $config_desc = array(
  113. 'prefix' => 'Installation prefix ($prefix)',
  114. 'temp_dir' => 'Temporary files directory',
  115. 'bin_dir' => 'Binaries directory',
  116. 'php_dir' => 'PHP code directory ($php_dir)',
  117. 'doc_dir' => 'Documentation base directory',
  118. 'data_dir' => 'Data base directory',
  119. 'test_dir' => 'Tests base directory',
  120. );
  121. if(!WEBINSTALLER && WINDOWS){
  122. $config_desc['php_bin'] = 'php.exe path';
  123. }
  124. if (WEBINSTALLER) {
  125. $config_desc['cache_dir'] = 'PEAR Installer cache directory';
  126. $config_desc['cache_ttl'] = 'Cache TimeToLive';
  127. $config_desc['webfrontend_file'] = 'Filename of WebFrontend';
  128. $config_desc['php_bin'] = "php.exe path, optional (CLI command tools)";
  129. }
  130. if (my_env('HTTP_PROXY')) {
  131. $http_proxy = my_env('HTTP_PROXY');
  132. } elseif (my_env('http_proxy')) {
  133. $http_proxy = my_env('http_proxy');
  134. } else {
  135. $http_proxy = '';
  136. }
  137. register_shutdown_function('bail');
  138. detect_install_dirs();
  139. if (WEBINSTALLER) {
  140. @session_start();
  141. // If welcome, just welcome
  142. if (!isset($_GET['step'])) {
  143. $_GET['step'] = 'Welcome';
  144. /* clean up old sessions datas */
  145. session_destroy();
  146. }
  147. if ($_GET['step'] == 'Welcome') {
  148. displayHTML('Welcome');
  149. exit();
  150. }
  151. if (!isset($_SESSION['go-pear']) || isset($_GET['restart'])) {
  152. $_SESSION['go-pear'] = array(
  153. 'http_proxy' => $http_proxy,
  154. 'config' => array(
  155. 'prefix' => dirname(__FILE__),
  156. 'bin_dir' => $bin_dir,
  157. 'php_bin' => $php_bin,
  158. 'php_dir' => '$prefix/PEAR',
  159. 'doc_dir' => $doc_dir,
  160. 'data_dir' => $data_dir,
  161. 'test_dir' => $test_dir,
  162. 'temp_dir' => '$prefix/temp',
  163. 'cache_dir' => '$php_dir/cache',
  164. 'cache_ttl' => 300,
  165. 'webfrontend_file' => '$prefix/index.php',
  166. ),
  167. 'install_pfc' => true,
  168. 'install_optional_packages' => array(),
  169. 'DHTML' => true,
  170. );
  171. }
  172. // save submited values
  173. if ($_GET['step'] == 'install') {
  174. $_SESSION['go-pear']['http_proxy'] = strip_magic_quotes($_POST['proxy']['host']).':'.strip_magic_quotes($_POST['proxy']['port']);
  175. if ($_SESSION['go-pear']['http_proxy'] == ':') {
  176. $_SESSION['go-pear']['http_proxy'] = '';
  177. };
  178. $config_errors = array();
  179. foreach($_POST['config'] as $key => $value) {
  180. $_POST['config'][$key] = strip_magic_quotes($value);
  181. if ($key != 'cache_ttl' && $key != 'php_bin') {
  182. if ( empty($_POST['config'][$key]) ) {
  183. $config_errors[$key] = 'Please fill this path, you can use $prefix, $php_dir or a full path.';
  184. }
  185. }
  186. }
  187. if( sizeof($config_errors)>0){
  188. $_GET['step'] = 'config';
  189. }
  190. $_SESSION['go-pear']['config'] = $_POST['config'];
  191. $_SESSION['go-pear']['install_pfc'] = (isset($_POST['install_pfc']) && $_POST['install_pfc'] == 'on');
  192. // webinstaller allows to choose pfc packages individually
  193. foreach ($pfc_packages as $key => $value) {
  194. $pos = array_search($key, $_SESSION['go-pear']['install_optional_packages']);
  195. if (isset($_POST[$key]) && $_POST[$key] == 'on' && $pos === false) {
  196. $_SESSION['go-pear']['install_optional_packages'][] = $key;
  197. }
  198. if (!isset($_POST[$key]) && $pos !== false) {
  199. unset($_SESSION['go-pear']['install_optional_packages'][$pos]);
  200. }
  201. }
  202. $_SESSION['go-pear']['DHTML'] = isset($_POST['BCmode']) ? false : true;
  203. }
  204. // export session values
  205. $http_proxy = $_SESSION['go-pear']['http_proxy'];
  206. $GLOBALS['config_vars'] = array_keys($config_desc);
  207. array_unshift($GLOBALS['config_vars'], '');
  208. unset($GLOBALS['config_vars'][0]); // make indices run from 1...
  209. foreach($_SESSION['go-pear']['config'] as $var => $value) {
  210. $$var = $value;
  211. }
  212. $install_pfc = $_SESSION['go-pear']['install_pfc'];
  213. $install_optional_packages = $_SESSION['go-pear']['install_optional_packages'];
  214. if ($_GET['step'] == 'config') {
  215. displayHTML('config');
  216. exit();
  217. }
  218. // Anything past this step has something to do with the installation
  219. }
  220. if (!WEBINSTALLER) {
  221. $tty = WINDOWS ? @fopen('\con', 'r') : @fopen('/dev/tty', 'r');
  222. if (!$tty) {
  223. $tty = fopen('php://stdin', 'r');
  224. }
  225. $local = isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'local';
  226. if ($local) {
  227. $local = "
  228. Running in local install mode
  229. ";
  230. } elseif (WINDOWS) {
  231. $local = "
  232. Use 'php " . $_SERVER['argv'][0] . " local' to install a local copy of PEAR.
  233. ";
  234. }
  235. print "Welcome to go-pear!
  236. Go-pear will install the 'pear' command and all the files needed by
  237. it. This command is your tool for PEAR installation and maintenance.
  238. $local
  239. Go-pear also lets you download and install the following optional PEAR
  240. packages: " . implode(', ', array_keys($pfc_packages)) . ".
  241. If you wish to abort, press Control-C now, or press Enter to continue: ";
  242. fgets($tty, 1024);
  243. print "\n";
  244. print "HTTP proxy (http://user:password@proxy.myhost.com:port), or Enter for none:";
  245. if (!empty($http_proxy)) {
  246. print " [$http_proxy]";
  247. }
  248. print ": ";
  249. $tmp = trim(fgets($tty, 1024));
  250. if (!empty($tmp)) {
  251. $http_proxy = $tmp;
  252. }
  253. }
  254. $origpwd = getcwd();
  255. $config_vars = array_keys($config_desc);
  256. // make indices run from 1...
  257. array_unshift($config_vars, "");
  258. unset($config_vars[0]);
  259. reset($config_vars);
  260. $desclen = max(array_map('strlen', $config_desc));
  261. $descfmt = "%-{$desclen}s";
  262. $first = key($config_vars);
  263. end($config_vars);
  264. $last = key($config_vars);
  265. $progress = 0;
  266. /*
  267. * Checks PHP SAPI version under windows/CLI
  268. */
  269. if( WINDOWS && !WEBINSTALLER && $php_bin=='') {
  270. print "
  271. We do not find any php.exe, please select the php.exe folder (CLI is
  272. recommanded, usually in c:\php\cli\php.exe)
  273. ";
  274. $php_bin_set = false;
  275. } elseif ( WINDOWS && !WEBINSTALLER && strlen($php_bin) ) {
  276. $php_bin_sapi = win32DetectPHPSAPI();
  277. $php_bin_set = true;
  278. switch($php_bin_sapi){
  279. case 'cli':
  280. break;
  281. case 'cgi':
  282. print "
  283. *NOTICE*
  284. We found php.exe under $php_bin, it uses a $php_bin_sapi SAPI. PEAR commandline
  285. tool works well with it, if you have a CLI php.exe available, we
  286. recommand to use it.
  287. ";
  288. break;
  289. default:
  290. print "
  291. *WARNING*
  292. We found php.exe under $php_bin, it uses an unknown SAPI. PEAR commandline
  293. tool has not been tested with it, if you have a CLI (or CGI) php.exe available,
  294. we strongly recommand to use it.
  295. ";
  296. break;
  297. }
  298. }
  299. while (!WEBINSTALLER) {
  300. print "
  301. Below is a suggested file layout for your new PEAR installation. To
  302. change individual locations, type the number in front of the
  303. directory. Type 'all' to change all of them or simply press Enter to
  304. accept these locations.
  305. ";
  306. foreach ($config_vars as $n => $var) {
  307. printf("%2d. $descfmt : %s\n", $n, $config_desc[$var], $$var);
  308. }
  309. print "\n$first-$last, 'all' or Enter to continue: ";
  310. $tmp = trim(fgets($tty, 1024));
  311. if ( empty($tmp) ) {
  312. if( WINDOWS && !$php_bin_set ){
  313. echo "**ERROR**
  314. Please, enter the php.exe path.
  315. ";
  316. } else {
  317. break;
  318. }
  319. }
  320. if (isset($config_vars[(int)$tmp])) {
  321. $var = $config_vars[(int)$tmp];
  322. $desc = $config_desc[$var];
  323. $current = $$var;
  324. if(WIN32GUI){
  325. $tmp = win32BrowseForFolder("$desc [$current] :");
  326. } else {
  327. print "$desc [$current] : ";
  328. $tmp = trim(fgets($tty, 1024));
  329. }
  330. $old = $$var;
  331. if(WINDOWS && $var=='php_bin' ){
  332. if(file_exists($tmp.DIRECTORY_SEPARATOR.'php.exe')){
  333. $tmp = $tmp.DIRECTORY_SEPARATOR.'php.exe';
  334. $php_bin_sapi = win32DetectPHPSAPI();
  335. if($php_bin_sapi=='cgi'){
  336. print "
  337. ******************************************************************************
  338. NOTICE! We found php.exe under $php_bin, it uses a $php_bin_sapi SAPI.
  339. PEAR commandline tool works well with it.
  340. If you have a CLI php.exe available, we recommand to use it.
  341. ";
  342. } elseif ($php_bin_sapi=='unknown') {
  343. print "
  344. ******************************************************************************
  345. WARNING! We found php.exe under $php_bin, it uses an $php_bin_sapi SAPI.
  346. PEAR commandline tool has not been tested with it.
  347. If you have a CLI (or CGI) php.exe available, we strongly recommand to use it.
  348. ";
  349. }
  350. echo "php.exe (sapi: $php_bin_sapi) found.\n\n";
  351. $php_bin_set = true;
  352. } else {
  353. echo "**ERROR**: no php.exe found in this folder.\n";
  354. $tmp='';
  355. }
  356. }
  357. if (!empty($tmp) ) {
  358. $$var = parse_dirname($tmp);
  359. }
  360. } elseif ($tmp == 'all') {
  361. foreach ($config_vars as $n => $var) {
  362. $desc = $config_desc[$var];
  363. $current = $$var;
  364. print "$desc [$current] : ";
  365. $tmp = trim(fgets($tty, 1024));
  366. if (!empty($tmp)) {
  367. $$var = $tmp;
  368. }
  369. }
  370. }
  371. }
  372. ####
  373. # Installation stuff
  374. ####
  375. // expand all subvars in the config vars
  376. foreach ($config_vars as $n => $var) {
  377. for ($m = 1; $m <= count($config_vars); $m++) {
  378. $var2 = $config_vars[$m];
  379. $$var = str_replace('$'.$var2, $$var2, $$var);
  380. }
  381. $$var = parse_dirname($$var);
  382. }
  383. // temp dir stuff (separate for windows bugs)
  384. if (!empty($temp_dir)) {
  385. $_found = temp_dir($temp_dir);
  386. } else {
  387. $_found = temp_dir();
  388. }
  389. if (!$_found) {
  390. if (!WEBINSTALLER) {
  391. print "
  392. ******************************************************************************
  393. FATAL ERROR! We cannot initialize the temp directory. Please be sure to give
  394. full write access to this directory and the install directory.
  395. ";
  396. if (!empty($temp_dir)) {
  397. print "'$temp_dir' was given.";
  398. }
  399. exit();
  400. } else { // WEBINSTALLER
  401. if (!is_dir($temp_dir)) {
  402. $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.';
  403. if (!WINDOWS) {
  404. $config_errors['temp_dir'] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
  405. <tt>mkdir '.dirname($temp_dir).' && chmod 0777 '.dirname($temp_dir).'</tt></p>';
  406. }
  407. } else { // is_dir(temp_dir)
  408. $config_errors['temp_dir'] = 'FATAL ERROR! This directory exists, but we have no write permission in it.';
  409. if (!WINDOWS) {
  410. $config_errors['temp_dir'] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
  411. <tt>chmod 0777 '.$temp_dir.'</tt></p>';
  412. }
  413. }
  414. }
  415. }
  416. if (@is_dir($ptmp)) {
  417. chdir($ptmp);
  418. }
  419. // check every dir, existence and permissions
  420. foreach ($config_vars as $var) {
  421. if (!preg_match('/_dir$/', $var) || $var == 'temp_dir') {
  422. continue;
  423. }
  424. $dir = $$var;
  425. if (!@is_dir($dir)) {
  426. if (!mkdir_p($dir)) {
  427. if (!WEBINSTALLER) {
  428. $root = WINDOWS ? 'administrator' : 'root';
  429. bail("Unable to create {$config_desc[$var]} $dir.
  430. Run this script as $root or pick another location.\n");
  431. } else { // WEBINSTALLER
  432. $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.';
  433. if (!WINDOWS) {
  434. $config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
  435. <tt>mkdir '.dirname($dir).' && chmod 0777 '.dirname($dir).'</tt></p>';
  436. }
  437. }
  438. }
  439. }
  440. if (WEBINSTALLER && @is_dir($dir) && !is_writable($dir)) {
  441. $config_errors[$var] = 'ERROR! This directory exists, but we have no write permission in it.';
  442. if (!WINDOWS) {
  443. $config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
  444. <tt>chmod 0777 '.$dir.'</tt></p>';
  445. }
  446. }
  447. }
  448. // check every file, existence and permissions
  449. foreach ($config_vars as $var) {
  450. if (!preg_match('/_file$/', $var)) {
  451. continue;
  452. }
  453. $file = $$var;
  454. $dir = dirname($file);
  455. if (!file_exists($file) && !is_writable($dir)) {
  456. if (!WEBINSTALLER) {
  457. $root = WINDOWS ? 'administrator' : 'root';
  458. bail("Unable to create {$config_desc[$var]} $file.
  459. Run this script as $root or pick another location.\n");
  460. } else { // WEBINSTALLER
  461. $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.';
  462. if (!WINDOWS) {
  463. $config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
  464. <tt>chmod 0777 '.$dir.'</tt></p>';
  465. }
  466. }
  467. } elseif (WEBINSTALLER && file_exists($file) && !is_writable($file)) {
  468. $config_errors[$var] = 'ERROR! This file exists, but we have no write permission on it.';
  469. if (!WINDOWS) {
  470. $config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
  471. <tt>chmod 0777 '.$file.'</tt></p>';
  472. }
  473. }
  474. }
  475. if (WEBINSTALLER) {
  476. if ( isset($config_errors) && sizeof($config_errors) ) {
  477. displayHTML('config');
  478. exit();
  479. } else {
  480. if (isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'] == true && $_GET['step'] == 'install') {
  481. $_GET['step'] = 'preinstall';
  482. }
  483. if ($_GET['step'] != 'install' && $_GET['step'] != 'install-progress') {
  484. displayHTML($_GET['step']);
  485. exit;
  486. }
  487. if ($_GET['step'] == 'install-progress') {
  488. displayHTMLHeader();
  489. echo "Starting installation ...<br/>";
  490. }
  491. ob_start();
  492. }
  493. }
  494. if (!WEBINSTALLER) {
  495. $msg = "The following PEAR packages are bundled with PHP: " .
  496. implode(', ', array_keys($pfc_packages));
  497. print "\n" . wordwrap($msg, 75) . ".\n";
  498. print "Would you like to install these as well? [Y/n] : ";
  499. $install_pfc = !stristr(fgets($tty, 1024), "n");
  500. $install_optional_packages = array();
  501. print "\n";
  502. }
  503. ####
  504. # Download
  505. ####
  506. if (function_exists('set_include_path')) {
  507. set_include_path($ptmp);
  508. } else {
  509. ini_set('include_path', $ptmp);
  510. }
  511. if (!extension_loaded('zlib') && !WEBINSTALLER) { // In Web context we could be in multithread env which makes dl() end up with a fatal error.
  512. if (WINDOWS) {
  513. @dl('php_zlib.dll');
  514. } elseif (PHP_OS == 'HP-UX') {
  515. @dl('zlib.sl');
  516. } elseif (PHP_OS == 'AIX') {
  517. @dl('zlib.a');
  518. } else {
  519. @dl('zlib.so');
  520. }
  521. }
  522. if (!extension_loaded('zlib')) {
  523. $urltemplate = 'http://pear.php.net/get/%s?uncompress=yes';
  524. $have_gzip = null;
  525. } else {
  526. $urltemplate = 'http://pear.php.net/get/%s';
  527. $have_gzip = true;
  528. }
  529. print "Loading zlib: ".($have_gzip ? 'ok' : 'failed')."\n";
  530. if (!$have_gzip) {
  531. print "Downloading uncompressed packages\n";
  532. };
  533. if ($install_pfc) {
  534. $to_install = array_merge($installer_packages, array_keys($pfc_packages));
  535. } else {
  536. $to_install = $installer_packages;
  537. // webinstaller allows to choose pfc packages individually
  538. foreach ($pfc_packages as $pkg => $desc) {
  539. if (in_array($pkg, $install_optional_packages)) {
  540. array_push($to_install, $pkg);
  541. }
  542. }
  543. }
  544. // gopear_bundle usage
  545. $local_dir = array();
  546. if (file_exists($gopear_bundle_dir) || is_dir($gopear_bundle_dir)) {
  547. $dh = @opendir($gopear_bundle_dir);
  548. while($file = @readdir($dh)) {
  549. if ($file == '.' || $file == '..' || !is_file($gopear_bundle_dir.'/'.$file)) {
  550. continue;
  551. }
  552. $_pos = strpos($file, '-');
  553. if ($_pos === false) {
  554. $local_dir[$file] = $file;
  555. } else {
  556. $local_dir[substr($file, 0, $_pos)] = $file;
  557. }
  558. }
  559. closedir($dh);
  560. unset($dh, $file, $_pos);
  561. }
  562. print "\n".'Bootstrapping Installer...................'."\n";
  563. displayHTMLProgress($progress = 5);
  564. // Bootstrap needed ?
  565. $nobootstrap = false;
  566. if (is_dir($php_dir)) {
  567. $nobootstrap = true;
  568. foreach ($bootstrap_files as $file => $url) {
  569. $nobootstrap &= is_file($php_dir.'/'.$file);
  570. }
  571. }
  572. if ($nobootstrap) {
  573. print('Using previously install ... ');
  574. if (function_exists('set_include_path')) {
  575. set_include_path($php_dir);
  576. } else {
  577. ini_set('include_path', $php_dir);
  578. }
  579. include_once 'PEAR.php';
  580. print "ok\n";
  581. } else {
  582. foreach($bootstrap_files as $name => $url) {
  583. $file = basename($name);
  584. $dir = dirname($name);
  585. print 'Bootstrapping '.$name.'............';
  586. displayHTMLProgress($progress += round(14 / count($bootstrap_files)));
  587. if ($dir != '' && $dir != '.') {
  588. mkdir($dir, 0700);
  589. }
  590. if (in_array($file, $local_dir)) {
  591. copy($gopear_bundle_dir.'/'.$file, $name);
  592. echo '(local) ';
  593. } else {
  594. download_url($url, $name, $http_proxy);
  595. echo '(remote) ';
  596. }
  597. include_once $name;
  598. print "ok\n";
  599. }
  600. }
  601. unset($nobootstrap, $file, $url, $name, $dir);
  602. PEAR::setErrorHandling(PEAR_ERROR_DIE, "\n%s\n");
  603. print "\n".'Extracting installer..................'."\n";
  604. displayHTMLProgress($progress = 20);
  605. // Extract needed ?
  606. $noextract = false;
  607. if (is_dir($php_dir)) {
  608. $noextract = @include_once 'PEAR/Registry.php';
  609. if ($noextract) {
  610. $registry = new PEAR_Registry($php_dir);
  611. foreach ($bootstrap_pkgs as $pkg) {
  612. $noextract &= $registry->packageExists($pkg);
  613. }
  614. }
  615. }
  616. if ($noextract) {
  617. print('Using previously installed installer ... ');
  618. print "ok\n";
  619. } else {
  620. $bootstrap_pkgs_tarballs = array();
  621. foreach ($bootstrap_pkgs as $pkg) {
  622. $tarball = null;
  623. if (isset($local_dir[$pkg])) {
  624. echo str_pad("Using local package: $pkg", max(38,21+strlen($pkg)+4), '.');
  625. copy($gopear_bundle_dir.'/'.$local_dir[$pkg], $local_dir[$pkg]);
  626. $tarball = $local_dir[$pkg];
  627. } else {
  628. print str_pad("Downloading package: $pkg", max(38,21+strlen($pkg)+4), '.');
  629. $url = sprintf($urltemplate, $pkg);
  630. $pkg = str_replace('-stable', '', $pkg);
  631. $tarball = download_url($url, null, $http_proxy);
  632. }
  633. displayHTMLProgress($progress += round(19 / count($bootstrap_pkgs)));
  634. $fullpkg = substr($tarball, 0, strrpos($tarball, '.'));
  635. $tar = &new Archive_Tar($tarball, $have_gzip);
  636. if (!$tar->extractModify($ptmp, $fullpkg)) {
  637. bail("Extraction for $fullpkg failed!\n");
  638. }
  639. $bootstrap_pkgs_tarballs[$pkg] = $tarball;
  640. print "ok\n";
  641. }
  642. }
  643. unset($noextract, $registry, $pkg, $tarball, $url, $fullpkg, $tar);
  644. print "\n".'Preparing installer..................'."\n";
  645. displayHTMLProgress($progress = 40);
  646. // Default for sig_bin
  647. putenv('PHP_PEAR_SIG_BIN=""');
  648. // Default for sig_keydir
  649. putenv('PHP_PEAR_SIG_KEYDIR=""');
  650. putenv('PHP_PEAR_DOWNLOAD_DIR=' . $temp_dir . '/download');
  651. putenv('PHP_PEAR_TEMP_DIR=' . $temp_dir);
  652. include_once "PEAR/Config.php";
  653. include_once "PEAR/Command.php";
  654. include_once "PEAR/Registry.php";
  655. if (WEBINSTALLER || isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'local') {
  656. $config = &PEAR_Config::singleton($prefix."/pear.conf", '');
  657. } else {
  658. $config = &PEAR_Config::singleton();
  659. }
  660. $config->set('preferred_state', 'stable');
  661. foreach ($config_vars as $var) {
  662. if (isset($$var) && $$var != '') {
  663. $config->set($var, $$var);
  664. }
  665. }
  666. $config->set('download_dir', $temp_dir . '/download');
  667. $config->set('temp_dir', $temp_dir);
  668. $config->set('http_proxy', $http_proxy);
  669. $config->store();
  670. $registry = new PEAR_Registry($php_dir);
  671. PEAR_Command::setFrontendType('CLI');
  672. PEAR::staticPushErrorHandling(PEAR_ERROR_DIE); //fail silently
  673. $ch_cmd = &PEAR_Command::factory('update-channels', $config);
  674. $ch_cmd->run('update-channels', $options, array());
  675. PEAR::staticPopErrorHandling(); // reset error handling
  676. unset($ch_cmd);
  677. print "\n".'Installing selected packages..................'."\n";
  678. displayHTMLProgress($progress = 45);
  679. $install = &PEAR_Command::factory('install', $config);
  680. foreach ($to_install as $pkg) {
  681. $pkg_basename = substr($pkg, 0, strpos($pkg, '-'));
  682. if (in_array($pkg, $installer_packages)) {
  683. $options = array('nodeps' => true);
  684. } else {
  685. $options = array('onlyreqdeps' => true);
  686. }
  687. if ($registry->packageExists($pkg) || $registry->packageExists($pkg_basename)) {
  688. print(str_pad("Package: $pkg", max(50,9+strlen($pkg)+4), '.').' already installed ... ok'."\n");
  689. displayHTMLProgress($progress += round(50 / count($to_install)));
  690. continue;
  691. }
  692. $pkg_basename = substr($pkg, 0, strpos($pkg, '-'));
  693. if (in_array($pkg_basename, $bootstrap_pkgs)) {
  694. print(str_pad("Installing bootstrap package: $pkg_basename", max(50,30+strlen($pkg_basename)+4), '.')."...");
  695. displayHTMLProgress($progress += round(25 / count($to_install)));
  696. $install->run('install', $options, array($bootstrap_pkgs_tarballs[$pkg_basename]));
  697. } elseif (isset($local_dir[$pkg_basename])) {
  698. print(str_pad("Installing local package: $pkg", max(50,26+strlen($pkg)+4), '.')."...");
  699. displayHTMLProgress($progress += round(25 / count($to_install)));
  700. $install->run('install', $options, array($gopear_bundle_dir.'/'.$local_dir[$pkg_basename]));
  701. } else { // no local copy
  702. print(str_pad("Downloading and installing package: $pkg", max(50,36+strlen($pkg)+4), '.')."...");
  703. displayHTMLProgress($progress += round(25 / count($to_install)));
  704. $install->run('install', $options, array($pkg));
  705. }
  706. displayHTMLProgress($progress += round(25 / count($to_install)));
  707. }
  708. unset($pkg, $pkg_basename, $options, $bootstrap_pkgs_tarballs);
  709. /* TODO: Memory exhaustion in webinstaller : / (8Mb)
  710. print "\n".'Making sure every package is at the latest version........';
  711. $install->run('upgrade-all', array('soft' => true), array());
  712. print "ok\n";
  713. */
  714. unset($config, $registry, $install);
  715. displayHTMLProgress($progress = 99);
  716. // Base installation finished
  717. ini_restore("include_path");
  718. if (!WEBINSTALLER) {
  719. $sep = WINDOWS ? ';' : ':';
  720. $include_path = explode($sep, ini_get('include_path'));
  721. if (WINDOWS) {
  722. $found = false;
  723. $t = strtolower($php_dir);
  724. foreach($include_path as $path) {
  725. if ($t==strtolower($path)) {
  726. $found = true;
  727. break;
  728. }
  729. }
  730. } else {
  731. $found = in_array($php_dir, $include_path);
  732. }
  733. if (!$found) {
  734. print "
  735. ******************************************************************************
  736. WARNING! The include_path defined in the currently used php.ini does not
  737. contain the PEAR PHP directory you just specified:
  738. <$php_dir>
  739. If the specified directory is also not in the include_path used by
  740. your scripts, you will have problems getting any PEAR packages working.
  741. ";
  742. if ( $php_ini = getPhpiniPath() ) {
  743. print "\n\nWould you like to alter php.ini <$php_ini>? [Y/n] : ";
  744. $alter_phpini = !stristr(fgets($tty, 1024), "n");
  745. if( $alter_phpini ) {
  746. alterPhpIni($php_ini);
  747. } else {
  748. if (WINDOWS) {
  749. print "
  750. Please look over your php.ini file to make sure
  751. $php_dir is in your include_path.";
  752. } else {
  753. print "
  754. I will add a workaround for this in the 'pear' command to make sure
  755. the installer works, but please look over your php.ini or Apache
  756. configuration to make sure $php_dir is in your include_path.
  757. ";
  758. }
  759. }
  760. }
  761. print "
  762. Current include path : ".ini_get('include_path')."
  763. Configured directory : $php_dir
  764. Currently used php.ini (guess) : $php_ini
  765. ";
  766. print "Press Enter to continue: ";
  767. fgets($tty, 1024);
  768. }
  769. $pear_cmd = $bin_dir . DIRECTORY_SEPARATOR . 'pear';
  770. $pear_cmd = WINDOWS ? strtolower($pear_cmd).'.bat' : $pear_cmd;
  771. // check that the installed pear and the one in tha path are the same (if any)
  772. $pear_old = which(WINDOWS ? 'pear.bat' : 'pear', $bin_dir);
  773. if ($pear_old && ($pear_old != $pear_cmd)) {
  774. // check if it is a link or symlink
  775. $islink = WINDOWS ? false : is_link($pear_old) ;
  776. if ($islink && readlink($pear_old) != $pear_cmd) {
  777. print "\n** WARNING! The link $pear_old does not point to the " .
  778. "installed $pear_cmd\n";
  779. } elseif (is_writable($pear_old) && !is_dir($pear_old)) {
  780. rename($pear_old, "{$pear_old}_old");
  781. print "\n** WARNING! Backed up old pear to {$pear_old}_old\n";
  782. } else {
  783. print "\n** WARNING! Old version found at $pear_old, please remove it or ".
  784. "be sure to use the new $pear_cmd command\n";
  785. }
  786. }
  787. print "\nThe 'pear' command is now at your service at $pear_cmd\n";
  788. // Alert the user if the pear cmd is not in PATH
  789. $old_dir = $pear_old ? dirname($pear_old) : false;
  790. if (!which('pear', $old_dir)) {
  791. print "
  792. ** The 'pear' command is not currently in your PATH, so you need to
  793. ** use '$pear_cmd' until you have added
  794. ** '$bin_dir' to your PATH environment variable.
  795. ";
  796. print "Run it without parameters to see the available actions, try 'pear list'
  797. to see what packages are installed, or 'pear help' for help.
  798. For more information about PEAR, see:
  799. http://pear.php.net/faq.php
  800. http://pear.php.net/manual/
  801. Thanks for using go-pear!
  802. ";
  803. }
  804. }
  805. if (WEBINSTALLER) {
  806. print "\n".'Writing WebFrontend file ... ';
  807. @unlink($webfrontend_file); //Delete old one
  808. copy ( $doc_dir.DIRECTORY_SEPARATOR.
  809. 'PEAR_Frontend_Web'.DIRECTORY_SEPARATOR.
  810. 'docs'.DIRECTORY_SEPARATOR.
  811. 'index.php.txt',
  812. $webfrontend_file
  813. );
  814. print "ok\n";
  815. if ($_GET['step'] == 'install-progress') {
  816. displayHTMLProgress($progress = 100);
  817. ob_end_clean();
  818. displayHTMLInstallationSummary();
  819. displayHTMLFooter();
  820. } else {
  821. $out = ob_get_contents();
  822. $out = explode("\n", $out);
  823. foreach($out as $line => $value) {
  824. if (preg_match('/ok$/', $value)) {
  825. $value = preg_replace('/(ok)$/', '<span class="green">\1</span>', $value);
  826. };
  827. if (preg_match('/^install ok:/', $value)) {
  828. $value = preg_replace('/^(install ok:)/', '<span class="green">\1</span>', $value);
  829. };
  830. if (preg_match('/^Warning:/', $value)) {
  831. $value = '<span style="color: #ff0000">'.$value.'</span>';
  832. };
  833. $out[$line] = $value;
  834. };
  835. $out = nl2br(implode("\n",$out));
  836. ob_end_clean();
  837. displayHTML('install', $out);
  838. }
  839. // Little hack, this will be fixed in PEAR later
  840. if ( WINDOWS ) {
  841. clearstatcache();
  842. @unlink($bin_dir.DIRECTORY_SEPARATOR.'.tmppear');
  843. }
  844. exit;
  845. }
  846. // Little hack, this will be fixed in PEAR later
  847. if ( WINDOWS ) {
  848. clearstatcache();
  849. @unlink($bin_dir.DIRECTORY_SEPARATOR.'.tmppear');
  850. }
  851. if (WINDOWS && !WEBINSTALLER) {
  852. win32CreateRegEnv();
  853. }
  854. // Set of functions following
  855. /**
  856. * Parse the given dirname
  857. * eg. expands '~' etc
  858. *
  859. * @param string $dir directory, from input
  860. * @return string parsed directory
  861. */
  862. function parse_dirname($dir)
  863. {
  864. if (!isset($_ENV['HOME'])) {
  865. if (strpos($dir, '~') === 0) {
  866. if (WEBINSTALLER) {
  867. die('<p><em>Can\'t use the \'~\' symbol for homedir substitution, write the directory out in full.</em></p>');
  868. } else {
  869. die('Can\'t use the \'~\' symbol for homedir substitution, write the directory out in full.');
  870. }
  871. }
  872. return $dir;
  873. }
  874. $home_root = $_ENV['HOME'];
  875. // first strip last slash, if available
  876. if (substr($home_root, -1) == DIRECTORY_SEPARATOR) {
  877. $home_root = substr($home_root, 0, -1);
  878. }
  879. if (strpos($dir, '~/') === 0) {
  880. // eg ~/ = /home/tias/
  881. $dir = substr_replace($dir, $home_root, 0, 1);
  882. } elseif (strpos($dir, '~') === 0) {
  883. // eg ~tias/ = /home/tias/
  884. // then delete user-dir
  885. $home_root = dirname($home_root) . DIRECTORY_SEPARATOR;
  886. $dir = substr_replace($dir, $home_root, 0, 1);
  887. }
  888. return $dir;
  889. }
  890. // {{{ download_url()
  891. function download_url($url, $destfile = null, $proxy = null)
  892. {
  893. $use_suggested_filename = ($destfile === null);
  894. if ($use_suggested_filename) {
  895. $destfile = basename($url);
  896. }
  897. $tmp = parse_url($url);
  898. if (empty($tmp['port'])) {
  899. $tmp['port'] = 80;
  900. }
  901. if (empty($proxy)) {
  902. $fp = fsockopen($tmp['host'], $tmp['port'], $errno, $errstr);
  903. //print "\nconnecting to $tmp[host]:$tmp[port]\n";
  904. } else {
  905. $tmp_proxy = parse_url($proxy);
  906. $phost = $tmp_proxy['host'];
  907. $pport = $tmp_proxy['port'];
  908. $fp = fsockopen($phost, $pport, $errno, $errstr);
  909. //print "\nconnecting to $phost:$pport\n";
  910. }
  911. if (!$fp) {
  912. bail("download of $url failed: $errstr ($errno)\n");
  913. // If valid URL but error, no CURL extentions installed
  914. }
  915. if (empty($proxy)) {
  916. $path = $tmp['path'];
  917. } else {
  918. $path = "http://$tmp[host]:$tmp[port]$tmp[path]";
  919. }
  920. if (isset($tmp['query'])) {
  921. $path .= "?$tmp[query]";
  922. }
  923. if (isset($tmp['fragment'])) {
  924. $path .= "#$tmp[fragment]";
  925. }
  926. $request = "GET $path HTTP/1.0\r\nHost: $tmp[host]:$tmp[port]\r\n".
  927. "User-Agent: go-pear\r\n";
  928. if (!empty($proxy) && $tmp_proxy['user'] != '') {
  929. $request .= 'Proxy-Authorization: Basic ' .
  930. base64_encode($tmp_proxy['user'] . ':' . $tmp_proxy['pass']) . "\r\n";
  931. }
  932. $request .= "\r\n";
  933. fwrite($fp, $request);
  934. $cdh = "content-disposition:";
  935. $cdhl = strlen($cdh);
  936. $content_length = 0;
  937. while ($line = fgets($fp, 2048)) {
  938. if (trim($line) == '') {
  939. break;
  940. }
  941. if (preg_match('/^Content-Length: (.*)$/i', $line, $matches)) {
  942. $content_length = trim($matches[1]);
  943. }
  944. if ($use_suggested_filename && !strncasecmp($line, $cdh, $cdhl)) {
  945. if (eregi('filename="([^"]+)"', $line, $matches)) {
  946. $destfile = basename($matches[1]);
  947. }
  948. }
  949. }
  950. displayHTMLSetDownload($destfile);
  951. $wp = fopen($destfile, "wb");
  952. if (!$wp) {
  953. bail("could not open $destfile for writing\n");
  954. }
  955. $bytes_read = 0;
  956. $progress = 0;
  957. while ($data = fread($fp, 2048)) {
  958. fwrite($wp, $data);
  959. $bytes_read += strlen($data);
  960. if ($content_length != 0 && floor($bytes_read * 10 / $content_length) != $progress) {
  961. $progress = floor($bytes_read * 10 / $content_length);
  962. displayHTMLDownloadProgress($progress * 10);
  963. };
  964. }
  965. displayHTMLDownloadProgress(100);
  966. fclose($fp);
  967. fclose($wp);
  968. displayHTMLSetDownload('');
  969. return $destfile;
  970. }
  971. // }}}
  972. // {{{ which()
  973. function which($program, $dont_search_in = false)
  974. {
  975. if (WINDOWS) {
  976. if ($_path=my_env('Path')) {
  977. $dirs = explode(';', $_path);
  978. } else {
  979. $dirs = explode(';', my_env('PATH'));
  980. }
  981. foreach ($dirs as $i => $dir) {
  982. $dirs[$i] = strtolower(realpath($dir));
  983. }
  984. if ($dont_search_in) {
  985. $dont_search_in = strtolower(realpath($dont_search_in));
  986. }
  987. if ($dont_search_in &&
  988. ($key = array_search($dont_search_in, $dirs)) !== false)
  989. {
  990. unset($dirs[$key]);
  991. }
  992. foreach ($dirs as $dir) {
  993. $dir = str_replace('\\\\', '\\', $dir);
  994. if (!strlen($dir)) {
  995. continue;
  996. }
  997. if ($dir{strlen($dir) - 1} != '\\') {
  998. $dir .= '\\';
  999. }
  1000. $tmp = $dir . $program;
  1001. $info = pathinfo($tmp);
  1002. if (in_array(strtolower($info['extension']),
  1003. array('exe', 'com', 'bat', 'cmd'))) {
  1004. if (file_exists($tmp)) {
  1005. return strtolower($tmp);
  1006. }
  1007. } elseif (file_exists($ret = $tmp . '.exe') ||
  1008. file_exists($ret = $tmp . '.com') ||
  1009. file_exists($ret = $tmp . '.bat') ||
  1010. file_exists($ret = $tmp . '.cmd')) {
  1011. return strtolower($ret);
  1012. }
  1013. }
  1014. } else {
  1015. $dirs = explode(':', my_env('PATH'));
  1016. if ($dont_search_in &&
  1017. ($key = array_search($dont_search_in, $dirs)) !== false)
  1018. {
  1019. unset($dirs[$key]);
  1020. }
  1021. foreach ($dirs as $dir) {
  1022. if (is_executable("$dir/$program")) {
  1023. return "$dir/$program";
  1024. }
  1025. }
  1026. }
  1027. return false;
  1028. }
  1029. // }}}
  1030. // {{{ bail()
  1031. function bail($msg = '')
  1032. {
  1033. global $ptmp, $origpwd;
  1034. if ($ptmp && is_dir($ptmp)) {
  1035. chdir($origpwd);
  1036. rm_rf($ptmp);
  1037. }
  1038. if ($msg && WEBINSTALLER) {
  1039. $msg = @ob_get_contents() ."\n\n". $msg;
  1040. @ob_end_clean();
  1041. displayHTML('error', $msg);
  1042. exit;
  1043. };
  1044. if ($msg && !WEBINSTALLER) {
  1045. die($msg);
  1046. }
  1047. }
  1048. // }}}
  1049. // {{{ mkdir_p()
  1050. function mkdir_p($dir, $mode = 0777)
  1051. {
  1052. if (@is_dir($dir)) {
  1053. return true;
  1054. }
  1055. $parent = dirname($dir);
  1056. $ok = true;
  1057. if (!@is_dir($parent) && $parent != $dir) {
  1058. $ok = mkdir_p(dirname($dir), $mode);
  1059. }
  1060. if ($ok) {
  1061. $ok = @mkdir($dir, $mode);
  1062. // This is handled in the caller function (eg. webfrontend or not)
  1063. //if (!$ok) {
  1064. // print "mkdir failed: <$dir>\n";
  1065. //}
  1066. }
  1067. return $ok;
  1068. }
  1069. // }}}
  1070. // {{{ rm_rf()
  1071. function rm_rf($path)
  1072. {
  1073. if (@is_dir($path) && is_writable($path)) {
  1074. $dp = opendir($path);
  1075. while ($ent = readdir($dp)) {
  1076. if ($ent == '.' || $ent == '..') {
  1077. continue;
  1078. }
  1079. $file = $path . DIRECTORY_SEPARATOR . $ent;
  1080. if (@is_dir($file)) {
  1081. rm_rf($file);
  1082. } elseif (is_writable($file)) {
  1083. unlink($file);
  1084. } else {
  1085. echo $file . "is not writable and cannot be removed.
  1086. Please fix the permission or select a new path.\n";
  1087. }
  1088. }
  1089. closedir($dp);
  1090. return rmdir($path);
  1091. } else {
  1092. return @unlink($path);
  1093. }
  1094. }
  1095. // }}}
  1096. // {{{ tmpdir()
  1097. /*
  1098. * Fixes for winXP/wrong tmp set by Urs Gehrig (urs@circle.ch)
  1099. */
  1100. function temp_dir($default=false)
  1101. {
  1102. global $ptmp, $prefix;
  1103. if ($default) {
  1104. if (!@is_dir($default)) {
  1105. if (!mkdir_p($default)) {
  1106. return false;
  1107. }
  1108. }
  1109. /* try it really, is_writable is buggy with openbasedir */
  1110. $fh = @fopen(realpath($default) . "/test","wb");
  1111. if ($fh) {
  1112. // desparately try to set temp dir any possible way, see bug #13167
  1113. $ptmp = $_temp = $temp_dir = $default;
  1114. putenv('TMPDIR='.$default);
  1115. return true;
  1116. } else {
  1117. return false;
  1118. }
  1119. }
  1120. $_temp = false;
  1121. if (WINDOWS){
  1122. if ( my_env('TEMP') ) {
  1123. $_temp = my_env('TEMP');
  1124. } elseif ( my_env('TMP') ) {
  1125. $_temp = my_env('TMP');
  1126. } elseif ( my_env('windir') ) {
  1127. $_temp = my_env('windir') . '\temp';
  1128. } elseif ( my_env('SystemRoot') ) {
  1129. $_temp = my_env('SystemRoot') . '\temp';
  1130. }
  1131. // handle ugly ENV var like \Temp instead of c:\Temp
  1132. $dirs = explode("\\", realpath($_temp));
  1133. if(strpos($_temp, ":") != 1) {
  1134. unset($_temp);
  1135. $_dirs = array();
  1136. foreach($dirs as $val) {
  1137. if((boolean)$val ) {
  1138. $_dirs[] = str_replace("/", "", $val);
  1139. }
  1140. }
  1141. unset($dirs);
  1142. $dirs = $_dirs;
  1143. array_unshift ($dirs, "c:" );
  1144. $_temp = $dirs[0];
  1145. for($i = 1;$i < count($dirs);$i++) {
  1146. $_temp .= "//" . $dirs[$i];
  1147. }
  1148. }
  1149. $ptmp = $_temp;
  1150. } else {
  1151. $_temp = my_env('TMPDIR');
  1152. if (!$_temp) {
  1153. if (is_writable('/tmp')) {
  1154. $_temp = '/tmp';
  1155. }
  1156. }
  1157. }
  1158. // If for some reason the user has no rights to access to
  1159. // the standard tempdir, we assume that he has the right
  1160. // to access his prefix and choose $prefix/tmp as tempdir
  1161. if (!$_temp || !is_writable($_temp)) {
  1162. print "System's Tempdir failed, trying to use \$prefix/tmp ...";
  1163. $res = mkdir_p($prefix.'/tmp');
  1164. if (!$res) {
  1165. bail('mkdir '.$prefix.'/tmp'.' ... failed');
  1166. }
  1167. $ptmp = $prefix . '/tmp';
  1168. $_temp = tempnam($prefix.'/tmp', 'gope');
  1169. rm_rf($_temp);
  1170. mkdir_p($_temp, 0700);
  1171. $ok = @chdir($ptmp);
  1172. if (!$ok) { // This should not happen, really ;)
  1173. bail('chdir '.$ptmp.' ... failed');
  1174. }
  1175. print "ok\n";
  1176. // Adjust TEMPDIR envvars
  1177. if (!isset($_ENV)) {
  1178. $_ENV = array();
  1179. }
  1180. $_ENV['TMPDIR'] = $_ENV['TEMP'] = $prefix.'/tmp';
  1181. } else {
  1182. $_temp = tempnam($_temp.'/tmp', 'gope');
  1183. }
  1184. $temp_dir = $ptmp = $_temp;
  1185. return true;
  1186. }
  1187. // }}}
  1188. // {{{ my_env()
  1189. /*
  1190. (cox) In my system PHP 4.2.1 (both cgi & cli) $_ENV is empty
  1191. but getenv() does work fine
  1192. */
  1193. function my_env($var)
  1194. {
  1195. if (is_array($_ENV) && isset($_ENV[$var])) {
  1196. return $_ENV[$var];
  1197. }
  1198. return getenv($var);
  1199. }
  1200. // }}}
  1201. // {{{ detect_install_dirs()
  1202. function detect_install_dirs($_prefix = null) {
  1203. global $temp_dir, $prefix, $bin_dir, $php_dir, $php_bin, $doc_dir, $data_dir, $test_dir;
  1204. if (WINDOWS) {
  1205. if ($_prefix === null) {
  1206. $prefix = getcwd();
  1207. } else {
  1208. $prefix = $_prefix;
  1209. }
  1210. if (!@is_dir($prefix)) {
  1211. if (@is_dir('c:\php5')) {
  1212. $prefix = 'c:\php5';
  1213. } elseif (@is_dir('c:\php4')) {
  1214. $prefix = 'c:\php4';
  1215. } elseif (@is_dir('c:\php')) {
  1216. $prefix = 'c:\php';
  1217. }
  1218. }
  1219. $bin_dir = '$prefix';
  1220. $php_dir = '$prefix\pear';
  1221. $doc_dir = '$php_dir\docs';
  1222. $data_dir = '$php_dir\data';
  1223. $test_dir = '$php_dir\tests';
  1224. $temp_dir = '$prefix\temp';
  1225. /*
  1226. * Detects php.exe
  1227. */
  1228. if( $t=getenv('PHP_PEAR_PHP_BIN') ){
  1229. $php_bin = $t;
  1230. } elseif ($t=getenv('PHP_BIN') ) {
  1231. $php_bin = $t;
  1232. } elseif ( $t=which('php') ) {
  1233. $php_bin = $t;
  1234. } elseif ( is_file($prefix.'\cli\php.exe') ) {
  1235. $php_bin = $prefix.'\cli\php.exe';
  1236. } elseif ( is_file($prefix.'\php.exe') ) {
  1237. $php_bin = $prefix.'\php.exe';
  1238. }
  1239. if( $php_bin && !is_file($php_bin) ){
  1240. $php_bin = '';
  1241. } else {
  1242. if(!ereg(":",$php_bin)){
  1243. $php_bin = getcwd().DIRECTORY_SEPARATOR.$php_bin;
  1244. }
  1245. }
  1246. if (!is_file($php_bin)) {
  1247. if (is_file('c:/php/cli/php.exe')) {
  1248. $php_bin = 'c:/php/cli/php.exe';
  1249. } elseif (is_file('c:/php5/php.exe')) {
  1250. $php_bin = 'c:/php5/php.exe';
  1251. } elseif (is_file('c:/php4/cli/php.exe')) {
  1252. $php_bin = 'c:/php4/cli/php.exe';
  1253. }
  1254. }
  1255. } else {
  1256. if ($_prefix === null) {
  1257. #$prefix = dirname(PHP_BINDIR);
  1258. $prefix = dirname(__FILE__);
  1259. } else {
  1260. $prefix = $_prefix;
  1261. }
  1262. $bin_dir = '$prefix/bin';
  1263. #$php_dir = '$prefix/share/pear';
  1264. $php_dir = '$prefix/PEAR';
  1265. $doc_dir = '$php_dir/docs';
  1266. $data_dir = '$php_dir/data';
  1267. $test_dir = '$php_dir/tests';
  1268. $temp_dir = '$prefix/temp';
  1269. // check if the user has installed PHP with PHP or GNU layout
  1270. if (@is_dir("$prefix/lib/php/.registry")) {
  1271. $php_dir = '$prefix/lib/php';
  1272. } elseif (@is_dir("$prefix/share/pear/lib/.registry")) {
  1273. $php_dir = '$prefix/share/pear/lib';
  1274. $doc_dir = '$prefix/share/pear/docs';
  1275. $data_dir = '$prefix/share/pear/data';
  1276. $test_dir = '$prefix/share/pear/tests';
  1277. } elseif (@is_dir("$prefix/share/php/.registry")) {
  1278. $php_dir = '$prefix/share/php';
  1279. }
  1280. }
  1281. }
  1282. // }}}
  1283. // {{{ displayHTMLHeader
  1284. function displayHTMLHeader()
  1285. {
  1286. ?>
  1287. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  1288. <html>
  1289. <head>
  1290. <title>PEAR :: Installer :: Go-PEAR</title>
  1291. <style type="text/css">
  1292. <!--
  1293. a {
  1294. color:#000000;
  1295. text-decoration: none;
  1296. }
  1297. a:visited {
  1298. color:#000000;
  1299. text-decoration: none;
  1300. }
  1301. a:active {
  1302. color:#000000;
  1303. text-decoration: none;
  1304. }
  1305. a:hover {
  1306. color:#000000;
  1307. text-decoration: underline;
  1308. }
  1309. a.green {
  1310. color:#006600;
  1311. text-decoration: none;
  1312. }
  1313. a.green:visited {
  1314. color:#006600;
  1315. text-decoration: none;
  1316. }
  1317. a.green:active {
  1318. color:#006600;
  1319. text-decoration: none;
  1320. }
  1321. a.green:hover {
  1322. color:#006600;
  1323. text-decoration: underline;
  1324. }
  1325. body, td, th {
  1326. font-family: verdana,arial,helvetica,sans-serif;
  1327. font-size: 90%;
  1328. }
  1329. p {
  1330. font-family: verdana,arial,helvetica,sans-serif;
  1331. }
  1332. th.pack {
  1333. color: #FFFFFF;
  1334. background: #009933;
  1335. text-align: right;
  1336. }
  1337. td.package_info_title {
  1338. color: #006600;
  1339. font-weight: bold;
  1340. }
  1341. th.others {
  1342. color: #006600;
  1343. text-align: left;
  1344. }
  1345. em {
  1346. font-weight: bold;
  1347. font-style: italic;
  1348. }
  1349. .green {
  1350. color: #006600;
  1351. }
  1352. .red {
  1353. color: #ff0000;
  1354. }
  1355. .grey {
  1356. color: #a9a9a9;
  1357. }
  1358. span.headline {
  1359. font-family: verdana,arial,helvetica,sans-serif;
  1360. font-size: 125%;
  1361. font-weight: bold;
  1362. color: #ffffff;
  1363. }
  1364. span.title {
  1365. font-family: verdana,arial,helvetica,sans-serif;
  1366. font-size: 110%;
  1367. font-weight: bold;
  1368. color: #006600;
  1369. }
  1370. .newsDate {
  1371. font-size: 85%;
  1372. font-style: italic;
  1373. color: #66cc66;
  1374. }
  1375. .compact {
  1376. font-family: arial, helvetica, sans-serif;
  1377. font-size: 90%;
  1378. }
  1379. .menuWhite {
  1380. font-family: verdana,arial,helvetica,sans-serif;
  1381. font-size: 75%;
  1382. color: #ffffff;
  1383. }
  1384. .menuBlack {
  1385. font-family: verdana,arial,helvetica,sans-serif;
  1386. text-decoration: none;
  1387. font-weight: bold;
  1388. font-size: 75%;
  1389. color: #000000;
  1390. }
  1391. .sidebar {
  1392. font-size: 85%;
  1393. }
  1394. code, pre, tt {
  1395. font-family: Courier, "Courier New", monospace;
  1396. font-size: 90%;
  1397. }
  1398. pre.php {
  1399. border-color: black;
  1400. border-style: dashed;
  1401. border-width: 1px;
  1402. background-color: #eeeeee;
  1403. padding: 5px;
  1404. }
  1405. h1 {
  1406. font-family: verdana,arial,helvetica,sans-serif;
  1407. font-size: 140%;
  1408. font-weight: bold;
  1409. color: #006600;
  1410. }
  1411. h2 {
  1412. font-family: verdana,arial,helvetica,sans-serif;
  1413. font-size: 125%;
  1414. font-weight: bold;
  1415. color: #006600;
  1416. }
  1417. h3 {
  1418. font-family: verdana,arial,helvetica,sans-serif;
  1419. font-size: 110%;
  1420. font-weight: bold;
  1421. color: #006600;
  1422. }
  1423. small {
  1424. font-family: verdana,arial,helvetica,sans-serif;
  1425. font-size: 75%;
  1426. }
  1427. a.small {
  1428. font-family: verdana,arial,helvetica,sans-serif;
  1429. font-size: 75%;
  1430. text-decoration: none;
  1431. }
  1432. .tableTitle {
  1433. font-family: verdana,arial,helvetica,sans-serif;
  1434. font-weight: bold;
  1435. }
  1436. .tableExtras {
  1437. font-family: verdana,arial,helvetica,sans-serif;
  1438. font-size: 85%;
  1439. color: #FFFFFF;
  1440. }
  1441. input {
  1442. font-family: verdana,arial,helvetica,sans-serif;
  1443. }
  1444. textarea {
  1445. font-family: verdana,arial,helvetica,sans-serif;
  1446. }
  1447. input.small, select.small {
  1448. font-family: verdana,arial,helvetica,sans-serif;
  1449. font-size: 75%;
  1450. }
  1451. textarea.small {
  1452. font-family: verdana,arial,helvetica,sans-serif;
  1453. font-size: 75%;
  1454. }
  1455. form {
  1456. margin-bottom : 0;
  1457. }
  1458. hr {
  1459. text-align: left;
  1460. width: 80%;
  1461. }
  1462. -->
  1463. </style>
  1464. <meta name="description" content="This is the Web Interface of the PEAR Installer" />
  1465. </head>
  1466. <body topmargin="0" leftmargin="0"
  1467. marginheight="0" marginwidth="0"
  1468. bgcolor="#ffffff"
  1469. text="#000000"
  1470. link="#006600"
  1471. alink="#cccc00"
  1472. vlink="#003300"
  1473. >
  1474. <?php
  1475. }
  1476. // }}}
  1477. // {{{ displayHTML
  1478. function displayHTML($page = 'Welcome', $data = array())
  1479. {
  1480. global $pfc_packages;
  1481. displayHTMLHeader();
  1482. ?>
  1483. <a name="TOP" /></a>
  1484. <table border="0" cellspacing="0" cellpadding="0" height="48" width="100%">
  1485. <tr bgcolor="#339900">
  1486. <td align="left" width="120">
  1487. <img src="<?php echo basename(__FILE__); ?>?action=img&amp;img=pearlogo" width="104" height="50" vspace="2" hspace="5" alt="PEAR">
  1488. </td>
  1489. <td align="left" valign="middle" width="20">
  1490. &nbsp;
  1491. </td>
  1492. <td align="left" valign="middle">
  1493. <span class="Headline">Go-PEAR Installer</span>
  1494. </td>
  1495. </tr>
  1496. <tr bgcolor="#003300"><td colspan="3"></td></tr>
  1497. <tr bgcolor="#006600">
  1498. <td align="right" valign="top" colspan="3">
  1499. <span style="color: #ffffff">Version <?php echo GO_PEAR_VER; ?></span>&nbsp;<br />
  1500. </td>
  1501. </tr>
  1502. <tr bgcolor="#003300"><td colspan="3"></td></tr>
  1503. </table>
  1504. <table cellpadding="0" cellspacing="0" width="100%">
  1505. <tr valign="top">
  1506. <td bgcolor="#f0f0f0" width="100">
  1507. <table width="200" border="0" cellpadding="4" cellspacing="0">
  1508. <tr valign="top">
  1509. <td style="font-size: 90%" align="left" width="200">
  1510. <p><br />
  1511. <?php
  1512. $menus = array('Welcome' => 'Welcome to Go-PEAR',
  1513. 'config' => 'Configuration',
  1514. 'preinstall' => 'Installation',
  1515. 'install' => 'Completed');
  1516. $after_current = false;
  1517. // Menu robustness (a bit low, but better then never)
  1518. if ($page == 'error') {
  1519. $_GET['last'] = $_GET['step'];
  1520. $after_current = true;
  1521. } elseif (!array_key_exists($page, $menus)) {
  1522. $page = 'Welcome';
  1523. }
  1524. foreach ($menus as $menu => $descr) {
  1525. print('<img src="'.basename(__FILE__).'?action=img&amp;img=smallpear" border="0">');
  1526. if (!$after_current) {
  1527. $class = '';
  1528. if ($page == $menu) {
  1529. $class = 'green';
  1530. }
  1531. if (!isSet($_GET['last'])) { $_GET['last'] = $page; }
  1532. print('<a href="'.basename(__FILE__).'?step='.$menu.'&last='.$_GET['last'].'" class="'.$class.'">'.$descr.'</a><br />');
  1533. if ($_GET['last'] == $menu) {
  1534. $after_current = true;
  1535. }
  1536. } else {
  1537. print('<span class="grey">'.$descr.'</span><br />');
  1538. }
  1539. }
  1540. ?>
  1541. </td>
  1542. </tr>
  1543. </table>
  1544. </td>
  1545. <td bgcolor="#cccccc" width="1" background="/gifs/checkerboard.gif"></td>
  1546. <td>
  1547. <table width="100%" cellpadding="10" cellspacing="0">
  1548. <tr>
  1549. <td valign="top">
  1550. <table border="0">
  1551. <tr>
  1552. <td width="20">
  1553. </td>
  1554. <td>
  1555. <?php
  1556. if ($page == 'error') {
  1557. ?>
  1558. <span class="title">Error</span><br/>
  1559. <br/>
  1560. <?php
  1561. $value = $data;
  1562. if (preg_match('/ok$/', $value)) {
  1563. $value = preg_replace('/(ok)$/', '<span class="green">\1</span>', $value);
  1564. }
  1565. if (preg_match('/failed$/', $value)) {
  1566. $value = preg_replace('/(failed)$/', '<span class="red">\1</span>', $value);
  1567. }
  1568. if (preg_match('/^install ok:/', $value)) {
  1569. $value = preg_replace('/^(install ok:)/', '<span class="green">\1</span>', $value);
  1570. }
  1571. if (preg_match('/^Warning:/', $value)) {
  1572. $value = '<span style="color: #ff0000">'.$value.'</span>';
  1573. }
  1574. echo nl2br($value);
  1575. } elseif ($page == 'Welcome') {
  1576. ?>
  1577. <span class="title">Welcome to go-pear <?php echo GO_PEAR_VER; ?>!</span><br/>
  1578. <p>
  1579. Go-pear will install Pear, its Web Frontend and all the needed files. This<br/>
  1580. frontend is your tool for PEAR installation and maintenance.
  1581. </p>
  1582. <p>
  1583. Go-pear also lets you download and install the following optional PEAR<br/>
  1584. packages: <?php echo implode(', ', array_keys($GLOBALS['pfc_packages'])); ?>.
  1585. </p>
  1586. <a href="<?php echo basename(__FILE__); ?>?step=config&restart=1" class="green">Next &gt;&gt;</a>
  1587. <?php
  1588. } elseif ($page == 'config') {
  1589. if (!empty($GLOBALS['http_proxy'])) {
  1590. $tmp_proxy = parse_url($GLOBALS['http_proxy']);
  1591. $proxy_host = $tmp_proxy['scheme'] . '://';
  1592. if ($tmp_proxy['user'] != '') {
  1593. $proxy_host .= $tmp_proxy['user'];
  1594. if ($tmp_proxy['pass'] != '') {
  1595. $proxy_host .= ':' . $tmp_proxy['pass'];
  1596. }
  1597. $proxy_host .= '@';
  1598. }
  1599. $proxy_host .= $tmp_proxy['host'];
  1600. $proxy_port = $tmp_proxy['port'];
  1601. } else {
  1602. $proxy_host = $proxy_port = '';
  1603. }
  1604. ?>
  1605. <form action="<?php echo basename(__FILE__);?>?step=install" method="post">
  1606. <!-- Packages stuff -->
  1607. <span class="title">Packages</span>
  1608. <p>
  1609. The following PEAR packages will be installed. You can select some optional<br />
  1610. packages to be installed by go-pear too:<br />
  1611. </p>
  1612. <table border="0">
  1613. <tr>
  1614. <th>&nbsp;</th><th>Package</th><th width="65%">Description</th>
  1615. </tr><tr>
  1616. <td>(required)</td><td>PEAR core</td><td>PEAR Base System</td>
  1617. </tr>
  1618. <?php
  1619. // automatically install frontend
  1620. $frontend = 'PEAR_Frontend_Web-beta';
  1621. print('<tr><td>(required)<input type="hidden" name="'.$frontend.'" value="on" /></td><td>'.$frontend.'</td><td>'.$GLOBALS['pfc_packages'][$frontend].'</td></tr>');
  1622. unset($GLOBALS['pfc_packages'][$frontend]);
  1623. foreach ($GLOBALS['pfc_packages'] as $var => $descr) {
  1624. $checked = '';
  1625. if (in_array($var, $GLOBALS['install_optional_packages'])) { $checked = ' checked'; }
  1626. printf('<tr><td align="center"><input type="checkbox" name="%s"%s></td><td>%s</td><td>%s</td></tr>',
  1627. $var,
  1628. $checked,
  1629. $var,
  1630. $descr);
  1631. }
  1632. ?>
  1633. </table>
  1634. <hr />
  1635. <!-- Configuration stuff -->
  1636. <span class="title">Configuration</span>
  1637. <p>
  1638. Below is a suggested file layout for your new PEAR installation.
  1639. </p>
  1640. <!--
  1641. <p>
  1642. <table border="0">
  1643. <tr>
  1644. <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&amp;img=note" border="0"></td>
  1645. <td>
  1646. <span class="green">
  1647. <b>Note:</b> Make sure that PHP has the permission to access the specified<br/>
  1648. directories.
  1649. </span>
  1650. </td>
  1651. </tr>
  1652. </table>
  1653. </p>
  1654. -->
  1655. <table border="0" width="80%">
  1656. <?php
  1657. foreach ($GLOBALS['config_vars'] as $n => $var) {
  1658. $error_class = '';
  1659. if (is_array($GLOBALS['config_errors']) && array_key_exists($var, $GLOBALS['config_errors'])) {
  1660. // www_error for this var
  1661. $error_class = ' class="red"';
  1662. }
  1663. printf('<tr><td>%d. %s</td><td><input type="text" name="config[%s]" value="%s"%s></td></tr>',
  1664. $n,
  1665. $GLOBALS['config_desc'][$var],
  1666. $var,
  1667. $_SESSION['go-pear']['config'][$var],
  1668. $error_class);
  1669. // prefix dir, check perm (uses GLOBALS: resolved subvars)
  1670. if ($n == 1 && is_dir($GLOBALS[$var]) && !is_writable($GLOBALS[$var])) {
  1671. $error = '<em>WARNING!</em> No permission to create subdirectories in this prefix dir. Unless you fix this, the default configuration will not work.';
  1672. if (!WINDOWS) {
  1673. $error .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
  1674. <tt>chmod 0777 '.$GLOBALS[$var].'</tt></p>';
  1675. }
  1676. print('<tr><td colspan="2" class="green">'.$error.'</td></tr>');
  1677. }
  1678. if (is_array($GLOBALS['config_errors']) && array_key_exists($var, $GLOBALS['config_errors'])) {
  1679. // www_error for this var
  1680. print('<tr><td colspan="2" class="red">'.$GLOBALS['config_errors'][$var].'</td></tr>');
  1681. }
  1682. }
  1683. ?>
  1684. </table>
  1685. </p>
  1686. <hr />
  1687. <!-- Optional stuff -->
  1688. <span class="title">Optional:</span>
  1689. <ul>
  1690. <p>
  1691. <li />HTTP proxy (host:port)
  1692. <input type="text" name="proxy[host]" value="<?php echo $proxy_host;?>"> : <input type="text" name="proxy[port]" value="<?php echo $proxy_port;?>" size="6">
  1693. </p>
  1694. <p>
  1695. <li />Compatibility-Mode for old non-DOM Browsers <input type="checkbox" name="BCmode" id="BCmode" checked>
  1696. <script type="text/javascript">
  1697. <!--
  1698. if (document.getElementById('BCmode')) {
  1699. document.getElementById('BCmode').checked = 0;
  1700. };
  1701. // -->
  1702. </script>
  1703. </p>
  1704. </ul>
  1705. <?php
  1706. if (WINDOWS && phpversion() == '4.1.1') {
  1707. ?>
  1708. <p>
  1709. <table border="0">
  1710. <tr>
  1711. <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&amp;img=note" border="0"></td>
  1712. <td>
  1713. <span style="color: #ff0000">
  1714. <b>Warning:</b> Your PHP version (4.1.1) might be imcompatible with go-pear due to a bug<br/>
  1715. in your PHP binary. If the installation crashes you might want to update your PHP version.</br>
  1716. </span>
  1717. </td>
  1718. </tr>
  1719. </table>
  1720. </p>
  1721. <?php
  1722. }
  1723. ?>
  1724. <hr />
  1725. <!-- Closing note -->
  1726. <p>
  1727. <table border="0">
  1728. <tr>
  1729. <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&amp;img=note" border="0"></td>
  1730. <td>
  1731. <span class="green">
  1732. <b>Note:</b> Installation might take some time, because go-pear has to<br/>
  1733. download all needed files from pear.php.net. Just be patient and wait for<br/>
  1734. the next page to load.<br/>
  1735. </span>
  1736. </td>
  1737. </tr>
  1738. </table>
  1739. </p>
  1740. <input type="submit" value="Install" onClick="javascript: submitButton.value='Downloading and installing ... please wait ...'" name="submitButton">
  1741. </form>
  1742. <?php
  1743. } elseif ($page == 'install') {
  1744. ?>
  1745. <span class="title">Installation Complete - Summary</span><br/>
  1746. <?php
  1747. displayHTMLInstallationSummary($data);
  1748. } elseif ($page == 'preinstall') {
  1749. ?>
  1750. <p>
  1751. <span class="title">Installation in progress ...</span></br >
  1752. <i>(If the page stops loading before the end of the installation, then just reload it)</i></p>
  1753. <script language="javascript">
  1754. <!--
  1755. var progress;
  1756. var downloadprogress;
  1757. progress = 0;
  1758. downloadprogress = 0;
  1759. function setprogress(value)
  1760. {
  1761. progress = value;
  1762. prog = document.getElementById('installation_progress');
  1763. prog.innerHTML = progress + " %";
  1764. progress2 = progress / 10;
  1765. progress2 = Math.floor(progress2);
  1766. for (i=0; i < 10; i++)
  1767. document.getElementById('progress_cell_'+i).style.backgroundColor = "#cccccc";
  1768. switch(progress2)
  1769. {
  1770. case 10:
  1771. document.getElementById('progress_cell_9').style.backgroundColor = "#006600";
  1772. case 9:
  1773. document.getElementById('progress_cell_8').style.backgroundColor = "#006600";
  1774. case 8:
  1775. document.getElementById('progress_cell_7').style.backgroundColor = "#006600";
  1776. case 7:
  1777. document.getElementById('progress_cell_6').style.backgroundColor = "#006600";
  1778. case 6:
  1779. document.getElementById('progress_cell_5').style.backgroundColor = "#006600";
  1780. case 5:
  1781. document.getElementById('progress_cell_4').style.backgroundColor = "#006600";
  1782. case 4:
  1783. document.getElementById('progress_cell_3').style.backgroundColor = "#006600";
  1784. case 3:
  1785. document.getElementById('progress_cell_2').style.backgroundColor = "#006600";
  1786. case 2:
  1787. document.getElementById('progress_cell_1').style.backgroundColor = "#006600";
  1788. case 1:
  1789. document.getElementById('progress_cell_0').style.backgroundColor = "#006600";
  1790. };
  1791. }
  1792. function addprogress(value)
  1793. {
  1794. progress += value;
  1795. setprogress(progress);
  1796. }
  1797. function setdownloadfile(value)
  1798. {
  1799. setdownloadprogress(0);
  1800. prog = document.getElementById('download_file');
  1801. prog.innerHTML = 'Downloading '+value+' ...';
  1802. };
  1803. function unsetdownloadfile()
  1804. {
  1805. setdownloadprogress(0);
  1806. prog = document.getElementById('download_file');
  1807. prog.innerHTML = '';
  1808. };
  1809. function setdownloadprogress(value)
  1810. {
  1811. downloadprogress = value;
  1812. prog = document.getElementById('download_progress');
  1813. prog.innerHTML = downloadprogress + " %";
  1814. progress2 = downloadprogress / 10;
  1815. progress2 = Math.floor(progress2);
  1816. for (i=0; i < 10; i++)
  1817. document.getElementById('download_progress_cell_'+i).style.backgroundColor = "#cccccc";
  1818. switch(progress2)
  1819. {
  1820. case 10:
  1821. document.getElementById('download_progress_cell_9').style.backgroundColor = "#006600";
  1822. case 9:
  1823. document.getElementById('download_progress_cell_8').style.backgroundColor = "#006600";
  1824. case 8:
  1825. document.getElementById('download_progress_cell_7').style.backgroundColor = "#006600";
  1826. case 7:
  1827. document.getElementById('download_progress_cell_6').style.backgroundColor = "#006600";
  1828. case 6:
  1829. document.getElementById('download_progress_cell_5').style.backgroundColor = "#006600";
  1830. case 5:
  1831. document.getElementById('download_progress_cell_4').style.backgroundColor = "#006600";
  1832. case 4:
  1833. document.getElementById('download_progress_cell_3').style.backgroundColor = "#006600";
  1834. case 3:
  1835. document.getElementById('download_progress_cell_2').style.backgroundColor = "#006600";
  1836. case 2:
  1837. document.getElementById('download_progress_cell_1').style.backgroundColor = "#006600";
  1838. case 1:
  1839. document.getElementById('download_progress_cell_0').style.backgroundColor = "#006600";
  1840. };
  1841. };
  1842. // -->
  1843. </script>
  1844. <table style="border-width: 1px; border-color: #000000" cellspacing="0" cellpadding="0">
  1845. <tr>
  1846. <td>
  1847. <table border="0">
  1848. <tr>
  1849. <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_0">&nbsp;</td>
  1850. <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_1">&nbsp;</td>
  1851. <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_2">&nbsp;</td>
  1852. <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_3">&nbsp;</td>
  1853. <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_4">&nbsp;</td>
  1854. <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_5">&nbsp;</td>
  1855. <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_6">&nbsp;</td>
  1856. <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_7">&nbsp;</td>
  1857. <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_8">&nbsp;</td>
  1858. <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_9">&nbsp;</td>
  1859. <td bgcolor="#ffffff" width="10" height="20">&nbsp;</td>
  1860. <td bgcolor="#ffffff" height="20" id="installation_progress" class="green">0 %</td>
  1861. </tr>
  1862. </table>
  1863. <br>
  1864. <table border="0">
  1865. <tr>
  1866. <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_0">&nbsp;</td>
  1867. <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_1">&nbsp;</td>
  1868. <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_2">&nbsp;</td>
  1869. <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_3">&nbsp;</td>
  1870. <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_4">&nbsp;</td>
  1871. <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_5">&nbsp;</td>
  1872. <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_6">&nbsp;</td>
  1873. <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_7">&nbsp;</td>
  1874. <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_8">&nbsp;</td>
  1875. <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_9">&nbsp;</td>
  1876. <td bgcolor="#ffffff" width="10" height="20">&nbsp;</td>
  1877. <td bgcolor="#ffffff" height="20" id="download_progress" class="green">0 %</td>
  1878. <td bgcolor="#ffffff" width="10" height="20">&nbsp;</td>
  1879. <td bgcolor="#ffffff" height="20" id="download_file" class="green"></td>
  1880. </tr>
  1881. </table>
  1882. <br>
  1883. <iframe src="<?php echo basename(__FILE__); ?>?step=install-progress&amp;<?php echo SID;?>" width="700" height="700" frameborder="0" marginheight="0" marginwidth="0"></iframe>
  1884. </td>
  1885. </tr>
  1886. </table>
  1887. <?php
  1888. }
  1889. ?>
  1890. </td>
  1891. </tr>
  1892. </table>
  1893. </td>
  1894. </tr>
  1895. </table>
  1896. </td>
  1897. </tr>
  1898. </table>
  1899. <?php
  1900. displayHTMLFooter();
  1901. }
  1902. // }}}
  1903. // {{{ displayHTMLFooter
  1904. function displayHTMLFooter()
  1905. {
  1906. ?>
  1907. </body>
  1908. </html>
  1909. <?php
  1910. };
  1911. // }}}
  1912. // {{{ displayHTMLInstallationSummary
  1913. function displayHTMLInstallationSummary($data = '')
  1914. {
  1915. $next = NULL;
  1916. $file = $GLOBALS['webfrontend_file'];
  1917. $doc_root = strip_magic_quotes($_SERVER['DOCUMENT_ROOT']);
  1918. $file_dir = dirname(__FILE__);
  1919. if ( WINDOWS ) {
  1920. $file = str_replace('/', '\\', strtolower($file));
  1921. $doc_root = str_replace('/', '\\', strtolower($doc_root));
  1922. $file_dir = str_replace('/', '\\', strtolower($file_dir));
  1923. }
  1924. if ($doc_root && substr($file, 0, strlen($doc_root)) == $doc_root) {
  1925. $next = substr($file, strlen($doc_root));
  1926. // need leading / (file - docroot = path from docroot)
  1927. if (substr($next, 0, 1) != '/') {
  1928. $next = '/'.$next;
  1929. }
  1930. } else if ($file_dir && substr($file, 0, strlen($file_dir)) == $file_dir) {
  1931. $next = substr($file, strlen($file_dir));
  1932. // strip leading / (file - file_dir = path from go-pear file)
  1933. if (substr($next, 0, 1) == '/') {
  1934. $next = substr($next, 1, strlen($next));
  1935. }
  1936. }
  1937. if ($data) {
  1938. echo "<br/>".$data;
  1939. }
  1940. ?>
  1941. <p>
  1942. <span class="title">Installation Completed !</span>
  1943. </p>
  1944. <table border="0">
  1945. <tr>
  1946. <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&amp;img=note" border="0"></td>
  1947. <td>
  1948. <span class="green">
  1949. <b>Note:</b> To use PEAR without any problems you need to add your<br/>
  1950. PEAR Installation path (<?php echo $GLOBALS['php_dir']; ?>)<br>
  1951. to your <a href="http://www.php.net/manual/en/configuration.directives.php#ini.include_path">include_path</a>.<br/>
  1952. <br/>
  1953. Using a .htaccess file or directly edit httpd.conf would be working solutions<br/>
  1954. for Apache running servers, too.<br/>
  1955. </span>
  1956. </td>
  1957. </tr>
  1958. </table>
  1959. <br/>
  1960. For more information about PEAR, see:<br/>
  1961. <a href="http://pear.php.net/faq.php" target="_new" class="green">PEAR FAQ</a><br/>
  1962. <a href="http://pear.php.net/manual/" target="_new" class="green">PEAR Manual</a><br/>
  1963. <br/>
  1964. Thanks for using go-pear!<br/>
  1965. <br/>
  1966. <?php
  1967. if ($next === NULL) {
  1968. ?>
  1969. <table border="0">
  1970. <tr>
  1971. <td valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&amp;img=note" border="0"></td>
  1972. <td>
  1973. <span style="color: #ff0000">
  1974. <b>Warning:</b> Can not determine the URL of the freshly installed Web Frontend<br />
  1975. (file: <?php echo $file ?>).<br />
  1976. Please access it manually !
  1977. </span>
  1978. </td>
  1979. </tr>
  1980. </table>
  1981. <?php
  1982. } else {
  1983. if ($_GET['step'] == 'install-progress') {
  1984. ?>
  1985. <a href="<?php echo $next;?>" class="green" target="_parent">Start Web Frontend of the PEAR Installer &gt;&gt;</a>
  1986. <?php
  1987. } else {
  1988. ?>
  1989. <a href="<?php echo $next;?>" class="green">Start Web Frontend of the PEAR Installer &gt;&gt;</a>
  1990. <?php
  1991. }
  1992. }
  1993. }
  1994. // }}}
  1995. // {{{ strip_magic_quotes
  1996. function strip_magic_quotes($value)
  1997. {
  1998. if (ini_get('magic_quotes_gpc')) {
  1999. return stripslashes($value);
  2000. }
  2001. return $value;
  2002. };
  2003. // }}}
  2004. // {{{ showImage
  2005. function showImage($img)
  2006. {
  2007. $images = array(
  2008. 'smallpear' => array(
  2009. 'type' => 'gif',
  2010. 'data' => 'R0lGODlhEQATAMQAAAAAACqUACiTAC2WAC+YAzKZBTSaBsHgszOZADCYADmcB4TCZp3Ohtfrzd/v1+by4PD47DaaAz+fDUijF2WyOlCoHvT58VqtJPn893y+S/v9+f7//f3+/Pz9+////////ywAAAAAEQATAAAFkqAnjiR5NGXqcdpCoapnMVRdWbEHUROVVROYalHJTCaVAKWTcjAUGckgQY04SJAFMhJJIL5e4a5I6X6/gwlkRIwOzucAY9SYZBRvOCKheIwYFxR5enxCLhVeemAHbBQVg4SMIoCCinsKVyIOdlKKAhQcJFpGiWgFQiIYPxeJCQEEcykcDIgDAwYUkjEWB70NGykhADs=',
  2011. ),
  2012. 'pearlogo' => array(
  2013. 'type' => 'gif',
  2014. 'data' => 'R0lGODlhaAAyAMT/AMDAwP3+/TWaAvD47Pj89vz++zebBDmcBj6fDEekFluvKmu3PvX68ujz4XvBS8LgrNXqxeHw1ZnPaa/dgvv9+cLqj8LmltD2msnuls3xmszwmf7+/f///wAAAAAAAAAAACH5BAEAAAAALAAAAABoADIAQAX/ICCOZGmeaKqubOtWWjwJphLLgH1XUu//C1Jisfj9YLEKQnSY3GaixWQqQTkYHM4AMulNLJFC9pEwIW/odKU8cqTfsWoTTtcomU4ZjbR4ZP+AgYKCG0EiZ1AuiossEhwEXRMEg5SVWQ6MmZqKWD0QlqCUEHubpaYlExwRPRZioZZVp7KzKQoSDxANDLsNXA5simd2FcQYb4YAc2jEU80TmAAIztPCMcjKdg4OEsZJmwIWWQPQI4ikIwtoVQnddgrv8PFlCWgYCwkI+fp5dkvJ/IlUKMCy6tYrDhNIIKLFEAWCTxse+ABD4SClWA0zovAjcUJFi6EwahxZwoGqHhFA/4IqoICkyxQSKkbo0gDkuBXV4FRAJkRCnTgi2P28IcEfk5xpWppykFJVuScmEvDTEETAVJ6bEpypcADPkz3pvKVAICHChkC7siQ08zVqu4Q6hgIFEFZuEn/KMgRUkaBmAQs+cEHgIiHVH5EAFpIgW4+NT6LnaqhDwe/Ov7YOmWZp4MkiAWBIl0kAVsJWuzcYpdiNgddc0E8cKBAu/FElBwagMb88ZZKDRAkWJtkWhHh3wwUbKHQJN3wQAaXGR2LpArv5oFHRR34C7Mf6oLXZNfqBgNI7oOLhj1f8PaGpygHQ0xtP8MDVKwYTSKcgxr9/hS6/pCCAAg5M4B9/sWh1YP9/XSgQWRML/idBfKUc4IBET9lFjggKhDYZAELZJYEBI2BDB3ouNBEABwE8gAwiCcSYgAKqPdEVAG7scM8BPPZ4AIlM+OgjAgpMhRE24OVoBwsIFEGFA7ZkQQBWienWxmRa7XDjKZXhBdAeSmKQwgLuUVLICa6VEKIGcK2mQWoVZHCBXJblJUFkY06yAXlGsPIHBEYdYiWHb+WQBgaIJqqoHFNpgMGB7dT5ZQuG/WbBAIAUEEFNfwxAWpokTIXJAWdgoJ9kRFG2g5eDRpXSBpEIF0oEQFaZhDbaSFANRgqcJoEDRARLREtxOQpsPO906ZUeJgjQB6dZUPBAdwcF8KLXXRVQaKFcsRRLJ6vMiiCNKxRE8ECZKgUA3Va4arOAAqdGRWO7uMZH5AL05gvsjQbg6y4NCjQ1kw8TVGcbdoKGKx8j3bGH7nARBArqwi0gkFJBrZiXBQRbHoIgnhSjcEBKfD7c3HMhz+JIQSY3t8GGKW+SUhfUajxGzKd0IoHBNkNQK86ZYEqdzYA8AHQpqXRUm80oHs1CAgMoBxzRqvzs9CIKECC1JBp7enUpfXHApwVYNAfo16c4IrYPLVdSAJVob7IAtCBFQGHcs/RRdiUDPHA33oADEAIAOw==',
  2015. ),
  2016. 'note' => array(
  2017. 'type' => 'png',
  2018. 'data' => 'iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAAAAADFHGIkAAAAAmJLR0QAAKqNIzIAAAEESURBVHjaZZIhksMwDEV9voWFSwsLA0MLDf8VdARBUUNBQ1FBHcErZ5M0baXJjOPnb0vfLuMMn3H+lWMgBKL89A1Eq9Q9IrwB+gIOsnMPBR8giMclguQfBGS8x5xIoPQxnxqb4LL/eQ4l2AVNONP2ZshLCqJ3qqzWtT5pNgNnLU4OcNbuiqaLmFmHGhJ0TCMC99+f2wphlhaOYjuQVc0IIzLH2BRWfQoWsNSjct8AVop4rF3belTuVAb3MRj6kLrcTwtIy+g03V1vC57t1XrMzqfP5pln5yLTkk7+5UhstvOni1X3ixLEdf2c36+W0Q7kOb48hnSRLI/XdNPfX4kpMkgP5R+elfdkDPprQgAAAEN0RVh0U29mdHdhcmUAQCgjKUltYWdlTWFnaWNrIDQuMi44IDk5LzA4LzAxIGNyaXN0eUBteXN0aWMuZXMuZHVwb250LmNvbZG6IbgAAAAqdEVYdFNpZ25hdHVyZQAzYmQ3NDdjNWU0NTgwNzAwNmIwOTBkZDNlN2EyNmM0NBTTk/oAAAAOdEVYdFBhZ2UAMjR4MjQrMCswclsJMQAAAABJRU5ErkJggg==',
  2019. ),
  2020. );
  2021. Header('Content-Type: image/'.$images[$img]['type']);
  2022. echo base64_decode($images[$img]['data']);
  2023. };
  2024. // }}}
  2025. // {{{ displayHTMLProgress
  2026. function displayHTMLProgress($progress)
  2027. {
  2028. if (!(WEBINSTALLER && isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'])) {
  2029. return;
  2030. };
  2031. $msg = ob_get_contents();
  2032. ob_end_clean();
  2033. $msg = explode("\n", $msg);
  2034. foreach($msg as $key => $value) {
  2035. if (preg_match('/ok$/', $value)) {
  2036. $value = preg_replace('/(ok)$/', '<span class="green">\1</span>', $value);
  2037. };
  2038. if (preg_match('/failed$/', $value)) {
  2039. $value = preg_replace('/(failed)$/', '<span style="color: #ff0000">\1</span>', $value);
  2040. };
  2041. if (preg_match('/^install ok:/', $value)) {
  2042. //$value = preg_replace('/^(install ok:)/', '<span class="green">\1</span>', $value).'<br />';
  2043. //$msg = array($value); // if install succeeded: don't show the irritatingly verbose pear installer
  2044. $msg = array('<span class="green">ok</span><br />');
  2045. break;
  2046. };
  2047. if (preg_match('/^Warning:/', $value)) {
  2048. $value = '<span style="color: #ff0000">'.$value.'</span>';
  2049. };
  2050. $msg[$key] = $value;
  2051. };
  2052. $msg = implode('<br>', $msg);
  2053. $msg.='<script type="text/javascript"> parent.setprogress('.((int) $progress).'); </script>';
  2054. echo $msg;
  2055. ob_start();
  2056. };
  2057. // }}}
  2058. // {{{ displayHTMLDownloadProgress
  2059. function displayHTMLDownloadProgress($progress)
  2060. {
  2061. if (!(WEBINSTALLER && isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'])) {
  2062. return;
  2063. };
  2064. $msg = ob_get_contents();
  2065. ob_end_clean();
  2066. echo '<script type="text/javascript"> parent.setdownloadprogress('.((int) $progress).'); </script>';
  2067. ob_start();
  2068. echo $msg;
  2069. };
  2070. // }}}
  2071. // {{{ displayHTMLSetDownload
  2072. function displayHTMLSetDownload($file)
  2073. {
  2074. if (!(WEBINSTALLER && isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'])) {
  2075. return;
  2076. };
  2077. $msg = ob_get_contents();
  2078. ob_end_clean();
  2079. if ($file != null && $file != '') {
  2080. echo '<script type="text/javascript"> parent.setdownloadfile("'.$file.'"); </script>';
  2081. } else {
  2082. echo '<script type="text/javascript"> parent.unsetdownloadfile(); </script>';
  2083. }
  2084. ob_start();
  2085. echo $msg;
  2086. };
  2087. // }}}
  2088. // {{{ win32BrowseForFolder
  2089. /*
  2090. * Create a vbs script to browse the getfolder dialog, called
  2091. * by cscript, if it's available.
  2092. * $label is the label text in the header of the dialog box
  2093. *
  2094. * TODO:
  2095. * - Do not show Control panel
  2096. * - Replace WSH with calls to w32 as soon as callbacks work
  2097. * @Author Pierrre-Alain Joye
  2098. */
  2099. function win32BrowseForFolder($label)
  2100. {
  2101. global $ptmp;
  2102. static $wshSaved=false;
  2103. static $cscript='';
  2104. $wsh_browserfolder = 'Option Explicit
  2105. Dim ArgObj, var1, var2, sa, sFld
  2106. Set ArgObj = WScript.Arguments
  2107. Const BIF_EDITBOX = &H10
  2108. Const BIF_NEWDIALOGSTYLE = &H40
  2109. Const BIF_RETURNONLYFSDIRS = &H0001
  2110. Const BIF_DONTGOBELOWDOMAIN = &H0002
  2111. Const BIF_STATUSTEXT = &H0004
  2112. Const BIF_RETURNFSANCESTORS = &H0008
  2113. Const BIF_VALIDATE = &H0020
  2114. Const BIF_BROWSEFORCOMPUTER = &H1000
  2115. Const BIF_BROWSEFORPRINTER = &H2000
  2116. Const BIF_BROWSEINCLUDEFILES = &H4000
  2117. Const OFN_LONGNAMES = &H200000
  2118. Const OFN_NOLONGNAMES = &H40000
  2119. Const ssfDRIVES = &H11
  2120. Const ssfNETWORK = &H12
  2121. Set sa = CreateObject("Shell.Application")
  2122. var1=ArgObj(0)
  2123. Set sFld = sa.BrowseForFolder(0, var1, BIF_EDITBOX + BIF_VALIDATE + BIF_BROWSEINCLUDEFILES + BIF_RETURNFSANCESTORS+BIF_NEWDIALOGSTYLE , ssfDRIVES )
  2124. if not sFld is nothing Then
  2125. if not left(sFld.items.item.path,1)=":" Then
  2126. WScript.Echo sFld.items.item.path
  2127. Else
  2128. WScript.Echo "invalid"
  2129. End If
  2130. Else
  2131. WScript.Echo "cancel"
  2132. End If
  2133. ';
  2134. if( !$wshSaved){
  2135. $cscript = $ptmp.DIRECTORY_SEPARATOR."bf.vbs";
  2136. $fh = fopen($cscript,"wb+");
  2137. fwrite($fh,$wsh_browserfolder,strlen($wsh_browserfolder));
  2138. fclose($fh);
  2139. $wshSaved = true;
  2140. }
  2141. exec('cscript '.$cscript.' "'.$label.'" //noLogo',$arPath);
  2142. if($arPath[0]=='' || $arPath[0]=='cancel'){
  2143. return '';
  2144. } elseif ($arPath[0]=='invalid') {
  2145. echo "Invalid Path.\n";
  2146. return '';
  2147. }
  2148. return $arPath[0];
  2149. }
  2150. // }}}
  2151. // {{{ win32CreateRegEnv
  2152. /*
  2153. * Generates a registry addOn for Win32 platform
  2154. * This addon set PEAR environment variables
  2155. * @Author Pierrre-Alain Joye
  2156. */
  2157. function win32CreateRegEnv()
  2158. {
  2159. global $prefix, $bin_dir, $php_dir, $php_bin, $doc_dir, $data_dir, $test_dir, $temp_dir;
  2160. $nl = "\r\n";
  2161. $reg ='REGEDIT4'.$nl.
  2162. '[HKEY_CURRENT_USER\Environment]'.$nl.
  2163. '"PHP_PEAR_SYSCONF_DIR"="'.addslashes($prefix).'"'.$nl.
  2164. '"PHP_PEAR_INSTALL_DIR"="'.addslashes($php_dir).'"'.$nl.
  2165. '"PHP_PEAR_DOC_DIR"="'.addslashes($doc_dir).'"'.$nl.
  2166. '"PHP_PEAR_BIN_DIR"="'.addslashes($bin_dir).'"'.$nl.
  2167. '"PHP_PEAR_DATA_DIR"="'.addslashes($data_dir).'"'.$nl.
  2168. '"PHP_PEAR_PHP_BIN"="'.addslashes($php_bin).'"'.$nl.
  2169. '"PHP_PEAR_TEST_DIR"="'.addslashes($test_dir).'"'.$nl;
  2170. $fh = fopen($prefix.DIRECTORY_SEPARATOR.'PEAR_ENV.reg','wb');
  2171. if($fh){
  2172. fwrite($fh, $reg ,strlen($reg));
  2173. fclose($fh);
  2174. echo "
  2175. * WINDOWS ENVIRONMENT VARIABLES *
  2176. For convenience, a REG file is available under $prefix\\PEAR_ENV.reg .
  2177. This file creates ENV variables for the current user.
  2178. Double-click this file to add it to the current user registry.
  2179. ";
  2180. }
  2181. }
  2182. // }}}
  2183. // {{{ win32DetectPHPSAPI
  2184. /*
  2185. * Try to detect the kind of SAPI used by the
  2186. * the given php.exe.
  2187. * @Author Pierrre-Alain Joye
  2188. */
  2189. function win32DetectPHPSAPI()
  2190. {
  2191. global $php_bin,$php_sapi_name;
  2192. if (WEBINSTALLER) {
  2193. return $php_sapi_name;
  2194. }
  2195. if($php_bin!=''){
  2196. exec($php_bin.' -v', $res);
  2197. if(is_array($res)) {
  2198. if( isset($res[0]) && strpos($res[0],"(cli)")) {
  2199. return 'cli';
  2200. }
  2201. if( isset($res[0]) && strpos($res[0],"cgi")) {
  2202. return 'cgi';
  2203. } else {
  2204. return 'unknown';
  2205. }
  2206. }
  2207. }
  2208. return 'unknown';
  2209. }
  2210. // }}}
  2211. // {{{ getPhpiniPath
  2212. /*
  2213. * Get the php.ini file used with the current
  2214. * process or with the given php.exe
  2215. *
  2216. * Horrible hack, but well ;)
  2217. *
  2218. * Not used yet, will add the support later
  2219. * @Author Pierre-Alain Joye <paj@pearfr.org>
  2220. */
  2221. function getPhpiniPath()
  2222. {
  2223. $pathIni = get_cfg_var('cfg_file_path');
  2224. if( $pathIni && is_file($pathIni) ){
  2225. return $pathIni;
  2226. }
  2227. // Oh well, we can keep this too :)
  2228. // I dunno if get_cfg_var() is safe on every OS
  2229. if (WINDOWS) {
  2230. // on Windows, we can be pretty sure that there is a php.ini
  2231. // file somewhere
  2232. do {
  2233. $php_ini = PHP_CONFIG_FILE_PATH . DIRECTORY_SEPARATOR . 'php.ini';
  2234. if ( @file_exists($php_ini) ) break;
  2235. $php_ini = 'c:\winnt\php.ini';
  2236. if ( @file_exists($php_ini) ) break;
  2237. $php_ini = 'c:\windows\php.ini';
  2238. } while (false);
  2239. } else {
  2240. $php_ini = PHP_CONFIG_FILE_PATH . DIRECTORY_SEPARATOR . 'php.ini';
  2241. }
  2242. if( @is_file($php_ini) ){
  2243. return $php_ini;
  2244. }
  2245. // We re running in hackz&troubles :)
  2246. ob_implicit_flush(false);
  2247. ob_start();
  2248. phpinfo(INFO_GENERAL);
  2249. $strInfo = ob_get_contents ();
  2250. ob_end_clean();
  2251. ob_implicit_flush(true);
  2252. if ( php_sapi_name() != 'cli' ) {
  2253. $strInfo = strip_tags($strInfo,'<td>');
  2254. $arrayInfo = explode("</td>", $strInfo );
  2255. $cli = false;
  2256. } else {
  2257. $arrayInfo = explode("\n",$strInfo);
  2258. $cli = true;
  2259. }
  2260. foreach($arrayInfo as $val){
  2261. if ( strpos($val,"php.ini") ) {
  2262. if($cli){
  2263. list(,$pathIni) = explode('=>',$val);
  2264. } else {
  2265. $pathIni = strip_tags(trim($val) );
  2266. }
  2267. $pathIni = trim($pathIni);
  2268. if(is_file($pathIni)){
  2269. return $pathIni;
  2270. }
  2271. }
  2272. }
  2273. return false;
  2274. }
  2275. // }}}
  2276. // {{{ alterPhpIni
  2277. /*
  2278. * Not optimized, but seems to work, if some nice
  2279. * peardev will test it? :)
  2280. *
  2281. * @Author Pierre-Alain Joye <paj@pearfr.org>
  2282. */
  2283. function alterPhpIni($pathIni='')
  2284. {
  2285. global $php_dir, $prefix;
  2286. $iniSep = WINDOWS?';':':';
  2287. if( $pathIni=='' ){
  2288. $pathIni = getphpinipath();
  2289. }
  2290. $arrayIni = file($pathIni);
  2291. $i=0;
  2292. $found=0;
  2293. // Looks for each active include_path directives
  2294. foreach ( $arrayIni as $iniLine ) {
  2295. $iniLine = trim($iniLine);
  2296. $iniLine = str_replace(array("\n","\r"),array(),$iniLine);
  2297. if( preg_match("/^include_path/",$iniLine) ){
  2298. $foundAt[] = $i;
  2299. $found++;
  2300. }
  2301. $i++;
  2302. }
  2303. if ( $found ) {
  2304. $includeLine = $arrayIni[$foundAt[0]];
  2305. list(,$currentPath)=explode('=',$includeLine);
  2306. $currentPath = trim($currentPath);
  2307. if(substr($currentPath,0,1)=='"'){
  2308. $currentPath = substr($currentPath,1,strlen($currentPath)-2);
  2309. }
  2310. $arrayPath = explode($iniSep, $currentPath);
  2311. if( $arrayPath[0]=='.' ){
  2312. $newPath[0] = '.';
  2313. $newPath[1] = $php_dir;
  2314. array_shift($arrayPath);
  2315. } else {
  2316. $newPath[0] = $php_dir;
  2317. }
  2318. foreach( $arrayPath as $path ){
  2319. $newPath[]= $path;
  2320. }
  2321. } else {
  2322. $newPath[0] = '.';
  2323. $newPath[1] = $php_dir;
  2324. }
  2325. $nl = WINDOWS?"\r\n":"\n";
  2326. $includepath = 'include_path="'.implode($iniSep,$newPath).'"';
  2327. $newInclude = "$nl$nl;***** Added by go-pear$nl".
  2328. $includepath.
  2329. $nl.";*****".
  2330. $nl.$nl;
  2331. $arrayIni[$foundAt[0]] = $newInclude;
  2332. for( $i=1; $i<$found; $i++){
  2333. $arrayIni[$foundAt[$i]]=';'.trim($arrayIni[$foundAt[$i]]);
  2334. }
  2335. $newIni = implode("",$arrayIni);
  2336. if ( !($fh = @fopen($pathIni, "wb+")) ){
  2337. $prefixIni = $prefix.DIRECTORY_SEPARATOR."php.ini-gopear";
  2338. $fh = fopen($prefixIni, "wb+");
  2339. if ( !$fh ) {
  2340. echo
  2341. "
  2342. ******************************************************************************
  2343. WARNING! I cannot write to $pathIni nor in $prefix/php.ini-gopear. Please
  2344. modify manually your php.ini by adding:
  2345. $includepath
  2346. ";
  2347. return false;
  2348. } else {
  2349. fwrite($fh, $newIni, strlen($newIni));
  2350. fclose($fh);
  2351. echo
  2352. "
  2353. ******************************************************************************
  2354. WARNING! I cannot write to $pathIni, but I succesfully created a php.ini
  2355. under <$prefix/php.ini-gopear>. Please replace the file <$pathIni> with
  2356. <$prefixIni> or modify your php.ini by adding:
  2357. $includepath
  2358. ";
  2359. }
  2360. } else {
  2361. fwrite($fh, $newIni, strlen($newIni));
  2362. fclose($fh);
  2363. echo "
  2364. php.ini <$pathIni> include_path updated.
  2365. ";
  2366. }
  2367. return true;
  2368. }
  2369. ?>