Revision 2104
Added by darkviper almost 11 years ago
| save.php | ||
|---|---|---|
| 39 | 39 |
include(dirname(__DIR__).'/framework/globalExceptionHandler.php'); |
| 40 | 40 |
include(dirname(__DIR__).'/framework/WbAutoloader.php'); |
| 41 | 41 |
WbAutoloader::doRegister(array('admin'=>'a', 'modules'=>'m', 'templates'=>'t', 'include'=>'i'));
|
| 42 |
include(__DIR__.'/InstallHelper.php'); |
|
| 42 | 43 |
// register PHPMailer autoloader --- |
| 43 | 44 |
if (!function_exists('PHPMailerAutoload')) {
|
| 44 | 45 |
require(dirname(__DIR__).'/include/phpmailer/PHPMailerAutoload.php'); |
| ... | ... | |
| 261 | 262 |
// End path and timezone details code |
| 262 | 263 |
|
| 263 | 264 |
// Get the default language |
| 264 |
$allowed_languages = array('BG','CA', 'CS', 'DA', 'DE', 'EN', 'ES', 'ET', 'FI', 'FR', 'HR', 'HU', 'IT', 'LV', 'NL', 'NO', 'PL', 'PT', 'RU','SE','SK','TR');
|
|
| 265 |
$sLanguageDirectory = dirname(__DIR__).'languages/'; |
|
| 266 |
$allowed_languages = array_keys(InstallHelper::getAvailableLanguages($sLanguageDirectory)); |
|
| 265 | 267 |
if(!isset($_POST['default_language']) OR !in_array($_POST['default_language'], $allowed_languages)) {
|
| 266 | 268 |
set_error('Please select a valid default backend language','default_language');
|
| 267 | 269 |
} else {
|
| ... | ... | |
| 400 | 402 |
."pass = \"".$database_password."\"\n" |
| 401 | 403 |
."host = \"".$database_host."\"\n" |
| 402 | 404 |
."port = \"3306\"\n" |
| 405 |
."socket = \"\"\n" |
|
| 403 | 406 |
."name = \"".$database_name."\"\n" |
| 404 | 407 |
."charset = \"utf8\"\n" |
| 405 | 408 |
."table_prefix = \"".$table_prefix."\"\n" |
| ... | ... | |
| 463 | 466 |
$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
|
| 464 | 467 |
$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php'; |
| 465 | 468 |
require_once($sSecMod); |
| 469 |
require(ADMIN_PATH.'/interface/version.php'); |
|
| 470 |
|
|
| 471 |
/***************************** |
|
| 472 |
Begin Create Database Tables |
|
| 473 |
*****************************/ |
|
| 474 |
if (is_readable(__DIR__.'/sql/install-struct.sql')) {
|
|
| 475 |
if (! $database->SqlImport(__DIR__.'/sql/install-struct.sql', TABLE_PREFIX, false)) {
|
|
| 476 |
set_error('unable to import install-struct.sql');
|
|
| 477 |
} |
|
| 478 |
} |
|
| 479 |
if (is_readable(__DIR__.'/sql/install-data.sql')) {
|
|
| 480 |
if (! $database->SqlImport(__DIR__.'/sql/install-data.sql', TABLE_PREFIX)) {
|
|
| 481 |
set_error('unable to import install-data.sql');
|
|
| 482 |
} |
|
| 483 |
} |
|
| 484 |
$sql = // additional settings from install input |
|
| 485 |
'REPLACE INTO `'.TABLE_PREFIX.'settings` (`name`, `value`) VALUES ' |
|
| 486 |
. '(\'wb_version\', \''.VERSION.'\'), ' |
|
| 487 |
. '(\'website_title\', \''.$website_title.'\'), ' |
|
| 488 |
. '(\'default_language\', \''.$default_language.'\'), ' |
|
| 489 |
. '(\'app_name\', \'wb_'.$session_rand.'\'), ' |
|
| 490 |
. '(\'default_timezone\', \''.$default_timezone.'\'), ' |
|
| 491 |
. '(\'operating_system\', \''.$operating_system.'\'), ' |
|
| 492 |
. '(\'string_file_mode\', \''.$file_mode.'\'), ' |
|
| 493 |
. '(\'string_dir_mode\', \''.$dir_mode.'\'), ' |
|
| 494 |
. '(\'server_email\', \''.$admin_email.'\'), ' |
|
| 495 |
. '(\'wb_revision\', \''.REVISION.'\'), ' |
|
| 496 |
. '(\'wb_sp\', \''.SP.'\'), ' |
|
| 497 |
. '(\'groups_updated\', \''.time().'\')'; |
|
| 498 |
if (! ($database->query($sql))) {
|
|
| 499 |
set_error('unable to write \'install presets\' into table \'settings\'');
|
|
| 500 |
} |
|
| 501 |
$sql = // add the Admin user |
|
| 502 |
'INSERT INTO `'.TABLE_PREFIX.'users` ' |
|
| 503 |
.'SET `user_id`=1, ' |
|
| 504 |
. '`group_id`=1, ' |
|
| 505 |
. '`groups_id`=\'1\', ' |
|
| 506 |
. '`active`=\'1\', ' |
|
| 507 |
. '`username`=\''.$admin_username.'\', ' |
|
| 508 |
. '`password`=\''.md5($admin_password).'\', ' |
|
| 509 |
. '`email`=\''.$admin_email.'\', ' |
|
| 510 |
. '`timezone`=\''.$default_timezone.'\', ' |
|
| 511 |
. '`language`=\''.$default_language.'\', ' |
|
| 512 |
. '`display_name`=\'Administrator\''; |
|
| 513 |
if (! ($database->query($sql))) {
|
|
| 514 |
set_error('unable to write Administrator account into table \'users\'');
|
|
| 515 |
} |
|
| 516 |
/********************** |
|
| 517 |
END OF TABLES IMPORT |
|
| 518 |
**********************/ |
|
| 519 |
// initialize the system |
|
| 520 |
require_once(WB_PATH.'/framework/initialize.php'); |
|
| 466 | 521 |
require_once(WB_PATH.'/framework/class.admin.php'); |
| 467 |
|
|
| 522 |
/*********************** |
|
| 468 | 523 |
// Dummy class to allow modules' install scripts to call $admin->print_error |
| 469 |
class admin_dummy extends admin |
|
| 470 |
{
|
|
| 471 |
var $error=''; |
|
| 472 |
function print_error($message, $link = 'index.php', $auto_footer = true) |
|
| 473 |
{
|
|
| 474 |
$this->error=$message; |
|
| 475 |
} |
|
| 476 |
} |
|
| 477 |
|
|
| 478 |
// core tables only structure |
|
| 479 |
$sSqlFileName = dirname(__FILE__).'/sql/websitebaker.sql'; |
|
| 480 |
if(!$database->SqlImport($sSqlFileName,TABLE_PREFIX, false)) { set_error($database->get_error()); }
|
|
| 481 |
|
|
| 482 |
require(ADMIN_PATH.'/interface/version.php'); |
|
| 483 |
|
|
| 484 |
$sql = 'INSERT INTO `'.TABLE_PREFIX.'settings` (`name`, `value`) VALUES ' |
|
| 485 |
. '(\'wb_version\', \''.VERSION.'\'), ' |
|
| 486 |
. '(\'website_title\', \''.$website_title.'\'), ' |
|
| 487 |
. '(\'website_description\', \'\'), ' |
|
| 488 |
. '(\'website_keywords\', \'\'), ' |
|
| 489 |
. '(\'website_header\', \'\'), ' |
|
| 490 |
. '(\'website_footer\', \'\'), ' |
|
| 491 |
. '(\'wysiwyg_style\', \'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;\'), ' |
|
| 492 |
. '(\'er_level\', \'0\'), ' |
|
| 493 |
. '(\'default_language\', \''.$default_language.'\'), ' |
|
| 494 |
. '(\'app_name\', \'wb_'.$session_rand.'\'), ' |
|
| 495 |
. '(\'sec_anchor\', \'Sec\'), ' |
|
| 496 |
. '(\'server_timezone\', \'UTC\'), ' |
|
| 497 |
. '(\'default_timezone\', \''.$default_timezone.'\'), ' |
|
| 498 |
. '(\'default_date_format\', \'Y-m-d\'), ' |
|
| 499 |
. '(\'default_time_format\', \'h:i A\'), ' |
|
| 500 |
. '(\'redirect_timer\', \'1500\'), ' |
|
| 501 |
. '(\'home_folders\', \'false\'), ' |
|
| 502 |
. '(\'warn_page_leave\', \'1\'), ' |
|
| 503 |
. '(\'default_template\', \'round\'), ' |
|
| 504 |
. '(\'default_theme\', \'WbTheme\'), ' |
|
| 505 |
. '(\'default_charset\', \'utf-8\'), ' |
|
| 506 |
. '(\'multiple_menus\', \'true\'), ' |
|
| 507 |
. '(\'page_level_limit\', \'6\'), ' |
|
| 508 |
. '(\'intro_page\', \'false\'), ' |
|
| 509 |
. '(\'page_trash\', \'inline\'), ' |
|
| 510 |
. '(\'homepage_redirection\', \'false\'), ' |
|
| 511 |
. '(\'page_languages\', \'false\'), ' |
|
| 512 |
. '(\'wysiwyg_editor\', \'fckeditor\'), ' |
|
| 513 |
. '(\'manage_sections\', \'true\'), ' |
|
| 514 |
. '(\'section_blocks\', \'false\'), ' |
|
| 515 |
. '(\'smart_login\', \'false\'), ' |
|
| 516 |
. '(\'frontend_login\', \'false\'), ' |
|
| 517 |
. '(\'frontend_signup\', \'false\'), ' |
|
| 518 |
. '(\'search\', \'public\'), ' |
|
| 519 |
. '(\'page_extension\', \'.php\'), ' |
|
| 520 |
. '(\'page_spacer\', \'-\'), ' |
|
| 521 |
. '(\'pages_directory\', \'/pages\'), ' |
|
| 522 |
. '(\'rename_files_on_upload\', \'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js,txt\'), ' |
|
| 523 |
. '(\'media_directory\', \'/media\'), ' |
|
| 524 |
. '(\'operating_system\', \''.$operating_system.'\'), ' |
|
| 525 |
. '(\'string_file_mode\', \''.$file_mode.'\'), ' |
|
| 526 |
. '(\'string_dir_mode\', \''.$dir_mode.'\'), ' |
|
| 527 |
. '(\'wbmailer_routine\', \'phpmail\'), ' |
|
| 528 |
. '(\'server_email\', \''.$admin_email.'\'), ' |
|
| 529 |
. '(\'wbmailer_default_sendername\', \'WebsiteBaker Mailer\'), ' |
|
| 530 |
. '(\'wbmailer_smtp_host\', \'\'), ' |
|
| 531 |
. '(\'wbmailer_smtp_auth\', \'\'), ' |
|
| 532 |
. '(\'wbmailer_smtp_username\', \'\'), ' |
|
| 533 |
. '(\'wbmailer_smtp_password\', \'\'), ' |
|
| 534 |
. '(\'fingerprint_with_ip_octets\', \'2\'), ' |
|
| 535 |
. '(\'secure_form_module\', \'\'), ' |
|
| 536 |
. '(\'mediasettings\', \'\'), ' |
|
| 537 |
. '(\'wb_revision\', \''.REVISION.'\'), ' |
|
| 538 |
. '(\'wb_sp\', \''.SP.'\'), ' |
|
| 539 |
. '(\'page_icon_dir\', \'/templates/*/title_images\'), ' |
|
| 540 |
. '(\'dev_infos\', \'false\'), ' |
|
| 541 |
. '(\'groups_updated\', \''.time().'\'), ' |
|
| 542 |
. '(\'wbmail_signature\', \'\'), ' |
|
| 543 |
. '(\'confirmed_registration\', \'1\'), ' |
|
| 544 |
. '(\'page_extendet\', \'true\'), ' |
|
| 545 |
. '(\'system_locked\', \'0\'), ' |
|
| 546 |
. '(\'password_crypt_loops\', \'12\'), ' |
|
| 547 |
. '(\'password_hash_type\', \'false\'), ' |
|
| 548 |
. '(\'password_length\', \'10\'), ' |
|
| 549 |
. '(\'password_use_types\', \''.(int)0xFFFF.'\') ' |
|
| 550 |
. ''; |
|
| 551 |
if(!$database->query($sql)) { set_error($database->get_error()); }
|
|
| 552 |
|
|
| 553 |
// Admin group |
|
| 554 |
$full_system_permissions = 'access,addons,admintools,admintools_view,groups,groups_add,groups_delete,' |
|
| 555 |
. 'groups_modify,groups_view,languages,languages_install,languages_uninstall,' |
|
| 556 |
. 'languages_view,media,media_create,media_delete,media_rename,media_upload,' |
|
| 557 |
. 'media_view,modules,modules_advanced,modules_install,modules_uninstall,' |
|
| 558 |
. 'modules_view,pages,pages_add,pages_add_l0,pages_delete,pages_intro,' |
|
| 559 |
. 'pages_modify,pages_settings,pages_view,preferences,preferences_view,' |
|
| 560 |
. 'settings,settings_advanced,settings_basic,settings_view,templates,' |
|
| 561 |
. 'templates_install,templates_uninstall,templates_view,users,users_add,' |
|
| 562 |
. 'users_delete,users_modify,users_view'; |
|
| 563 |
$sql = 'INSERT INTO `'.TABLE_PREFIX.'groups` ' |
|
| 564 |
. 'SET `group_id` =1,' |
|
| 565 |
. '`name`=\'Administrators\',' |
|
| 566 |
. '`system_permissions`=\''.$full_system_permissions.'\',' |
|
| 567 |
. '`module_permissions`=\'\',' |
|
| 568 |
. '`template_permissions`=\'\''; |
|
| 569 |
if(!$database->query($sql)) { set_error($database->get_error()); }
|
|
| 570 |
|
|
| 571 |
// Admin user |
|
| 572 |
$insert_admin_user = "INSERT INTO `".TABLE_PREFIX."users` VALUES (1, 1, '1', 1, '$admin_username', '".md5($admin_password)."', '', 0, '', 0, 'Administrator', '$admin_email', $default_timezone, '', '', '$default_language', '', 0, '');"; |
|
| 573 |
if(!$database->query($insert_admin_user)) { set_error($database->get_error()); }
|
|
| 574 |
|
|
| 575 |
// Search layout default data |
|
| 576 |
$sSqlFileName = dirname(__FILE__).'/sql/wb_search_data.sql'; |
|
| 577 |
if(!$database->SqlImport($sSqlFileName,TABLE_PREFIX, false)) { set_error($database->get_error()); }
|
|
| 578 |
|
|
| 579 |
require_once(WB_PATH.'/framework/initialize.php'); |
|
| 580 |
// |
|
| 524 |
***********************/ |
|
| 525 |
class admin_dummy extends admin |
|
| 526 |
{
|
|
| 527 |
public $error=''; |
|
| 528 |
public function print_error($message, $link = 'index.php', $auto_footer = true) |
|
| 529 |
{
|
|
| 530 |
$this->error=$message; |
|
| 531 |
} |
|
| 532 |
} |
|
| 581 | 533 |
// Include WB functions file |
| 582 | 534 |
require_once(WB_PATH.'/framework/functions.php'); |
| 583 | 535 |
// Re-connect to the database, this time using in-build database class |
| ... | ... | |
| 585 | 537 |
// Include the PclZip class file (thanks to |
| 586 | 538 |
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php'); |
| 587 | 539 |
// Install add-ons |
| 588 |
if(file_exists(WB_PATH.'/install/modules')) {
|
|
| 589 |
// Unpack pre-packaged modules |
|
| 590 |
} |
|
| 591 |
if(file_exists(WB_PATH.'/install/templates')) {
|
|
| 592 |
// Unpack pre-packaged templates |
|
| 593 |
} |
|
| 594 |
if(file_exists(WB_PATH.'/install/languages')) {
|
|
| 595 |
// Unpack pre-packaged languages |
|
| 596 |
} |
|
| 597 |
|
|
| 598 | 540 |
$admin=new admin_dummy('Start','',false,false);
|
| 599 |
// Load addons into DB |
|
| 600 |
$dirs['modules'] = WB_PATH.'/modules/'; |
|
| 601 |
$dirs['templates'] = WB_PATH.'/templates/'; |
|
| 602 |
$dirs['languages'] = WB_PATH.'/languages/'; |
|
| 541 |
// Load addons and templates into DB |
|
| 542 |
$aScanDirs = array( |
|
| 543 |
'module' => dirname(__DIR__).'/modules/', |
|
| 544 |
'template' => dirname(__DIR__).'/templates/', |
|
| 545 |
'language' => dirname(__DIR__).'/languages/' |
|
| 546 |
); |
|
| 547 |
foreach ($aScanDirs as $sType => $sPath) {
|
|
| 548 |
$sCommand = 'load_'.$sType; |
|
| 549 |
if ($sType != 'language') {
|
|
| 550 |
foreach (glob($sPath, GLOB_ONLYDIR) as $sMatchingPath) {
|
|
| 551 |
if ($sType == 'module') {
|
|
| 552 |
$sCommand($sMatchingPath, true); |
|
| 553 |
if ($admin->error) { set_error($admin->error); }
|
|
| 554 |
} elseif ($sType == 'template') {
|
|
| 555 |
$sCommand($sMatchingPath); |
|
| 556 |
} |
|
| 557 |
} |
|
| 558 |
} else {
|
|
| 559 |
foreach (glob(dirname(__DIR__).'/languages/??.php') as $sMatchingPath) {
|
|
| 560 |
if (preg_match('/\/[A-Z]{2}\.php$/sU', $sMatchingPath)) {
|
|
| 561 |
$sCommand($sMatchingPath); |
|
| 562 |
} |
|
| 563 |
} |
|
| 564 |
} |
|
| 565 |
} |
|
| 603 | 566 |
|
| 604 |
foreach($dirs AS $type => $dir) {
|
|
| 605 |
if(($handle = opendir($dir))) {
|
|
| 606 |
while(false !== ($file = readdir($handle))) {
|
|
| 607 |
if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
|
|
| 608 |
// Get addon type |
|
| 609 |
if($type == 'modules') {
|
|
| 610 |
load_module($dir.'/'.$file, true); |
|
| 611 |
// Pretty ugly hack to let modules run $admin->set_error |
|
| 612 |
// See dummy class definition admin_dummy above |
|
| 613 |
if ($admin->error!='') {
|
|
| 614 |
set_error($admin->error); |
|
| 615 |
} |
|
| 616 |
} elseif($type == 'templates') {
|
|
| 617 |
load_template($dir.'/'.$file); |
|
| 618 |
} elseif($type == 'languages') {
|
|
| 619 |
load_language($dir.'/'.$file); |
|
| 620 |
} |
|
| 621 |
} |
|
| 622 |
} |
|
| 623 |
closedir($handle); |
|
| 624 |
} |
|
| 625 |
} |
|
| 626 |
|
|
| 627 | 567 |
// Check if there was a database error |
| 628 | 568 |
if($database->is_error()) {
|
| 629 | 569 |
set_error($database->get_error()); |
Also available in: Unified diff
! complete rebuild of wb/install/ - changed to use import-struct.sql
! change class WbDatabase from mysql to msqli
! rework of WbDatabase::importSql()
! function db_update_key_value() optimized for speed
! field `settings_id`removed from table `settings` and new primary key set to `name`
! update-script extended to modify table `settings`