function ufdbg_admin_mysql($severity, $subject, $text, $file = null, $line = 0) { if (!is_numeric($line)) { $line = 0; } $key = md5($subject); if (isset($GLOBALS["NOTIFS"][$key])) { if (tool_time_min($GLOBALS["NOTIFS"][$key]) < 5) { return; } } $GLOBALS["NOTIFS"][$key] = time(); // 0 -> RED, 1 -> WARN, 2 -> INFO if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { if ($file == null) { $file = basename($trace[1]["file"]); } $function = $trace[1]["function"]; if ($line == 0) { $line = $trace[1]["line"]; } } } if (function_exists("syslog")) { $file = basename($file); $LOG_SEV = LOG_INFO; openlog($file, LOG_PID, LOG_SYSLOG); syslog($LOG_SEV, $subject . " [{$line}]"); closelog(); } $GLOBALS["SCHEDULE_ID"] = 0; $array["zdate"] = date("Y-m-d H:i:s"); $array["subject"] = $subject; $array["text"] = $text; $array["severity"] = $severity; $array["function"] = $function; $array["file"] = basename($file); $array["line"] = $line; $array["pid"] = getmypid(); $array["TASKID"] = $GLOBALS["SCHEDULE_ID"]; $serialize = serialize($array); $md5 = md5($serialize); if (!is_dir("/var/log/squid/squid_admin_mysql")) { @mkdir("/var/log/squid/squid_admin_mysql", 0755, true); } @file_put_contents("/var/log/squid/squid_admin_mysql/{$md5}.log", $serialize); }
function GetMacToUid($mac) { if ($mac == null) { return; } $filereload = "/var/log/squid/reload/{$GLOBALS["PID"]}.external_acl_squid.php"; if (is_file("/var/log/squid/reload/{$GLOBALS["PID"]}.external_acl_squid.php")) { WLOG("Flush memory..."); unset($GLOBALS["GetMacToUidMD5"]); unset($GLOBALS["GetMacToUid"]); unset($GLOBALS["USERSDB"]); unset($GLOBALS["UID_FROM_MAC"]); unset($GLOBALS["UID_FROM_IP"]); @unlink($filereload); } if (isset($GLOBALS["GetMacToUidTIME"])) { if (tool_time_min($GLOBALS["GetMacToUidTIME"]) > 5) { unset($GLOBALS["GetMacToUidMD5"]); unset($GLOBALS["GetMacToUid"]); unset($GLOBALS["USERSDB"]); unset($GLOBALS["UID_FROM_MAC"]); unset($GLOBALS["UID_FROM_IP"]); $GLOBALS["GetMacToUidTIME"] = time(); } } WLOG("Reloading MACToUid helper configuration"); $uid = $GLOBALS["Q"]->MacToUid($mac); if ($uid != null) { return $uid; } if ($GLOBALS["EnableArticaHotSpot"] == 1) { $time = time(); $q = new mysql_squid_builder(); $sql = "SELECT uid FROM hotspot_sessions WHERE MAC='{$mac}'"; $ligne = @mysql_fetch_array($q->QUERY_SQL($sql)); if (!$q->ok) { WLOG("Mysql Error line " . __LINE__); WLOG($sql); WLOG($q->mysql_error); } if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("{$sql}"); } if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("{$mac} -> uid/mac: {$ligne["uid"]}"); } if ($ligne["uid"] != null) { return $ligne["uid"]; } $sql = "SELECT uid FROM hotspot_sessions WHERE ipaddr='{$mac}'"; $ligne = @mysql_fetch_array($q->QUERY_SQL($sql)); if (!$q->ok) { WLOG("Mysql Error line " . __LINE__); WLOG($sql); WLOG($q->mysql_error); } if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("{$sql}"); } if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("{$mac} -> uid/ipaddr: {$ligne["uid"]}"); } if ($ligne["uid"] != null) { return $ligne["uid"]; } $sql = "SELECT uid FROM hotspot_networks WHERE pattern='{$mac}'"; $ligne = @mysql_fetch_array($q->QUERY_SQL($sql)); if (!$q->ok) { WLOG("Mysql Error line " . __LINE__); WLOG($sql); WLOG($q->mysql_error); } if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("{$sql}"); } if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("{$mac} -> uid/ipaddr: {$ligne["uid"]}"); } if ($ligne["uid"] != null) { return $ligne["uid"]; } } if (isset($GLOBALS["GetMacToUidMD5"])) { $md5file = md5_file("/etc/squid3/MacToUid.ini"); if ($md5file != $GLOBALS["GetMacToUidMD5"]) { unset($GLOBALS["GetMacToUid"]); } } if (isset($GLOBALS["GetMacToUid"])) { if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("MEM: {$mac} =`{$GLOBALS["GetMacToUid"][$mac]}`"); } if (isset($GLOBALS["GetMacToUid"][$mac])) { return $GLOBALS["GetMacToUid"][$mac]; } return; } $GLOBALS["GetMacToUid"] = unserialize(@file_get_contents("/etc/squid3/MacToUid.ini")); $GLOBALS["GetMacToUidMD5"] = md5_file("/etc/squid3/MacToUid.ini"); $GLOBALS["GetMacToUidTIME"] = time(); if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("DISK: {$mac} =`{$GLOBALS["GetMacToUid"][$mac]}`"); } if (isset($GLOBALS["GetMacToUid"][$mac])) { return $GLOBALS["GetMacToUid"][$mac]; } }
function GetMacToUid($mac, $ipaddr) { if ($mac == null) { return; } $filereload = "/var/log/squid/reload/{$GLOBALS["PID"]}.MACTOUID"; if (is_file("/var/log/squid/reload/{$GLOBALS["PID"]}.MACTOUID")) { LoadDatabase(); @unlink("/var/log/squid/reload/{$GLOBALS["PID"]}.MACTOUID"); } if (isset($GLOBALS["GetMacToUidTIME"])) { if (tool_time_min($GLOBALS["GetMacToUidTIME"]) > 10) { unset($GLOBALS["USERSDB"]); } } if (!isset($GLOBALS["USERSDB"])) { LoadDatabase(); } $uid = MacToUid($mac); if ($uid != null) { return $uid; } $uid = IpToUid($ipaddr); return $uid; }