security/clamav: make freshclam fetch a bit more clever

This commit is contained in:
Franco Fichtner
2017-08-10 12:48:12 +02:00
parent 8b5af2e44a
commit 929cca97e6
5 changed files with 115 additions and 49 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
PLUGIN_NAME= clamav
PLUGIN_VERSION= 0.1
PLUGIN_VERSION= 0.2
PLUGIN_COMMENT= Antivirus engine for detecting malicious threats
PLUGIN_DEPENDS= clamav
PLUGIN_MAINTAINER= m.muenz@gmail.com
@@ -43,16 +43,21 @@ class ServiceController extends ApiControllerBase
{
/**
* load the initial signatures
* @param string $command test or go fetch
* @return array
*/
public function freshclamAction()
{
if ($this->request->isPost()) {
$backend = new Backend();
$response = $backend->configdRun("clamav freshclam");
return array("response" => $response);
$command = 'clamav freshclam';
if ($this->request->hasPost('action')) {
$command .= ' go';
}
$response = trim($backend->configdRun($command));
return array('status' => $response);
} else {
return array("response" => array());
return array('status' => 'error');
}
}
/**
@@ -26,12 +26,12 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
#}
<?php if (!file_exists('/var/db/clamav/main.cvd')): ?>
<div class="alert alert-warning" role="alert" style="min-height: 65px;">
<button class='btn btn-primary pull-right' id="dl_sig" type="button">{{ lang._('Download signatures') }}<i id="dl_sig_progress"></i> </button>
<div style="margin-top: 8px;" id="dl_sig_err">{{ lang._('No signature database found, please download before starting. Download will take several minutes, come back in a few moments until this message is gone. If you have memory file system enabled where /var is mounted into RAM you have to download this file with every reboot.')}}</div>
</div>
<?php endif ?>
<div class="alert alert-warning" role="alert" id="dl_sig_alert" style="display:none;min-height:65px;">
<button class="btn btn-primary pull-right" id="dl_sig" type="button">{{ lang._('Download signatures') }} <i id="dl_sig_progress"></i></button>
<div style="margin-top: 8px;">{{ lang._('No signature database found, please download before use. The download will take several minutes and this message will disappear when it has been completed. If you have memory file system enabled where /var is mounted into RAM you have to download this file with every reboot.')}}</div>
</div>
<div class="tab-content content-box tab-content">
<div id="general" class="tab-pane fade in active">
<div class="content-box" style="padding-bottom: 1.5em;">
@@ -45,40 +45,58 @@ POSSIBILITY OF SUCH DAMAGE.
</div>
<script type="text/javascript">
$( document ).ready(function() {
var data_get_map = {'frm_general_settings':"/api/clamav/general/get"};
mapDataToFormUI(data_get_map).done(function(data){
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
});
ajaxCall(url="/api/clamav/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
// link save button to API set action
$("#saveAct").click(function(){
saveFormToEndpoint(url="/api/clamav/general/set", formid='frm_general_settings',callback_ok=function(){
$("#saveAct_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/clamav/service/reconfigure", sendData={}, callback=function(data,status) {
ajaxCall(url="/api/clamav/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
$("#saveAct_progress").removeClass("fa fa-spinner fa-pulse");
});
});
});
$("#dl_sig").click(function(){
ajaxCall(url="/api/clamav/service/freshclam", callback_ok=function(){
$("#dl_sig_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/clamav/service/reconfigure", sendData={}, callback=function(data,status) {
ajaxCall(url="/api/clamav/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
$("#dl_sig_progress").removeClass("fa fa-spinner fa-pulse");
});
});
});
function timeoutCheck() {
ajaxCall(url="/api/clamav/service/freshclam", sendData={}, callback=function(data,status) {
if (data['status'] == 'done') {
$("#dl_sig_progress").removeClass("fa fa-spinner fa-pulse");
$("#dl_sig").prop("disabled", false);
$('#dl_sig_alert').hide();
} else {
setTimeout(timeoutCheck, 2500);
}
});
}
$( document ).ready(function() {
var data_get_map = {'frm_general_settings':"/api/clamav/general/get"};
mapDataToFormUI(data_get_map).done(function(data){
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
});
ajaxCall(url="/api/clamav/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
ajaxCall(url="/api/clamav/service/freshclam", sendData={}, callback=function(data,status) {
if (data['status'] != 'done') {
if (data['status'] == 'running') {
$("#dl_sig_progress").addClass("fa fa-spinner fa-pulse");
$("#dl_sig").prop("disabled", true);
setTimeout(timeoutCheck, 2500);
}
$('#dl_sig_alert').show();
}
});
$("#saveAct").click(function(){
saveFormToEndpoint(url="/api/clamav/general/set", formid='frm_general_settings',callback_ok=function(){
$("#saveAct_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/clamav/service/reconfigure", sendData={}, callback=function(data,status) {
ajaxCall(url="/api/clamav/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
$("#saveAct_progress").removeClass("fa fa-spinner fa-pulse");
});
});
});
$("#dl_sig").click(function(){
$("#dl_sig_progress").addClass("fa fa-spinner fa-pulse");
$("#dl_sig").prop("disabled", true);
ajaxCall(url="/api/clamav/service/freshclam", sendData={action:1}, callback_ok=function(){
setTimeout(timeoutCheck, 2500);
});
});
});
</script>
@@ -0,0 +1,43 @@
#!/bin/sh
# Copyright (c) 2017 Franco Fichtner <franco@opnsense.org>
#
# 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
PIDFILE="/var/run/clamav/freshclam-init.pid"
DBFILE="/var/db/clamav/main.cvd"
COMMAND="${1}"
if [ -f ${DBFILE} ]; then
echo "done"
elif pgrep -qF ${PIDFILE} 2> /dev/null; then
echo "running"
elif [ -z "${COMMAND}" ]; then
echo "missing"
else
daemon -f -p ${PIDFILE} freshclam --quiet
echo "starting"
fi
exit 0
@@ -29,7 +29,7 @@ type:script_output
message:request ClamAV status
[freshclam]
command:/usr/sbin/daemon -f -p /var/run/clamav/freshclam-init.pid freshclam --quiet
parameters:
type:script
message:downloading signatures
command:/usr/local/opnsense/scripts/OPNsense/ClamAV/freshclam.sh
parameters:%s
type:script_output
message:Check or install signatures