Пример #1
0
/**
 * How do we want to name the admin user?
 */
function create_admin_user()
{
    global $output, $mybb, $errors, $db, $lang;
    $mybb->input['action'] = "adminuser";
    // If no errors then check for errors from last step
    if (!is_array($errors)) {
        if (empty($mybb->input['bburl'])) {
            $errors[] = $lang->config_step_error_url;
        }
        if (empty($mybb->input['bbname'])) {
            $errors[] = $lang->config_step_error_name;
        }
        if (is_array($errors)) {
            configure();
        }
    }
    $output->print_header($lang->create_admin, 'admin');
    echo <<<EOF
\t\t<script type="text/javascript">\t
\t\tfunction comparePass()
\t\t{
\t\t\tvar parenttr = \$('#adminpass2').closest('tr');
\t\t\tvar passval = \$('#adminpass2').val();
\t\t\tif(passval && passval != \$('#adminpass').val())
\t\t\t{
\t\t\t\tif(!parenttr.next('.pass_peeker').length)
\t\t\t\t{
\t\t\t\t\tparenttr.removeClass('last').after('<tr class="pass_peeker"><td colspan="2">{$lang->admin_step_nomatch}</td></tr>');
\t\t\t\t}
\t\t\t} else {
\t\t\t\tparenttr.addClass('last').next('.pass_peeker').remove();
\t\t\t}
\t\t}
\t\t</script>
\t\t
EOF;
    if (is_array($errors)) {
        $error_list = error_list($errors);
        echo $lang->sprintf($lang->admin_step_error_config, $error_list);
        $adminuser = $mybb->get_input('adminuser');
        $adminemail = $mybb->get_input('adminemail');
    } else {
        require MYBB_ROOT . 'inc/config.php';
        $db = db_connection($config);
        echo $lang->admin_step_setupsettings;
        $adminuser = $adminemail = '';
        $settings = file_get_contents(INSTALL_ROOT . 'resources/settings.xml');
        $parser = new XMLParser($settings);
        $parser->collapse_dups = 0;
        $tree = $parser->get_tree();
        $groupcount = $settingcount = 0;
        // Insert all the settings
        foreach ($tree['settings'][0]['settinggroup'] as $settinggroup) {
            $groupdata = array('name' => $db->escape_string($settinggroup['attributes']['name']), 'title' => $db->escape_string($settinggroup['attributes']['title']), 'description' => $db->escape_string($settinggroup['attributes']['description']), 'disporder' => (int) $settinggroup['attributes']['disporder'], 'isdefault' => $settinggroup['attributes']['isdefault']);
            $gid = $db->insert_query('settinggroups', $groupdata);
            ++$groupcount;
            foreach ($settinggroup['setting'] as $setting) {
                $settingdata = array('name' => $db->escape_string($setting['attributes']['name']), 'title' => $db->escape_string($setting['title'][0]['value']), 'description' => $db->escape_string($setting['description'][0]['value']), 'optionscode' => $db->escape_string($setting['optionscode'][0]['value']), 'value' => $db->escape_string($setting['settingvalue'][0]['value']), 'disporder' => (int) $setting['disporder'][0]['value'], 'gid' => $gid, 'isdefault' => 1);
                $db->insert_query('settings', $settingdata);
                $settingcount++;
            }
        }
        if (my_substr($mybb->get_input('bburl'), -1, 1) == '/') {
            $mybb->input['bburl'] = my_substr($mybb->get_input('bburl'), 0, -1);
        }
        $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('bbname'))), "name='bbname'");
        $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('bburl'))), "name='bburl'");
        $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('websitename'))), "name='homename'");
        $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('websiteurl'))), "name='homeurl'");
        $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('cookiedomain'))), "name='cookiedomain'");
        $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('cookiepath'))), "name='cookiepath'");
        $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('contactemail'))), "name='adminemail'");
        $db->update_query("settings", array('value' => 'contact.php'), "name='contactlink'");
        write_settings();
        echo $lang->sprintf($lang->admin_step_insertesettings, $settingcount, $groupcount);
        // Save the acp pin
        $pin = addslashes($mybb->get_input('pin'));
        $file = @fopen(MYBB_ROOT . "inc/config.php", "a");
        @fwrite($file, "/**\n * Admin CP Secret PIN\n *  If you wish to request a PIN\n *  when someone tries to login\n *  on your Admin CP, enter it below.\n */\n\n\$config['secret_pin'] = '{$pin}';");
        @fclose($file);
        include_once MYBB_ROOT . "inc/functions_task.php";
        $tasks = file_get_contents(INSTALL_ROOT . 'resources/tasks.xml');
        $parser = new XMLParser($tasks);
        $parser->collapse_dups = 0;
        $tree = $parser->get_tree();
        $taskcount = 0;
        // Insert scheduled tasks
        foreach ($tree['tasks'][0]['task'] as $task) {
            $new_task = array('title' => $db->escape_string($task['title'][0]['value']), 'description' => $db->escape_string($task['description'][0]['value']), 'file' => $db->escape_string($task['file'][0]['value']), 'minute' => $db->escape_string($task['minute'][0]['value']), 'hour' => $db->escape_string($task['hour'][0]['value']), 'day' => $db->escape_string($task['day'][0]['value']), 'weekday' => $db->escape_string($task['weekday'][0]['value']), 'month' => $db->escape_string($task['month'][0]['value']), 'enabled' => $db->escape_string($task['enabled'][0]['value']), 'logging' => $db->escape_string($task['logging'][0]['value']));
            $new_task['nextrun'] = fetch_next_run($new_task);
            $db->insert_query("tasks", $new_task);
            $taskcount++;
        }
        // For the version check task, set a random date and hour (so all MyBB installs don't query mybb.com all at the same time)
        $update_array = array('hour' => rand(0, 23), 'weekday' => rand(0, 6));
        $db->update_query("tasks", $update_array, "file = 'versioncheck'");
        echo $lang->sprintf($lang->admin_step_insertedtasks, $taskcount);
        $views = file_get_contents(INSTALL_ROOT . 'resources/adminviews.xml');
        $parser = new XMLParser($views);
        $parser->collapse_dups = 0;
        $tree = $parser->get_tree();
        $view_count = 0;
        // Insert admin views
        foreach ($tree['adminviews'][0]['view'] as $view) {
            $fields = array();
            foreach ($view['fields'][0]['field'] as $field) {
                $fields[] = $field['attributes']['name'];
            }
            $conditions = array();
            if (isset($view['conditions'][0]['condition']) && is_array($view['conditions'][0]['condition'])) {
                foreach ($view['conditions'][0]['condition'] as $condition) {
                    if (!$condition['value']) {
                        continue;
                    }
                    if ($condition['attributes']['is_serialized'] == 1) {
                        $condition['value'] = my_unserialize($condition['value']);
                    }
                    $conditions[$condition['attributes']['name']] = $condition['value'];
                }
            }
            $custom_profile_fields = array();
            if (isset($view['custom_profile_fields'][0]['field']) && is_array($view['custom_profile_fields'][0]['field'])) {
                foreach ($view['custom_profile_fields'][0]['field'] as $field) {
                    $custom_profile_fields[] = $field['attributes']['name'];
                }
            }
            $new_view = array("uid" => 0, "type" => $db->escape_string($view['attributes']['type']), "visibility" => (int) $view['attributes']['visibility'], "title" => $db->escape_string($view['title'][0]['value']), "fields" => $db->escape_string(my_serialize($fields)), "conditions" => $db->escape_string(my_serialize($conditions)), "custom_profile_fields" => $db->escape_string(my_serialize($custom_profile_fields)), "sortby" => $db->escape_string($view['sortby'][0]['value']), "sortorder" => $db->escape_string($view['sortorder'][0]['value']), "perpage" => (int) $view['perpage'][0]['value'], "view_type" => $db->escape_string($view['view_type'][0]['value']));
            $db->insert_query("adminviews", $new_view);
            $view_count++;
        }
        echo $lang->sprintf($lang->admin_step_insertedviews, $view_count);
        echo $lang->admin_step_createadmin;
    }
    echo $lang->sprintf($lang->admin_step_admintable, $adminuser, $adminemail);
    $output->print_footer('final');
}
function create_admin_user()
{
    global $output, $mybb, $errors, $db, $lang;
    $mybb->input['action'] = "adminuser";
    // If no errors then check for errors from last step
    if (!is_array($errors)) {
        if (empty($mybb->input['bburl'])) {
            $errors[] = $lang->config_step_error_url;
        }
        if (empty($mybb->input['bbname'])) {
            $errors[] = $lang->config_step_error_name;
        }
        if (is_array($errors)) {
            configure();
        }
    }
    $output->print_header($lang->create_admin, 'admin');
    if (is_array($errors)) {
        $error_list = error_list($errors);
        echo $lang->sprintf($lang->admin_step_error_config, $error_list);
        $adminuser = $mybb->input['adminuser'];
        $adminemail = $mybb->input['adminemail'];
    } else {
        require MYBB_ROOT . 'inc/config.php';
        $db = db_connection($config);
        echo $lang->admin_step_setupsettings;
        $settings = file_get_contents(INSTALL_ROOT . 'resources/settings.xml');
        $parser = new XMLParser($settings);
        $parser->collapse_dups = 0;
        $tree = $parser->get_tree();
        // Insert all the settings
        foreach ($tree['settings'][0]['settinggroup'] as $settinggroup) {
            $groupdata = array('name' => $db->escape_string($settinggroup['attributes']['name']), 'title' => $db->escape_string($settinggroup['attributes']['title']), 'description' => $db->escape_string($settinggroup['attributes']['description']), 'disporder' => intval($settinggroup['attributes']['disporder']), 'isdefault' => $settinggroup['attributes']['isdefault']);
            $gid = $db->insert_query('settinggroups', $groupdata);
            ++$groupcount;
            foreach ($settinggroup['setting'] as $setting) {
                $settingdata = array('name' => $db->escape_string($setting['attributes']['name']), 'title' => $db->escape_string($setting['title'][0]['value']), 'description' => $db->escape_string($setting['description'][0]['value']), 'optionscode' => $db->escape_string($setting['optionscode'][0]['value']), 'value' => $db->escape_string($setting['settingvalue'][0]['value']), 'disporder' => intval($setting['disporder'][0]['value']), 'gid' => $gid, 'isdefault' => 1);
                $db->insert_query('settings', $settingdata);
                $settingcount++;
            }
        }
        if (my_substr($mybb->input['bburl'], -1, 1) == '/') {
            $mybb->input['bburl'] = my_substr($mybb->input['bburl'], 0, -1);
        }
        $db->update_query("settings", array('value' => $db->escape_string($mybb->input['bbname'])), "name='bbname'");
        $db->update_query("settings", array('value' => $db->escape_string($mybb->input['bburl'])), "name='bburl'");
        $db->update_query("settings", array('value' => $db->escape_string($mybb->input['websitename'])), "name='homename'");
        $db->update_query("settings", array('value' => $db->escape_string($mybb->input['websiteurl'])), "name='homeurl'");
        $db->update_query("settings", array('value' => $db->escape_string($mybb->input['cookiedomain'])), "name='cookiedomain'");
        $db->update_query("settings", array('value' => $db->escape_string($mybb->input['cookiepath'])), "name='cookiepath'");
        $db->update_query("settings", array('value' => $db->escape_string($mybb->input['contactemail'])), "name='adminemail'");
        $db->update_query("settings", array('value' => 'mailto:' . $db->escape_string($mybb->input['contactemail'])), "name='contactlink'");
        write_settings();
        echo $lang->sprintf($lang->admin_step_insertesettings, $settingcount, $groupcount);
        include_once MYBB_ROOT . "inc/functions_task.php";
        $tasks = file_get_contents(INSTALL_ROOT . 'resources/tasks.xml');
        $parser = new XMLParser($tasks);
        $parser->collapse_dups = 0;
        $tree = $parser->get_tree();
        // Insert scheduled tasks
        foreach ($tree['tasks'][0]['task'] as $task) {
            $new_task = array('title' => $db->escape_string($task['title'][0]['value']), 'description' => $db->escape_string($task['description'][0]['value']), 'file' => $db->escape_string($task['file'][0]['value']), 'minute' => $db->escape_string($task['minute'][0]['value']), 'hour' => $db->escape_string($task['hour'][0]['value']), 'day' => $db->escape_string($task['day'][0]['value']), 'weekday' => $db->escape_string($task['weekday'][0]['value']), 'month' => $db->escape_string($task['month'][0]['value']), 'enabled' => $db->escape_string($task['enabled'][0]['value']), 'logging' => $db->escape_string($task['logging'][0]['value']));
            $new_task['nextrun'] = fetch_next_run($new_task);
            $db->insert_query("tasks", $new_task);
            $taskcount++;
        }
        echo $lang->sprintf($lang->admin_step_insertedtasks, $taskcount);
        $views = file_get_contents(INSTALL_ROOT . 'resources/adminviews.xml');
        $parser = new XMLParser($views);
        $parser->collapse_dups = 0;
        $tree = $parser->get_tree();
        // Insert admin views
        foreach ($tree['adminviews'][0]['view'] as $view) {
            $fields = array();
            foreach ($view['fields'][0]['field'] as $field) {
                $fields[] = $field['attributes']['name'];
            }
            $conditions = array();
            if (is_array($view['conditions'][0]['condition'])) {
                foreach ($view['conditions'][0]['condition'] as $condition) {
                    if (!$condition['value']) {
                        continue;
                    }
                    if ($condition['attributes']['is_serialized'] == 1) {
                        $condition['value'] = unserialize($condition['value']);
                    }
                    $conditions[$condition['attributes']['name']] = $condition['value'];
                }
            }
            $custom_profile_fields = array();
            if (is_array($view['custom_profile_fields'][0]['field'])) {
                foreach ($view['custom_profile_fields'][0]['field'] as $field) {
                    $custom_profile_fields[] = $field['attributes']['name'];
                }
            }
            $new_view = array("uid" => 0, "type" => $db->escape_string($view['attributes']['type']), "visibility" => intval($view['attributes']['visibility']), "title" => $db->escape_string($view['title'][0]['value']), "fields" => $db->escape_string(serialize($fields)), "conditions" => $db->escape_string(serialize($conditions)), "custom_profile_fields" => $db->escape_string(serialize($custom_profile_fields)), "sortby" => $db->escape_string($view['sortby'][0]['value']), "sortorder" => $db->escape_string($view['sortorder'][0]['value']), "perpage" => intval($view['perpage'][0]['value']), "view_type" => $db->escape_string($view['view_type'][0]['value']));
            $db->insert_query("adminviews", $new_view);
            $view_count++;
        }
        echo $lang->sprintf($lang->admin_step_insertedviews, $view_count);
        echo $lang->admin_step_createadmin;
    }
    echo $lang->sprintf($lang->admin_step_admintable, $adminuser, $adminemail);
    $output->print_footer('final');
}
Пример #3
0
    $salt = str_rand();
    $sqldata = array_merge($data, array('QUOTETABLE' => db_tablename('quotes'), 'QUEUETABLE' => db_tablename('queue'), 'USERSTABLE' => db_tablename('users'), 'TRACKINGTABLE' => db_tablename('tracking'), 'NEWSTABLE' => db_tablename('news'), 'SPAMTABLE' => db_tablename('spamlog'), 'DUPETABLE' => db_tablename('dupes'), 'ADMINUSER' => "'" . $_POST['adminuser'] . "'", 'ADMINPASS' => "'\\\$1" . crypt($_POST['adminpass'], "\$1\$" . substr($salt, 0, 8) . "\$") . "'", 'ADMINSALT' => '\'\\$1\\$' . $salt . '\\$\''));
    $sql = mangle_sql('install.sql', $sqldata);
    print '<pre>' . $sql . '</pre>';
    $CONFIG = remove_quotes($data);
    include 'db.php';
    $db = get_db($CONFIG);
    if ($db) {
        db_query($sql);
        $db = null;
    } else {
        print '<p>Sorry, cannot access the database. You may need to do the commands manually.';
    }
} else {
    if (!file_exists('settings.php')) {
        if (!write_settings('settings.php', null)) {
            die('Cannot write settings.');
        }
        @unlink('settings.php');
        function mk_rss_url()
        {
            return 'http://' . $_SERVER['SERVER_NAME'] . preg_replace('/\\/install.php$/', '', $_SERVER['REQUEST_URI']);
        }
        $hidelink = 1;
        ?>
<h2>Install</h2>
<form action="./install.php" method="post">
<table>
 <tr>
  <td>Template</td>
  <td><select name="template"><?php 
<?php

require "settings.php";
if (isset($_POST["key"])) {
    switch ($_POST["key"]) {
        case "confirm":
            $OUTPUT = confirm_settings($_POST);
            break;
        case "write":
            $OUTPUT = write_settings($_POST);
            break;
        default:
            $OUTPUT = get_setting();
    }
} else {
    $OUTPUT = get_setting();
}
require "template.php";
function get_setting()
{
    #get current setting
    $get_period = "SELECT * FROM settings WHERE label = 'VAT Period' LIMIT 1";
    $run_period = db_exec($get_period) or errDie("Unable to get vat period information.");
    if (pg_numrows($run_period) < 1) {
        $period = "2";
    } else {
        $parr = pg_fetch_array($run_period);
        $period = $parr['value'];
    }
    $options = array("1" => "1 Month", "2" => "2 Months", "3" => "3 Months", "6" => "6 Months", "12" => "1 Year");
    $period_drop = "<select name='period'>";
Пример #5
0
function test_shutdown_function()
{
    global $db;
    $db->update_query("settings", array('value' => 'yes'), "name='useshutdownfunc'");
    write_settings();
}