summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2025-05-22 18:07:09 +0200
committerSimon Rettberg2025-05-22 18:07:09 +0200
commit3ae8d417ae410cf1d00b187a2f736d2a1ee50f5c (patch)
treef0e3ee00894cce78903dec50c3254258ed080e60
parent[serversetup-bwlp-ipxe] Open entry editor as popup from menu editor (diff)
downloadslx-admin-3ae8d417ae410cf1d00b187a2f736d2a1ee50f5c.tar.gz
slx-admin-3ae8d417ae410cf1d00b187a2f736d2a1ee50f5c.tar.xz
slx-admin-3ae8d417ae410cf1d00b187a2f736d2a1ee50f5c.zip
[syslog/eventlog] Allow creating filter rule based on client log entry
-rw-r--r--modules-available/eventlog/pages/rules.inc.php71
-rw-r--r--modules-available/eventlog/templates/page-filters-edit-rule.html2
-rw-r--r--modules-available/eventlog/templates/page-filters-rules.html6
-rw-r--r--modules-available/syslog/templates/page-syslog.html6
4 files changed, 59 insertions, 26 deletions
diff --git a/modules-available/eventlog/pages/rules.inc.php b/modules-available/eventlog/pages/rules.inc.php
index 94ca473b..6e1fada2 100644
--- a/modules-available/eventlog/pages/rules.inc.php
+++ b/modules-available/eventlog/pages/rules.inc.php
@@ -90,9 +90,9 @@ class SubPage
public static function doRender()
{
User::assertPermission('filter.rules.view');
- $id = Request::get('id', null, 'int');
- if ($id !== null) {
- self::showRuleEditor($id);
+ $action = Request::get('action');
+ if ($action === 'editrule') {
+ self::showRuleEditor();
} else {
// LIST
$data = [];
@@ -114,28 +114,58 @@ class SubPage
/**
* @param int $id Rule to edit. If id is 0, a new rule will be created.
*/
- private static function showRuleEditor(int $id)
+ private static function showRuleEditor()
{
// EDIT
User::assertPermission('filter.rules.edit');
$filterIdx = 0;
$knownIdxList = [];
- if ($id !== 0) {
- $data = Database::queryFirst('SELECT ruleid, title, description, type, datafilter, subject, message, predefid
+ $id = Request::get('id', null, 'int');
+ if ($id === 0) {
+ // New entry
+ $data = ['filter' => [], 'ruleid' => 0];
+ } else {
+ if ($id > 0) {
+ $data = Database::queryFirst('SELECT ruleid, title, description, type, datafilter, subject, message, predefid
FROM notification_rule WHERE ruleid = :id', ['id' => $id]);
- if ($data === false) {
- Message::addError('invalid-rule-id', $id);
- Util::redirect('?do=eventlog&show=rules');
- }
- $data['edit_warn'] = $data['predefid'] !== null;
- if (Request::get('copy', false, 'bool')) {
- $data['ruleid'] = 0;
- $data['title'] = '';
- $data['edit_warn'] = false;
- }
- $list = json_decode($data['datafilter'], true);
- if (!is_array($list['list'])) {
- $list['list'] = [];
+ if ($data === false) {
+ Message::addError('invalid-rule-id', $id);
+ Util::redirect('?do=eventlog&show=rules');
+ }
+ $data['edit_warn'] = $data['predefid'] !== null;
+ if (Request::get('copy', false, 'bool')) {
+ $data['ruleid'] = 0;
+ $data['title'] = '';
+ $data['edit_warn'] = false;
+ }
+ $list = (array)json_decode($data['datafilter'], true);
+ if (!is_array($list['list'])) {
+ $list['list'] = [];
+ }
+ } else {
+ // New from URL
+ $data = [
+ 'ruleid' => 0,
+ 'type' => Request::get('type', Request::REQUIRED, 'string'),
+ 'subject' => Request::get('subject', '', 'string'),
+ 'message' => Request::get('message', '', 'string'),
+ ];
+ $list = ['list' => []];
+ foreach (Request::get('filter', [], 'array') as $key => $filter) {
+ $list['list'][] = [
+ 'index' => $filterIdx++,
+ 'path' => $key,
+ 'op' => '=',
+ 'arg' => $filter,
+ ];
+ }
+ foreach (Request::get('exists', [], 'array') as $key) {
+ $list['list'][] = [
+ 'index' => $filterIdx++,
+ 'path' => $key,
+ 'op' => '*',
+ ];
+ }
}
foreach ($list['list'] as $item) {
if (isset($item['index'])) {
@@ -158,9 +188,6 @@ class SubPage
}
}
$data['filter'] = $list['list'];
- } else {
- // New entry
- $data = ['filter' => [], 'ruleid' => 0];
}
// Add suggestions for type
$data['types'] = Database::queryColumnArray("SELECT DISTINCT type
diff --git a/modules-available/eventlog/templates/page-filters-edit-rule.html b/modules-available/eventlog/templates/page-filters-edit-rule.html
index 374b4ee6..74b6af9b 100644
--- a/modules-available/eventlog/templates/page-filters-edit-rule.html
+++ b/modules-available/eventlog/templates/page-filters-edit-rule.html
@@ -8,7 +8,7 @@
</h2>
{{#edit_warn}}
<div class="alert alert-info">
- <a class="pull-right btn btn-xs btn-default" href="?do=eventlog&amp;show=rules&amp;id={{ruleid}}&amp;copy=1" title="{{lang_copy}}">
+ <a class="pull-right btn btn-xs btn-default" href="?do=eventlog&amp;show=rules&amp;action=editrule&amp;id={{ruleid}}&amp;copy=1" title="{{lang_copy}}">
<span class="glyphicon glyphicon-duplicate" aria-label="{{lang_copy}}"></span>
</a>
{{lang_noticeEditingExample}}
diff --git a/modules-available/eventlog/templates/page-filters-rules.html b/modules-available/eventlog/templates/page-filters-rules.html
index d65b9bb4..a7fdbdfe 100644
--- a/modules-available/eventlog/templates/page-filters-rules.html
+++ b/modules-available/eventlog/templates/page-filters-rules.html
@@ -31,11 +31,11 @@
</td>
<td class="slx-smallcol">
<a class="btn btn-xs btn-default {{perms.filter.rules.edit.disabled}}"
- href="?do=eventlog&amp;show=rules&amp;id={{ruleid}}" title="{{lang_edit}}">
+ href="?do=eventlog&amp;show=rules&amp;action=editrule&amp;id={{ruleid}}" title="{{lang_edit}}">
<span class="glyphicon glyphicon-edit" aria-label="{{lang_edit}}"></span>
</a>
<a class="btn btn-xs btn-default {{perms.filter.rules.edit.disabled}}"
- href="?do=eventlog&amp;show=rules&amp;id={{ruleid}}&amp;copy=1" title="{{lang_copy}}">
+ href="?do=eventlog&amp;show=rules&amp;action=editrule&amp;id={{ruleid}}&amp;copy=1" title="{{lang_copy}}">
<span class="glyphicon glyphicon-duplicate" aria-label="{{lang_copy}}"></span>
</a>
<button class="btn btn-xs btn-danger" type="submit" name="id" value="{{ruleid}}" title="{{lang_delete}}"
@@ -51,7 +51,7 @@
</form>
<div class="buttonbar text-right">
- <a class="btn btn-success {{perms.filter.rules.edit.disabled}}" href="?do=eventlog&amp;show=rules&amp;id=0">
+ <a class="btn btn-success {{perms.filter.rules.edit.disabled}}" href="?do=eventlog&amp;show=rules&amp;action=editrule&amp;id=0">
<span class="glyphicon glyphicon-plus"></span>
{{lang_add}}
</a>
diff --git a/modules-available/syslog/templates/page-syslog.html b/modules-available/syslog/templates/page-syslog.html
index 2b7c1439..33be4ab7 100644
--- a/modules-available/syslog/templates/page-syslog.html
+++ b/modules-available/syslog/templates/page-syslog.html
@@ -42,6 +42,7 @@
<th class="text-center">{{lang_client}}</th>
<th class="text-center">{{lang_event}}</th>
<th width="1">{{lang_details}}</th>
+ <th width="1">{{lang_addFilter}}</th>
</thead>
<tbody>
{{#list}}
@@ -55,6 +56,11 @@
data-toggle="modal" data-target="#myModal">&raquo;</a>
<div class="hidden" id="extra-{{logid}}">{{extra}}</div>
{{/extra}}</td>
+ <td class="text-center">
+ <a class="btn btn-default btn-xs" href="?do=eventlog&amp;show=rules&amp;action=editrule&amp;type={{logtypeid}}&amp;filter[description]={{description}}&amp;exists[]=clientip&amp;subject=Event+{{logtypeid}}&amp;message=IP%3A+%251%25%2C+Content%3A+%250%25">
+ <span class="glyphicon glyphicon-plus"></span>
+ </a>
+ </td>
</tr>
{{/list}}
</tbody>