Commit 9a1d7dc7 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(ids) add option to drop/reset suricata log file (eve.json*), closes...

(ids) add option to drop/reset suricata log file (eve.json*), closes https://github.com/opnsense/core/issues/997

(cherry picked from commit 40e4bdc2)
(cherry picked from commit 8de70201)
parent c216bc9f
......@@ -311,4 +311,24 @@ class ServiceController extends ApiControllerBase
return array();
}
}
/**
* drop alert log
* @return array status
*/
public function dropAlertLogAction()
{
if ($this->request->isPost()) {
// close session for long running action
$this->sessionClose();
$backend = new Backend();
$filename = $this->request->getPost('filename', 'string', null);
if ($filename != null) {
$filename = basename($filename);
$backend->configdpRun("ids drop alertlog", array($filename));
return array("status" => "ok");
}
}
return array("status" => "failed");
}
}
......@@ -25,4 +25,16 @@
<help><![CDATA[Select interface(s) to use. When enabling IPS, only use physical interfaces here (no vlans etc).]]></help>
<hint>Type or select interface.</hint>
</field>
<field>
<id>ids.general.AlertLogrotate</id>
<label>Rotate log</label>
<type>dropdown</type>
<help><![CDATA[Rotate alert logs at provided interval.]]></help>
</field>
<field>
<id>ids.general.AlertSaveLogs</id>
<label>Save logs</label>
<type>text</type>
<help><![CDATA[Number of logs to keep.]]></help>
</field>
</form>
......@@ -119,6 +119,23 @@
<ValidationMessage>Related cron not found.</ValidationMessage>
<Required>N</Required>
</UpdateCron>
<AlertLogrotate type="OptionField">
<Required>N</Required>
<default>W0D23</default>
<BlankDesc>Default</BlankDesc>
<OptionValues>
<W0D23>Weekly</W0D23>
<D0>Daily</D0>
</OptionValues>
<ValidationMessage>Please select a valid rotation</ValidationMessage>
</AlertLogrotate>
<AlertSaveLogs type="IntegerField">
<Required>N</Required>
<default>4</default>
<MinimumValue>1</MinimumValue>
<MaximumValue>1000</MaximumValue>
<ValidationMessage>Enter a valid number of logs to save</ValidationMessage>
</AlertSaveLogs>
</general>
</items>
</model>
......@@ -69,9 +69,9 @@ POSSIBILITY OF SUCH DAMAGE.
$('#alert-logfile').html("");
$.each(data, function(key, value) {
if (value['sequence'] == undefined) {
$('#alert-logfile').append($("<option></option>").attr("value",'none').text(value['modified']));
$('#alert-logfile').append($("<option/>").data('filename', value['filename']).attr("value",'none').text(value['modified']));
} else {
$('#alert-logfile').append($("<option></option>").attr("value",value['sequence']).text(value['modified']));
$('#alert-logfile').append($("<option/>").data('filename', value['filename']).attr("value",value['sequence']).text(value['modified']));
}
});
$('.selectpicker').selectpicker('refresh');
......@@ -427,6 +427,34 @@ POSSIBILITY OF SUCH DAMAGE.
history.pushState(null, null, e.target.hash);
});
// delete selected alert log
$("#actDeleteLog").click(function(){
var selected_log = $("#alert-logfile > option:selected");
BootstrapDialog.show({
type:BootstrapDialog.TYPE_DANGER,
title: '{{ lang._('Remove log file ') }} ' + selected_log.html(),
message: '{{ lang._('Removing this file will cleanup disk space, but cannot be undone.') }}',
buttons: [{
icon: 'fa fa-trash-o',
label: '{{ lang._('Yes') }}',
cssClass: 'btn-primary',
action: function(dlg){
ajaxCall(url="/api/ids/service/dropAlertLog/",sendData={filename: selected_log.data('filename')},
callback=function(data,status){
updateAlertLogs();
});
dlg.close();
}
}, {
label: 'Close',
action: function(dlg){
dlg.close();
}
}]
});
});
});
......@@ -568,6 +596,7 @@ POSSIBILITY OF SUCH DAMAGE.
<div class="row">
<div class="col-sm-12 actionBar">
<select id="alert-logfile" class="selectpicker" data-width="200px"></select>
<span id="actDeleteLog" class="btn btn-lg fa fa-trash" style="cursor: pointer;"></span>
<select id="alert-logfile-max" class="selectpicker" data-width="80px">
<option value="7">7</option>
<option value="50">50</option>
......
#!/usr/local/bin/python2.7
"""
Copyright (c) 2016 Ad Schellevis
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.
--------------------------------------------------------------------------------------
drop requested alert log
"""
import os
import sys
import glob
from lib import suricata_alert_log
if __name__ == '__main__' and len(sys.argv) > 1:
result = []
for filename in glob.glob('%s*' % suricata_alert_log):
if os.path.basename(filename) == sys.argv[1]:
if os.path.basename(filename) == 'eve.json':
# current logfile, truncate to 0
with open(filename, 'wb') as f:
f.truncate()
else:
# archive, remove
os.remove(filename)
print ("removed %s" % filename)
......@@ -22,6 +22,12 @@ parameters:
type:script_output
message:list available suricata alert logs
[drop.alertlog]
command:/usr/local/opnsense/scripts/suricata/dropAlertLog.py
parameters:%s
type:script_output
message:drop suricata alert log %s
[query.rules]
command:/usr/local/opnsense/scripts/suricata/queryInstalledRules.py
parameters:/limit %s /offset %s /filter %s /sort_by %s
......
......@@ -2,5 +2,7 @@
{% if helpers.exists('OPNsense.IDS.general') and OPNsense.IDS.general.enabled|default("0") == "1" %}
/var/log/suricata/stats.log root:wheel 640 7 * $D0 B /var/run/suricata.pid 1
/var/log/suricata.log root:wheel 640 7 * $D0 B /var/run/suricata.pid 1
/var/log/suricata/eve.json root:wheel 640 4 * $W0D23 B /var/run/suricata.pid 1
/var/log/suricata/eve.json root:wheel 640 {{ OPNsense.IDS.general.AlertSaveLogs|default("4") }} * ${{
OPNsense.IDS.general.AlertLogrotate|default("W0D23")
}} B /var/run/suricata.pid 1
{% endif %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment