Changeset 1296

Show
Ignore:
Timestamp:
09/20/07 13:34:18 (1 year ago)
Author:
benoitg
Message:
  • install.php: Hopefully fix #384, and remove pages unlikely to be implemented for 1.0
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wifidog-auth/CHANGELOG

    r1295 r1296  
    11# $Id$ 
     22007-09-20 Benoit Grégoire  <bock@step.polymtl.ca> 
     3        * install.php:  Hopefully fix #384, and remove pages unlikely to be implemented for 1.0 
     4         
    252007-09-18 Benoit Grégoire  <bock@step.polymtl.ca> 
    36        * portal/index.php:  Add a call to garbage_collect() to fix #367 
    4          
     7 
    582007-09-17 Benoit Grégoire  <bock@step.polymtl.ca> 
    69        * SmartyWifidog:  If ANY of the mandatory dependencies (not just smarty) are missing, user will be redirected to the install script 
  • trunk/wifidog-auth/wifidog/install.php

    r1294 r1296  
    172172'lib/feedpressreview', 
    173173'config.php' 
    174     ); 
     174); 
    175175 
    176176$smarty_full_url = 'http://smarty.php.net/do_download.php?download_file=Smarty-2.6.14.tar.gz'; 
     
    182182'message' => '', 
    183183'file' => 'lib/smarty/Smarty.class.php' 
    184         ), 
     184), 
    185185'simplepie' => array ( 
    186186'needed' => 0, 
     
    189189'file' => 'lib/simplepie/simplepie.inc', 
    190190'svn_source' => 'http://svn.simplepie.org/simplepie/branches/1.0/' 
    191         ), 
     191), 
    192192'feedpressreview' => array ( 
    193193'needed' => 0, 
     
    196196'file' => 'lib/feedpressreview/FeedPressReview.inc', 
    197197'svn_source' => 'http://projects.coeus.ca/svn/feedpressreview/trunk/' 
    198        
     198
    199199); 
    200200 
     
    211211'depend' => 'return 1;', 
    212212'message' => '&nbsp;' 
    213         ), 
     213), 
    214214'GMAPS_HOTSPOTS_MAP_ENABLED' => array ( 
    215215'title' => 'Google Maps Support', 
    216216'depend' => 'return 1;', 
    217217'message' => '&nbsp;' 
    218        
     218
    219219); 
    220220 
     
    251251        '', 
    252252        '' 
    253             ); 
     253        ); 
    254254        $key = preg_replace($pattern, $replacement, trim($key)); 
    255255        $value = preg_replace($pattern, $replacement, trim($value)); 
     
    281281 
    282282EndHTML; 
    283 if (array_key_exists($num +1, $dataArray)) 
     283        if (array_key_exists($num +1, $dataArray)) 
    284284        print "&nbsp;-&nbsp;"; 
    285285    } 
     
    297297 
    298298 
    299     ################################### 
    300     # 
    301     /*function debugButton() { 
    302     print <<<EndHTML 
    303     <p><INPUT TYPE="button" VALUE="Debug" ONCLICK="javascript: window.location.reload(true);"></p> 
    304     EndHTML; 
    305     } */ 
    306  
    307     ################################### 
    308     # In development 
    309     /*function installPackage($pkg_name, $full_url, $copy) { 
    310     print "<h1>$pkg_name installation</h1>\n"; 
    311     chdir(WIFIDOG_ABS_FILE_PATH."tmp"); 
    312     list($url, $filename) = split ("=", $full_url); 
    313  
    314     print "Download source code ($filename) : "; 
    315     if (!file_exists($filename)) 
    316     Dependency::execVerbose("wget \"$url\"", $output, $return); 
    317     if (!file_exists($filename)) // wget success if file exists 
    318     Dependency::execVerbose("wget \"$full_url\" 2>&1", $output_array, $return); 
    319     if (!file_exists($filename)) { 
    320     print "<B STYLE=\"color:red\">Error</b><p>Current working directory : <em>$basepath/tmp/smarty</em>"; 
    321     $output = implode("\n", $output_array); 
    322     print "<pre><em>wget \"$full_url\"</em>\n$output</pre>"; 
    323     exit(); 
    324     } else { 
    325     print "OK<BR>"; 
     299################################### 
     300
     301/*function debugButton() { 
     302 print <<<EndHTML 
     303 <p><INPUT TYPE="button" VALUE="Debug" ONCLICK="javascript: window.location.reload(true);"></p> 
     304 EndHTML; 
     305 } */ 
     306 
     307################################### 
     308# In development 
     309/*function installPackage($pkg_name, $full_url, $copy) { 
     310 print "<h1>$pkg_name installation</h1>\n"; 
     311 chdir(WIFIDOG_ABS_FILE_PATH."tmp"); 
     312 list($url, $filename) = split ("=", $full_url); 
     313 
     314 print "Download source code ($filename) : "; 
     315 if (!file_exists($filename)) 
     316 Dependency::execVerbose("wget \"$url\"", $output, $return); 
     317 if (!file_exists($filename)) // wget success if file exists 
     318 Dependency::execVerbose("wget \"$full_url\" 2>&1", $output_array, $return); 
     319 if (!file_exists($filename)) { 
     320 print "<B STYLE=\"color:red\">Error</b><p>Current working directory : <em>$basepath/tmp/smarty</em>"; 
     321 $output = implode("\n", $output_array); 
     322 print "<pre><em>wget \"$full_url\"</em>\n$output</pre>"; 
     323 exit(); 
     324 } else { 
     325 print "OK<BR>"; 
     326 } 
     327 
     328 print "Uncompressing : "; 
     329 $dirname = array_shift(split(".tar.gz", $filename)); 
     330 
     331 if (!file_exists($dirname)) 
     332 Dependency::execVerbose("tar -xzf $dirname.tar.gz", $output, $return); 
     333 print "OK<BR>"; 
     334 print "Copying : "; 
     335 if (!file_exists('../../lib/smarty/Smarty.class.php')); 
     336 Dependency::execVerbose("cp -r $dirname/libs/* ../../lib/smarty", $output, $return); 
     337 Dependency::execVerbose("cp -r $dirname/libs/* ../../lib/smarty", $output, $return); 
     338 $copy 
     339 print "OK<BR>"; 
     340 }*/ 
     341 
     342################################### 
     343
     344function saveConfig($data) { 
     345    print "<!-- saveConfig DATA=($data) -->\n"; # DEBUG 
     346 
     347    global $CONFIG_FILE; 
     348 
     349    $contentArray = file(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE"); 
     350    $fd = fopen(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE", 'w'); 
     351 
     352    $defineArrayToken = array (); 
     353    $defineArrayToken = explode('|', $data); 
     354 
     355    foreach ($defineArrayToken as $nameValue) { 
     356        list ($name, $value) = explode('=', $nameValue); 
     357        $defineArray[$name] = $value; # New define value ($name and value) 
     358        #print "K=$name V=$value<BR>"; # DEBUG 
    326359    } 
    327360 
    328     print "Uncompressing : "; 
    329     $dirname = array_shift(split(".tar.gz", $filename)); 
    330  
    331     if (!file_exists($dirname)) 
    332     Dependency::execVerbose("tar -xzf $dirname.tar.gz", $output, $return); 
    333     print "OK<BR>"; 
    334     print "Copying : "; 
    335     if (!file_exists('../../lib/smarty/Smarty.class.php')); 
    336     Dependency::execVerbose("cp -r $dirname/libs/* ../../lib/smarty", $output, $return); 
    337     Dependency::execVerbose("cp -r $dirname/libs/* ../../lib/smarty", $output, $return); 
    338     $copy 
    339     print "OK<BR>"; 
    340     }*/ 
    341  
    342     ################################### 
    343     # 
    344     function saveConfig($data) { 
    345         print "<!-- saveConfig DATA=($data) -->\n"; # DEBUG 
    346  
    347         global $CONFIG_FILE; 
    348  
    349         $contentArray = file(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE"); 
    350         $fd = fopen(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE", 'w'); 
    351  
    352         $defineArrayToken = array (); 
    353         $defineArrayToken = explode('|', $data); 
    354  
    355         foreach ($defineArrayToken as $nameValue) { 
    356             list ($name, $value) = explode('=', $nameValue); 
    357             $defineArray[$name] = $value; # New define value ($name and value) 
    358             #print "K=$name V=$value<BR>"; # DEBUG 
    359         } 
    360  
    361         foreach ($contentArray as $line) { 
    362             #print "L=$line<BR>\n"; 
    363             if (preg_match("/^define\((.+)\);/", $line, $matchesArray)) { 
    364                 list ($key, $value) = explode(',', $matchesArray[1]); 
    365                 $pattern = array ( 
     361    foreach ($contentArray as $line) { 
     362        #print "L=$line<BR>\n"; 
     363        if (preg_match("/^define\((.+)\);/", $line, $matchesArray)) { 
     364            list ($key, $value) = explode(',', $matchesArray[1]); 
     365            $pattern = array ( 
    366366                "/^'/", 
    367367                "/'$/" 
    368                 ); 
    369                 $replacement = array ( 
     368            ); 
     369            $replacement = array ( 
    370370                '', 
    371371                '' 
     
    392392                    fwrite($fd, $line); # Write the same line in config.php 
    393393                } 
    394             } 
    395             else { 
    396                 fwrite($fd, $line); # Write the line (not a define line). Ex: Commented text 
    397             } 
     394        } 
     395        else { 
     396            fwrite($fd, $line); # Write the line (not a define line). Ex: Commented text 
    398397        } 
    399398    } 
    400  
    401     ################################### 
    402     # MAIN 
    403     switch ($page) { 
    404         case 'permission' : 
    405             print "<h1>Permissions</h1>"; 
    406  
    407             $process_info_user_id = posix_getpwuid(posix_getuid()); 
    408  
    409             if($process_info_user_id){ 
    410                 $process_username = $process_info_user_id['name']; 
     399
     400 
     401################################### 
     402# MAIN 
     403switch ($page) { 
     404    case 'permission' : 
     405        print "<h1>Permissions</h1>"; 
     406 
     407        $process_info_user_id = posix_getpwuid(posix_getuid()); 
     408 
     409        if($process_info_user_id){ 
     410            $process_username = $process_info_user_id['name']; 
     411        } 
     412        else { 
     413            //Posix functions aren't available on windows 
     414            $process_username = 'unknown_user'; 
     415        } 
     416        $process_info_group_id = posix_getgrgid(posix_getegid()); 
     417        if($process_info_group_id){ 
     418            $process_group = $process_info_group_id['name']; 
     419        } 
     420        else { 
     421            //Posix functions aren't available on windows 
     422            $process_group = 'unknown_group'; 
     423        } 
     424        $cmd_mkdir = ''; 
     425        $cmd_chown = ''; 
     426        $error = 0; 
     427 
     428        print "<p><em>HTTP daemon UNIX username/group</em>: $process_username/$process_group</p>"; 
     429        #    print "<p><em>HTTPD group</em>: $process_group<BR</p>"; 
     430        print "<p><table BORDER=\"1\"><tr><td><em>Directory</em></td></td><td><em>Owner</em></td><td><em>Writable</em></td></tr>\n"; 
     431 
     432        foreach ($dir_array as $dir) { 
     433            print "<tr><td>$dir</td>"; 
     434            if (!file_exists(WIFIDOG_ABS_FILE_PATH . "$dir")) { 
     435                print "<TD COLSPAN=\"2\" STYLE=\"text-align:center;\">Missing</td></tr>\n"; 
     436                $cmd_mkdir .= WIFIDOG_ABS_FILE_PATH . "$dir "; 
     437                $cmd_chown .= WIFIDOG_ABS_FILE_PATH . "$dir "; 
     438                $error = 1; 
     439                continue; 
     440            } 
     441 
     442            $dir_info = posix_getpwuid(fileowner(WIFIDOG_ABS_FILE_PATH . "$dir")); 
     443            if($dir_info) { 
     444                $dir_owner_username = $dir_info['name']; 
    411445            } 
    412446            else { 
    413447                //Posix functions aren't available on windows 
    414                 $process_username = 'unknown_user'; 
    415             } 
    416             $process_info_group_id = posix_getgrgid(posix_getegid()); 
    417             if($process_info_group_id){ 
    418                 $process_group = $process_info_group_id['name']; 
     448                $dir_owner_username = fileowner(WIFIDOG_ABS_FILE_PATH . "$dir"); 
     449            } 
     450            print "<td>$dir_owner_username</td>"; 
     451 
     452            if (is_writable(WIFIDOG_ABS_FILE_PATH . "$dir")) { 
     453                print "<td>YES</td>"; 
    419454            } 
    420455            else { 
    421                 //Posix functions aren't available on windows 
    422                 $process_group = 'unknown_group'; 
    423             } 
    424             $cmd_mkdir = ''; 
    425             $cmd_chown = ''; 
    426             $error = 0; 
    427  
    428             print "<p><em>HTTP daemon UNIX username/group</em>: $process_username/$process_group</p>"; 
    429             #    print "<p><em>HTTPD group</em>: $process_group<BR</p>"; 
    430             print "<p><table BORDER=\"1\"><tr><td><em>Directory</em></td></td><td><em>Owner</em></td><td><em>Writable</em></td></tr>\n"; 
    431  
    432             foreach ($dir_array as $dir) { 
    433                 print "<tr><td>$dir</td>"; 
    434                 if (!file_exists(WIFIDOG_ABS_FILE_PATH . "$dir")) { 
    435                     print "<TD COLSPAN=\"2\" STYLE=\"text-align:center;\">Missing</td></tr>\n"; 
    436                     $cmd_mkdir .= WIFIDOG_ABS_FILE_PATH . "$dir "; 
    437                     $cmd_chown .= WIFIDOG_ABS_FILE_PATH . "$dir "; 
    438                     $error = 1; 
    439                     continue; 
    440                 } 
    441  
    442                 $dir_info = posix_getpwuid(fileowner(WIFIDOG_ABS_FILE_PATH . "$dir")); 
    443                 if($dir_info) { 
    444                     $dir_owner_username = $dir_info['name']; 
    445                 } 
    446                 else { 
    447                     //Posix functions aren't available on windows 
    448                     $dir_owner_username = fileowner(WIFIDOG_ABS_FILE_PATH . "$dir"); 
    449                 } 
    450                 print "<td>$dir_owner_username</td>"; 
    451  
    452                 if (is_writable(WIFIDOG_ABS_FILE_PATH . "$dir")) { 
    453                     print "<td>YES</td>"; 
    454                 } 
    455                 else { 
    456                     print "<td>NO</td>"; 
    457                     $cmd_chown .= WIFIDOG_ABS_FILE_PATH . "$dir "; 
    458                     $error = 1; 
    459                 } 
    460                 print "</tr>\n"; 
    461             } 
    462             print "</table>\n"; 
    463  
    464             if ($error != 1) { 
    465                 navigation(array ( 
    466                 array ( 
     456                print "<td>NO</td>"; 
     457                $cmd_chown .= WIFIDOG_ABS_FILE_PATH . "$dir "; 
     458                $error = 1; 
     459            } 
     460            print "</tr>\n"; 
     461        } 
     462        print "</table>\n"; 
     463 
     464        if ($error != 1) { 
     465            navigation(array ( 
     466            array ( 
    467467                "title" => "Next", 
    468468                "page" => "version" 
    469                    
     469               
    470470                )); 
    471             } 
    472             else { 
    473                 refreshButton(); 
    474                 print "<p>You need to allow UNIX user <em>$process_username</em> to write to these directories (mkdir, chown or chmod)</p>"; 
    475                 if (!empty ($cmd_mkdir) || !empty ($cmd_mkdir)) 
    476                 print "<p><b>For instance, you may want to use the following commands</b> :</p>\n"; 
    477                 if (!empty ($cmd_mkdir)) 
    478                 print "mkdir $cmd_mkdir <br />"; 
    479                 if (!empty ($cmd_chown)) 
    480                 print "chgrp -R $process_group $cmd_chown;<br/>chmod g+wx $cmd_chown;<br/>"; 
    481                 print "<p>After permissions modification done, hit the REFRESH button to see the NEXT button and continue with the installation"; 
    482             } 
    483             break; 
    484             ################################### 
    485         case 'version' : 
    486             print "<h1>Checking Dependency</h1>"; 
    487             $error = 0; 
    488             $userData['error']=&$error; 
    489             require_once("classes/DependenciesList.php"); 
    490             print DependenciesList::getAdminUIStatic($userData); 
     471        } 
     472        else { 
    491473            refreshButton(); 
    492             if ($error != 1) { 
    493                 navigation(array ( 
    494                 array ( 
     474            print "<p>You need to allow UNIX user <em>$process_username</em> to write to these directories (mkdir, chown or chmod)</p>"; 
     475            if (!empty ($cmd_mkdir) || !empty ($cmd_mkdir)) 
     476            print "<p><b>For instance, you may want to use the following commands</b> :</p>\n"; 
     477            if (!empty ($cmd_mkdir)) 
     478            print "mkdir $cmd_mkdir <br />"; 
     479            if (!empty ($cmd_chown)) 
     480            print "chgrp -R $process_group $cmd_chown;<br/>chmod g+wx $cmd_chown;<br/>"; 
     481            print "<p>After permissions modification done, hit the REFRESH button to see the NEXT button and continue with the installation"; 
     482        } 
     483        break; 
     484        ################################### 
     485    case 'version' : 
     486        print "<h1>Checking Dependency</h1>"; 
     487        $error = 0; 
     488        $userData['error']=&$error; 
     489        require_once("classes/DependenciesList.php"); 
     490        print DependenciesList::getAdminUIStatic($userData); 
     491        refreshButton(); 
     492        if ($error != 1) { 
     493            navigation(array ( 
     494            array ( 
    495495                "title" => "Back", 
    496496                "page" => "permission" 
     
    501501                ) 
    502502                )); 
    503            
    504  
    505             break; 
    506 ################################### 
    507         case 'simplepie' : // Download, uncompress and install SimplePie 
    508             print "<h1>SimplePie installation</h1>\n"; 
    509  
    510             if ($neededPackages['simplepie']['available']) { 
    511                 print "Already installed !<BR>"; 
    512                 navigation(array ( 
    513                 array ( 
     503       
     504 
     505        break; 
     506        ################################### 
     507    case 'simplepie' : // Download, uncompress and install SimplePie 
     508        print "<h1>SimplePie installation</h1>\n"; 
     509 
     510        if ($neededPackages['simplepie']['available']) { 
     511            print "Already installed !<BR>"; 
     512            navigation(array ( 
     513            array ( 
    514514                "title" => "Back", 
    515515                "page" => "smarty" 
     
    520520                ) 
    521521                )); 
    522            
    523             elseif ($action == 'install') { 
    524                require_once (dirname(__FILE__) . '/include/common.php'); 
    525                 print "Download source code frpm svn($filename) : "; 
    526                 Dependency::execVerbose("svn co ".escapeshellarg($neededPackages['simplepie']['svn_source'])." ".escapeshellarg(WIFIDOG_ABS_FILE_PATH."lib/simplepie"), $output, $return); 
    527                 #Dependency::execVerbose("locale", $output, $return); 
    528  
    529                 refreshButton(); 
    530                 navigation(array ( 
    531                 array ( 
     522       
     523        elseif ($action == 'install') { 
     524            require_once (dirname(__FILE__) . '/include/common.php'); 
     525            print "Download source code frpm svn($filename) : "; 
     526            Dependency::execVerbose("svn co ".escapeshellarg($neededPackages['simplepie']['svn_source'])." ".escapeshellarg(WIFIDOG_ABS_FILE_PATH."lib/simplepie"), $output, $return); 
     527            #Dependency::execVerbose("locale", $output, $return); 
     528 
     529            refreshButton(); 
     530            navigation(array ( 
     531            array ( 
    532532                "title" => "Back", 
    533533                "page" => "smarty" 
     
    538538                ) 
    539539                )); 
    540            
    541             else { 
    542                 print<<< EndHTML 
     540       
     541        else { 
     542            print<<< EndHTML 
    543543<p><A HREF="http://simplepie.org/">SimplePie</A> is a dependency of provides an RSS parser in PHP. It is required for RssPressReview.  It's is recommended to install it, if you don't, RSS feeds options will be disabled. 
    544544 
    545545<p>Do you want to install SimplePie ? 
    546546EndHTML; 
    547 navigation(array ( 
    548                 array ( 
     547            navigation(array ( 
     548            array ( 
    549549                "title" => "Back", 
    550550                "page" => "smarty" 
     
    560560                ) 
    561561                )); 
    562            
    563             break; 
    564             ################################### 
    565         case 'feedpressreview' : // Download, uncompress and install feedpressreview 
    566             print "<h1>Feed press review installation</h1>\n"; 
    567  
    568             if ($neededPackages['feedpressreview']['available']) { 
    569                 print "Already installed !<BR>"; 
    570                 navigation(array ( 
    571                 array ( 
     562       
     563        break; 
     564        ################################### 
     565    case 'feedpressreview' : // Download, uncompress and install feedpressreview 
     566        print "<h1>Feed press review installation</h1>\n"; 
     567 
     568        if ($neededPackages['feedpressreview']['available']) { 
     569            print "Already installed !<BR>"; 
     570            navigation(array ( 
     571            array ( 
    572572                "title" => "Back", 
    573573                "page" => "simplepie" 
     
    578578                ) 
    579579                )); 
    580            
    581             elseif ($action == 'install') { 
    582                require_once (dirname(__FILE__) . '/include/common.php'); 
    583                 print "Download source code frpm svn($filename) : "; 
    584                 Dependency::execVerbose("svn co ".escapeshellarg($neededPackages['feedpressreview']['svn_source'])." ".escapeshellarg(WIFIDOG_ABS_FILE_PATH."lib/feedpressreview"), $output, $return); 
    585                 #Dependency::execVerbose("locale", $output, $return); 
    586  
    587                 refreshButton(); 
    588                 navigation(array ( 
    589                 array ( 
     580       
     581        elseif ($action == 'install') { 
     582            require_once (dirname(__FILE__) . '/include/common.php'); 
     583            print "Download source code frpm svn($filename) : "; 
     584            Dependency::execVerbose("svn co ".escapeshellarg($neededPackages['feedpressreview']['svn_source'])." ".escapeshellarg(WIFIDOG_ABS_FILE_PATH."lib/feedpressreview"), $output, $return); 
     585            #Dependency::execVerbose("locale", $output, $return); 
     586 
     587            refreshButton(); 
     588            navigation(array ( 
     589            array ( 
    590590                "title" => "Back", 
    591591                "page" => "smarty" 
     
    596596                ) 
    597597                )); 
    598            
    599             else { 
    600                 print<<< EndHTML 
     598       
     599        else { 
     600            print<<< EndHTML 
    601601<p><A HREF="http://projects.coeus.ca/feedpressreview/">Feed press review</A> is a dependency that provides a Feed aggregator in PHP.  It is recommended to install it.  If you don't, RSS feeds options will be disabled. 
    602602 
    603603<p>Do you want to install FeedPressReview ? 
    604604EndHTML; 
    605 navigation(array ( 
    606                 array ( 
     605            navigation(array ( 
     606            array ( 
    607607                "title" => "Back", 
    608608                "page" => "simplepie" 
     
    618618                ) 
    619619                )); 
    620            
    621             break; 
    622             ################################### 
    623         case 'jpgraph' : // Download, uncompress and install JpGraph library 
    624             print "<h1>JpGraph installation</h1>\n"; 
    625  
    626             if ($neededPackages['jpgraph']['available']) { 
    627                 print "Already installed !<BR>"; 
    628                 navigation(array ( 
    629                 array ( 
     620       
     621        break; 
     622        ################################### 
     623    case 'jpgraph' : // Download, uncompress and install JpGraph library 
     624        print "<h1>JpGraph installation</h1>\n"; 
     625 
     626        if ($neededPackages['jpgraph']['available']) { 
     627            print "Already installed !<BR>"; 
     628            navigation(array ( 
     629            array ( 
    630630                "title" => "Back", 
    631631                "page" => "feedpressreview" 
     
    636636                ) 
    637637                )); 
    638             } 
    639             elseif ($action == 'install') { 
    640                 chdir(WIFIDOG_ABS_FILE_PATH . "tmp"); 
    641                 $filename = array_pop(preg_split("/\//", $jpgraph_full_url)); 
    642  
    643                 print "Download source code ($filename) : "; 
    644                 if (!file_exists($filename)) 
    645                 Dependency::execVerbose("wget \"$jpgraph_full_url\" 2>&1", $output, $return); 
    646                 if (!file_exists($filename)) { # Error occured, print output of wget 
    647                     print "<B STYLE=\"color:red\">Error</b><p>Current working directory : <em>$basepath/tmp</em>"; 
    648                     $output = implode("\n", $output); 
    649                     print "<pre><em>wget \"$jpgraph_full_url\"</em>\n$output</pre>"; 
    650                     exit (); 
    651                 } 
    652                 else { 
    653                     print "OK<BR>"; 
    654                 } 
    655  
    656                 print "Uncompressing : "; 
    657                 $dirname = array_shift(split(".tar.gz", $filename)); 
    658                 if (!file_exists($dirname)) 
    659                 Dependency::execVerbose("tar -xzf $dirname.tar.gz", $output, $return); 
     638        } 
     639        elseif ($action == 'install') { 
     640            chdir(WIFIDOG_ABS_FILE_PATH . "tmp"); 
     641            $filename = array_pop(preg_split("/\//", $jpgraph_full_url)); 
     642 
     643            print "Download source code ($filename) : "; 
     644            if (!file_exists($filename)) 
     645            Dependency::execVerbose("wget \"$jpgraph_full_url\" 2>&1", $output, $return); 
     646            if (!file_exists($filename)) { # Error occured, print output of wget 
     647                print "<B STYLE=\"color:red\">Error</b><p>Current working directory : <em>$basepath/tmp</em>"; 
     648                $output = implode("\n", $output); 
     649                print "<pre><em>wget \"$jpgraph_full_url\"</em>\n$output</pre>"; 
     650                exit (); 
     651            } 
     652            else { 
    660653                print "OK<BR>"; 
    661  
    662                 print "Copying : "; 
    663                 if (!file_exists(WIFIDOG_ABS_FILE_PATH."lib/jpgraph/jpgraph.php")) 
    664                 Dependency::execVerbose("cp $dirname/src/* ".WIFIDOG_ABS_FILE_PATH."lib/jpgraph", $output, $return); # TODO : Utiliser JPGRAPH_REL_PATH 
    665  
    666                 print "OK<BR>"; 
    667  
    668                 refreshButton(); 
    669                 navigation(array ( 
    670                 array ( 
     654            } 
     655 
     656            print "Uncompressing : "; 
     657            $dirname = array_shift(split(".tar.gz", $filename)); 
     658            if (!file_exists($dirname)) 
     659            Dependency::execVerbose("tar -xzf $dirname.tar.gz", $output, $return); 
     660            print "OK<BR>"; 
     661 
     662            print "Copying : "; 
     663            if (!file_exists(WIFIDOG_ABS_FILE_PATH."lib/jpgraph/jpgraph.php")) 
     664            Dependency::execVerbose("cp $dirname/src/* ".WIFIDOG_ABS_FILE_PATH."lib/jpgraph", $output, $return); # TODO : Utiliser JPGRAPH_REL_PATH 
     665 
     666            print "OK<BR>"; 
     667 
     668            refreshButton(); 
     669            navigation(array ( 
     670            array ( 
    671671                "title" => "Back", 
    672672                "page" => "feedpressreview" 
     
    677677                ) 
    678678                )); 
    679            
    680             else { 
    681                 print<<< EndHTML 
     679       
     680        else { 
     681            print<<< EndHTML 
    682682<p><A HREF="http://www.aditus.nu/jpgraph/">JpGraph</A> is a Object-Oriented Graph creating library for PHP. 
    683683JpGraph is not currently use by Wifidog (will be use for statistique graph in a later version). You can skip this installation if your not a developper. 
     
    685685<p>Do you want to install JpGraph ? 
    686686EndHTML; 
    687 navigation(array ( 
    688                 array ( 
     687            navigation(array ( 
     688            array ( 
    689689                "title" => "Back", 
    690690                "page" => "feedpressreview" 
     
    700700                ) 
    701701                )); 
    702            
    703             break; 
    704             ################################### 
    705         case 'database' : 
    706             ### TODO : Valider en javascript que les champs soumit ne sont pas vide 
    707             #          Pouvoir choisir le port de la DB ??? 
    708             print<<< EndHTML 
     702       
     703        break; 
     704        ################################### 
     705    case 'database' : 
     706        ### TODO : Valider en javascript que les champs soumit ne sont pas vide 
     707        #          Pouvoir choisir le port de la DB ??? 
     708        print<<< EndHTML 
    709709<h1>Database access configuration</h1> 
    710710<BR> 
     
    729729EndHTML; 
    730730 
    731             navigation(array ( 
    732             array ( 
     731        navigation(array ( 
     732        array ( 
    733733            "title" => "Back", 
    734734            "page" => "simplepie" 
     
    742742            break; 
    743743            ################################### 
    744         case 'testdatabase' : 
    745             print "<h1>Database connection</h1>"; 
    746             /* TODO : Tester la version minimale requise de Postgresql                */ 
    747  
    748             print "<UL><LI>Postgresql database connection : "; 
    749  
    750             $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; 
    751             $ptr_connexion = pg_connect($conn_string); 
    752  
    753             if ($ptr_connexion == TRUE) { 
    754                 print "Success<BR>"; 
    755             } 
    756             else { 
    757                 print "Unable to connect to database on $CONF_DATABASE_HOST<BR>The database must be online to continue.<BR>Please go back and retry with correct values"; 
    758                 refreshButton(); 
    759                 navigation(array(array("title" => "Back", "page" => "database"))); 
    760                 die(); 
    761             } 
    762  
    763             $postgresql_info = pg_version(); 
    764             #        $postgresql_info['server']; 
    765             #        if ($postgresql_info['server'] > $requiredPostgeSQLVersion) { Todo : Do something } 
    766  
    767             print "</UL>"; 
     744    case 'testdatabase' : 
     745        print "<h1>Database connection</h1>"; 
     746        /* TODO : Tester la version minimale requise de Postgresql                */ 
     747 
     748        print "<UL><LI>Trying to open a Postgresql database connection : "; 
     749 
     750        $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; 
     751        $ptr_connexion = pg_connect($conn_string); 
     752 
     753        if ($ptr_connexion == TRUE) { 
     754            print "Success!<BR>"; 
     755        } 
     756        else { 
     757            printf ("<p>Unable to connect!  The server has to be online, the database \"%s\" must exist, and the postgresql.conf and pg_hba.conf must allow the user \"%s\" to open a connection to it on host \"%s\" to continue.  See the error above for hints on what the problem may be.", $CONF_DATABASE_NAME, $CONF_DATABASE_USER, $CONF_DATABASE_HOST); 
     758            print "<p>Please go back and retry with correct values, or fix your server configuration.</p>"; 
    768759            refreshButton(); 
    769             navigation(array ( 
    770             array ( 
     760            navigation(array(array("title" => "Back", "page" => "database"))); 
     761            die(); 
     762        } 
     763        print "</li>"; 
     764               print "<li>";  
     765        $postgresql_info = pg_version(); 
     766        printf ("PostgreSQL server version: %s", $postgresql_info['server']);        print "</li>"; 
     767         
     768        #        if ($postgresql_info['server'] > $requiredPostgeSQLVersion) { Todo : Do something } 
     769 
     770 
     771        print "</UL>"; 
     772        refreshButton(); 
     773        navigation(array ( 
     774        array ( 
    771775            "title" => "Back", 
    772776            "page" => "database" 
    773                     ), 
     777            ), 
    774778            array ( 
    775779            "title" => "Next", 
    776780            "page" => "dbinit" 
    777                    
     781           
    778782            )); 
    779783            break; 
    780784            ################################### 
    781         case 'dbinit' : 
    782             print "<h1>Database initialisation</h1>"; 
    783             # SQL are executed with PHP, some lignes need to be commented. 
    784             $file_db_version = 'UNKNOW'; 
    785             $patterns[0] = '/CREATE DATABASE wifidog/'; 
    786             $patterns[1] = '/\\\connect/'; 
    787             //The following is strictly for compatibility with postgresql 7.4 
    788             $patterns[2] = '/COMMENT/'; 
    789             $patterns[3] = '/^SET /m'; 
    790             $patterns[4] = '/CREATE PROCEDURAL LANGUAGE/'; 
    791             $patterns[5] = '/ALTER SEQUENCE/'; 
    792             $patterns[6] = '/::regclass/';//To fix incompatibility of postgres < 8.1 with later nextval() calling convention 
    793             $replacements[0] = '-- '; 
    794             $replacements[1] = '-- '; 
    795             $replacements[2] = '-- '; 
    796             $replacements[3] = '-- '; 
    797             $replacements[4] = '-- '; 
    798             $replacements[5] = '-- '; 
    799             $replacements[6] = '::text';             
    800  
    801             $content_schema_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-schema.sql") or die("<em>Error</em>: Can not open $basepath/../sql/wifidog-postgres-schema.sql"); # Read SQL schema file 
    802             $content_schema = implode("", $content_schema_array); 
    803             $content_data_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-initial-data.sql"); # Read SQL initial data file 
    804             $content_data = implode("", $content_data_array); 
    805  
    806             $db_schema_version = ''; # Schema version query from database 
    807             $file_schema_version = ''; # Schema version from define(REQUIRED_SCHEMA_VERSION) in schema_validate.php 
    808  
    809             $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; 
    810             $connection = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==<BR>"); 
    811  
    812             if (preg_match("/\('schema_version', '(\d+)'\);/", $content_data, $matchesArray)) # Get schema_version from initial data file 
    813             $file_db_version = $matchesArray[1]; 
    814  
    815             $contentArray = file(WIFIDOG_ABS_FILE_PATH . "include/schema_validate.php"); 
    816             foreach ($contentArray as $line) { 
    817                 #print "$line<BR>"; # Debug 
    818                 if (preg_match("/^define\('REQUIRED_SCHEMA_VERSION', (\d+)\);/", $line, $matchesArray)) { 
    819                     #print "REQUIRED_SCHEMA_VERSION = " . $matchesArray[1] . "<BR>"; 
    820                     $file_schema_version = $matchesArray[1]; 
    821                 } 
    822             } 
    823  
    824             # Get current database schema version (if defined) 
    825             $sql = "SELECT * FROM schema_info WHERE tag='schema_version'"; 
    826             if ($result = @ pg_query($connection, $sql)) { # The @ remove warning display 
    827                 $result_array = pg_fetch_all($result); 
    828                 $db_shema_version = $result_array[0]['value']; 
    829  
    830                 print "<p>On <em>$CONF_DATABASE_HOST</em>, Database <em>$CONF_DATABASE_NAME</em> exists and is "; 
    831                 if ($db_shema_version == $file_schema_version) { 
    832                     print "up to date (shema version <em>$db_shema_version</em>)."; 
    833                     navigation(array ( 
    834                     array ( 
    835                     "title" => "Back", 
    836                     "page" => "database" 
    837                             ), 
    838                     array ( 
    839                     "title" => "Next", 
    840                     "page" => "options" 
    841                             ) 
    842                     )); 
    843                 } 
    844                 elseif ($db_shema_version < $file_schema_version) { 
    845                     print "at schema version <em>$db_shema_version</em>. The required schema version is <em>$file_schema_version</em><p>Please upgrade the database"; 
    846                     navigation(array ( 
    847                     array ( 
    848                     "title" => "Back", 
    849                     "page" => "database" 
    850                             ), 
    851                     array ( 
    852                     "title" => "Upgrade", 
    853                     "page" => "schema_validate" 
    854                             ), 
    855                     array ( 
    856                     "title" => "Next", 
    857                     "page" => "options" 
    858                             ) 
    859                     )); 
    860                 } 
    861                 else { 
    862                     print "Error : Unexpected result"; 
    863                 } 
    864                 exit (); 
    865             } 
    866  
    867             print "<UL><LI>Creating wifidog database schema : "; 
     785    case 'dbinit' : 
     786        print "<h1>Database initialisation</h1>"; 
     787        # SQL are executed with PHP, some lines need to be commented out. 
     788        $file_db_version = 'UNKNOW'; 
     789        $patterns[0] = '/CREATE DATABASE wifidog/'; 
     790        $patterns[1] = '/\\\connect/'; 
     791        //The following is strictly for compatibility with postgresql 7.4 
     792        $patterns[2] = '/COMMENT/'; 
     793        $patterns[3] = '/^SET /m'; 
     794        $patterns[4] = '/CREATE PROCEDURAL LANGUAGE/'; 
     795        $patterns[5] = '/ALTER SEQUENCE/'; 
     796        $patterns[6] = '/::regclass/';//To fix incompatibility of postgres < 8.1 with later nextval() calling convention 
     797        $replacements[0] = '-- '; 
     798        $replacements[1] = '-- '; 
     799        $replacements[2] = '-- '; 
     800        $replacements[3] = '-- '; 
     801        $replacements[4] = '-- '; 
     802        $replacements[5] = '-- '; 
     803        $replacements[6] = '::text'; 
     804 
     805        $content_schema_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-schema.sql") or die("<em>Error</em>: Can not open $basepath/../sql/wifidog-postgres-schema.sql"); # Read SQL schema file 
     806        $content_schema = implode("", $content_schema_array); 
     807        $content_data_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-initial-data.sql"); # Read SQL initial data file 
     808        $content_data = implode("", $content_data_array); 
     809 
     810        $db_schema_version = ''; # Schema version query from database 
     811        $file_schema_version = ''; # Schema version from define(REQUIRED_SCHEMA_VERSION) in schema_validate.php 
     812 
     813        $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; 
     814        $connection = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==<BR>"); 
     815 
     816        if (preg_match("/\('schema_version', '(\d+)'\);/", $content_data, $matchesArray)) # Get schema_version from initial data file 
     817        $file_db_version = $matchesArray[1]; 
     818 
     819        $contentArray = file(WIFIDOG_ABS_FILE_PATH . "include/schema_validate.php"); 
     820        foreach ($contentArray as $line) { 
     821            #print "$line<BR>"; # Debug 
     822            if (preg_match("/^define\('REQUIRED_SCHEMA_VERSION', (\d+)\);/", $line, $matchesArray)) { 
     823                #print "REQUIRED_SCHEMA_VERSION = " . $matchesArray[1] . "<BR>"; 
     824                $file_schema_version = $matchesArray[1]; 
     825            } 
     826        } 
     827 
     828        # Get current database schema version (if defined) 
     829        $schemaVersionSql = "SELECT * FROM schema_info WHERE tag='schema_version'"; 
     830 
     831        if (!@ pg_query($connection, $schemaVersionSql)) { # The @ remove warning display 
     832 
     833            print "<UL><LI>Database did not exist, creating wifidog database schema : "; 
    868834            $content_schema = preg_replace($patterns, $replacements, $content_schema); # Comment bad SQL lines 
    869835            //echo "<pre>$content_schema</pre>"; 
    870836            $result = pg_query($connection, $content_schema) or die("<em>" . pg_last_error() . "</em> <=<BR>"); 
    871             print "OK"; 
    872