From 88fd464b6cc951c0e4339e169dc40c13ddfa3480 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sun, 11 Oct 2015 15:59:50 +0200 Subject: Add Squid3 antivirus widget --- config/squid3/34/squid_antivirus_status.widget.php | 176 +++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 config/squid3/34/squid_antivirus_status.widget.php (limited to 'config/squid3') diff --git a/config/squid3/34/squid_antivirus_status.widget.php b/config/squid3/34/squid_antivirus_status.widget.php new file mode 100644 index 00000000..8d96a3a1 --- /dev/null +++ b/config/squid3/34/squid_antivirus_status.widget.php @@ -0,0 +1,176 @@ + + Copyright (C) 2015 ESF, LLC + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ +require_once("guiconfig.inc"); +require_once("pfsense-utils.inc"); +require_once("functions.inc"); +require_once("pkg-utils.inc"); +if (file_exists("/usr/local/pkg/squid.inc")) { + require_once("/usr/local/pkg/squid.inc"); +} else { + echo "No squid.inc found. You must have Squid3 package installed to use this widget."; +} + +define('PATH_CLAMDB', '/var/db/clamav'); +define('PATH_SQUID', SQUID_BASE . '/bin/squid'); +define('PATH_AVLOG', '/var/log/c-icap/virus.log'); +global $clamd_path, $cicap_cfg_path, $img; +$clamd_path = SQUID_BASE . "/bin/clamd"; +$cicap_cfg_path = SQUID_LOCALBASE . "/bin/c-icap-config"; +$img = array(); +$img['up'] = ""; +$img['down'] = ""; + +function squid_avdb_info($filename) { + $stl = "style='padding-top: 0px; padding-bottom: 0px; padding-left: 4px; padding-right: 4px; border-left: 1px solid #999999;'"; + $r = ''; + $path = PATH_CLAMDB . "/{$filename}"; + if (file_exists($path)) { + $handle = ''; + if ($handle = fopen($path, "r")) { + $s = fread($handle, 1024); + $s = explode(':', $s); + # datetime + $dt = explode(" ", $s[1]); + $s[1] = strftime("%Y.%m.%d", strtotime("{$dt[0]} {$dt[1]} {$dt[2]}")); + if ($s[0] == 'ClamAV-VDB') { + $r .= "{$filename}{$s[1]}{$s[2]}{$s[7]}"; + } + fclose($handle); + } + return $r; + } +} + +function squid_antivirus_bases_info() { + $db = ''; + $db .= ''; + $db .= squid_avdb_info("daily.cvd"); + $db .= squid_avdb_info("bytecode.cvd"); + $db .= squid_avdb_info("main.cvd"); + $db .= squid_avdb_info("safebrowsing.cvd"); + $db .= '
DatabaseDateVersionBuilder
'; + return $db; +} + +function squid_clamav_version() { + global $clamd_path, $cicap_cfg_path, $img; + if (is_executable($clamd_path)) { + $s = (is_service_running("clamd") ? $img['up'] : $img['down']); + $version = preg_split("@/@", shell_exec("{$clamd_path} -V")); + $s .= "  {$version[0]}"; + } else { + $s .= "  ClamAV: N/A"; + } + if (is_executable($cicap_cfg_path)) { + $s .= "  "; + $s .= (is_service_running("c-icap") ? $img['up'] : $img['down']); + $s .= "  C-ICAP " . shell_exec("{$cicap_cfg_path} --version"); + } else { + $s .= "  C-ICAP: N/A"; + } + if (file_exists("/usr/local/www/squid_clwarn.php")) { + preg_match("@(VERSION.*).(\d{1}).(\d{2})@", file_get_contents("/usr/local/www/squid_clwarn.php"), $squidclamav_version); + $s .= "+  SquidClamav " . str_replace("'", "", strstr($squidclamav_version[0], "'")); + } else { + $s .= "+  SquidClamav: N/A"; + } + return $s; +} + +function squid_avupdate_status() { + global $clamd_path; + $s = "N/A"; + if (is_executable($clamd_path)) { + $lastupd = preg_split("@/@", shell_exec("{$clamd_path} -V")); + $s = $lastupd[2]; + } + return $s; +} + +function squid_antivirus_statistics() { + $s = "Unknown (no log exists)"; + if (file_exists(PATH_AVLOG)) { + $log = file_get_contents(PATH_AVLOG); + $count = substr_count(strtolower($log), "virus found"); + $s = "Found {$count} virus(es) total."; + } + return $s; +} + +?> + + + + + + + + + + + + + + + + + + + + + + + + +
Squid Version + +
Antivirus Scanner + +
Antivirus Bases + +
Last Update + +
Statistics + +
-- cgit v1.2.3