12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355 |
- <?php
- if (!defined('SMF'))
- die('No direct access...');
- 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 : '')]))
- return;
-
- if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_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();
- unset($_SESSION['request_referer']);
- 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();
- unset($_SESSION['request_referer']);
- return;
- }
- }
-
- if (!empty($user_settings['openid_uri']))
- {
- require_once($sourcedir . '/Subs-OpenID.php');
- smf_openID_revalidate();
- $_SESSION[$type . '_time'] = time();
- unset($_SESSION['request_referer']);
- return;
- }
-
- if (empty($_SESSION['request_referer']))
- $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
- elseif (empty($_POST))
- unset($_SESSION['request_referer']);
-
- if (!isset($_GET['xml']))
- adminLogin($type);
- else
- return 'session_verify_fail';
- }
- function is_not_guest($message = '')
- {
- global $user_info, $txt, $context, $scripturl;
-
- if (isset($user_info['is_guest']) && !$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 ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
- continue;
- $ban_query[] = constructBanQueryIP($user_info[$ip_number]);
-
- if (empty($modSettings['disableHostnameLookup']) && $user_info[$ip_number] != 'unknown')
- {
- $hostname = host_from_ip($user_info[$ip_number]);
- if (strlen($hostname) > 0)
- {
- $ban_query[] = '({string:hostname} LIKE bi.hostname)';
- $ban_query_vars['hostname'] = $hostname;
- }
- }
- }
-
- 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($cookiename . '_', '', 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($cookiename . '_', 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',
- );
- call_integration_hook('integrate_post_ban_permissions', array(&$denied_permissions));
- $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',
- );
- call_integration_hook('integrate_warn_permissions', array(&$permission_change));
- 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;
- }
-
- if (isset($_SESSION['request_referer']))
- $referrer = $_SESSION['request_referer'];
- else
- $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($action . '_token_var' => $token_var, $action . '_token' => $token);
- }
- function validateToken($action, $type = 'post', $reset = true)
- {
- global $modSettings, $db_show_debug;
-
-
- if (!empty($db_show_debug))
- return true;
- $type = $type == 'get' || $type == 'request' ? $type : 'post';
-
- if ($action == 'login')
- {
- if (isset($_SESSION['token'][$type . '-' . $action]))
- {
- $return = $_SESSION['token'][$type . '-' . $action][3];
- unset($_SESSION['token'][$type . '-' . $action]);
- return $return;
- }
- else
- return '';
- }
-
-
- 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, $simple = true)
- {
- global $user_info, $modSettings, $smcFunc;
-
- if (!is_array($permissions))
- $permissions = array($permissions);
-
-
- if ($user_info['is_admin'])
- {
- if ($simple)
- return array(0);
- else
- {
- $boards = array();
- foreach ($permissions as $permission)
- $boards[$permission] = array(0);
- return $boards;
- }
- }
-
- $groups = array_diff($user_info['groups'], array(3));
- $request = $smcFunc['db_query']('', '
- SELECT b.id_board, bp.add_deny' . ($simple ? '' : ', bp.permission') . '
- 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 ($simple)
- {
- if (empty($row['add_deny']))
- $deny_boards[] = $row['id_board'];
- else
- $boards[] = $row['id_board'];
- }
- else
- {
- if (empty($row['add_deny']))
- $deny_boards[$row['permission']][] = $row['id_board'];
- else
- $boards[$row['permission']][] = $row['id_board'];
- }
- }
- $smcFunc['db_free_result']($request);
- if ($simple)
- $boards = array_unique(array_values(array_diff($boards, $deny_boards)));
- else
- {
- foreach ($permissions as $permission)
- {
-
- if (empty($boards[$permission]))
- $boards[$permission] = array();
- else
- {
-
- $deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
- $boards[$permission] = array_unique(array_values(array_diff($boards[$permission], $deny_boards[$permission])));
- }
- }
- }
- return $boards;
- }
- function showEmailAddress($userProfile_hideEmail, $userProfile_id)
- {
- global $modSettings, $user_info;
-
-
-
-
-
-
-
-
- if ((!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']) || isset($_SESSION['ban']['cannot_post']))
- return 'no';
- elseif ((!$user_info['is_guest'] && $user_info['id'] == $userProfile_id && !$userProfile_hideEmail) || allowedTo('moderate_forum'))
- return 'yes_permission_override';
- elseif ($userProfile_hideEmail)
- return 'no';
- elseif (!empty($modSettings['make_email_viewable']) )
- return 'yes';
- else
- return 'no_through_forum';
- }
- function spamProtection($error_type)
- {
- global $modSettings, $txt, $user_info, $smcFunc;
-
- $timeOverrides = array(
- 'login' => 2,
- 'register' => 2,
- 'remind' => 30,
- 'sendtopic' => $modSettings['spamWaitTime'] * 4,
- 'sendmail' => $modSettings['spamWaitTime'] * 5,
- 'reporttm' => $modSettings['spamWaitTime'] * 4,
- 'search' => !empty($modSettings['search_floodcontrol_time']) ? $modSettings['search_floodcontrol_time'] : 1,
- );
- call_integration_hook('integrate_spam_protection', array(&$timeOverrides));
-
- 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;
- }
- function secureDirectory($path, $attachments = false)
- {
- if (empty($path))
- return 'empty_path';
- if (!is_writable($path))
- return 'path_not_writable';
- $directoryname = basename($path);
- $errors = array();
- $close = empty($attachments) ? '
- </Files>' : '
- Allow from localhost
- </Files>
- RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
- if (file_exists($path . '/.htaccess'))
- $errors[] = 'htaccess_exists';
- else
- {
- $fh = @fopen($path . '/.htaccess', 'w');
- if ($fh) {
- fwrite($fh, '<Files *>
- Order Deny,Allow
- Deny from all' . $close);
- fclose($fh);
- }
- $errors[] = 'htaccess_cannot_create_file';
- }
- if (file_exists($path . '/index.php'))
- $errors[] = 'index-php_exists';
- else
- {
- $fh = @fopen($path . '/index.php', 'w');
- if ($fh) {
- fwrite($fh, '<?php
- /**
- * This file is here solely to protect your ' . $directoryname . ' directory.
- */
- // Look for Settings.php....
- if (file_exists(dirname(dirname(__FILE__)) . \'/Settings.php\'))
- {
- // Found it!
- require(dirname(dirname(__FILE__)) . \'/Settings.php\');
- header(\'Location: \' . $boardurl);
- }
- // Can\'t find it... just forget it.
- else
- exit;
- ?>');
- fclose($fh);
- }
- $errors[] = 'index-php_cannot_create_file';
- }
- if (!empty($errors))
- return $errors;
- else
- return true;
- }
- function constructBanQueryIP($fullip)
- {
-
- if (isValidIPv6($fullip))
- {
- $ip_parts = convertIPv6toInts($fullip);
- $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))';
- }
-
- elseif (preg_match('/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/', $fullip, $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))';
-
- else
- $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)';
- return $ban_query;
- }
- ?>
|