-
Notifications
You must be signed in to change notification settings - Fork 596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Squid - dashboard widget bootstrap facelift + fixes #270
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
83187fc
Squid - dashboard widget bootstrap facelift + fixes
doktornotor 5352e4f
Bump port revision
doktornotor 6395394
Update description
doktornotor 9f70ab8
Do not hardcode version here, use pkg_exec()
doktornotor 6e417d8
Produce some valid HTML on virus warning page
doktornotor 0ee0aa1
Rename priv; there is only one Squid version left in pfSense
doktornotor f383279
Check pkg_exec() return code
doktornotor d8381d4
Check pkg_exec() return code
doktornotor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* squid_antivirus_status.widget.php | ||
* | ||
* part of pfSense (https://www.pfsense.org) | ||
* Copyright (c) 2015 Rubicon Communications, LLC (Netgate) | ||
* Copyright (c) 2015-2017 Rubicon Communications, LLC (Netgate) | ||
* Copyright (C) 2010 Serg Dvoriancev <[email protected]> | ||
* All rights reserved. | ||
* | ||
|
@@ -20,25 +20,25 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
require_once("functions.inc"); | ||
require_once("guiconfig.inc"); | ||
require_once("pfsense-utils.inc"); | ||
require_once("functions.inc"); | ||
require_once("pkg-utils.inc"); | ||
require_once("service-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."; | ||
echo "No squid.inc found. You must have Squid 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; | ||
global $clamd_path, $img; | ||
$clamd_path = SQUID_BASE . "/sbin/clamd"; | ||
$cicap_cfg_path = SQUID_LOCALBASE . "/bin/c-icap-config"; | ||
$img = array(); | ||
$img['up'] = "<img src='data:image/gif;base64,R0lGODlhCwALAIABACPcMP///yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgABACwAAAAACwALAAACFYwNpwi50eKK9NA722Puyf15GjgaBQA7' title='Service running' alt='' />"; | ||
$img['down'] = "<img src='data:image/gif;base64,R0lGODlhCwALAIABANwjI////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgABACwAAAAACwALAAACFowDeYvKlsCD7sXZ5Iq89kpdFshoRwEAOw==' title='Service not running' alt='' />"; | ||
$img['up'] = '<i class="fa fa-level-up text-success" title="Service running"></i>'; | ||
$img['down'] = '<i class="fa fa-level-down text-danger" title="Service not running"></i>'; | ||
|
||
function squid_avdb_info($filename) { | ||
$stl = "style='padding-top: 0px; padding-bottom: 0px; padding-left: 4px; padding-right: 4px; border-left: 1px solid #999999;'"; | ||
|
@@ -49,11 +49,11 @@ function squid_avdb_info($filename) { | |
if ($handle = fopen($path, "r")) { | ||
$s = fread($handle, 1024); | ||
$s = explode(':', $s); | ||
# datetime | ||
// datetime | ||
$dt = explode(" ", $s[1]); | ||
$s[1] = strftime("%Y.%m.%d", strtotime("{$dt[0]} {$dt[1]} {$dt[2]}")); | ||
if ($s[0] == 'ClamAV-VDB') { | ||
$r .= "<tr class='listr'><td>{$filename}</td><td {$stl}>{$s[1]}</td><td {$stl}>{$s[2]}</td><td $stl>{$s[7]}</td></tr>"; | ||
$r .= "<tr><td>{$filename}</td><td {$stl}>{$s[1]}</td><td {$stl}>{$s[2]}</td><td $stl>{$s[7]}</td></tr>"; | ||
} | ||
fclose($handle); | ||
} | ||
|
@@ -62,8 +62,8 @@ function squid_avdb_info($filename) { | |
} | ||
|
||
function squid_antivirus_bases_info() { | ||
$db = '<table width="100%" border="0" cellspacing="0" cellpadding="1"><tbody>'; | ||
$db .= '<tr class="vncellt" ><td>Database</td><td>Date</td><td>Version</td><td>Builder</td></tr>'; | ||
$db = '<table class="table table-striped table-hover table-condensed"><tbody>'; | ||
$db .= '<tr><th>Database</th><th>Date</th><th>Version</th><th>Builder</th></tr>'; | ||
$avdbs = array("daily.cvd", "daily.cld", "bytecode.cvd", "bytecode.cld", "main.cvd", "main.cld", "safebrowsing.cvd", "safebrowsing.cld"); | ||
foreach ($avdbs as $avdb) { | ||
$db .= squid_avdb_info($avdb); | ||
|
@@ -73,27 +73,19 @@ function squid_antivirus_bases_info() { | |
} | ||
|
||
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"; | ||
} | ||
global $img; | ||
// ClamAV status and version | ||
$s = (is_service_running("clamd") ? $img['up'] : $img['down']); | ||
pkg_exec("query '%v' clamav", $version, $err); | ||
$s .= " ClamAV {$version}"; | ||
$s .= " "; | ||
// C-ICAP status and version | ||
$s .= (is_service_running("c-icap") ? $img['up'] : $img['down']); | ||
pkg_exec("query '%v' c-icap", $version, $err); | ||
$s .= " C-ICAP {$version}"; | ||
// SquidClamav version | ||
pkg_exec("query '%v' squidclamav", $version, $err); | ||
$s .= "+ SquidClamav {$version}"; | ||
return $s; | ||
} | ||
|
||
|
@@ -119,11 +111,12 @@ function squid_antivirus_statistics() { | |
|
||
?> | ||
|
||
<table width="100%" border="0" cellspacing="0" cellpadding="0"> | ||
<div class="table-responsive"> | ||
<table class="table table-striped table-hover table-condensed"> | ||
<tbody> | ||
<tr> | ||
<td class="vncellt">Squid Version</td> | ||
<td class="listr" width="75%"> | ||
<th>Squid Version</th> | ||
<td width="75%"> | ||
<?php | ||
$updown = (is_service_running("squid") ? $img['up'] : $img['down']); | ||
pkg_exec("query '%v' squid", $version, $err); | ||
|
@@ -132,28 +125,29 @@ function squid_antivirus_statistics() { | |
</td> | ||
</tr> | ||
<tr> | ||
<td class="vncellt">Antivirus Scanner</td> | ||
<td class="listr" width="75%"> | ||
<th>Antivirus Scanner</th> | ||
<td width="75%"> | ||
<?php echo squid_clamav_version(); ?> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td class="vncellt">Antivirus Bases</td> | ||
<td class="listr" width="75%"> | ||
<th style="vertical-align:middle;">Antivirus Bases</th> | ||
<td width="75%"> | ||
<?php echo squid_antivirus_bases_info(); ?> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td class="vncellt">Last Update</td> | ||
<td class="listr" width="75%"> | ||
<th>Last Update</th> | ||
<td width="75%"> | ||
<?php echo squid_avupdate_status(); ?> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td class="vncellt">Statistics</td> | ||
<td class="listr" width="75%"> | ||
<th>Statistics</th> | ||
<td width="75%"> | ||
<?php echo squid_antivirus_statistics(); ?> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</table> | ||
</div> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's missing to check pkg_exec return code to make sure it succeeded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it is working perfectly fine here? confused The version is in
$version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg_exec returns 0 for success and != 0 when it fails. It would be good to check if return is 0 before assume $version really contains a valid value