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 ItCharted($ARRAY) { $MAC = null; $IP = $ARRAY["IP"]; if (preg_match("#([0-9\\.]+)\\/(.*)#", $IP, $re)) { $hostname = $re[2]; $IP = $re[1]; } $userid = $ARRAY["userid"]; $PROTO = $ARRAY["PROTO"]; $URI = $ARRAY["URI"]; $SquidGuardIPWeb = $GLOBALS["SquidGuardIPWeb"]; $CONNECT = false; $KEY = null; if (isset($ARRAY["MAC"])) { $MAC = $ARRAY["MAC"]; } if (!class_exists("mysql_squid_builder")) { include_once dirname(__FILE__) . "/ressources/class.mysql.squid.builder.php"; } if (!isset($GLOBALS["SQUID_SQL"])) { $GLOBALS["SQUID_SQL"] = new mysql_squid_builder(); } if ($GLOBALS["DEBUG_ITCHART"]) { events("user:{$userid} {$IP}/{$MAC}"); } $arrayNext["src"] = $URI; $arrayNext["LOGIN"] = $userid; $arrayNext["IPADDR"] = $IP; $arrayNext["MAC"] = $MAC; if ($userid != null) { $FIELD = "uid"; $KEY = $userid; } if ($KEY == null) { if ($MAC != null) { $FIELD = "MAC"; $KEY = $MAC; } } if ($KEY == null) { if ($IP != null) { $FIELD = "ipaddr"; $KEY = $IP; } } if ($PROTO == "CONNECT") { $CONNECT = true; } $SquidGuardIPWeb = str_replace("ufdbguardd.php", "itchart.php", $SquidGuardIPWeb); if (!isset($GLOBALS["ITCHARTS_ENABLED"])) { $GLOBALS["ITCHARTS_ENABLED"] = unserialize(@file_get_contents("/etc/squid3/itCharts.enabled.db")); if (count($GLOBALS["ITCHARTS_ENABLED"]) == 0) { if ($GLOBALS["DEBUG_ITCHART"]) { events("/etc/squid3/itCharts.enabled.db = 0 entries"); } return false; } } if ($GLOBALS["DEBUG_ITCHART"]) { events(count($GLOBALS["ITCHARTS_ENABLED"]) . " It Charts to query ({$KEY})"); } $ITCHARTS = $GLOBALS["ITCHARTS_ENABLED"]; while (list($ID, $title) = each($ITCHARTS)) { if ($GLOBALS["DEBUG_ITCHART"]) { events("{$ID} - {$title} against {$KEY}"); } if (isset($GLOBALS["IT_CHART_SUCCESS"][$ID][$KEY])) { if ($GLOBALS["DEBUG_ITCHART"]) { events("{$ID} - {$KEY} MEMORY = TRUE"); } continue; } $sql = "SELECT ID FROM itchartlog WHERE `{$FIELD}`='{$KEY}' AND chartid='{$ID}'"; if ($GLOBALS["DEBUG_ITCHART"]) { events("{$sql}"); } $ligne = mysql_fetch_array($GLOBALS["SQUID_SQL"]->QUERY_SQL($sql)); if (!$GLOBALS["SQUID_SQL"]) { events("{$GLOBALS["SQUID_SQL"]->mysql_error}"); return false; } $RESULT_ID = intval($ligne["ID"]); if ($GLOBALS["DEBUG_ITCHART"]) { events("{$ID} - {$KEY} = {$RESULT_ID}"); } if ($RESULT_ID > 0) { $GLOBALS["IT_CHART_SUCCESS"][$ID][$KEY] = true; if ($GLOBALS["DEBUG_ITCHART"]) { events("{$ID} - {$KEY} -> continue"); } continue; } if ($GLOBALS["DEBUG_ITCHART"]) { events("{$ID} - {$KEY} NONE -> REDIRECT"); } $arrayNext["ChartID"] = $ID; ufdbgevents($title, "itChart"); $arrayNextEnc = base64_encode(serialize($arrayNext)); $output = "status=302 url=\"{$SquidGuardIPWeb}?request={$arrayNextEnc}&xtime=" . time() . "\""; Output_results($output, __FUNCTION__, __LINE__, $CONNECT); return true; } if ($GLOBALS["DEBUG_ITCHART"]) { events("DONE {$KEY}"); } }
function BlackListedBase($url,$IP,$userid){ $db_path="/var/log/squid/ufdbgclient.black.db"; if(!is_file($db_path)){ if($GLOBALS["VERBOSE"]){events("$db_path -> no such file");} return false; } $H=parse_url($url); $domain=$H["host"]; reset_memory(); if($GLOBALS["SquidGuardIPWeb"]==null){ $GLOBALS["SquidGuardIPWeb"]="http://127.0.0.1/exec.squidguard.php"; } $urlenc=urlencode($url); if(preg_match("#([0-9\.]+)#", $IP,$re)){$IP=$re[1];} if($userid=="-"){$userid=null;} $returned="{$GLOBALS["SquidGuardIPWeb"]}?rule-id=0SquidGuardIPWeb=". base64_encode($GLOBALS["SquidGuardIPWeb"])."&clientaddr=$IP&clientname=$IP&clientuser=$userid". "&clientgroup=default&targetgroup=blacklist&url=$urlenc"; if(isset($GLOBALS["BlacklistedBase"][$domain])){ if($GLOBALS["BlacklistedBase"][$domain]){ if($GLOBALS["VERBOSE"]){events("BlackListedBase: $domain -> MEM BLOCK"); } ufdbgevents("blacklist","default"); Output_results($returned); return true; }else{ if($GLOBALS["VERBOSE"]){events("BlackListedBase: $domain -> MEM PASS"); } return false; } } $db_con = dba_open($db_path, "r","db4"); if(!$db_con){return false;} $mainkey=trim(dba_firstkey($db_con)); while($mainkey !=false){ $val=0; if(trim($mainkey)==null){ $mainkey=dba_nextkey($db_con); continue; } if($GLOBALS["VERBOSE"]){events("BlackListedBase:Checking $mainkey -> $domain"); } if(preg_match("#$mainkey#", $domain)){ $GLOBALS["BlacklistedBase"][$domain]=true; if($GLOBALS["VERBOSE"]){events("BlackListedBase: BLACKLIST MATCH $mainkey -> $domain"); } ufdbgevents("blacklist","global-blacklist"); Output_results($returned); dba_close($db_con); return true; } $mainkey=dba_nextkey($db_con); } $GLOBALS["BlacklistedBase"][$domain]=false; dba_close($db_con); return false; }