function build() { if (!function_exists("IsPhysicalAddress")) { include_once dirname(__FILE__) . "/ressources/class.templates.inc"; } $unix = new unix(); $file_duration = "/etc/squid3/squid.durations.ini"; $file_quotas_day = "/etc/squid3/squid.quotasD.ini"; $file_quotas_hour = "/etc/squid3/squid.quotasH.ini"; $php5 = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $sql = "SELECT * FROM webfilters_quotas"; $q = new mysql_squid_builder(); $results = $q->QUERY_SQL($sql); $array = array(); while ($ligne = mysql_fetch_assoc($results)) { $duration = $ligne["duration"]; $xtype = $ligne["xtype"]; $value = $ligne["value"]; $array[$duration][$xtype][$value] = $ligne["maxquota"] * 1024 * 1000; if ($GLOBALS["VERBOSE"]) { echo "duration[{$duration}]: {$xtype} ({$value}) = {$array[$duration][$xtype][$value]} (bytes)\n"; } } if (count($array) == 0) { @unlink($file_duration); } else { @file_put_contents($file_duration, serialize($array)); } $table = "UserSizeD_" . date("Ymd"); if (!$q->TABLE_EXISTS($table)) { $q->CreateUserSizeRTT_day($table); shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.squid.php --build-schedules >/dev/null 2>&1 &"); } $sql = "SELECT uid,ipaddr,hostname,account,MAC,SUM(size) as size FROM `{$table}` GROUP BY uid,ipaddr,hostname,account,MAC"; $results = $q->QUERY_SQL($sql); $array = array(); while ($ligne = mysql_fetch_assoc($results)) { $array["ipaddr"][$ligne["ipaddr"]] = $ligne["size"]; $array["uid"][$ligne["uid"]] = $ligne["size"]; $array["hostname"][$ligne["hostname"]] = $ligne["size"]; $array["MAC"][$ligne["MAC"]] = $ligne["size"]; if ($GLOBALS["VERBOSE"]) { $sizeM = $ligne["size"] / 1024 / 1000; echo date("l d") . ": {$ligne["MAC"]},{$ligne["uid"]},{$ligne["ipaddr"]} = {$ligne["size"]} ({$sizeM} M)\n"; } } @file_put_contents($file_quotas_day, serialize($array)); $array = array(); $sql = "SELECT DAY(zDate) as tday,HOUR(zDate) as thour,uid,ipaddr,hostname,account,MAC,SUM(size) as size FROM `UserSizeRTT` \nGROUP BY uid,ipaddr,hostname,account,MAC,tday,thour HAVING tday=DAY(NOW()) AND thour=HOUR(NOW())"; $results = $q->QUERY_SQL($sql); $array = array(); while ($ligne = mysql_fetch_assoc($results)) { if ($GLOBALS["VERBOSE"]) { $sizeM = $ligne["size"] / 1024 / 1000; echo "{$ligne["thour"]}h: {$ligne["MAC"]},{$ligne["uid"]},{$ligne["ipaddr"]} = {$ligne["size"]} ({$sizeM} M)\n"; } $array["ipaddr"][$ligne["ipaddr"]] = $ligne["size"]; $array["uid"][$ligne["uid"]] = $ligne["size"]; $array["hostname"][$ligne["hostname"]] = $ligne["size"]; $array["MAC"][$ligne["MAC"]] = $ligne["size"]; } @file_put_contents($file_quotas_hour, serialize($array)); MacToUid(); }
exit; } if (isset($_GET["squid-get-system-info"])) { squid_get_system_info(); exit; } if (isset($_GET["squid-get-storage-info"])) { squid_get_storage_info(); exit; } if (isset($_GET["MacToUidStats"])) { MacToUidStats(); exit; } if (isset($_GET["MacToUid"])) { MacToUid(); exit; } if (isset($_GET["watchdog-log"])) { watchdoglogs(); exit; } if (isset($_GET["artica-db-restart"])) { articadb_restart(); exit; } if (isset($_GET["rrd-perform"])) { rrd_perform(); exit; } if (isset($_GET["squidhour-repair-exec"])) {
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; }