2011-03-28 14:21:28 +00:00
|
|
|
<?
|
|
|
|
require 'config.php'; //The config contains all site wide configuration information as well as memcached rules
|
2013-05-27 08:00:58 +00:00
|
|
|
require(SERVER_ROOT.'/classes/debug.class.php');
|
|
|
|
require(SERVER_ROOT.'/classes/cache.class.php'); //Require the caching class
|
|
|
|
require(SERVER_ROOT.'/classes/encrypt.class.php'); //Require the caching class
|
2011-07-13 08:00:06 +00:00
|
|
|
|
|
|
|
$Debug = new DEBUG;
|
2012-10-03 08:00:16 +00:00
|
|
|
$Cache = NEW CACHE($MemcachedServers); //Load the caching class
|
2011-03-28 14:21:28 +00:00
|
|
|
$Enc = NEW CRYPT; //Load the encryption class
|
|
|
|
|
|
|
|
$SSL = ($_SERVER['SERVER_PORT'] === '443');
|
|
|
|
|
2013-04-20 08:01:01 +00:00
|
|
|
if (isset($_COOKIE['session'])) {
|
|
|
|
$LoginCookie = $Enc->decrypt($_COOKIE['session']);
|
|
|
|
}
|
|
|
|
if (isset($LoginCookie)) {
|
2013-06-18 08:00:48 +00:00
|
|
|
list($SessionID, $UserID) = explode("|~|", $Enc->decrypt($LoginCookie));
|
2012-10-11 08:00:15 +00:00
|
|
|
|
2013-04-20 08:01:01 +00:00
|
|
|
if (!$UserID || !$SessionID) {
|
2011-03-28 14:21:28 +00:00
|
|
|
die('Not logged in!');
|
|
|
|
}
|
2012-10-11 08:00:15 +00:00
|
|
|
|
2013-04-20 08:01:01 +00:00
|
|
|
if (!$Enabled = $Cache->get_value('enabled_'.$UserID)) {
|
2013-05-27 08:00:58 +00:00
|
|
|
require(SERVER_ROOT.'/classes/mysql.class.php'); //Require the database wrapper
|
2011-03-28 14:21:28 +00:00
|
|
|
$DB=NEW DB_MYSQL; //Load the database wrapper
|
2013-06-06 08:01:03 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT Enabled
|
|
|
|
FROM users_main
|
|
|
|
WHERE ID='$UserID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
list($Enabled) = $DB->next_record();
|
|
|
|
$Cache->cache_value('enabled_'.$UserID, $Enabled, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
die('Not logged in!');
|
|
|
|
}
|
|
|
|
|
|
|
|
function error($Error) {
|
|
|
|
die($Error);
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_number($Str) {
|
2013-04-20 08:01:01 +00:00
|
|
|
if ($Str < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
// We're converting input to a int, then string and comparing to original
|
|
|
|
return ($Str == strval(intval($Str)) ? true : false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function display_str($Str) {
|
2013-04-20 08:01:01 +00:00
|
|
|
if ($Str != '') {
|
|
|
|
$Str = make_utf8($Str);
|
2013-06-18 08:00:48 +00:00
|
|
|
$Str = mb_convert_encoding($Str, 'HTML-ENTITIES', 'UTF-8');
|
|
|
|
$Str = preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/m", '&', $Str);
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
$Replace = array(
|
|
|
|
"'",'"',"<",">",
|
|
|
|
'€','‚','ƒ','„','…','†','‡','ˆ','‰','Š','‹','Œ','Ž','‘','’','“','”','•','–','—','˜','™','š','›','œ','ž','Ÿ'
|
|
|
|
);
|
|
|
|
|
2013-04-20 08:01:01 +00:00
|
|
|
$With = array(
|
2011-03-28 14:21:28 +00:00
|
|
|
''','"','<','>',
|
|
|
|
'€','‚','ƒ','„','…','†','‡','ˆ','‰','Š','‹','Œ','Ž','‘','’','“','”','•','–','—','˜','™','š','›','œ','ž','Ÿ'
|
|
|
|
);
|
|
|
|
|
2013-06-18 08:00:48 +00:00
|
|
|
$Str = str_replace($Replace, $With, $Str);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
return $Str;
|
|
|
|
}
|
|
|
|
|
|
|
|
function make_utf8($Str) {
|
2013-04-20 08:01:01 +00:00
|
|
|
if ($Str != '') {
|
|
|
|
if (is_utf8($Str)) {
|
|
|
|
$Encoding = 'UTF-8';
|
|
|
|
}
|
|
|
|
if (empty($Encoding)) {
|
2013-04-30 18:18:07 +00:00
|
|
|
$Encoding = mb_detect_encoding($Str, 'UTF-8, ISO-8859-1');
|
2013-04-20 08:01:01 +00:00
|
|
|
}
|
|
|
|
if (empty($Encoding)) {
|
|
|
|
$Encoding = 'ISO-8859-1';
|
|
|
|
}
|
|
|
|
if ($Encoding == 'UTF-8') {
|
|
|
|
return $Str;
|
|
|
|
} else {
|
2013-04-30 18:18:07 +00:00
|
|
|
return @mb_convert_encoding($Str, 'UTF-8', $Encoding);
|
2013-04-20 08:01:01 +00:00
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_utf8($Str) {
|
|
|
|
return preg_match('%^(?:
|
|
|
|
[\x09\x0A\x0D\x20-\x7E] // ASCII
|
|
|
|
| [\xC2-\xDF][\x80-\xBF] // non-overlong 2-byte
|
|
|
|
| \xE0[\xA0-\xBF][\x80-\xBF] // excluding overlongs
|
|
|
|
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} // straight 3-byte
|
|
|
|
| \xED[\x80-\x9F][\x80-\xBF] // excluding surrogates
|
|
|
|
| \xF0[\x90-\xBF][\x80-\xBF]{2} // planes 1-3
|
|
|
|
| [\xF1-\xF3][\x80-\xBF]{3} // planes 4-15
|
|
|
|
| \xF4[\x80-\x8F][\x80-\xBF]{2} // plane 16
|
|
|
|
)*$%xs', $Str
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function display_array($Array, $DontEscape = array()) {
|
|
|
|
foreach ($Array as $Key => $Val) {
|
2013-04-20 08:01:01 +00:00
|
|
|
if (!in_array($Key, $DontEscape)) {
|
2011-03-28 14:21:28 +00:00
|
|
|
$Array[$Key] = display_str($Val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $Array;
|
|
|
|
}
|
2011-07-13 08:00:06 +00:00
|
|
|
|
|
|
|
function make_secret($Length = 32) {
|
|
|
|
$Secret = '';
|
2013-04-30 18:18:07 +00:00
|
|
|
$Chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
for ($i = 0; $i < $Length; $i++) {
|
|
|
|
$Rand = mt_rand(0, strlen($Chars) - 1);
|
2011-07-13 08:00:06 +00:00
|
|
|
$Secret .= substr($Chars, $Rand, 1);
|
|
|
|
}
|
|
|
|
return str_shuffle($Secret);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send a message to an IRC bot listening on SOCKET_LISTEN_PORT
|
|
|
|
function send_irc($Raw) {
|
|
|
|
$IRCSocket = fsockopen(SOCKET_LISTEN_ADDRESS, SOCKET_LISTEN_PORT);
|
|
|
|
$Raw = str_replace(array("\n", "\r"), '', $Raw);
|
|
|
|
fwrite($IRCSocket, $Raw);
|
|
|
|
fclose($IRCSocket);
|
|
|
|
}
|