function parseTemplate_categoryname($category = null, $license = 0, $nosuffix = 0) { $CATEGORY_PLUS_TXT = null; parseTemplateLogs("parseTemplate_categoryname({$category},{$license})", __FUNCTION__, __FILE__, __LINE__); $sock = new sockets(); $SquidGuardApacheShowGroupNameTXT = null; if ($license == 1) { $SquidGuardApacheShowGroupName = $sock->GET_INFO("SquidGuardApacheShowGroupName"); if (!is_numeric($SquidGuardApacheShowGroupName)) { $SquidGuardApacheShowGroupName = 0; } if ($SquidGuardApacheShowGroupName == 1) { $SquidGuardApacheShowGroupNameTXT = $sock->GET_INFO("SquidGuardApacheShowGroupNameTXT"); if ($SquidGuardApacheShowGroupNameTXT == null) { $LicenseInfos = unserialize(base64_decode($sock->GET_INFO("LicenseInfos"))); if ($LicenseInfos["COMPANY"] == null) { $WizardSavedSettings = unserialize(base64_decode($sock->GET_INFO("WizardSavedSettings"))); $LicenseInfos["COMPANY"] = $WizardSavedSettings["company_name"]; } } $SquidGuardApacheShowGroupNameTXT = $LicenseInfos["COMPANY"]; } } $category = strtolower(trim($category)); include_once dirname(__FILE__) . "/ressources/class.ufdbguard-tools.inc"; if (preg_match("#^art(.+)#", $category, $re)) { parseTemplateLogs("Parsing: `{$category}`=`{$re[1]}`", __FUNCTION__, __FILE__, __LINE__); $category = CategoryCodeToCatName($category); $CATEGORY_PLUS_TXT = "Artica Database"; $users = new usersMenus(); if ($users->WEBSECURIZE) { $CATEGORY_PLUS_TXT = "Web Securize Database"; } if ($users->LANWANSAT) { $CATEGORY_PLUS_TXT = "LanWanSAT Database"; } if ($users->BAMSIGHT) { $CATEGORY_PLUS_TXT = "BamSight Database"; } } if (preg_match("#^tls(.+)#", $category, $re)) { parseTemplateLogs("Parsing: `{$category}`=`{$re[1]}`", __FUNCTION__, __FILE__, __LINE__); $category = CategoryCodeToCatName($category); $CATEGORY_PLUS_TXT = "Toulouse University Database"; } parseTemplateLogs("Parsing: `{$category}` - {$CATEGORY_PLUS_TXT} nosuffix={$nosuffix}", __FUNCTION__, __FILE__, __LINE__); if ($nosuffix == 1) { return $category; } if ($SquidGuardApacheShowGroupNameTXT != null) { $CATEGORY_PLUS_TXT = $SquidGuardApacheShowGroupNameTXT; } if ($CATEGORY_PLUS_TXT != null) { return $category . " (" . $CATEGORY_PLUS_TXT . ")"; } return $category; }
function Parseline($buffer) { $buffer = trim($buffer); if ($buffer == null) { return null; } $mdbuff = md5($buffer); if (isset($GLOBALS['MDBUFF'][$mdbuff])) { return; } $GLOBALS['MDBUFF'][$mdbuff] = true; if (count($GLOBALS['MDBUFF']) > 1000) { $GLOBALS['MDBUFF'] = array(); } if (strpos($buffer, "] PASS ") > 0) { return; } if (strpos($buffer, "UFDBinitHTTPSchecker") > 0) { return; } if (strpos($buffer, "IP socket port") > 0) { return; } if (strpos($buffer, "listening on interface") > 0) { return; } if (strpos($buffer, "yielding") > 0) { return; } if (strpos($buffer, "system:") > 0) { return; } if (strpos($buffer, "URL verification threads and") > 0) { return; } if (strpos($buffer, "worker threads") > 0) { return; } if (strpos($buffer, "license status") > 0) { return; } if (strpos($buffer, "redirect-fatal-error") > 0) { return; } if (strpos($buffer, "using OpenSSL library") > 0) { return; } if (strpos($buffer, "CA certificates are") > 0) { return; } if (strpos($buffer, "Failure to load the CA database") > 0) { return; } if (strpos($buffer, "CA file is") > 0) { return; } if (strpos($buffer, "ufdbHandleAlarmForTimeEvents") > 0) { return; } if (strpos($buffer, "Changing daemon status") > 0) { return; } if (strpos($buffer, "UFDBchangeStatus") > 0) { return; } if (strpos($buffer, "url-lookup-delay-during-database-reload") > 0) { return; } if (strpos($buffer, "url-lookup-result-during-database-reload") > 0) { return; } if (strpos($buffer, "url-lookup-result-when-fatal-error") > 0) { return; } if (strpos($buffer, "no http-server") > 0) { return; } if (strpos($buffer, "upload-stats") > 0) { return; } if (strpos($buffer, "analyse-uncategorised-urls") > 0) { return; } if (strpos($buffer, "redirect-loading-database") > 0) { return; } if (strpos($buffer, "ufdb-expression-debug") > 0) { return; } if (strpos($buffer, "ufdb-debug-filter") > 0) { return; } if (strpos($buffer, "database status: up to date") > 0) { return; } if (strpos($buffer, "ufdbGenTable should be called with the") > 0) { return; } if (strpos($buffer, "is deprecated and ignored") > 0) { return; } if (strpos($buffer, "init domainlist") > 0) { return; } if (strpos($buffer, "is empty !") > 0) { return; } if (strpos($buffer, "init expressionlist") > 0) { return; } if (strpos($buffer, "is optimised to one expression") > 0) { return; } if (strpos($buffer, "be analysed since there is no proper database") > 0) { return; } if (strpos($buffer, "REDIRECT 302") > 0) { return; } if (strpos($buffer, "close fd") > 0) { return; } if (strpos($buffer, ": open fd ") > 0) { return; } if (strpos($buffer, "acl {") > 0) { return; } if (strpos($buffer, "URL verifications") > 0) { return; } if (strpos($buffer, "must be part of the security") > 0) { return; } if (strpos($buffer, "}") > 0) { return; } if (strpos($buffer, "finished retrieving") > 0) { return; } if (strpos($buffer, "loading URL table from") > 0) { return; } if (strpos($buffer, "] option") > 0) { return; } if (strpos($buffer, "{") > 0) { return; } if (strpos($buffer, "] category \"") > 0) { return; } if (strpos($buffer, "] domainlist \"") > 0) { return; } if (strpos($buffer, "] pass ") > 0) { return; } if (strpos($buffer, "] safe-search") > 0) { return; } if (strpos($buffer, "configuration file") > 0) { return; } if (strpos($buffer, "refreshdomainlist") > 0) { return; } if (strpos($buffer, "software suite is free and Open Source Software") > 0) { return; } if (strpos($buffer, "by URLfilterDB") > 0) { return; } if (strpos($buffer, "] configuration status") > 0) { return; } if (strpos($buffer, 'expressionlist "') > 0) { return; } if (strpos($buffer, 'is newer than') > 0) { return; } if (strpos($buffer, 'source "') > 0) { return; } if (strpos($buffer, 'youtube-edufilter-id') > 0) { return; } if (trim($buffer) == null) { return; } if (strpos($buffer, 'max-logfile-size') > 0) { return; } if (strpos($buffer, 'check-proxy-tunnels') > 0) { return; } if (strpos($buffer, 'seconds to allow worker') > 0) { return; } if (strpos($buffer, '] loading URL category') > 0) { return; } if (preg_match("#\\] REDIR\\s+#", $buffer)) { return; } if (strpos($buffer, 'execdomainlist for') > 0) { return; } if (strpos($buffer, 'dynamic_domainlist_updater_main') > 0) { return; } if (preg_match("#FATAL ERROR: connection queue is full#", $buffer)) { $TimeFile = "/etc/artica-postfix/pids/webfiltering-connection.queue.full"; if (!IfFileTime($TimeFile, 5)) { return; } $Threads = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/UfdbGuardThreads")); $ThreadNew = $Threads + 5; if ($ThreadNew > 128) { $ThreadNew = 128; } squid_admin_mysql(0, "Webfiltering Service connection queue is full increase Threads from {$Threads} to {$ThreadNew} [action=restart]", $buffer, __FILE__, __LINE__); @file_put_contents("/etc/artica-postfix/settings/Daemons/UfdbGuardThreads", $ThreadNew); shell_exec("{$GLOBALS["nohup"]} /etc/init.d/ufdb restart --force >/dev/null 2>&1 &"); return; } if (stripos(" {$buffer}", "HUP signal received to reload the configuration") > 0) { squid_admin_mysql(1, "Webfiltering Service was reloaded - reloading databases [action=notify]", $buffer, __FILE__, __LINE__); events_ufdb_exec("Webfiltering Service was reloaded, wait 15 seconds"); return; } if (stripos(" {$buffer}", "ufdbGuard daemon stopped") > 0) { squid_admin_mysql(1, "Webfiltering Service was stopped [action=notify]", $buffer, __FILE__, __LINE__); events_ufdb_exec("Webfiltering Service was stopped, wait 15 seconds"); return; } if (stripos(" {$buffer}", 'Changing daemon status to "started"') > 0) { squid_admin_mysql(1, "Webfiltering Service was started [action=notify]", $buffer, __FILE__, __LINE__); events_ufdb_exec("Webfiltering Service was started, wait 15 seconds"); return; } if (preg_match("#thread socket-handler caught signal 11#", $buffer, $re)) { $TimeFile = "/etc/artica-postfix/pids/webfiltering-emergency"; if (!IfFileTime($TimeFile, 5)) { return; } squid_admin_mysql(0, "Webfiltering crash [action=Webfiltering Emergency]", $buffer, __FILE__, __LINE__); shell_exec("{$GLOBALS["nohup"]} {$GLOBALS["PHP5_BIN"]} /usr/share/artica-postfix/exec.squid.urgency.remove.php --ufdb-on >/dev/null 2>&1 &"); return; } if (preg_match("#Changing daemon status to \"error\"#", $buffer, $re)) { $TimeFile = "/etc/artica-postfix/pids/webfiltering-emergency"; if (!IfFileTime($TimeFile, 5)) { return; } squid_admin_mysql(0, "Webfiltering service error [action=Webfiltering Emergency]", $buffer, __FILE__, __LINE__); shell_exec("{$GLOBALS["nohup"]} {$GLOBALS["PHP5_BIN"]} /usr/share/artica-postfix/exec.ufdb.emergency.php --ufdb-on >/dev/null 2>&1 &"); return; } if (preg_match("#FATAL ERROR: cannot open configuration file\\s+\\/etc\\/squid3\\/ufdbGuard\\.conf#i", $buffer, $re)) { squid_admin_mysql(0, "Webfiltering error, Open Configuration File failed [action=restart service]", $buffer, __FILE__, __LINE__); shell_exec("{$GLOBALS["nohup"]} {$GLOBALS["PHP5_BIN"]} /usr/share/artica-postfix/exec.ufdb.php --restart --force --ufdbtail --fatal-error >/dev/null 2>&1 &"); return; } if (preg_match("#FATAL.*?read failed on \"(.+?)\".*?Bad address#i", $buffer, $re)) { squid_admin_mysql(0, "Webfiltering service error on database: {$re[1]} [action=Webfiltering Emergency]", $buffer, __FILE__, __LINE__); shell_exec("{$GLOBALS["nohup"]} {$GLOBALS["PHP5_BIN"]} /usr/share/artica-postfix/exec.ufdb.emergency.php --ufdb-on >/dev/null 2>&1 &"); return; } if (preg_match("#FATAL ERROR: cannot read from.*?No such file or directory#", $buffer, $re)) { squid_admin_mysql(0, "Webfiltering error: a database is missing [action=reconfigure]", $buffer, __FILE__, __LINE__); shell_exec("{$GLOBALS["nohup"]} {$GLOBALS["PHP5_BIN"]} /usr/share/artica-postfix/exec.squidguard.php --build --force >/dev/null 2>&1 &"); return; } if (preg_match("#There are no sources and there is no default ACL#i", $buffer)) { events("Seems not to be defined -> build compilation."); xsyslog("{reconfigure} ufdb service..."); shell_exec("{$GLOBALS["nohup"]} {$GLOBALS["PHP5_BIN"]} /usr/share/artica-postfix/exec.squidguard.php --build --force >/dev/null 2>&1 &"); return; } if (preg_match("#ERROR: cannot write to PID file\\s+(.+)#i", $buffer, $re)) { xsyslog("Apply permissions on {$re[1]}"); $pidfile = $re[1]; $pidpath = dirname($pidfile); @mkdir($pidpath, 0755, true); @chown($pidpath, "squid"); @chmod($pidpath, 0755); return; } if (preg_match("#\\] Changing daemon status to.*?error#", $buffer, $re)) { squid_admin_mysql(0, "Fatal! Webfilter daemon is turned to error", $buffer, __FILE__, __LINE__); return; } if (preg_match("#\\] Changing daemon status to.*?terminated#", $buffer, $re)) { squid_admin_mysql(1, "Webfilter daemon is turned to OFF", $buffer, __FILE__, __LINE__); return; } if (preg_match("#can't execute command of execdomainlist.*?popen failed: Cannot allocate memory#", $buffer, $re)) { @file_put_contents("/etc/artica-postfix/settings/Daemons/UfdbExecDomainList", 0); squid_admin_mysql(0, "Not Enough memory to use execdomainlist feature [action=reconfigure]", "{$buffer}\nexecdomainlist feature will be disabled..", __FILE__, __LINE__); shell_exec("{$GLOBALS["nohup"]} {$GLOBALS["PHP5_BIN"]} /usr/share/artica-postfix/exec.squidguard.php --build --force >/dev/null 2>&1 &"); return; } if (preg_match('#FATAL ERROR: table "(.+?)"\\s+could not be parsed.*?error code = [0-9]+#', $buffer, $re)) { $direname = dirname($re[1]); squid_admin_mysql(0, "Database {$direname} corrupted", $buffer . "\nReconfigure ufdb service after removing {$direname}...", __FILE__, __LINE__); events("Webfiltering engine error on {$direname}"); if (!is_dir($direname)) { return; } shell_exec("{$GLOBALS["SBIN_RM"]} -rf {$direname} >/dev/null 2>&1"); xsyslog("{reconfigure} ufdb service after removing {$direname}..."); shell_exec("{$GLOBALS["nohup"]} {$GLOBALS["PHP5_BIN"]} /usr/share/artica-postfix/exec.squidguard.php --build --force >/dev/null 2>&1 &"); return; } if (preg_match("#BLOCK-FATAL\\s+#", $buffer, $re)) { $TimeFile = "/etc/artica-postfix/pids/UFDB_BLOCK_FATAL"; if (!IfFileTime($TimeFile, 10)) { return; } events("Webfiltering engine error, reload service"); events_ufdb_exec("service was restarted, {$buffer}"); squid_admin_mysql(0, "Fatal, Web filtering engine error", $buffer . "\nThe service will be reloaded", __FILE__, __LINE__); xsyslog("Reloading ufdb service..."); shell_exec("{$GLOBALS["nohup"]} /etc/init.d/ufdb reload >/dev/null 2>&1 &"); return; } if (preg_match("#FATAL ERROR: connection queue is full#", $buffer, $re)) { $TimeFile = "/etc/artica-postfix/pids/UFDB_QUEUE_IS_FULL"; $Threads = @file_get_contents("/etc/artica-postfix/settings/Daemons/UfdbGuardThreads"); if (!is_numeric($Threads)) { $Threads = 48; } $Threads = $Threads + 1; if ($Threads > 140) { $Threads = 140; } @file_put_contents("/etc/artica-postfix/settings/Daemons/UfdbGuardThreads", $Threads); if (!IfFileTime($TimeFile, 2)) { return; } squid_admin_mysql(0, "Fatal, Web filtering connection queue is full", $buffer . "\nThe service will be restarted and threads are increased to {$Threads}", __FILE__, __LINE__); xsyslog("Restarting ufdb service after connection queue is full..."); shell_exec("{$GLOBALS["nohup"]} /etc/init.d/ufdb restart >/dev/null 2>&1 &"); return; } if (preg_match('#FATAL\\*\\s+table\\s+"(.+?)"\\s+could not be parsed.+?14#', $buffer, $re)) { events("Table on {$re[1]} crashed"); squid_admin_mysql(0, "Database {$re[1]} corrupted", $buffer, __FILE__, __LINE__); ufdbguard_admin_events("Table on {$re[1]} crashed\n{$buffer}", __FUNCTION__, __FILE__, __LINE__, "ufdbguard-service"); events_ufdb_exec("{$buffer}"); $GLOBALS["CLASS_UNIX"]->send_email_events("ufdbguard: {$re[1]} could not be parsed", "Ufdbguard claim: {$buffer}\n\n\t\tYou need to compile this database", "proxy"); return; } if (preg_match("#FATAL ERROR: cannot bind daemon socket: Address already in use#", $buffer)) { events_ufdb_exec("ERROR DETECTED : {$buffer} `cannot bind daemon socket`"); squid_admin_mysql(1, "Fatal ERROR: cannot bind daemon socket: Address already in use [action=restart]", $buffer, __FILE__, __LINE__); ufdbguard_admin_events("Fatal ERROR: cannot bind daemon socket: Address already in use", __FUNCTION__, __FILE__, __LINE__, "ufdbguard-service"); xsyslog("Restarting ufdb service..."); shell_exec("{$GLOBALS["nohup"]} /etc/init.d/ufdb restart >/dev/null 2>&1 &"); return; } if (preg_match('#\\] FATAL ERROR: cannot read from "(.+?)".*?No such file or directory#', $buffer, $re)) { squid_admin_mysql(0, "Database {$re[1]} missing", $buffer, __FILE__, __LINE__); events("cannot read '{$re[1]}' -> \"{$buffer}\""); squid_admin_mysql(2, "Web filtering issue on {$re[1]}", "Launch recover_a_database()", __FILE__, __LINE__); recover_a_database($re[1]); return; } if (preg_match('#\\*FATAL.+? cannot read from "(.+?)".+?: No such file or directory#', $buffer, $re)) { squid_admin_mysql(0, "Database {$re[1]} missing", $buffer, __FILE__, __LINE__); events("cannot read '{$re[1]}' -> \"{$buffer}\""); squid_admin_mysql(2, "Web filtering issue on {$re[1]}", "Launch recover_a_database()", __FILE__, __LINE__); recover_a_database($re[1]); return; } if (preg_match('#\\*FATAL\\*\\s+cannot read from\\s+"(.+?)"#', $buffer, $re)) { squid_admin_mysql(0, "Database {$re[1]} missing", $buffer, __FILE__, __LINE__); events("Problem on {$re[1]}"); events_ufdb_exec("{$buffer}"); squid_admin_mysql(2, "Web filtering issue on {$re[1]}", "Launch recover_a_database()", __FILE__, __LINE__); recover_a_database($re[1]); $GLOBALS["CLASS_UNIX"]->send_email_events("ufdbguard: {$re[1]} Not compiled..", "Ufdbguard claim: {$buffer}\nYou need to compile your databases"); return; } if (preg_match("#\\*FATAL\\*\\s+cannot read from\\s+\"(.+?)\\.ufdb\".+?No such file or directory#", $buffer, $re)) { squid_admin_mysql(0, "Database {$re[1]} missing", $buffer . "\n Problem on {$re[1]}\n\nYou need to compile your databases", __FILE__, __LINE__); events("UFDB database missing : Problem on {$re[1]}"); if (!is_file($re[1])) { @mkdir(dirname($re[1]), 666, true); shell_exec("/bin/touch {$re[1]}"); } $GLOBALS["CLASS_UNIX"]->send_email_events("ufdbguard: {$re[1]} Not compiled..", "Ufdbguard claim: {$buffer}\nYou need to compile your databases", "ufdbguard-service"); return; } if (preg_match("#thread worker-[0-1]+.+?caught signal\\s+[0-1]+#", $buffer, $re)) { squid_admin_mysql(0, "Webfiltering Daemon as crashed - Start a new one", $buffer, __FILE__, __LINE__); $GLOBALS["CLASS_UNIX"]->send_email_events("ufdbguard: crashed", "Ufdbguard claim: {$buffer}\n", "proxy"); shell_exec("/etc/init.d/ufdb start &"); } if (preg_match("#\\*FATAL\\*\\s+expression list\\s+(.+?): Permission denied#", $buffer, $re)) { squid_admin_mysql(0, "Database {$re[1]} permission denied", $buffer . "\nProblem on '{$re[1]}' -> chown squid:squid", __FILE__, __LINE__); events("UFDB expression permission issue : Problem on '{$re[1]}' -> chown squid:squid"); shell_exec("{$GLOBALS["chown"]} -R squid:squid " . dirname($re[1])); return; } if (preg_match("#\\*FATAL.+?expression list\\s+(.+?):\\s+No such file or directory#", $buffer, $re)) { squid_admin_mysql(0, "Database {$re[1]} missing", $buffer . "\nProblem on '{$re[1]}' -> Try to repair", __FILE__, __LINE__); events("Expression list: Problem on {$re[1]} -> \"{$buffer}\""); events("Creating directory " . dirname($re[1])); @mkdir(dirname($re[1]), 0755, true); events("Creating empty file '" . $re[1] . "'"); @file_put_contents($re[1], "\n"); events("ufdbguard tail: Service will be reloaded"); $GLOBALS["CLASS_UNIX"]->send_email_events(basename(__FILE__) . ":Service ufdb will be reloaded ", "Cause:{$buffer}", "ufdbguard-service"); squid_admin_mysql(2, "Ask to reload the Web filtering service", "Cause:{$buffer}"); ufdbguard_admin_events("ufdbguard tail: Service will be reloaded", __FUNCTION__, __FILE__, __LINE__, "watchdog"); shell_exec("{$GLOBALS["RELOADCMD"]} --function==" . __FUNCTION__ . " --line=" . __LINE__ . " " . "--filename=" . basename(__FILE__) . " >/dev/null 2>&1 &"); return; } if (preg_match("#database table \\/var\\/lib\\/squidguard\\/(.+?)\\/domains\\s+is empty#", $buffer, $re)) { //ufdbguard_admin_events("Database {$re[1]} as no datas, you should recompile your databases",__FUNCTION__,__FILE__,__LINE__,"ufdbguard-service"); //$GLOBALS["CLASS_UNIX"]->send_email_events("ufdbguard: {$re[1]} database is empty, please compile your databases","Ufdbguard claim: $buffer\nYou need to compile your databases","proxy"); return; } if (preg_match("#the new configuration and database are loaded for ufdbguardd ([0-9\\.]+)#", $buffer, $re)) { squid_admin_mysql(2, "Web Filtering engine service v{$re[1]} has reloaded new configuration and databases", ""); $GLOBALS["CLASS_UNIX"]->send_email_events("UfdbGuard v{$re[1]} has reloaded new configuration and databases", null, "ufdbguard-service"); return; } if (preg_match("#statistics:(.+)#", $buffer, $re)) { if (preg_match("#blocked ([0-9]+) times#", $re[1], $ri)) { if ($ri[1] > 0) { //squid_admin_mysql(2, "{$re[1]}",""); } } return; } if (preg_match("#BLOCK (.*?)\\s+(.+?)\\s+(.+?)\\s+(.+?)\\s+(|http|https|ftp|ftps)://(.+?)myip=(.+)\$#", $buffer, $re)) { $user = trim($re[1]); $local_ip = $re[2]; $rulename = $re[3]; $category = $re[4]; $www = $re[6]; $public_ip = $re[7]; //events("BLOCK[".__LINE__."]: $user/$local_ip - $www"); if (strpos($www, "/") > 0) { $tb = explode("/", $www); $www = $tb[0]; } if (preg_match("#^www\\.(.+)#", $www, $re)) { $www = $re[1]; } if (preg_match("#([0-9]+)\\.addr#", $www)) { $www = long2ip($re[1]); } if (preg_match("#^([0-9\\.]+)#", $local_ip, $re)) { $local_ip = $re[1]; } $date = time(); $table = date('Ymd') . "_blocked"; $category = CategoryCodeToCatName($category); if ($user == "-") { $user = null; } $MAC = $GLOBALS["CLASS_UNIX"]->IpToMac($local_ip); $time = time(); if (preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $www)) { $public_ip = $www; $www = $GLOBALS["CLASS_UNIX"]->IpToHostname($www); } $Clienthostname = $GLOBALS["CLASS_UNIX"]->IpToHostname($local_ip); if ($Clienthostname == null) { $Clienthostname = $local_ip; } paranoidmode($local_ip, $www); $q = new influx(); if ($GLOBALS["UfdbguardSMTPNotifs"]["BLOCK_NOTIFS"] == 1) { events("Write notif"); $line_notif = date("H:i:s") . " [{$www}]: blocked domain: User: {$user}/{$local_ip}/{$Clienthostname}, Category: {$category}, Rule: {$rulename}"; $q->insert_ufdb_notif($line_notif); } if ($GLOBALS["SQUID_PERFORMANCE"] > 2) { return; } $line = "{$time}:::{$user}:::{$category}:::{$rulename}:::{$public_ip}:::blocked domain:::blocked domain:::{$Clienthostname}:::{$www}:::{$local_ip}"; $q->insert_ufdb($line); return; } if (preg_match("#BLOCK\\s+(.*?)\\s+(.+?)\\s+(.*?)\\s+(.+?)\\s+(.+?)\\s+[A-Z]+#", $buffer, $re)) { $date = time(); $user = trim($re[1]); $local_ip = $re[2]; $rulename = $re[3]; $category = $re[4]; $uri = $re[5]; //events("BLOCK[".__LINE__."]: $user/$local_ip - $www Notif:{$GLOBALS["UfdbguardSMTPNotifs"]["BLOCK_NOTIFS"]}"); if (preg_match("#^([0-9\\.]+)#", $local_ip, $re)) { $local_ip = $re[1]; } $time = time(); $array = parse_url($uri); $www = $array["host"]; if (strpos($www, ":") > 0) { $t = explode(":", $www); $www = $t[0]; } if (preg_match("#([0-9]+)\\.addr#", $www)) { $www = long2ip($re[1]); } $category = CategoryCodeToCatName($category); $MAC = $GLOBALS["CLASS_UNIX"]->IpToMac($local_ip); if (preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $www)) { $public_ip = $www; $www = $GLOBALS["CLASS_UNIX"]->IpToHostname($www); } else { $public_ip = HostnameToIp($www); } if (preg_match("#^www\\.(.+)#", $www, $re)) { $www = $re[1]; } $Clienthostname = $GLOBALS["CLASS_UNIX"]->IpToHostname($local_ip); if ($Clienthostname == null) { $Clienthostname = $local_ip; } if ($user == "-") { $user = null; } CreateCounter($www, $local_ip, $user, $category); paranoidmode($local_ip, $www); $q = new influx(); if ($GLOBALS["UfdbguardSMTPNotifs"]["BLOCK_NOTIFS"] == 1) { $line_notif = date("H:i:s") . " [{$www}]: blocked domain: User: {$user}/{$local_ip}/{$Clienthostname}, Category: {$category}, Rule: {$rulename}"; $q->insert_ufdb_notif($line_notif); } if ($GLOBALS["SQUID_PERFORMANCE"] > 2) { return; } $q = new influx(); $line = "{$time}:::{$user}:::{$category}:::{$rulename}:::{$public_ip}:::blocked domain:::blocked domain:::{$Clienthostname}:::{$www}:::{$local_ip}"; $q->insert_ufdb($line); return; } events("Not filtered: {$buffer}"); }
function section_blocked_realtime_search() { $_GET["section-blocked-realtime-search"] = url_decode_special_tool($_GET["section-blocked-realtime-search"]); $page = CurrentPageName(); $tpl = new templates(); $sock = new sockets(); if (!isset($_GET["rp"])) { $_GET["rp"] = 350; } if ($_GET["section-blocked-realtime-search"] != null) { $search = base64_encode($_GET["section-blocked-realtime-search"]); $datas = unserialize(base64_decode($sock->getFrameWork("squid.php?ufdbguard-logs={$search}&rp={$_GET["rp"]}"))); if (count($datas) == 0) { senderror("no data"); } $total = count($datas); } else { $datas = unserialize(base64_decode($sock->getFrameWork("squid.php?ufdbguard-logs=&rp={$_GET["rp"]}"))); if (count($datas) == 0) { senderror("no data"); } $total = count($datas); } $boot = new boostrap_form(); $q2 = new mysql(); $t = time(); while (list($ID, $line) = each($datas)) { if (!preg_match('#(.+?)\\s+\\[(.+?)\\]\\s+(.+)#', $line, $re)) { continue; } $color = "black"; $date = $re[1]; $pid = $re[2]; $event = $re[3]; if (!preg_match("#^BLOCK\\s+(.*?)\\s+(.*?)\\s+(.*?)\\s+(.*?)\\s+(.*?)\\s+[A-Z]+#", $event, $re)) { continue; } $account = $re[1]; $group = $re[2]; $category = $re[4]; $rule = $re[3]; $uri = $re[5]; $sitename = null; $js = null; $unblock = null; if (preg_match("#^art(.+)#", $category, $re)) { $category = CategoryCodeToCatName($category); $CATEGORY_PLUS_TXT = "Artica Database"; } if (preg_match("#^tls(.+)#", $category, $re)) { $category = CategoryCodeToCatName($category); $CATEGORY_PLUS_TXT = "Toulouse University Database"; } $URLAR = parse_url($uri); if (isset($URLAR["host"])) { $sitename = $URLAR["host"]; } if (preg_match("#^(.*?):[0-9]+\$#", $sitename, $re)) { $sitename = $re[1]; } if (preg_match("#^www\\.(.*?)\$#", $sitename, $re)) { $sitename = $re[1]; } if ($sitename != null) { $js = "Loadjs('squid.categories.php?category={$category}&website={$sitename}',true)"; $link = $boot->trswitch($js); $unblock = imgsimple("whitelist-24.png", null, "UnBlockWebSite{$t}('{$sitename}')"); $ligne3 = mysql_fetch_array($q2->QUERY_SQL("SELECT items FROM urlrewriteaccessdeny WHERE items='{$sitename}'", "artica_backup")); } if (!$q2->ok) { $unblock = "<img src='img/icon_err.gif'><br>{$q2->mysql_error}"; } else { if ($ligne3["items"] != null) { $unblock = imgsimple("20-check.png", null, null); } } $strlen = strlen($uri); $uriT = wordwrap($uri, 100, "\n", true); $uriT = htmlentities($uriT); $uriT = nl2br($uriT); $uriT = str_replace($sitename, "<a href=\"javascript:blur()\"\n\t\t\t\tOnClick=\"javascript:Loadjs('miniadm.webstats.familysite.all.php?familysite={$sitename}');\"\n\t\t\t\tstyle='text-decoration:underline;color:{$color}'>{$sitename}</a>", $uriT); $tr[] = "<tr>\n\t\t<td nowrap style='font-size:14px' width=1% nowrap>{$date}</td>\n\t\t<td style='font-size:14px' width=1% nowrap>{$pid}</td>\n\t\t<td style='font-size:14px' width=1% nowrap>{$category}<div style='font-size:11px'>{$CATEGORY_PLUS_TXT}</div></td>\n\t\t<td style='font-size:14px' width=1% nowrap>{$account}/{$group}</td>\n\t\t<td style='font-size:14px' width=1% nowrap>{$rule}</td>\n\t\t<td style='font-size:14px'>{$uriT}</td>\n\t\t<td style='font-size:14px' width=1% nowrap>{$unblock}</td>\n\t\t</tr>\n\t\t"; } $tpl = new templates(); $UnBlockWebSiteExplain = $tpl->javascript_parse_text("{UnBlockWebSiteExplain}"); echo $tpl->_ENGINE_parse_body("<table class='table table-bordered'>\n\t\n\t\t\t<thead>\n\t\t\t<tr>\n\t\t\t<th>{date}</th>\n\t\t\t<th>PID</th>\n\t\t\t<th>{category}</th>\n\t\t\t<th>{member}</th>\n\t\t\t<th nowrap>{rulename}</th>\n\t\t\t<th>{url}</th>\n\t\t\t<th> </th>\n\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t<tbody>\n\t\t\t") . @implode("\n", $tr) . " </tbody></table>\t\t\n<script>\n\tvar x_UnBlockWebSite{$t}=function(obj){\n\t var tempvalue=obj.responseText;\n\t if(tempvalue.length>3){alert(tempvalue);}\n\t \n\t}\t\n\nfunction UnBlockWebSite{$t}(domain){\n\tif(confirm('{$UnBlockWebSiteExplain}:'+domain+' ?')){\n\t\tvar XHR = new XHRConnection();\n\t\tXHR.appendData('unlock',domain);\n\t\tXHR.sendAndLoad('squid.blocked.events.php', 'POST',x_UnBlockWebSite{$t});\n\t}\n\n}\n</script>"; }
function events_list() { $sock = new sockets(); include_once 'ressources/class.ufdbguard-tools.inc'; $sock->getFrameWork("squid.php?ufdb-real=yes&rp={$_POST["rp"]}&query=" . urlencode($_POST["query"])); $filename = "/usr/share/artica-postfix/ressources/logs/ufdb.log.tmp"; $dataZ = explode("\n", @file_get_contents($filename)); $tpl = new templates(); $data = array(); $data['page'] = 1; $data['total'] = count($data); $data['rows'] = array(); $today = date("Y-m-d"); $tcp = new IP(); $c = 0; krsort($dataZ); if (count($dataZ) == 0) { json_error_show("no data"); } $logfileD = new logfile_daemon(); $zcat = new squid_familysite(); while (list($num, $line) = each($dataZ)) { $TR = preg_split("/[\\s]+/", $line); if (count($TR) < 5) { continue; } $c++; $color = "black"; $date = $TR[0]; $TIME = $TR[1]; $PID = $TR[2]; $ALLOW = $TR[3]; $CLIENT = $TR[4]; $CLIENT_IP = $TR[5]; $RULE = $TR[6]; $CATEGORY = CategoryCodeToCatName($TR[7]); $URI = $TR[8]; $PROTO = $TR[9]; $parse = parse_url($URI); $hostname = $parse["host"]; if (!isset($parse["host"])) { continue; } if ($CLIENT == null) { $CLIENT = "-"; } if ($ALLOW == "BLOCK-LD") { $color = "#D0080A"; } if ($ALLOW == "BLOCK") { $color = "#D0080A"; } if ($ALLOW == "REDIR") { $color = "#BAB700"; } if ($ALLOW == "PASS") { $color = "#009223"; } $familysite = $zcat->GetFamilySites($hostname); $familysiteEnc = urlencode($familysite); if ($CLIENT == $CLIENT_IP) { $CLIENT_IP = null; } else { $CLIENT_IP = "/{$CLIENT_IP}"; } $hostname = texttooltip($hostname, "{webfiltering_tasks_explain}", "Loadjs('squid.access.webfilter.tasks.php?familysite={$familysiteEnc}')"); $fontsize = 14; if ($_GET["minsize"] == 1) { $fontsize = 12; } if ($date == $today) { $date = null; } $data['rows'][] = array('id' => md5($line), 'cell' => array("<span style='font-size:{$fontsize}px;color:{$color}'>{$date} {$TIME}</span>", "<span style='font-size:{$fontsize}px;color:{$color}'>{$CLIENT}{$CLIENT_IP}</span>", "<span style='font-size:{$fontsize}px;color:{$color}'>{$RULE}/{$CATEGORY}</span>", "<span style='font-size:{$fontsize}px;color:{$color}'>{$ALLOW}</span>", "<span style='font-size:{$fontsize}px;color:{$color}'>{$PROTO}</span>", "<span style='font-size:{$fontsize}px;color:{$color}'>{$hostname}</span>", "<span style='font-size:{$fontsize}px;color:{$color}'>{$URI}</span>")); } if ($c == 0) { json_error_show("No data"); } $data['total'] = $c; echo json_encode($data); }