function install_user() { if (!confirmed()) { confirm('Create Admin User'); } if ($_POST) { create_admin_user(); } else { write_admin_user_form(); } }
/** * Installation is finished */ function install_done() { global $output, $db, $mybb, $errors, $cache, $lang; if (empty($mybb->input['adminuser'])) { $errors[] = $lang->admin_step_error_nouser; } if (empty($mybb->input['adminpass'])) { $errors[] = $lang->admin_step_error_nopassword; } if ($mybb->get_input('adminpass') != $mybb->get_input('adminpass2')) { $errors[] = $lang->admin_step_error_nomatch; } if (empty($mybb->input['adminemail'])) { $errors[] = $lang->admin_step_error_noemail; } if (is_array($errors)) { create_admin_user(); } require MYBB_ROOT . 'inc/config.php'; $db = db_connection($config); require MYBB_ROOT . 'inc/settings.php'; $mybb->settings =& $settings; ob_start(); $output->print_header($lang->finish_setup, 'finish'); echo $lang->done_step_usergroupsinserted; // Insert all of our user groups from the XML file $usergroup_settings = file_get_contents(INSTALL_ROOT . 'resources/usergroups.xml'); $parser = new XMLParser($usergroup_settings); $parser->collapse_dups = 0; $tree = $parser->get_tree(); $admin_gid = ''; $group_count = 0; foreach ($tree['usergroups'][0]['usergroup'] as $usergroup) { // usergroup[cancp][0][value] $new_group = array(); foreach ($usergroup as $key => $value) { if (!is_array($value)) { continue; } $new_group[$key] = $db->escape_string($value[0]['value']); } $db->insert_query("usergroups", $new_group, false); // If this group can access the admin CP and we haven't established the admin group - set it (just in case we ever change IDs) if ($new_group['cancp'] == 1 && !$admin_gid) { $admin_gid = $usergroup['gid'][0]['value']; } $group_count++; } // Restart usergroup sequence with correct # of groups if ($config['database']['type'] == "pgsql") { $db->query("SELECT setval('{$config['database']['table_prefix']}usergroups_gid_seq', (SELECT max(gid) FROM {$config['database']['table_prefix']}usergroups));"); } echo $lang->done . '</p>'; echo $lang->done_step_admincreated; $now = TIME_NOW; $salt = random_str(); $loginkey = generate_loginkey(); $saltedpw = md5(md5($salt) . md5($mybb->get_input('adminpass'))); $newuser = array('username' => $db->escape_string($mybb->get_input('adminuser')), 'password' => $saltedpw, 'salt' => $salt, 'loginkey' => $loginkey, 'email' => $db->escape_string($mybb->get_input('adminemail')), 'usergroup' => $admin_gid, 'regdate' => $now, 'lastactive' => $now, 'lastvisit' => $now, 'website' => '', 'icq' => '', 'aim' => '', 'yahoo' => '', 'skype' => '', 'google' => '', 'birthday' => '', 'signature' => '', 'allownotices' => 1, 'hideemail' => 0, 'subscriptionmethod' => '0', 'receivepms' => 1, 'pmnotice' => 1, 'pmnotify' => 1, 'buddyrequestspm' => 1, 'buddyrequestsauto' => 0, 'showimages' => 1, 'showvideos' => 1, 'showsigs' => 1, 'showavatars' => 1, 'showquickreply' => 1, 'invisible' => 0, 'style' => '0', 'timezone' => 0, 'dst' => 0, 'threadmode' => '', 'daysprune' => 0, 'regip' => $db->escape_binary(my_inet_pton(get_ip())), 'language' => '', 'showcodebuttons' => 1, 'tpp' => 0, 'ppp' => 0, 'referrer' => 0, 'buddylist' => '', 'ignorelist' => '', 'pmfolders' => '', 'notepad' => '', 'showredirect' => 1, 'usernotes' => ''); $db->insert_query('users', $newuser); echo $lang->done . '</p>'; echo $lang->done_step_adminoptions; $adminoptions = file_get_contents(INSTALL_ROOT . 'resources/adminoptions.xml'); $parser = new XMLParser($adminoptions); $parser->collapse_dups = 0; $tree = $parser->get_tree(); $insertmodule = array(); $db->delete_query("adminoptions"); // Insert all the admin permissions foreach ($tree['adminoptions'][0]['user'] as $users) { $uid = $users['attributes']['uid']; foreach ($users['permissions'][0]['module'] as $module) { foreach ($module['permission'] as $permission) { $insertmodule[$module['attributes']['name']][$permission['attributes']['name']] = $permission['value']; } } $defaultviews = array(); foreach ($users['defaultviews'][0]['view'] as $view) { $defaultviews[$view['attributes']['type']] = $view['value']; } $adminoptiondata = array('uid' => (int) $uid, 'cpstyle' => '', 'notes' => '', 'permissions' => $db->escape_string(my_serialize($insertmodule)), 'defaultviews' => $db->escape_string(my_serialize($defaultviews))); $insertmodule = array(); $db->insert_query('adminoptions', $adminoptiondata); } echo $lang->done . '</p>'; // Automatic Login my_unsetcookie("sid"); my_unsetcookie("mybbuser"); my_setcookie('mybbuser', $uid . '_' . $loginkey, null, true); ob_end_flush(); // Make fulltext columns if supported if ($db->supports_fulltext('threads')) { $db->create_fulltext_index('threads', 'subject'); } if ($db->supports_fulltext_boolean('posts')) { $db->create_fulltext_index('posts', 'message'); } echo $lang->done_step_cachebuilding; require_once MYBB_ROOT . 'inc/class_datacache.php'; $cache = new datacache(); $cache->update_version(); $cache->update_attachtypes(); $cache->update_smilies(); $cache->update_badwords(); $cache->update_usergroups(); $cache->update_forumpermissions(); $cache->update_stats(); $cache->update_statistics(); $cache->update_forums(); $cache->update_moderators(); $cache->update_usertitles(); $cache->update_reportedcontent(); $cache->update_awaitingactivation(); $cache->update_mycode(); $cache->update_profilefields(); $cache->update_posticons(); $cache->update_spiders(); $cache->update_bannedips(); $cache->update_banned(); $cache->update_bannedemails(); $cache->update_birthdays(); $cache->update_groupleaders(); $cache->update_threadprefixes(); $cache->update_forumsdisplay(); $cache->update("plugins", array()); $cache->update("internal_settings", array('encryption_key' => random_str(32))); $cache->update_default_theme(); $version_history = array(); $dh = opendir(INSTALL_ROOT . "resources"); while (($file = readdir($dh)) !== false) { if (preg_match("#upgrade([0-9]+).php\$#i", $file, $match)) { $version_history[$match[1]] = $match[1]; } } sort($version_history, SORT_NUMERIC); $cache->update("version_history", $version_history); // Schedule an update check so it occurs an hour ago. Gotta stay up to date! $update['nextrun'] = TIME_NOW - 3600; $db->update_query("tasks", $update, "tid='12'"); $cache->update_update_check(); $cache->update_tasks(); echo $lang->done . '</p>'; echo $lang->done_step_success; $written = 0; if (is_writable('./')) { $lock = @fopen('./lock', 'w'); $written = @fwrite($lock, '1'); @fclose($lock); if ($written) { echo $lang->done_step_locked; } } if (!$written) { echo $lang->done_step_dirdelete; } echo $lang->done_whats_next; $output->print_footer(''); }
} set_config('adminblocks_initialised', 1); } /// Define the unique site ID code if it isn't already set. This getter does that as a side-effect. get_site_identifier(); /// Check if the guest user exists. If not, create one. if (!record_exists("user", "username", "guest")) { if (!($guest = create_guest_record())) { notify("Could not create guest user record !!!"); } } /// Set up the admin user if (empty($CFG->rolesactive)) { build_context_path(); // just in case - should not be needed create_admin_user(); } /// Check for valid admin user - no guest autologin require_login(0, false); $context = get_context_instance(CONTEXT_SYSTEM); require_capability('moodle/site:config', $context); /// check that site is properly customized if (empty($site->shortname)) { // probably new installation - lets return to frontpage after this step // remove settings that we want uninitialised unset_config('registerauth'); redirect('upgradesettings.php?return=site'); } /// Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders if (!empty($id)) { if ($id == $CFG->siteidentifier) {
fclose($h); echo '<p>Created .htaccess file to support the www/local directory</p>'; } } } $mybuf = ob_get_contents(); ob_end_clean(); if (isset($alarm) && $alarm) { echo '<p class="error">Warning: The .htaccess setup for the local version of your www folder may be improperly setup</p>'; } echo $mybuf; } if (admin_user_exists() == false) { $password = create_pass(); $password_hash = sha1($password); $user_id = create_admin_user($password); if ($user_id > 0) { // create the page types demo site if running the first time (i.e. there is no admin user) reason_include_once('function_libraries/admin_actions.php'); reason_include_once('classes/entity_selector.php'); $ptds_id = id_of('page_types_demo_site'); $ptds_entity = new entity($ptds_id); $path = WEB_PATH . trim_slashes($ptds_entity->get_value('base_url')); echo '<h3>Checking for Page Types Demo site</h3>'; if (!is_dir($path)) { echo '<p>Creating demo site</p>'; reason_include_once('classes/url_manager.php'); include_once CARL_UTIL_INC . 'basic/filesystem.php'; mkdir_recursive($path, 0775); if (!is_dir($path)) { die_with_message('<p>The demo site folder at ' . $path . ' could not be written. Check paths and permissions.</p>');
if (!in_array("folder", $tables)) { if (create_table_folder()) { print_msg("Table folder created", "success"); } else { print_msg(mysql_error(), "error"); } } else { print_msg("Table folder exists, checking for version:", "notice"); # check for public field in table upgrade_table("folder", "public", "ALTER TABLE folder ADD COLUMN public ENUM('0','1') DEFAULT 0 NOT NULL"); } # the user table if (!in_array("user", $tables)) { if (create_table_user()) { print_msg("Table user created", "success"); if (create_admin_user()) { print_msg("Admin user created (see below)", "success"); $admin_message = 'Initial user created. Login with username "admin" and password "admin"'; } } else { print_msg(mysql_error(), "error"); } } else { print_msg("Table user exists, checking for version:", "notice"); # check for date_format field in table upgrade_table("user", "date_format", "ALTER TABLE user ADD COLUMN date_format SMALLINT(6) NOT NULL DEFAULT '0' AFTER show_column_date"); # check for show_public field in table upgrade_table("user", "show_public", "ALTER TABLE user ADD COLUMN show_public ENUM('0','1') DEFAULT 1 NOT NULL"); # check for admin field in table upgrade_table("user", "admin", "ALTER TABLE user ADD COLUMN admin ENUM('0','1') DEFAULT 0 NOT NULL AFTER password"); }
if (!isset($adminpassword)) { $adminpassword = $DEFAULT['adminpassword']; } if (!isset($adminemail)) { $adminemail = $DEFAULT['adminemail']; } $user = new object(); $user->auth = 'manual'; $user->firstname = $adminfirstname; //get_string('admin'); $user->lastname = $adminlastname; //get_string('user'); $user->username = $adminusername; //'admin'; $user->password = hash_internal_user_password($adminpassword); // 'admin' $user->email = $adminemail; //'root@localhost'; $user->confirmed = 1; $user->mnethostid = $CFG->mnet_localhost_id; $user->lang = $CFG->lang; $user->maildisplay = 1; $user->timemodified = time(); create_admin_user($user); } if ($verbose > CLI_NO) { print_newline(); console_write('upgradingcompleted'); console_write("\n", '', false); } }
function install_done() { global $output, $db, $mybb, $errors, $cache, $lang; if (empty($mybb->input['adminuser'])) { $errors[] = $lang->admin_step_error_nouser; } if (empty($mybb->input['adminpass'])) { $errors[] = $lang->admin_step_error_nopassword; } if ($mybb->input['adminpass'] != $mybb->input['adminpass2']) { $errors[] = $lang->admin_step_error_nomatch; } if (empty($mybb->input['adminemail'])) { $errors[] = $lang->admin_step_error_noemail; } if (is_array($errors)) { create_admin_user(); } require MYBB_ROOT . 'inc/config.php'; $db = db_connection($config); require MYBB_ROOT . 'inc/settings.php'; $mybb->settings =& $settings; ob_start(); $output->print_header($lang->finish_setup, 'finish'); echo $lang->done_step_usergroupsinserted; // Insert all of our user groups from the XML file $settings = file_get_contents(INSTALL_ROOT . 'resources/usergroups.xml'); $parser = new XMLParser($settings); $parser->collapse_dups = 0; $tree = $parser->get_tree(); $admin_gid = ''; $group_count = 0; foreach ($tree['usergroups'][0]['usergroup'] as $usergroup) { // usergroup[cancp][0][value] $new_group = array(); foreach ($usergroup as $key => $value) { if ($key == "gid" || !is_array($value)) { continue; } $new_group[$key] = $db->escape_string($value[0]['value']); } $return_gid = $db->insert_query("usergroups", $new_group); // If this group can access the admin CP and we haven't established the admin group - set it (just in case we ever change IDs) if ($new_group['cancp'] == 1 && !$admin_gid) { $admin_gid = $return_gid; } $group_count++; } echo $lang->done . '</p>'; echo $lang->done_step_admincreated; $now = TIME_NOW; $salt = random_str(); $loginkey = generate_loginkey(); $saltedpw = md5(md5($salt) . md5($mybb->input['adminpass'])); $newuser = array('username' => $db->escape_string($mybb->input['adminuser']), 'password' => $saltedpw, 'salt' => $salt, 'loginkey' => $loginkey, 'email' => $db->escape_string($mybb->input['adminemail']), 'usergroup' => $admin_gid, 'regdate' => $now, 'lastactive' => $now, 'lastvisit' => $now, 'website' => '', 'icq' => '', 'aim' => '', 'yahoo' => '', 'msn' => '', 'birthday' => '', 'signature' => '', 'allownotices' => 1, 'hideemail' => 0, 'subscriptionmethod' => '0', 'receivepms' => 1, 'pmnotice' => 1, 'pmnotify' => 1, 'remember' => 1, 'showsigs' => 1, 'showavatars' => 1, 'showquickreply' => 1, 'invisible' => 0, 'style' => '0', 'timezone' => 0, 'dst' => 0, 'threadmode' => '', 'daysprune' => 0, 'regip' => $db->escape_string(get_ip()), 'longregip' => intval(ip2long(get_ip())), 'language' => '', 'showcodebuttons' => 1, 'tpp' => 0, 'ppp' => 0, 'referrer' => 0, 'buddylist' => '', 'ignorelist' => '', 'pmfolders' => '', 'notepad' => '', 'showredirect' => 1); $db->insert_query('users', $newuser); echo $lang->done . '</p>'; echo $lang->done_step_adminoptions; $adminoptions = file_get_contents(INSTALL_ROOT . 'resources/adminoptions.xml'); $parser = new XMLParser($adminoptions); $parser->collapse_dups = 0; $tree = $parser->get_tree(); $insertmodule = array(); $db->delete_query("adminoptions"); // Insert all the admin permissions foreach ($tree['adminoptions'][0]['user'] as $users) { $uid = $users['attributes']['uid']; foreach ($users['permissions'][0]['module'] as $module) { foreach ($module['permission'] as $permission) { $insertmodule[$module['attributes']['name']][$permission['attributes']['name']] = $permission['value']; } } $defaultviews = array(); foreach ($users['defaultviews'][0]['view'] as $view) { $defaultviews[$view['attributes']['type']] = $view['value']; } $adminoptiondata = array('uid' => intval($uid), 'cpstyle' => '', 'notes' => '', 'permissions' => $db->escape_string(serialize($insertmodule)), 'defaultviews' => $db->escape_string(serialize($defaultviews))); $insertmodule = array(); $db->insert_query('adminoptions', $adminoptiondata); } echo $lang->done . '</p>'; // Automatic Login my_unsetcookie("sid"); my_unsetcookie("mybbuser"); my_setcookie('mybbuser', $uid . '_' . $loginkey, null, true); ob_end_flush(); // Make fulltext columns if supported if ($db->supports_fulltext('threads')) { $db->create_fulltext_index('threads', 'subject'); } if ($db->supports_fulltext_boolean('posts')) { $db->create_fulltext_index('posts', 'message'); } // Register a shutdown function which actually tests if this functionality is working add_shutdown('test_shutdown_function'); echo $lang->done_step_cachebuilding; require_once MYBB_ROOT . 'inc/class_datacache.php'; $cache = new datacache(); $cache->update_version(); $cache->update_attachtypes(); $cache->update_smilies(); $cache->update_badwords(); $cache->update_usergroups(); $cache->update_forumpermissions(); $cache->update_stats(); $cache->update_forums(); $cache->update_moderators(); $cache->update_usertitles(); $cache->update_reportedposts(); $cache->update_mycode(); $cache->update_posticons(); $cache->update_update_check(); $cache->update_tasks(); $cache->update_spiders(); $cache->update_bannedips(); $cache->update_banned(); $cache->update_birthdays(); $cache->update("plugins", array()); $cache->update("internal_settings", array('encryption_key' => random_str(32))); echo $lang->done . '</p>'; echo $lang->done_step_success; $written = 0; if (is_writable('./')) { $lock = @fopen('./lock', 'w'); $written = @fwrite($lock, '1'); @fclose($lock); if ($written) { echo $lang->done_step_locked; } } if (!$written) { echo $lang->done_step_dirdelete; } echo $lang->done_subscribe_mailing; $output->print_footer(''); }