1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321 |
- <?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 : '')]))
- 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();
- 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;
- }
-
- if (!isset($_GET['xml']))
- adminLogin($type);
- else
- return 'session_verify_fail';
- }
- 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 ($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;
- }
-
- $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 ($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;
-
- $permissions = (array) $permissions;
-
-
- if ($user_info['is_admin'])
- {
- if ($simple)
- return array(0);
- else
- {
- $result = array();
- foreach ($permissions as $permission)
- $result[$permission] = array(0);
- return $result;
- }
- }
-
- $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 = $deny_boards = $result = 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)
- $result = array_unique(array_values(array_diff($boards, $deny_boards)));
- else
- foreach ($permissions as $permission)
- $result[$permission] = array_unique(array_values(array_diff($boards[$permission], $deny_boards[$permission])));
- return $result;
- }
- 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;
- }
- ?>
|