/** * Step #7 - Default User Setup... * */ function step_7($data = null) { if ($data['response']) { array_map('trim', $data['htmldata']); $errors = array(); if (empty($data['htmldata']['username'])) { $errors['username'] = $this->phrase['install']['error_username']; } if (empty($data['htmldata']['email']) or !is_valid_email($data['htmldata']['email'])) { $errors['email'] = $this->phrase['install']['error_email']; } if (empty($data['htmldata']['password']) or empty($data['htmldata']['confirmpassword'])) { if (empty($data['htmldata']['password'])) { $errors['password'] = $this->phrase['install']['error_password']; } else { if (empty($data['htmldata']['confirmpassword'])) { $errors['confirmpassword'] = $this->phrase['install']['error_confirmpassword']; } } } else { if ($data['htmldata']['password'] != $data['htmldata']['confirmpassword']) { $errors['mismatch'] = $this->phrase['install']['error_password_not_match']; } else { if ($data['htmldata']['password'] == $data['htmldata']['username'] and !defined('ALLOW_SAME_USERNAME_PASSWORD')) { $errors['samepasswordasusername'] = $this->phrase['install']['error_same_password_as_username']; } } } // check if a user already exists. If so, DO NOT CREATE A NEW USER. $vbexists = $this->fetch_vbexists(); if (!$vbexists) { $errors[] = $this->phrase['install']['user_table_missing']; // we can't create a user without a user table. } else { // assuming if user table exists, userid will exist. If a user exists, DO NOT CREATE A NEW USER if ($this->db->query_first("SELECT userid FROM " . trim($this->registry->config['Database']['tableprefix']) . "user LIMIT 1")) { $errors[] = $this->phrase['install']['user_already_exists']; } } if (empty($errors)) { require_once DIR . '/includes/class_bitfield_builder.php'; vB_Bitfield_Builder::save($this->db); $admin_defaults = array('vbasset_enable', 'showsignatures', 'showavatars', 'showimages', 'adminemail', 'dstauto', 'receivepm', 'showusercss', 'receivefriendemailrequest', 'vm_enable'); $admin_useroption = 0; foreach ($admin_defaults as $bitfield) { $admin_useroption |= $this->registry->bf_misc_useroptions["{$bitfield}"]; } require_once DIR . '/includes/functions_user.php'; //for now we'll just include these to get the define for the salt length. Should investigate //using the DM to add the initial admin user, but there may be issues with doing that without //a proper user session (which we can't have until we require the user. require_once DIR . '/includes/class_dm.php'; require_once DIR . '/includes/class_dm_user.php'; $salt = fetch_user_salt(SALT_LENGTH); /*insert query*/ $this->db->query_write("\n\t\t\t\t\tINSERT INTO " . TABLE_PREFIX . "user\n\t\t\t\t\t\t(username, salt, password, email, usertitle, joindate, lastvisit, lastactivity, usergroupid, passworddate, options, showvbcode)\n\t\t\t\t\tVALUES (\n\t\t\t\t\t\t'" . $this->db->escape_string(htmlspecialchars_uni($data['htmldata']['username'])) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($salt) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string(md5(md5($data['htmldata']['password']) . $salt)) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($data['htmldata']['email']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($this->phrase['install']['usergroup_admin_usertitle']) . "',\n\t\t\t\t\t\t" . TIMENOW . ",\n\t\t\t\t\t\t" . TIMENOW . ",\n\t\t\t\t\t\t" . TIMENOW . ",\n\t\t\t\t\t\t6,\n\t\t\t\t\t\tFROM_UNIXTIME(" . TIMENOW . "),\n\t\t\t\t\t\t{$admin_useroption},\n\t\t\t\t\t\t2\n\t\t\t\t\t)\n\t\t\t\t"); $userid = $this->db->insert_id(); /*insert query*/ $this->db->query_write("\n\t\t\t\t\tINSERT INTO " . TABLE_PREFIX . "usertextfield\n\t\t\t\t\t\t(userid)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t({$userid})\n\t\t\t\t"); /*insert query*/ $this->db->query_write("\n\t\t\t\t\tINSERT INTO " . TABLE_PREFIX . "userfield\n\t\t\t\t\t\t(userid)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t({$userid})\n\t\t\t\t"); /*insert query*/ $this->db->query_write("INSERT INTO " . TABLE_PREFIX . "administrator\n\t\t\t\t\t(userid, adminpermissions)\n\t\t\t\tVALUES\n\t\t\t\t\t({$userid}, " . (array_sum($this->registry->bf_ugp_adminpermissions) - 3) . ")\n\t\t\t\t"); /*insert query*/ $this->db->query_write("INSERT INTO " . TABLE_PREFIX . "moderator\n\t\t\t\t\t(userid, forumid, permissions, permissions2)\n\t\t\t\tVALUES\n\t\t\t\t\t(\n\t\t\t\t\t\t{$userid},\n\t\t\t\t\t\t-1,\n\t\t\t\t\t\t" . (array_sum($this->registry->bf_misc_moderatorpermissions) - ($this->registry->bf_misc_moderatorpermissions['newthreademail'] + $this->registry->bf_misc_moderatorpermissions['newpostemail'])) . ",\n\t\t\t\t\t\t" . array_sum($this->registry->bf_misc_moderatorpermissions2) . "\n\t\t\t\t\t)\n\t\t\t\t"); build_image_cache('smilie'); build_image_cache('avatar'); build_image_cache('icon'); build_bbcode_cache(); require_once DIR . '/includes/functions_databuild.php'; build_user_statistics(); require_once DIR . '/includes/adminfunctions_forums.php'; build_forum_child_lists(); build_forum_permissions(); require_once DIR . '/includes/functions_cron.php'; build_cron_next_run(); require_once DIR . '/includes/adminfunctions_attachment.php'; build_attachment_permissions(); require_once DIR . '/includes/class_block.php'; $blockmanager = vB_BlockManager::create($this->registry); $blockmanager->reloadBlockTypes(); $this->show_message($this->phrase['install']['administrator_account_created']); return; } else { foreach ($errors as $key => $value) { $errors["{$key}"] = '<span class="usererror">' . $value . '</span>'; } } } else { $data['htmldata'] = array(); } $html = '<table cellspacing="0" cellpadding="4" border="0" align="center" width="100%" id="cpform_table" class="" style="border-collapse: separate;"> <tbody> <tr valign="top"> <td class="alt1">' . $this->phrase['install']['username'] . $errors['username'] . ' <span id="htmldata[username]_error" class="usererror hidden">' . $this->phrase['install']['field_required'] . '</span> </td> <td class="alt1"> <div id="ctrl_username"> <input type="text" tabindex="1" dir="ltr" size="35" value="' . htmlspecialchars_uni($data['htmldata']['username']) . '" id="it_username_1" name="htmldata[username]" class="bginput" vbrequire="1" /> </div> </td> </tr> <tr valign="top"> <td class="alt2">' . $this->phrase['install']['password'] . $errors['password'] . $errors['mismatch'] . $errors['samepasswordasusername'] . ' <span id="htmldata[password]_error" class="usererror hidden">' . $this->phrase['install']['field_required'] . '</span> </td> <td class="alt2"> <div id="ctrl_password"> <input type="password" tabindex="1" size="35" value="' . htmlspecialchars_uni($data['htmldata']['password']) . '" name="htmldata[password]" class="bginput" vbrequire="1" /> </div> </td> </tr> <tr valign="top"> <td class="alt1">' . $this->phrase['install']['confirm_password'] . $errors['confirmpassword'] . $errors['mismatch'] . ' <span id="htmldata[confirmpassword]_error" class="usererror hidden">' . $this->phrase['install']['field_required'] . '</span> </td> <td class="alt1"> <div id="ctrl_confirmpassword"> <input type="password" tabindex="1" size="35" value="' . htmlspecialchars_uni($data['htmldata']['confirmpassword']) . '" name="htmldata[confirmpassword]" class="bginput" vbrequire="1" /> </div> </td> </tr> <tr valign="top"> <td class="alt2">' . $this->phrase['install']['email_address'] . $errors['email'] . ' <span id="htmldata[email]_error" class="usererror hidden">' . $this->phrase['install']['field_required'] . '</span> </td> <td class="alt2"> <div id="ctrl_email"> <input type="text" tabindex="1" dir="ltr" size="35" value="' . htmlspecialchars_uni($data['htmldata']['email']) . '" id="it_email_2" name="htmldata[email]" class="bginput" vbrequire="1" /> </div> </td> </tr> </tbody></table>'; return array('html' => $html, 'width' => '640px', 'hidecancel' => true, 'title' => $this->phrase['install']['administrator_account_setup'], 'reset' => true); }
$admin_defaults = array('vbasset_enable', 'showsignatures', 'showavatars', 'showimages', 'adminemail', 'dstauto' , 'receivepm', 'showusercss', 'receivefriendemailrequest', 'vm_enable'); $admin_useroption = 0; foreach ($admin_defaults AS $bitfield) { $admin_useroption |= $vbulletin->bf_misc_useroptions["$bitfield"]; } require_once(DIR . '/includes/functions_user.php'); //for now we'll just include these to get the define for the salt length. Should investigate //using the DM to add the initial admin user, but there may be issues with doing that without //a proper user session (which we can't have until we require the user. require_once(DIR . '/includes/class_dm.php'); require_once(DIR . '/includes/class_dm_user.php'); $salt = fetch_user_salt(SALT_LENGTH); /*insert query*/ $db->query_write(" INSERT INTO " . TABLE_PREFIX . "user (username, salt, password, email, usertitle, joindate, lastvisit, lastactivity, usergroupid, passworddate, options, showvbcode) VALUES ( '" . $db->escape_string(htmlspecialchars_uni($vbulletin->GPC['username'])) . "', '" . $db->escape_string($salt) . "', '" . $db->escape_string(md5(md5($vbulletin->GPC['password']) . $salt)) . "', '" . $db->escape_string($vbulletin->GPC['email']) . "', '" . $db->escape_string($install_phrases['usergroup_admin_usertitle']) . "', " . TIMENOW . ", " . TIMENOW . ", " . TIMENOW . ", 6, FROM_UNIXTIME(" . TIMENOW . "),
// ############################################################################# // Upgrade pmfolders, pmtotals and insert usertextfield entries if ($vbulletin->GPC['step'] == 7) { $vbulletin->GPC['perpage'] = 1000; $maxuser = $db->query_first("SELECT MAX(userid) AS userid FROM user"); echo_flush("<p>" . sprintf($upgrade_phrases['upgrade_300b3.php']['upgrading_users_x'], construct_upgrade_page_hint($maxuser['userid'], $vbulletin->GPC['startat'], $vbulletin->GPC['perpage'])) . "<br />\n"); if ($vbulletin->GPC['startat'] <= $maxuser['userid']) { $endat = $vbulletin->GPC['startat'] + $vbulletin->GPC['perpage']; // Copy the textfields from the user table to the new table then remove them $users = $db->query_read("\n\t\t\tSELECT\n\t\t\t\tuser.userid, user.username, user.pmfolders, user.buddylist, user.ignorelist,\n\t\t\t\tuser.signature, user.password, user.usergroupid,\n\t\t\t\tCOUNT(pmid) AS pmtotal,\n\t\t\t\tSUM(IF(messageread = 0, 1, 0)) AS pmunread\n\t\t\tFROM user\n\t\t\tLEFT JOIN pm USING(userid)\n\t\t\tWHERE user.userid > {$vbulletin->GPC['startat']}\n\t\t\tAND user.userid <= {$endat}\n\t\t\tGROUP BY user.userid\n\t\t"); $batchnum = $db->num_rows($users); echo_flush(sprintf($upgrade_phrases['upgrade_300b3.php']['found_x_users'], $batchnum) . "</p>\n"); $sql = array(); require_once DIR . '/includes/functions_user.php'; while ($user = $db->fetch_array($users)) { $salt = fetch_user_salt(3); // update user table with new private message totals fields and salted password - only salt passwords for non-admins $query[] = "\n\t\t\t\tUPDATE user SET\n\t\t\t\t\tsalt = '" . $db->escape_string($salt) . "',\n\t\t\t\t\t" . iif($user['usergroupid'] != 6, "password = '******'password'] . $salt)) . "',") . "\n\t\t\t\t\tpmtotal = {$user['pmtotal']},\n\t\t\t\t\tpmunread = {$user['pmunread']}\n\t\t\t\tWHERE userid = {$user['userid']}\n\t\t\t"; $explain[] = sprintf($upgrade_phrases['upgrade_300b3.php']['updating_priv_messages_for_x'], $user['username']); // work out the new pmfolders format $user['pmfolders'] = trim($user['pmfolders']); $pmfolders = array(); if ($user['pmfolders'] != '') { foreach (explode("\n", $user['pmfolders']) as $folderbits) { $folderbits = explode('|||', $folderbits); $pmfolders[intval($folderbits[0] + 1)] = $folderbits[1]; } } // add to sql $sql[] = "({$user['userid']}, '" . iif(empty($pmfolders), '', $db->escape_string(serialize($pmfolders))) . "', '" . $db->escape_string($user['ignorelist']) . "', '" . $db->escape_string($user['buddylist']) . "', '" . $db->escape_string($user['signature']) . "')"; }