| 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 : "; |
|---|