| 299 | | ################################### |
| 300 | | # |
| 301 | | /*function debugButton() { |
| 302 | | print <<<EndHTML |
| 303 | | <p><INPUT TYPE="button" VALUE="Debug" ONCLICK="javascript: window.location.reload(true);"></p> |
| 304 | | EndHTML; |
| 305 | | } */ |
| 306 | | |
| 307 | | ################################### |
| 308 | | # In development |
| 309 | | /*function installPackage($pkg_name, $full_url, $copy) { |
| 310 | | print "<h1>$pkg_name installation</h1>\n"; |
| 311 | | chdir(WIFIDOG_ABS_FILE_PATH."tmp"); |
| 312 | | list($url, $filename) = split ("=", $full_url); |
| 313 | | |
| 314 | | print "Download source code ($filename) : "; |
| 315 | | if (!file_exists($filename)) |
| 316 | | Dependency::execVerbose("wget \"$url\"", $output, $return); |
| 317 | | if (!file_exists($filename)) // wget success if file exists |
| 318 | | Dependency::execVerbose("wget \"$full_url\" 2>&1", $output_array, $return); |
| 319 | | if (!file_exists($filename)) { |
| 320 | | print "<B STYLE=\"color:red\">Error</b><p>Current working directory : <em>$basepath/tmp/smarty</em>"; |
| 321 | | $output = implode("\n", $output_array); |
| 322 | | print "<pre><em>wget \"$full_url\"</em>\n$output</pre>"; |
| 323 | | exit(); |
| 324 | | } else { |
| 325 | | print "OK<BR>"; |
| | 299 | ################################### |
| | 300 | # |
| | 301 | /*function debugButton() { |
| | 302 | print <<<EndHTML |
| | 303 | <p><INPUT TYPE="button" VALUE="Debug" ONCLICK="javascript: window.location.reload(true);"></p> |
| | 304 | EndHTML; |
| | 305 | } */ |
| | 306 | |
| | 307 | ################################### |
| | 308 | # In development |
| | 309 | /*function installPackage($pkg_name, $full_url, $copy) { |
| | 310 | print "<h1>$pkg_name installation</h1>\n"; |
| | 311 | chdir(WIFIDOG_ABS_FILE_PATH."tmp"); |
| | 312 | list($url, $filename) = split ("=", $full_url); |
| | 313 | |
| | 314 | print "Download source code ($filename) : "; |
| | 315 | if (!file_exists($filename)) |
| | 316 | Dependency::execVerbose("wget \"$url\"", $output, $return); |
| | 317 | if (!file_exists($filename)) // wget success if file exists |
| | 318 | Dependency::execVerbose("wget \"$full_url\" 2>&1", $output_array, $return); |
| | 319 | if (!file_exists($filename)) { |
| | 320 | print "<B STYLE=\"color:red\">Error</b><p>Current working directory : <em>$basepath/tmp/smarty</em>"; |
| | 321 | $output = implode("\n", $output_array); |
| | 322 | print "<pre><em>wget \"$full_url\"</em>\n$output</pre>"; |
| | 323 | exit(); |
| | 324 | } else { |
| | 325 | print "OK<BR>"; |
| | 326 | } |
| | 327 | |
| | 328 | print "Uncompressing : "; |
| | 329 | $dirname = array_shift(split(".tar.gz", $filename)); |
| | 330 | |
| | 331 | if (!file_exists($dirname)) |
| | 332 | Dependency::execVerbose("tar -xzf $dirname.tar.gz", $output, $return); |
| | 333 | print "OK<BR>"; |
| | 334 | print "Copying : "; |
| | 335 | if (!file_exists('../../lib/smarty/Smarty.class.php')); |
| | 336 | Dependency::execVerbose("cp -r $dirname/libs/* ../../lib/smarty", $output, $return); |
| | 337 | Dependency::execVerbose("cp -r $dirname/libs/* ../../lib/smarty", $output, $return); |
| | 338 | $copy |
| | 339 | print "OK<BR>"; |
| | 340 | }*/ |
| | 341 | |
| | 342 | ################################### |
| | 343 | # |
| | 344 | function saveConfig($data) { |
| | 345 | print "<!-- saveConfig DATA=($data) -->\n"; # DEBUG |
| | 346 | |
| | 347 | global $CONFIG_FILE; |
| | 348 | |
| | 349 | $contentArray = file(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE"); |
| | 350 | $fd = fopen(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE", 'w'); |
| | 351 | |
| | 352 | $defineArrayToken = array (); |
| | 353 | $defineArrayToken = explode('|', $data); |
| | 354 | |
| | 355 | foreach ($defineArrayToken as $nameValue) { |
| | 356 | list ($name, $value) = explode('=', $nameValue); |
| | 357 | $defineArray[$name] = $value; # New define value ($name and value) |
| | 358 | #print "K=$name V=$value<BR>"; # DEBUG |
| 328 | | print "Uncompressing : "; |
| 329 | | $dirname = array_shift(split(".tar.gz", $filename)); |
| 330 | | |
| 331 | | if (!file_exists($dirname)) |
| 332 | | Dependency::execVerbose("tar -xzf $dirname.tar.gz", $output, $return); |
| 333 | | print "OK<BR>"; |
| 334 | | print "Copying : "; |
| 335 | | if (!file_exists('../../lib/smarty/Smarty.class.php')); |
| 336 | | Dependency::execVerbose("cp -r $dirname/libs/* ../../lib/smarty", $output, $return); |
| 337 | | Dependency::execVerbose("cp -r $dirname/libs/* ../../lib/smarty", $output, $return); |
| 338 | | $copy |
| 339 | | print "OK<BR>"; |
| 340 | | }*/ |
| 341 | | |
| 342 | | ################################### |
| 343 | | # |
| 344 | | function saveConfig($data) { |
| 345 | | print "<!-- saveConfig DATA=($data) -->\n"; # DEBUG |
| 346 | | |
| 347 | | global $CONFIG_FILE; |
| 348 | | |
| 349 | | $contentArray = file(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE"); |
| 350 | | $fd = fopen(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE", 'w'); |
| 351 | | |
| 352 | | $defineArrayToken = array (); |
| 353 | | $defineArrayToken = explode('|', $data); |
| 354 | | |
| 355 | | foreach ($defineArrayToken as $nameValue) { |
| 356 | | list ($name, $value) = explode('=', $nameValue); |
| 357 | | $defineArray[$name] = $value; # New define value ($name and value) |
| 358 | | #print "K=$name V=$value<BR>"; # DEBUG |
| 359 | | } |
| 360 | | |
| 361 | | foreach ($contentArray as $line) { |
| 362 | | #print "L=$line<BR>\n"; |
| 363 | | if (preg_match("/^define\((.+)\);/", $line, $matchesArray)) { |
| 364 | | list ($key, $value) = explode(',', $matchesArray[1]); |
| 365 | | $pattern = array ( |
| | 361 | foreach ($contentArray as $line) { |
| | 362 | #print "L=$line<BR>\n"; |
| | 363 | if (preg_match("/^define\((.+)\);/", $line, $matchesArray)) { |
| | 364 | list ($key, $value) = explode(',', $matchesArray[1]); |
| | 365 | $pattern = array ( |
| 400 | | |
| 401 | | ################################### |
| 402 | | # MAIN |
| 403 | | switch ($page) { |
| 404 | | case 'permission' : |
| 405 | | print "<h1>Permissions</h1>"; |
| 406 | | |
| 407 | | $process_info_user_id = posix_getpwuid(posix_getuid()); |
| 408 | | |
| 409 | | if($process_info_user_id){ |
| 410 | | $process_username = $process_info_user_id['name']; |
| | 399 | } |
| | 400 | |
| | 401 | ################################### |
| | 402 | # MAIN |
| | 403 | switch ($page) { |
| | 404 | case 'permission' : |
| | 405 | print "<h1>Permissions</h1>"; |
| | 406 | |
| | 407 | $process_info_user_id = posix_getpwuid(posix_getuid()); |
| | 408 | |
| | 409 | if($process_info_user_id){ |
| | 410 | $process_username = $process_info_user_id['name']; |
| | 411 | } |
| | 412 | else { |
| | 413 | //Posix functions aren't available on windows |
| | 414 | $process_username = 'unknown_user'; |
| | 415 | } |
| | 416 | $process_info_group_id = posix_getgrgid(posix_getegid()); |
| | 417 | if($process_info_group_id){ |
| | 418 | $process_group = $process_info_group_id['name']; |
| | 419 | } |
| | 420 | else { |
| | 421 | //Posix functions aren't available on windows |
| | 422 | $process_group = 'unknown_group'; |
| | 423 | } |
| | 424 | $cmd_mkdir = ''; |
| | 425 | $cmd_chown = ''; |
| | 426 | $error = 0; |
| | 427 | |
| | 428 | print "<p><em>HTTP daemon UNIX username/group</em>: $process_username/$process_group</p>"; |
| | 429 | # print "<p><em>HTTPD group</em>: $process_group<BR</p>"; |
| | 430 | print "<p><table BORDER=\"1\"><tr><td><em>Directory</em></td></td><td><em>Owner</em></td><td><em>Writable</em></td></tr>\n"; |
| | 431 | |
| | 432 | foreach ($dir_array as $dir) { |
| | 433 | print "<tr><td>$dir</td>"; |
| | 434 | if (!file_exists(WIFIDOG_ABS_FILE_PATH . "$dir")) { |
| | 435 | print "<TD COLSPAN=\"2\" STYLE=\"text-align:center;\">Missing</td></tr>\n"; |
| | 436 | $cmd_mkdir .= WIFIDOG_ABS_FILE_PATH . "$dir "; |
| | 437 | $cmd_chown .= WIFIDOG_ABS_FILE_PATH . "$dir "; |
| | 438 | $error = 1; |
| | 439 | continue; |
| | 440 | } |
| | 441 | |
| | 442 | $dir_info = posix_getpwuid(fileowner(WIFIDOG_ABS_FILE_PATH . "$dir")); |
| | 443 | if($dir_info) { |
| | 444 | $dir_owner_username = $dir_info['name']; |
| 638 | | } |
| 639 | | elseif ($action == 'install') { |
| 640 | | chdir(WIFIDOG_ABS_FILE_PATH . "tmp"); |
| 641 | | $filename = array_pop(preg_split("/\//", $jpgraph_full_url)); |
| 642 | | |
| 643 | | print "Download source code ($filename) : "; |
| 644 | | if (!file_exists($filename)) |
| 645 | | Dependency::execVerbose("wget \"$jpgraph_full_url\" 2>&1", $output, $return); |
| 646 | | if (!file_exists($filename)) { # Error occured, print output of wget |
| 647 | | print "<B STYLE=\"color:red\">Error</b><p>Current working directory : <em>$basepath/tmp</em>"; |
| 648 | | $output = implode("\n", $output); |
| 649 | | print "<pre><em>wget \"$jpgraph_full_url\"</em>\n$output</pre>"; |
| 650 | | exit (); |
| 651 | | } |
| 652 | | else { |
| 653 | | print "OK<BR>"; |
| 654 | | } |
| 655 | | |
| 656 | | print "Uncompressing : "; |
| 657 | | $dirname = array_shift(split(".tar.gz", $filename)); |
| 658 | | if (!file_exists($dirname)) |
| 659 | | Dependency::execVerbose("tar -xzf $dirname.tar.gz", $output, $return); |
| | 638 | } |
| | 639 | elseif ($action == 'install') { |
| | 640 | chdir(WIFIDOG_ABS_FILE_PATH . "tmp"); |
| | 641 | $filename = array_pop(preg_split("/\//", $jpgraph_full_url)); |
| | 642 | |
| | 643 | print "Download source code ($filename) : "; |
| | 644 | if (!file_exists($filename)) |
| | 645 | Dependency::execVerbose("wget \"$jpgraph_full_url\" 2>&1", $output, $return); |
| | 646 | if (!file_exists($filename)) { # Error occured, print output of wget |
| | 647 | print "<B STYLE=\"color:red\">Error</b><p>Current working directory : <em>$basepath/tmp</em>"; |
| | 648 | $output = implode("\n", $output); |
| | 649 | print "<pre><em>wget \"$jpgraph_full_url\"</em>\n$output</pre>"; |
| | 650 | exit (); |
| | 651 | } |
| | 652 | else { |
| 744 | | case 'testdatabase' : |
| 745 | | print "<h1>Database connection</h1>"; |
| 746 | | /* TODO : Tester la version minimale requise de Postgresql */ |
| 747 | | |
| 748 | | print "<UL><LI>Postgresql database connection : "; |
| 749 | | |
| 750 | | $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; |
| 751 | | $ptr_connexion = pg_connect($conn_string); |
| 752 | | |
| 753 | | if ($ptr_connexion == TRUE) { |
| 754 | | print "Success<BR>"; |
| 755 | | } |
| 756 | | else { |
| 757 | | print "Unable to connect to database on $CONF_DATABASE_HOST<BR>The database must be online to continue.<BR>Please go back and retry with correct values"; |
| 758 | | refreshButton(); |
| 759 | | navigation(array(array("title" => "Back", "page" => "database"))); |
| 760 | | die(); |
| 761 | | } |
| 762 | | |
| 763 | | $postgresql_info = pg_version(); |
| 764 | | # $postgresql_info['server']; |
| 765 | | # if ($postgresql_info['server'] > $requiredPostgeSQLVersion) { Todo : Do something } |
| 766 | | |
| 767 | | print "</UL>"; |
| | 744 | case 'testdatabase' : |
| | 745 | print "<h1>Database connection</h1>"; |
| | 746 | /* TODO : Tester la version minimale requise de Postgresql */ |
| | 747 | |
| | 748 | print "<UL><LI>Trying to open a Postgresql database connection : "; |
| | 749 | |
| | 750 | $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; |
| | 751 | $ptr_connexion = pg_connect($conn_string); |
| | 752 | |
| | 753 | if ($ptr_connexion == TRUE) { |
| | 754 | print "Success!<BR>"; |
| | 755 | } |
| | 756 | else { |
| | 757 | printf ("<p>Unable to connect! The server has to be online, the database \"%s\" must exist, and the postgresql.conf and pg_hba.conf must allow the user \"%s\" to open a connection to it on host \"%s\" to continue. See the error above for hints on what the problem may be.", $CONF_DATABASE_NAME, $CONF_DATABASE_USER, $CONF_DATABASE_HOST); |
| | 758 | print "<p>Please go back and retry with correct values, or fix your server configuration.</p>"; |
| 781 | | case 'dbinit' : |
| 782 | | print "<h1>Database initialisation</h1>"; |
| 783 | | # SQL are executed with PHP, some lignes need to be commented. |
| 784 | | $file_db_version = 'UNKNOW'; |
| 785 | | $patterns[0] = '/CREATE DATABASE wifidog/'; |
| 786 | | $patterns[1] = '/\\\connect/'; |
| 787 | | //The following is strictly for compatibility with postgresql 7.4 |
| 788 | | $patterns[2] = '/COMMENT/'; |
| 789 | | $patterns[3] = '/^SET /m'; |
| 790 | | $patterns[4] = '/CREATE PROCEDURAL LANGUAGE/'; |
| 791 | | $patterns[5] = '/ALTER SEQUENCE/'; |
| 792 | | $patterns[6] = '/::regclass/';//To fix incompatibility of postgres < 8.1 with later nextval() calling convention |
| 793 | | $replacements[0] = '-- '; |
| 794 | | $replacements[1] = '-- '; |
| 795 | | $replacements[2] = '-- '; |
| 796 | | $replacements[3] = '-- '; |
| 797 | | $replacements[4] = '-- '; |
| 798 | | $replacements[5] = '-- '; |
| 799 | | $replacements[6] = '::text'; |
| 800 | | |
| 801 | | $content_schema_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-schema.sql") or die("<em>Error</em>: Can not open $basepath/../sql/wifidog-postgres-schema.sql"); # Read SQL schema file |
| 802 | | $content_schema = implode("", $content_schema_array); |
| 803 | | $content_data_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-initial-data.sql"); # Read SQL initial data file |
| 804 | | $content_data = implode("", $content_data_array); |
| 805 | | |
| 806 | | $db_schema_version = ''; # Schema version query from database |
| 807 | | $file_schema_version = ''; # Schema version from define(REQUIRED_SCHEMA_VERSION) in schema_validate.php |
| 808 | | |
| 809 | | $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; |
| 810 | | $connection = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==<BR>"); |
| 811 | | |
| 812 | | if (preg_match("/\('schema_version', '(\d+)'\);/", $content_data, $matchesArray)) # Get schema_version from initial data file |
| 813 | | $file_db_version = $matchesArray[1]; |
| 814 | | |
| 815 | | $contentArray = file(WIFIDOG_ABS_FILE_PATH . "include/schema_validate.php"); |
| 816 | | foreach ($contentArray as $line) { |
| 817 | | #print "$line<BR>"; # Debug |
| 818 | | if (preg_match("/^define\('REQUIRED_SCHEMA_VERSION', (\d+)\);/", $line, $matchesArray)) { |
| 819 | | #print "REQUIRED_SCHEMA_VERSION = " . $matchesArray[1] . "<BR>"; |
| 820 | | $file_schema_version = $matchesArray[1]; |
| 821 | | } |
| 822 | | } |
| 823 | | |
| 824 | | # Get current database schema version (if defined) |
| 825 | | $sql = "SELECT * FROM schema_info WHERE tag='schema_version'"; |
| 826 | | if ($result = @ pg_query($connection, $sql)) { # The @ remove warning display |
| 827 | | $result_array = pg_fetch_all($result); |
| 828 | | $db_shema_version = $result_array[0]['value']; |
| 829 | | |
| 830 | | print "<p>On <em>$CONF_DATABASE_HOST</em>, Database <em>$CONF_DATABASE_NAME</em> exists and is "; |
| 831 | | if ($db_shema_version == $file_schema_version) { |
| 832 | | print "up to date (shema version <em>$db_shema_version</em>)."; |
| 833 | | navigation(array ( |
| 834 | | array ( |
| 835 | | "title" => "Back", |
| 836 | | "page" => "database" |
| 837 | | ), |
| 838 | | array ( |
| 839 | | "title" => "Next", |
| 840 | | "page" => "options" |
| 841 | | ) |
| 842 | | )); |
| 843 | | } |
| 844 | | elseif ($db_shema_version < $file_schema_version) { |
| 845 | | print "at schema version <em>$db_shema_version</em>. The required schema version is <em>$file_schema_version</em><p>Please upgrade the database"; |
| 846 | | navigation(array ( |
| 847 | | array ( |
| 848 | | "title" => "Back", |
| 849 | | "page" => "database" |
| 850 | | ), |
| 851 | | array ( |
| 852 | | "title" => "Upgrade", |
| 853 | | "page" => "schema_validate" |
| 854 | | ), |
| 855 | | array ( |
| 856 | | "title" => "Next", |
| 857 | | "page" => "options" |
| 858 | | ) |
| 859 | | )); |
| 860 | | } |
| 861 | | else { |
| 862 | | print "Error : Unexpected result"; |
| 863 | | } |
| 864 | | exit (); |
| 865 | | } |
| 866 | | |
| 867 | | print "<UL><LI>Creating wifidog database schema : "; |
| | 785 | case 'dbinit' : |
| | 786 | print "<h1>Database initialisation</h1>"; |
| | 787 | # SQL are executed with PHP, some lines need to be commented out. |
| | 788 | $file_db_version = 'UNKNOW'; |
| | 789 | $patterns[0] = '/CREATE DATABASE wifidog/'; |
| | 790 | $patterns[1] = '/\\\connect/'; |
| | 791 | //The following is strictly for compatibility with postgresql 7.4 |
| | 792 | $patterns[2] = '/COMMENT/'; |
| | 793 | $patterns[3] = '/^SET /m'; |
| | 794 | $patterns[4] = '/CREATE PROCEDURAL LANGUAGE/'; |
| | 795 | $patterns[5] = '/ALTER SEQUENCE/'; |
| | 796 | $patterns[6] = '/::regclass/';//To fix incompatibility of postgres < 8.1 with later nextval() calling convention |
| | 797 | $replacements[0] = '-- '; |
| | 798 | $replacements[1] = '-- '; |
| | 799 | $replacements[2] = '-- '; |
| | 800 | $replacements[3] = '-- '; |
| | 801 | $replacements[4] = '-- '; |
| | 802 | $replacements[5] = '-- '; |
| | 803 | $replacements[6] = '::text'; |
| | 804 | |
| | 805 | $content_schema_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-schema.sql") or die("<em>Error</em>: Can not open $basepath/../sql/wifidog-postgres-schema.sql"); # Read SQL schema file |
| | 806 | $content_schema = implode("", $content_schema_array); |
| | 807 | $content_data_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-initial-data.sql"); # Read SQL initial data file |
| | 808 | $content_data = implode("", $content_data_array); |
| | 809 | |
| | 810 | $db_schema_version = ''; # Schema version query from database |
| | 811 | $file_schema_version = ''; # Schema version from define(REQUIRED_SCHEMA_VERSION) in schema_validate.php |
| | 812 | |
| | 813 | $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; |
| | 814 | $connection = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==<BR>"); |
| | 815 | |
| | 816 | if (preg_match("/\('schema_version', '(\d+)'\);/", $content_data, $matchesArray)) # Get schema_version from initial data file |
| | 817 | $file_db_version = $matchesArray[1]; |
| | 818 | |
| | 819 | $contentArray = file(WIFIDOG_ABS_FILE_PATH . "include/schema_validate.php"); |
| | 820 | foreach ($contentArray as $line) { |
| | 821 | #print "$line<BR>"; # Debug |
| | 822 | if (preg_match("/^define\('REQUIRED_SCHEMA_VERSION', (\d+)\);/", $line, $matchesArray)) { |
| | 823 | #print "REQUIRED_SCHEMA_VERSION = " . $matchesArray[1] . "<BR>"; |
| | 824 | $file_schema_version = $matchesArray[1]; |
| | 825 | } |
| | 826 | } |
| | 827 | |
| | 828 | # Get current database schema version (if defined) |
| | 829 | $schemaVersionSql = "SELECT * FROM schema_info WHERE tag='schema_version'"; |
| | 830 | |
| | 831 | if (!@ pg_query($connection, $schemaVersionSql)) { # The @ remove warning display |
| | 832 | |
| | 833 | print "<UL><LI>Database did not exist, creating wifidog database schema : "; |
| 927 | | //echo '<pre>';print_r($optionsInfo);echo '</pre>'; |
| 928 | | foreach ($optionsInfo as $name => $foo) { # Foreach generate all <table> fields |
| 929 | | $value = $configArray[$name]; # Value of option in config.php |
| 930 | | $title = $optionsInfo[$name]['title']; # Field Title |
| 931 | | $message = $optionsInfo[$name]['message']; # Message why option is disable |
| 932 | | if(empty($value)) |
| 933 | | $message .= ", ERROR: unable to find the '$name' directive in the config file"; |
| 934 | | $depend = @ eval ($optionsInfo[$name]['depend']); # Evaluate the dependencie |
| 935 | | $selectedTrue = ''; |
| 936 | | $selectedFalse = ''; # Initialize value |
| 937 | | $value == 'true' ? $selectedTrue = 'SELECTED' : $selectedFalse = 'SELECTED'; # Use to select the previous saved option |
| 938 | | $depend == 1 ? $disabled = '' : $disabled = 'DISABLED'; # Disable <SELECT> if dependencie is not satisfied |
| 939 | | $jscript = "<script type=\"text/javascript\"> newConfig(\"$name=false\"); </script>\n"; # Use to save a failed dependencie (option=false) |
| 940 | | if ($disabled == '') # Dependencie ok, erase $jscript value |
| 941 | | $jscript = ''; |
| 942 | | |
| 943 | | print<<< EndHTML |
| | 896 | //echo '<pre>';print_r($optionsInfo);echo '</pre>'; |
| | 897 | foreach ($optionsInfo as $name => $foo) { # Foreach generate all <table> fields |
| | 898 | $value = $configArray[$name]; # Value of option in config.php |
| | 899 | $title = $optionsInfo[$name]['title']; # Field Title |
| | 900 | $message = $optionsInfo[$name]['message']; # Message why option is disable |
| | 901 | if(empty($value)) |
| | 902 | $message .= ", ERROR: unable to find the '$name' directive in the config file"; |
| | 903 | $depend = @ eval ($optionsInfo[$name]['depend']); # Evaluate the dependencie |
| | 904 | $selectedTrue = ''; |
| | 905 | $selectedFalse = ''; # Initialize value |
| | 906 | $value == 'true' ? $selectedTrue = 'SELECTED' : $selectedFalse = 'SELECTED'; # Use to select the previous saved option |
| | 907 | $depend == 1 ? $disabled = '' : $disabled = 'DISABLED'; # Disable <SELECT> if dependencie is not satisfied |
| | 908 | $jscript = "<script type=\"text/javascript\"> newConfig(\"$name=false\"); </script>\n"; # Use to save a failed dependencie (option=false) |
| | 909 | if ($disabled == '') # Dependencie ok, erase $jscript value |
| | 910 | $jscript = ''; |
| | 911 | |
| | 912 | print<<< EndHTML |
| 1032 | | case 'admin' : |
| 1033 | | print "<h1>Administration account</h1>"; |
| 1034 | | # TODO : Allow to create more than one admin account and list the current admin users |
| 1035 | | # Allow admin to choose to show or not is username |
| 1036 | | empty ($_REQUEST['username']) ? $username = 'admin' : $username = $_REQUEST['username']; |
| 1037 | | empty ($_REQUEST['password']) ? $password = '' : $password = $_REQUEST['password']; |
| 1038 | | empty ($_REQUEST['password2']) ? $password2 = '' : $password2 = $_REQUEST['password2']; |
| 1039 | | empty ($_REQUEST['email']) ? $email = $_SERVER['SERVER_ADMIN'] : $email = $_REQUEST['email']; |
| 1040 | | |
| 1041 | | $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; |
| 1042 | | $connection = pg_connect($conn_string) or die(); |
| 1043 | | |
| 1044 | | if ($action == 'create') { |
| 1045 | | // require_once(dirname(__FILE__) . '/config.php'); |
| 1046 | | require_once (dirname(__FILE__) . '/include/common.php'); |
| 1047 | | require_once (dirname(__FILE__) . '/classes/User.php'); |
| 1048 | | |
| 1049 | | $created_user = User :: createUser(get_guid(), $username, Network :: getDefaultNetwork(), $email, $password); |
| 1050 | | $user_id = $created_user->getId(); |
| 1051 | | |
| 1052 | | # Add user to admin table, hide his username and set his account status to 1 (allowed) |
| 1053 | | $sql = "INSERT INTO server_stakeholders (user_id, role_id, object_id) VALUES ('$user_id', 'SERVER_SYSADMIN', 'SERVER_ID');\n"; |
| 1054 | | $sql .= "INSERT INTO network_stakeholders (user_id, role_id, object_id) VALUES ('$user_id', 'NETWORK_SYSADMIN', 'default-network');\n"; |
| 1055 | | $sql .= "UPDATE users SET account_status='1' WHERE user_id='$user_id'"; |
| 1056 | | $result = pg_query($connection, $sql); |
| 1057 | | } |
| 1058 | | |
| 1059 | | $sql = "SELECT * FROM users NATURAL JOIN server_stakeholders WHERE account_origin = 'default-network'"; |
| | 983 | case 'admin' : |
| | 984 | print "<h1>Administration account</h1>"; |
| | 985 | # TODO : Allow to create more than one admin account and list the current admin users |
| | 986 | # Allow admin to choose to show or not is username |
| | 987 | empty ($_REQUEST['username']) ? $username = 'admin' : $username = $_REQUEST['username']; |
| | 988 | empty ($_REQUEST['password']) ? $password = '' : $password = $_REQUEST['password']; |
| | 989 | empty ($_REQUEST['password2']) ? $password2 = '' : $password2 = $_REQUEST['password2']; |
| | 990 | empty ($_REQUEST['email']) ? $email = $_SERVER['SERVER_ADMIN'] : $email = $_REQUEST['email']; |
| | 991 | |
| | 992 | $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; |
| | 993 | $connection = pg_connect($conn_string) or die(); |
| | 994 | |
| | 995 | if ($action == 'create') { |
| | 996 | // require_once(dirname(__FILE__) . '/config.php'); |
| | 997 | require_once (dirname(__FILE__) . '/include/common.php'); |
| | 998 | require_once (dirname(__FILE__) . '/classes/User.php'); |
| | 999 | |
| | 1000 | $created_user = User :: createUser(get_guid(), $username, Network :: getDefaultNetwork(), $email, $password); |
| | 1001 | $user_id = $created_user->getId(); |
| | 1002 | |
| | 1003 | # Add user to admin table, hide his username and set his account status to 1 (allowed) |
| | 1004 | $sql = "INSERT INTO server_stakeholders (user_id, role_id, object_id) VALUES ('$user_id', 'SERVER_SYSADMIN', 'SERVER_ID');\n"; |
| | 1005 | $sql .= "INSERT INTO network_stakeholders (user_id, role_id, object_id) VALUES ('$user_id', 'NETWORK_SYSADMIN', 'default-network');\n"; |
| | 1006 | $sql .= "UPDATE users SET account_status='1' WHERE user_id='$user_id'"; |
| 1123 | | } |
| 1124 | | break; |
| 1125 | | |
| 1126 | | ################################### |
| 1127 | | case 'network' : |
| 1128 | | print "<h1>Network</h1>"; |
| 1129 | | |
| 1130 | | //$HOTSPOT_NETWORK_NAME = $configArray['HOTSPOT_NETWORK_NAME']; |
| 1131 | | //$HOTSPOT_NETWORK_URL = $configArray['HOTSPOT_NETWORK_URL']; |
| 1132 | | //$TECH_SUPPORT_EMAIL = $configArray['TECH_SUPPORT_EMAIL']; |
| 1133 | | //$VALIDATION_GRACE_TIME = $configArray['VALIDATION_GRACE_TIME']; |
| 1134 | | //$VALIDATION_EMAIL_FROM_ADDRESS = $configArray['VALIDATION_EMAIL_FROM_ADDRESS']; |
| 1135 | | |
| 1136 | | /** |
| 1137 | | * @deprecated 2005-12-26 Needs to use network abstraction |
| 1138 | | * |
| 1139 | | * |
| 1140 | | * <p> |
| 1141 | | <table border="1"> |
| 1142 | | <tr> |
| 1143 | | <td>Network Name</td><td><INPUT type="text" name="HOTSPOT_NETWORK_NAME" value="" size="30"></td> |
| 1144 | | </tr> |
| 1145 | | <tr> |
| 1146 | | <td>Network URL</td><td><INPUT type="text" name="HOTSPOT_NETWORK_URL" value="" size="30"></td> |
| 1147 | | </tr> |
| 1148 | | <tr> |
| 1149 | | <td>Tech Support Email</td><td><INPUT type="text" name="TECH_SUPPORT_EMAIL" value="" size="30"></td> |
| 1150 | | </tr> |
| 1151 | | <tr> |
| 1152 | | <td>Validation Grace Time (min)</td><td><INPUT type="text" name="VALIDATION_GRACE_TIME" value="" size="30"></td> |
| 1153 | | </tr> |
| 1154 | | <tr> |
| 1155 | | <td>Validation Email (send from)</td><td><INPUT type="text" name="VALIDATION_EMAIL_FROM_ADDRESS" value="" size="30"></td> |
| 1156 | | </tr> |
| 1157 | | </table> |
| 1158 | | */ |
| 1159 | | print "Need to reimplement this... Until then connect to the administration pages and modify it by yourself."; |
| 1160 | | |
| 1161 | | print<<< EndHTML |
| 1162 | | |
| 1163 | | |
| 1164 | | <script type="text/javascript"> |
| 1165 | | function submitOptionsValue() { |
| 1166 | | //newConfig("HOTSPOT_NETWORK_NAME='" + document.myform.HOTSPOT_NETWORK_NAME.value + "'"); |
| 1167 | | //newConfig("HOTSPOT_NETWORK_URL='" + document.myform.HOTSPOT_NETWORK_URL.value + "'"); |
| 1168 | | //newConfig("TECH_SUPPORT_EMAIL='" + document.myform.TECH_SUPPORT_EMAIL.value + "'"); |
| 1169 | | //newConfig("VALIDATION_GRACE_TIME=" + document.myform.VALIDATION_GRACE_TIME.value); |
| 1170 | | //newConfig("VALIDATION_EMAIL_FROM_ADDRESS='" + document.myform.VALIDATION_EMAIL_FROM_ADDRESS.value + "'"); |
| 1171 | | } |
| 1172 | | </script> |
| 1173 | | |
| 1174 | | EndHTML; |
| 1175 | | |
| 1176 | | navigation(array ( |
| 1177 | | array ( |
| 1178 | | "title" => "Back", |
| 1179 | | "page" => "admin" |
| 1180 | | ) |
| 1181 | | )); |
| 1182 | | |
| 1183 | | print<<< EndHTML |
| 1184 | | <p><A HREF="#" ONCLICK="javascript: document.myform.page.value='hotspot'; submitOptionsValue(); document.myform.submit();" CLASS="button">Next</A></p> |
| 1185 | | EndHTML; |
| 1186 | | #navigation(array(array("title" => "Back", "page" => "admin"), array("title" => "Next", "page" => "hotspot"))); |
| 1187 | | break; |
| 1188 | | |
| 1189 | | ################################### |
| 1190 | | case 'hotspot' : |
| 1191 | | print "<h1>Hotspot</h1>"; |
| 1192 | | print "<p>A default hotspot has already been created<p>Use administration interface to add more hotspots."; |
| 1193 | | navigation(array ( |
| 1194 | | array ( |
| 1195 | | "title" => "Back", |
| 1196 | | "page" => "network" |
| 1197 | | ), |
| 1198 | | array ( |
| 1199 | | "title" => "Next", |
| 1200 | | "page" => "end" |
| 1201 | | ) |
| 1202 | | )); |
| 1203 | | break; |
| 1204 | | |
| 1205 | | ################################### |
| 1206 | | case 'delete' : |
| 1207 | | print<<<EndHTML |
| 1208 | | <h1>Delete temporary files</h1> |
| 1209 | | ... |
| 1210 | | EndHTML; |
| 1211 | | #navigation(array(array("title" => "Back", "page" => "hotspot"))); |
| 1212 | | break; |
| 1213 | | |
| 1214 | | ################################### |
| 1215 | | case 'end' : |
| 1216 | | $url = 'http://' . $_SERVER['HTTP_HOST'] . SYSTEM_PATH; |
| 1217 | | print<<<EndHTML |
| | 1074 | } |
| | 1075 | break; |
| | 1076 | ################################### |
| | 1077 | case 'end' : |
| | 1078 | $url = 'http://' . $_SERVER['HTTP_HOST'] . SYSTEM_PATH; |
| | 1079 | print<<<EndHTML |
| 1241 | | #navigation(array(array("title" => "Back", "page" => "hotspot"))); |
| 1242 | | break; |
| 1243 | | |
| 1244 | | ################################### |
| 1245 | | case 'toc' : |
| 1246 | | print "<h1>Table of content</h1>"; |
| 1247 | | $contentArray = file(__file__); # Read myself |
| 1248 | | print "<UL>\n"; |
| 1249 | | foreach ($contentArray as $line) { |
| 1250 | | if (preg_match("/^ case '(\w+)':/", $line, $matchesArray)) { # Parse for "case" regex |
| 1251 | | if ($matchesArray[1] == 'toc') |
| 1252 | | continue; |
| 1253 | | print "<LI><A HREF=\"" . $_SERVER['SCRIPT_NAME'] . "?page=" . $matchesArray[1] . "\">" . $matchesArray[1] . "</A>\n"; # Display a Table of Content |
| 1254 | | } |
| 1255 | | } |
| 1256 | | print "</UL>\n"; |
| 1257 | | break; |
| 1258 | | ################################### |
| 1259 | | case 'notes' : |
| 1260 | | print<<<EndHTML |
| | 1103 | #navigation(array(array("title" => "Back", "page" => "hotspot"))); |
| | 1104 | break; |
| | 1105 | |
| | 1106 | ################################### |
| | 1107 | case 'toc' : |
| | 1108 | print "<h1>Table of content</h1>"; |
| | 1109 | $contentArray = file(__file__); # Read myself |
| | 1110 | print "<UL>\n"; |
| | 1111 | foreach ($contentArray as $line) { |
| | 1112 | if (preg_match("/^ case '(\w+)':/", $line, $matchesArray)) { # Parse for "case" regex |
| | 1113 | if ($matchesArray[1] == 'toc') |
| | 1114 | continue; |
| | 1115 | print "<LI><A HREF=\"" . $_SERVER['SCRIPT_NAME'] . "?page=" . $matchesArray[1] . "\">" . $matchesArray[1] . "</A>\n"; # Display a Table of Content |
| | 1116 | } |
| | 1117 | } |
| | 1118 | print "</UL>\n"; |
| | 1119 | break; |
| | 1120 | ################################### |
| | 1121 | case 'notes' : |
| | 1122 | print<<<EndHTML |