Changeset 895

Show
Ignore:
Timestamp:
01/08/06 21:38:12 (7 years ago)
Author:
benoitg
Message:

005-01-08 Benoit Gr�goire <bock@…>

  • common.php: Improve path detection code, and start moving PATH detection back to a central location. You should NEVER go to any $_SERVER[] variables for path related stuff, all you need is already available in defines.
  • UserReport?.php: Remove dangling reference to BASEPATH.
  • install.php: Use centralised path detection.
Location:
trunk/wifidog-auth
Files:
2 added
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/ChangeLog

    r891 r895  
     12005-01-08 Benoit Grégoire  <bock@step.polymtl.ca> 
     2        * common.php:  Improve path detection code, and start moving PATH detection back to a central location. 
     3        You should NEVER go to any $_SERVER[] variables for path related stuff, all you need is already available 
     4         in defines. 
     5        * UserReport.php:  Remove dangling reference to BASEPATH. 
     6        * install.php:  Use centralised path detection. 
     7         
    182005-01-04 Benoit Grégoire  <bock@step.polymtl.ca> 
    29        * config.php, common.php:  Completely remove SYSTEM_PATH from config.php, making one less config option to manage.  It is now autodetected. 
  • trunk/wifidog-auth/wifidog/classes/SmartyWifidog.php

    r882 r895  
    5454    require_once('lib/smarty/Smarty.class.php'); 
    5555} else { 
    56     $exploded_path = explode("/", $_SERVER['SCRIPT_NAME']);     # Split directories in token 
    57     array_pop($exploded_path);                                  # Remove install.php from the list 
    58     $system_path = implode("/", $exploded_path);                # Build the system_path for the auth-server 
    59     print "Redirection to Wifidog web-base install since Smarty is missing <META HTTP-EQUIV=Refresh CONTENT=\"1; URL=$system_path/install.php\">"; 
     56             # Build the system_path for the auth-server 
     57    print "Redirection to Wifidog web-base install since Smarty is missing <META HTTP-EQUIV=Refresh CONTENT=\"5; URL=".BASE_URL_PATH."/install.php\">"; 
    6058    exit(); 
    6159} 
  • trunk/wifidog-auth/wifidog/classes/User.php

    r880 r895  
    356356                if ($user_info['validation_grace_time_expired'] == 't') 
    357357                { 
    358                     $errmsg = sprintf(_("Sorry, your %s minutes grace period to retrieve your email and validate your account has now expired. You will have to connect to the internet and validate your account from another location or create a new account. For help, please %s click here %s."), $user_info['validation_grace_time_expired'], '<a href="'.BASEPATH.'faq.php'.'">', '</a>'); 
     358                    $errmsg = sprintf(_("Sorry, your %s minutes grace period to retrieve your email and validate your account has now expired. You will have to connect to the internet and validate your account from another location or create a new account. For help, please %s click here %s."), $user_info['validation_grace_time_expired'], '<a href="'.BASE_URL_PATH.'faq.php'.'">', '</a>'); 
    359359                    $retval = false; 
    360360                } 
  • trunk/wifidog-auth/wifidog/include/common.php

    r891 r895  
    11<?php 
     2 
    23 
    34/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
     
    4445error_reporting(E_ALL); 
    4546 
     47require_once ('path_defines_base.php'); 
    4648/** 
    4749 * Include configuration file 
    4850 */ 
    4951cmnRequireConfig(); 
    50  
    51  
    52 /** 
    53  * Path of WiFiDOG auth server installation 
    54  * ======================================== 
    55  * 
    56  * SYSTEM_PATH must be set to the url path needed to reach the wifidog 
    57  * directory. 
    58  * 
    59  * Normally '/' or '/wifidog/', depending on where configure your 
    60  * document root. 
    61  * 
    62  * Gateway configuration must match this as well. 
    63  */ 
    64    $path_tmp = str_replace ( $_SERVER['DOCUMENT_ROOT'], '', __FILE__); 
    65    $path_tmp = str_replace ( 'include/common.php', '', $path_tmp); 
    66    define('SYSTEM_PATH', $path_tmp); 
    67    //echo SYSTEM_PATH;exit; 
    68 /** 
    69  * Add system path of WiFiDog installation to PHPs include path 
    70  */ 
    71   
    72 set_include_path(cmnHomeDir() . PATH_SEPARATOR . get_include_path()); 
    73  
    74 function undo_magic_quotes() 
    75 { 
    76     if (get_magic_quotes_gpc()) 
    77     { 
    78         $_GET = array_map_recursive('stripslashes', $_GET); 
    79         $_POST = array_map_recursive('stripslashes', $_POST); 
    80         $_COOKIE = array_map_recursive('stripslashes', $_COOKIE); 
    81         $_REQUEST = array_map_recursive('stripslashes', $_REQUEST); 
    82     } 
    83 } 
    84  
    85 if (!function_exists('array_map_recursive')) 
    86 { 
    87     function array_map_recursive($function, $data) 
    88     { 
    89         foreach ($data as $i => $item) 
    90         { 
    91             $data[$i] = is_array($item) ? array_map_recursive($function, $item) : $function ($item); 
    92         } 
    93         return $data; 
    94     } 
    95 } 
     52require_once ('path_defines_url_content.php'); 
     53 
     54 
    9655undo_magic_quotes(); 
    9756 
    98 require_once('classes/EventLogging.php'); 
    99 require_once('classes/AbstractDb.php'); 
    100 require_once('classes/Dependencies.php'); 
     57require_once ('classes/EventLogging.php'); 
     58require_once ('classes/AbstractDb.php'); 
     59require_once ('classes/Locale.php');//Must be included for gettext handling 
     60require_once ('classes/Dependencies.php'); 
    10161// require_once('classes/Session.php'); 
    10262 
     
    10666$db = new AbstractDb(); 
    10767 
    108 /* NEVER edit these, as they mush match the C code of the gateway */ 
     68/* Constant shared with the gateway 
     69 * NEVER edit these, as they mush match the C code of the gateway */ 
    10970define('ACCOUNT_STATUS_ERROR', -1); 
    11071define('ACCOUNT_STATUS_DENIED', 0); 
     
    12586define('TOKEN_USED', 'USED'); 
    12687 
    127 $token_to_text[TOKEN_UNUSED] = "Unused"; 
    128 $token_to_text[TOKEN_INUSE] = "In use"; 
    129 $token_to_text[TOKEN_USED] = "Used"; 
     88$token_to_text[TOKEN_UNUSED] = _("Unused"); 
     89$token_to_text[TOKEN_INUSE] = _("In use"); 
     90$token_to_text[TOKEN_USED] = _("Used"); 
    13091 
    13192define('STAGE_LOGIN', "login"); 
     
    13596define('ONLINE_STATUS_ONLINE', 1); 
    13697define('ONLINE_STATUS_OFFLINE', 2); 
    137  
    138 /* This section deals with sessions */ 
    139  
     98/* End Constant shared with the gateway*/ 
     99 
     100/* session constants, perhaps this coulb be moved to Session.php?  benoitg, 2005-08-01 */ 
    140101define('SESS_USERNAME_VAR', 'SESS_USERNAME'); 
    141102define('SESS_USER_ID_VAR', 'SESS_USER_ID'); 
     
    146107define('SESS_GW_PORT_VAR', 'SESS_GW_PORT'); 
    147108define('SESS_GW_ID_VAR', 'SESS_GW_ID'); 
    148  
    149 /* End */ 
    150  
    151 /* This section deals with PATHs */ 
    152 define('BASE_NON_SSL_PATH', 'http://'.$_SERVER['SERVER_NAME'].SYSTEM_PATH); 
    153  
    154 //echo "<pre>";print_r($_SERVER);echo "</pre>"; 
    155  
    156 $curent_url = 'http'; 
    157 if ($_SERVER['SERVER_PORT'] == '443') 
    158 { 
    159     $curent_url .= 's'; 
    160 } 
    161 $curent_url .= '://'.$_SERVER['HTTP_HOST']; 
    162 if ($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) 
    163     $curent_url .= ':'.$_SERVER['SERVER_PORT']; 
    164 $curent_url .= $_SERVER['REQUEST_URI']; 
    165 define('CURRENT_REQUEST_URL', $curent_url); 
    166  
    167 if (SSL_AVAILABLE) 
    168 { 
    169     define('BASE_SSL_PATH', 'https://'.$_SERVER['SERVER_NAME'].SYSTEM_PATH); 
    170 } 
    171 else 
    172 { 
    173     define('BASE_SSL_PATH', BASE_NON_SSL_PATH); 
    174 } 
    175  
    176 /* If we actually ARE in SSL mode, make all URLS http:// to avoid security warnings. */ 
    177 if (isset ($_SERVER['HTTPS'])) 
    178 { 
    179     define('BASE_URL_PATH', BASE_SSL_PATH); 
    180 } 
    181 else 
    182 { 
    183     define('BASE_URL_PATH', BASE_NON_SSL_PATH); 
    184 } 
    185  
    186 if (empty ($_REQUEST['gw_id'])) 
    187 { 
    188     define('CURRENT_NODE_ID', DEFAULT_NODE_ID); 
    189 } 
    190 else 
    191 { 
    192     define('CURRENT_NODE_ID', trim($_REQUEST['gw_id'])); 
    193 } 
    194  
    195 define('DEFAULT_CONTENT_URL', BASE_URL_PATH.LOCAL_CONTENT_REL_PATH.DEFAULT_NODE_ID.'/'); 
    196 define('DEFAULT_CONTENT_PHP_RELATIVE_PATH', LOCAL_CONTENT_REL_PATH.DEFAULT_NODE_ID.'/'); 
    197  
    198 define('NODE_CONTENT_URL', BASE_URL_PATH.LOCAL_CONTENT_REL_PATH.CURRENT_NODE_ID.'/'); 
    199 define('NODE_CONTENT_PHP_RELATIVE_PATH', LOCAL_CONTENT_REL_PATH.CURRENT_NODE_ID.'/'); 
    200  
    201 define('COMMON_CONTENT_URL', BASE_URL_PATH.LOCAL_CONTENT_REL_PATH.'common/'); 
    202  
    203 define('GENERIC_OBJECT_ADMIN_ABS_HREF', BASE_URL_PATH.'admin/generic_object_admin.php'); 
    204 define('CONTENT_ADMIN_ABS_HREF', BASE_URL_PATH.'admin/content_admin.php'); 
    205  
     109/* End session constants */ 
     110 
     111 
     112 
     113function undo_magic_quotes() { 
     114    if (get_magic_quotes_gpc()) { 
     115        $_GET = array_map_recursive('stripslashes', $_GET); 
     116        $_POST = array_map_recursive('stripslashes', $_POST); 
     117        $_COOKIE = array_map_recursive('stripslashes', $_COOKIE); 
     118        $_REQUEST = array_map_recursive('stripslashes', $_REQUEST); 
     119    } 
     120} 
     121 
     122if (!function_exists('array_map_recursive')) { 
     123    function array_map_recursive($function, $data) { 
     124        foreach ($data as $i => $item) { 
     125            $data[$i] = is_array($item) ? array_map_recursive($function, $item) : $function ($item); 
     126        } 
     127        return $data; 
     128    } 
     129} 
    206130/** Convert a password hash form a NoCat passwd file into the same format as get_password_hash(). 
    207131* @return The 32 character hash. 
    208132*/ 
    209 function convert_nocat_password_hash($hash) 
    210 { 
     133function convert_nocat_password_hash($hash) { 
    211134    return $hash.'=='; 
    212135} 
    213136 
    214 function iso8601_date($unix_timestamp) 
    215 { 
     137function iso8601_date($unix_timestamp) { 
    216138    $tzd = date('O', $unix_timestamp); 
    217139    $tzd = substr(chunk_split($tzd, 3, ':'), 0, 6); 
     
    221143 
    222144/** Cleanup dangling tokens and connections from the database, left if a gateway crashed, etc. */ 
    223 function garbage_collect() 
    224 { 
     145function garbage_collect() { 
    225146    global $db; 
    226147 
     
    232153 
    233154/** Get the url from the local content_specific folder if the file exists, and from the default content folder otherwise */ 
    234 function find_local_content_url($filename) 
    235 { 
     155function find_local_content_url($filename) { 
    236156    //echo "find_local_content_url():  Looking for:                  ".NODE_CONTENT_PHP_RELATIVE_PATH.$filename."<br>\n"; 
    237     if (is_file(NODE_CONTENT_PHP_RELATIVE_PATH.$filename)) 
    238     { 
     157    if (is_file(NODE_CONTENT_PHP_RELATIVE_PATH.$filename)) { 
    239158        $retval = NODE_CONTENT_URL.$filename; 
    240159    } 
    241     else 
    242     { 
     160    else { 
    243161        $retval = DEFAULT_CONTENT_URL.$filename; 
    244162    } 
     
    248166 
    249167/** Return a 32 byte guid valid for database use */ 
    250 function get_guid() 
    251 { 
     168function get_guid() { 
    252169    return md5(uniqid(rand(), true)); 
    253170} 
    254171 
    255172/** like the php function print_r(), but the way it was meant to be... */ 
    256 function pretty_print_r($param) 
    257 { 
     173function pretty_print_r($param) { 
    258174    echo "\n<pre>\n"; 
    259175    print_r($param); 
     
    262178 
    263179/** pop directory path */ 
    264 function cmnPopDir($dirname=null, $popcount=1) { 
    265   if (empty($dirname)) $dirname = dirname($_SERVER['PHP_SELF']); 
    266   if ($dirname === DIRECTORY_SEPARATOR) return DIRECTORY_SEPARATOR; 
    267   if (substr($dirname,-1,1) === DIRECTORY_SEPARATOR) $popcount++; 
    268  
    269   $popped = implode(DIRECTORY_SEPARATOR, array_slice(explode(DIRECTORY_SEPARATOR, $dirname), 0, -$popcount)); 
    270  
    271   return empty($popped) ? DIRECTORY_SEPARATOR : substr($popped,-1,1) === DIRECTORY_SEPARATOR ? $popped : 
    272     $popped . DIRECTORY_SEPARATOR; 
     180function cmnPopDir($dirname = null, $popcount = 1) { 
     181    if (empty ($dirname)) 
     182        $dirname = dirname($_SERVER['PHP_SELF']); 
     183    if ($dirname === DIRECTORY_SEPARATOR) 
     184        return DIRECTORY_SEPARATOR; 
     185    if (substr($dirname, -1, 1) === DIRECTORY_SEPARATOR) 
     186        $popcount ++; 
     187 
     188    $popped = implode(DIRECTORY_SEPARATOR, array_slice(explode(DIRECTORY_SEPARATOR, $dirname), 0, - $popcount)); 
     189 
     190    return empty ($popped) ? DIRECTORY_SEPARATOR : substr($popped, -1, 1) === DIRECTORY_SEPARATOR ? $popped : $popped.DIRECTORY_SEPARATOR; 
    273191} 
    274192 
    275193function cmnDirectorySlash($dirname) { 
    276   return empty($dirname) ? DIRECTORY_SEPARATOR : substr($dirname,-1,1) === DIRECTORY_SEPARATOR ? $dirname : 
    277     $dirname . DIRECTORY_SEPARATOR; 
     194    return empty ($dirname) ? DIRECTORY_SEPARATOR : substr($dirname, -1, 1) === DIRECTORY_SEPARATOR ? $dirname : $dirname.DIRECTORY_SEPARATOR; 
    278195} 
    279196 
    280197/** search parent directory hierarchy for a file */ 
    281198function cmnSearchParentDirectories($dirname, $searchfor) { 
    282   $pieces = explode(DIRECTORY_SEPARATOR, $dirname); 
    283   $is_absolute = substr($dirname,0,1) === DIRECTORY_SEPARATOR ? 1 : 0; 
    284  
    285   for ($i=count($pieces); $i > $is_absolute; $i--) { 
    286     $filename = implode(DIRECTORY_SEPARATOR, array_merge(array_slice($pieces,0,$i), array($searchfor))); 
    287     if (file_exists($filename)) return $filename; 
    288   } 
    289  
    290   return false; 
    291 } 
    292  
    293 /** get the execution home directory */ 
    294 function cmnHomeDir() { 
    295   if (defined('BASEPATH')) { 
    296     // the old way of setting the home directory 
    297     $basedir = constant('BASEPATH'); 
    298   } 
    299   elseif (!empty($_SERVER['DOCUMENT_ROOT'])) { 
    300     // the new way of setting the home directory 
    301     $basedir = $_SERVER["DOCUMENT_ROOT"] . ( defined('SYSTEM_PATH') ? constant('SYSTEM_PATH') : DIRECTORY_SEPARATOR ); 
    302   } 
    303   elseif (!empty($_SERVER['PHP_SELF'])) { 
    304     // look to the name of the executing file 
    305     $basedir = dirname($_SERVER['PHP_SELF']); 
    306   } 
    307   else { 
    308     // look to the path name of this file (common.php) 
    309     $basedir = cmnPopDir( dirname(__FILE__) ); 
    310   } 
    311  
    312   $path_to_config = cmnSearchParentDirectories($basedir, 'config.php'); 
    313   if (empty($path_to_config)) $path_to_config = cmnSearchParentDirectories($basedir, 'local.config.php'); 
    314  
    315   return empty($path_to_config) ? false : cmnDirectorySlash(dirname($path_to_config)); 
     199    $pieces = explode(DIRECTORY_SEPARATOR, $dirname); 
     200    $is_absolute = substr($dirname, 0, 1) === DIRECTORY_SEPARATOR ? 1 : 0; 
     201 
     202    for ($i = count($pieces); $i > $is_absolute; $i --) { 
     203        $filename = implode(DIRECTORY_SEPARATOR, array_merge(array_slice($pieces, 0, $i), array ($searchfor))); 
     204        if (file_exists($filename)) 
     205            return $filename; 
     206    } 
     207 
     208    return false; 
    316209} 
    317210 
    318211/** join file path pieces together */ 
    319212function cmnJoinPath() { 
    320   $fullpath = ''; 
    321  
    322   //$arguments = func_get_args(); 
    323  
    324   for ($i=0; $i < func_num_args(); $i++) { 
    325     $pathelement = func_get_arg($i); 
    326     if ($pathelement=='') continue; 
    327  
    328     if ($fullpath=='') $fullpath = $pathelement; 
    329     elseif (substr($fullpath,-1,1)==DIRECTORY_SEPARATOR) { 
    330       if (substr($pathelement,0,1)==DIRECTORY_SEPARATOR) 
    331         $fullpath .= substr($pathelement,1); 
    332       else 
    333         $fullpath .= $pathelement; 
    334     } 
    335     else { 
    336       if (substr($pathelement,0,1)==DIRECTORY_SEPARATOR) 
    337         $fullpath .= $pathelement; 
    338       else 
    339         $fullpath .= DIRECTORY_SEPARATOR . $pathelement; 
    340     } 
    341   } 
    342  
    343   return $fullpath; 
     213    $fullpath = ''; 
     214 
     215    //$arguments = func_get_args(); 
     216 
     217    for ($i = 0; $i < func_num_args(); $i ++) { 
     218        $pathelement = func_get_arg($i); 
     219        if ($pathelement == '') 
     220            continue; 
     221 
     222        if ($fullpath == '') 
     223            $fullpath = $pathelement; 
     224        elseif (substr($fullpath, -1, 1) == DIRECTORY_SEPARATOR) { 
     225            if (substr($pathelement, 0, 1) == DIRECTORY_SEPARATOR) 
     226                $fullpath .= substr($pathelement, 1); 
     227            else 
     228                $fullpath .= $pathelement; 
     229        } 
     230        else { 
     231            if (substr($pathelement, 0, 1) == DIRECTORY_SEPARATOR) 
     232                $fullpath .= $pathelement; 
     233            else 
     234                $fullpath .= DIRECTORY_SEPARATOR.$pathelement; 
     235        } 
     236    } 
     237 
     238    return $fullpath; 
    344239} 
    345240 
    346241/** find a named file in the include path */ 
    347 function cmnFindPackage($rel_path, $private=false) { 
    348   $basepath = cmnHomeDir(); 
    349  
    350   $paths = isset($private) && ($private===true || $private==='PRIVATE') ? array($basepath) : 
    351     explode(PATH_SEPARATOR, get_include_path()); 
    352  
    353   foreach ($paths as $topdir) { 
    354     $package = cmnJoinPath($topdir, $rel_path); 
    355     if (file_exists($package)) { 
    356       if ($private) 
    357         return $package; 
    358       else 
    359         return $rel_path; 
    360     } 
    361   } 
    362  
    363   return false;                 // package was not found 
     242function cmnFindPackage($rel_path, $private = false) { 
     243 
     244    $paths = isset ($private) && ($private === true || $private === 'PRIVATE') ? array (WIFIDOG_ABS_FILE_PATH) : explode(PATH_SEPARATOR, get_include_path()); 
     245 
     246    foreach ($paths as $topdir) { 
     247        $package = cmnJoinPath($topdir, $rel_path); 
     248        if (file_exists($package)) { 
     249            if ($private) 
     250                return $package; 
     251            else 
     252                return $rel_path; 
     253        } 
     254    } 
     255 
     256    return false; // package was not found 
    364257} 
    365258 
    366259/** require_once a named file */ 
    367 function cmnRequirePackage($rel_path, $private=false) { 
    368   $basepath = cmnHomeDir(); 
    369  
    370   $paths = isset($private) && ($private===true || $private==='PRIVATE') ? array($basepath) : 
    371     explode(PATH_SEPARATOR, get_include_path()); 
    372  
    373   foreach ($paths as $topdir) { 
    374     $package = cmnJoinPath($topdir, $rel_path); 
    375     if (file_exists($package)) { 
    376       if ($private) 
    377         @require_once $package; 
    378       else 
    379         @require_once $rel_path; 
    380  
    381       return true;              // package was found 
    382     } 
    383   } 
    384  
    385   return false;                 // package was not found 
     260function cmnRequirePackage($rel_path, $private = false) { 
     261 
     262    $paths = isset ($private) && ($private === true || $private === 'PRIVATE') ? array (WIFIDOG_ABS_FILE_PATH) : explode(PATH_SEPARATOR, get_include_path()); 
     263 
     264    foreach ($paths as $topdir) { 
     265        $package = cmnJoinPath($topdir, $rel_path); 
     266        if (file_exists($package)) { 
     267            if ($private) 
     268                @ require_once $package; 
     269            else 
     270                @ require_once $rel_path; 
     271 
     272            return true; // package was found 
     273        } 
     274    } 
     275 
     276    return false; // package was not found 
    386277} 
    387278 
    388279/** include_once a named file */ 
    389 function cmnIncludePackage($rel_path, $private=false) { 
    390   $basepath = cmnHomeDir(); 
    391  
    392   $paths = isset($private) && ($private===true || $private==='PRIVATE') ? array($basepath) : 
    393     explode(PATH_SEPARATOR, get_include_path()); 
    394  
    395   foreach ($paths as $topdir) { 
    396     $package = cmnJoinPath($topdir, $rel_path); 
    397     if (file_exists($package)) { 
    398       if ($private) 
    399         @include_once $package; 
    400       else 
    401         @include_once $rel_path; 
    402  
    403       return true;              // package was found 
    404     } 
    405   } 
    406  
    407   return false;                 // package was not found 
    408 } 
    409  
    410 function cmnRequireConfig($config_file='config.php') { 
    411   global $AVAIL_LOCALE_ARRAY;   // so that nobody has to change their custom config.php 
    412   $config_path = cmnSearchParentDirectories(dirname(__FILE__), $config_file); 
    413   if (!empty($config_path)) require_once($config_path); 
     280function cmnIncludePackage($rel_path, $private = false) { 
     281 
     282    $paths = isset ($private) && ($private === true || $private === 'PRIVATE') ? array (WIFIDOG_ABS_FILE_PATH) : explode(PATH_SEPARATOR, get_include_path()); 
     283 
     284    foreach ($paths as $topdir) { 
     285        $package = cmnJoinPath($topdir, $rel_path); 
     286        if (file_exists($package)) { 
     287            if ($private) 
     288                @ include_once $package; 
     289            else 
     290                @ include_once $rel_path; 
     291 
     292            return true; // package was found 
     293        } 
     294    } 
     295 
     296    return false; // package was not found 
     297} 
     298 
     299function cmnRequireConfig($config_file = 'config.php') { 
     300    global $AVAIL_LOCALE_ARRAY; // so that nobody has to change their custom config.php 
     301    $config_path = cmnSearchParentDirectories(dirname(__FILE__), $config_file); 
     302    if (!empty ($config_path)) 
     303        require_once ($config_path); 
    414304} 
    415305 
     
    421311 * End: 
    422312 */ 
    423  
    424313?> 
     314 
  • trunk/wifidog-auth/wifidog/install.php

    r894 r895  
    11<?php 
     2 
    23 
    34/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
     
    4445 */ 
    4546 
    46 empty($_REQUEST['page'])   ? $page    = 'Welcome' : $page    = $_REQUEST['page'];   # The page to be loaded 
    47 empty($_REQUEST['action']) ? $action  = ''        : $action  = $_REQUEST['action']; # The action to be done (in page) 
    48 empty($_REQUEST['debug'])  ? $debug   = 0         : $debug   = $_REQUEST['debug'];  # Use for MySQL debugging 
    49 empty($_REQUEST['config']) ? $config  = ''        : $config  = $_REQUEST['config']; # Store data to be saved in config.php 
    50  
    51 $exploded_path = explode("/", $_SERVER['SCRIPT_FILENAME']); # Split directories in token 
    52 array_pop($exploded_path);                                  # Remove install.php from the list 
    53 $basepath = implode("/", $exploded_path);                   # Build the basepath for this script 
    54  
    55 $exploded_path = explode("/", $_SERVER['SCRIPT_NAME']);     # Split directories in token 
    56 array_pop($exploded_path);                                  # Remove install.php from the list 
    57 $system_path = implode("/", $exploded_path);                # Build the system_path for the auth-server 
     47require_once ('include/path_defines_base.php'); 
     48 
     49empty ($_REQUEST['page']) ? $page = 'Welcome' : $page = $_REQUEST['page']; # The page to be loaded 
     50empty ($_REQUEST['action']) ? $action = '' : $action = $_REQUEST['action']; # The action to be done (in page) 
     51empty ($_REQUEST['debug']) ? $debug = 0 : $debug = $_REQUEST['debug']; # Use for MySQL debugging 
     52empty ($_REQUEST['config']) ? $config = '' : $config = $_REQUEST['config']; # Store data to be saved in config.php 
    5853 
    5954# Security : Minimal access validation is use by asking user to retreive a random password in a local file. This prevent remote user to access unprotected installation script. It's dummy, easy to implement and better than nothing. 
     
    6257$password_file = '/tmp/dog_cookie.txt'; 
    6358if (!file_exists($password_file)) { 
    64   srand(date("s")); 
    65   $possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
    66   $password = ""; 
    67   while(strlen($random_password)<8) { 
    68     $random_password .= substr($possible_charactors, rand()%(strlen($possible_charactors)), 1); 
    69   } 
    70   $fd = fopen($password_file, 'w'); 
    71   fwrite($fd, $random_password); 
    72   fclose($fd); 
     59    srand(date("s")); 
     60    $possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
     61    $password = ""; 
     62    while (strlen($random_password) < 8) { 
     63        $random_password .= substr($possible_charactors, rand() % (strlen($possible_charactors)), 1); 
     64    } 
     65    $fd = fopen($password_file, 'w'); 
     66    fwrite($fd, $random_password); 
     67    fclose($fd); 
    7368} 
    7469 
     
    8176 
    8277if ($page != 'Welcome') { 
    83   if (isset($_SERVER['PHP_AUTH_PW'])) { 
    84     #echo "PHP_AUTH_USER=(" . $_SERVER['PHP_AUTH_USER'] . ") PHP_AUTH_PW=(" . $_SERVER['PHP_AUTH_PW'] . ")"; # DEBUG 
    85     if ($password == $_SERVER['PHP_AUTH_PW']) 
    86       $auth = true; 
    87   } 
     78    if (isset ($_SERVER['PHP_AUTH_PW'])) { 
     79        #echo "PHP_AUTH_USER=(" . $_SERVER['PHP_AUTH_USER'] . ") PHP_AUTH_PW=(" . $_SERVER['PHP_AUTH_PW'] . ")"; # DEBUG 
     80        if ($password == $_SERVER['PHP_AUTH_PW']) 
     81            $auth = true; 
     82    } 
    8883} 
    8984else 
    90   $auth = true; 
     85    $auth = true; 
    9186 
    9287if (!$auth) { # Ask user for the passorwd 
    93   header('WWW-Authenticate: Basic realm="Private"'); 
    94   header('HTTP/1.0 401 Unauthorized'); 
    95   echo "Authorization Required !"; 
    96   exit; 
     88    header('WWW-Authenticate: Basic realm="Private"'); 
     89    header('HTTP/1.0 401 Unauthorized'); 
     90    echo "Authorization Required !"; 
     91    exit; 
    9792} 
    9893# End of Security validation 
    9994 
    100 print <<<EndHTML 
     95print<<<EndHTML 
    10196<HTML> 
    10297<HEAD> 
     
    159154 
    160155# Minimal version needed 
    161 $requiredPHPVersion       = '5.0.0'; 
    162 $requiredMySQLVersion     = '0.0.0'; // Todo 
     156$requiredPHPVersion = '5.0.0'; 
     157$requiredMySQLVersion = '0.0.0'; // Todo 
    163158$requiredPostgeSQLVersion = '0.0.0'; // Todo 
    164159 
    165160# Needed files/directories with write access 
    166 $dir_array = array('tmp', 'tmp/magpie_cache', 'lib/smarty', 'tmp/smarty/templates_c', 'lib/magpie', 'lib/Phlickr', 'config.php'); 
    167  
    168 $smarty_full_url    = 'http://smarty.php.net/do_download.php?download_file=Smarty-2.6.7.tar.gz'; 
     161$dir_array = array ('tmp', 'tmp/magpie_cache', 'lib/smarty', 'tmp/smarty/templates_c', 'lib/magpie', 'lib/Phlickr', 'config.php'); 
     162 
     163$smarty_full_url = 'http://smarty.php.net/do_download.php?download_file=Smarty-2.6.7.tar.gz'; 
    169164$magpierss_full_url = 'http://easynews.dl.sourceforge.net/sourceforge/magpierss/magpierss-0.71.1.tar.gz'; 
    170 $phlickr_full_url   = 'http://easynews.dl.sourceforge.net/sourceforge/phlickr/Phlickr-0.2.4.tgz'; 
    171  
    172 $neededPackages = array( 
    173   'smarty'    => array('needed' => 1, 'available' => 0, 'message' => '', 'file' => 'lib/smarty/Smarty.class.php'), 
    174   'magpierss' => array('needed' => 0, 'available' => 0, 'message' => '', 'file' => 'lib/magpie/rss_fetch.inc'), 
    175   'phlickr'   => array('needed' => 0, 'available' => 0, 'message' => '', 'file' => 'lib/Phlickr/Photo.php') 
    176 ); 
    177  
    178 $neededExtentions = array( 
    179   'xml'      => array('needed'    => 0, 
    180                       'available' => 0, 
    181                       'message'   => '<B>xml</B> extention is missing', 
    182                       'note'      => 'Required for RSS support'), 
    183   'pgsql'    => array('needed'    => 1, 
    184                       'available' => 0, 
    185                       'message'   => '<B>Posgresql</B> extention is missing', 
    186                       'note'      => 'Required to connect to Postgresql database'), 
    187   'mysql'    => array('needed'    => 0, 
    188                       'available' => 0, 
    189                       'message'   => '<B>MySQL</B> extention is missing', 
    190                       'note'      => 'Required to connect to MySQL database (experimental and not working)'), 
    191   'dom'      => array('needed'    => 1, 
    192                       'available' => 0, 
    193                       'message'   => '<B>DOM</B> extention is missing', 
    194                       'note'      => 'Required if you want to export the list of HotSpots as a RSS feed'), 
    195   'gettext'  => array('needed'    => 0, 
    196                       'available' => 0, 
    197                       'message'   => 'Gettext is unavailable, the auth-server will work, but you will loose internationalization', 
    198                       'note'      => 'Internationalization support'), 
    199   'mbstring' => array('needed'    => 1, 
    200                       'available' => 0, 
    201                       'message'   => '<B>mbstring</B> extention is missing', 
    202                       'note'      => 'Required for core auth-server and RSS support'), 
    203   'mcrypt'   => array('needed'    => 0, 
    204                       'available' => 0, 
    205                       'message'   => '<B>mcrypt</B> extention is missing', 
    206                       'note'      => 'Required for RADIUS support'), 
    207   'mhash'    => array('needed'    => 0, 
    208                       'available' => 0, 
    209                       'message'   => '<B>mhash</B> extention is missing', 
    210                       'note'      => 'Required for RADIUS support'), 
    211   'xmlrpc'   => array('needed'    => 0, 
    212                       'available' => 0, 
    213                       'message'   => '<B>xmlrpc</B> extention is missing', 
    214                       'note'      => 'Required for RADIUS support') 
    215 ); 
     165$phlickr_full_url = 'http://easynews.dl.sourceforge.net/sourceforge/phlickr/Phlickr-0.2.4.tgz'; 
     166 
     167$neededPackages = array ('smarty' => array ('needed' => 1, 'available' => 0, 'message' => '', 'file' => 'lib/smarty/Smarty.class.php'), 'magpierss' => array ('needed' => 0, 'available' => 0, 'message' => '', 'file' => 'lib/magpie/rss_fetch.inc'), 'phlickr' => array ('needed' => 0, 'available' => 0, 'message' => '', 'file' => 'lib/Phlickr/Photo.php')); 
     168 
     169$neededExtentions = array ('xml' => array ('needed' => 0, 'available' => 0, 'message' => '<B>xml</B> extention is missing', 'note' => 'Required for RSS support'), 'pgsql' => array ('needed' => 1, 'available' => 0, 'message' => '<B>Posgresql</B> extention is missing', 'note' => 'Required to connect to Postgresql database'), 'mysql' => array ('needed' => 0, 'available' => 0, 'message' => '<B>MySQL</B> extention is missing', 'note' => 'Required to connect to MySQL database (experimental and not working)'), 'dom' => array ('needed' => 1, 'available' => 0, 'message' => '<B>DOM</B> extention is missing', 'note' => 'Required if you want to export the list of HotSpots as a RSS feed'), 'gettext' => array ('needed' => 0, 'available' => 0, 'message' => 'Gettext is unavailable, the auth-server will work, but you will loose internationalization', 'note' => 'Internationalization support'), 'mbstring' => array ('needed' => 1, 'available' => 0, 'message' => '<B>mbstring</B> extention is missing', 'note' => 'Required for core auth-server and RSS support'), 'mcrypt' => array ('needed' => 0, 'available' => 0, 'message' => '<B>mcrypt</B> extention is missing', 'note' => 'Required for RADIUS support'), 'mhash' => array ('needed' => 0, 'available' => 0, 'message' => '<B>mhash</B> extention is missing', 'note' => 'Required for RADIUS support'), 'xmlrpc' => array ('needed' => 0, 'available' => 0, 'message' => '<B>xmlrpc</B> extention is missing', 'note' => 'Required for RADIUS support')); 
    216170 
    217171$loadedExtensions = array_flip(get_loaded_extensions()); # Debug : An empty array for $loadedExtensions will show needed dependencies 
    218172 
    219 $neededPEARPackages = array( 
    220   'radius'      => array('needed' => 0, 'available' => 0, 'command' => "return dl('radius.so');",                'message' => 'Try in command line : pear install radius'), 
    221   'Auth_RADIUS' => array('needed' => 0, 'available' => 0, 'command' => "return include_once 'Auth/RADIUS.php';", 'message' => 'Try in command line : pear install Auth_RADIUS'), 
    222   'Crypt_CHAP'  => array('needed' => 0, 'available' => 0, 'command' => "return include_once 'Crypt/CHAP.php';",  'message' => 'Try in command line : pear install Crypt_CHAP (mhash and mcrypt extensions are needed)') 
    223 ); 
    224  
    225 $optionsInfo = array( 
    226   'SSL_AVAILABLE'                => array('title'   => 'SSL Support', 
    227                                           'depend'  => 'return 1;', 
    228                                           'message' => '&nbsp;'), 
    229   'RSS_SUPPORT'                  => array('title'   => 'RSS Support', 
    230                                           'depend'  => 'return ($neededExtentions[\'xml\'][\'available\'] && $neededPackages[\'magpierss\'][\'available\']);', 
    231                                           'message' => 'Missing <B>xml</B> extentions or <B>MagpieRSS</B>'), 
    232   'PHLICKR_SUPPORT'              => array('title'   => 'Flickr Photostream content support', 
    233                                           'depend'  => 'return $neededPackages[\'phlickr\'][\'available\'];', 
    234                                           'message' => '<B>Phlickr</B> library not installed'), 
    235   'CONF_USE_CRON_FOR_DB_CLEANUP' => array('title'   => 'Use cron for DB cleanup', 
    236                                           'depend'  => 'return 1;', 
    237                                           'message' => '&nbsp;'), 
    238   'XSLT_SUPPORT'                 => array('title'   => 'XSLT Support', 
    239                                           'depend'  => 'return 1;', 
    240                                           'message' => '&nbsp;'), 
    241   'GMAPS_HOTSPOTS_MAP_ENABLED'   => array('title'   => 'Google Maps Support', 
    242                                           'depend'  => 'return 1;', 
    243                                           'message' => '&nbsp;') 
    244 ); 
    245  
    246 foreach($neededExtentions as $key => $value) {   # Detect availables extentions 
    247   if (array_key_exists($key, $loadedExtensions)) 
    248     $neededExtentions[$key]['available'] = 1; 
     173$neededPEARPackages = array ('radius' => array ('needed' => 0, 'available' => 0, 'command' => "return dl('radius.so');", 'message' => 'Try in command line : pear install radius'), 'Auth_RADIUS' => array ('needed' => 0, 'available' => 0, 'command' => "return include_once 'Auth/RADIUS.php';", 'message' => 'Try in command line : pear install Auth_RADIUS'), 'Crypt_CHAP' => array ('needed' => 0, 'available' => 0, 'command' => "return include_once 'Crypt/CHAP.php';", 'message' => 'Try in command line : pear install Crypt_CHAP (mhash and mcrypt extensions are needed)')); 
     174 
     175$optionsInfo = array ('SSL_AVAILABLE' => array ('title' => 'SSL Support', 'depend' => 'return 1;', 'message' => '&nbsp;'), 'RSS_SUPPORT' => array ('title' => 'RSS Support', 'depend' => 'return ($neededExtentions[\'xml\'][\'available\'] && $neededPackages[\'magpierss\'][\'available\']);', 'message' => 'Missing <B>xml</B> extentions or <B>MagpieRSS</B>'), 'PHLICKR_SUPPORT' => array ('title' => 'Flickr Photostream content support', 'depend' => 'return $neededPackages[\'phlickr\'][\'available\'];', 'message' => '<B>Phlickr</B> library not installed'), 'CONF_USE_CRON_FOR_DB_CLEANUP' => array ('title' => 'Use cron for DB cleanup', 'depend' => 'return 1;', 'message' => '&nbsp;'), 'XSLT_SUPPORT' => array ('title' => 'XSLT Support', 'depend' => 'return 1;', 'message' => '&nbsp;'), 'GMAPS_HOTSPOTS_MAP_ENABLED' => array ('title' => 'Google Maps Support', 'depend' => 'return 1;', 'message' => '&nbsp;')); 
     176 
     177foreach ($neededExtentions as $key => $value) { # Detect availables extentions 
     178    if (array_key_exists($key, $loadedExtensions)) 
     179        $neededExtentions[$key]['available'] = 1; 
    249180} 
    250181 
    251 foreach($neededPEARPackages as $key => $value) { # Detect availables PEAR Packages 
    252   if (@eval($neededPEARPackages[$key]['command'])) 
    253     $neededPEARPackages[$key]['available'] = 1; 
     182foreach ($neededPEARPackages as $key => $value) { # Detect availables PEAR Packages 
     183    if (@ eval ($neededPEARPackages[$key]['command'])) 
     184        $neededPEARPackages[$key]['available'] = 1; 
    254185} 
    255186 
    256 foreach($neededPackages as $key => $value) {    # Detect installed libraries (smarty, ...) 
    257   if (file_exists($basepath . '/' . $neededPackages[$key]['file'])) 
    258     $neededPackages[$key]['available'] = 1; 
     187foreach ($neededPackages as $key => $value) { # Detect installed libraries (smarty, ...) 
     188    if (file_exists(WIFIDOG_ABS_FILE_PATH.$neededPackages[$key]['file'])) 
     189        $neededPackages[$key]['available'] = 1; 
    259190} 
    260191 
    261 $CONFIG_FILE       = 'config.php'; 
     192$CONFIG_FILE = 'config.php'; 
    262193$LOCAL_CONFIG_FILE = 'local.config.php'; 
    263194 
    264 if (!empty($config)) # If not empty, save javascript 'config' variable to config.php file 
    265   saveConfig($config); 
     195if (!empty ($config)) # If not empty, save javascript 'config' variable to config.php file 
     196    saveConfig($config); 
    266197 
    267198### Read Configuration file. Keys and Values => define('FOO', 'BRAK'); 
    268199# Use config.php if local.config.php does not exist 
    269 //if(!file_exists("$basepath/$LOCAL_CONFIG_FILE")) 
    270   $contentArray = file("$basepath/$CONFIG_FILE"); 
     200//if(!file_exists(WIFIDOG_ABS_FILE_PATH."$LOCAL_CONFIG_FILE")) 
     201$contentArray = file(WIFIDOG_ABS_FILE_PATH."$CONFIG_FILE"); 
    271202//else 
    272 //  $contentArray = file("$basepath/$LOCAL_CONFIG_FILE"); 
    273  
    274 $configArray = array(); 
    275  
    276 foreach($contentArray as $line) { 
    277   #print "$line<BR>"; # Debug 
    278   if(preg_match("/^define\((.+)\);/", $line, $matchesArray)) { 
    279     list($key, $value) = explode(',', $matchesArray[1]); 
    280     $pattern = array("/^'/", "/'$/"); 
    281     $replacement = array('', ''); 
    282     $key = preg_replace($pattern, $replacement, trim($key)); 
    283     $value = preg_replace($pattern, $replacement, trim($value)); 
    284     $configArray[$key] = $value; 
    285   } 
     203//  $contentArray = file(WIFIDOG_ABS_FILE_PATH."$LOCAL_CONFIG_FILE"); 
     204 
     205$configArray = array (); 
     206 
     207foreach ($contentArray as $line) { 
     208    #print "$line<BR>"; # Debug 
     209    if (preg_match("/^define\((.+)\);/", $line, $matchesArray)) { 
     210        list ($key, $value) = explode(',', $matchesArray[1]); 
     211        $pattern = array ("/^'/", "/'$/"); 
     212        $replacement = array ('', ''); 
     213        $key = preg_replace($pattern, $replacement, trim($key)); 
     214        $value = preg_replace($pattern, $replacement, trim($value)); 
     215        $configArray[$key] = $value; 
     216    } 
    286217} 
    287218 
    288219# Database connections variables 
    289 $CONF_DBMS              = $configArray['CONF_DBMS']; 
    290 $CONF_DATABASE_HOST     = $configArray['CONF_DATABASE_HOST']; 
    291 $CONF_DATABASE_NAME     = $configArray['CONF_DATABASE_NAME']; 
    292 $CONF_DATABASE_USER     = $configArray['CONF_DATABASE_USER']; 
     220$CONF_DBMS = $configArray['CONF_DBMS']; 
     221$CONF_DATABASE_HOST = $configArray['CONF_DATABASE_HOST']; 
     222$CONF_DATABASE_NAME = $configArray['CONF_DATABASE_NAME']; 
     223$CONF_DATABASE_USER = $configArray['CONF_DATABASE_USER']; 
    293224$CONF_DATABASE_PASSWORD = $configArray['CONF_DATABASE_PASSWORD']; 
    294  
    295 # Update SYSTEM_PATH if $system_path (value detected be this script) is not the same as the config.php value 
    296 # Don't update SYSTEM_PATH before $page=='permissions' in case of no write access to config.php 
    297 if ($configArray['SYSTEM_PATH'] != $system_path and $page == 'smarty') { 
    298   print <<<EndHTML 
    299 <script type="text/javascript"> 
    300     newConfig("SYSTEM_PATH='$system_path/'"); 
    301 </script> 
    302 EndHTML; 
    303 } 
    304225 
    305226//foreach($configArray as $key => $value) { print "K=$key V=$value<BR>"; } exit(); # DEBUG 
     
    309230# Todo : Supporter HTTP_REFERER (j'me comprends) 
    310231function navigation($dataArray) { 
    311   $SERVER = $_SERVER['HTTP_HOST']; 
    312   $SCRIPT = $_SERVER['SCRIPT_NAME']; 
    313   print "\n<P>"; 
    314   foreach($dataArray as $num => $navArray) { 
    315     $title = $navArray['title']; 
    316     $page  = $navArray['page']; 
    317     empty($navArray['action']) ? $action = '' : $action = $navArray['action']; 
    318     print <<<EndHTML 
     232    $SERVER = $_SERVER['HTTP_HOST']; 
     233    $SCRIPT = $_SERVER['SCRIPT_NAME']; 
     234    print "\n<P>"; 
     235    foreach ($dataArray as $num => $navArray) { 
     236        $title = $navArray['title']; 
     237        $page = $navArray['page']; 
     238        empty ($navArray['action']) ? $action = '' : $action = $navArray['action']; 
     239        print<<<EndHTML 
    319240<A HREF="#" ONCLICK="document.myform.page.value = '$page'; document.myform.action.value = '$action'; document.myform.submit();" CLASS="button">$title</A> 
    320241 
    321242EndHTML; 
    322     if (array_key_exists($num+1, $dataArray)) 
    323       print "&nbsp;-&nbsp;"; 
    324   } 
    325   print "</P>\n"; 
     243        if (array_key_exists($num +1, $dataArray)) 
     244            print "&nbsp;-&nbsp;"; 
     245    } 
     246    print "</P>\n"; 
    326247} 
    327248 
     
    329250# 
    330251function refreshButton() { 
    331   print <<<EndHTML 
     252    print<<<EndHTML 
    332253 
    333254<P><A HREF="#" ONCLICK="javascript: window.location.reload(true);" CLASS="button">Refresh</A></P> 
     
    347268/*function installPackage($pkg_name, $full_url, $copy) { 
    348269    print "<H1>$pkg_name installation</H1>\n"; 
    349     chdir("$basepath/tmp"); 
     270    chdir(WIFIDOG_ABS_FILE_PATH."tmp"); 
    350271    list($url, $filename) = split ("=", $full_url); 
    351272 
     
    383304# 
    384305function saveConfig($data) { 
    385   print "<!-- saveConfig DATA=($data) -->\n"; # DEBUG 
    386  
    387   global $basepath; 
    388   global $CONFIG_FILE; 
    389  
    390   $contentArray = file("$basepath/$CONFIG_FILE"); 
    391   $fd = fopen("$basepath/$CONFIG_FILE", 'w'); 
    392  
    393   $defineArrayToken = array(); 
    394   $defineArrayToken = explode('|', $data); 
    395  
    396   foreach($defineArrayToken as $nameValue) { 
    397     list($name, $value) = explode('=', $nameValue); 
    398     $defineArray[$name] = $value;  # New define value ($name and value) 
    399     #print "K=$name V=$value<BR>"; # DEBUG 
    400   } 
    401  
    402   foreach($contentArray as $line) { 
    403     #print "L=$line<BR>\n"; 
    404     if(preg_match("/^define\((.+)\);/", $line, $matchesArray)) { 
    405       list($key, $value) = explode(',', $matchesArray[1]); 
    406       $pattern     = array("/^'/", "/'$/"); 
    407       $replacement = array('', ''); 
    408       $key   = preg_replace($pattern, $replacement, trim($key)); 
    409       //$value = preg_replace($pattern, $replacement, trim($value)); 
    410  
    411       if (array_key_exists($key, $defineArray)) { // A new value is defined 
    412         #print "$key EXISTS<BR>"; 
    413         #print "define => (" . $defineArray[$key] . ")<BR>"; 
    414         $pattern     = array("/^\\\'/", "/\\\'$/"); 
    415         $replacement = array("'", "'"); 
    416         $value = preg_replace($pattern, $replacement, trim($defineArray[$key])); 
    417         #print "(define('$key', $value);)<BR>"; 
    418         fwrite($fd, "define('$key', $value);\n"); # Write the new define($name, $value) 
    419       } 
    420       else { // The key does not exist (no new value to be saved) 
    421         fwrite($fd, $line); # Write the same line in config.php 
    422       } 
     306    print "<!-- saveConfig DATA=($data) -->\n"; # DEBUG 
     307 
     308    global $CONFIG_FILE; 
     309 
     310    $contentArray = file(WIFIDOG_ABS_FILE_PATH."$CONFIG_FILE"); 
     311    $fd = fopen(WIFIDOG_ABS_FILE_PATH."$CONFIG_FILE", 'w'); 
     312 
     313    $defineArrayToken = array (); 
     314    $defineArrayToken = explode('|', $data); 
     315 
     316    foreach ($defineArrayToken as $nameValue) { 
     317        list ($name, $value) = explode('=', $nameValue); 
     318        $defineArray[$name] = $value; # New define value ($name and value) 
     319        #print "K=$name V=$value<BR>"; # DEBUG 
    423320    } 
    424     else { 
    425       fwrite($fd, $line);   # Write the line (not a define line). Ex: Commented text 
     321 
     322    foreach ($contentArray as $line) { 
     323        #print "L=$line<BR>\n"; 
     324        if (preg_match("/^define\((.+)\);/", $line, $matchesArray)) { 
     325            list ($key, $value) = explode(',', $matchesArray[1]); 
     326            $pattern = array ("/^'/", "/'$/"); 
     327            $replacement = array ('', ''); 
     328            $key = preg_replace($pattern, $replacement, trim($key)); 
     329            //$value = preg_replace($pattern, $replacement, trim($value)); 
     330 
     331            if (array_key_exists($key, $defineArray)) { // A new value is defined 
     332                #print "$key EXISTS<BR>"; 
     333                #print "define => (" . $defineArray[$key] . ")<BR>"; 
     334                $pattern = array ("/^\\\'/", "/\\\'$/"); 
     335                $replacement = array ("'", "'"); 
     336                $value = preg_replace($pattern, $replacement, trim($defineArray[$key])); 
     337                #print "(define('$key', $value);)<BR>"; 
     338                fwrite($fd, "define('$key', $value);\n"); # Write the new define($name, $value) 
     339            } 
     340            else { // The key does not exist (no new value to be saved) 
     341                fwrite($fd, $line); # Write the same line in config.php 
     342            } 
     343        } 
     344        else { 
     345            fwrite($fd, $line); # Write the line (not a define line). Ex: Commented text 
     346        } 
    426347    } 
    427   } 
    428348} 
    429349 
     
    431351# MAIN 
    432352switch ($page) { 
    433   case 'version': 
    434 /*  TODO : Valider qu'au moins une extention de DB est existante (pgsql, mysql, etc) 
    435            Definir les versions minimales de Posgres et MySQL */ 
    436  
    437     print "<H1>Version validation</H1>"; 
    438     print "<TABLE BORDER=\"1\">"; 
    439  
    440     $phpVersion = phpversion(); 
    441     $okMsg      = '<TD ALIGN="CENTER" STYLE="background:lime;">OK</TD>'; 
    442     $errorMsg   = '<TD ALIGN="CENTER" STYLE="background:red;">ERROR</TD>'; 
    443     $warningMsg = '<TD ALIGN="CENTER" STYLE="background:yellow;">Warning</TD>'; 
    444     $error = 0; 
    445  
    446     print "<TR><TD>PHP</TD>"; 
    447     if (version_compare($phpVersion, $requiredPHPVersion, ">=")) { 
    448       print "$okMsg<TD>$phpVersion</TD>";  // Version 5.0.0 or later 
    449     } else { 
    450       print "$errorMsg<TD>Version $requiredPHPVersion needed</TD>"; // Version < 5.0.0 
    451       $error = 1; 
    452     } 
    453     print "</TR></TABLE><BR>"; 
    454  
    455     print "<TABLE BORDER=\"1\"><TR><TD><B>Extention</B></TD><TD><B>Status</B></TD><TD><B>Note</B></TD><TD><B>Message</B></TD></TR>"; 
    456     foreach($neededExtentions as $key => $value) { 
    457       print  "<TR><TD><A HREF=\"http://www.php.net/$key\">$key</A></TD>"; 
    458       $note = $neededExtentions[$key]['note']; 
    459       if ($neededExtentions[$key]['available']) { 
    460         print  "$okMsg<TD>$note</TD><TD>&nbsp;</TD></TR>"; 
    461       } else { 
    462         $message = $neededExtentions[$key]['message']; 
    463         if ($neededExtentions[$key]['needed'] == 1) { 
    464           print  "$errorMsg<TD>$note</TD><TD>$message</TD></TR>"; 
    465           $error = 1; 
    466         } else { 
    467           print  "$warningMsg<TD>$note</TD><TD>$message</TD></TR>"; 
    468         } 
    469       } 
    470     } 
    471     print "</TABLE><BR>"; 
    472  
    473     /************************************ 
    474     * PEAR Components 
    475     *************************************/ 
    476     print "<TABLE BORDER=\"1\"><TR><TD COLSPAN=\"3\"><CENTER><B>PEAR</B></CENTER></TD></TR>"; 
    477     print "<TR><TD><B>Component</B></TD><TD><B>Status</B></TD><TD><B>Note</B></TD></TR>"; 
    478  
    479     foreach($neededPEARPackages as $key => $value) { 
    480       $return = 0; 
    481       print  "<TR><TD><A HREF=\"http://pear.php.net/package/$key\">$key</A></TD>"; 
    482       if ($neededPEARPackages[$key]['available']) { 
    483         print  "$okMsg<TD>&nbsp;</TD></TR>"; 
    484       } else { 
    485         $message = $neededPEARPackages[$key]['message']; 
    486         if ($neededPEARPackages[$key]['needed'] == 1) { 
    487           print  "$errorMsg<TD>$message</TD></TR>"; 
    488           $error = 1; 
    489         } else { 
    490           print  "$warningMsg<TD>$message</TD></TR>"; 
    491         } 
    492       } 
    493     } 
    494     print "</TABLE><BR>"; 
    495  
    496     /************************************ 
    497     * GD with PNG and JPEG support (will be needed by stats and graphics) 
    498     *************************************/ 
    499 /*  $gdInfo = @gd_info(); 
    500     print "<TABLE BORDER=\"1\"><TR><TD><PRE>"; 
    501     print_r($gdInfo); 
    502     print "</PRE></TD></TR></TABLE>"; 
    503 */ 
    504  
    505 #    if (!($neededExtentions['pgsql']['available'] && $neededExtentions['mysql']['available'])) 
    506 #      print "At least one DB extentions is nedded<BR>"; 
    507  
    508     //TODO: PostgreSQL and MySQL version are not validated"; 
    509     print "We recommend you use PostgreSQL 8.0 or newer"; 
    510  
    511     refreshButton(); 
    512     if ($error != 1) { 
    513       navigation(array(array("title" => "Next", "page" => "permission"))); 
    514     } 
    515  
    516   break; 
    517   ################################### 
    518   case 'permission': 
    519     print "<H1>Permissions</H1>"; 
    520  
    521     $process_info_user_id  = posix_getpwuid(posix_getuid()); 
    522     $process_info_group_id = posix_getgrgid(posix_getegid()); 
    523     $process_username      = $process_info_user_id['name']; 
    524     $process_group         = $process_info_group_id['name']; 
    525     $cmd_mkdir = ''; 
    526     $cmd_chown = ''; 
    527     $error     = 0; 
    528  
    529     print "<P><B>Installation directory</B>: $basepath</P>"; 
    530     print "<P><B>HTTP daemon UNIX username/group</B>: $process_username/$process_group</P>"; 
    531 #    print "<P><B>HTTPD group</B>: $process_group<BR</P>"; 
    532     print "<P><TABLE BORDER=\"1\"><TR><TD><B>Directory</B></TD></TD><TD><B>Owner</B></TD><TD><B>Writable</B></TD></TR>\n"; 
    533  
    534     foreach($dir_array as $dir) { 
    535       print "<TR><TD>$dir</TD>"; 
    536       if (!file_exists("$basepath/$dir")) { 
    537         print "<TD COLSPAN=\"2\" STYLE=\"text-align:center;\">Missing</TD></TR>\n"; 
    538         $cmd_mkdir .= "$basepath/$dir "; 
    539         $cmd_chown .= "$basepath/$dir "; 
    540         $error = 1; 
    541         continue; 
    542       } 
    543  
    544       $dir_info = posix_getpwuid(fileowner("$basepath/$dir")); 
    545       $dir_owner_username = $dir_info['name']; 
    546       print "<TD>$dir_owner_username</TD>"; 
    547  
    548       if (is_writable("$basepath/$dir")) { 
    549         print "<TD>YES</TD>"; 
    550       } 
    551       else { 
    552         print "<TD>NO</TD>"; 
    553         $cmd_chown .= "$basepath/$dir "; 
    554         $error = 1; 
    555       } 
    556       print "</TR>\n"; 
    557     } 
    558     print "</TABLE>\n"; 
    559  
    560     if ($error != 1) { 
    561       navigation(array(array("title" => "Back", "page" => ""), array("title" => "Next", "page" => "smarty"))); 
    562     } 
    563     else { 
    564       refreshButton(); 
    565       print "<P>You need to allow UNIX user <B>$process_username</B> to write to these directories (mkdir, chown or chmod)</P>"; 
    566       if(!empty($cmd_mkdir)) 
    567         print "<P><B>For instance</B> : mkdir $cmd_mkdir"; 
    568       if(!empty($cmd_chown)) 
    569         print "<P><B>For instance</B> : chown -R $process_username:$process_group $cmd_chown"; 
    570       print "<P>After permissions modification done, hit the REFRESH button to see the NEXT button and continue with the installation"; 
    571     } 
    572   break; 
    573   ################################### 
    574   case 'smarty': // Download, uncompress and install Smarty 
    575     print <<< EndHTML 
     353    case 'version' : 
     354        /*  TODO : Valider qu'au moins une extention de DB est existante (pgsql, mysql, etc) 
     355                   Definir les versions minimales de Posgres et MySQL */ 
     356 
     357        print "<H1>Version validation</H1>"; 
     358        print "<TABLE BORDER=\"1\">"; 
     359 
     360        $phpVersion = phpversion(); 
     361        $okMsg = '<TD ALIGN="CENTER" STYLE="background:lime;">OK</TD>'; 
     362        $errorMsg = '<TD ALIGN="CENTER" STYLE="background:red;">ERROR</TD>'; 
     363        $warningMsg = '<TD ALIGN="CENTER" STYLE="background:yellow;">Warning</TD>'; 
     364        $error = 0; 
     365 
     366        print "<TR><TD>PHP</TD>"; 
     367        if (version_compare($phpVersion, $requiredPHPVersion, ">=")) { 
     368            print "$okMsg<TD>$phpVersion</TD>"; // Version 5.0.0 or later 
     369        } 
     370        else { 
     371            print "$errorMsg<TD>Version $requiredPHPVersion needed</TD>"; // Version < 5.0.0 
     372            $error = 1; 
     373        } 
     374        print "</TR></TABLE><BR>"; 
     375 
     376        print "<TABLE BORDER=\"1\"><TR><TD><B>Extention</B></TD><TD><B>Status</B></TD><TD><B>Note</B></TD><TD><B>Message</B></TD></TR>"; 
     377        foreach ($neededExtentions as $key => $value) { 
     378            print "<TR><TD><A HREF=\"http://www.php.net/$key\">$key</A></TD>"; 
     379            $note = $neededExtentions[$key]['note']; 
     380            if ($neededExtentions[$key]['available']) { 
     381                print "$okMsg<TD>$note</TD><TD>&nbsp;</TD></TR>"; 
     382            } 
     383            else { 
     384                $message = $neededExtentions[$key]['message']; 
     385                if ($neededExtentions[$key]['needed'] == 1) { 
     386                    print "$errorMsg<TD>$note</TD><TD>$message</TD></TR>"; 
     387                    $error = 1; 
     388                } 
     389                else { 
     390                    print "$warningMsg<TD>$note</TD><TD>$message</TD></TR>"; 
     391                } 
     392            } 
     393        } 
     394        print "</TABLE><BR>"; 
     395 
     396        /************************************ 
     397        * PEAR Components 
     398        *************************************/ 
     399        print "<TABLE BORDER=\"1\"><TR><TD COLSPAN=\"3\"><CENTER><B>PEAR</B></CENTER></TD></TR>"; 
     400        print "<TR><TD><B>Component</B></TD><TD><B>Status</B></TD><TD><B>Note</B></TD></TR>"; 
     401 
     402        foreach ($neededPEARPackages as $key => $value) { 
     403            $return = 0; 
     404            print "<TR><TD><A HREF=\"http://pear.php.net/package/$key\">$key</A></TD>"; 
     405            if ($neededPEARPackages[$key]['available']) { 
     406                print "$okMsg<TD>&nbsp;</TD></TR>"; 
     407            } 
     408            else { 
     409                $message = $neededPEARPackages[$key]['message']; 
     410                if ($neededPEARPackages[$key]['needed'] == 1) { 
     411                    print "$errorMsg<TD>$message</TD></TR>"; 
     412                    $error = 1; 
     413                } 
     414                else { 
     415                    print "$warningMsg<TD>$message</TD></TR>"; 
     416                } 
     417            } 
     418        } 
     419        print "</TABLE><BR>"; 
     420 
     421        /************************************ 
     422        * GD with PNG and JPEG support (will be needed by stats and graphics) 
     423        *************************************/ 
     424        /*  $gdInfo = @gd_info(); 
     425            print "<TABLE BORDER=\"1\"><TR><TD><PRE>"; 
     426            print_r($gdInfo); 
     427            print "</PRE></TD></TR></TABLE>"; 
     428        */ 
     429 
     430        #    if (!($neededExtentions['pgsql']['available'] && $neededExtentions['mysql']['available'])) 
     431        #      print "At least one DB extentions is nedded<BR>"; 
     432 
     433        //TODO: PostgreSQL and MySQL version are not validated"; 
     434        print "We recommend you use PostgreSQL 8.0 or newer"; 
     435 
     436        refreshButton(); 
     437        if ($error != 1) { 
     438            navigation(array (array ("title" => "Next", "page" => "permission"))); 
     439        } 
     440 
     441        break; 
     442        ################################### 
     443    case 'permission' : 
     444        print "<H1>Permissions</H1>"; 
     445 
     446        $process_info_user_id = posix_getpwuid(posix_getuid()); 
     447        $process_info_group_id = posix_getgrgid(posix_getegid()); 
     448        $process_username = $process_info_user_id['name']; 
     449        $process_group = $process_info_group_id['name']; 
     450        $cmd_mkdir = ''; 
     451        $cmd_chown = ''; 
     452        $error = 0; 
     453 
     454        print "<P><B>Installation directory</B>: ".WIFIDOG_ABS_FILE_PATH."</P>"; 
     455        print "<P><B>HTTP daemon UNIX username/group</B>: $process_username/$process_group</P>"; 
     456        #    print "<P><B>HTTPD group</B>: $process_group<BR</P>"; 
     457        print "<P><TABLE BORDER=\"1\"><TR><TD><B>Directory</B></TD></TD><TD><B>Owner</B></TD><TD><B>Writable</B></TD></TR>\n"; 
     458 
     459        foreach ($dir_array as $dir) { 
     460            print "<TR><TD>$dir</TD>"; 
     461            if (!file_exists(WIFIDOG_ABS_FILE_PATH."$dir")) { 
     462                print "<TD COLSPAN=\"2\" STYLE=\"text-align:center;\">Missing</TD></TR>\n"; 
     463                $cmd_mkdir .= WIFIDOG_ABS_FILE_PATH."$dir "; 
     464                $cmd_chown .= WIFIDOG_ABS_FILE_PATH."$dir "; 
     465                $error = 1; 
     466                continue; 
     467            } 
     468 
     469            $dir_info = posix_getpwuid(fileowner(WIFIDOG_ABS_FILE_PATH."$dir")); 
     470            $dir_owner_username = $dir_info['name']; 
     471            print "<TD>$dir_owner_username</TD>"; 
     472 
     473            if (is_writable(WIFIDOG_ABS_FILE_PATH."$dir")) { 
     474                print "<TD>YES</TD>"; 
     475            } 
     476            else { 
     477                print "<TD>NO</TD>"; 
     478                $cmd_chown .= WIFIDOG_ABS_FILE_PATH."$dir "; 
     479                $error = 1; 
     480            } 
     481            print "</TR>\n"; 
     482        } 
     483        print "</TABLE>\n"; 
     484 
     485        if ($error != 1) { 
     486            navigation(array (array ("title" => "Back", "page" => ""), array ("title" => "Next", "page" => "smarty"))); 
     487        } 
     488        else { 
     489            refreshButton(); 
     490            print "<P>You need to allow UNIX user <B>$process_username</B> to write to these directories (mkdir, chown or chmod)</P>"; 
     491            if (!empty ($cmd_mkdir)) 
     492                print "<P><B>For instance</B> : mkdir $cmd_mkdir"; 
     493            if (!empty ($cmd_chown)) 
     494                print "<P><B>For instance</B> : chown -R $process_username:$process_group $cmd_chown"; 
     495            print "<P>After permissions modification done, hit the REFRESH button to see the NEXT button and continue with the installation"; 
     496        } 
     497        break; 
     498        ################################### 
     499    case 'smarty' : // Download, uncompress and install Smarty 
     500        print<<< EndHTML 
    576501    <H1>Smarty template engine installation</H1> 
    577502    <P><A HREF="http://smarty.php.net/">Smarty</A> is Template Engine. WifiDog requires you install it before you continue.</P> 
    578503EndHTML; 
    579     if ($neededPackages['smarty']['available']) { 
    580       print "Already installed !<br/>"; 
    581     } 
    582     else { 
    583       chdir("$basepath/tmp"); 
    584       list($url, $filename) = split ("=", $smarty_full_url); 
    585  
    586       print "Download source code ($filename) : "; 
    587       if (!file_exists($filename)) 
    588         exec("wget \"$smarty_full_url\" 2>&1", $output, $return); 
    589       if (!file_exists($filename)) { 
    590         print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp/smarty</B>"; 
    591         $output = implode("\n", $output); 
    592         print "<PRE><B>wget \"$smarty_full_url\"</B>\n$output</PRE>"; 
    593         exit(); 
    594       } else { 
    595         print "OK<BR>"; 
    596       } 
    597  
    598       print "Uncompressing : "; 
    599       $dir_array = split(".tar.gz", $filename); 
    600       $dirname = array_shift($dir_array); 
    601  
    602       if (!file_exists($dirname)) 
    603         exec("tar -xzf $dirname.tar.gz &>/tmp/tar.output", $output, $return); 
    604       print "OK<BR>"; 
    605  
    606       exec("pwd", $output, $return); 
    607       print "Copying : "; 
    608       if (!file_exists("$basepath/lib/smarty")); 
    609         exec("cp -r $dirname/libs/* $basepath/lib/smarty &>/tmp/cp.output", $output, $return); # TODO : Utiliser SMARTY_REL_PATH 
    610       print "OK<BR>"; 
    611  
    612       refreshButton(); 
    613     } 
    614     navigation(array(array("title" => "Back", "page" => "permission"), array("title" => "Next", "page" => "magpierss"))); 
    615   break; 
    616   ################################### 
    617   case 'magpierss': // Download, uncompress and install MagpieRSS 
    618     print "<H1>MagpieRSS installation</H1>\n"; 
    619  
    620     if ( $neededPackages['magpierss']['available']) { 
    621       print "Already installed !<BR>"; 
    622       navigation(array(array("title" => "Back", "page" => "smarty"), array("title" => "Next", "page" => "phlickr"))); 
    623     } 
    624     elseif ($action == 'install') { 
    625       chdir("$basepath/tmp"); 
    626       $filename_array = preg_split("/\//", $magpierss_full_url); 
    627       $filename = array_pop($filename_array); 
    628  
    629       print "Download source code ($filename) : "; 
    630       if (!file_exists($filename)) 
    631         exec("wget \"$magpierss_full_url\" 2>&1", $output, $return); 
    632       if (!file_exists($filename)) { 
    633         print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp/smarty</B>"; 
    634         $output = implode("\n", $output); 
    635         print "<PRE><B>wget \"$magpierss_full_url\"</B>\n$output</PRE>"; 
    636         exit(); 
    637       } else { 
    638         print "OK<BR>"; 
    639       } 
    640  
    641       print "Uncompressing : "; 
    642       $dir_array = split(".tar.gz", $filename); 
    643       $dirname = array_shift($dir_array); 
    644       if (!file_exists($dirname)) 
    645         exec("tar -xzf $dirname.tar.gz &>/tmp/tar.output", $output, $return); 
    646       print "OK<BR>"; 
    647  
    648       print "Copying : "; 
    649       exec("cp -r $dirname/* ../lib/magpie &>/tmp/cp.output", $output, $return); # TODO : Utiliser MAGPIE_REL_PATH 
    650       print "OK<BR>"; 
    651  
    652       refreshButton(); 
    653       navigation(array(array("title" => "Back", "page" => "smarty"), array("title" => "Next", "page" => "phlickr"))); 
    654     } 
    655     else { 
    656       print <<< EndHTML 
     504        if ($neededPackages['smarty']['available']) { 
     505            print "Already installed !<br/>"; 
     506        } 
     507        else { 
     508            chdir(WIFIDOG_ABS_FILE_PATH."tmp"); 
     509            list ($url, $filename) = split("=", $smarty_full_url); 
     510 
     511            print "Download source code ($filename) : "; 
     512            if (!file_exists($filename)) 
     513                exec("wget \"$smarty_full_url\" 2>&1", $output, $return); 
     514            if (!file_exists($filename)) { 
     515                print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp/smarty</B>"; 
     516                $output = implode("\n", $output); 
     517                print "<PRE><B>wget \"$smarty_full_url\"</B>\n$output</PRE>"; 
     518                exit (); 
     519            } 
     520            else { 
     521                print "OK<BR>"; 
     522            } 
     523 
     524            print "Uncompressing : "; 
     525            $dir_array = split(".tar.gz", $filename); 
     526            $dirname = array_shift($dir_array); 
     527 
     528            if (!file_exists($dirname)) 
     529                exec("tar -xzf $dirname.tar.gz &>/tmp/tar.output", $output, $return); 
     530            print "OK<BR>"; 
     531 
     532            exec("pwd", $output, $return); 
     533            print "Copying : "; 
     534            if (!file_exists(WIFIDOG_ABS_FILE_PATH."lib/smarty")); 
     535            exec("cp -r $dirname/libs/* $basepath/lib/smarty &>/tmp/cp.output", $output, $return); # TODO : Utiliser SMARTY_REL_PATH 
     536            print "OK<BR>"; 
     537 
     538            refreshButton(); 
     539        } 
     540        navigation(array (array ("title" => "Back", "page" => "permission"), array ("title" => "Next", "page" => "magpierss"))); 
     541        break; 
     542        ################################### 
     543    case 'magpierss' : // Download, uncompress and install MagpieRSS 
     544        print "<H1>MagpieRSS installation</H1>\n"; 
     545 
     546        if ($neededPackages['magpierss']['available']) { 
     547            print "Already installed !<BR>"; 
     548            navigation(array (array ("title" => "Back", "page" => "smarty"), array ("title" => "Next", "page" => "phlickr"))); 
     549        } 
     550        elseif ($action == 'install') { 
     551            chdir(WIFIDOG_ABS_FILE_PATH."tmp"); 
     552            $filename_array = preg_split("/\//", $magpierss_full_url); 
     553            $filename = array_pop($filename_array); 
     554 
     555            print "Download source code ($filename) : "; 
     556            if (!file_exists($filename)) 
     557                exec("wget \"$magpierss_full_url\" 2>&1", $output, $return); 
     558            if (!file_exists($filename)) { 
     559                print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp/smarty</B>"; 
     560                $output = implode("\n", $output); 
     561                print "<PRE><B>wget \"$magpierss_full_url\"</B>\n$output</PRE>"; 
     562                exit (); 
     563            } 
     564            else { 
     565                print "OK<BR>"; 
     566            } 
     567 
     568            print "Uncompressing : "; 
     569            $dir_array = split(".tar.gz", $filename); 
     570            $dirname = array_shift($dir_array); 
     571            if (!file_exists($dirname)) 
     572                exec("tar -xzf $dirname.tar.gz &>/tmp/tar.output", $output, $return); 
     573            print "OK<BR>"; 
     574 
     575            print "Copying : "; 
     576            exec("cp -r $dirname/* ../lib/magpie &>/tmp/cp.output", $output, $return); # TODO : Utiliser MAGPIE_REL_PATH 
     577            print "OK<BR>"; 
     578 
     579            refreshButton(); 
     580            navigation(array (array ("title" => "Back", "page" => "smarty"), array ("title" => "Next", "page" => "phlickr"))); 
     581        } 
     582        else { 
     583            print<<< EndHTML 
    657584<P><A HREF="http://magpierss.sourceforge.net/">MagpieRSS</A> provides an XML-based (expat) RSS parser in PHP. MagpieRSS is needed by Wifidog for RSS feeds. It's is recommended to install MagpieRSS, if you don't, RSS feeds options will be disable. 
    658585 
    659586<P>Do you want to install MagpieRSS ? 
    660587EndHTML; 
    661       navigation(array(array("title" => "Back", "page" => "smarty"), array("title" => "Install", "page" => "magpierss", "action" => "install"), array("title" => "Next", "page" => "phlickr"))); 
    662     } 
    663   break; 
    664   ################################### 
    665   case 'phlickr': // Download, uncompress and install phlickr library 
    666     print "<H1>Phlickr installation</H1>\n"; 
    667  
    668     if ( $neededPackages['phlickr']['available']) { 
    669       print "Already installed !<BR>"; 
    670       navigation(array(array("title" => "Back", "page" => "magpierss"), array("title" => "Next", "page" => "database"))); 
    671     } 
    672     elseif ($action == 'install') { 
    673       chdir("$basepath/tmp"); 
    674       $filename_array = preg_split("/\//", $phlickr_full_url); 
    675       $filename = array_pop($filename_array); 
    676  
    677       print "Download source code ($filename) : "; 
    678       if (!file_exists($filename)) 
    679         exec("wget \"$phlickr_full_url\" 2>&1", $output, $return); 
    680       if (!file_exists($filename)) { # Error occured, print output of wget 
    681         print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp/smarty</B>"; 
    682         $output = implode("\n", $output); 
    683         print "<PRE><B>wget \"$phlickr_full_url\"</B>\n$output</PRE>"; 
    684         exit(); 
    685       } else { 
    686         print "OK<BR>"; 
    687       } 
    688  
    689       print "Uncompressing : "; 
    690       $dirname_array = split(".tgz", $filename); 
    691       $dirname = array_shift($dirname_array); 
    692       if (!file_exists($dirname)) 
    693         exec("tar -xzf $dirname.tgz &>/tmp/tar.output", $output, $return); 
    694       print "OK<BR>"; 
    695  
    696       print "Copying : "; 
    697       if (!file_exists('../../lib/Phlickr/Photo.php')) 
    698         exec("cp -r $dirname/* ../lib/Phlickr &>/tmp/cp.output", $output, $return); # TODO : Utiliser PHLICKR_REL_PATH 
    699       print "OK<BR>"; 
    700  
    701       refreshButton(); 
    702       // Skipping jpgraph install 
    703       navigation(array(array("title" => "Back", "page" => "magpierss"), array("title" => "Next", "page" => "database"))); 
    704     } 
    705     else { 
    706       print <<< EndHTML 
     588            navigation(array (array ("title" => "Back", "page" => "smarty"), array ("title" => "Install", "page" => "magpierss", "action" => "install"), array ("title" => "Next", "page" => "phlickr"))); 
     589        } 
     590        break; 
     591        ################################### 
     592    case 'phlickr' : // Download, uncompress and install phlickr library 
     593        print "<H1>Phlickr installation</H1>\n"; 
     594 
     595        if ($neededPackages['phlickr']['available']) { 
     596            print "Already installed !<BR>"; 
     597            navigation(array (array ("title" => "Back", "page" => "magpierss"), array ("title" => "Next", "page" => "database"))); 
     598        } 
     599        elseif ($action == 'install') { 
     600            chdir(WIFIDOG_ABS_FILE_PATH."tmp"); 
     601            $filename_array = preg_split("/\//", $phlickr_full_url); 
     602            $filename = array_pop($filename_array); 
     603 
     604            print "Download source code ($filename) : "; 
     605            if (!file_exists($filename)) 
     606                exec("wget \"$phlickr_full_url\" 2>&1", $output, $return); 
     607            if (!file_exists($filename)) { # Error occured, print output of wget 
     608                print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp/smarty</B>"; 
     609                $output = implode("\n", $output); 
     610                print "<PRE><B>wget \"$phlickr_full_url\"</B>\n$output</PRE>"; 
     611                exit (); 
     612            } 
     613            else { 
     614                print "OK<BR>"; 
     615            } 
     616 
     617            print "Uncompressing : "; 
     618            $dirname_array = split(".tgz", $filename); 
     619            $dirname = array_shift($dirname_array); 
     620            if (!file_exists($dirname)) 
     621                exec("tar -xzf $dirname.tgz &>/tmp/tar.output", $output, $return); 
     622            print "OK<BR>"; 
     623 
     624            print "Copying : "; 
     625            if (!file_exists('../../lib/Phlickr/Photo.php')) 
     626                exec("cp -r $dirname/* ../lib/Phlickr &>/tmp/cp.output", $output, $return); # TODO : Utiliser PHLICKR_REL_PATH 
     627            print "OK<BR>"; 
     628 
     629            refreshButton(); 
     630            // Skipping jpgraph install 
     631            navigation(array (array ("title" => "Back", "page" => "magpierss"), array ("title" => "Next", "page" => "database"))); 
     632        } 
     633        else { 
     634            print<<< EndHTML 
    707635<P><A HREF="http://phlickr.sourceforge.net/">Phlickr</A> is an Open Source PHP 5 interface to the Flickr API. <A HREF="http://flickr.com/">Flickr</A> is a digital photo sharing website. Phlickr allows WifiDog to display pictures from Flickr on its portal pages. Phlickr is thus an optional package.. 
    708636 
    709637<P>Do you want to install Phlickr ? 
    710638EndHTML; 
    711       navigation(array(array("title" => "Back", "page" => "magpierss"), array("title" => "Install", "page" => "phlickr", "action" => "install"), array("title" => "Next", "page" => "database"))); 
    712     } 
    713   break; 
    714   ################################### 
    715   case 'jpgraph': // Download, uncompress and install JpGraph library 
    716     print "<H1>JpGraph installation</H1>\n"; 
    717  
    718     if ( $neededPackages['jpgraph']['available']) { 
    719       print "Already installed !<BR>"; 
    720       navigation(array(array("title" => "Back", "page" => "phlickr"), array("title" => "Next", "page" => "database"))); 
    721     } 
    722     elseif ($action == 'install') { 
    723       chdir("$basepath/tmp"); 
    724       $filename = array_pop(preg_split("/\//", $jpgraph_full_url)); 
    725  
    726       print "Download source code ($filename) : "; 
    727       if (!file_exists($filename)) 
    728         exec("wget \"$jpgraph_full_url\" 2>&1", $output, $return); 
    729       if (!file_exists($filename)) { # Error occured, print output of wget 
    730         print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp</B>"; 
    731         $output = implode("\n", $output); 
    732         print "<PRE><B>wget \"$jpgraph_full_url\"</B>\n$output</PRE>"; 
    733         exit(); 
    734       } else { 
    735         print "OK<BR>"; 
    736       } 
    737  
    738       print "Uncompressing : "; 
    739       $dirname = array_shift(split(".tar.gz", $filename)); 
    740       if (!file_exists($dirname)) 
    741         exec("tar -xzf $dirname.tar.gz &>/tmp/tar.output", $output, $return); 
    742       print "OK<BR>"; 
    743  
    744       print "Copying : "; 
    745       if (!file_exists('../../lib/jpgraph/jpgraph.php')) 
    746         exec("cp $dirname/src/* ../lib/jpgraph &>/tmp/cp.output", $output, $return); # TODO : Utiliser JPGRAPH_REL_PATH 
    747  
    748       print "OK<BR>"; 
    749  
    750       refreshButton(); 
    751       navigation(array(array("title" => "Back", "page" => "phlickr"), array("title" => "Next", "page" => "database"))); 
    752     } 
    753     else { 
    754       print <<< EndHTML 
     639            navigation(array (array ("title" => "Back", "page" => "magpierss"), array ("title" => "Install", "page" => "phlickr", "action" => "install"), array ("title" => "Next", "page" => "database"))); 
     640        } 
     641        break; 
     642        ################################### 
     643    case 'jpgraph' : // Download, uncompress and install JpGraph library 
     644        print "<H1>JpGraph installation</H1>\n"; 
     645 
     646        if ($neededPackages['jpgraph']['available']) { 
     647            print "Already installed !<BR>"; 
     648            navigation(array (array ("title" => "Back", "page" => "phlickr"), array ("title" => "Next", "page" => "database"))); 
     649        } 
     650        elseif ($action == 'install') { 
     651            chdir(WIFIDOG_ABS_FILE_PATH."tmp"); 
     652            $filename = array_pop(preg_split("/\//", $jpgraph_full_url)); 
     653 
     654            print "Download source code ($filename) : "; 
     655            if (!file_exists($filename)) 
     656                exec("wget \"$jpgraph_full_url\" 2>&1", $output, $return); 
     657            if (!file_exists($filename)) { # Error occured, print output of wget 
     658                print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp</B>"; 
     659                $output = implode("\n", $output); 
     660                print "<PRE><B>wget \"$jpgraph_full_url\"</B>\n$output</PRE>"; 
     661                exit (); 
     662            } 
     663            else { 
     664                print "OK<BR>"; 
     665            } 
     666 
     667            print "Uncompressing : "; 
     668            $dirname = array_shift(split(".tar.gz", $filename)); 
     669            if (!file_exists($dirname)) 
     670                exec("tar -xzf $dirname.tar.gz &>/tmp/tar.output", $output, $return); 
     671            print "OK<BR>"; 
     672 
     673            print "Copying : "; 
     674            if (!file_exists('../../lib/jpgraph/jpgraph.php')) 
     675                exec("cp $dirname/src/* ../lib/jpgraph &>/tmp/cp.output", $output, $return); # TODO : Utiliser JPGRAPH_REL_PATH 
     676 
     677            print "OK<BR>"; 
     678 
     679            refreshButton(); 
     680            navigation(array (array ("title" => "Back", "page" => "phlickr"), array ("title" => "Next", "page" => "database"))); 
     681        } 
     682        else { 
     683            print<<< EndHTML 
    755684<P><A HREF="http://www.aditus.nu/jpgraph/">JpGraph</A> is a Object-Oriented Graph creating library for PHP. 
    756685JpGraph 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. 
     
    758687<P>Do you want to install JpGraph ? 
    759688EndHTML; 
    760       navigation(array(array("title" => "Back", "page" => "phlickr"), array("title" => "Install", "page" => "jpgraph", "action" => "install"), array("title" => "Next", "page" => "database"))); 
    761     } 
    762   break; 
    763   ################################### 
    764   case 'database': 
    765     ### TODO : Valider en javascript que les champs soumit ne sont pas vide 
    766     #          Pouvoir choisir le port de la DB ??? 
    767     print <<< EndHTML 
     689            navigation(array (array ("title" => "Back", "page" => "phlickr"), array ("title" => "Install", "page" => "jpgraph", "action" => "install"), array ("title" => "Next", "page" => "database"))); 
     690        } 
     691        break; 
     692        ################################### 
     693    case 'database' : 
     694        ### TODO : Valider en javascript que les champs soumit ne sont pas vide 
     695        #          Pouvoir choisir le port de la DB ??? 
     696        print<<< EndHTML 
    768697<H1>Database access configuration</H1> 
    769698<BR> 
     
    773702EndHTML; 
    774703 
    775     foreach($configArray as $key => $value) { # In config.php, find all DBMS_* define 
    776       if (preg_match("/^(DBMS_)(.*)/", $key, $matchesArray)) { 
    777         $dbname_lower = strtolower($matchesArray[2]); 
    778     if ($dbname_lower == 'postgres') # config.php use postgres and PHP use pgsql 
    779           $dbname_lower = 'pgsql'; 
    780         if ($neededExtentions[$dbname_lower]['available'] == 0) # Validate dependencie 
    781           continue; 
    782         if ($CONF_DBMS == $key) 
    783           print "    <OPTION value=\"$key\" SELECTED>" . $matchesArray[2] . "</OPTION>\n"; 
    784         else 
    785           print "    <OPTION value=\"$key\">" . $matchesArray[2] . "</OPTION>\n"; 
    786       } 
    787     } 
    788  
    789     print <<< EndHTML 
     704        foreach ($configArray as $key => $value) { # In config.php, find all DBMS_* define 
     705            if (preg_match("/^(DBMS_)(.*)/", $key, $matchesArray)) { 
     706                $dbname_lower = strtolower($matchesArray[2]); 
     707                if ($dbname_lower == 'postgres') # config.php use postgres and PHP use pgsql 
     708                    $dbname_lower = 'pgsql'; 
     709                if ($neededExtentions[$dbname_lower]['available'] == 0) # Validate dependencie 
     710                    continue; 
     711                if ($CONF_DBMS == $key) 
     712                    print "    <OPTION value=\"$key\" SELECTED>".$matchesArray[2]."</OPTION>\n"; 
     713                else 
     714                    print "    <OPTION value=\"$key\">".$matchesArray[2]."</OPTION>\n"; 
     715            } 
     716        } 
     717 
     718        print<<< EndHTML 
    790719  </TD></TR> 
    791720  <TR><TD>Host</TD><TD><INPUT type="text" name="CONF_DATABASE_HOST" value="$CONF_DATABASE_HOST"></TD></TR> 
     
    811740EndHTML; 
    812741 
    813     navigation(array(array("title" => "Back", "page" => "magpierss"))); #, array("title" => "Next", "page" => "testdatabase"))); 
    814     print <<< EndHTML 
     742        navigation(array (array ("title" => "Back", "page" => "magpierss"))); #, array("title" => "Next", "page" => "testdatabase"))); 
     743        print<<< EndHTML 
    815744<P><A HREF="#" ONCLICK="javascript: document.myform.page.value='testdatabase'; submitDatabaseValue(); document.myform.submit();" CLASS="button">Next</A></P> 
    816745 
    817746EndHTML; 
    818747 
    819   break; 
    820   ################################### 
    821   case 'testdatabase': 
    822     print "<H1>Database connection</H1>"; 
    823     /* TODO : Tester la version minimale requise de MySQL et Postgresql 
    824               Tester si MySQL supporte InnoDB                           */ 
    825  
    826     switch ($CONF_DBMS) { 
    827       case 'DBMS_POSTGRES': 
    828         print "<UL><LI>Postgresql database connection : "; 
    829  
    830         $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; 
    831         $ptr_connexion = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==<BR>"); 
    832  
    833         #if ($ptr_connexion == TRUE) { 
    834           print "Success<BR>"; 
    835         #} 
    836 #        } else { 
    837 #          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"; 
    838 #          navigation(array(array("title" => "Back", "page" => "database"))); 
    839 #        } 
    840  
    841         $postgresql_info = pg_version(); 
    842 #        $postgresql_info['server']; 
    843 #        if ($postgresql_info['server'] > $requiredPostgeSQLVersion) { Todo : Do something } 
    844  
    845         print "</UL>"; 
    846         refreshButton(); 
    847         navigation(array(array("title" => "Back", "page" => "database"), array("title" => "Next", "page" => "dbinit"))); 
    848       break; 
    849       ################################### 
    850       case 'DBMS_MYSQL': 
    851         $ptr_connexion = @mysql_connect($CONF_DATABASE_HOST, $CONF_DATABASE_USER, $CONF_DATABASE_PASSWORD); 
    852         print "<UL>\n"; 
    853  
    854         if ($ptr_connexion == TRUE) { 
    855           print "<LI>MySQL database connection : Success"; 
    856  
    857           $mysql_server_version = mysql_get_server_info(); 
    858             print("<LI>MySQL server version: $mysql_server_version"); 
    859  
    860           #if ($mysql_server_version > $requiredMySQLVersion) { Todo : Do something } 
    861  
    862           #printf("<LI>MySQL host info: %s\n", mysql_get_host_info()); 
    863  
    864           print "<LI>Select DB $CONF_DATABASE_NAME : "; 
    865           $select_db = mysql_select_db($CONF_DATABASE_NAME); 
    866  
    867           if($select_db == TRUE) { 
    868             print "Success</UL>"; 
    869               navigation(array(array("title" => "Back", "page" => "database"), array("title" => "Next", "page" => "dbinit"))); 
    870           } else { 
    871             print "</UL>ERROR (Unable to select the database)<BR>"; 
    872             refreshButton(); 
    873             navigation(array(array("title" => "Back", "page" => "database"))); 
    874           } 
    875         } else { 
    876           print "Unable to connect to database on <B>$CONF_DATABASE_HOST</B><BR>The database must be online to continue.<P>Please go back and retry with correct values"; 
    877           refreshButton(); 
    878           navigation(array(array("title" => "Back", "page" => "database"))); 
    879         } 
    880       break; 
    881       default: 
    882         print <<<EndHTML 
     748        break; 
     749        ################################### 
     750    case 'testdatabase' : 
     751        print "<H1>Database connection</H1>"; 
     752        /* TODO : Tester la version minimale requise de MySQL et Postgresql 
     753                  Tester si MySQL supporte InnoDB                           */ 
     754 
     755        switch ($CONF_DBMS) { 
     756            case 'DBMS_POSTGRES' : 
     757                print "<UL><LI>Postgresql database connection : "; 
     758 
     759                $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; 
     760                $ptr_connexion = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==<BR>"); 
     761 
     762                #if ($ptr_connexion == TRUE) { 
     763                print "Success<BR>"; 
     764                #} 
     765                #        } else { 
     766                #          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"; 
     767                #          navigation(array(array("title" => "Back", "page" => "database"))); 
     768                #        } 
     769 
     770                $postgresql_info = pg_version(); 
     771                #        $postgresql_info['server']; 
     772                #        if ($postgresql_info['server'] > $requiredPostgeSQLVersion) { Todo : Do something } 
     773 
     774                print "</UL>"; 
     775                refreshButton(); 
     776                navigation(array (array ("title" => "Back", "page" => "database"), array ("title" => "Next", "page" => "dbinit"))); 
     777                break; 
     778                ################################### 
     779            case 'DBMS_MYSQL' : 
     780                $ptr_connexion = @ mysql_connect($CONF_DATABASE_HOST, $CONF_DATABASE_USER, $CONF_DATABASE_PASSWORD); 
     781                print "<UL>\n"; 
     782 
     783                if ($ptr_connexion == TRUE) { 
     784                    print "<LI>MySQL database connection : Success"; 
     785 
     786                    $mysql_server_version = mysql_get_server_info(); 
     787                    print ("<LI>MySQL server version: $mysql_server_version"); 
     788 
     789                    #if ($mysql_server_version > $requiredMySQLVersion) { Todo : Do something } 
     790 
     791                    #printf("<LI>MySQL host info: %s\n", mysql_get_host_info()); 
     792 
     793                    print "<LI>Select DB $CONF_DATABASE_NAME : "; 
     794                    $select_db = mysql_select_db($CONF_DATABASE_NAME); 
     795 
     796                    if ($select_db == TRUE) { 
     797                        print "Success</UL>"; 
     798                        navigation(array (array ("title" => "Back", "page" => "database"), array ("title" => "Next", "page" => "dbinit"))); 
     799                    } 
     800                    else { 
     801                        print "</UL>ERROR (Unable to select the database)<BR>"; 
     802                        refreshButton(); 
     803                        navigation(array (array ("title" => "Back", "page" => "database"))); 
     804                    } 
     805                } 
     806                else { 
     807                    print "Unable to connect to database on <B>$CONF_DATABASE_HOST</B><BR>The database must be online to continue.<P>Please go back and retry with correct values"; 
     808                    refreshButton(); 
     809                    navigation(array (array ("title" => "Back", "page" => "database"))); 
     810                } 
     811                break; 
     812            default : 
     813                print<<<EndHTML 
    883814          The CONF_DBMS value <B>$CONF_DBMS</B> is not currently suported by this install script. 
    884815EndHTML; 
    885         navigation(array(array("title" => "Back", "page" => "database"))); 
    886     } 
    887   break; 
    888   ################################### 
    889   case 'dbinit': 
    890     print "<H1>Database initialisation</H1>"; 
    891  
    892     # SQL are executed with PHP, some lignes need to be commented 
    893     $file_db_version = 'UNKNOW'; 
    894     $patterns[0]     = '/CREATE DATABASE wifidog/'; 
    895     $patterns[1]     = '/\\\connect/'; 
    896     $patterns[2]     = '/COMMENT/'; 
    897     $patterns[3]     = '/SET default_tablespace/'; 
    898     $patterns[4]     = '/SET default_with_oids/'; 
    899     $replacements[0] = '-- '; 
    900     $replacements[1] = '-- '; 
    901     $replacements[2] = '-- '; 
    902     $replacements[3] = '-- '; 
    903     $replacements[4] = '-- '; 
    904  
    905     $content_schema_array = file("$basepath/../sql/wifidog-postgres-schema.sql") or die("Can not open $basepath/../sql/wifidog-postgres-schema.sql");       # Read SQL schema file 
    906     $content_schema       = implode("", $content_schema_array); 
    907     $content_data_array   = file("$basepath/../sql/wifidog-postgres-initial-data.sql"); # Read SQL initial data file 
    908     $content_data         = implode("", $content_data_array); 
    909  
    910     $db_schema_version   = ''; # Schema version query from database 
    911     $file_schema_version = ''; # Schema version from define(REQUIRED_SCHEMA_VERSION) in schema_validate.php 
    912  
    913     switch ($CONF_DBMS) { 
    914       case 'DBMS_POSTGRES': 
    915         $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; 
    916         $connection = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==<BR>"); 
    917  
    918         if (preg_match("/\('schema_version', '(\d+)'\);/", $content_data, $matchesArray)) # Get schema_version from initial data file 
    919           $file_db_version = $matchesArray[1]; 
    920  
    921         $contentArray = file("$basepath/include/schema_validate.php"); 
    922         foreach($contentArray as $line) { 
    923           #print "$line<BR>"; # Debug 
    924           if(preg_match("/^define\('REQUIRED_SCHEMA_VERSION', (\d+)\);/", $line, $matchesArray)) { 
    925             #print "REQUIRED_SCHEMA_VERSION = " . $matchesArray[1] . "<BR>"; 
    926             $file_schema_version = $matchesArray[1]; 
    927           } 
    928         } 
    929  
    930         # Get current database schema version (if defined) 
    931         $sql = "SELECT * FROM schema_info WHERE tag='schema_version'"; 
    932         if ($result = @pg_query($connection, $sql)) { # The @ remove warning display 
    933           $result_array = pg_fetch_all($result); 
    934           $db_shema_version = $result_array[0]['value']; 
    935  
    936           print "<P>On <B>$CONF_DATABASE_HOST</B>, Database <B>$CONF_DATABASE_NAME</B> exists and is "; 
    937           if ($db_shema_version == $file_schema_version) { 
    938             print "up to date (shema version <B>$db_shema_version</B>)."; 
    939             navigation(array(array("title" => "Back", "page" => "database"), array("title" => "Next", "page" => "options"))); 
    940           } elseif ($db_shema_version < $file_schema_version) { 
    941             print "at schema version <B>$db_shema_version</B>. The required schema version is <B>$file_schema_version</B><P>Please upgrade the database"; 
    942             navigation(array(array("title" => "Back", "page" => "database"), array("title" => "Upgrade", "page" => "schema_validate"), array("title" => "Next", "page" => "options"))); 
    943           } 
    944           else { print "Error : Unexpected result"; } 
    945           exit(); 
    946         } 
    947  
    948         print "<UL><LI>Creating wifidog database schema : "; 
    949         $content_schema = preg_replace($patterns, $replacements, $content_schema); # Comment bad SQL lines 
    950  
    951         $result = pg_query($connection, $content_schema) or die("<B>".pg_last_error()."</B> <=<BR>"); 
    952         print "OK"; 
    953  
    954         print "<LI>Creating wifidog database initial data : "; 
    955         $content_data = preg_replace($patterns, $replacements, $content_data); # Comment bad SQL lines 
    956  
    957         $result = pg_query($connection, $content_data) or die("<B>".pg_last_error()."</B> <=<BR>"); 
    958         print "OK</UL>"; 
    959  
    960         navigation(array(array("title" => "Back", "page" => "database"), array("title" => "Next", "page" => "options"))); 
    961       break; 
    962       ################################### 
    963       case 'DBMS_MYSQL': 
    964         print "MYSQL ... (Not working)<BR>\n"; 
    965         $ptr_connexion = @mysql_connect($CONF_DATABASE_HOST, $CONF_DATABASE_USER, $CONF_DATABASE_PASSWORD); 
    966         $select_db = mysql_select_db($CONF_DATABASE_NAME); 
    967  
    968         $previous_line = ''; # Used to remove "," on the line before CONSTRAINT removed line. 
    969  
    970         if ($debug) print "<PRE>"; 
    971  
    972         $inTable = 0; 
    973         foreach ($content_schema_array as $lineNum => $line) { 
    974 #          if (preg_match("/^--/", $line)) continue; # Remove commented lines 
    975 #          if (preg_match("/^$/", $line))  continue; # Remove empty lines 
    976           if ($debug) print "<B>ORI</B> $line"; 
    977           if (preg_match("/^CREATE TABLE/", $line, $matchesArray)) 
    978             $inTable = 1; 
    979           if ($inTable) { 
    980             if ($inTable && preg_match("/^\);$/", $line, $matchesArray)) { 
    981               #print "<B STYLE=\"color:#FF0000;\">OUT</B>\n"; 
    982  
    983               # PG    => ); 
    984               # MySQL => ) TYPE=InnoDB; 
    985               $line = preg_replace("/^\);$/", ") TYPE=InnoDB;", $line); 
    986               $inTable = 0; 
    987             } 
    988             else { 
    989               #print "<B>IN  \n</B>"; # The line is in CREATE TABLE 
    990  
    991               if(preg_match("/\s*CONSTRAINT.*\n$/", $line)) { # Remove CONSTRAINT. TODO : support constraint 
    992                 $line = preg_replace("/\s*CONSTRAINT.*\n$/", "", $line); 
    993                 $previous_line = preg_replace("/,$/", "", $previous_line); 
    994                 #print "<B STYLE=\"color:#FF0000;\">ICI : L=$line PL=$previous_line</B>"; 
    995               } 
    996               # Mettre TYPE=InnoDB uniquement pour table avec CONSTRAINT ??? 
    997  
    998               # PG    =>  token_status character varying(10) NOT NULL 
    999               # MySQL => `token_status` character varying(10) NOT NULL 
    1000               $line = preg_replace("/^(\s+)(\w+)/", "\${1}`\${2}`", $line); 
    1001  
    1002               $line = preg_replace("/DEFAULT ('.*')::character varying NOT NULL/", "NOT NULL default \${1}", $line); 
    1003  
    1004               $line = preg_replace("/text DEFAULT [\w':]+/", "text DEFAULT ''", $line); # MySQL does not support "text" default value 
    1005               #??? Erreur : 1101 - BLOB/TEXT column 'venue_type' can't have a default value. Solution : Changer 'text' pour varchar ??? 
    1006  
    1007               # PG    =>  token_status character varying(10) NOT NULL 
    1008               # MySQL =>  token_status VARCHAR(10) NOT NULL 
    1009               $line = preg_replace("/character varying\(/", "VARCHAR(", $line); 
    1010  
    1011               $line = preg_replace("/::character varying/", "", $line); # Remove string "::character varying" 
    1012  
    1013               # PG    => account_status integer, 
    1014               # MySQL => account_status int, 
    1015               $line = preg_replace("/integer/", "int", $line); 
    1016  
    1017               # TODO : Comprendre : Le timestamp de postgres est sous le format '2005-04-07 16:33:49.917127' 
    1018               #                     datetime de MySQL est '0000-00-00 00:00:00' 
    1019               $line = preg_replace("/timestamp without time zone/", "datetime", $line); 
    1020  
    1021               $line = preg_replace("/now\(\)/", "'NOW()'", $line); 
    1022  
    1023               #$line = preg_replace("/::text/", "", $line); 
    1024  
    1025               $line = preg_replace("/false/", "0", $line); # Change "false" strings for 0 (zero) 
    1026               $line = preg_replace("/true/", "1", $line);  # Change "true" strings for 1 (one) 
    1027               $line = preg_replace("/WITHOUT OIDS/", "", $line); # Remove "WITHOUT OIDS" 
    1028  
    1029               # PG    => binary_data bytea, 
    1030               # MySQL => binary_data MEDIUMBLOB 
    1031               # Uploading, Saving and Downloading Binary Data in a MySQL Database http://www.onlamp.com/lpt/a/370 
    1032               $line = preg_replace("/bytea/", "MEDIUMBLOB", $line); # maximum 16777215 (2^24 - 1) bytes 
    1033             } ### End of else. Regex in CREATE TABLE {}; 
    1034           } ### End of if ($inTable). 
    1035  
    1036           # PG    => CREATE INDEX idx_token ON connections USING btree (token); 
    1037           # MySQL => CREATE INDEX idx_token USING btree ON connections (token); 
    1038           $line = preg_replace("/(ON \w+) USING btree/", "USING btree \${1}", $line); 
    1039  
    1040           # SQL-query : CREATE UNIQUE INDEX idx_unique_username_and_account_origin USING btree ON users(username,account_origin) 
    1041           # MySQL said: #1170 - BLOB/TEXT column 'username' used in key specification without a key length 
    1042           # Solution : http://www.dbforums.com/t1100992.html 
    1043           $line = preg_replace("/CREATE UNIQUE INDEX idx_unique_username_and_account_origin USING btree ON users \(username, account_origin\);/", "CREATE UNIQUE INDEX idx_unique_username_and_account_origin USING btree ON users (username(100), account_origin(100));", $line); 
    1044  
    1045           $line = preg_replace("/CREATE INDEX idx_content_group_element_content_group_id USING btree ON content_group_element \(content_group_id\);/", "CREATE INDEX idx_content_group_element_content_group_id USING btree ON content_group_element (content_group_id(100));", $line); 
    1046  
    1047           if ($debug) print "NEW $line"; 
    1048             $content_mysql .= $previous_line; 
    1049           $previous_line = $line; 
    1050         } ### End of foreach ($content_schema_array as $lineNum => $line) 
    1051  
    1052         $content_mysql .= $previous_line; # TODO: verif save the last line ? 
    1053         if ($debug) print "<B STYLE=\"color:#FF0000;\">####################################################################</B>\n\n$content_mysql"; # Debug 
    1054         if ($debug) print "</PRE>"; 
    1055  
    1056 #        $content_data = implode("", $content_mysql); 
    1057  
    1058         $patterns[3]     = '/SET client_encoding/'; 
    1059         $patterns[4]     = '/SET check_function_bodies/'; 
    1060         $patterns[5]     = '/SET search_path/'; 
     816                navigation(array (array ("title" => "Back", "page" => "database"))); 
     817        } 
     818        break; 
     819        ################################### 
     820    case 'dbinit' : 
     821        print "<H1>Database initialisation</H1>"; 
     822 
     823        # SQL are executed with PHP, some lignes need to be commented 
     824        $file_db_version = 'UNKNOW'; 
     825        $patterns[0] = '/CREATE DATABASE wifidog/'; 
     826        $patterns[1] = '/\\\connect/'; 
     827        $patterns[2] = '/COMMENT/'; 
     828        $patterns[3] = '/SET default_tablespace/'; 
     829        $patterns[4] = '/SET default_with_oids/'; 
     830        $replacements[0] = '-- '; 
     831        $replacements[1] = '-- '; 
     832        $replacements[2] = '-- '; 
    1061833        $replacements[3] = '-- '; 
    1062834        $replacements[4] = '-- '; 
    1063         $replacements[5] = '-- '; 
    1064  
    1065         $content_mysql = preg_replace($patterns, $replacements, $content_mysql); 
    1066  
    1067         print "<PRE>$content_mysql</PRE>"; # Debug 
    1068  
    1069         exit(); 
    1070  
    1071         $result = mysql_query($content_mysql); 
    1072         if (!$result) { 
    1073           die('Invalid query: ' . mysql_error()); 
    1074         } 
    1075  
    1076         navigation(array(array("title" => "Back", "page" => "database"), array("title" => "Next", "page" => "dbinit"))); 
    1077       break; 
    1078       default: 
    1079         print <<<EndHTML 
     835 
     836        $content_schema_array = file(WIFIDOG_ABS_FILE_PATH."../sql/wifidog-postgres-schema.sql") or die("Can not open $basepath/../sql/wifidog-postgres-schema.sql"); # Read SQL schema file 
     837        $content_schema = implode("", $content_schema_array); 
     838        $content_data_array = file(WIFIDOG_ABS_FILE_PATH."../sql/wifidog-postgres-initial-data.sql"); # Read SQL initial data file 
     839        $content_data = implode("", $content_data_array); 
     840 
     841        $db_schema_version = ''; # Schema version query from database 
     842        $file_schema_version = ''; # Schema version from define(REQUIRED_SCHEMA_VERSION) in schema_validate.php 
     843 
     844        switch ($CONF_DBMS) { 
     845            case 'DBMS_POSTGRES' : 
     846                $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; 
     847                $connection = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==<BR>"); 
     848 
     849                if (preg_match("/\('schema_version', '(\d+)'\);/", $content_data, $matchesArray)) # Get schema_version from initial data file 
     850                    $file_db_version = $matchesArray[1]; 
     851 
     852                $contentArray = file(WIFIDOG_ABS_FILE_PATH."include/schema_validate.php"); 
     853                foreach ($contentArray as $line) { 
     854                    #print "$line<BR>"; # Debug 
     855                    if (preg_match("/^define\('REQUIRED_SCHEMA_VERSION', (\d+)\);/", $line, $matchesArray)) { 
     856                        #print "REQUIRED_SCHEMA_VERSION = " . $matchesArray[1] . "<BR>"; 
     857                        $file_schema_version = $matchesArray[1]; 
     858                    } 
     859                } 
     860 
     861                # Get current database schema version (if defined) 
     862                $sql = "SELECT * FROM schema_info WHERE tag='schema_version'"; 
     863                if ($result = @ pg_query($connection, $sql)) { # The @ remove warning display 
     864                    $result_array = pg_fetch_all($result); 
     865                    $db_shema_version = $result_array[0]['value']; 
     866 
     867                    print "<P>On <B>$CONF_DATABASE_HOST</B>, Database <B>$CONF_DATABASE_NAME</B> exists and is "; 
     868                    if ($db_shema_version == $file_schema_version) { 
     869                        print "up to date (shema version <B>$db_shema_version</B>)."; 
     870                        navigation(array (array ("title" => "Back", "page" => "database"), array ("title" => "Next", "page" => "options"))); 
     871                    } 
     872                    elseif ($db_shema_version < $file_schema_version) { 
     873                        print "at schema version <B>$db_shema_version</B>. The required schema version is <B>$file_schema_version</B><P>Please upgrade the database"; 
     874                        navigation(array (array ("title" => "Back", "page" => "database"), array ("title" => "Upgrade", "page" => "schema_validate"), array ("title" => "Next", "page" => "options"))); 
     875                    } 
     876                    else { 
     877                        print "Error : Unexpected result"; 
     878                    } 
     879                    exit (); 
     880                } 
     881 
     882                print "<UL><LI>Creating wifidog database schema : "; 
     883                $content_schema = preg_replace($patterns, $replacements, $content_schema); # Comment bad SQL lines 
     884 
     885                $result = pg_query($connection, $content_schema) or die("<B>".pg_last_error()."</B> <=<BR>"); 
     886                print "OK"; 
     887 
     888                print "<LI>Creating wifidog database initial data : "; 
     889                $content_data = preg_replace($patterns, $replacements, $content_data); # Comment bad SQL lines 
     890 
     891                $result = pg_query($connection, $content_data) or die("<B>".pg_last_error()."</B> <=<BR>"); 
     892                print "OK</UL>"; 
     893 
     894                navigation(array (array ("title" => "Back", "page" => "database"), array ("title" => "Next", "page" => "options"))); 
     895                break; 
     896                ################################### 
     897            case 'DBMS_MYSQL' : 
     898                print "MYSQL ... (Not working)<BR>\n"; 
     899                $ptr_connexion = @ mysql_connect($CONF_DATABASE_HOST, $CONF_DATABASE_USER, $CONF_DATABASE_PASSWORD); 
     900                $select_db = mysql_select_db($CONF_DATABASE_NAME); 
     901 
     902                $previous_line = ''; # Used to remove "," on the line before CONSTRAINT removed line. 
     903 
     904                if ($debug) 
     905                    print "<PRE>"; 
     906 
     907                $inTable = 0; 
     908                foreach ($content_schema_array as $lineNum => $line) { 
     909                    #          if (preg_match("/^--/", $line)) continue; # Remove commented lines 
     910                    #          if (preg_match("/^$/", $line))  continue; # Remove empty lines 
     911                    if ($debug) 
     912                        print "<B>ORI</B> $line"; 
     913                    if (preg_match("/^CREATE TABLE/", $line, $matchesArray)) 
     914                        $inTable = 1; 
     915                    if ($inTable) { 
     916                        if ($inTable && preg_match("/^\);$/", $line, $matchesArray)) { 
     917                            #print "<B STYLE=\"color:#FF0000;\">OUT</B>\n"; 
     918 
     919                            # PG    => ); 
     920                            # MySQL => ) TYPE=InnoDB; 
     921                            $line = preg_replace("/^\);$/", ") TYPE=InnoDB;", $line); 
     922                            $inTable = 0; 
     923                        } 
     924                        else { 
     925                            #print "<B>IN  \n</B>"; # The line is in CREATE TABLE 
     926 
     927                            if (preg_match("/\s*CONSTRAINT.*\n$/", $line)) { # Remove CONSTRAINT. TODO : support constraint 
     928                                $line = preg_replace("/\s*CONSTRAINT.*\n$/", "", $line); 
     929                                $previous_line = preg_replace("/,$/", "", $previous_line); 
     930                                #print "<B STYLE=\"color:#FF0000;\">ICI : L=$line PL=$previous_line</B>"; 
     931                            } 
     932                            # Mettre TYPE=InnoDB uniquement pour table avec CONSTRAINT ??? 
     933 
     934                            # PG    =>  token_status character varying(10) NOT NULL 
     935                            # MySQL => `token_status` character varying(10) NOT NULL 
     936                            $line = preg_replace("/^(\s+)(\w+)/", "\${1}`\${2}`", $line); 
     937 
     938                            $line = preg_replace("/DEFAULT ('.*')::character varying NOT NULL/", "NOT NULL default \${1}", $line); 
     939 
     940                            $line = preg_replace("/text DEFAULT [\w':]+/", "text DEFAULT ''", $line); # MySQL does not support "text" default value 
     941                            #??? Erreur : 1101 - BLOB/TEXT column 'venue_type' can't have a default value. Solution : Changer 'text' pour varchar ??? 
     942 
     943                            # PG    =>  token_status character varying(10) NOT NULL 
     944                            # MySQL =>  token_status VARCHAR(10) NOT NULL 
     945                            $line = preg_replace("/character varying\(/", "VARCHAR(", $line); 
     946 
     947                            $line = preg_replace("/::character varying/", "", $line); # Remove string "::character varying" 
     948 
     949                            # PG    => account_status integer, 
     950                            # MySQL => account_status int, 
     951                            $line = preg_replace("/integer/", "int", $line); 
     952 
     953                            # TODO : Comprendre : Le timestamp de postgres est sous le format '2005-04-07 16:33:49.917127' 
     954                            #                     datetime de MySQL est '0000-00-00 00:00:00' 
     955                            $line = preg_replace("/timestamp without time zone/", "datetime", $line); 
     956 
     957                            $line = preg_replace("/now\(\)/", "'NOW()'", $line); 
     958 
     959                            #$line = preg_replace("/::text/", "", $line); 
     960 
     961                            $line = preg_replace("/false/", "0", $line); # Change "false" strings for 0 (zero) 
     962                            $line = preg_replace("/true/", "1", $line); # Change "true" strings for 1 (one) 
     963                            $line = preg_replace("/WITHOUT OIDS/", "", $line); # Remove "WITHOUT OIDS" 
     964 
     965                            # PG    => binary_data bytea, 
     966                            # MySQL => binary_data MEDIUMBLOB 
     967                            # Uploading, Saving and Downloading Binary Data in a MySQL Database http://www.onlamp.com/lpt/a/370 
     968                            $line = preg_replace("/bytea/", "MEDIUMBLOB", $line); # maximum 16777215 (2^24 - 1) bytes 
     969                        } ### End of else. Regex in CREATE TABLE {}; 
     970                    } ### End of if ($inTable). 
     971 
     972                    # PG    => CREATE INDEX idx_token ON connections USING btree (token); 
     973                    # MySQL => CREATE INDEX idx_token USING btree ON connections (token); 
     974                    $line = preg_replace("/(ON \w+) USING btree/", "USING btree \${1}", $line); 
     975 
     976                    # SQL-query : CREATE UNIQUE INDEX idx_unique_username_and_account_origin USING btree ON users(username,account_origin) 
     977                    # MySQL said: #1170 - BLOB/TEXT column 'username' used in key specification without a key length 
     978                    # Solution : http://www.dbforums.com/t1100992.html 
     979                    $line = preg_replace("/CREATE UNIQUE INDEX idx_unique_username_and_account_origin USING btree ON users \(username, account_origin\);/", "CREATE UNIQUE INDEX idx_unique_username_and_account_origin USING btree ON users (username(100), account_origin(100));", $line); 
     980 
     981                    $line = preg_replace("/CREATE INDEX idx_content_group_element_content_group_id USING btree ON content_group_element \(content_group_id\);/", "CREATE INDEX idx_content_group_element_content_group_id USING btree ON content_group_element (content_group_id(100));", $line); 
     982 
     983                    if ($debug) 
     984                        print "NEW $line"; 
     985                    $content_mysql .= $previous_line; 
     986                    $previous_line = $line; 
     987                } ### End of foreach ($content_schema_array as $lineNum => $line) 
     988 
     989                $content_mysql .= $previous_line; # TODO: verif save the last line ? 
     990                if ($debug) 
     991                    print "<B STYLE=\"color:#FF0000;\">####################################################################</B>\n\n$content_mysql"; # Debug 
     992                if ($debug) 
     993                    print "</PRE>"; 
     994 
     995                #        $content_data = implode("", $content_mysql); 
     996 
     997                $patterns[3] = '/SET client_encoding/'; 
     998                $patterns[4] = '/SET check_function_bodies/'; 
     999                $patterns[5] = '/SET search_path/'; 
     1000                $replacements[3] = '-- '; 
     1001                $replacements[4] = '-- '; 
     1002                $replacements[5] = '-- '; 
     1003 
     1004                $content_mysql = preg_replace($patterns, $replacements, $content_mysql); 
     1005 
     1006                print "<PRE>$content_mysql</PRE>"; # Debug 
     1007 
     1008                exit (); 
     1009 
     1010                $result = mysql_query($content_mysql); 
     1011                if (!$result) { 
     1012                    die('Invalid query: '.mysql_error()); 
     1013                } 
     1014 
     1015                navigation(array (array ("title" => "Back", "page" => "database"), array ("title" => "Next", "page" => "dbinit"))); 
     1016                break; 
     1017            default : 
     1018                print<<<EndHTML 
    10801019          The CONF_DBMS value <B>$CONF_DBMS</B> is not currently suported by this install script. 
    10811020EndHTML; 
    1082         navigation(array(array("title" => "Back", "page" => "database"))); 
    1083     } 
    1084   break; 
    1085  
    1086   ################################### 
    1087   case 'schema_validate': 
    1088     print "<H1>Database schema upgrade</H1>\n"; 
    1089  
    1090     require_once(dirname(__FILE__) . '/include/common.php'); 
    1091  
    1092     require_once('classes/AbstractDb.php'); 
    1093     require_once('classes/Session.php'); 
    1094     require_once('include/schema_validate.php'); 
    1095  
    1096     validate_schema(); 
    1097  
    1098     navigation(array(array("title" => "Back", "page" => "dbinit"), array("title" => "Next", "page" => "options"))); 
    1099  
    1100     //navigation(array(array("title" => "Back", "page" => "dbinit"))); 
    1101   break; 
    1102  
    1103   ################################### 
    1104   case 'options': 
    1105     # TODO : Tester que la connection SSL est fonctionnelle 
    1106     #        Options avancees : Supporter les define de [SMARTY|MAGPIE|PHLICKR|JPGRAPH]_REL_PATH 
    1107     print <<< EndHTML 
     1021                navigation(array (array ("title" => "Back", "page" => "database"))); 
     1022        } 
     1023        break; 
     1024 
     1025        ################################### 
     1026    case 'schema_validate' : 
     1027        print "<H1>Database schema upgrade</H1>\n"; 
     1028 
     1029        require_once (dirname(__FILE__).'/include/common.php'); 
     1030 
     1031        require_once ('classes/AbstractDb.php'); 
     1032        require_once ('classes/Session.php'); 
     1033        require_once ('include/schema_validate.php'); 
     1034 
     1035        validate_schema(); 
     1036 
     1037        navigation(array (array ("title" => "Back", "page" => "dbinit"), array ("title" => "Next", "page" => "options"))); 
     1038 
     1039        //navigation(array(array("title" => "Back", "page" => "dbinit"))); 
     1040        break; 
     1041 
     1042        ################################### 
     1043    case 'options' : 
     1044        # TODO : Tester que la connection SSL est fonctionnelle 
     1045        #        Options avancees : Supporter les define de [SMARTY|MAGPIE|PHLICKR|JPGRAPH]_REL_PATH 
     1046        print<<< EndHTML 
    11081047<H1>Options</H1> 
    11091048  <TABLE border="1"> 
     
    11111050EndHTML; 
    11121051 
    1113     #$neededPackages['phlickr']['available'] = 0; 
    1114     #$neededExtentions['xml']['available'] = 0; 
    1115     foreach ($optionsInfo as $name => $foo) {         # Foreach generate all <TABLE> fields 
    1116       $value  = $configArray[$name];                  # Value of option in config.php 
    1117       $title  = $optionsInfo[$name]['title'];         # Field Title 
    1118       $message = $optionsInfo[$name]['message'];      # Message why option is disable 
    1119       $depend = @eval($optionsInfo[$name]['depend']); # Evaluate the dependencie 
    1120       $selectedTrue = ''; $selectedFalse = '';        # Initialize value 
    1121       $value  == 'true' ? $selectedTrue = 'SELECTED' : $selectedFalse = 'SELECTED';           # Use to select the previous saved option 
    1122       $depend == 1      ? $disabled     = ''         : $disabled = 'DISABLED';                # Disable <SELECT> if dependencie is not satisfied 
    1123       $jscript = "<script type=\"text/javascript\"> newConfig(\"$name=false\"); </script>\n"; # Use to save a failed dependencie (option=false) 
    1124       if ($disabled == '') # Dependencie ok, erase $jscript value 
    1125         $jscript = ''; 
    1126  
    1127       print <<< EndHTML 
     1052        #$neededPackages['phlickr']['available'] = 0; 
     1053        #$neededExtentions['xml']['available'] = 0; 
     1054        foreach ($optionsInfo as $name => $foo) { # Foreach generate all <TABLE> fields 
     1055            $value = $configArray[$name]; # Value of option in config.php 
     1056            $title = $optionsInfo[$name]['title']; # Field Title 
     1057            $message = $optionsInfo[$name]['message']; # Message why option is disable 
     1058            $depend = @ eval ($optionsInfo[$name]['depend']); # Evaluate the dependencie 
     1059            $selectedTrue = ''; 
     1060            $selectedFalse = ''; # Initialize value 
     1061            $value == 'true' ? $selectedTrue = 'SELECTED' : $selectedFalse = 'SELECTED'; # Use to select the previous saved option 
     1062            $depend == 1 ? $disabled = '' : $disabled = 'DISABLED'; # Disable <SELECT> if dependencie is not satisfied 
     1063            $jscript = "<script type=\"text/javascript\"> newConfig(\"$name=false\"); </script>\n"; # Use to save a failed dependencie (option=false) 
     1064            if ($disabled == '') # Dependencie ok, erase $jscript value 
     1065                $jscript = ''; 
     1066 
     1067            print<<< EndHTML 
    11281068  <TR> 
    11291069    <TD>$title</TD> 
     
    11371077  $jscript 
    11381078EndHTML; 
    1139     } # End or foreach 
    1140     print <<< EndHTML 
     1079        } # End or foreach 
     1080        print<<< EndHTML 
    11411081    </TABLE> 
    11421082 
     
    11461086EndHTML; 
    11471087 
    1148     foreach ($optionsInfo as $name => $foo) { # Generate the javascript to save value on submit 
    1149     print <<< EndHTML 
     1088        foreach ($optionsInfo as $name => $foo) { # Generate the javascript to save value on submit 
     1089            print<<< EndHTML 
    11501090    if (!document.myform.$name.disabled) 
    11511091      newConfig("$name=" + document.myform.$name.value); 
    11521092 
    11531093EndHTML; 
    1154     } # End Foreach 
    1155  
    1156     print <<< EndHTML 
     1094        } # End Foreach 
     1095 
     1096        print<<< EndHTML 
    11571097  } 
    11581098</script> 
    11591099 
    11601100EndHTML; 
    1161     navigation(array(array("title" => "Back", "page" => "dbinit"))); 
    1162  
    1163     print <<< EndHTML 
     1101        navigation(array (array ("title" => "Back", "page" => "dbinit"))); 
     1102 
     1103        print<<< EndHTML 
    11641104<P><A HREF="#" ONCLICK="javascript: document.myform.page.value='languages'; submitOptionsValue(); document.myform.submit();" CLASS="button">Next</A></P> 
    11651105EndHTML; 
    11661106 
    1167   break; 
    1168  
    1169   ################################### 
    1170   case 'languages': 
    1171     print "<H1>Languages configuration</H1>"; 
    1172     print <<< EndHTML 
     1107        break; 
     1108 
     1109        ################################### 
     1110    case 'languages' : 
     1111        print "<H1>Languages configuration</H1>"; 
     1112        print<<< EndHTML 
    11731113      <P>Not yet implemented ...</P> 
    11741114      <P>Will allow selecting language to use.</P> 
     
    11771117<P><B>I repeat</B> : This is an example of message you can see in the top of your working auth-server if language are not set correctly. To change these values please edit <B>config.php</B> in auth-server install directory. Look for "Available locales" and "Default language" header in config.php. 
    11781118EndHTML; 
    1179 //    exec("locale -a 2>&1", $output, $return); 
    1180  
    1181     navigation(array(array("title" => "Back", "page" => "options"), array("title" => "Next", "page" => "radius"))); 
    1182   break; 
    1183  
    1184   ################################### 
    1185   case 'radius': 
    1186     print "<H1>Radius Authenticator configuration</H1>"; 
    1187     print "<P>Not yet implemented ..."; 
    1188  
    1189     # Dependencies 
    1190     #$neededExtentions['mcrypt']['available']; 
    1191     #$neededExtentions['mhash']['available']; 
    1192     #$neededExtentions['xmlrpc']['available']; 
    1193     #$neededPEARPackages['radius']['available']; 
    1194     #$neededPEARPackages['Auth_RADIUS']['available']; 
    1195     #$neededPEARPackages['Crypt_CHAP']['available']; 
    1196  
    1197     navigation(array(array("title" => "Back", "page" => "languages"), array("title" => "Next", "page" => "admin"))); 
    1198   break; 
    1199  
    1200   ################################### 
    1201   case 'admin': 
    1202     print "<H1>Administration account</H1>"; 
    1203     # TODO : Allow to create more than one admin account and list the current admin users 
    1204     #        Allow admin to choose to show or not is username 
    1205     empty($_REQUEST['username'])  ? $username   = 'admin'                  : $username  = $_REQUEST['username']; 
    1206     empty($_REQUEST['password'])  ? $password   = ''                       : $password  = $_REQUEST['password']; 
    1207     empty($_REQUEST['password2']) ? $password2  = ''                       : $password2 = $_REQUEST['password2']; 
    1208     empty($_REQUEST['email'])     ? $email      = $_SERVER['SERVER_ADMIN'] : $email      = $_REQUEST['email']; 
    1209  
    1210     $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; 
    1211     $connection = pg_connect($conn_string) or die(); 
    1212  
    1213     if ($action == 'create') { 
    1214 //      require_once(dirname(__FILE__) . '/config.php'); 
    1215       require_once(dirname(__FILE__) . '/include/common.php'); 
    1216       require_once(dirname(__FILE__) . '/classes/User.php'); 
    1217  
    1218       $created_user = User :: createUser(get_guid(), $username, Network::getDefaultNetwork(), $email, $password); 
    1219       $user_id = $created_user->getId(); 
    1220  
    1221       # Add user to admin table, hide his username and set his account status to 1 (allowed) 
    1222       $sql = "INSERT INTO administrators (user_id) VALUES ('$user_id'); UPDATE users SET  account_status='1', never_show_username=true WHERE user_id='$user_id'"; 
    1223       $result = pg_query($connection, $sql); 
    1224     } 
    1225  
    1226     $sql = "SELECT * FROM users NATURAL JOIN administrators WHERE account_origin = 'default-network'"; 
    1227     $result = pg_query($connection, $sql); 
    1228     $result_array = pg_fetch_all($result); 
    1229     $username_db = $result_array[0]['username']; 
    1230  
    1231     if (!empty($username_db)) { 
    1232       print "<P>Your administrator user account is <B>$username_db</B>"; 
    1233       navigation(array(array("title" => "Back", "page" => "radius"), array("title" => "Next", "page" => "network"))); 
    1234     } 
    1235     else { 
    1236       print<<<EndHTML 
     1119        //    exec("locale -a 2>&1", $output, $return); 
     1120 
     1121        navigation(array (array ("title" => "Back", "page" => "options"), array ("title" => "Next", "page" => "radius"))); 
     1122        break; 
     1123 
     1124        ################################### 
     1125    case 'radius' : 
     1126        print "<H1>Radius Authenticator configuration</H1>"; 
     1127        print "<P>Not yet implemented ..."; 
     1128 
     1129        # Dependencies 
     1130        #$neededExtentions['mcrypt']['available']; 
     1131        #$neededExtentions['mhash']['available']; 
     1132        #$neededExtentions['xmlrpc']['available']; 
     1133        #$neededPEARPackages['radius']['available']; 
     1134        #$neededPEARPackages['Auth_RADIUS']['available']; 
     1135        #$neededPEARPackages['Crypt_CHAP']['available']; 
     1136 
     1137        navigation(array (array ("title" => "Back", "page" => "languages"), array ("title" => "Next", "page" => "admin"))); 
     1138        break; 
     1139 
     1140        ################################### 
     1141    case 'admin' : 
     1142        print "<H1>Administration account</H1>"; 
     1143        # TODO : Allow to create more than one admin account and list the current admin users 
     1144        #        Allow admin to choose to show or not is username 
     1145        empty ($_REQUEST['username']) ? $username = 'admin' : $username = $_REQUEST['username']; 
     1146        empty ($_REQUEST['password']) ? $password = '' : $password = $_REQUEST['password']; 
     1147        empty ($_REQUEST['password2']) ? $password2 = '' : $password2 = $_REQUEST['password2']; 
     1148        empty ($_REQUEST['email']) ? $email = $_SERVER['SERVER_ADMIN'] : $email = $_REQUEST['email']; 
     1149 
     1150        $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; 
     1151        $connection = pg_connect($conn_string) or die(); 
     1152 
     1153        if ($action == 'create') { 
     1154            //      require_once(dirname(__FILE__) . '/config.php'); 
     1155            require_once (dirname(__FILE__).'/include/common.php'); 
     1156            require_once (dirname(__FILE__).'/classes/User.php'); 
     1157 
     1158            $created_user = User :: createUser(get_guid(), $username, Network :: getDefaultNetwork(), $email, $password); 
     1159            $user_id = $created_user->getId(); 
     1160 
     1161            # Add user to admin table, hide his username and set his account status to 1 (allowed) 
     1162            $sql = "INSERT INTO administrators (user_id) VALUES ('$user_id'); UPDATE users SET  account_status='1', never_show_username=true WHERE user_id='$user_id'"; 
     1163            $result = pg_query($connection, $sql); 
     1164        } 
     1165 
     1166        $sql = "SELECT * FROM users NATURAL JOIN administrators WHERE account_origin = 'default-network'"; 
     1167        $result = pg_query($connection, $sql); 
     1168        $result_array = pg_fetch_all($result); 
     1169        $username_db = $result_array[0]['username']; 
     1170 
     1171        if (!empty ($username_db)) { 
     1172            print "<P>Your administrator user account is <B>$username_db</B>"; 
     1173            navigation(array (array ("title" => "Back", "page" => "radius"), array ("title" => "Next", "page" => "network"))); 
     1174        } 
     1175        else { 
     1176            print<<<EndHTML 
    12371177        <P> 
    12381178        <TABLE BORDER="1"> 
     
    12721212 
    12731213EndHTML; 
    1274     navigation(array(array("title" => "Back", "page" => "radius"))); 
    1275     print "<P><A HREF=\"#\" ONCLICK=\"javascript: submitValue();\" CLASS=\"button\">Next</A></P>\n"; 
    1276     } 
    1277   break; 
    1278  
    1279   ################################### 
    1280   case 'network': 
    1281     print "<H1>Network</H1>"; 
    1282  
    1283     //$HOTSPOT_NETWORK_NAME          = $configArray['HOTSPOT_NETWORK_NAME']; 
    1284     //$HOTSPOT_NETWORK_URL           = $configArray['HOTSPOT_NETWORK_URL']; 
    1285     //$TECH_SUPPORT_EMAIL            = $configArray['TECH_SUPPORT_EMAIL']; 
    1286     //$VALIDATION_GRACE_TIME         = $configArray['VALIDATION_GRACE_TIME']; 
    1287     //$VALIDATION_EMAIL_FROM_ADDRESS = $configArray['VALIDATION_EMAIL_FROM_ADDRESS']; 
    1288  
    1289         /** 
    1290         * @deprecated version - Dec 26, 2005 - Needs to use network abstraction 
    1291         * 
    1292         * 
    1293         * <P> 
    1294   <TABLE border="1"> 
    1295   <TR> 
    1296     <TD>Network Name</TD><TD><INPUT type="text" name="HOTSPOT_NETWORK_NAME" value="" size="30"></TD> 
    1297   </TR> 
    1298   <TR> 
    1299     <TD>Network URL</TD><TD><INPUT type="text" name="HOTSPOT_NETWORK_URL" value="" size="30"></TD> 
    1300   </TR> 
    1301   <TR> 
    1302     <TD>Tech Support Email</TD><TD><INPUT type="text" name="TECH_SUPPORT_EMAIL" value="" size="30"></TD> 
    1303   </TR> 
    1304   <TR> 
    1305     <TD>Validation Grace Time (min)</TD><TD><INPUT type="text" name="VALIDATION_GRACE_TIME" value="" size="30"></TD> 
    1306   </TR> 
    1307   <TR> 
    1308     <TD>Validation Email (send from)</TD><TD><INPUT type="text" name="VALIDATION_EMAIL_FROM_ADDRESS" value="" size="30"></TD> 
    1309   </TR> 
    1310   </TABLE> 
    1311         */ 
    1312         print "Need to reimplement this... Until then connect to the administration pages and modify it by yourself."; 
    1313  
    1314     print <<< EndHTML 
     1214            navigation(array (array ("title" => "Back", "page" => "radius"))); 
     1215            print "<P><A HREF=\"#\" ONCLICK=\"javascript: submitValue();\" CLASS=\"button\">Next</A></P>\n"; 
     1216        } 
     1217        break; 
     1218 
     1219        ################################### 
     1220    case 'network' : 
     1221        print "<H1>Network</H1>"; 
     1222 
     1223        //$HOTSPOT_NETWORK_NAME          = $configArray['HOTSPOT_NETWORK_NAME']; 
     1224        //$HOTSPOT_NETWORK_URL           = $configArray['HOTSPOT_NETWORK_URL']; 
     1225        //$TECH_SUPPORT_EMAIL            = $configArray['TECH_SUPPORT_EMAIL']; 
     1226        //$VALIDATION_GRACE_TIME         = $configArray['VALIDATION_GRACE_TIME']; 
     1227        //$VALIDATION_EMAIL_FROM_ADDRESS = $configArray['VALIDATION_EMAIL_FROM_ADDRESS']; 
     1228 
     1229        /** 
     1230        * @deprecated version - Dec 26, 2005 - Needs to use network abstraction 
     1231        * 
     1232        * 
     1233        * <P> 
     1234        <TABLE border="1"> 
     1235        <TR> 
     1236        <TD>Network Name</TD><TD><INPUT type="text" name="HOTSPOT_NETWORK_NAME" value="" size="30"></TD> 
     1237        </TR> 
     1238        <TR> 
     1239        <TD>Network URL</TD><TD><INPUT type="text" name="HOTSPOT_NETWORK_URL" value="" size="30"></TD> 
     1240        </TR> 
     1241        <TR> 
     1242        <TD>Tech Support Email</TD><TD><INPUT type="text" name="TECH_SUPPORT_EMAIL" value="" size="30"></TD> 
     1243        </TR> 
     1244        <TR> 
     1245        <TD>Validation Grace Time (min)</TD><TD><INPUT type="text" name="VALIDATION_GRACE_TIME" value="" size="30"></TD> 
     1246        </TR> 
     1247        <TR> 
     1248        <TD>Validation Email (send from)</TD><TD><INPUT type="text" name="VALIDATION_EMAIL_FROM_ADDRESS" value="" size="30"></TD> 
     1249        </TR> 
     1250        </TABLE> 
     1251        */ 
     1252        print "Need to reimplement this... Until then connect to the administration pages and modify it by yourself."; 
     1253 
     1254        print<<< EndHTML 
    13151255 
    13161256 
     
    13271267EndHTML; 
    13281268 
    1329     navigation(array(array("title" => "Back", "page" => "admin"))); 
    1330  
    1331     print <<< EndHTML 
     1269        navigation(array (array ("title" => "Back", "page" => "admin"))); 
     1270 
     1271        print<<< EndHTML 
    13321272<P><A HREF="#" ONCLICK="javascript: document.myform.page.value='hotspot'; submitOptionsValue(); document.myform.submit();" CLASS="button">Next</A></P> 
    13331273EndHTML; 
    1334     #navigation(array(array("title" => "Back", "page" => "admin"), array("title" => "Next", "page" => "hotspot"))); 
    1335   break; 
    1336  
    1337   ################################### 
    1338   case 'hotspot': 
    1339     print "<H1>Hotspot</H1>"; 
    1340     print "<P>A default hotspot has already been created<P>Use administration interface to add more hotspots."; 
    1341     navigation(array(array("title" => "Back", "page" => "network"), array("title" => "Next", "page" => "end"))); 
    1342   break; 
    1343  
    1344   ################################### 
    1345   case 'delete': 
    1346     print<<<EndHTML 
     1274        #navigation(array(array("title" => "Back", "page" => "admin"), array("title" => "Next", "page" => "hotspot"))); 
     1275        break; 
     1276 
     1277        ################################### 
     1278    case 'hotspot' : 
     1279        print "<H1>Hotspot</H1>"; 
     1280        print "<P>A default hotspot has already been created<P>Use administration interface to add more hotspots."; 
     1281        navigation(array (array ("title" => "Back", "page" => "network"), array ("title" => "Next", "page" => "end"))); 
     1282        break; 
     1283 
     1284        ################################### 
     1285    case 'delete' : 
     1286        print<<<EndHTML 
    13471287  <H1>Delete temporary files</H1> 
    13481288  ... 
    13491289EndHTML; 
    1350     #navigation(array(array("title" => "Back", "page" => "hotspot"))); 
    1351   break; 
    1352  
    1353   ################################### 
    1354   case 'end': 
    1355     $url = 'http://' . $_SERVER['HTTP_HOST'] . $system_path; 
    1356     print<<<EndHTML 
     1290        #navigation(array(array("title" => "Back", "page" => "hotspot"))); 
     1291        break; 
     1292 
     1293        ################################### 
     1294    case 'end' : 
     1295        $url = 'http://'.$_SERVER['HTTP_HOST'].SYSTEM_PATH; 
     1296        print<<<EndHTML 
    13571297  <H1>Thanks for using Wifidog</H1> 
    13581298  Redirection to your new WifiDog Authentification Server in 3 seconds 
     
    13781318</PRE> 
    13791319EndHTML; 
    1380     #navigation(array(array("title" => "Back", "page" => "hotspot"))); 
    1381   break; 
    1382  
    1383   ################################### 
    1384   case 'toc': 
    1385     print "<H1>Table of content</H1>"; 
    1386     $contentArray = file(__file__); # Read myself 
    1387     print "<UL>\n"; 
    1388     foreach($contentArray as $line) { 
    1389       if(preg_match("/^  case '(\w+)':/", $line, $matchesArray)) { # Parse for "case" regex 
    1390         if ($matchesArray[1] == 'toc') 
    1391           continue; 
    1392         print "<LI><A HREF=\"" . $_SERVER['SCRIPT_NAME'] . "?page=" . $matchesArray[1] . "\">" . $matchesArray[1] . "</A>\n"; # Display a Table of Content 
    1393       } 
    1394     } 
    1395     print "</UL>\n"; 
    1396   break; 
    1397   ################################### 
    1398   case 'notes': 
    1399     print <<<EndHTML 
     1320        #navigation(array(array("title" => "Back", "page" => "hotspot"))); 
     1321        break; 
     1322 
     1323        ################################### 
     1324    case 'toc' : 
     1325        print "<H1>Table of content</H1>"; 
     1326        $contentArray = file(__file__); # Read myself 
     1327        print "<UL>\n"; 
     1328        foreach ($contentArray as $line) { 
     1329            if (preg_match("/^  case '(\w+)':/", $line, $matchesArray)) { # Parse for "case" regex 
     1330                if ($matchesArray[1] == 'toc') 
     1331                    continue; 
     1332                print "<LI><A HREF=\"".$_SERVER['SCRIPT_NAME']."?page=".$matchesArray[1]."\">".$matchesArray[1]."</A>\n"; # Display a Table of Content 
     1333            } 
     1334        } 
     1335        print "</UL>\n"; 
     1336        break; 
     1337        ################################### 
     1338    case 'notes' : 
     1339        print<<<EndHTML 
    14001340<!-- /* Editor highlighting trick --> 
    14011341<PRE> 
     
    14371377<!-- Editor highlighting trick */ --> 
    14381378EndHTML; 
    1439   break; 
    1440   ################################### 
    1441 /*  case 'phpinfo': // Use for debugging, to be removed 
    1442     print "<PRE>"; 
    1443     print_r(get_loaded_extensions()); 
    1444     print "</PRE><BR><BR>"; 
    1445     phpinfo(); 
    1446   break;*/ 
    1447  
    1448   default: 
    1449     $WIFIDOG_VERSION = $configArray['WIFIDOG_VERSION']; 
    1450     # TODO : Add links to auth-server web documents 
    1451     print <<<EndHTML 
     1379        break; 
     1380        ################################### 
     1381        /*  case 'phpinfo': // Use for debugging, to be removed 
     1382            print "<PRE>"; 
     1383            print_r(get_loaded_extensions()); 
     1384            print "</PRE><BR><BR>"; 
     1385            phpinfo(); 
     1386          break;*/ 
     1387 
     1388    default : 
     1389        $WIFIDOG_VERSION = $configArray['WIFIDOG_VERSION']; 
     1390        # TODO : Add links to auth-server web documents 
     1391        print<<<EndHTML 
    14521392<H1>Welcome to WifiDog Auth-Server installation and configuration script.</H1> 
    14531393<P>This installation still needs improvement, so please any report bug to the mailing list for better support.<BR/> 
     
    14781418EndHTML; 
    14791419 
    1480     navigation(array(array("title" => "Next", "page" => "version"))); 
     1420        navigation(array (array ("title" => "Next", "page" => "version"))); 
    14811421} 
    1482  
    1483  
    14841422?> 
    14851423 
     
    14871425</body> 
    14881426</html> 
     1427