| 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')); |
| 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' => ' '), |
| 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' => ' '), |
| 238 | | 'XSLT_SUPPORT' => array('title' => 'XSLT Support', |
| 239 | | 'depend' => 'return 1;', |
| 240 | | 'message' => ' '), |
| 241 | | 'GMAPS_HOTSPOTS_MAP_ENABLED' => array('title' => 'Google Maps Support', |
| 242 | | 'depend' => 'return 1;', |
| 243 | | 'message' => ' ') |
| 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' => ' '), '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' => ' '), 'XSLT_SUPPORT' => array ('title' => 'XSLT Support', 'depend' => 'return 1;', 'message' => ' '), 'GMAPS_HOTSPOTS_MAP_ENABLED' => array ('title' => 'Google Maps Support', 'depend' => 'return 1;', 'message' => ' ')); |
| | 176 | |
| | 177 | foreach ($neededExtentions as $key => $value) { # Detect availables extentions |
| | 178 | if (array_key_exists($key, $loadedExtensions)) |
| | 179 | $neededExtentions[$key]['available'] = 1; |
| 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 |
| 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> </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> </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> </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> </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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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] = '-- '; |
| 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 |
| 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 |
| 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 |