123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170 |
- <?php
- if (!defined('SMF'))
- die('Hacking attempt...');
- function validateSession($type = 'admin')
- {
- global $modSettings, $sourcedir, $user_info, $sc, $user_settings;
-
- is_not_guest();
-
- $types = array();
- call_integration_hook('integrate_validateSession', array($types));
- $type = in_array($type, $types) || $type == 'moderate' ? $type : 'admin';
-
- $refreshTime = isset($_GET['xml']) ? 4200 : 3600;
-
- if (!empty($modSettings['securityDisable' . $type != 'admin' ? '_' . $type : '']) || (!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()))
- return;
- require_once($sourcedir . '/Subs-Auth.php');
-
- if (isset($_POST[$type . '_hash_pass']) && strlen($_POST[$type . '_hash_pass']) == 40)
- {
- checkSession();
- $good_password = in_array(true, call_integration_hook('integrate_verify_password', array($user_info['username'], $_POST[$type . '_hash_pass'], true)), true);
- if ($good_password || $_POST[$type . '_hash_pass'] == sha1($user_info['passwd'] . $sc))
- {
- $_SESSION[$type . '_time'] = time();
- return;
- }
- }
-
- if (isset($_POST[$type. '_pass']))
- {
- checkSession();
- $good_password = in_array(true, call_integration_hook('integrate_verify_password', array($user_info['username'], $_POST[$type . '_pass'], false)), true);
-
- if ($good_password || sha1(strtolower($user_info['username']) . $_POST[$type . '_pass']) == $user_info['passwd'])
- {
- $_SESSION[$type . '_time'] = time();
- return;
- }
- }
-
- if (!empty($user_settings['openid_uri']))
- {
- require_once($sourcedir . '/Subs-OpenID.php');
- smf_openID_revalidate();
- $_SESSION[$type . '_time'] = time();
- return;
- }
-
- adminLogin($type);
- }
- function is_not_guest($message = '')
- {
- global $user_info, $txt, $context, $scripturl;
-
- if (!$user_info['is_guest'])
- return;
-
- $_GET['action'] = '';
- $_GET['board'] = '';
- $_GET['topic'] = '';
- writeLog(true);
-
- if (isset($_REQUEST['xml']))
- obExit(false);
-
- if (!WIRELESS && SMF != 'SSI' && empty($context['theme_loaded']))
- loadTheme();
-
- if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
- $_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
-
- loadLanguage('Login');
-
- if (WIRELESS)
- {
- $context['login_error'] = $message ? $message : $txt['only_members_can_access'];
- $context['sub_template'] = WIRELESS_PROTOCOL . '_login';
- }
-
- elseif (empty($context['template_layers']))
- {
- $_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING'];
- redirectexit('action=login');
- }
- else
- {
- loadTemplate('Login');
- $context['sub_template'] = 'kick_guest';
- $context['robot_no_index'] = true;
- }
-
- $context['kick_message'] = $message;
- $context['page_title'] = $txt['login'];
- obExit();
-
- trigger_error('Hacking attempt...', E_USER_ERROR);
- }
- function is_not_banned($forceCheck = false)
- {
- global $txt, $modSettings, $context, $user_info;
- global $sourcedir, $cookiename, $user_settings, $smcFunc;
-
- if ($user_info['is_admin'])
- return;
-
- if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']))
- {
-
- $_SESSION['ban'] = array(
- 'last_checked' => time(),
- 'id_member' => $user_info['id'],
- 'ip' => $user_info['ip'],
- 'ip2' => $user_info['ip2'],
- 'email' => $user_info['email'],
- );
- $ban_query = array();
- $ban_query_vars = array('current_time' => time());
- $flag_is_activated = false;
-
- foreach (array('ip', 'ip2') as $ip_number)
- {
-
- if (strpos($user_info[$ip_number], ':') !== false)
- {
- if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
- continue;
- $ip_parts = array_map('hexdec', explode(':', expandIPv6($user_info[$ip_number])));
- $ban_query[] = '((' . $ip_parts[0] . ' BETWEEN bi.ip_low1 AND bi.ip_high1)
- AND (' . $ip_parts[1] . ' BETWEEN bi.ip_low2 AND bi.ip_high2)
- AND (' . $ip_parts[2] . ' BETWEEN bi.ip_low3 AND bi.ip_high3)
- AND (' . $ip_parts[3] . ' BETWEEN bi.ip_low4 AND bi.ip_high4)
- AND (' . $ip_parts[4] . ' BETWEEN bi.ip_low5 AND bi.ip_high5)
- AND (' . $ip_parts[5] . ' BETWEEN bi.ip_low6 AND bi.ip_high6)
- AND (' . $ip_parts[6] . ' BETWEEN bi.ip_low7 AND bi.ip_high7)
- AND (' . $ip_parts[7] . ' BETWEEN bi.ip_low8 AND bi.ip_high8))';
-
- if (empty($modSettings['disableHostnameLookup']))
- {
- $hostname = host_from_ip($user_info[$ip_number]);
- if (strlen($hostname) > 0)
- {
- $ban_query[] = '({string:hostname} LIKE bi.hostname)';
- $ban_query_vars['hostname'] = $hostname;
- }
- }
- }
-
- elseif (preg_match('/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/', $user_info[$ip_number], $ip_parts) == 1)
- {
- $ban_query[] = '((' . $ip_parts[1] . ' BETWEEN bi.ip_low1 AND bi.ip_high1)
- AND (' . $ip_parts[2] . ' BETWEEN bi.ip_low2 AND bi.ip_high2)
- AND (' . $ip_parts[3] . ' BETWEEN bi.ip_low3 AND bi.ip_high3)
- AND (' . $ip_parts[4] . ' BETWEEN bi.ip_low4 AND bi.ip_high4))';
-
- if (empty($modSettings['disableHostnameLookup']))
- {
- $hostname = host_from_ip($user_info[$ip_number]);
- if (strlen($hostname) > 0)
- {
- $ban_query[] = '({string:hostname} LIKE bi.hostname)';
- $ban_query_vars['hostname'] = $hostname;
- }
- }
- }
-
- elseif ($user_info['ip'] == 'unknown')
- $ban_query[] = '(bi.ip_low1 = 255 AND bi.ip_high1 = 255
- AND bi.ip_low2 = 255 AND bi.ip_high2 = 255
- AND bi.ip_low3 = 255 AND bi.ip_high3 = 255
- AND bi.ip_low4 = 255 AND bi.ip_high4 = 255)';
- }
-
- if (strlen($user_info['email']) != 0)
- {
- $ban_query[] = '({string:email} LIKE bi.email_address)';
- $ban_query_vars['email'] = $user_info['email'];
- }
-
- if (!$user_info['is_guest'] && !empty($user_info['id']))
- {
- $ban_query[] = 'bi.id_member = {int:id_member}';
- $ban_query_vars['id_member'] = $user_info['id'];
- }
-
- if (!empty($ban_query))
- {
- $restrictions = array(
- 'cannot_access',
- 'cannot_login',
- 'cannot_post',
- 'cannot_register',
- );
- $request = $smcFunc['db_query']('', '
- SELECT bi.id_ban, bi.email_address, bi.id_member, bg.cannot_access, bg.cannot_register,
- bg.cannot_post, bg.cannot_login, bg.reason, IFNULL(bg.expire_time, 0) AS expire_time
- FROM {db_prefix}ban_items AS bi
- INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:current_time}))
- WHERE
- (' . implode(' OR ', $ban_query) . ')',
- $ban_query_vars
- );
-
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- foreach ($restrictions as $restriction)
- if (!empty($row[$restriction]))
- {
- $_SESSION['ban'][$restriction]['reason'] = $row['reason'];
- $_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
- if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])))
- $_SESSION['ban']['expire_time'] = $row['expire_time'];
- if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email']))
- $flag_is_activated = true;
- }
- }
- $smcFunc['db_free_result']($request);
- }
-
- if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login']))
- log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
-
- if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated)
- || ($user_settings['is_activated'] < 10 && $flag_is_activated)))
- {
- require_once($sourcedir . '/ManageBans.php');
- updateBanMembers();
- }
- }
-
- if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_']))
- {
- $bans = explode(',', $_COOKIE[$cookiename . '_']);
- foreach ($bans as $key => $value)
- $bans[$key] = (int) $value;
- $request = $smcFunc['db_query']('', '
- SELECT bi.id_ban, bg.reason
- FROM {db_prefix}ban_items AS bi
- INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group)
- WHERE bi.id_ban IN ({array_int:ban_list})
- AND (bg.expire_time IS NULL OR bg.expire_time > {int:current_time})
- AND bg.cannot_access = {int:cannot_access}
- LIMIT ' . count($bans),
- array(
- 'cannot_access' => 1,
- 'ban_list' => $bans,
- 'current_time' => time(),
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- $_SESSION['ban']['cannot_access']['ids'][] = $row['id_ban'];
- $_SESSION['ban']['cannot_access']['reason'] = $row['reason'];
- }
- $smcFunc['db_free_result']($request);
-
- if (!isset($_SESSION['ban']['cannot_access']))
- {
- require_once($sourcedir . '/Subs-Auth.php');
- $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
- smf_setcookie($modSettings['cookie_name'] . '_', '', time() - 3600, $cookie_url[1], $cookie_url[0], false, false);
- }
- }
-
- if (isset($_SESSION['ban']['cannot_access']))
- {
-
- if (!$user_info['is_guest'])
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}log_online
- WHERE id_member = {int:current_member}',
- array(
- 'current_member' => $user_info['id'],
- )
- );
-
- $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
- $user_info['name'] = '';
- $user_info['username'] = '';
- $user_info['is_guest'] = true;
- $user_info['is_admin'] = false;
- $user_info['permissions'] = array();
- $user_info['id'] = 0;
- $context['user'] = array(
- 'id' => 0,
- 'username' => '',
- 'name' => $txt['guest_title'],
- 'is_guest' => true,
- 'is_logged' => false,
- 'is_admin' => false,
- 'is_mod' => false,
- 'can_mod' => false,
- 'language' => $user_info['language'],
- );
-
- require_once($sourcedir . '/Subs-Auth.php');
- $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
- smf_setcookie($modSettings['cookie_name'] . '_', implode(',', $_SESSION['ban']['cannot_access']['ids']), time() + 3153600, $cookie_url[1], $cookie_url[0], false, false);
-
- $_GET['action'] = '';
- $_GET['board'] = '';
- $_GET['topic'] = '';
- writeLog(true);
-
- fatal_error(sprintf($txt['your_ban'], $old_name) . (empty($_SESSION['ban']['cannot_access']['reason']) ? '' : '<br />' . $_SESSION['ban']['cannot_access']['reason']) . '<br />' . (!empty($_SESSION['ban']['expire_time']) ? sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)) : $txt['your_ban_expires_never']), 'user');
-
- trigger_error('Hacking attempt...', E_USER_ERROR);
- }
-
- elseif (isset($_SESSION['ban']['cannot_login']) && !$user_info['is_guest'])
- {
-
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}log_online
- WHERE id_member = {int:current_member}',
- array(
- 'current_member' => $user_info['id'],
- )
- );
-
- $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
- $user_info['name'] = '';
- $user_info['username'] = '';
- $user_info['is_guest'] = true;
- $user_info['is_admin'] = false;
- $user_info['permissions'] = array();
- $user_info['id'] = 0;
- $context['user'] = array(
- 'id' => 0,
- 'username' => '',
- 'name' => $txt['guest_title'],
- 'is_guest' => true,
- 'is_logged' => false,
- 'is_admin' => false,
- 'is_mod' => false,
- 'can_mod' => false,
- 'language' => $user_info['language'],
- );
-
- $_GET['action'] = '';
- $_GET['board'] = '';
- $_GET['topic'] = '';
- writeLog(true);
- require_once($sourcedir . '/LogInOut.php');
- Logout(true, false);
- fatal_error(sprintf($txt['your_ban'], $old_name) . (empty($_SESSION['ban']['cannot_login']['reason']) ? '' : '<br />' . $_SESSION['ban']['cannot_login']['reason']) . '<br />' . (!empty($_SESSION['ban']['expire_time']) ? sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)) : $txt['your_ban_expires_never']) . '<br />' . $txt['ban_continue_browse'], 'user');
- }
-
- if (isset($user_info['permissions']))
- banPermissions();
- }
- function banPermissions()
- {
- global $user_info, $sourcedir, $modSettings, $context;
-
- if (isset($_SESSION['ban']['cannot_access']))
- $user_info['permissions'] = array();
-
- elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
- {
- $denied_permissions = array(
- 'pm_send',
- 'calendar_post', 'calendar_edit_own', 'calendar_edit_any',
- 'poll_post',
- 'poll_add_own', 'poll_add_any',
- 'poll_edit_own', 'poll_edit_any',
- 'poll_lock_own', 'poll_lock_any',
- 'poll_remove_own', 'poll_remove_any',
- 'manage_attachments', 'manage_smileys', 'manage_boards', 'admin_forum', 'manage_permissions',
- 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news',
- 'profile_identity_any', 'profile_extra_any', 'profile_title_any',
- 'post_new', 'post_reply_own', 'post_reply_any',
- 'delete_own', 'delete_any', 'delete_replies',
- 'make_sticky',
- 'merge_any', 'split_any',
- 'modify_own', 'modify_any', 'modify_replies',
- 'move_any',
- 'send_topic',
- 'lock_own', 'lock_any',
- 'remove_own', 'remove_any',
- 'post_unapproved_topics', 'post_unapproved_replies_own', 'post_unapproved_replies_any',
- );
- $user_info['permissions'] = array_diff($user_info['permissions'], $denied_permissions);
- }
-
- elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $user_info['warning'])
- {
-
- $permission_change = array(
- 'post_new' => 'post_unapproved_topics',
- 'post_reply_own' => 'post_unapproved_replies_own',
- 'post_reply_any' => 'post_unapproved_replies_any',
- 'post_attachment' => 'post_unapproved_attachments',
- );
- foreach ($permission_change as $old => $new)
- {
- if (!in_array($old, $user_info['permissions']))
- unset($permission_change[$old]);
- else
- $user_info['permissions'][] = $new;
- }
- $user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
- }
-
-
- if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
- $user_info['mod_cache'] = $_SESSION['mc'];
- else
- {
- require_once($sourcedir . '/Subs-Auth.php');
- rebuildModCache();
- }
-
- if (isset($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id'])
- $context['open_mod_reports'] = $_SESSION['rc']['reports'];
- elseif ($_SESSION['mc']['bq'] != '0=1')
- {
- require_once($sourcedir . '/ModerationCenter.php');
- recountOpenReports();
- }
- else
- $context['open_mod_reports'] = 0;
- }
- function log_ban($ban_ids = array(), $email = null)
- {
- global $user_info, $smcFunc;
-
- if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
- return;
- $smcFunc['db_insert']('',
- '{db_prefix}log_banned',
- array('id_member' => 'int', 'ip' => 'string-16', 'email' => 'string', 'log_time' => 'int'),
- array($user_info['id'], $user_info['ip'], ($email === null ? ($user_info['is_guest'] ? '' : $user_info['email']) : $email), time()),
- array('id_ban_log')
- );
-
- if (!empty($ban_ids))
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}ban_items
- SET hits = hits + 1
- WHERE id_ban IN ({array_int:ban_ids})',
- array(
- 'ban_ids' => $ban_ids,
- )
- );
- }
- function isBannedEmail($email, $restriction, $error)
- {
- global $txt, $smcFunc;
-
- if (empty($email) || trim($email) == '')
- return;
-
- $ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
- $ban_reason = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['reason'] : '';
-
- $request = $smcFunc['db_query']('', '
- SELECT bi.id_ban, bg.' . $restriction . ', bg.cannot_access, bg.reason
- FROM {db_prefix}ban_items AS bi
- INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group)
- WHERE {string:email} LIKE bi.email_address
- AND (bg.' . $restriction . ' = {int:cannot_access} OR bg.cannot_access = {int:cannot_access})
- AND (bg.expire_time IS NULL OR bg.expire_time >= {int:now})',
- array(
- 'email' => $email,
- 'cannot_access' => 1,
- 'now' => time(),
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- if (!empty($row['cannot_access']))
- {
- $_SESSION['ban']['cannot_access']['ids'][] = $row['id_ban'];
- $_SESSION['ban']['cannot_access']['reason'] = $row['reason'];
- }
- if (!empty($row[$restriction]))
- {
- $ban_ids[] = $row['id_ban'];
- $ban_reason = $row['reason'];
- }
- }
- $smcFunc['db_free_result']($request);
-
- if (isset($_SESSION['ban']['cannot_access']))
- {
- log_ban($_SESSION['ban']['cannot_access']['ids']);
- $_SESSION['ban']['last_checked'] = time();
- fatal_error(sprintf($txt['your_ban'], $txt['guest_title']) . $_SESSION['ban']['cannot_access']['reason'], false);
- }
- if (!empty($ban_ids))
- {
-
- log_ban($ban_ids, $email);
- fatal_error($error . $ban_reason, false);
- }
- }
- function checkSession($type = 'post', $from_action = '', $is_fatal = true)
- {
- global $sc, $modSettings, $boardurl;
-
- if ($type == 'post')
- {
- $check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
- if ($check !== $sc)
- $error = 'session_timeout';
- }
-
- elseif ($type == 'get')
- {
- $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
- if ($check !== $sc)
- $error = 'session_verify_fail';
- }
-
- elseif ($type == 'request')
- {
- $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null)));
- if ($check !== $sc)
- $error = 'session_verify_fail';
- }
-
- if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
- $error = 'session_verify_fail';
-
- if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
- {
- ob_end_clean();
- header('HTTP/1.1 403 Forbidden');
- die;
- }
-
- $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
- if (!empty($referrer['host']))
- {
- if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
- $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
- else
- $real_host = $_SERVER['HTTP_HOST'];
- $parsed_url = parse_url($boardurl);
-
- if (!empty($modSettings['globalCookies']))
- {
- if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
- $parsed_url['host'] = $parts[1];
- if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
- $referrer['host'] = $parts[1];
- if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
- $real_host = $parts[1];
- }
-
- if (isset($parsed_url['host']) && strtolower($referrer['host']) != strtolower($parsed_url['host']) && strtolower($referrer['host']) != strtolower($real_host))
- {
- $error = 'verify_url_fail';
- $log_error = true;
- }
- }
-
- if (!empty($from_action) && (!isset($_SESSION['old_url']) || preg_match('~[?;&]action=' . $from_action . '([;&]|$)~', $_SESSION['old_url']) == 0))
- {
- $error = 'verify_url_fail';
- $log_error = true;
- }
- if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
- fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false);
-
- if (!isset($error))
- return '';
-
- elseif ($is_fatal)
- {
- if (isset($_GET['xml']))
- {
- ob_end_clean();
- header('HTTP/1.1 403 Forbidden - Session timeout');
- die;
- }
- else
- fatal_lang_error($error, isset($log_error) ? 'user' : false);
- }
-
- else
- return $error;
-
- trigger_error('Hacking attempt...', E_USER_ERROR);
- }
- function checkConfirm($action)
- {
- global $modSettings;
- if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
- return true;
- else
- {
- $token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
- $_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
- return $token;
- }
- }
- function createToken($action, $type = 'post')
- {
- global $modSettings, $context;
- $token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed'] . $type);
- $token_var = substr(preg_replace('~^\d+~', '', md5(mt_rand() . (string) microtime() . mt_rand())), 0, rand(7, 12));
- $_SESSION['token'][$type . '-' . $action] = array($token_var, md5($token . $_SERVER['HTTP_USER_AGENT']), time(), $token);
- $context[$action . '_token'] = $token;
- $context[$action . '_token_var'] = $token_var;
- return array($token_var, $token);
- }
- function validateToken($action, $type = 'post', $reset = true)
- {
- global $modSettings;
- $type = $type == 'get' || $type == 'request' ? $type : 'post';
-
-
- if (isset($_SESSION['token'][$type . '-' . $action], $GLOBALS['_' . strtoupper($type)][$_SESSION['token'][$type . '-' . $action][0]]) && md5($GLOBALS['_' . strtoupper($type)][$_SESSION['token'][$type . '-' . $action][0]] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['token'][$type . '-' . $action][1])
- {
-
- unset($_SESSION['token'][$type . '-' . $action]);
- return true;
- }
-
- if ($reset)
- {
-
- cleanTokens();
-
- createToken($action, $type);
- fatal_lang_error('token_verify_fail', false);
- }
-
- else
- unset($_SESSION['token'][$type . '-' . $action]);
-
- if (mt_rand(0, 138) == 23)
- cleanTokens();
- return false;
- }
- function cleanTokens($complete = false)
- {
-
- if (!isset($_SESSION['token']))
- return;
-
- foreach ($_SESSION['token'] as $key => $data)
- if ($data[2] + 10800 < time() || $complete)
- unset($_SESSION['token'][$key]);
- }
- function checkSubmitOnce($action, $is_fatal = true)
- {
- global $context;
- if (!isset($_SESSION['forms']))
- $_SESSION['forms'] = array();
-
- if ($action == 'register')
- {
- $context['form_sequence_number'] = 0;
- while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
- $context['form_sequence_number'] = mt_rand(1, 16000000);
- }
-
- elseif ($action == 'check')
- {
- if (!isset($_REQUEST['seqnum']))
- return true;
- elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
- {
- $_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
- return true;
- }
- elseif ($is_fatal)
- fatal_lang_error('error_form_already_submitted', false);
- else
- return false;
- }
-
- elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
- $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
- elseif ($action != 'free')
- trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
- }
- function allowedTo($permission, $boards = null)
- {
- global $user_info, $modSettings, $smcFunc;
-
- if (empty($permission))
- return true;
-
- if (empty($user_info))
- return false;
-
- if ($user_info['is_admin'])
- return true;
-
- if ($boards === null)
- {
-
- if (!is_array($permission) && in_array($permission, $user_info['permissions']))
- return true;
-
- elseif (is_array($permission) && count(array_intersect($permission, $user_info['permissions'])) != 0)
- return true;
-
- else
- return false;
- }
- elseif (!is_array($boards))
- $boards = array($boards);
- $request = $smcFunc['db_query']('', '
- SELECT MIN(bp.add_deny) AS add_deny
- FROM {db_prefix}boards AS b
- INNER JOIN {db_prefix}board_permissions AS bp ON (bp.id_profile = b.id_profile)
- LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
- WHERE b.id_board IN ({array_int:board_list})
- AND bp.id_group IN ({array_int:group_list}, {int:moderator_group})
- AND bp.permission {raw:permission_list}
- AND (mods.id_member IS NOT NULL OR bp.id_group != {int:moderator_group})
- GROUP BY b.id_board',
- array(
- 'current_member' => $user_info['id'],
- 'board_list' => $boards,
- 'group_list' => $user_info['groups'],
- 'moderator_group' => 3,
- 'permission_list' => (is_array($permission) ? 'IN (\'' . implode('\', \'', $permission) . '\')' : ' = \'' . $permission . '\''),
- )
- );
-
- if ($smcFunc['db_num_rows']($request) != count($boards))
- return false;
- $result = true;
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $result &= !empty($row['add_deny']);
- $smcFunc['db_free_result']($request);
-
- return $result;
- }
- function isAllowedTo($permission, $boards = null)
- {
- global $user_info, $txt;
- static $heavy_permissions = array(
- 'admin_forum',
- 'manage_attachments',
- 'manage_smileys',
- 'manage_boards',
- 'edit_news',
- 'moderate_forum',
- 'manage_bans',
- 'manage_membergroups',
- 'manage_permissions',
- );
-
- $permission = is_array($permission) ? $permission : array($permission);
-
- if (!allowedTo($permission, $boards))
- {
-
- $error_permission = array_shift($permission);
-
- if ($user_info['is_guest'])
- {
- loadLanguage('Errors');
- is_not_guest($txt['cannot_' . $error_permission]);
- }
-
- $_GET['action'] = '';
- $_GET['board'] = '';
- $_GET['topic'] = '';
- writeLog(true);
- fatal_lang_error('cannot_' . $error_permission, false);
-
- trigger_error('Hacking attempt...', E_USER_ERROR);
- }
-
-
- if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
- validateSession();
- }
- function boardsAllowedTo($permissions, $check_access = true)
- {
- global $user_info, $modSettings, $smcFunc;
-
- if ($user_info['is_admin'])
- return array(0);
-
- if (!is_array($permissions))
- $permissions = array($permissions);
-
- $groups = array_diff($user_info['groups'], array(3));
- $request = $smcFunc['db_query']('', '
- SELECT b.id_board, bp.add_deny
- FROM {db_prefix}board_permissions AS bp
- INNER JOIN {db_prefix}boards AS b ON (b.id_profile = bp.id_profile)
- LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
- WHERE bp.id_group IN ({array_int:group_list}, {int:moderator_group})
- AND bp.permission IN ({array_string:permissions})
- AND (mods.id_member IS NOT NULL OR bp.id_group != {int:moderator_group})' .
- ($check_access ? ' AND {query_see_board}' : ''),
- array(
- 'current_member' => $user_info['id'],
- 'group_list' => $groups,
- 'moderator_group' => 3,
- 'permissions' => $permissions,
- )
- );
- $boards = array();
- $deny_boards = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- if (empty($row['add_deny']))
- $deny_boards[] = $row['id_board'];
- else
- $boards[] = $row['id_board'];
- }
- $smcFunc['db_free_result']($request);
- $boards = array_unique(array_values(array_diff($boards, $deny_boards)));
- return $boards;
- }
- function showEmailAddress($userProfile_hideEmail, $userProfile_id)
- {
- global $modSettings, $user_info;
-
-
-
-
-
-
-
-
-
- return (!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']) || isset($_SESSION['ban']['cannot_post']) ? 'no' : ((!$user_info['is_guest'] && $user_info['id'] == $userProfile_id && !$userProfile_hideEmail) || allowedTo('moderate_forum') ? 'yes_permission_override' : ($userProfile_hideEmail ? 'no' : (!empty($modSettings['make_email_viewable']) ? 'yes' : 'no_through_forum')));
- }
- function spamProtection($error_type)
- {
- global $modSettings, $txt, $user_info, $smcFunc;
-
- $timeOverrides = array(
- 'login' => 2,
- 'register' => 2,
- 'sendtopc' => $modSettings['spamWaitTime'] * 4,
- 'sendmail' => $modSettings['spamWaitTime'] * 5,
- 'reporttm' => $modSettings['spamWaitTime'] * 4,
- 'search' => !empty($modSettings['search_floodcontrol_time']) ? $modSettings['search_floodcontrol_time'] : 1,
- );
-
- if (!allowedTo('moderate_board'))
- $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
- else
- $timeLimit = 2;
-
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}log_floodcontrol
- WHERE log_time < {int:log_time}
- AND log_type = {string:log_type}',
- array(
- 'log_time' => time() - $timeLimit,
- 'log_type' => $error_type,
- )
- );
-
- $smcFunc['db_insert']('replace',
- '{db_prefix}log_floodcontrol',
- array('ip' => 'string-16', 'log_time' => 'int', 'log_type' => 'string'),
- array($user_info['ip'], time(), $error_type),
- array('ip', 'log_type')
- );
-
- if ($smcFunc['db_affected_rows']() != 1)
- {
-
- fatal_lang_error($error_type . 'WaitTime_broken', false, array($timeLimit));
- return true;
- }
-
- return false;
- }
- ?>
|