Revision 1686
Added by darkviper over 13 years ago
| save.php | ||
|---|---|---|
| 32 | 32 |
list($usec,$sec) = explode(' ',microtime());
|
| 33 | 33 |
srand((float)$sec+((float)$usec*100000)); |
| 34 | 34 |
$session_rand = rand(1000,9999); |
| 35 |
if(!class_exists('WbAutoloader', false)) {
|
|
| 36 |
include(dirname(dirname(__FILE__)).'/framework/WbAutoloader.php'); |
|
| 37 |
} |
|
| 38 |
WbAutoloader::doRegister(array('admin'=>'a', 'modules'=>'m'));
|
|
| 35 | 39 |
|
| 36 | 40 |
// Function to set error |
| 37 | 41 |
function set_error($message, $field_name = '') {
|
| ... | ... | |
| 322 | 326 |
define('DB_USERNAME', $database_username);
|
| 323 | 327 |
define('DB_PASSWORD', $database_password);
|
| 324 | 328 |
define('TABLE_PREFIX', $table_prefix);
|
| 325 |
define('WB_PATH', str_replace(array('/install','\install'), '',dirname(__FILE__)));
|
|
| 329 |
define('WB_PATH', dirname(dirname(__FILE__)));
|
|
| 326 | 330 |
define('WB_URL', $wb_url);
|
| 327 |
define('ADMIN_PATH', WB_PATH.'/admin');
|
|
| 328 |
define('ADMIN_URL', $wb_url.'/admin');
|
|
| 331 |
define('ADMIN_DIRECTORY', 'admin');
|
|
| 332 |
define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY);
|
|
| 333 |
define('ADMIN_URL', $wb_url.'/'.ADMIN_DIRECTORY);
|
|
| 329 | 334 |
|
| 330 | 335 |
// Check if the user has entered a correct path |
| 331 | 336 |
if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
|
| 332 | 337 |
set_error('It appears the Absolute path that you entered is incorrect');
|
| 333 | 338 |
} |
| 339 |
$sSqlUrl = DB_TYPE.'://'.DB_USERNAME.':'.DB_PASSWORD.'@'.DB_HOST.'/'.DB_NAME; |
|
| 340 |
$database = WbDatabase::getInstance(); |
|
| 341 |
$database->doConnect($sSqlUrl); |
|
| 334 | 342 |
|
| 335 |
// Try connecting to database
|
|
| 336 |
if(!@mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) {
|
|
| 337 |
set_error('Database host name, username and/or password incorrect. MySQL Error:<br />'.mysql_error());
|
|
| 338 |
}
|
|
| 343 |
$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
|
|
| 344 |
$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
|
|
| 345 |
require_once($sSecMod);
|
|
| 346 |
require_once(WB_PATH.'/framework/class.admin.php');
|
|
| 339 | 347 |
|
| 340 |
// Try to create the database |
|
| 341 |
mysql_query('CREATE DATABASE `'.$database_name.'`');
|
|
| 342 |
|
|
| 343 |
// Close the mysql connection |
|
| 344 |
mysql_close(); |
|
| 345 |
|
|
| 346 |
$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
|
|
| 347 |
$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php'; |
|
| 348 |
require_once($sSecMod); |
|
| 349 |
|
|
| 350 |
require_once(WB_PATH.'/framework/class.admin.php'); |
|
| 351 |
|
|
| 352 | 348 |
// Dummy class to allow modules' install scripts to call $admin->print_error |
| 353 |
class admin_dummy extends admin |
|
| 354 |
{
|
|
| 355 |
var $error=''; |
|
| 356 |
function print_error($message, $link = 'index.php', $auto_footer = true) |
|
| 349 |
class admin_dummy extends admin |
|
| 357 | 350 |
{
|
| 358 |
$this->error=$message; |
|
| 351 |
var $error=''; |
|
| 352 |
function print_error($message, $link = 'index.php', $auto_footer = true) |
|
| 353 |
{
|
|
| 354 |
$this->error=$message; |
|
| 355 |
} |
|
| 359 | 356 |
} |
| 360 |
} |
|
| 361 |
|
|
| 362 | 357 |
// Include WB functions file |
| 363 |
require_once(WB_PATH.'/framework/functions.php'); |
|
| 364 |
|
|
| 358 |
require_once(WB_PATH.'/framework/functions.php'); |
|
| 365 | 359 |
// Re-connect to the database, this time using in-build database class |
| 366 |
require_once(WB_PATH.'/framework/class.login.php'); |
|
| 367 |
|
|
| 368 |
$database=new database(); |
|
| 369 |
|
|
| 360 |
require_once(WB_PATH.'/framework/class.login.php'); |
|
| 370 | 361 |
// Check if we should install tables |
| 371 |
if($install_tables == true) {
|
|
| 372 |
if (!defined('WB_INSTALL_PROCESS')) define ('WB_INSTALL_PROCESS', true);
|
|
| 373 |
// Remove tables if they exist |
|
| 374 | 362 |
|
| 375 |
// Pages table |
|
| 376 |
$pages = "DROP TABLE IF EXISTS `".TABLE_PREFIX."pages`"; |
|
| 377 |
$database->query($pages); |
|
| 378 |
// Sections table |
|
| 379 |
$sections = "DROP TABLE IF EXISTS `".TABLE_PREFIX."sections`"; |
|
| 380 |
$database->query($sections); |
|
| 381 |
// Settings table |
|
| 382 |
$settings = "DROP TABLE IF EXISTS `".TABLE_PREFIX."settings`"; |
|
| 383 |
$database->query($settings); |
|
| 384 |
// Users table |
|
| 385 |
$users = "DROP TABLE IF EXISTS `".TABLE_PREFIX."users`"; |
|
| 386 |
$database->query($users); |
|
| 387 |
// Groups table |
|
| 388 |
$groups = "DROP TABLE IF EXISTS `".TABLE_PREFIX."groups`"; |
|
| 389 |
$database->query($groups); |
|
| 390 |
// Search table |
|
| 391 |
$search = "DROP TABLE IF EXISTS `".TABLE_PREFIX."search`"; |
|
| 392 |
$database->query($search); |
|
| 393 |
// Addons table |
|
| 394 |
$addons = "DROP TABLE IF EXISTS `".TABLE_PREFIX."addons`"; |
|
| 395 |
$database->query($addons); |
|
| 396 |
|
|
| 363 |
$sql = 'SHOW TABLES LIKE \''.str_replace('_', '\_', TABLE_PREFIX).'%';
|
|
| 364 |
$aTables = array(); |
|
| 365 |
if(($oTables = $database->query($sql))) {
|
|
| 366 |
while($aTable = $oTables->fetchRow()) {
|
|
| 367 |
$aTables[] = $aTable[0]; |
|
| 368 |
} |
|
| 369 |
} |
|
| 370 |
$sTableList = implode(', ', $aTables);
|
|
| 371 |
if($sTableList != '') {
|
|
| 372 |
$database->query('DROP TABLE '.$sTableList);
|
|
| 373 |
} |
|
| 397 | 374 |
// Try installing tables |
| 398 |
|
|
| 399 | 375 |
// Pages table |
| 400 | 376 |
$pages = 'CREATE TABLE `'.TABLE_PREFIX.'pages` ( `page_id` INT NOT NULL auto_increment,' |
| 401 | 377 |
. ' `parent` INT NOT NULL DEFAULT \'0\',' |
| ... | ... | |
| 662 | 638 |
$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
|
| 663 | 639 |
|
| 664 | 640 |
require_once(WB_PATH.'/framework/initialize.php'); |
| 665 |
|
|
| 666 | 641 |
// Include the PclZip class file (thanks to |
| 667 | 642 |
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php'); |
| 668 |
|
|
| 669 | 643 |
// Install add-ons |
| 670 | 644 |
if(file_exists(WB_PATH.'/install/modules')) {
|
| 671 | 645 |
// Unpack pre-packaged modules |
| 672 |
|
|
| 673 | 646 |
} |
| 674 | 647 |
if(file_exists(WB_PATH.'/install/templates')) {
|
| 675 | 648 |
// Unpack pre-packaged templates |
| 676 |
|
|
| 677 | 649 |
} |
| 678 | 650 |
if(file_exists(WB_PATH.'/install/languages')) {
|
| 679 | 651 |
// Unpack pre-packaged languages |
| 680 |
|
|
| 681 | 652 |
} |
| 682 |
|
|
| 683 | 653 |
$admin=new admin_dummy('Start','',false,false);
|
| 684 |
|
|
| 685 | 654 |
// Load addons into DB |
| 686 | 655 |
$dirs['modules'] = WB_PATH.'/modules/'; |
| 687 | 656 |
$dirs['templates'] = WB_PATH.'/templates/'; |
| 688 | 657 |
$dirs['languages'] = WB_PATH.'/languages/'; |
| 689 | 658 |
|
| 690 | 659 |
foreach($dirs AS $type => $dir) {
|
| 691 |
if($handle = opendir($dir)) {
|
|
| 660 |
if(($handle = opendir($dir))) {
|
|
| 692 | 661 |
while(false !== ($file = readdir($handle))) {
|
| 693 | 662 |
if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
|
| 694 | 663 |
// Get addon type |
| ... | ... | |
| 706 | 675 |
} |
| 707 | 676 |
} |
| 708 | 677 |
} |
| 709 |
closedir($handle); |
|
| 678 |
closedir($handle);
|
|
| 710 | 679 |
} |
| 711 | 680 |
} |
| 712 | 681 |
|
| ... | ... | |
| 716 | 685 |
} |
| 717 | 686 |
|
| 718 | 687 |
// end of if install_tables |
| 719 |
} else {
|
|
| 720 |
/** |
|
| 721 |
* DB - Exists |
|
| 722 |
* Tables also? |
|
| 723 |
* |
|
| 724 |
*/ |
|
| 725 |
$requested_tables = array("pages","sections","settings","users","groups","search","addons");
|
|
| 726 |
for($i=0;$i<count($requested_tables);$i++) $requested_tables[$i] = $table_prefix.$requested_tables[$i]; |
|
| 727 | 688 |
|
| 728 |
$result = mysql_list_tables( DB_NAME ); |
|
| 729 |
$all_tables = array(); |
|
| 730 |
for($i=0; $i < mysql_num_rows($result); $i++) $all_tables[] = mysql_table_name($result, $i); |
|
| 731 |
|
|
| 732 |
$missing_tables = array(); |
|
| 733 |
foreach($requested_tables as $temp_table) {
|
|
| 734 |
if (!in_array($temp_table, $all_tables)) {
|
|
| 735 |
$missing_tables[] = $temp_table; |
|
| 736 |
} |
|
| 737 |
} |
|
| 738 |
|
|
| 739 |
/** |
|
| 740 |
* If one or more needed tables are missing, so |
|
| 741 |
* we can't go on and have to display an error |
|
| 742 |
*/ |
|
| 743 |
if ( count($missing_tables) > 0 ) {
|
|
| 744 |
$error_message = "One or more tables are missing in the selected database <b><font color='#990000'>".DB_NAME."</font></b>.<br />"; |
|
| 745 |
$error_message .= "Please install the missing tables or choose 'install tables' as recommend.<br />"; |
|
| 746 |
$error_message .= "Missing tables are: <b>".implode(", ", $missing_tables)."</b>";
|
|
| 747 |
|
|
| 748 |
set_error( $error_message ); |
|
| 749 |
} |
|
| 750 |
|
|
| 751 |
/** |
|
| 752 |
* Try to get some default settings ... |
|
| 753 |
*/ |
|
| 754 |
$vars = array( |
|
| 755 |
'DEFAULT_THEME' => "wb_theme", |
|
| 756 |
'THEME_URL' => WB_URL."/templates/wb_theme", |
|
| 757 |
'THEME_PATH' => WB_PATH."/templates/wb_theme", |
|
| 758 |
'LANGUAGE' => $_POST['default_language'], |
|
| 759 |
'SERVER_EMAIL' => "admin@yourdomain.com", |
|
| 760 |
'SMART_LOGIN' => false |
|
| 761 |
); |
|
| 762 |
foreach($vars as $k => $v) if (!defined($k)) define($k, $v); |
|
| 763 |
|
|
| 764 |
if (!isset($MESSAGE)) include (WB_PATH."/languages/".LANGUAGE.".php"); |
|
| 765 |
|
|
| 766 |
/** |
|
| 767 |
* The important part ... |
|
| 768 |
* Is there an valid user? |
|
| 769 |
*/ |
|
| 770 |
$result = $database->query("SELECT * from ".$table_prefix."users where username='".$_POST['admin_username']."'");
|
|
| 771 |
if ( $database->is_error() ) {
|
|
| 772 |
set_error ($database->get_error() ); |
|
| 773 |
} |
|
| 774 |
if ($result->numRows() == 0) {
|
|
| 775 |
/** |
|
| 776 |
* No matches found ... user properly unknown |
|
| 777 |
*/ |
|
| 778 |
set_error ("Unkown user. Please use a valid username.");
|
|
| 779 |
} else {
|
|
| 780 |
|
|
| 781 |
$data = $result->fetchRow(); |
|
| 782 |
/** |
|
| 783 |
* Does the password match |
|
| 784 |
*/ |
|
| 785 |
if ( md5($_POST['admin_password']) != $data['password']) {
|
|
| 786 |
set_error ("Password didn't match");
|
|
| 787 |
} |
|
| 788 |
} |
|
| 789 |
} |
|
| 790 |
|
|
| 791 | 689 |
$ThemeUrl = WB_URL.$admin->correct_theme_source('warning.html');
|
| 792 | 690 |
// Setup template object, parse vars to it, then parse it |
| 793 | 691 |
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('login.htt'));
|
Also available in: Unified diff
some modifications concerning the new autoloader
Twig Template engine v.1.7.0
some droplets actualisized
unfinished changes in installer