Revision 224
Added by stefan almost 20 years ago
| save.php | ||
|---|---|---|
| 633 | 633 | 
    'GROUPS_TABLE' => TABLE_PREFIX."groups",  | 
| 634 | 634 | 
    )  | 
| 635 | 635 | 
    );  | 
| 636 | 
     | 
|
| 637 | 
    ?>=======  | 
|
| 638 | 
    <?php  | 
|
| 639 | 
     | 
|
| 640 | 
    // $Id$  | 
|
| 641 | 
     | 
|
| 642 | 
    /*  | 
|
| 643 | 
     | 
|
| 644 | 
    Website Baker Project <http://www.websitebaker.org/>  | 
|
| 645 | 
    Copyright (C) 2004-2005, Ryan Djurovich  | 
|
| 646 | 
     | 
|
| 647 | 
    Website Baker is free software; you can redistribute it and/or modify  | 
|
| 648 | 
    it under the terms of the GNU General Public License as published by  | 
|
| 649 | 
    the Free Software Foundation; either version 2 of the License, or  | 
|
| 650 | 
    (at your option) any later version.  | 
|
| 651 | 
     | 
|
| 652 | 
    Website Baker is distributed in the hope that it will be useful,  | 
|
| 653 | 
    but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
|
| 654 | 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  | 
|
| 655 | 
    GNU General Public License for more details.  | 
|
| 656 | 
     | 
|
| 657 | 
    You should have received a copy of the GNU General Public License  | 
|
| 658 | 
    along with Website Baker; if not, write to the Free Software  | 
|
| 659 | 
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  | 
|
| 660 | 
     | 
|
| 661 | 
    */  | 
|
| 662 | 
     | 
|
| 663 | 
    // Start a session  | 
|
| 664 | 
    if(!defined('SESSION_STARTED')) {
   | 
|
| 665 | 
    	session_name('wb_session_id');
   | 
|
| 666 | 
    session_start();  | 
|
| 667 | 
    	define('SESSION_STARTED', true);
   | 
|
| 668 | 
    }  | 
|
| 669 | 
     | 
|
| 670 | 
    // Function to set error  | 
|
| 671 | 
    function set_error($message) {
   | 
|
| 672 | 
    global $_POST;  | 
|
| 673 | 
    	if(isset($message) AND $message != '') {
   | 
|
| 674 | 
    // Copy values entered into session so user doesn't have to re-enter everything  | 
|
| 675 | 
    		if(isset($_POST['website_title'])) {
   | 
|
| 676 | 
    $_SESSION['wb_url'] = $_POST['wb_url'];  | 
|
| 677 | 
    $_SESSION['wb_path'] = $_POST['wb_path'];  | 
|
| 678 | 
    $_SESSION['default_timezone'] = $_POST['default_timezone'];  | 
|
| 679 | 
    			if(!isset($_POST['operating_system'])) {
   | 
|
| 680 | 
    $_SESSION['operating_system'] = 'linux';  | 
|
| 681 | 
    			} else {
   | 
|
| 682 | 
    $_SESSION['operating_system'] = $_POST['operating_system'];  | 
|
| 683 | 
    }  | 
|
| 684 | 
    			if(!isset($_POST['world_writeable'])) {
   | 
|
| 685 | 
    $_SESSION['world_writeable'] = false;  | 
|
| 686 | 
    			} else {
   | 
|
| 687 | 
    $_SESSION['world_writeable'] = true;  | 
|
| 688 | 
    }  | 
|
| 689 | 
    $_SESSION['database_host'] = $_POST['database_host'];  | 
|
| 690 | 
    $_SESSION['database_username'] = $_POST['database_username'];  | 
|
| 691 | 
    $_SESSION['database_password'] = $_POST['database_password'];  | 
|
| 692 | 
    $_SESSION['database_name'] = $_POST['database_name'];  | 
|
| 693 | 
    $_SESSION['table_prefix'] = $_POST['table_prefix'];  | 
|
| 694 | 
    			if(!isset($_POST['install_tables'])) {
   | 
|
| 695 | 
    $_SESSION['install_tables'] = false;  | 
|
| 696 | 
    			} else {
   | 
|
| 697 | 
    $_SESSION['install_tables'] = true;  | 
|
| 698 | 
    }  | 
|
| 699 | 
    $_SESSION['website_title'] = $_POST['website_title'];  | 
|
| 700 | 
    $_SESSION['admin_username'] = $_POST['admin_username'];  | 
|
| 701 | 
    $_SESSION['admin_email'] = $_POST['admin_email'];  | 
|
| 702 | 
    $_SESSION['admin_password'] = $_POST['admin_password'];  | 
|
| 703 | 
    }  | 
|
| 704 | 
    // Set the message  | 
|
| 705 | 
    $_SESSION['message'] = $message;  | 
|
| 706 | 
    // Specify that session support is enabled  | 
|
| 707 | 
    $_SESSION['session_support'] = '<font class="good">Enabled</font>';  | 
|
| 708 | 
    // Redirect to first page again and exit  | 
|
| 709 | 
    		header('Location: index.php?sessions_checked=true');
   | 
|
| 710 | 
    exit();  | 
|
| 711 | 
    }  | 
|
| 712 | 
    }  | 
|
| 713 | 
     | 
|
| 714 | 
    // Function to workout what the default permissions are for files created by the webserver  | 
|
| 715 | 
    function default_file_mode($temp_dir) {
   | 
|
| 716 | 
    	$v = explode(".",PHP_VERSION);
   | 
|
| 717 | 
    $v = $v[0].$v[1];  | 
|
| 718 | 
    	if($v > 41 AND is_writable($temp_dir)) {
   | 
|
| 719 | 
    $filename = $temp_dir.'/test_permissions.txt';  | 
|
| 720 | 
    $handle = fopen($filename, 'w');  | 
|
| 721 | 
    fwrite($handle, 'This file is to get the default file permissions');  | 
|
| 722 | 
    fclose($handle);  | 
|
| 723 | 
    		$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
   | 
|
| 724 | 
    unlink($filename);  | 
|
| 725 | 
    	} else {
   | 
|
| 726 | 
    $default_file_mode = '0777';  | 
|
| 727 | 
    }  | 
|
| 728 | 
    return $default_file_mode;  | 
|
| 729 | 
    }  | 
|
| 730 | 
     | 
|
| 731 | 
    // Function to workout what the default permissions are for directories created by the webserver  | 
|
| 732 | 
    function default_dir_mode($temp_dir) {
   | 
|
| 733 | 
    	$v = explode(".",PHP_VERSION);
   | 
|
| 734 | 
    $v = $v[0].$v[1];  | 
|
| 735 | 
    	if($v > 41 AND is_writable($temp_dir)) {
   | 
|
| 736 | 
    $dirname = $temp_dir.'/test_permissions/';  | 
|
| 737 | 
    mkdir($dirname);  | 
|
| 738 | 
    		$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
   | 
|
| 739 | 
    rmdir($dirname);  | 
|
| 740 | 
    	} else {
   | 
|
| 741 | 
    $default_dir_mode = '0777';  | 
|
| 742 | 
    }  | 
|
| 743 | 
    return $default_dir_mode;  | 
|
| 744 | 
    }  | 
|
| 745 | 
     | 
|
| 746 | 
    function add_slashes($input) {
   | 
|
| 747 | 
    		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
   | 
|
| 748 | 
    return $input;  | 
|
| 749 | 
    }  | 
|
| 750 | 
    $output = addslashes($input);  | 
|
| 751 | 
    return $output;  | 
|
| 752 | 
    }  | 
|
| 753 | 
     | 
|
| 754 | 
    // Begin check to see if form was even submitted  | 
|
| 755 | 
    // Set error if no post vars found  | 
|
| 756 | 
    if(!isset($_POST['website_title'])) {
   | 
|
| 757 | 
    	set_error('Please fill-in the form below');
   | 
|
| 758 | 
    }  | 
|
| 759 | 
    // End check to see if form was even submitted  | 
|
| 760 | 
     | 
|
| 761 | 
    // Begin path and timezone details code  | 
|
| 762 | 
     | 
|
| 763 | 
    // Check if user has entered the installation url  | 
|
| 764 | 
    if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
   | 
|
| 765 | 
    	set_error('Please enter an absolute URL');
   | 
|
| 766 | 
    } else {
   | 
|
| 767 | 
    $wb_url = $_POST['wb_url'];  | 
|
| 768 | 
    }  | 
|
| 769 | 
    // Remove any slashes at the end of the URL  | 
|
| 770 | 
    if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
   | 
|
| 771 | 
    $wb_url = substr($wb_url, 0, strlen($wb_url)-1);  | 
|
| 772 | 
    }  | 
|
| 773 | 
    if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
   | 
|
| 774 | 
    $wb_url = substr($wb_url, 0, strlen($wb_url)-1);  | 
|
| 775 | 
    }  | 
|
| 776 | 
    if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
   | 
|
| 777 | 
    $wb_url = substr($wb_url, 0, strlen($wb_url)-1);  | 
|
| 778 | 
    }  | 
|
| 779 | 
    if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
   | 
|
| 780 | 
    $wb_url = substr($wb_url, 0, strlen($wb_url)-1);  | 
|
| 781 | 
    }  | 
|
| 782 | 
    // Get the default time zone  | 
|
| 783 | 
    if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
   | 
|
| 784 | 
    	set_error('Please select a valid default timezone');
   | 
|
| 785 | 
    } else {
   | 
|
| 786 | 
    $default_timezone = $_POST['default_timezone']*60*60;  | 
|
| 787 | 
    }  | 
|
| 788 | 
    // End path and timezone details code  | 
|
| 789 | 
     | 
|
| 790 | 
    // Begin operating system specific code  | 
|
| 791 | 
    // Get operating system  | 
|
| 792 | 
    if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
   | 
|
| 793 | 
    	set_error('Please select a valid operating system');
   | 
|
| 794 | 
    } else {
   | 
|
| 795 | 
    $operating_system = $_POST['operating_system'];  | 
|
| 796 | 
    }  | 
|
| 797 | 
    // Work-out file permissions  | 
|
| 798 | 
    if($operating_system == 'windows') {
   | 
|
| 799 | 
    $file_mode = '0777';  | 
|
| 800 | 
    $dir_mode = '0777';  | 
|
| 801 | 
    } elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
   | 
|
| 802 | 
    $file_mode = '0777';  | 
|
| 803 | 
    $dir_mode = '0777';  | 
|
| 804 | 
    } else {
   | 
|
| 805 | 
    	$file_mode = default_file_mode('../temp');
   | 
|
| 806 | 
    	$dir_mode = default_dir_mode('../temp');
   | 
|
| 807 | 
    }  | 
|
| 808 | 
    // End operating system specific code  | 
|
| 809 | 
     | 
|
| 810 | 
    // Begin database details code  | 
|
| 811 | 
    // Check if user has entered a database host  | 
|
| 812 | 
    if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
   | 
|
| 813 | 
    	set_error('Please enter a database host name');
   | 
|
| 814 | 
    } else {
   | 
|
| 815 | 
    $database_host = $_POST['database_host'];  | 
|
| 816 | 
    }  | 
|
| 817 | 
    // Check if user has entered a database username  | 
|
| 818 | 
    if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
   | 
|
| 819 | 
    	set_error('Please enter a database username');
   | 
|
| 820 | 
    } else {
   | 
|
| 821 | 
    $database_username = $_POST['database_username'];  | 
|
| 822 | 
    }  | 
|
| 823 | 
    // Check if user has entered a database password  | 
|
| 824 | 
    if(!isset($_POST['database_password'])) {
   | 
|
| 825 | 
    	set_error('Please enter a database password');
   | 
|
| 826 | 
    } else {
   | 
|
| 827 | 
    $database_password = $_POST['database_password'];  | 
|
| 828 | 
    }  | 
|
| 829 | 
    // Check if user has entered a database name  | 
|
| 830 | 
    if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
   | 
|
| 831 | 
    	set_error('Please enter a database name');
   | 
|
| 832 | 
    } else {
   | 
|
| 833 | 
    $database_name = $_POST['database_name'];  | 
|
| 834 | 
    }  | 
|
| 835 | 
    // Get table prefix  | 
|
| 836 | 
    $table_prefix = $_POST['table_prefix'];  | 
|
| 837 | 
    // Find out if the user wants to install tables and data  | 
|
| 838 | 
    if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
   | 
|
| 839 | 
    $install_tables = true;  | 
|
| 840 | 
    } else {
   | 
|
| 841 | 
    $install_tables = false;  | 
|
| 842 | 
    }  | 
|
| 843 | 
    // End database details code  | 
|
| 844 | 
     | 
|
| 845 | 
    // Begin website title code  | 
|
| 846 | 
    // Get website title  | 
|
| 847 | 
    if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
   | 
|
| 848 | 
    	set_error('Please enter a website title');
   | 
|
| 849 | 
    } else {
   | 
|
| 850 | 
    $website_title = add_slashes($_POST['website_title']);  | 
|
| 851 | 
    }  | 
|
| 852 | 
    // End website title code  | 
|
| 853 | 
     | 
|
| 854 | 
    // Begin admin user details code  | 
|
| 855 | 
    // Get admin username  | 
|
| 856 | 
    if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
   | 
|
| 857 | 
    	set_error('Please enter a username for the Administrator account');
   | 
|
| 858 | 
    } else {
   | 
|
| 859 | 
    $admin_username = $_POST['admin_username'];  | 
|
| 860 | 
    }  | 
|
| 861 | 
    // Get admin email and validate it  | 
|
| 862 | 
    if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
   | 
|
| 863 | 
    	set_error('Please enter an email for the Administrator account');
   | 
|
| 864 | 
    } else {
   | 
|
| 865 | 
    	if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['admin_email'])) {
   | 
|
| 866 | 
    $admin_email = $_POST['admin_email'];  | 
|
| 867 | 
    	} else {
   | 
|
| 868 | 
    		set_error('Please enter a valid email address for the Administrator account');
   | 
|
| 869 | 
    }  | 
|
| 870 | 
    }  | 
|
| 871 | 
    // Get the two admin passwords entered, and check that they match  | 
|
| 872 | 
    if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
   | 
|
| 873 | 
    	set_error('Please enter a password for the Administrator account');
   | 
|
| 874 | 
    } else {
   | 
|
| 875 | 
    $admin_password = $_POST['admin_password'];  | 
|
| 876 | 
    }  | 
|
| 877 | 
    if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
   | 
|
| 878 | 
    	set_error('Please make sure you re-enter the password for the Administrator account');
   | 
|
| 879 | 
    } else {
   | 
|
| 880 | 
    $admin_repassword = $_POST['admin_repassword'];  | 
|
| 881 | 
    }  | 
|
| 882 | 
    if($admin_password != $admin_repassword) {
   | 
|
| 883 | 
    	set_error('Sorry, the two Administrator account passwords you entered do not match');
   | 
|
| 884 | 
    }  | 
|
| 885 | 
    // End admin user details code  | 
|
| 886 | 
     | 
|
| 887 | 
    // Try and write settings to config file  | 
|
| 888 | 
    $config_content = "" .  | 
|
| 889 | 
    "<?php\n".  | 
|
| 890 | 
    "\n".  | 
|
| 891 | 
    "define('DB_TYPE', 'mysql');\n".
   | 
|
| 892 | 
    "define('DB_HOST', '$database_host');\n".
   | 
|
| 893 | 
    "define('DB_USERNAME', '$database_username');\n".
   | 
|
| 894 | 
    "define('DB_PASSWORD', '$database_password');\n".
   | 
|
| 895 | 
    "define('DB_NAME', '$database_name');\n".
   | 
|
| 896 | 
    "define('TABLE_PREFIX', '$table_prefix');\n".
   | 
|
| 897 | 
    "\n".  | 
|
| 898 | 
    "define('WB_PATH', dirname(__FILE__));\n".
   | 
|
| 899 | 
    "define('WB_URL', '$wb_url');\n".
   | 
|
| 900 | 
    "define('ADMIN_PATH', WB_PATH.'/admin');\n".
   | 
|
| 901 | 
    "define('ADMIN_URL', '$wb_url/admin');\n".
   | 
|
| 902 | 
    "\n".  | 
|
| 903 | 
    "require_once(WB_PATH.'/framework/initialize.php');\n".  | 
|
| 904 | 
    "\n".  | 
|
| 905 | 
    "?>";  | 
|
| 906 | 
     | 
|
| 907 | 
    $config_filename = '../config.php';  | 
|
| 908 | 
     | 
|
| 909 | 
    // Check if the file exists and is writable first.  | 
|
| 910 | 
    if(file_exists($config_filename) AND is_writable($config_filename)) {
   | 
|
| 911 | 
    	if(!$handle = fopen($config_filename, 'w')) {
   | 
|
| 912 | 
    		set_error("Cannot open the configuration file ($config_filename)");
   | 
|
| 913 | 
    	} else {
   | 
|
| 914 | 
    		if (fwrite($handle, $config_content) === FALSE) {
   | 
|
| 915 | 
    			set_error("Cannot write to the configuration file ($config_filename)");
   | 
|
| 916 | 
    }  | 
|
| 917 | 
    // Close file  | 
|
| 918 | 
    fclose($handle);  | 
|
| 919 | 
    }  | 
|
| 920 | 
    } else {
   | 
|
| 921 | 
    	set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
   | 
|
| 922 | 
    }  | 
|
| 923 | 
     | 
|
| 924 | 
    // Define configuration vars  | 
|
| 925 | 
    define('DB_TYPE', 'mysql');
   | 
|
| 926 | 
    define('DB_HOST', $database_host);
   | 
|
| 927 | 
    define('DB_USERNAME', $database_username);
   | 
|
| 928 | 
    define('DB_PASSWORD', $database_password);
   | 
|
| 929 | 
    define('DB_NAME', $database_name);
   | 
|
| 930 | 
    define('TABLE_PREFIX', $table_prefix);
   | 
|
| 931 | 
    define('WB_PATH', str_replace(array('/install','\install'), '',dirname(__FILE__)));
   | 
|
| 932 | 
    define('WB_URL', $wb_url);
   | 
|
| 933 | 
    define('ADMIN_PATH', WB_PATH.'/admin');
   | 
|
| 934 | 
    define('ADMIN_URL', $wb_url.'/admin');
   | 
|
| 935 | 
     | 
|
| 936 | 
    // Check if the user has entered a correct path  | 
|
| 937 | 
    if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
   | 
|
| 938 | 
    	set_error('It appears the Absolute path that you entered is incorrect');
   | 
|
| 939 | 
    }  | 
|
| 940 | 
     | 
|
| 941 | 
    // Try connecting to database  | 
|
| 942 | 
    if(!mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) {
   | 
|
| 943 | 
    	set_error('Database host name, username and/or password incorrect. MySQL Error:<br />'.mysql_error());
   | 
|
| 944 | 
    }  | 
|
| 945 | 
     | 
|
| 946 | 
    // Try to create the database  | 
|
| 947 | 
    mysql_query('CREATE DATABASE '.$database_name);
   | 
|
| 948 | 
     | 
|
| 949 | 
    // Close the mysql connection  | 
|
| 950 | 
    mysql_close();  | 
|
| 951 | 
     | 
|
| 952 | 
    // Include WB functions file  | 
|
| 953 | 
    require_once(WB_PATH.'/framework/functions.php');  | 
|
| 954 | 
     | 
|
| 955 | 
    // Re-connect to the database, this time using in-build database class  | 
|
| 956 | 
    require_once(WB_PATH.'/framework/class.login.php');  | 
|
| 957 | 
    $database=new database();  | 
|
| 958 | 
     | 
|
| 959 | 
    // Check if we should install tables  | 
|
| 960 | 
    if($install_tables == true) {
   | 
|
| 961 | 
     | 
|
| 962 | 
    // Remove tables if they exist  | 
|
| 963 | 
     | 
|
| 964 | 
    // Pages table  | 
|
| 965 | 
    $pages = "DROP TABLE IF EXISTS `".TABLE_PREFIX."pages`";  | 
|
| 966 | 
    $database->query($pages);  | 
|
| 967 | 
    // Sections table  | 
|
| 968 | 
    $sections = "DROP TABLE IF EXISTS `".TABLE_PREFIX."sections`";  | 
|
| 969 | 
    $database->query($sections);  | 
|
| 970 | 
    // Settings table  | 
|
| 971 | 
    $settings = "DROP TABLE IF EXISTS `".TABLE_PREFIX."settings`";  | 
|
| 972 | 
    $database->query($settings);  | 
|
| 973 | 
    // Users table  | 
|
| 974 | 
    $users = "DROP TABLE IF EXISTS `".TABLE_PREFIX."users`";  | 
|
| 975 | 
    $database->query($users);  | 
|
| 976 | 
    // Groups table  | 
|
| 977 | 
    $groups = "DROP TABLE IF EXISTS `".TABLE_PREFIX."groups`";  | 
|
| 978 | 
    $database->query($groups);  | 
|
| 979 | 
    // Search table  | 
|
| 980 | 
    $search = "DROP TABLE IF EXISTS `".TABLE_PREFIX."search`";  | 
|
| 981 | 
    $database->query($search);  | 
|
| 982 | 
    // Addons table  | 
|
| 983 | 
    $addons = "DROP TABLE IF EXISTS `".TABLE_PREFIX."addons`";  | 
|
| 984 | 
    $database->query($addons);  | 
|
| 985 | 
     | 
|
| 986 | 
    // Try installing tables  | 
|
| 987 | 
     | 
|
| 988 | 
    // Pages table  | 
|
| 989 | 
    $pages = 'CREATE TABLE `'.TABLE_PREFIX.'pages` ( `page_id` INT NOT NULL auto_increment,'  | 
|
| 990 | 
    . ' `parent` INT NOT NULL ,'  | 
|
| 991 | 
    . ' `root_parent` INT NOT NULL ,'  | 
|
| 992 | 
    . ' `level` INT NOT NULL ,'  | 
|
| 993 | 
    . ' `link` TEXT NOT NULL ,'  | 
|
| 994 | 
    . ' `target` VARCHAR( 7 ) NOT NULL ,'  | 
|
| 995 | 
    . ' `page_title` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 996 | 
    . ' `menu_title` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 997 | 
    . ' `description` TEXT NOT NULL ,'  | 
|
| 998 | 
    . ' `keywords` TEXT NOT NULL ,'  | 
|
| 999 | 
    . ' `page_trail` TEXT NOT NULL ,'  | 
|
| 1000 | 
    . ' `template` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1001 | 
    . ' `visibility` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1002 | 
    . ' `position` INT NOT NULL ,'  | 
|
| 1003 | 
    . ' `menu` INT NOT NULL ,'  | 
|
| 1004 | 
    . ' `language` VARCHAR( 5 ) NOT NULL ,'  | 
|
| 1005 | 
    . ' `searching` INT NOT NULL ,'  | 
|
| 1006 | 
    . ' `admin_groups` TEXT NOT NULL ,'  | 
|
| 1007 | 
    . ' `admin_users` TEXT NOT NULL ,'  | 
|
| 1008 | 
    . ' `viewing_groups` TEXT NOT NULL ,'  | 
|
| 1009 | 
    . ' `viewing_users` TEXT NOT NULL ,'  | 
|
| 1010 | 
    . ' `modified_when` INT NOT NULL ,'  | 
|
| 1011 | 
    . ' `modified_by` INT NOT NULL ,'  | 
|
| 1012 | 
    . ' PRIMARY KEY ( `page_id` ) )'  | 
|
| 1013 | 
    . ' ';  | 
|
| 1014 | 
    $database->query($pages);  | 
|
| 1015 | 
     | 
|
| 1016 | 
    // Sections table  | 
|
| 1017 | 
    $pages = 'CREATE TABLE `'.TABLE_PREFIX.'sections` ( `section_id` INT NOT NULL auto_increment,'  | 
|
| 1018 | 
    . ' `page_id` INT NOT NULL ,'  | 
|
| 1019 | 
    . ' `position` INT NOT NULL ,'  | 
|
| 1020 | 
    . ' `module` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1021 | 
    . ' `block` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1022 | 
    . ' PRIMARY KEY ( `section_id` ) )'  | 
|
| 1023 | 
    . ' ';  | 
|
| 1024 | 
    $database->query($pages);  | 
|
| 1025 | 
     | 
|
| 1026 | 
    require(WB_PATH.'/admin/interface/version.php');  | 
|
| 1027 | 
     | 
|
| 1028 | 
    // Settings table  | 
|
| 1029 | 
    $settings="CREATE TABLE `".TABLE_PREFIX."settings` ( `setting_id` INT NOT NULL auto_increment,  | 
|
| 1030 | 
    `name` VARCHAR( 255 ) NOT NULL ,  | 
|
| 1031 | 
    `value` TEXT NOT NULL ,  | 
|
| 1032 | 
    PRIMARY KEY ( `setting_id` ) )";  | 
|
| 1033 | 
    $database->query($settings);  | 
|
| 1034 | 
    $settings_rows= "INSERT INTO `".TABLE_PREFIX."settings` VALUES "  | 
|
| 1035 | 
    	." ('', 'wb_version', '".VERSION."'),"
   | 
|
| 1036 | 
    	." ('', 'website_title', '$website_title'),"
   | 
|
| 1037 | 
    	." ('', 'website_description', ''),"
   | 
|
| 1038 | 
    	." ('', 'website_keywords', ''),"
   | 
|
| 1039 | 
    	." ('', 'website_header', ''),"
   | 
|
| 1040 | 
    	." ('', 'website_footer', ''),"
   | 
|
| 1041 | 
    	." ('', 'wysiwyg_style', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'),"
   | 
|
| 1042 | 
    	." ('', 'rename_files_on_upload', 'php,asp,phpx,aspx'),"
   | 
|
| 1043 | 
    	." ('', 'er_level', ''),"
   | 
|
| 1044 | 
    	." ('', 'default_language', 'EN'),"
   | 
|
| 1045 | 
    	." ('', 'app_name', 'wb'),"
   | 
|
| 1046 | 
    	." ('', 'default_timezone', '$default_timezone'),"
   | 
|
| 1047 | 
    	." ('', 'default_date_format', 'M d Y'),"
   | 
|
| 1048 | 
    	." ('', 'default_time_format', 'g:i A'),"
   | 
|
| 1049 | 
    	." ('', 'home_folders', 'true'),"
   | 
|
| 1050 | 
    	." ('', 'default_template', 'round'),"
   | 
|
| 1051 | 
    	." ('', 'multiple_menus', 'false'),"
   | 
|
| 1052 | 
    	." ('', 'page_level_limit', '4'),"
   | 
|
| 1053 | 
    	." ('', 'intro_page', 'false'),"
   | 
|
| 1054 | 
    	." ('', 'page_trash', 'disabled'),"
   | 
|
| 1055 | 
    	." ('', 'homepage_redirection', 'false'),"
   | 
|
| 1056 | 
    	." ('', 'page_languages', 'false'),"
   | 
|
| 1057 | 
    	." ('', 'wysiwyg_editor', 'htmlarea'),"
   | 
|
| 1058 | 
    	." ('', 'manage_sections', 'true'),"
   | 
|
| 1059 | 
    	." ('', 'section_blocks', 'false'),"
   | 
|
| 1060 | 
    	." ('', 'smart_login', 'false'),"
   | 
|
| 1061 | 
    	." ('', 'frontend_login', 'false'),"
   | 
|
| 1062 | 
    	." ('', 'frontend_signup', 'false'),"
   | 
|
| 1063 | 
    	." ('', 'server_email', '$admin_email'),"
   | 
|
| 1064 | 
    	." ('', 'search', 'public'),"
   | 
|
| 1065 | 
    	." ('', 'page_extension', '.php'),"
   | 
|
| 1066 | 
    	." ('', 'page_spacer', '-'),"
   | 
|
| 1067 | 
    	." ('', 'pages_directory', '/pages'),"
   | 
|
| 1068 | 
    	." ('', 'media_directory', '/media'),"
   | 
|
| 1069 | 
    	." ('', 'operating_system', '$operating_system'),"
   | 
|
| 1070 | 
    	." ('', 'string_file_mode', '$file_mode'),"
   | 
|
| 1071 | 
    	." ('', 'string_dir_mode', '$dir_mode');";
   | 
|
| 1072 | 
    $database->query($settings_rows);  | 
|
| 1073 | 
     | 
|
| 1074 | 
     | 
|
| 1075 | 
    // Users table  | 
|
| 1076 | 
    $users = 'CREATE TABLE `'.TABLE_PREFIX.'users` ( `user_id` INT NOT NULL auto_increment,'  | 
|
| 1077 | 
    . ' `group_id` INT NOT NULL ,'  | 
|
| 1078 | 
    . ' `active` INT NOT NULL ,'  | 
|
| 1079 | 
    . ' `username` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1080 | 
    . ' `password` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1081 | 
    . ' `remember_key` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1082 | 
    . ' `last_reset` INT NOT NULL ,'  | 
|
| 1083 | 
    . ' `display_name` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1084 | 
    . ' `email` TEXT NOT NULL ,'  | 
|
| 1085 | 
    . ' `timezone` INT NOT NULL ,'  | 
|
| 1086 | 
    . ' `date_format` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1087 | 
    . ' `time_format` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1088 | 
    . ' `language` VARCHAR( 5 ) NOT NULL ,'  | 
|
| 1089 | 
    . ' `home_folder` TEXT NOT NULL ,'  | 
|
| 1090 | 
    . ' `login_when` INT NOT NULL ,'  | 
|
| 1091 | 
    . ' `login_ip` VARCHAR( 15 ) NOT NULL ,'  | 
|
| 1092 | 
    . ' PRIMARY KEY ( `user_id` ) )'  | 
|
| 1093 | 
    . ' ';  | 
|
| 1094 | 
    $database->query($users);  | 
|
| 1095 | 
     | 
|
| 1096 | 
    // Groups table  | 
|
| 1097 | 
    $groups = 'CREATE TABLE `'.TABLE_PREFIX.'groups` ( `group_id` INT NOT NULL auto_increment,'  | 
|
| 1098 | 
    . ' `name` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1099 | 
    . ' `system_permissions` TEXT NOT NULL ,'  | 
|
| 1100 | 
    . ' `module_permissions` TEXT NOT NULL ,'  | 
|
| 1101 | 
    . ' `template_permissions` TEXT NOT NULL ,'  | 
|
| 1102 | 
    . ' PRIMARY KEY ( `group_id` ) )'  | 
|
| 1103 | 
    . ' ';  | 
|
| 1104 | 
    $database->query($groups);  | 
|
| 1105 | 
     | 
|
| 1106 | 
    // Search settings table  | 
|
| 1107 | 
    $search = 'CREATE TABLE `'.TABLE_PREFIX.'search` ( `search_id` INT NOT NULL auto_increment,'  | 
|
| 1108 | 
    . ' `name` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1109 | 
    . ' `value` TEXT NOT NULL ,'  | 
|
| 1110 | 
    . ' `extra` TEXT NOT NULL ,'  | 
|
| 1111 | 
    . ' PRIMARY KEY ( `search_id` ) )'  | 
|
| 1112 | 
    . ' ';  | 
|
| 1113 | 
    $database->query($search);  | 
|
| 1114 | 
     | 
|
| 1115 | 
    // Addons table  | 
|
| 1116 | 
    $addons = 'CREATE TABLE `'.TABLE_PREFIX.'addons` ( '  | 
|
| 1117 | 
    .'`addon_id` INT NOT NULL auto_increment ,'  | 
|
| 1118 | 
    .'`type` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1119 | 
    .'`directory` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1120 | 
    .'`name` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1121 | 
    .'`description` TEXT NOT NULL ,'  | 
|
| 1122 | 
    .'`function` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1123 | 
    .'`version` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1124 | 
    .'`platform` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1125 | 
    .'`author` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1126 | 
    .'`license` VARCHAR( 255 ) NOT NULL ,'  | 
|
| 1127 | 
    .' PRIMARY KEY ( `addon_id` ) )';  | 
|
| 1128 | 
    $database->query($addons);  | 
|
| 1129 | 
     | 
|
| 1130 | 
    // Insert default data  | 
|
| 1131 | 
     | 
|
| 1132 | 
    // Admin group  | 
|
| 1133 | 
    $full_system_permissions = 'pages,pages_view,pages_add,pages_add_l0,pages_settings,pages_modify,pages_intro,pages_delete,media,media_view,media_upload,media_rename,media_delete,media_create,addons,modules,modules_view,modules_install,modules_uninstall,templates,templates_view,templates_install,templates_uninstall,languages,languages_view,languages_install,languages_uninstall,settings,settings_basic,settings_advanced,access,users,users_view,users_add,users_modify,users_delete,groups,groups_view,groups_add,groups_modify,groups_delete';  | 
|
| 1134 | 
    	$insert_admin_group = "INSERT INTO `".TABLE_PREFIX."groups` VALUES ('1', 'Administrators', '$full_system_permissions', '', '')";
   | 
|
| 1135 | 
    $database->query($insert_admin_group);  | 
|
| 1136 | 
    // Admin user  | 
|
| 1137 | 
    	$insert_admin_user = "INSERT INTO `".TABLE_PREFIX."users` (user_id,group_id,active,username,password,email,display_name) VALUES ('1','1','1','$admin_username','".md5($admin_password)."','$admin_email','Administrator')";
   | 
|
| 1138 | 
    $database->query($insert_admin_user);  | 
|
| 1139 | 
     | 
|
| 1140 | 
    // Search header  | 
|
| 1141 | 
    	$search_header = addslashes('
   | 
|
| 1142 | 
    <h1>Search</h1>  | 
|
| 1143 | 
     | 
|
| 1144 | 
    <form name="search" action="[WB_URL]/search/index[PAGE_EXTENSION]" method="post">  | 
|
| 1145 | 
    <table cellpadding="3" cellspacing="0" border="0" width="500">  | 
|
| 1146 | 
    <tr>  | 
|
| 1147 | 
    <td>  | 
|
| 1148 | 
    <input type="text" name="string" value="[SEARCH_STRING]" style="width: 100%;" />  | 
|
| 1149 | 
    </td>  | 
|
| 1150 | 
    <td width="150">  | 
|
| 1151 | 
    <input type="submit" value="[TEXT_SEARCH]" style="width: 100%;" />  | 
|
| 1152 | 
    </td>  | 
|
| 1153 | 
    </tr>  | 
|
| 1154 | 
    <tr>  | 
|
| 1155 | 
    <td colspan="2">  | 
|
| 1156 | 
    <input type="radio" name="match" id="match_all" value="all"[ALL_CHECKED] />  | 
|
| 1157 | 
    <a href="javascript: toggle_radio(\'match_all\');">[TEXT_ALL_WORDS]</a>  | 
|
| 1158 | 
    <input type="radio" name="match" id="match_any" value="any"[ANY_CHECKED] />  | 
|
| 1159 | 
    <a href="javascript: toggle_radio(\'match_any\');">[TEXT_ANY_WORDS]</a>  | 
|
| 1160 | 
    <input type="radio" name="match" id="match_exact" value="exact"[EXACT_CHECKED] />  | 
|
| 1161 | 
    <a href="javascript: toggle_radio(\'match_exact\');">[TEXT_EXACT_MATCH]</a>  | 
|
| 1162 | 
    </td>  | 
|
| 1163 | 
    </tr>  | 
|
| 1164 | 
    </table>  | 
|
| 1165 | 
     | 
|
| 1166 | 
    </form>  | 
|
| 1167 | 
     | 
|
| 1168 | 
    <hr />  | 
|
| 1169 | 
    ');  | 
|
| 1170 | 
    	$insert_search_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'header', '$search_header', '')";
   | 
|
| 1171 | 
    $database->query($insert_search_header);  | 
|
| 1172 | 
    // Search footer  | 
|
| 1173 | 
    	$search_footer = addslashes('');
   | 
|
| 1174 | 
    	$insert_search_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'footer', '$search_footer', '')";
   | 
|
| 1175 | 
    $database->query($insert_search_footer);  | 
|
| 1176 | 
    // Search results header  | 
|
| 1177 | 
    	$search_results_header = addslashes(''.
   | 
|
| 1178 | 
    '[TEXT_RESULTS_FOR] \'<b>[SEARCH_STRING]</b>\':  | 
|
| 1179 | 
    <table cellpadding="2" cellspacing="0" border="0" width="100%" style="padding-top: 10px;">');  | 
|
| 1180 | 
    	$insert_search_results_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_header', '$search_results_header', '')";
   | 
|
| 1181 | 
    $database->query($insert_search_results_header);  | 
|
| 1182 | 
    // Search results loop  | 
|
| 1183 | 
    	$search_results_loop = addslashes(''.
   | 
|
| 1184 | 
    '<tr style="background-color: #F0F0F0;">  | 
|
| 1185 | 
    <td><a href="[LINK]">[TITLE]</a></td>  | 
|
| 1186 | 
    <td align="right">[TEXT_LAST_UPDATED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [DATE]</td>  | 
|
| 1187 | 
    </tr>  | 
|
| 1188 | 
    <tr><td colspan="2" style="text-align: justify; padding-bottom: 10px;">[DESCRIPTION]</td></tr>');  | 
|
| 1189 | 
    $insert_search_results_loop = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_loop', '$search_results_loop', '')";
   | 
|
| 1190 | 
    $database->query($insert_search_results_loop);  | 
|
| 1191 | 
    // Search results footer  | 
|
| 1192 | 
    $search_results_footer = addslashes("</table>");
   | 
|
| 1193 | 
    $insert_search_results_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_footer', '$search_results_footer', '')";
   | 
|
| 1194 | 
    $database->query($insert_search_results_footer);  | 
|
| 1195 | 
    // Search no results  | 
|
| 1196 | 
    $search_no_results = addslashes('<br />No results found');
   | 
|
| 1197 | 
    	$insert_search_no_results = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'no_results', '$search_no_results', '')";
   | 
|
| 1198 | 
    $database->query($insert_search_no_results);  | 
|
| 1199 | 
    // Search template  | 
|
| 1200 | 
    	$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
   | 
|
| 1201 | 
     | 
|
| 1202 | 
    require_once(WB_PATH.'/framework/initialize.php');  | 
|
| 1203 | 
    $wb = new wb();  | 
|
| 1204 | 
     | 
|
| 1205 | 
    // Install add-ons  | 
|
| 1206 | 
    	if(file_exists(WB_PATH.'/install/modules')) {
   | 
|
| 1207 | 
    // Unpack pre-packaged modules  | 
|
| 1208 | 
     | 
|
| 1209 | 
    }  | 
|
| 1210 | 
    	if(file_exists(WB_PATH.'/install/templates')) {
   | 
|
| 1211 | 
    // Unpack pre-packaged templates  | 
|
| 1212 | 
     | 
|
| 1213 | 
    }  | 
|
| 1214 | 
    	if(file_exists(WB_PATH.'/install/languages')) {
   | 
|
| 1215 | 
    // Unpack pre-packaged languages  | 
|
| 1216 | 
     | 
|
| 1217 | 
    }  | 
|
| 1218 | 
    // Load addons into DB  | 
|
| 1219 | 
    $dirs['modules'] = WB_PATH.'/modules/';  | 
|
| 1220 | 
    $dirs['templates'] = WB_PATH.'/templates/';  | 
|
| 1221 | 
    $dirs['languages'] = WB_PATH.'/languages/';  | 
|
| 1222 | 
    	foreach($dirs AS $type => $dir) {
   | 
|
| 1223 | 
    		if($handle = opendir($dir)) {
   | 
|
| 1224 | 
    			while(false !== ($file = readdir($handle))) {
   | 
|
| 1225 | 
    				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
   | 
|
| 1226 | 
    // Get addon type  | 
|
| 1227 | 
    					if($type == 'modules') {
   | 
|
| 1228 | 
    load_module($dir.'/'.$file, true);  | 
|
| 1229 | 
    					} elseif($type == 'templates') {
   | 
|
| 1230 | 
    load_template($dir.'/'.$file);  | 
|
| 1231 | 
    					} elseif($type == 'languages') {
   | 
|
| 1232 | 
    load_language($dir.'/'.$file);  | 
|
| 1233 | 
    }  | 
|
| 1234 | 
    }  | 
|
| 1235 | 
    }  | 
|
| 1236 | 
    closedir($handle);  | 
|
| 1237 | 
    }  | 
|
| 1238 | 
    }  | 
|
| 1239 | 
     | 
|
| 1240 | 
    // Check if there was a database error  | 
|
| 1241 | 
    	if($database->is_error()) {
   | 
|
| 1242 | 
    set_error($database->get_error());  | 
|
| 1243 | 
    }  | 
|
| 1244 | 
     | 
|
| 1245 | 
    }  | 
|
| 1246 | 
     | 
|
| 1247 | 
    // Log the user in and go to Website Baker Administration  | 
|
| 1248 | 
    $thisApp = new Login(  | 
|
| 1249 | 
    array(  | 
|
| 1250 | 
    "MAX_ATTEMPS" => "50",  | 
|
| 1251 | 
    "WARNING_URL" => ADMIN_URL."/login/warning.html",  | 
|
| 1252 | 
    "USERNAME_FIELDNAME" => 'admin_username',  | 
|
| 1253 | 
    "PASSWORD_FIELDNAME" => 'admin_password',  | 
|
| 1254 | 
    "REMEMBER_ME_OPTION" => SMART_LOGIN,  | 
|
| 1255 | 
    "MIN_USERNAME_LEN" => "2",  | 
|
| 1256 | 
    "MIN_PASSWORD_LEN" => "2",  | 
|
| 1257 | 
    "MAX_USERNAME_LEN" => "30",  | 
|
| 1258 | 
    "MAX_PASSWORD_LEN" => "30",  | 
|
| 1259 | 
    'LOGIN_URL' => ADMIN_URL."/login/index.php",  | 
|
| 1260 | 
    'DEFAULT_URL' => ADMIN_URL."/start/index.php",  | 
|
| 1261 | 
    'TEMPLATE_DIR' => ADMIN_PATH."/login",  | 
|
| 1262 | 
    'TEMPLATE_FILE' => "template.html",  | 
|
| 1263 | 
    'FRONTEND' => false,  | 
|
| 1264 | 
    'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",  | 
|
| 1265 | 
    'USERS_TABLE' => TABLE_PREFIX."users",  | 
|
| 1266 | 
    'GROUPS_TABLE' => TABLE_PREFIX."groups",  | 
|
| 1267 | 
    )  | 
|
| 1268 | 
    );  | 
|
| 1269 | 
     | 
|
| 1270 | 636 | 
    ?>  | 
Also available in: Unified diff
Fixed save.php