function LOADRULES($id) { $f = explode("\n", @file_get_contents("/etc/squid3/acls/container_{$id}.txt")); while (list($num, $val) = each($f)) { $val = trim(strtolower($val)); if ($val == null) { continue; } if (is_regex($val)) { $GLOBALS["RULES"][$val] = true; continue; } $val = str_replace(".", "\\.", $val); $val = str_replace("*", ".*?", $val); $GLOBALS["RULES"][$val] = true; } WLOG("Starting Group Number:{$id} " . count($GLOBALS["RULES"]) . " rules"); }
function GetMacFromIP($ipaddr) { $ipaddr = trim($ipaddr); $ttl = date('YmdH'); if (count($GLOBALS["CACHEARP"]) > 3) { unset($GLOBALS["CACHEARP"]); } if (isset($GLOBALS["CACHEARP"][$ttl][$ipaddr])) { return $GLOBALS["CACHEARP"][$ttl][$ipaddr]; } if (!isset($GLOBALS["SBIN_ARP"])) { $GLOBALS["SBIN_ARP"] = find_program("arp"); } if (!isset($GLOBALS["SBIN_ARPING"])) { $GLOBALS["SBIN_ARPING"] = find_program("arping"); } if (strlen($GLOBALS["SBIN_ARPING"]) > 3) { $cmd = "{$GLOBALS["SBIN_ARPING"]} {$ipaddr} -c 1 -r 2>&1"; exec($cmd, $results); while (list($num, $line) = each($results)) { if (preg_match("#^([0-9a-zA-Z\\:]+)#", $line, $re)) { $GLOBALS["CACHEARP"][$ttl][$ipaddr] = $re[1]; return $GLOBALS["CACHEARP"][$ttl][$ipaddr]; } } } $results = array(); if (strlen($GLOBALS["SBIN_ARP"]) < 4) { return; } if (!isset($GLOBALS["SBIN_PING"])) { $GLOBALS["SBIN_PING"] = find_program("ping"); } if (!isset($GLOBALS["SBIN_NOHUP"])) { $GLOBALS["SBIN_NOHUP"] = find_program("nohup"); } $cmd = "{$GLOBALS["SBIN_ARP"]} -n \"{$ipaddr}\" 2>&1"; WLOG($cmd); exec($cmd, $results); while (list($num, $line) = each($results)) { if (preg_match("#^[0-9\\.]+\\s+.+?\\s+([0-9a-z\\:]+)#", $line, $re)) { if ($re[1] == "no") { continue; } $GLOBALS["CACHEARP"][$ttl][$ipaddr] = $re[1]; return $GLOBALS["CACHEARP"][$ttl][$ipaddr]; } } if (!isset($GLOBALS["PINGEDHOSTS"][$ipaddr])) { shell_exec("{$GLOBALS["SBIN_NOHUP"]} {$GLOBALS["SBIN_PING"]} {$ipaddr} -c 3 >/dev/null 2>&1 &"); $GLOBALS["PINGEDHOSTS"][$ipaddr] = true; } }
private function Hotspot_debug($text) { if (!$GLOBALS["SPLASH_DEBUG"]) { return; } if (function_exists("WLOG")) { WLOG($text); return; } writelogs($text, "Hotspot_SessionActive", __FILE__, 0); }
@file_put_contents($lockfile, time()); $line = fread($urlptr, $blocksize); $bytes = $bytes + strlen($line); $c++; echo $line; if ($c > 300) { WLOG("({$id}): [{$basename}]:Ouput " . round($bytes / 1024 / 1000, 2) . "MB / {$lengthlog}MB", __LINE__); $c = 0; } if ($fileptr) { fwrite($fileptr, $line); } @unlink($lockfile); } @unlink($lockfile); WLOG("Finish {$fname}", __LINE__); $sock = new sockets(); $sock->getFrameWork("squid.php?streamget=yes"); @fclose($urlptr); if ($fileptr) { fclose($fileptr); } function logdata($type, $what, $fname) { $file_path = "/home/artica/cache"; $logfile = "{$file_path}/cache.log"; $line = "@ " . time() . "Cache {$type} url: {$what} file: {$fname} client:" . $_SERVER['REMOTE_ADDR'] . "\n"; file_put_contents($logfile, $line, FILE_APPEND); } function WLOG($text = null, $line) {
function HashUsersFromGPID($gpid) { $array = array(); if (!is_numeric($gpid)) { return array(); } TestConnectToPureLDAP(); $sr = @ldap_search($GLOBALS["CONNECTION"], $GLOBALS["SUFFIX"], "(&(gidnumber={$gpid})(objectclass=posixGroup))"); if (!$sr) { WLOG("[QUERY]:HashUsersFromGPID::{$gpid} Ressource false query (gidnumber={$gpid})"); return array(); } $entry_id = @ldap_first_entry($GLOBALS["CONNECTION"], $sr); if (!$entry_id) { WLOG("[QUERY]:HashUsersFromGPID::{$gpid} entry_id false query (gidnumber={$gpid})"); return array(); } $attrs = @ldap_get_attributes($GLOBALS["CONNECTION"], $entry_id); if (!isset($attrs["memberUid"])) { return array(); } for ($i = 0; $i < $attrs["memberUid"]["count"]; $i++) { $array[$attrs["memberUid"][$i]] = $attrs["memberUid"][$i]; } return $array; }
$member = trim(strtolower($member)); if ($GLOBALS["DEBUG_GROUPS"] > 0) { WLOG("Checking {$member} in {$LOGNAME} ({$DN})"); } $MEMBERS = $ldapext->HashUsersFromGroupDN($DN); if (!isset($MEMBERS[$member])) { fwrite(STDOUT, "ERR\n"); continue; } fwrite(STDOUT, "OK\n"); } } CleanSessions(); $distanceInSeconds = round(abs(time() - $GLOBALS["STARTIME"])); $distanceInMinutes = round($distanceInSeconds / 60); WLOG("[STOP]: Stopping process After ({$distanceInSeconds}s - about {$distanceInMinutes}mn)"); if (isset($GLOBALS["F"])) { @fclose($GLOBALS["F"]); } function CleanSessions() { if (!isset($GLOBALS["SESSIONS"])) { return; } if (!is_array($GLOBALS["SESSIONS"])) { return; } } function internal_find_program($strProgram) { global $addpaths;
function TIMED_OUT($array) { $WWW = $array["website"]; if (count($GLOBALS["ACL_RULES"]) == 0) { if ($GLOBALS["DEBUG"]) { WLOG("[{$WWW}]:TIMED_OUT: skipped no rule defined"); } $array["LOCK"] = false; return $array; } if ($GLOBALS["DEBUG"]) { WLOG("[{$WWW}]: ---------------- ||{$WWW}|| ANALYZE ----------------"); } $passed_minutes = $array["TIME"]; if (!is_numeric($passed_minutes)) { $passed_minutes = 0; } foreach ($GLOBALS["ACL_RULES"] as $array_rules) { if (!isset($array_rules["INTERVAL"])) { $array_rules["INTERVAL"] = 5; } $MAX = intval($array_rules["MAX"]); $WAIT = intval($array_rules["WAIT"]); $INTERVAL = intval($array_rules["INTERVAL"]); if ($MAX == 0) { $MAX = 5; } if ($INTERVAL == 0) { $INTERVAL = 5; } // On calcul l'intervalle de la dernière heure de scan si ce n'est pas locké. $interval_passed = time_passed_min($array["END"], time()); if (!$array["LOCK"]) { if ($interval_passed > $INTERVAL) { // L'interval est trop important, on débloque et on réitère. if ($GLOBALS["DEBUG"]) { WLOG("[{$WWW}]:TIMED_OUT:: UNLOCK : Interval {$interval_passed}Mn > {$INTERVAL} [" . __LINE__ . "]"); } $array["START"] = time(); $array["LOCK"] = false; return $array; } } if ($GLOBALS["DEBUG"]) { WLOG("[{$WWW}]:TIMED_OUT:: passed minutes: {$passed_minutes}mn rule: {$MAX}mn [" . __LINE__ . "]"); } if ($passed_minutes < $MAX) { continue; } // Délai imparti if ($GLOBALS["DEBUG"]) { WLOG("[{$WWW}]:TIMED_OUT:: LOCKED [" . __LINE__ . "]"); } $array["LOCK"] = true; if ($WAIT == 0) { // On block tout le temps if ($GLOBALS["DEBUG"]) { WLOG("[{$WWW}]:TIMED_OUT:: Locked every time [" . __LINE__ . "]"); } return $array; } if (!isset($array["WAIT_START_TIME"])) { //premier pointeur if ($GLOBALS["DEBUG"]) { WLOG("[{$WWW}]:TIMED_OUT:: %%% First pointer %%% [" . __LINE__ . "]"); } $array["WAIT_START_TIME"] = time(); return $array; } // nombre de minutes d'attente $MINUTES_TO_WAIT = time_passed_min($array["WAIT_START_TIME"], time()); if ($GLOBALS["DEBUG"]) { $started = date("m d H:i:s", $array["WAIT_START_TIME"]); WLOG("[{$WWW}]:TIMED_OUT:: Current {$MINUTES_TO_WAIT}mn from {$started} need to wait: {$WAIT}mn [" . __LINE__ . "]"); } if ($MINUTES_TO_WAIT > $WAIT) { //A attendu suffisament de temps, flush... if ($GLOBALS["DEBUG"]) { WLOG("[{$WWW}]:TIMED_OUT:: Unlock!, flush [" . __LINE__ . "]"); } $array["START"] = time(); $array["LOCK"] = false; return $array; } } // rien découvert, on retourne le tableau; if ($GLOBALS["DEBUG"]) { WLOG("[{$WWW}]:Nothing to do [" . __LINE__ . "]"); } return $array; }
function IsInCache($KEY) { if (!is_numeric($GLOBALS["StreamCacheTTLUri"])) { $GLOBALS["StreamCacheTTLUri"] = 30; } if (isset($GLOBALS["CACHE"][$KEY]["URI"])) { if (trim($GLOBALS["CACHE"][$KEY]["URI"]) == null) { unset($GLOBALS["CACHE"][$KEY]["URI"]); } } if (!isset($GLOBALS["CACHE"][$KEY]["time"])) { if ($GLOBALS["DEBUG"]) { WLOG("IsInCache() {$KEY} = FALSE"); } return false; } $data1 = $GLOBALS["CACHE"][$KEY]["time"]; $data2 = time(); $difference = $data2 - $data1; if ($GLOBALS["DEBUG"]) { WLOG("IsInCache() {$KEY} = {$difference}s/{$GLOBALS["StreamCacheTTLUri"]}s"); } if ($difference > $GLOBALS["StreamCacheTTLUri"]) { if ($GLOBALS["DEBUG"]) { WLOG("IsInCache() {$KEY} = FALSE"); } unset($GLOBALS["CACHE"][$KEY]); return false; } if ($GLOBALS["DEBUG"]) { WLOG("IsInCache() {$KEY} = TRUE"); } return true; }
function Checktime($MAC, $ipaddr) { $MAC = trim(strtolower($MAC)); if ($MAC == "00:00:00:00:00:00") { return false; } NewComputer($MAC, $ipaddr); $MAIN = $GLOBALS["MAIN"]; if (count($MAIN) == 0) { if ($GLOBALS["VERBOSE"]) { WLOG("[ERR]: MAIN NO ARRAY..."); } return false; } if (!isset($MAIN[$MAC])) { if ($GLOBALS["VERBOSE"]) { WLOG("[INFO]: [{$MAC}] Not found"); } return false; } $time = time(); $currentStartDay = strtotime(date("Y-m-d 00:00:01")); $ThisInt = $time - $currentStartDay; $array["0"] = "00:00"; $array["3600"] = "01:00"; $array["7200"] = "02:00"; $array["10800"] = "03:00"; $array["14400"] = "04:00"; $array["18000"] = "05:00"; $array["21600"] = "06:00"; $array["25200"] = "07:00"; $array["28800"] = "08:00"; $array["32400"] = "09:00"; $array["36000"] = "10:00"; $array["39600"] = "11:00"; $array["43200"] = "12:00"; $array["46800"] = "13:00"; $array["50400"] = "14:00"; $array["54000"] = "15:00"; $array["57600"] = "16:00"; $array["61200"] = "17:00"; $array["64800"] = "18:00"; $array["68400"] = "19:00"; $array["72000"] = "20:00"; $array["75600"] = "21:00"; $array["79200"] = "22:00"; $array["82800"] = "23:00"; $DayIndex = date("w"); if ($GLOBALS["VERBOSE"]) { WLOG("[INFO]: [{$MAC}] Day Index: {$DayIndex} Start: {$currentStartDay} - Time:{$time} = {$ThisInt}"); } if ($ThisInt < 43200) { $allow_time_from = $MAIN[$MAC][$DayIndex]["AM"][0]; $allow_time_to = $MAIN[$MAC][$DayIndex]["AM"][1]; if ($GLOBALS["VERBOSE"]) { WLOG("[INFO]: [{$MAC}] We are in morning..."); } } else { $allow_time_from = $MAIN[$MAC][$DayIndex]["PM"][0]; $allow_time_to = $MAIN[$MAC][$DayIndex]["PM"][1]; if ($GLOBALS["VERBOSE"]) { WLOG("[INFO]: [{$MAC}] We are in afternoon..."); } } if ($GLOBALS["VERBOSE"]) { WLOG("[INFO]: [{$MAC}] FROM: {$allow_time_from} ({$array[$allow_time_from]}) TO {$allow_time_to} ({$array[$allow_time_to]})"); } if ($ThisInt > $allow_time_from) { if ($ThisInt < $allow_time_to) { if ($GLOBALS["VERBOSE"]) { WLOG("[INFO]: [{$MAC}] ALLOWED"); } return false; } } if ($GLOBALS["VERBOSE"]) { WLOG("[INFO]: [{$MAC}] BANNED"); } ufdbgevents($ipaddr); return true; }
function LoadSessions() { $GLOBALS["SESSIONS"] = unserialize(@file_get_contents("/etc/squid3/" . basename(__FILE__) . ".cache")); WLOG("[START]:Loading " . count($GLOBALS["SESSIONS"]) . "sessions in cache...\n"); }
function CHECK_UID($WWW, $SUBF, $MaxPerHour = 0, $MaxPerDay = 0, $MaxPerWeek = 0) { $YEAR = date("Y"); $MONTH = date("m"); $DAY = date("d"); $HOUR = date("H"); $WEEK = date("W"); $base = "/home/squid/rttsize/{$YEAR}/{$MONTH}"; if ($MaxPerHour > 0) { $path = "{$base}/{$WEEK}/{$DAY}/{$HOUR}/{$SUBF}/{$WWW}"; if (is_file($path)) { $SIZE = intval(@file_get_contents($path)); $SIZE = $SIZE / 1024; //KB $SIZE = $SIZE / 1024; //MB if ($GLOBALS["DEBUG"]) { WLOG("{$WWW}/{$SUBF} == {$SIZE}MB Max Hour:{$MaxPerHour}MB"); } if ($SIZE >= $MaxPerHour) { return true; } } else { if ($GLOBALS["DEBUG"]) { WLOG("WARNING! {$path} no such file"); } } } if ($MaxPerDay > 0) { $path = "{$base}/{$WEEK}/{$DAY}/{$SUBF}/{$WWW}"; if (is_file($path)) { $SIZE = intval(@file_get_contents($path)); $SIZE = $SIZE / 1024; //KB $SIZE = $SIZE / 1024; //MB if ($GLOBALS["DEBUG"]) { WLOG("{$WWW}/{$SUBF} == {$SIZE}MB Max Day:{$MaxPerDay}MB"); } if ($SIZE >= $MaxPerDay) { return true; } } else { if ($GLOBALS["DEBUG"]) { WLOG("WARNING! {$path} no such file"); } } } if ($MaxPerWeek > 0) { $path = "{$base}/{$WEEK}/{$SUBF}/{$WWW}"; if (is_file($path)) { $SIZE = intval(@file_get_contents($path)); $SIZE = $SIZE / 1024; //KB $SIZE = $SIZE / 1024; //MB if ($GLOBALS["DEBUG"]) { WLOG("{$WWW}/{$SUBF} == {$SIZE}MB Max Day:{$MaxPerDay}MB"); } if ($SIZE >= $MaxPerWeek) { return true; } } else { if ($GLOBALS["DEBUG"]) { WLOG("WARNING! {$path} no such file"); } } } }
function SIZE_QUOTA($url) { if (trim($url) == null) { if ($GLOBALS["DEBUG"]) { WLOG("SIZE_QUOTA::URL is null [" . __LINE__ . "]"); return false; } } if (strpos(" {$url}", "127.0.0.1 00:00:00:00:00:00") > 0) { return false; } if ($GLOBALS["DEBUG"]) { WLOG("SIZE_QUOTA::{$url} [" . __LINE__ . "]"); } $values = explode(" ", $url); $USERNAME = $values[0]; if (strpos($USERNAME, '$') > 0) { if (substr($USERNAME, strlen($USERNAME) - 1, 1) == "\$") { $USERNAME = null; } } $IPADDR = $values[1]; $MAC = $values[2]; $XFORWARD = $values[3]; $WWW = $values[4]; if ($GLOBALS["DEBUG"]) { WLOG("SIZE_QUOTA::USERNAME:{$USERNAME} [" . __LINE__ . "]"); } if ($GLOBALS["DEBUG"]) { WLOG("SIZE_QUOTA::IPADDR..:{$IPADDR} [" . __LINE__ . "]"); } if ($GLOBALS["DEBUG"]) { WLOG("SIZE_QUOTA::MAC.....:{$MAC} [" . __LINE__ . "]"); } if ($GLOBALS["DEBUG"]) { WLOG("SIZE_QUOTA::XFORWARD:{$XFORWARD} [" . __LINE__ . "]"); } if ($GLOBALS["DEBUG"]) { WLOG("SIZE_QUOTA::WWW.....:{$WWW} [" . __LINE__ . "]"); } $USERNAME = str_replace("%20", " ", $USERNAME); $USERNAME = str_replace("%25", "-", $USERNAME); $IPADDR = str_replace("%25", "-", $IPADDR); $MAC = str_replace("%25", "-", $MAC); $XFORWARD = str_replace("%25", "-", $XFORWARD); if ($XFORWARD == "-") { $XFORWARD = null; } if ($MAC == "00:00:00:00:00:00") { $MAC = null; } if ($MAC == "-") { $MAC = null; } if ($USERNAME == "-") { $USERNAME = null; } $IPCalls = new IP(); if ($IPCalls->isIPAddress($XFORWARD)) { $IPADDR = $XFORWARD; } if (preg_match("#(.+?):[0-9]+#", $WWW, $re)) { $WWW = $re[1]; } if (preg_match("#^www\\.(.+)#", $WWW, $re)) { $WWW = $re[1]; } if (!class_exists("squid_familysite")) { include_once dirname(__FILE__) . "/ressources/class.squid.familysites.inc"; } $fam = new squid_familysite(); $WWW = $fam->GetFamilySites($WWW); if ($IPADDR != null) { $keymd5 = md5("{$WWW}{$IPADDR}"); $LOG_PREFIX = "{$IPADDR}/{$WWW}"; } if ($MAC != null) { $keymd5 = md5("{$WWW}{$MAC}"); $LOG_PREFIX = "{$MAC}/{$WWW}"; } if ($USERNAME != null) { $keymd5 = md5("{$WWW}{$USERNAME}"); $LOG_PREFIX = "{$USERNAME}/{$WWW}"; } $database_size_path = "/var/log/squid/" . date("YW") . "_QUOTASIZE.db"; if (!is_file($database_size_path)) { if ($GLOBALS["DEBUG"]) { WLOG("{$LOG_PREFIX}:FATAL!!! {$database_size_path} doesn't exists"); } return false; } $db_con = dba_open($database_size_path, "r", "db4"); if (!$db_con) { if ($GLOBALS["DEBUG"]) { WLOG("{$LOG_PREFIX}:FATAL!!! SIZE_QUOTA::{$database_size_path}, unable to open"); } return false; } if (!dba_exists($keymd5, $db_con)) { if ($GLOBALS["DEBUG"]) { WLOG("{$LOG_PREFIX}:FATAL!!! SIZE_QUOTA::{$keymd5} doesn't exists"); } return false; } $array = unserialize(dba_fetch($keymd5, $db_con)); dba_close($db_con); $current_hour = 0; $current_day = 0; $current_week = 0; if (isset($array["HOURLY"][date("d")][date("H")])) { $current_hour = intval($array["HOURLY"][date("d")][date("H")]); $current_hour = $current_hour / 1024; $current_hour = $current_hour / 1024; } if (isset($array["DAILY"][date("d")])) { $current_day = intval($array["DAILY"][date("d")]); $current_day = $current_day / 1024; $current_day = $current_day / 1024; } if (isset($array["WEEK"])) { $current_week = intval($array["WEEK"]); $current_week = $current_week / 1024; $current_week = $current_week / 1024; } $rules_week = $GLOBALS["ACL_RULES"]["WEEK"]; $rules_hour = $GLOBALS["ACL_RULES"]["HOUR"]; $rules_day = $GLOBALS["ACL_RULES"]["DAY"]; if ($GLOBALS["DEBUG"]) { WLOG("{$LOG_PREFIX}:{$current_hour}MB/{$current_day}MB/{$current_week}MB - {$rules_hour}MB/{$rules_day}MB/{$rules_week}MB"); } if ($rules_week > 0) { if ($current_week > $rules_week) { if ($GLOBALS["DEBUG"]) { WLOG("{$LOG_PREFIX}: WEEKLY: {$current_week}MB/{$rules_week}MB MACTHES --> OK"); } return true; } } if ($rules_day > 0) { if ($current_day > $rules_day) { if ($GLOBALS["DEBUG"]) { WLOG("{$LOG_PREFIX}: DAILY: {$current_day}MB/{$rules_day}MB MACTHES --> OK"); } return true; } } if ($rules_hour > 0) { if ($current_hour > $rules_hour) { if ($GLOBALS["DEBUG"]) { WLOG("{$LOG_PREFIX}:HOURLY: {$current_hour}MB/{$rules_hour}MB MACTHES --> OK"); } return true; } } return false; }
function LoadDatabase() { WLOG("Reloading database..."); $GLOBALS["GetMacToUidTIME"] = time(); $GLOBALS["USERSDB"] = unserialize(@file_get_contents("/etc/squid3/usersMacs.db")); }
function LoadRules() { if (!is_file("/etc/squid3/paranoid.db")) { return array(); } if (!isset($GLOBALS["PARANOID_RULES"])) { WLOG("LoadRules()::Loading new rules /etc/squid3/paranoid.db [" . __LINE__ . "]"); $GLOBALS["PARANOID_RULES"] = unserialize(@file_get_contents("/etc/squid3/paranoid.db")); $GLOBALS["PARANOID_RULES"]["FFMTIMES"] = filemtime("/etc/squid3/paranoid.db"); $GLOBALS["PARANOID_RULES"]["FFMTCOUNT"] = 0; return $GLOBALS["PARANOID_RULES"]; } if ($GLOBALS["PARANOID_RULES"]["FFMTCOUNT"] > 5) { $ffm = filemtime("/etc/squid3/paranoid.db"); if ($ffm != $GLOBALS["PARANOID_RULES"]["FFMTIMES"]) { WLOG("LoadRules()::Loading new rules /etc/squid3/paranoid.db [" . __LINE__ . "]"); $GLOBALS["PARANOID_RULES"] = unserialize(@file_get_contents("/etc/squid3/paranoid.db")); $GLOBALS["PARANOID_RULES"]["FFMTIMES"] = filemtime("/etc/squid3/paranoid.db"); $GLOBALS["PARANOID_RULES"]["FFMTCOUNT"] = 0; return $GLOBALS["PARANOID_RULES"]; } $GLOBALS["PARANOID_RULES"]["FFMTCOUNT"] = 0; } $GLOBALS["PARANOID_RULES"]["FFMTCOUNT"] = $GLOBALS["PARANOID_RULES"]["FFMTCOUNT"] + 1; return $GLOBALS["PARANOID_RULES"]; }
function api_mysql_connect() { if ($GLOBALS["MYSQL_SOCKET"] != null) { $bd = @mysql_connect(":{$GLOBALS["MYSQL_SOCKET"]}", $GLOBALS["MYSQL_USERNAME"], $GLOBALS["MYSQL_PASSWORD"]); } else { $bd = @mysql_connect("{$GLOBALS["MYSQL_SERVER"]}:{$GLOBALS["MYSQL_PORT"]}", "{$GLOBALS["MYSQL_USERNAME"]}", "{$GLOBALS["MYSQL_PASSWORD"]}"); } if ($bd) { return $bd; } $des = @mysql_error(); $errnum = @mysql_errno(); WLOG("api_mysql_connect() failed (N:{$errnum}) \"{$des}\""); return false; }
function memory_trace($array) { $key = null; $uid = $array["uid"]; $ipaddr = $array["ipaddr"]; $mac = $array["mac"]; $size = $array["size"]; $type = $array["type"]; $servername = $array["servername"]; if ($array["size"] == 0) { if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("O size ({$uid},{$mac},{$ipaddr}) -> {$servername}"); } return; } if (preg_match("#^www\\.(.+)#", $servername, $re)) { $servername = $re[1]; } if ($uid != null) { $key = "uid"; } if ($key == null) { if ($mac != null) { $key = "MAC"; } } if ($key == null) { if ($ipaddr != null) { $key = "ipaddr"; } } if ($key == null) { if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("Unable to check key ({$uid},{$mac},{$ipaddr}) -> {$servername}"); } return; } if (!isset($GLOBALS["TABLE_CHECKED"][date("YmdH")])) { $GLOBALS["Q"]->check_quota_hour(); $GLOBALS["TABLE_CHECKED"][date("YmdH")] = true; } $table = "quotahours_" . date('YmdH'); $hour = date("H"); $keyr = md5("{$hour}{$uid}{$ipaddr}{$mac}{$type}{$servername}"); $sql = "SELECT `size` FROM `{$table}` WHERE `keyr`='{$keyr}'"; $ligne = mysql_fetch_array($GLOBALS["Q"]->QUERY_SQL($sql)); $ligne["size"] = intval($ligne["size"]); if (!is_numeric($ligne["size"])) { $ligne["size"] = 0; } if ($ligne["size"] > 0) { if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("{$uid}/{$ipaddr} {$servername} ={$ligne["size"]} + {$size}"); } $newsize = $ligne["size"] + $size; $sql = "UPDATE LOW_PRIORITY `{$table}` SET `size`='{$newsize}' WHERE `keyr`='{$keyr}'"; if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG($sql); } $GLOBALS["Q"]->QUERY_SQL($sql); if (!$GLOBALS["Q"]->ok) { WLOG($GLOBALS["Q"]->mysql_error); } return; } $familysite = $GLOBALS["Q"]->GetFamilySites($servername); $uid = mysql_escape_string2($uid); $sql = "INSERT IGNORE INTO `{$table}` (`hour`,`keyr`,`ipaddr`,`familysite`,`servername`,`filetype`,`uid`,`MAC`,`size`) VALUES\n\t('{$hour}','{$keyr}','{$ipaddr}','{$familysite}','{$servername}','{$type}','{$uid}','{$mac}','{$size}')"; if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG($sql); } $GLOBALS["Q"]->QUERY_SQL($sql); if (!$GLOBALS["Q"]->ok) { WLOG($GLOBALS["Q"]->mysql_error); } }
function XVFERTSZ() { $F = base64_decode("L3Vzci9sb2NhbC9zaGFyZS9hcnRpY2EvLmxpYw=="); if (!is_file($F)) { WLOG("License check no such license"); return false; } $D = trim(@file_get_contents($F)); if (trim($D) == "TRUE") { return true; } WLOG("License check no such license content"); return false; }
function UFDGUARD_UNLOCKED($url) { if (trim($url) == null) { if ($GLOBALS["DEBUG_UNLOCK"]) { WLOG("UFDGUARD_UNLOCKED::URL is null"); return false; } } if (strpos(" {$url}", "127.0.0.1 00:00:00:00:00:00") > 0) { return false; } $q = new mysql_squid_builder(); if ($q->COUNT_ROWS("ufdbunlock") == 0) { return false; } $values = explode(" ", $url); $IPADDR = $values[0]; $MAC = $values[1]; $XFORWARD = $values[2]; $WWW = $values[3]; $IPADDR = str_replace("%25", "-", $IPADDR); $MAC = str_replace("%25", "-", $MAC); $XFORWARD = str_replace("%25", "-", $XFORWARD); if ($XFORWARD == "-") { $XFORWARD = null; } if ($MAC == "00:00:00:00:00:00") { $MAC = null; } if ($MAC == "-") { $MAC = null; } $IPCalls = new IP(); if ($IPCalls->isIPAddress($XFORWARD)) { $IPADDR = $XFORWARD; } if (preg_match("#(.+?):[0-9]+#", $WWW, $re)) { $WWW = $re[1]; } if (preg_match("#^www\\.(.+)#", $WWW, $re)) { $WWW = $re[1]; } $WWW = $q->GetFamilySites($WWW); if (!isset($GLOBALS["ufdbunlock_c"])) { $GLOBALS["ufdbunlock_c"] = 0; } if ($GLOBALS["ufdbunlock_c"] > 90) { $q->QUERY_SQL("DELETE FROM ufdbunlock WHERE `finaltime` <" . time()); if (!$q->ok) { WLOG("{$q->mysql_error}"); } $GLOBALS["ufdbunlock_c"] = 0; } if ($MAC != null) { if ($GLOBALS["DEBUG_UNLOCK"]) { WLOG("SELECT md5,finaltime FROM ufdbunlock WHERE `www`='{$WWW}' AND MAC='{$MAC}'"); } $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT md5,finaltime FROM ufdbunlock WHERE `www`='{$WWW}' AND MAC='{$MAC}'")); if (!$q->ok) { WLOG("{$q->mysql_error}"); } if ($ligne["md5"] != null) { if ($ligne["finaltime"] < time()) { return false; } if ($IPADDR != null) { $q->QUERY_SQL("UPDATE ufdbunlock SET ipaddr='{$IPADDR}' WHERE MAC='{$MAC}'"); } return true; } } if ($IPADDR != null) { if ($GLOBALS["DEBUG_UNLOCK"]) { WLOG("SELECT md5,finaltime FROM ufdbunlock WHERE `www`='{$WWW}' AND ipaddr='{$IPADDR}'"); } $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT md5,finaltime FROM ufdbunlock WHERE `www`='{$WWW}' AND ipaddr='{$IPADDR}'")); if (!$q->ok) { WLOG("{$q->mysql_error}"); } $time = time(); if ($ligne["md5"] != null) { if ($ligne["finaltime"] < time()) { WLOG("{$ligne["finaltime"]} < {$time} -> FALSE"); return false; } if ($MAC != null) { $q->QUERY_SQL("UPDATE ufdbunlock SET MAC='{$MAC}' WHERE ipaddr='{$IPADDR}'"); } return true; } } }