Index: wifidog/install.php =================================================================== --- wifidog/install.php (revision 1323) +++ wifidog/install.php (working copy) @@ -51,7 +51,30 @@ empty ($_REQUEST['action']) ? $action = '' : $action = $_REQUEST['action']; # The action to be done (in page) empty ($_REQUEST['debug']) ? $debug = 0 : $debug = $_REQUEST['debug']; # Use for MySQL debugging empty ($_REQUEST['config']) ? $config = '' : $config = $_REQUEST['config']; # Store data to be saved in config.php +//The path to the inital sql data directory +$dirpath = WIFIDOG_ABS_FILE_PATH . "../sql/initaldata/"; + + +# SQL are executed with PHP, some lines need to be commented out. + $file_db_version = 'UNKNOW'; + $patterns[0] = '/CREATE DATABASE wifidog/'; + $patterns[1] = '/\\\connect/'; + //The following is strictly for compatibility with postgresql 7.4 + $patterns[2] = '/COMMENT/'; + $patterns[3] = '/^SET /m'; + $patterns[4] = '/CREATE PROCEDURAL LANGUAGE/'; + $patterns[5] = '/ALTER SEQUENCE/'; + $patterns[6] = '/::regclass/';//To fix incompatibility of postgres < 8.1 with later nextval() calling convention + $replacements[0] = '-- '; + $replacements[1] = '-- '; + $replacements[2] = '-- '; + $replacements[3] = '-- '; + $replacements[4] = '-- '; + $replacements[5] = '-- '; + $replacements[6] = '::text'; + + # 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. # Random password generator @@ -61,7 +84,7 @@ srand(date("s")); $possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $password = ""; - while (strlen($random_password) < 8) { + while (strlen($random_password) < 16) { $random_password .= substr($possible_charactors, rand() % (strlen($possible_charactors)), 1); } $fd = fopen($password_file, 'w'); @@ -155,8 +178,8 @@ $pageindex = array("Welcome"=>"Welcome", "Prerequisites"=>"Prerequisites", "Permissions"=>"Permissions", - "Dependencies"=> "Dependencies", - "Database Access"=> "Database", + "Dependencies"=> "Dependencies", + "Database Access"=> "Database", "Database Connection"=>"testdatabase", "Database Initialisation"=>"dbinit", "Global Options"=>"options", @@ -175,7 +198,7 @@ print<<
-

Change Log
+

Change Log
Known issues

@@ -265,14 +288,13 @@ $configArray[$key] = $value; } } -//echo '
';print_r($configArray);echo '
'; + # Database connections variables $CONF_DATABASE_HOST = $configArray['CONF_DATABASE_HOST']; $CONF_DATABASE_NAME = $configArray['CONF_DATABASE_NAME']; $CONF_DATABASE_USER = $configArray['CONF_DATABASE_USER']; $CONF_DATABASE_PASSWORD = $configArray['CONF_DATABASE_PASSWORD']; -//foreach($configArray as $key => $value) { print "K=$key V=$value
"; } exit(); # DEBUG ################################### # array (array1(name1, page1), array2(name2, page2), ..., arrayN(nameN, pageN)); @@ -306,16 +328,8 @@ ################################### # -/*function debugButton() { - print <<

- EndHTML; - } */ - -################################### -# function saveConfig($data) { - print "\n"; # DEBUG + print "\n"; global $CONFIG_FILE; @@ -328,11 +342,9 @@ foreach ($defineArrayToken as $nameValue) { list ($name, $value) = explode('=', $nameValue); $defineArray[$name] = $value; # New define value ($name and value) - #print "K=$name V=$value
"; # DEBUG } foreach ($contentArray as $line) { - #print "L=$line
\n"; if (preg_match("/^define\((.+)\);/", $line, $matchesArray)) { list ($key, $value) = explode(',', $matchesArray[1]); $pattern = array ( @@ -344,11 +356,8 @@ '' ); $key = preg_replace($pattern, $replacement, trim($key)); - //$value = preg_replace($pattern, $replacement, trim($value)); if (array_key_exists($key, $defineArray)) { // A new value is defined - #print "$key EXISTS
"; - #print "define => (" . $defineArray[$key] . ")
"; $pattern = array ( "/^\\\'/", "/\\\'$/" @@ -358,7 +367,6 @@ "'" ); $value = preg_replace($pattern, $replacement, trim($defineArray[$key])); - #print "(define('$key', $value);)
"; fwrite($fd, "define('$key', $value);\n"); # Write the new define($name, $value) } else { // The key does not exist (no new value to be saved) @@ -380,8 +388,8 @@ *********************************************************************************/ switch ($page) { case 'Permissions' : - print "

Permissions

"; - + print "

Folder Permissions

"; + $process_info_user_id = posix_getpwuid(posix_getuid()); if($process_info_user_id){ @@ -410,7 +418,7 @@ foreach ($dir_array as $dir) { print "$dir"; if (!file_exists(WIFIDOG_ABS_FILE_PATH . "$dir")) { - print "Missing\n"; + print "Missing\n"; $cmd_mkdir .= WIFIDOG_ABS_FILE_PATH . "$dir "; $cmd_chown .= WIFIDOG_ABS_FILE_PATH . "$dir "; $error = 1; @@ -428,10 +436,10 @@ print "$dir_owner_username"; if (is_writable(WIFIDOG_ABS_FILE_PATH . "$dir")) { - print "YES"; + print "YES"; } else { - print "NO"; + print "NO"; $cmd_chown .= WIFIDOG_ABS_FILE_PATH . "$dir "; $error = 1; } @@ -494,9 +502,8 @@ ########################################### case 'Database' : - ### TODO : Valider en javascript que les champs soumit ne sont pas vide - # Pouvoir choisir le port de la DB ??? - print<<< EndHTML + ### TODO : allow choosing the port of the database +print<<< EndHTML

Database Access Configuration


@@ -524,7 +531,7 @@ "title" => "Back", "page" => "Dependencies" ), - )); #, array("title" => "Next", "page" => "testdatabase"))); + )); print<<< EndHTML Next @@ -534,8 +541,6 @@ ########################################### case 'testdatabase' : print "

Database connection

"; - /* TODO : Tester la version minimale requise de Postgresql */ - print ""; @@ -576,27 +580,12 @@ ########################################### case 'dbinit' : print "

Database Initialisation

"; - # SQL are executed with PHP, some lines need to be commented out. - $file_db_version = 'UNKNOW'; - $patterns[0] = '/CREATE DATABASE wifidog/'; - $patterns[1] = '/\\\connect/'; - //The following is strictly for compatibility with postgresql 7.4 - $patterns[2] = '/COMMENT/'; - $patterns[3] = '/^SET /m'; - $patterns[4] = '/CREATE PROCEDURAL LANGUAGE/'; - $patterns[5] = '/ALTER SEQUENCE/'; - $patterns[6] = '/::regclass/';//To fix incompatibility of postgres < 8.1 with later nextval() calling convention - $replacements[0] = '-- '; - $replacements[1] = '-- '; - $replacements[2] = '-- '; - $replacements[3] = '-- '; - $replacements[4] = '-- '; - $replacements[5] = '-- '; - $replacements[6] = '::text'; - + $content_schema_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-schema.sql") or die("Error: Can not open $basepath/../sql/wifidog-postgres-schema.sql"); # Read SQL schema file $content_schema = implode("", $content_schema_array); - $content_data_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-initial-data.sql"); # Read SQL initial data file + + $content_data_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/initaldata/wifidog-postgres-initial-data.sql"); # Read SQL initial data file + $content_data = implode("", $content_data_array); $db_schema_version = ''; # Schema version query from database @@ -619,25 +608,7 @@ # Get current database schema version (if defined) $schemaVersionSql = "SELECT * FROM schema_info WHERE tag='schema_version'"; - - if (!@ pg_query($connection, $schemaVersionSql)) { # The @ remove warning display - - print ""; - - } - - if ($result = @ pg_query($connection, $schemaVersionSql)) { # The @ remove warning display + if ($result = @ pg_query($connection, $schemaVersionSql)) { # The @ remove warning display $result_array = pg_fetch_all($result); $db_shema_version = $result_array[0]['value']; @@ -663,7 +634,58 @@ } - navigation(array ( + if (!@ pg_query($connection, $schemaVersionSql)) { # The @ remove warning display + + print "

Please select the inital data to populate the database with:


"; + + + //Looks into the directory and returns the files, no subdirectories + print "

"; + +//OK button to continue installing + +print<<ok

+
If you would like to backup your wifidog database run the following terminal command: /usr/bin/pg_dump -h $CONF_DATABASE_HOST -p 5432 -U $CONF_DATABASE_USER -F p -O -d -f "/save_dir/filename.sql" $CONF_DATABASE_NAME. When you reinstall WiFiDog add the file to the following directory: $dirpath
+ +EndHTML; + } +else { +navigation(array ( array ( "title" => "Back", "page" => "testdatabase" @@ -673,7 +695,46 @@ "page" => "options" ) )); - break; + + } + + + +break; + case 'dbinitdata' : +print "
  • Adding wifidog initial data to database... "; + $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; + $connection = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==
    "); + $content_data_array = file("$dirpath$action"); # Read SQL data file + + $content_data = implode("", $content_data_array); + + if (preg_match("/\('schema_version', '(\d+)'\);/", $content_data, $matchesArray)) # Get schema_version from the data file + $file_db_version = $matchesArray[1]; + + $contentArray = file(WIFIDOG_ABS_FILE_PATH . "include/schema_validate.php"); + foreach ($contentArray as $line) { + if (preg_match("/^define\('REQUIRED_SCHEMA_VERSION', (\d+)\);/", $line, $matchesArray)) { + $file_schema_version = $matchesArray[1]; + } + } + + $content_data = preg_replace($patterns, $replacements, $content_data); # Comment bad SQL lines + + $result = pg_query($connection, $content_data) or die("" . pg_last_error() . " <=
    "); + print "OK
  • "; + print "
"; + + + navigation(array ( + array ( + "title" => "Next", + "page" => "dbinit" + ) + )); + +break; + ########################################### case 'options' : # TODO : Tester que la connection SSL est fonctionnelle @@ -812,8 +873,7 @@ ########################################### case 'admin' : print "

Administration accounts

"; - # TODO : Allow to create more than one admin account and list the current admin users - # Allow admin to choose to show or not is username + empty ($_REQUEST['username']) ? $username = 'admin' : $username = $_REQUEST['username']; empty ($_REQUEST['password']) ? $password = '' : $password = $_REQUEST['password']; empty ($_REQUEST['password2']) ? $password2 = '' : $password2 = $_REQUEST['password2']; @@ -875,7 +935,7 @@
-