summaryrefslogtreecommitdiffstats
path: root/modules-available/eventlog
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/eventlog')
-rw-r--r--modules-available/eventlog/hooks/cron.inc.php66
-rw-r--r--modules-available/eventlog/inc/filterruleprocessor.inc.php350
-rw-r--r--modules-available/eventlog/inc/notificationtransport.inc.php279
-rw-r--r--modules-available/eventlog/install.inc.php83
-rw-r--r--modules-available/eventlog/lang/de/messages.json9
-rw-r--r--modules-available/eventlog/lang/de/module.json2
-rw-r--r--modules-available/eventlog/lang/de/permissions.json8
-rw-r--r--modules-available/eventlog/lang/de/template-tags.json60
-rw-r--r--modules-available/eventlog/lang/en/messages.json9
-rw-r--r--modules-available/eventlog/lang/en/module.json2
-rw-r--r--modules-available/eventlog/lang/en/permissions.json8
-rw-r--r--modules-available/eventlog/lang/en/template-tags.json60
-rw-r--r--modules-available/eventlog/page.inc.php85
-rw-r--r--modules-available/eventlog/pages/log.inc.php56
-rw-r--r--modules-available/eventlog/pages/mailconfigs.inc.php99
-rw-r--r--modules-available/eventlog/pages/rules.inc.php187
-rw-r--r--modules-available/eventlog/pages/transports.inc.php179
-rw-r--r--modules-available/eventlog/permissions/permissions.json18
-rw-r--r--modules-available/eventlog/templates/_page.html13
-rw-r--r--modules-available/eventlog/templates/heading.html1
-rw-r--r--modules-available/eventlog/templates/page-filters-edit-mailconfig.html53
-rw-r--r--modules-available/eventlog/templates/page-filters-edit-rule.html219
-rw-r--r--modules-available/eventlog/templates/page-filters-edit-transport.html190
-rw-r--r--modules-available/eventlog/templates/page-filters-mailconfigs.html42
-rw-r--r--modules-available/eventlog/templates/page-filters-rules.html48
-rw-r--r--modules-available/eventlog/templates/page-filters-transports.html45
-rw-r--r--modules-available/eventlog/templates/page-header.html16
27 files changed, 2142 insertions, 45 deletions
diff --git a/modules-available/eventlog/hooks/cron.inc.php b/modules-available/eventlog/hooks/cron.inc.php
index 180bafd3..05a6921e 100644
--- a/modules-available/eventlog/hooks/cron.inc.php
+++ b/modules-available/eventlog/hooks/cron.inc.php
@@ -1,5 +1,69 @@
<?php
if (mt_rand(1, 10) === 1) {
- Database::exec("DELETE FROM eventlog WHERE (UNIX_TIMESTAMP() - 86400 * 190) > dateline");
+ // One year of event log
+ Database::exec("DELETE FROM eventlog WHERE (UNIX_TIMESTAMP() - 86400 * 365) > dateline");
+ // Keep at least 20 events or 7 days worth of samples (whichever is more)
+ $types = Database::simpleQuery("SELECT type, Count(*) AS num, Min(dateline) as oldest
+ FROM `notification_sample` GROUP BY type");
+ $cutoff = time() - 86400 * 7;
+ $maxCutoff = time() - 86400 * 365; // But don't keep anything for more than a year
+ foreach ($types as $type) {
+ if ($type['num'] > 20 && $type['oldest'] < $cutoff) {
+ // This type has more than 30 and the oldest one is older than 7 days
+ // find out which one takes priority
+ $thisCutoff = $cutoff;
+ $find = Database::queryFirst("SELECT dateline FROM notification_sample
+ WHERE type = :type AND dateline
+ ORDER BY dateline DESC
+ LIMIT 29, 1",
+ ['type' => $type['type']]);
+ // The 30th entry is older than 7 days? Bump the cutoff dateline back to this date,
+ // so we keep at least 20 entries
+ if ($find !== false && $find['dateline'] < $thisCutoff) {
+ $thisCutoff = $find['dateline'];
+ }
+ Database::exec("DELETE FROM notification_sample
+ WHERE type = :type AND dateline < :dateline",
+ ['type' => $type['type'], 'dateline' => max($thisCutoff, $maxCutoff)]);
+ }
+ }
}
+
+// Add missing/virtual columns to sample data
+$todo = Database::simpleQuery("SELECT sampleid, data FROM notification_sample WHERE extended = 0 LIMIT 10");
+foreach ($todo as $sample) {
+ $data = json_decode($sample['data'], true);
+ // First, add all the machine columns
+ if (isset($data['machineuuid'])) {
+ $row = Database::queryFirst("SELECT " . implode(',', FilterRuleProcessor::MACHINE_COLUMNS)
+ . " FROM machine WHERE machineuuid = :uuid", ['uuid' => $data['machineuuid']]);
+ } elseif (isset($data['clientip'])) {
+ $row = Database::queryFirst("SELECT " . implode(',', FilterRuleProcessor::MACHINE_COLUMNS)
+ . " FROM machine WHERE clientip = :ip ORDER BY lastseen DESC LIMIT 1", ['ip' => $data['clientip']]);
+ } else {
+ $row = false;
+ }
+ if ($row !== false) {
+ $data += $row;
+ }
+ // Add virtual statistics columns
+ if (isset($data['machineuuid']) && Module::isAvailable('statistics')) {
+ foreach (FilterRuleProcessor::HW_QUERIES as $key => $elem) {
+ if (isset($data[$key]))
+ continue; // Already present...
+ $q = new HardwareQuery($elem[0], $data['machineuuid']);
+ $q->addColumn($elem[2], $elem[1]);
+ $res = $q->query();
+ if ($res !== false) {
+ $row = $res->fetch();
+ if ($row !== false && $row[$elem[1]] !== null) {
+ $data[$key] = $row[$elem[1]];
+ }
+ }
+ }
+ }
+ // Finally, update entry
+ Database::exec("UPDATE notification_sample SET extended = 1, data = :data WHERE sampleid = :id",
+ ['id' => $sample['sampleid'], 'data' => json_encode($data)]);
+} \ No newline at end of file
diff --git a/modules-available/eventlog/inc/filterruleprocessor.inc.php b/modules-available/eventlog/inc/filterruleprocessor.inc.php
new file mode 100644
index 00000000..dd0160d7
--- /dev/null
+++ b/modules-available/eventlog/inc/filterruleprocessor.inc.php
@@ -0,0 +1,350 @@
+<?php
+
+class FilterRuleProcessor
+{
+
+ const MACHINE_COLUMNS = ['machineuuid', 'clientip', 'locationid', 'macaddr', 'firstseen', 'lastseen', 'logintime',
+ 'lastboot', 'state', 'realcores', 'mbram', 'kvmstate', 'cpumodel', 'systemmodel', 'id44mb', 'id45mb',
+ 'live_memsize', 'live_tmpsize', 'live_swapsize', 'live_id45size', 'live_memfree', 'live_tmpfree',
+ 'live_swapfree', 'live_id45free', 'live_cpuload', 'live_cputemp', 'badsectors', 'hostname', 'currentrunmode',
+ 'currentsession', 'currentuser', 'notes', 'standbysem'];
+
+ // <device-type>, <property>, <is_global_property>
+ const HW_QUERIES = [
+ 'cpu_sockets' => [HardwareInfo::MAINBOARD, 'cpu-sockets', false],
+ 'cpu_cores' => [HardwareInfo::MAINBOARD, 'cpu-cores', false],
+ 'cpu_threads' => [HardwareInfo::MAINBOARD, 'cpu-threads', false],
+
+ 'ram_max' => [HardwareInfo::MAINBOARD, 'Memory Maximum Capacity', true],
+ 'ram_slots' => [HardwareInfo::MAINBOARD, 'Memory Slot Count', true],
+ 'ram_manufacturer' => [HardwareInfo::RAM_MODULE, 'Manufacturer', true],
+ 'ram_part_no' => [HardwareInfo::RAM_MODULE, 'Part Number', true],
+ 'ram_speed_design' => [HardwareInfo::RAM_MODULE, 'Speed', true],
+ 'ram_speed_current' => [HardwareInfo::RAM_MODULE, 'Configured Memory Speed', false],
+ 'ram_size' => [HardwareInfo::RAM_MODULE, 'Size', true],
+ 'ram_type' => [HardwareInfo::RAM_MODULE, 'Type', true],
+ 'ram_form_factor' => [HardwareInfo::RAM_MODULE, 'Form Factor', true],
+ 'ram_serial_no' => [HardwareInfo::RAM_MODULE, 'Serial Number', false],
+ 'ram_voltage_min' => [HardwareInfo::RAM_MODULE, 'Minimum Voltage', true],
+ 'ram_voltage_max' => [HardwareInfo::RAM_MODULE, 'Maximum Voltage', true],
+ 'ram_voltage_current' => [HardwareInfo::RAM_MODULE, 'Configured Voltage', false],
+
+ 'mobo_manufacturer' => [HardwareInfo::MAINBOARD, 'Manufacturer', true],
+ 'mobo_product' => [HardwareInfo::MAINBOARD, 'Product Name', true],
+ 'mobo_type' => [HardwareInfo::MAINBOARD, 'Type', true],
+ 'mobo_version' => [HardwareInfo::MAINBOARD, 'Version', true],
+ 'mobo_serial_no' => [HardwareInfo::MAINBOARD, 'Serial Number', false],
+ 'mobo_asset_tag' => [HardwareInfo::MAINBOARD, 'Asset Tag', false],
+
+ 'sys_manufacturer' => [HardwareInfo::DMI_SYSTEM, 'Manufacturer', true],
+ 'sys_product' => [HardwareInfo::DMI_SYSTEM, 'Product Name', true],
+ 'sys_version' => [HardwareInfo::DMI_SYSTEM, 'Version', true],
+ 'sys_wakeup_type' => [HardwareInfo::DMI_SYSTEM, 'Wake-up Type', true],
+ 'sys_serial_no' => [HardwareInfo::DMI_SYSTEM, 'Serial Number', false],
+ 'sys_uuid' => [HardwareInfo::DMI_SYSTEM, 'UUID', false],
+ 'sys_sku' => [HardwareInfo::DMI_SYSTEM, 'SKU Number', false],
+
+ 'pci_class' => [HardwareInfo::PCI_DEVICE, 'class', true],
+ 'pci_vendor' => [HardwareInfo::PCI_DEVICE, 'vendor', true],
+ 'pci_device' => [HardwareInfo::PCI_DEVICE, 'device', true],
+
+ 'hdd_ifspeed' => [HardwareInfo::HDD, 'interface_speed//max', true],
+ 'hdd_blocksize' => [HardwareInfo::HDD, 'physical_block_size', true],
+ 'hdd_rpm' => [HardwareInfo::HDD, 'rotation_rate', true],
+ 'hdd_size' => [HardwareInfo::HDD, 'size', true],
+ 'hdd_sata_version' => [HardwareInfo::HDD, 'sata_version', true],
+ 'hdd_model' => [HardwareInfo::HDD, 'model', true],
+
+ 'nic_speed' => [HardwareInfo::MAINBOARD, 'nic-speed', false],
+ 'nic_duplex' => [HardwareInfo::MAINBOARD, 'nic-duplex', false],
+ ];
+
+ /*
+ * filter:
+ * [
+ * [path, op, arg, result],
+ * ...
+ * ]
+ *
+ * path: slash separated path in multi-dimensional array. Supports "*" for everything on a level
+ * op: <, >, = etc, or "regex"
+ * arg: what to match via op
+ * result: if not empty, a string that's added to the fired event. use %1% for the matched value (simple ops),
+ * or %n% for capture group of regex. supports a couple suffixes like b for bytes, which will turn
+ * a byte value into a human readable string, eg %1b% will turn 1234567 into 1.18MiB.
+ * ts = timestamp, d = duration.
+ */
+
+ /**
+ * Called from anywhere within slx-admin when some form of event happens.
+ * @param string $type the event. Will either be client state like ~poweron, ~runstate etc. or a client log type
+ * @param array $data A structured array containing event specific data that can be matched.
+ */
+ public static function applyFilterRules(string $type, array $data)
+ {
+ static $lastType;
+ // Kinda hacky - if there's a "data" key in the array, and it starts with '{',
+ // we assume it's the large machine hw info blob and discard it.
+ if (isset($data['data']) && $data['data'][0] === '{') {
+ unset($data['data']);
+ }
+ if ($lastType !== $type) {
+ $lastType = $type;
+ $exists = Database::queryFirst("SELECT type
+ FROM notification_sample
+ WHERE type = :type AND dateline > UNIX_TIMESTAMP() - 3600 LIMIT 1",
+ ['type' => $type]);
+ if ($exists === false) {
+ Database::exec("INSERT INTO notification_sample (type, dateline, data)
+ VALUES (:type, UNIX_TIMESTAMP(), :data)", [
+ 'type' => $type,
+ 'data' => json_encode($data),
+ ]);
+ }
+ }
+ $types = explode('-', $type);
+ for ($i = 1; $i < count($types); ++$i) {
+ $types[$i] = $types[$i-1] . '-' . $types[$i];
+ }
+ $res = Database::simpleQuery("SELECT ruleid, datafilter, subject, message
+ FROM notification_rule
+ WHERE type IN (:types)",
+ ['types' => $types]);
+ // Iterate over all matching filter rules
+ foreach ($res as $rule) {
+ if (empty($rule['message']) && empty($rule['subject'])) {
+ error_log('Filter rule with empty subject and message');
+ continue;
+ }
+ $filters = json_decode($rule['datafilter'], true);
+ $globalMatch = true;
+ $values = [];
+ // Iterate over all filter-paths of this rule
+ foreach ($filters['list'] as $key => $filter) {
+ $index = $filter['index'] ?? $key;
+ $path = explode('/', $filter['path']);
+ // Get all items from $data that match the path
+ $items = self::get($path, $data);
+ if (empty($items)) {
+ // If empty, add an empty string to result, so != can match
+ $items[] = '';
+ }
+ // Iterate over matches in $data - can be multiple if path contains '*'
+ foreach ($items as $item) {
+ if ($item === null || is_array($item))
+ continue;
+ $match = self::matches($item, $filter);
+ if ($match === null)
+ continue;
+ // Combine if multiple matches
+ $values[$index] = self::combine($values[$index] ?? [], $match);
+ }
+ if (!isset($values[$index])) {
+ $globalMatch = false;
+ break;
+ }
+ }
+ if ($globalMatch) {
+ self::fireEvent($rule, $values);
+ }
+ }
+ }
+
+ /**
+ * Fire event for given rule, fill templates with data from $values
+ */
+ private static function fireEvent(array $rule, array $values)
+ {
+ $ruleid = (int)$rule['ruleid'];
+ $subject = self::fillTemplate($rule['subject'], $values);
+ $message = self::fillTemplate($rule['message'], $values);
+ $ids = Database::queryColumnArray("SELECT transportid
+ FROM notification_rule_x_transport sfxb
+ WHERE sfxb.ruleid = :ruleid", ['ruleid' => $ruleid]);
+ $group = NotificationTransport::newGroup(...$ids);
+ $group->fire($subject, $message, $values);
+ }
+
+ /**
+ * Get value at given path from assoc array. Calls itself recursively until path
+ * is just one element. Supports special '*' path element, which will return all
+ * items at the current level. For this reason, the return value is always an array.
+ * This function is "hacky", as it tries to figure out whether the current key is
+ * 1) the last path element and 2) matches a known column from the machines array.
+ * If there exists no such key at the current level, it will be checked whether
+ * machineuuid (preferred) or clientip exist at the current level, and if so, they
+ * will be used to query the missing data from the database.
+ *
+ * @param array $path array of all the path elements
+ * @param array $data data to wade through, first element of $path should be in it
+ * @return array all the matched values
+ */
+ private static function get(array $path, array &$data): array
+ {
+ if (empty($path))
+ return [];
+ $pathElement = array_shift($path);
+ // Get everything on this level
+ if ($pathElement === '*') {
+ $return = [];
+ if (empty($path)) {
+ // End, everything needs to be primitive types
+ foreach ($data as $elem) {
+ if (!is_array($elem)) {
+ $return[] = $elem;
+ }
+ }
+ } else {
+ // Expected to go deeper
+ foreach ($data as $elem) {
+ if (is_array($elem)) {
+ $return = array_merge($return, self::get($path, $elem));
+ }
+ }
+ }
+ return $return;
+ }
+
+ if (!array_key_exists($pathElement, $data)
+ && (isset($data['clientip']) || isset($data['machineuuid']))) {
+ // An unknown key was requested, but we have clientip or machineuuid....
+ if (in_array($pathElement, self::MACHINE_COLUMNS) || !isset($data['machineuuid'])) {
+ // Key matches a column from machine table, OR we don't have machineuuid but clientip
+ // try to fetch it. Second condition is in case we have a HW_QUERIES virtual column.
+ if ($pathElement !== 'machineuuid' && isset($data['machineuuid'])) {
+ $row = Database::queryFirst("SELECT " . implode(',', self::MACHINE_COLUMNS)
+ . " FROM machine WHERE machineuuid = :uuid", ['uuid' => $data['machineuuid']]);
+ } elseif ($pathElement !== 'clientip' && isset($data['clientip'])) {
+ $row = Database::queryFirst("SELECT " . implode(',', self::MACHINE_COLUMNS)
+ . " FROM machine WHERE clientip = :ip ORDER BY lastseen DESC LIMIT 1", ['ip' => $data['clientip']]);
+ } else {
+ $row = false;
+ }
+ if ($row !== false) {
+ $data += $row;
+ }
+ }
+ if (isset($data['machineuuid'])
+ && isset(self::HW_QUERIES[$pathElement]) && Module::isAvailable('statistics')) {
+ // Key matches a predefined hwinfo property, resolve....
+ $q = new HardwareQuery(self::HW_QUERIES[$pathElement][0], $data['machineuuid']);
+ $q->addColumn(self::HW_QUERIES[$pathElement][2], self::HW_QUERIES[$pathElement][1]);
+ $res = $q->query();
+ if ($res !== false) {
+ foreach ($res as $row) {
+ $data[$pathElement][] = $row[self::HW_QUERIES[$pathElement][1]];
+ }
+ }
+ }
+ }
+
+ if (!array_key_exists($pathElement, $data))
+ return [];
+ if (empty($path) && !is_array($data[$pathElement]))
+ return [$data[$pathElement]];
+ if (empty($path) && ArrayUtil::isOnlyPrimitiveTypes($data[$pathElement]))
+ return $data[$pathElement];
+ if (is_array($data[$pathElement]))
+ return self::get($path, $data[$pathElement]);
+ return []; // No match
+ }
+
+ /**
+ * @param string $item item to match, string or number as string
+ * @param array $filter filter struct [op, arg, result]
+ * @return ?array null if op doesn't match, processed result otherwise
+ */
+ private static function matches(string $item, array $filter): ?array
+ {
+ $ok = false;
+ switch ($filter['op']) {
+ case '*':
+ $ok = true;
+ break;
+ case '>':
+ $ok = $item > $filter['arg'];
+ break;
+ case '>=':
+ $ok = $item >= $filter['arg'];
+ break;
+ case '<':
+ $ok = $item < $filter['arg'];
+ break;
+ case '<=':
+ $ok = $item <= $filter['arg'];
+ break;
+ case '=':
+ $ok = $item == $filter['arg'];
+ break;
+ case '!=':
+ $ok = $item != $filter['arg'];
+ break;
+ case 'regex':
+ $ok = (bool)preg_match($filter['arg'], $item, $out);
+ break;
+ default:
+ EventLog::warning("Invalid filter OP: {$filter['op']}");
+ }
+ if (!$ok) // No match
+ return null;
+ // Fake $out array for simple matches
+ if ($filter['op'] !== 'regex') {
+ $out = [1 => $item];
+ }
+ return $out ?? [];
+ }
+
+ private static function fillTemplate(string $template, array $values): string
+ {
+ return preg_replace_callback('/%([0-9]+)(?::([0-9]+|[a-z][a-z0-9_]*))?\.?([a-z]*)%/i', function($m) use ($values) {
+ if (!isset($values[$m[1]]))
+ return '<invalid row index #' . $m[1] . '>';
+ if (($m[2] ?? '') === '') {
+ $m[2] = 1;
+ }
+ if (!isset($values[$m[1]][$m[2]]))
+ return '<invalid column index #' . $m[2] . ' for row #' . $m[1] . '>';
+ $v = $values[$m[1]][$m[2]];
+ $shift = 0;
+ switch ($m[3]) {
+ case 'gb':
+ $shift++;
+ // fallthrough
+ case 'mb':
+ $shift++;
+ // fallthrough
+ case 'kb':
+ $shift++;
+ // fallthrough
+ case 'b':
+ return Util::readableFileSize((int)$v, -1, $shift);
+ case 'ts':
+ return Util::prettyTime((int)$v);
+ case 'd':
+ return Util::formatDuration((int)$v);
+ case 'L':
+ if (Module::isAvailable('locations'))
+ return Location::getName((int)$v) ?: '-';
+ break;
+ case '':
+ break;
+ default:
+ $v .= '(unknown suffix ' . $m[3] . ')';
+ }
+ return $v;
+ }, $template);
+ }
+
+ private static function combine(array $a, array $b): array
+ {
+ foreach ($b as $k => $v) {
+ if (isset($a[$k])) {
+ $a[$k] .= ', ' . $v;
+ } else {
+ $a[$k] = $v;
+ }
+ }
+ return $a;
+ }
+
+}
diff --git a/modules-available/eventlog/inc/notificationtransport.inc.php b/modules-available/eventlog/inc/notificationtransport.inc.php
new file mode 100644
index 00000000..499f6371
--- /dev/null
+++ b/modules-available/eventlog/inc/notificationtransport.inc.php
@@ -0,0 +1,279 @@
+<?php
+
+abstract class NotificationTransport
+{
+
+ public static function getInstance(array $data)
+ {
+ switch ($data['type'] ?? '') {
+ case 'mail':
+ return new MailNotificationTransport($data);
+ case 'irc':
+ return new IrcNotificationTransport($data);
+ case 'http':
+ return new HttpNotificationTransport($data);
+ case 'group':
+ return new GroupNotificationTransport($data);
+ }
+ error_log('Invalid Notification Transport: ' . ($data['type'] ?? '(unset)'));
+ return null;
+ }
+
+ public static function newGroup(int ...$ids): GroupNotificationTransport
+ {
+ return new GroupNotificationTransport(['group-list' => $ids]);
+ }
+
+ public abstract function __construct(array $data);
+
+ public abstract function toString(): string;
+
+ public abstract function fire(string $subject, string $message, array $raw): bool;
+
+ public abstract function isValid(): bool;
+
+}
+
+class MailNotificationTransport extends NotificationTransport
+{
+
+ /** @var int */
+ private $mailConfigId;
+
+ /** @var int[] */
+ private $userIds;
+
+ /** @var string */
+ private $extraMails;
+
+ public function __construct(array $data)
+ {
+ $this->mailConfigId = (int)($data['mail-config-id'] ?? 0);
+ $this->userIds = array_map(function ($i) { return (int)$i; }, $data['mail-users'] ?? []);
+ $this->extraMails = (string)($data['mail-extra-mails'] ?? '');
+ }
+
+ public function toString(): string
+ {
+ static $mailList = null;
+ if ($mailList === null) {
+ $mailList = Database::queryIndexedList("SELECT configid, host, senderaddress, replyto
+ FROM mail_config");
+ }
+ $str = 'Via: ' . ($mailList[$this->mailConfigId]['host'] ?? '<none>')
+ . ' as ' . ($mailList[$this->mailConfigId]['senderaddress'] ?? $mailList[$this->mailConfigId]['replyto'] ?? '<none>');
+ if (!empty($this->userIds)) {
+ $str .= ', Users: ' . count($this->userIds);
+ }
+ if (!empty($this->extraMails)) {
+ $str .= ', External: ' . substr_count($this->extraMails, '@');
+ }
+ return $str;
+ }
+
+ public function fire(string $subject, string $message, array $raw): bool
+ {
+ if (!$this->isValid())
+ return false;
+ $addrsOut = [];
+ if (preg_match_all('/[^@\s]+@[^@\s]+/', $this->extraMails, $out)) {
+ $addrsOut = $out[0];
+ }
+ if (!empty($this->userIds)) {
+ $mails = Database::queryColumnArray("SELECT email
+ FROM user
+ WHERE userid IN (:users)",
+ ['users' => $this->userIds]);
+ foreach ($mails as $mail) {
+ if (preg_match('/^[^@\s]+@[^@\s]+$/', $mail)) {
+ $addrsOut[] = $mail;
+ }
+ }
+ }
+ if (empty($addrsOut))
+ return false;
+ Mailer::queue($this->mailConfigId, $addrsOut, $subject, $message);
+ return true;
+ }
+
+ public function isValid(): bool
+ {
+ if ($this->mailConfigId === 0)
+ return false;
+ $mailer = Mailer::instanceFromConfig($this->mailConfigId);
+ return $mailer !== null;
+ }
+}
+
+class IrcNotificationTransport extends NotificationTransport
+{
+
+ private $server;
+
+ private $serverPasswort;
+
+ private $target;
+
+ private $nickName;
+
+ public function __construct(array $data)
+ {
+ $this->server = $data['irc-server'] ?? '';
+ $this->serverPasswort = $data['irc-server-password'] ?? '';
+ $this->target = $data['irc-target'] ?? '';
+ $this->nickName = $data['irc-nickname'] ?? 'BWLP-' . mt_rand(10000, 99999);
+ }
+
+ public function toString(): string
+ {
+ return '(' . $this->server . '), ' . $this->nickName . ' @ ' . $this->target;
+ }
+
+ public function fire(string $subject, string $message, array $raw): bool
+ {
+ if (!$this->isValid())
+ return false;
+ return !Taskmanager::isFailed(Taskmanager::submit('IrcNotification', [
+ 'serverAddress' => $this->server,
+ 'serverPassword' => $this->serverPasswort,
+ 'channel' => $this->target,
+ 'message' => preg_replace('/[\r\n]+\s*/', ' ', $message),
+ 'nickName' => $this->nickName,
+ ]));
+ }
+
+ public function isValid(): bool
+ {
+ return !empty($this->server) && !empty($this->target);
+ }
+}
+
+class HttpNotificationTransport extends NotificationTransport
+{
+
+ /** @var string */
+ private $uri;
+
+ /** @var string */
+ private $method;
+
+ /** @var string */
+ private $postField;
+
+ /** @var string */
+ private $postFormat;
+
+ public function __construct(array $data)
+ {
+ $this->uri = $data['http-uri'] ?? '';
+ $this->method = $data['http-method'] ?? 'POST';
+ $this->postField = $data['http-post-field'] ?? 'message=%TEXT%&subject=%SUBJECT%';
+ $this->postFormat = $data['http-post-format'] ?? 'FORM';
+ }
+
+ public function toString(): string
+ {
+ return $this->uri . ' (' . $this->method . ')';
+ }
+
+ public function fire(string $subject, string $message, array $raw): bool
+ {
+ if (!$this->isValid())
+ return false;
+ $url = str_replace(['%TEXT%', '%SUBJECT%'], [urlencode($message), urlencode($subject)], $this->uri);
+ if ($this->method === 'POST') {
+ switch ($this->postFormat) {
+ case 'FORM':
+ $body = str_replace(['%TEXT%', '%SUBJECT%'], [urlencode($message), urlencode($subject)], $this->postField);
+ $ctype = 'application/x-www-form-urlencoded';
+ break;
+ case 'JSON':
+ $body = str_replace(['%TEXT%', '%SUBJECT%'], [json_encode($message),
+ json_encode($subject)], $this->postField);
+ $ctype = 'application/json';
+ break;
+ default:
+ $out = [];
+ foreach ($raw as $k1 => $a) {
+ foreach ($a as $k2 => $v) {
+ $out["$k1.$k2"] = $v;
+ }
+ }
+ $body = json_encode($out);
+ $ctype = 'application/json';
+ }
+ } else {
+ $body = null;
+ $ctype = null;
+ }
+ return !Taskmanager::isFailed(Taskmanager::submit('HttpRequest', [
+ 'url' => $url,
+ 'postData' => $body,
+ 'contentType' => $ctype,
+ ]));
+ }
+
+ public function isValid(): bool
+ {
+ return !empty($this->uri);
+ }
+}
+
+class GroupNotificationTransport extends NotificationTransport
+{
+
+ /** @var int[] list of contained notification transports */
+ private $list;
+
+ public function __construct(array $data)
+ {
+ $this->list = array_map(function ($i) { return (int)$i; }, $data['group-list'] ?? []);
+ }
+
+ public function toString(): string
+ {
+ static $groupList = null;
+ if ($groupList === null) {
+ $groupList = Database::queryKeyValueList("SELECT transportid, title FROM notification_backend");
+ }
+ $out = array_map(function ($i) use ($groupList) { return $groupList[$i] ?? "#$i"; }, $this->list);
+ return implode(', ', $out);
+ }
+
+ public function fire(string $subject, string $message, array $raw): bool
+ {
+ // This is static, so recursing into groups will keep track of ones we already saw
+ static $done = false;
+ $first = ($done === false);
+ if ($first) { // Non-recursive call, init list
+ $done = [];
+ }
+ $list = array_diff($this->list, $done);
+ if (!empty($list)) {
+ $done = array_merge($done, $list);
+ $res = Database::simpleQuery("SELECT data FROM notification_backend WHERE transportid IN (:ids)",
+ ['ids' => $list]);
+ foreach ($res as $row) {
+ $data = json_decode($row['data'], true);
+ if (is_array($data)) {
+ $inst = NotificationTransport::getInstance($data);
+ if ($inst !== null) {
+ $inst->fire($subject, $message, $raw);
+ }
+ }
+ }
+ }
+ if ($first) {
+ $done = false; // Outer-most call, reset
+ }
+ return true;
+ }
+
+ public function isValid(): bool
+ {
+ // Do we really care about empty groups? They might be pointless, but not really invalid
+ // We could consider groups containing invalid IDs as invalid, but that would mean that we
+ // potentially ignore all the other existing IDs in this group, as it would never fire
+ return true;
+ }
+} \ No newline at end of file
diff --git a/modules-available/eventlog/install.inc.php b/modules-available/eventlog/install.inc.php
index e5fd32f6..75286af5 100644
--- a/modules-available/eventlog/install.inc.php
+++ b/modules-available/eventlog/install.inc.php
@@ -13,6 +13,47 @@ KEY `dateline` (`dateline`),
KEY `logtypeid` (`logtypeid`,`dateline`)
");
+$res[] = tableCreate('notification_rule', '
+ `ruleid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `title` varchar(100) NOT NULL,
+ `description` text,
+ `type` varchar(40) CHARACTER SET ascii NOT NULL,
+ `datafilter` blob NOT NULL,
+ `subject` varchar(200) NOT NULL,
+ `message` text NOT NULL,
+ `predefid` int(10) UNSIGNED NULL DEFAULT NULL,
+ PRIMARY KEY (`ruleid`),
+ KEY `type` (`type`),
+ UNIQUE KEY `predefid` (`predefid`)
+');
+
+$res[] = tableCreate('notification_backend', '
+ `transportid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `title` varchar(100) NOT NULL,
+ `description` text,
+ `data` blob,
+ PRIMARY KEY (`transportid`),
+ KEY (`title`)
+');
+
+$res[] = tableCreate('notification_rule_x_transport', '
+ `ruleid` int(10) UNSIGNED NOT NULL,
+ `transportid` int(10) UNSIGNED NOT NULL,
+ PRIMARY KEY (`ruleid`, `transportid`),
+ KEY (`transportid`)
+');
+
+$res[] = tableCreate('notification_sample', "
+ `sampleid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `dateline` int(10) UNSIGNED NOT NULL,
+ `extended` tinyint(1) NOT NULL DEFAULT '0',
+ `type` varchar(40) CHARACTER SET ascii NOT NULL,
+ `data` mediumblob,
+ KEY (`type`, `dateline`),
+ KEY (`extended`),
+ PRIMARY KEY (`sampleid`)
+");
+
// Update path
if (!tableHasColumn('eventlog', 'extra')) {
@@ -22,6 +63,48 @@ if (!tableHasColumn('eventlog', 'extra')) {
$res[] = UPDATE_DONE;
}
+// 2021-06-15: Add constraints to filter/backend stuff
+$res[] = tableAddConstraint('notification_rule_x_transport', 'ruleid',
+ 'notification_rule', 'ruleid', 'ON UPDATE CASCADE ON DELETE CASCADE');
+$res[] = tableAddConstraint('notification_rule_x_transport', 'transportid',
+ 'notification_backend', 'transportid', 'ON UPDATE CASCADE ON DELETE CASCADE');
+
+// 2022-07-20: Add flag to see if notification_sample has been extended
+if (!tableHasColumn('notification_sample', 'extended')) {
+ if (Database::exec("ALTER TABLE notification_sample
+ ADD COLUMN `extended` tinyint(1) NOT NULL DEFAULT '0',
+ ADD KEY (`extended`),
+ ADD COLUMN `sampleid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ ADD PRIMARY KEY (`sampleid`)") === false) {
+ finalResponse(UPDATE_FAILED, 'Could not add extended flag to notification_sample: ' . Database::lastError());
+ }
+ $res[] = UPDATE_DONE;
+}
+
+// 2023-08-03: Add a few example filters
+if (!tableHasColumn('notification_rule', 'predefid')) {
+ if (Database::exec("ALTER TABLE notification_rule
+ ADD COLUMN `predefid` int(10) UNSIGNED NULL DEFAULT NULL,
+ ADD UNIQUE KEY `predefid` (`predefid`)") === false) {
+ finalResponse(UPDATE_FAILED, 'Could not add predefid to notification_rule: ' . Database::lastError());
+ }
+ $res[] = UPDATE_DONE;
+}
+$q = "INSERT IGNORE INTO `notification_rule`
+ (predefid, title, `description`, type, datafilter, subject, message)
+ VALUES
+ (1,'Session start','Benachrichtigung über jede gestartete Session','.vmchooser-session','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"currentuser\",\"op\":\"*\",\"index\":2},{\"path\":\"sessionName\",\"op\":\"*\",\"index\":3}]}','Sitzungsstart','Client %0% - User %2% startet Veranstaltung %3%'),
+ (2,'PowerON: bwlp-Default','Kein spezieller Betriebsmodus','~poweron','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"currentrunmode\",\"op\":\"=\",\"arg\":\"\",\"index\":1},{\"path\":\"locationid\",\"op\":\"*\",\"index\":2}]}','PowerON-Event','Client %0% in Raum %2L% startet im Modus \'Standard\''),
+ (3,'Serverlog','Jegliche neue Einträge im Server-Log','#serverlog','{\"list\":[{\"path\":\"type\",\"op\":\"*\",\"index\":0},{\"path\":\"message\",\"op\":\"*\",\"index\":1},{\"path\":\"details\",\"op\":\"*\",\"index\":2}]}','','[%0%] - %1% - %2%'),
+ (4,'PowerON: Exammode','Rechner startet im Klausurmodus','~poweron','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"currentrunmode\",\"op\":\"=\",\"arg\":\"exams\",\"index\":1}]}','','Client %0% startet im Modus \'Prüfung\''),
+ (5,'PowerON: Remoteaccess','Rechner startet im Fernzugriffsmodus','~poweron','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"currentrunmode\",\"op\":\"=\",\"arg\":\"remoteaccess\",\"index\":1}]}','','Client %0% startet im Modus \'Fernzugriff\''),
+ (6,'NIC: Slow Uplink','Rechner ist mit weniger als 1GBit/s mit dem Switch verbunden','~poweron','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"nic_speed\",\"op\":\"<\",\"arg\":\"1000\",\"index\":1}]}','','Client %0% hat einen Uplink von %1% MBit/s'),
+ (7,'First boot of new Client','Neuer Client wurde gestartet, der dem Server bisher nicht bekannt war','~poweron','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"hostname\",\"op\":\"*\",\"index\":1},{\"path\":\"oldlastseen\",\"op\":\"=\",\"arg\":\"0\",\"index\":2}]}','','Neuer Client %0% (%1%) bootet bwLehrpool'),
+ (8,'Rechner mit Platte, ohne ID44','Besagter Rechner hat zwar eine HDD/SSD verbaut, aber keine ID44-Partition','~poweron','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"hdd_size\",\"op\":\">\",\"arg\":\"0\",\"index\":1},{\"path\":\"id44mb\",\"op\":\"=\",\"arg\":\"0\",\"index\":2},{\"path\":\"hostname\",\"op\":\"*\",\"index\":3}]}','Hallo','%3% (%0%) hat HDD %1b%, keine ID44 Partition'),
+ (9,'Lahmes Netzwerk, keine ID45','Rechner ist mit weniger als 1GBit/s mit dem Switch verbunden, und besitzt keine ID45-Partition','~poweron','{\"list\":[{\"path\":\"id45mb\",\"op\":\"=\",\"arg\":\"0\",\"index\":0},{\"path\":\"nic_speed\",\"op\":\"<\",\"arg\":\"1000\",\"index\":1},{\"path\":\"hostname\",\"op\":\"*\",\"index\":2},{\"path\":\"nic_speed\",\"op\":\">\",\"arg\":\"0\",\"index\":3},{\"path\":\"clientip\",\"op\":\"*\",\"index\":4}]}','Lahm','%2% (%4%) hat %1%MBit und keine ID45'),
+ (10,'Drehende Platte','Rechner hat eine Rotierende HDD und keine SSD.','~poweron','{\"list\":[{\"path\":\"hdd_rpm\",\"op\":\">\",\"arg\":\"0\",\"index\":0},{\"path\":\"clientip\",\"op\":\"*\",\"index\":1},{\"path\":\"hostname\",\"op\":\"*\",\"index\":2}]}','Da dreht was im Rechner...','Rechner %2% (%1%) hat drehende Platte (%0% RPM)')";
+Database::exec($q);
+
// Create response for browser
if (in_array(UPDATE_DONE, $res)) {
diff --git a/modules-available/eventlog/lang/de/messages.json b/modules-available/eventlog/lang/de/messages.json
new file mode 100644
index 00000000..662ea8c1
--- /dev/null
+++ b/modules-available/eventlog/lang/de/messages.json
@@ -0,0 +1,9 @@
+{
+ "event-mailconfig-saved": "Mail-Konfiguration {{0}} gespeichert",
+ "event-rule-saved": "Ereignisregel {{0}} gespeichert",
+ "invalid-mailconfig-id": "Ung\u00fcltige Konfigurations-ID {{0}}",
+ "invalid-rule-id": "Ung\u00fcltige Regel-ID {{0}}",
+ "invalid-transport-id": "Ung\u00fcltige Transport-ID {{0}}",
+ "no-valid-filters": "Keine g\u00fcltigen Filter angegeben",
+ "transport-saved": "Transport {{0}} gespeichert"
+} \ No newline at end of file
diff --git a/modules-available/eventlog/lang/de/module.json b/modules-available/eventlog/lang/de/module.json
index 8217fc02..93326963 100644
--- a/modules-available/eventlog/lang/de/module.json
+++ b/modules-available/eventlog/lang/de/module.json
@@ -1,3 +1,3 @@
{
- "module_name": "Server-Log"
+ "module_name": "Ereignisse"
} \ No newline at end of file
diff --git a/modules-available/eventlog/lang/de/permissions.json b/modules-available/eventlog/lang/de/permissions.json
index 7f1087bf..9d74bc19 100644
--- a/modules-available/eventlog/lang/de/permissions.json
+++ b/modules-available/eventlog/lang/de/permissions.json
@@ -1,3 +1,9 @@
{
- "view": "Server Log anschauen."
+ "filter.mailconfig.edit": "EMail-Konfigurationen bearbeiten.",
+ "filter.mailconfig.view": "EMail-Konfigurationen sehen.",
+ "filter.rules.edit": "Filterregeln bearbeiten.",
+ "filter.rules.view": "Filterregeln sehen.",
+ "filter.transports.edit": "Transporte bearbeiten.",
+ "filter.transports.view": "Transporte sehen.",
+ "view": "Server Log anschauen."
} \ No newline at end of file
diff --git a/modules-available/eventlog/lang/de/template-tags.json b/modules-available/eventlog/lang/de/template-tags.json
index 6ad75329..fd9cc532 100644
--- a/modules-available/eventlog/lang/de/template-tags.json
+++ b/modules-available/eventlog/lang/de/template-tags.json
@@ -1,6 +1,66 @@
{
+ "lang_add": "Hinzuf\u00fcgen",
+ "lang_additionalMailAddresses": "Zus\u00e4tzliche EMail-Adressen",
+ "lang_autoJson": "Vollst\u00e4ndige JSON-Daten",
+ "lang_autoJsonHelp": "Das Feld \"POST-Format\" wird ignoriert. Die POST-Daten sind eine JSON-Struktur mit allen zum Ereignis geh\u00f6renden Daten. Die Felder \"Betreff\" und \"Nachricht\" werden ebenfalls ignoriert.",
+ "lang_copy": "Kopieren",
+ "lang_createFilter": "Filter erstellen",
+ "lang_description": "Beschreibung",
"lang_details": "Details",
+ "lang_editFilter": "Filter bearbeiten",
+ "lang_editMail": "EMail bearbeiten",
+ "lang_editTransport": "Transport bearbeiten",
"lang_event": "Ereignis",
"lang_eventLog": "Serverprotokoll",
+ "lang_filterArg": "Argument",
+ "lang_filterExampleHelpText": "Hier k\u00f6nnen Sie Filter f\u00fcr verschiedene Ereignisse festlegen. Die Felder \"Typ\" und \"Pfad\" enthalten Beispielwerte, die je nach Browser mit einem einfachen oder Doppelklick angezeigt werden.",
+ "lang_filterOp": "Op",
+ "lang_filterPath": "Pfad",
+ "lang_filterResult": "Ausgabe-String",
+ "lang_filterRules": "Filterregeln",
+ "lang_formDataHelp": "POSTed das Event als \"urlencoded\" an die angegebene URL. Verwenden Sie die Platzhalter %SUBJECT% und %TEXT% f\u00fcr die entsprechenden Felder.",
+ "lang_hintRegex": "Wenn sie einen RegEx verwenden, k\u00f6nnen Sie \"capture groups\" benutzen, und im Betreff oder Nachrichtenfeld referenzieren.",
+ "lang_host": "Host",
+ "lang_http": "HTTP",
+ "lang_httpMethod": "HTTP-Methode",
+ "lang_httpPostField": "HTTP POST Payload",
+ "lang_httpPostFormat": "HTTP POST payload Content-Type",
+ "lang_httpUri": "URI",
+ "lang_id": "ID",
+ "lang_index": "Index",
+ "lang_irc": "IRC",
+ "lang_ircNickname": "Nickname",
+ "lang_ircServer": "Server",
+ "lang_ircServerPassword": "Server-Passwort",
+ "lang_ircTarget": "Senden an #Kanal\/Nick",
+ "lang_jsonStringHelp": "Formulieren Sie eine JSON-Struktur, die die Platzhalter %SUBJECT% und %TEXT% f\u00fcr beliebige Werte enth\u00e4lt.",
+ "lang_logAndEvents": "Server-Log und Ereignis\u00fcberwachung",
+ "lang_mail": "EMail",
+ "lang_mailConfig": "EMail-Konfiguration",
+ "lang_mailUsers": "Via Mail zu benachrichtigende Nutzer",
+ "lang_mailconfigs": "EMail-Konfigurationen",
+ "lang_messageTemplate": "Nachrichtenvorlage",
+ "lang_messageTemplateHelp": "Sie k\u00f6nnen mittels der Platzhalter %0%, %1%, etc. Bezug auf die Filter oben nehmen. F\u00fcr Filter vom Typ \"regex\" k\u00f6nnen Sie sich mittels %n:1%, %n:2% etc. auf die \"Capture Groups\" des Regul\u00e4ren Ausdrucks beziehen. Des Weiteren k\u00f6nnen numerische Werte durch Suffixe formatiert\/in lesbare Form umgewandelt werden. Geben Sie durch das Suffix an, welche Einheit die zu formatierende Zahl hat: \"b\", \"kb\", \"mb\", \"gb\" f\u00fcr Bytes (resp. Kilo, Mega, etc.), \"ts\" als Unix-Timestamp, \"d\" als Dauer in Sekunden, \"L\" f\u00fcr eine Location-ID.",
+ "lang_noMailConfig": "Keine EMail-Konfiguration",
+ "lang_optionalDescription": "Beschreibung (als Referenz, wird nicht f\u00fcr die Verarbeitung verwendet)",
+ "lang_port": "Port",
+ "lang_postUseSUBJECTandTEXThint": "Sie k\u00f6nnen die Platzhalter %SUBJECT% und %TEXT% verwenden, die entsprechend des ausgew\u00e4hlten POST-Formats escaped werden.",
+ "lang_reallyDelete": "Konfiguration l\u00f6schen?",
+ "lang_replyTo": "Antwort an",
+ "lang_rules": "Regeln",
+ "lang_sampleData": "Beispieldaten",
+ "lang_selectTransports": "Transporte ausw\u00e4hlen",
+ "lang_senderAddress": "Absenderadresse",
+ "lang_ssl": "TLS",
+ "lang_sslExplicit": "Explizites TLS",
+ "lang_sslImplicit": "Implizites TLS",
+ "lang_sslNone": "Kein TLS",
+ "lang_subject": "Betreff",
+ "lang_title": "Titel",
+ "lang_transportGroup": "Transportgruppe",
+ "lang_transports": "Transporte",
+ "lang_type": "Typ",
+ "lang_typeExample": "Beispiel",
+ "lang_uriUseSUBJECTandTEXThint": "Sie k\u00f6nnen %SUBJECT% und %TEXT% in der URI verwenden. Sie werden durch die entsprechenden Felder des Filters ersetzt.",
"lang_when": "Wann"
} \ No newline at end of file
diff --git a/modules-available/eventlog/lang/en/messages.json b/modules-available/eventlog/lang/en/messages.json
new file mode 100644
index 00000000..3d8eec5f
--- /dev/null
+++ b/modules-available/eventlog/lang/en/messages.json
@@ -0,0 +1,9 @@
+{
+ "event-mailconfig-saved": "Saved mail configuration {{0}}",
+ "event-rule-saved": "Saved rule {{0}}",
+ "invalid-mailconfig-id": "Invalid mail config ID {{0}}",
+ "invalid-rule-id": "Invalid rule ID {{0}}",
+ "invalid-transport-id": "Invalid transport ID {{0}}",
+ "no-valid-filters": "No valid filters provided",
+ "transport-saved": "Saved transport {{0}}"
+} \ No newline at end of file
diff --git a/modules-available/eventlog/lang/en/module.json b/modules-available/eventlog/lang/en/module.json
index 0fc536f3..574d36bb 100644
--- a/modules-available/eventlog/lang/en/module.json
+++ b/modules-available/eventlog/lang/en/module.json
@@ -1,3 +1,3 @@
{
- "module_name": "Server Log"
+ "module_name": "Events"
} \ No newline at end of file
diff --git a/modules-available/eventlog/lang/en/permissions.json b/modules-available/eventlog/lang/en/permissions.json
index ec438a4b..9a65dcaa 100644
--- a/modules-available/eventlog/lang/en/permissions.json
+++ b/modules-available/eventlog/lang/en/permissions.json
@@ -1,3 +1,9 @@
{
- "view": "View server log."
+ "filter.mailconfig.edit": "Edit email configs.",
+ "filter.mailconfig.view": "View email configs.",
+ "filter.rules.edit": "Edit filter rules.",
+ "filter.rules.view": "View filter rules.",
+ "filter.transports.edit": "Edit transports.",
+ "filter.transports.view": "View transports.",
+ "view": "View server log."
} \ No newline at end of file
diff --git a/modules-available/eventlog/lang/en/template-tags.json b/modules-available/eventlog/lang/en/template-tags.json
index 3132b97c..7535b86b 100644
--- a/modules-available/eventlog/lang/en/template-tags.json
+++ b/modules-available/eventlog/lang/en/template-tags.json
@@ -1,6 +1,66 @@
{
+ "lang_add": "Add",
+ "lang_additionalMailAddresses": "Additional mail addresses",
+ "lang_autoJson": "Full JSON data",
+ "lang_autoJsonHelp": "The field \"POST format\" is ignored. The POST payload is a JSON struct with all available data regarding the according event. \"Subject\" and \"Message\" are ignored as well.",
+ "lang_copy": "Copy",
+ "lang_createFilter": "Create filter",
+ "lang_description": "Description",
"lang_details": "Details",
+ "lang_editFilter": "Edit filter",
+ "lang_editMail": "Edit mail",
+ "lang_editTransport": "Edit transport",
"lang_event": "Event",
"lang_eventLog": "Server Log",
+ "lang_filterArg": "Argument",
+ "lang_filterExampleHelpText": "Here you can define filters for different events. Fields \"type\" and \"path\" contain example values, which can be displayed by single- or double-clicking (depending on browser) the according field.",
+ "lang_filterOp": "Op",
+ "lang_filterPath": "Path",
+ "lang_filterResult": "Resulting string",
+ "lang_filterRules": "Filter rules",
+ "lang_formDataHelp": "POST event als urlencoded form data. Put your desired post string into the field above and use %TEXT% and %SUBJECT% as placeholders for where the according event fields go.",
+ "lang_hintRegex": "If you use a regex, you can use capture groups in the filter expression, and refer to them later on in your message body.",
+ "lang_host": "Host",
+ "lang_http": "HTTP",
+ "lang_httpMethod": "HTTP method",
+ "lang_httpPostField": "HTTP post payload",
+ "lang_httpPostFormat": "HTTP post payload Content-Type",
+ "lang_httpUri": "URI",
+ "lang_id": "ID",
+ "lang_index": "Index",
+ "lang_irc": "IRC",
+ "lang_ircNickname": "Nickname",
+ "lang_ircServer": "Server",
+ "lang_ircServerPassword": "Server password",
+ "lang_ircTarget": "Target Channel\/Nick",
+ "lang_jsonStringHelp": "Supply a json struct containing placeholders %SUBJECT% and\/or %TEXT% in the \"HTTP post payload\" fied above.",
+ "lang_logAndEvents": "Server log and event filtering",
+ "lang_mail": "Mail",
+ "lang_mailConfig": "Mail config",
+ "lang_mailUsers": "Users to mail",
+ "lang_mailconfigs": "Mail configs",
+ "lang_messageTemplate": "Message template",
+ "lang_messageTemplateHelp": "You can refer to the matched rules above by using their index in percentage-signs, like %0%, %1%, etc. If you use a regex with capture groups, you can refer to them individually by using %n:1%, %n:2% etc. Furthermode, you can format raw numbers by appending \"b\", \"kb\", \"mb\", \"gb\" to interpret the given value as bytes (or kilobytes, megabytes, etc.), \"ts\" if the input value is a unix timestamp, \"d\" to turn a duration in seconds into human readable format, and \"L\" to turn a location id into the according location name.",
+ "lang_noMailConfig": "No mail config",
+ "lang_optionalDescription": "Description (for reference only)",
+ "lang_port": "Port",
+ "lang_postUseSUBJECTandTEXThint": "Use %SUBJECT% and %TEXT% placeholders which will be escaped properly, according to chosen POST format.",
+ "lang_reallyDelete": "Config deletion?",
+ "lang_replyTo": "Reply to",
+ "lang_rules": "Rules",
+ "lang_sampleData": "Sample data",
+ "lang_selectTransports": "Select transports",
+ "lang_senderAddress": "Sender address",
+ "lang_ssl": "TLS",
+ "lang_sslExplicit": "Explicit TLS",
+ "lang_sslImplicit": "Implicit TLS",
+ "lang_sslNone": "No TLS",
+ "lang_subject": "Subject",
+ "lang_title": "Title",
+ "lang_transportGroup": "Transport group",
+ "lang_transports": "Transports",
+ "lang_type": "Type",
+ "lang_typeExample": "Example",
+ "lang_uriUseSUBJECTandTEXThint": "You can use %SUBJECT% and %TEXT% in the URI too. They will be url-encoded.",
"lang_when": "When"
} \ No newline at end of file
diff --git a/modules-available/eventlog/page.inc.php b/modules-available/eventlog/page.inc.php
index 1c81983c..56fc97e2 100644
--- a/modules-available/eventlog/page.inc.php
+++ b/modules-available/eventlog/page.inc.php
@@ -3,56 +3,65 @@
class Page_EventLog extends Page
{
+ private $show;
+
protected function doPreprocess()
{
User::load();
- User::assertPermission('view');
- User::setLastSeenEvent(Property::getLastWarningId());
- }
- protected function doRender()
- {
- Render::addTemplate("heading");
- $lines = array();
- $paginate = new Paginate("SELECT logid, dateline, logtypeid, description, extra FROM eventlog ORDER BY logid DESC", 50);
- $res = $paginate->exec();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $row['date'] = Util::prettyTime($row['dateline']);
- $row['icon'] = $this->typeToIcon($row['logtypeid']);
- $row['color'] = $this->typeToColor($row['logtypeid']);
- $lines[] = $row;
+ $this->show = Request::any('show', false, 'string');
+ if ($this->show === false && Request::isGet()) {
+ if (User::hasPermission('view')) {
+ $this->show = 'log';
+ } elseif (User::hasPermission('filter.rules.view')) {
+ $this->show = 'rules';
+ } else {
+ User::assertPermission('filter.transports.view');
+ $this->show = 'transports';
+ }
+ }
+ if ($this->show !== false) {
+ $this->show = preg_replace('/[^a-z0-9_\-]/', '', $this->show);
+ if (!file_exists('modules/eventlog/pages/' . $this->show . '.inc.php')) {
+ Message::addError('main.invalid-action', $this->show);
+ Util::redirect('?do=eventlog');
+ } else {
+ require_once 'modules/eventlog/pages/' . $this->show . '.inc.php';
+ SubPage::doPreprocess();
+ }
+ }
+ if (Request::isPost()) {
+ Util::redirect('?do=eventlog&show=' . $this->show);
}
-
- $paginate->render('_page', array(
- 'list' => $lines
- ));
}
- private function typeToIcon($type)
+ protected function doRender()
{
- switch ($type) {
- case 'info':
- return 'ok';
- case 'warning':
- return 'exclamation-sign';
- case 'failure':
- return 'remove';
- default:
- return 'question-sign';
+ Render::addTemplate('page-header', ['active_' . $this->show => 'active']);
+ if ($this->show !== false) {
+ SubPage::doRender();
}
}
- private function typeToColor($type)
+ protected function doAjax()
{
- switch ($type) {
- case 'info':
- return '';
- case 'warning':
- return 'orange';
- case 'failure':
- return 'red';
- default:
- return '';
+ // XXX Should go into rules.inc.php
+ User::assertPermission('filter.rules.edit');
+ if (Request::any('show') === 'rules') {
+ $type = Request::any('type', Request::REQUIRED, 'string');
+ $res = Database::simpleQuery('SELECT data FROM notification_sample
+ WHERE type = :type ORDER BY dateline DESC LIMIT 5',
+ ['type' => $type]);
+ $output = [];
+ foreach ($res as $row) {
+ $row = json_decode($row['data'], true);
+ if (is_array($row)) {
+ $output += $row;
+ }
+ }
+ ksort($output);
+ Header('Content-Type: application/json');
+ echo json_encode($output);
}
}
diff --git a/modules-available/eventlog/pages/log.inc.php b/modules-available/eventlog/pages/log.inc.php
new file mode 100644
index 00000000..66826b08
--- /dev/null
+++ b/modules-available/eventlog/pages/log.inc.php
@@ -0,0 +1,56 @@
+<?php
+
+class SubPage
+{
+
+ public static function doPreprocess()
+ {
+ User::assertPermission('view');
+ User::setLastSeenEvent(Property::getLastWarningId());
+ }
+
+ public static function doRender()
+ {
+ $lines = array();
+ $paginate = new Paginate("SELECT logid, dateline, logtypeid, description, extra FROM eventlog ORDER BY logid DESC", 50);
+ $res = $paginate->exec();
+ foreach ($res as $row) {
+ $row['date'] = Util::prettyTime($row['dateline']);
+ $row['icon'] = self::typeToIcon($row['logtypeid']);
+ $row['color'] = self::typeToColor($row['logtypeid']);
+ $lines[] = $row;
+ }
+
+ $paginate->render('_page', array(
+ 'list' => $lines
+ ));
+ }
+
+ private static function typeToIcon(string $type): string
+ {
+ switch ($type) {
+ case 'info':
+ return 'ok';
+ case 'warning':
+ return 'exclamation-sign';
+ case 'failure':
+ return 'remove';
+ default:
+ return 'question-sign';
+ }
+ }
+
+ private static function typeToColor(string $type): string
+ {
+ switch ($type) {
+ case 'warning':
+ return 'orange';
+ case 'failure':
+ return 'red';
+ case 'info':
+ default:
+ return '';
+ }
+ }
+
+} \ No newline at end of file
diff --git a/modules-available/eventlog/pages/mailconfigs.inc.php b/modules-available/eventlog/pages/mailconfigs.inc.php
new file mode 100644
index 00000000..0ba71104
--- /dev/null
+++ b/modules-available/eventlog/pages/mailconfigs.inc.php
@@ -0,0 +1,99 @@
+<?php
+
+class SubPage
+{
+
+ public static function doPreprocess()
+ {
+ if (Request::isPost()) {
+ User::assertPermission('filter.mailconfigs.edit');
+ $action = Request::post('action');
+ if ($action === 'save-mailconfig') {
+ self::saveMailconfig();
+ } elseif ($action === 'delete-mailconfig') {
+ self::deleteMailconfig();
+ } else {
+ Message::addError('main.invalid-action', $action);
+ }
+ Util::redirect('?do=eventlog&show=mailconfigs');
+ }
+ }
+
+ private static function saveMailconfig()
+ {
+ User::assertPermission('filter.mailconfigs.edit');
+ $id = Request::post('id', Request::REQUIRED, 'int');
+ $data = [
+ 'host' => Request::post('host', Request::REQUIRED, 'string'),
+ 'port' => Request::post('port', Request::REQUIRED, 'int'),
+ 'ssl' => Request::post('ssl', Request::REQUIRED, 'string'),
+ 'senderaddress' => Request::post('senderaddress', Request::REQUIRED, 'string'),
+ 'replyto' => Request::post('replyto', '', 'string'),
+ 'username' => Request::post('username', '', 'string'),
+ 'password' => Request::post('password', '', 'string'),
+ ];
+ if ($id === 0) {
+ // NEW
+ Database::exec("INSERT INTO mail_config (host, port, `ssl`, senderaddress, replyto, username, password)
+ VALUES (:host, :port, :ssl, :senderaddress, :replyto, :username, :password)", $data);
+ } else {
+ // UPDATE
+ $data['configid'] = $id;
+ Database::exec("UPDATE mail_config SET host = :host, port = :port, `ssl` = :ssl,
+ senderaddress = :senderaddress, replyto = :replyto, username = :username, password = :password
+ WHERE configid = :configid", $data);
+ }
+ Message::addSuccess("event-mailconfig-saved", $id);
+ Util::redirect('?do=eventlog&show=mailconfigs');
+ }
+
+ private static function deleteMailconfig()
+ {
+ User::assertPermission('filter.mailconfigs.edit');
+ $id = Request::post('id', Request::REQUIRED, 'int');
+ Database::exec("DELETE FROM mail_config WHERE configid = :id", ['id' => $id]);
+ }
+
+ /*
+ *
+ */
+
+ public static function doRender()
+ {
+ User::assertPermission('filter.mailconfigs.view');
+ $id = Request::get('id', null, 'int');
+ if ($id !== null) {
+ self::showMailconfigEditor($id);
+ } else {
+ // LIST
+ $data = [];
+ $data['configs'] = Database::queryAll('SELECT configid, host, port, `ssl`, senderaddress, replyto
+ FROM mail_config
+ ORDER BY host');
+ Render::addTemplate('page-filters-mailconfigs', $data);
+ }
+ }
+
+ /**
+ * @param int $id Config to edit. If id is 0, a new config will be created.
+ */
+ private static function showMailconfigEditor(int $id)
+ {
+ User::assertPermission('filter.mailconfigs.edit');
+ if ($id !== 0) {
+ // EDIT
+ $data = Database::queryFirst('SELECT configid, host, port, `ssl`, senderaddress, replyto,
+ username, password
+ FROM mail_config
+ WHERE configid = :id', ['id' => $id]);
+ if ($data === false) {
+ Message::addError('invalid-mailconfig-id', $id);
+ Util::redirect('?do=eventlog&show=mailconfigs');
+ }
+ } else {
+ $data = ['configid' => 0];
+ }
+ Render::addTemplate('page-filters-edit-mailconfig', $data);
+ }
+
+} \ No newline at end of file
diff --git a/modules-available/eventlog/pages/rules.inc.php b/modules-available/eventlog/pages/rules.inc.php
new file mode 100644
index 00000000..7b43cfdb
--- /dev/null
+++ b/modules-available/eventlog/pages/rules.inc.php
@@ -0,0 +1,187 @@
+<?php
+
+class SubPage
+{
+
+ const OP_LIST = ['*', '=', '!=', '<', '<=', '>', '>=', 'regex'];
+
+ public static function doPreprocess()
+ {
+ if (Request::isPost()) {
+ User::assertPermission('filter.rules.edit');
+ $action = Request::post('action');
+ if ($action === 'save-filter') {
+ self::saveRule();
+ } elseif ($action === 'delete-filter') {
+ self::deleteRule();
+ } else {
+ Message::addError('main.invalid-action', $action);
+ }
+ Util::redirect('?do=eventlog&show=rules');
+ }
+ }
+
+ private static function saveRule()
+ {
+ User::assertPermission('filter.rules.edit');
+ $id = Request::post('id', Request::REQUIRED, 'int');
+ $type = Request::post('type', Request::REQUIRED, 'string');
+ $title = Request::post('title', Request::REQUIRED, 'string');
+ $message = Request::post('message', Request::REQUIRED, 'string');
+ $transports = Request::post('transports', [], 'array');
+ $filters = Request::post('filter', Request::REQUIRED, 'array');
+ $filters = array_filter($filters, function ($item) {
+ return is_array($item) && !empty($item['path']) && !empty($item['op']);
+ });
+ foreach ($filters as $index => &$item) {
+ $item['index'] = $index;
+ }
+ unset($item);
+ if (empty($filters)) {
+ Message::addError('no-valid-filters');
+ Util::redirect('?do=eventlog&show=rules');
+ }
+ if ($id === 0) {
+ $id = null;
+ }
+ $data = [
+ 'id' => $id,
+ 'type' => $type,
+ 'title' => $title,
+ 'description' => Request::post('description', '', 'string'),
+ 'data' => json_encode(['list' => array_values($filters)]),
+ 'subject' => Request::post('subject', '', 'string'),
+ 'message' => $message,
+ ];
+ if ($id === null) {
+ // NEW
+ Database::exec("INSERT INTO notification_rule (ruleid, title, description, type, datafilter, subject, message)
+ VALUES (:id, :title, :description, :type, :data, :subject, :message)", $data);
+ $id = Database::lastInsertId();
+ } else {
+ Database::exec("UPDATE notification_rule SET type = :type, title = :title, description = :description, datafilter = :data,
+ subject = :subject, message = :message
+ WHERE ruleid = :id", $data);
+ }
+ if (empty($transports)) {
+ Database::exec("DELETE FROM notification_rule_x_transport WHERE ruleid = :id", ['id' => $id]);
+ } else {
+ Database::exec("DELETE FROM notification_rule_x_transport
+ WHERE ruleid = :id AND transportid NOT IN (:transports)",
+ ['id' => $id, 'transports' => $transports]);
+ Database::exec("INSERT IGNORE INTO notification_rule_x_transport (ruleid, transportid)
+ VALUES :list", ['list' => array_map(function ($i) use ($id) { return [$id, $i]; }, $transports)]);
+ }
+ Message::addSuccess("event-rule-saved", $id);
+ Util::redirect('?do=eventlog&show=rules');
+ }
+
+ private static function deleteRule()
+ {
+ User::assertPermission('filter.rules.edit');
+ $id = Request::post('id', Request::REQUIRED, 'int');
+ Database::exec("DELETE FROM notification_rule WHERE ruleid = :id", ['id' => $id]);
+ }
+
+ /*
+ *
+ */
+
+ public static function doRender()
+ {
+ User::assertPermission('filter.rules.view');
+ $id = Request::get('id', null, 'int');
+ if ($id !== null) {
+ self::showRuleEditor($id);
+ } else {
+ // LIST
+ $data = [];
+ $data['filters'] = Database::queryAll('SELECT ruleid, type, title, datafilter,
+ Count(transportid) AS useCount
+ FROM notification_rule
+ LEFT JOIN notification_rule_x_transport sfxb USING (ruleid)
+ GROUP BY ruleid, title
+ ORDER BY title, ruleid');
+ Permission::addGlobalTags($data['perms'], null, ['filter.rules.edit']);
+ Render::addTemplate('page-filters-rules', $data);
+ }
+ }
+
+ /**
+ * @param int $id Rule to edit. If id is 0, a new rule will be created.
+ */
+ private static function showRuleEditor(int $id)
+ {
+ // EDIT
+ User::assertPermission('filter.rules.edit');
+ $filterIdx = 0;
+ $knownIdxList = [];
+ if ($id !== 0) {
+ $data = Database::queryFirst('SELECT ruleid, title, description, type, datafilter, subject, message
+ FROM notification_rule WHERE ruleid = :id', ['id' => $id]);
+ if ($data === false) {
+ Message::addError('invalid-rule-id', $id);
+ Util::redirect('?do=eventlog&show=rules');
+ }
+ if (Request::get('copy', false, 'bool')) {
+ $data['ruleid'] = 0;
+ $data['title'] = '';
+ }
+ $list = json_decode($data['datafilter'], true);
+ if (!is_array($list['list'])) {
+ $list['list'] = [];
+ }
+ foreach ($list['list'] as $item) {
+ if (isset($item['index'])) {
+ $knownIdxList[] = $item['index'];
+ }
+ }
+ foreach ($list['list'] as &$item) {
+ if (!isset($item['index'])) {
+ while (in_array($filterIdx, $knownIdxList)) {
+ $filterIdx++;
+ }
+ $item['index'] = $filterIdx++;
+ }
+ $item['operators'] = [];
+ foreach (self::OP_LIST as $op) {
+ $item['operators'][] = [
+ 'name' => $op,
+ 'selected' => ($op === $item['op']) ? 'selected' : '',
+ ];
+ }
+ }
+ $data['filter'] = $list['list'];
+ } else {
+ // New entry
+ $data = ['filter' => [], 'ruleid' => 0];
+ }
+ // Add suggestions for type
+ $data['types'] = Database::queryColumnArray("SELECT DISTINCT type
+ FROM notification_sample
+ ORDER BY type");
+ //
+ Module::isAvailable('bootstrap_multiselect');
+ $data['transports'] = Database::queryAll("SELECT nb.transportid, nb.title,
+ IF(sfxb.ruleid IS NULL, '', 'selected') AS selected
+ FROM notification_backend nb
+ LEFT JOIN notification_rule_x_transport sfxb ON (sfxb.transportid = nb.transportid AND sfxb.ruleid = :id)",
+ ['id' => $id]);
+ if (Module::isAvailable('statistics')) {
+ // Filter keys to suggest for events with machineuuid in data
+ $data['machine_keys'] = array_keys(FilterRuleProcessor::HW_QUERIES);
+ }
+ // Add a few empty rows at the bottom
+ for ($i = 0; $i < 8; ++$i) {
+ while (in_array($filterIdx, $knownIdxList)) {
+ $filterIdx++;
+ }
+ $data['filter'][] = [
+ 'index' => $filterIdx++,
+ 'operators' => array_map(function ($item) { return ['name' => $item]; }, self::OP_LIST),
+ ];
+ }
+ Render::addTemplate('page-filters-edit-rule', $data);
+ }
+
+} \ No newline at end of file
diff --git a/modules-available/eventlog/pages/transports.inc.php b/modules-available/eventlog/pages/transports.inc.php
new file mode 100644
index 00000000..439c650c
--- /dev/null
+++ b/modules-available/eventlog/pages/transports.inc.php
@@ -0,0 +1,179 @@
+<?php
+
+class SubPage
+{
+
+ public static function doPreprocess()
+ {
+ if (Request::isPost()) {
+ User::assertPermission('filter.transports.edit');
+ $action = Request::post('action');
+ if ($action === 'save-transport') {
+ self::saveTransport();
+ } elseif ($action === 'delete-transport') {
+ self::deleteTransport();
+ } else {
+ Message::addError('main.invalid-action', $action);
+ }
+ Util::redirect('?do=eventlog&show=transports');
+ }
+ }
+
+ private static function saveTransport()
+ {
+ User::assertPermission('filter.transports.edit');
+ $id = Request::post('id', Request::REQUIRED, 'int');
+ $rules = Request::post('rules', [], 'array');
+ static $types = [
+ 'type' => [Request::REQUIRED, 'string', ['mail', 'irc', 'http', 'group']],
+ 'mail-config-id' => [0, 'int'],
+ 'mail-users' => [[], 'int[]'],
+ 'mail-extra-mails' => ['', 'string'],
+ 'irc-server' => ['', 'string'],
+ 'irc-server-password' => ['', 'string'],
+ 'irc-target' => ['', 'string'],
+ 'irc-nickname' => ['', 'string'],
+ 'http-uri' => ['', 'string'],
+ 'http-method' => ['', 'string', ['GET', 'POST']],
+ 'http-post-field' => ['', 'string'],
+ 'http-post-format' => ['', 'string', ['FORM', 'JSON', 'JSON_AUTO']],
+ 'group-list' => [[], 'int[]'],
+ ];
+ $data = [];
+ foreach ($types as $key => $def) {
+ if (substr($def[1], -1) === ']') {
+ $type = substr($def[1], 0, -2);
+ $array = true;
+ } else {
+ $type = $def[1];
+ $array = false;
+ }
+ if ($array) {
+ $value = Request::post($key, [], 'array');
+ foreach ($value as &$v) {
+ settype($v, $type);
+ if (isset($def[2]) && !in_array($v, $def[2])) {
+ Message::addWarning('main.value-invalid', $key, $v);
+ }
+ }
+ } else {
+ $value = Request::post($key, $def[0], $type);
+ if (isset($def[2]) && !in_array($value, $def[2])) {
+ Message::addWarning('main.value-invalid', $key, $value);
+ }
+ }
+ $data[$key] = $value;
+ }
+ //die(print_r($data));
+ $params = [
+ 'title' => Request::post('title', 'Backend', 'string'),
+ 'description' => Request::post('description', '', 'string'),
+ 'data' => json_encode($data),
+ ];
+ if ($id === 0) {
+ $res = Database::exec("INSERT INTO notification_backend (title, description, data)
+ VALUES (:title, :description, :data)", $params);
+ $id = Database::lastInsertId();
+ } else {
+ $params['transportid'] = $id;
+ $res = Database::exec("UPDATE notification_backend
+ SET title = :title, description = :description, data = :data
+ WHERE transportid = :transportid", $params);
+ }
+ if (empty($rules)) {
+ Database::exec("DELETE FROM notification_rule_x_transport WHERE transportid = :id", ['id' => $id]);
+ } else {
+ Database::exec("DELETE FROM notification_rule_x_transport
+ WHERE transportid = :id AND ruleid NOT IN (:rules)",
+ ['id' => $id, 'rules' => $rules]);
+ Database::exec("INSERT IGNORE INTO notification_rule_x_transport (ruleid, transportid)
+ VALUES :list", ['list' => array_map(function ($i) use ($id) { return [$i, $id]; }, $rules)]);
+ }
+ if ($res > 0) {
+ Message::addSuccess('transport-saved', $id);
+ }
+ Util::redirect('?do=eventlog&show=transports&section=transports');
+ }
+
+ private static function deleteTransport()
+ {
+ User::assertPermission('filter.transports.edit');
+ $id = Request::post('id', Request::REQUIRED, 'int');
+ Database::exec("DELETE FROM notification_backend WHERE transportid = :id", ['id' => $id]);
+ }
+
+ /*
+ *
+ */
+
+ public static function doRender()
+ {
+ User::assertPermission('filter.transports.view');
+ $id = Request::get('id', null, 'int');
+ if ($id !== null) {
+ self::showTransportEditor($id);
+ } else {
+ // LIST
+ $data = [];
+ $data['transports'] = [];
+ foreach (Database::queryAll('SELECT transportid, title, data,
+ Count(ruleid) AS useCount
+ FROM notification_backend nb
+ LEFT JOIN notification_rule_x_transport sfxb USING (transportid)
+ GROUP BY transportid, title
+ ORDER BY title, transportid') as $transport) {
+ $json = json_decode($transport['data'], true);
+ $transport['type'] = $json['type'];
+ $transport['details'] = NotificationTransport::getInstance($json);
+ $data['transports'][] = $transport;
+ }
+ Render::addTemplate('page-filters-transports', $data);
+ }
+ }
+
+ /**
+ * @param int $id Transport to edit, 0 to create a new one
+ */
+ private static function showTransportEditor(int $id)
+ {
+ User::assertPermission('filter.transports.edit');
+ if ($id !== 0) {
+ $entry = Database::queryFirst('SELECT transportid, title, description, data
+ FROM notification_backend
+ WHERE transportid = :id', ['id' => $id]);
+ if ($entry === false) {
+ Message::addError('invalid-transport-id', $id);
+ Util::redirect('?do=eventlog&show=transports&section=transports');
+ }
+ $entry['data'] = json_decode($entry['data'], true);
+ $entry[($entry['data']['type'] ?? '') . '_selected'] = 'selected';
+ $entry[($entry['data']['http-method'] ?? '') . '_selected'] = 'selected';
+ $entry[($entry['data']['http-post-format'] ?? '') . '_selected'] = 'selected';
+ } else {
+ $entry = ['transportid' => $id, 'data' => [], 'backends' => []];
+ }
+ $entry['users'] = [];
+ foreach (Database::queryAll("SELECT userid, login, fullname, email FROM user ORDER BY login") as $row) {
+ $row['disabled'] = strpos($row['email'], '@') ? '' : 'disabled';
+ $row['selected'] = in_array($row['userid'], $entry['data']['mail-users'] ?? []) ? 'selected' : '';
+ $entry['users'][] = $row;
+ }
+ $entry['mailconfigs'] = [];
+ foreach (Database::queryAll("SELECT configid, host, port, senderaddress FROM mail_config") as $row) {
+ $row['selected'] = $row['configid'] == ($entry['data']['mail-config-id'] ?? []) ? 'selected' : '';
+ $entry['mailconfigs'][] = $row;
+ }
+ foreach (Database::queryAll("SELECT transportid, title FROM notification_backend") as $row) {
+ $row['selected'] = in_array($row['transportid'], ($entry['data']['group-list'] ?? [])) ? 'selected' : '';
+ $entry['backends'][] = $row;
+ }
+ Module::isAvailable('bootstrap_multiselect');
+ $entry['rules'] = Database::queryAll("SELECT sf.ruleid, sf.title,
+ IF(sfxb.transportid IS NULL, '', 'selected') AS selected
+ FROM notification_rule sf
+ LEFT JOIN notification_rule_x_transport sfxb ON (sf.ruleid = sfxb.ruleid AND sfxb.transportid = :id)",
+ ['id' => $id]);
+ Render::addTemplate('page-filters-edit-transport', $entry);
+ }
+
+} \ No newline at end of file
diff --git a/modules-available/eventlog/permissions/permissions.json b/modules-available/eventlog/permissions/permissions.json
index a1748957..13af297a 100644
--- a/modules-available/eventlog/permissions/permissions.json
+++ b/modules-available/eventlog/permissions/permissions.json
@@ -1,5 +1,23 @@
{
"view": {
"location-aware": false
+ },
+ "filter.rules.view": {
+ "location-aware": false
+ },
+ "filter.rules.edit": {
+ "location-aware": false
+ },
+ "filter.transports.view": {
+ "location-aware": false
+ },
+ "filter.transports.edit": {
+ "location-aware": false
+ },
+ "filter.mailconfig.view": {
+ "location-aware": false
+ },
+ "filter.mailconfig.edit": {
+ "location-aware": false
}
} \ No newline at end of file
diff --git a/modules-available/eventlog/templates/_page.html b/modules-available/eventlog/templates/_page.html
index 239286f8..facdd205 100644
--- a/modules-available/eventlog/templates/_page.html
+++ b/modules-available/eventlog/templates/_page.html
@@ -1,3 +1,4 @@
+<h2>{{lang_eventLog}}</h2>
{{{pagenav}}}
<table class="table table-striped table-condensed">
<thead>
@@ -11,7 +12,7 @@
<tr>
<td><span class="glyphicon glyphicon-{{icon}}" title="{{logtypeid}}"></span></td>
<td class="text-center" nowrap="nowrap">{{date}}</td>
- <td class="{{color}}">{{description}}</td>
+ <td class="{{color}} log-line">{{description}}</td>
<td class="text-center">{{#extra}}
<a class="btn btn-default btn-xs" onclick="$('#details-body').html($('#extra-{{logid}}').html())" data-toggle="modal" data-target="#myModal">&raquo;</a>
<div class="hidden" id="extra-{{logid}}">{{extra}}</div>
@@ -35,3 +36,13 @@
</div>
</div>
</div>
+<script>
+ (function () {
+ var x = document.getElementsByClassName('log-line');
+ for (var i = 0; i < x.length; ++i) {
+ var y = x[i];
+ y.innerHTML = y.innerHTML.replace(/(client) ([0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12})/i,
+ '$1 <a href="?do=statistics&amp;uuid=$2">$2</a>');
+ }
+ })();
+</script> \ No newline at end of file
diff --git a/modules-available/eventlog/templates/heading.html b/modules-available/eventlog/templates/heading.html
deleted file mode 100644
index 37612a77..00000000
--- a/modules-available/eventlog/templates/heading.html
+++ /dev/null
@@ -1 +0,0 @@
-<h1>{{lang_eventLog}}</h1> \ No newline at end of file
diff --git a/modules-available/eventlog/templates/page-filters-edit-mailconfig.html b/modules-available/eventlog/templates/page-filters-edit-mailconfig.html
new file mode 100644
index 00000000..1cf77057
--- /dev/null
+++ b/modules-available/eventlog/templates/page-filters-edit-mailconfig.html
@@ -0,0 +1,53 @@
+<h2>{{lang_editMail}} {{#senderaddress}}–{{/senderaddress}} {{senderaddress}}</h2>
+
+<form method="post" action="?do=eventlog&amp;show=mailconfigs">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="id" value="{{configid}}">
+ <div class="form-group row">
+ <div class="col-md-4">
+ <label for="i-host">{{lang_host}}</label>
+ <input id="i-host" class="form-control" name="host" value="{{host}}" required>
+ </div>
+ <div class="col-md-4">
+ <label for="i-ssl">{{lang_ssl}}</label>
+ <select name="ssl" id="i-ssl" class="form-control">
+ <option value="IMPLICIT" {{IMPLICIT_selected}}>{{lang_sslImplicit}}</option>
+ <option value="NONE" {{NONE_selected}}>{{lang_sslNone}}</option>
+ <option value="EXPLICIT" {{EXPLICIT_selected}}>{{lang_sslExplicit}}</option>
+ </select>
+ </div>
+ <div class="col-md-4">
+ <label for="i-port">{{lang_port}}</label>
+ <input id="i-port" type="number" min="1" max="65535" class="form-control" name="port" value="{{port}}" required>
+ </div>
+ </div>
+ <div class="form-group row">
+ <div class="col-sm-6">
+ <label for="i-username">{{lang_username}}</label>
+ <input id="i-username" class="form-control" name="username" value="{{username}}">
+ </div>
+ <div class="col-sm-6">
+ <label for="i-password">{{lang_password}}</label>
+ <input id="i-password" type="{{password_type}}" class="form-control" name="password" value="{{password}}">
+ </div>
+ </div>
+ <div class="form-group row">
+ <div class="col-sm-6">
+ <label for="i-senderaddress">{{lang_senderAddress}}</label>
+ <input id="i-senderaddress" class="form-control" name="senderaddress" value="{{senderaddress}}" required>
+ </div>
+ <div class="col-sm-6">
+ <label for="i-replyto">{{lang_replyTo}}</label>
+ <input id="i-replyto" class="form-control" name="replyto" value="{{replyto}}">
+ </div>
+ </div>
+ <div class="buttonbar text-right">
+ <a class="btn btn-default" href="?do=eventlog&amp;show=mailconfigs">
+ {{lang_cancel}}
+ </a>
+ <button class="btn btn-primary" type="submit" name="action" value="save-mailconfig">
+ <span class="glyphicon glyphicon-floppy-disk"></span>
+ {{lang_save}}
+ </button>
+ </div>
+</form> \ No newline at end of file
diff --git a/modules-available/eventlog/templates/page-filters-edit-rule.html b/modules-available/eventlog/templates/page-filters-edit-rule.html
new file mode 100644
index 00000000..42d601f2
--- /dev/null
+++ b/modules-available/eventlog/templates/page-filters-edit-rule.html
@@ -0,0 +1,219 @@
+<h2>
+ {{#ruleid}}
+ {{lang_editFilter}}
+ {{/ruleid}}
+ {{^ruleid}}
+ {{lang_createFilter}}
+ {{/ruleid}}
+</h2>
+<h3>{{title}}</h3>
+
+<p>{{lang_filterExampleHelpText}}</p>
+
+<form method="post" action="?do=eventlog&amp;show=rules">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="id" value="{{ruleid}}">
+ <div class="form-group row">
+ <div class="col-md-4">
+ <label for="i-type">{{lang_type}}</label>
+ <input autocomplete="off" id="i-type" list="i-types" class="form-control" name="type" value="{{type}}"
+ required>
+ <datalist id="i-types">
+ {{#types}}
+ <option value="{{.}}">{{lang_typeExample}}: {{.}}</option>
+ {{/types}}
+ </datalist>
+ </div>
+ <div class="col-md-8">
+ <label for="i-title">{{lang_title}}</label>
+ <input id="i-title" class="form-control" name="title" value="{{title}}" required>
+ </div>
+ </div>
+ <div class="form-group row">
+ <div class="col-md-12">
+ <label for="i-description">{{lang_description}}</label>
+ <textarea id="i-description" class="form-control" name="description" rows="4">{{description}}</textarea>
+ </div>
+ </div>
+ <div class="form-group row">
+ <div class="col-md-12">
+ <label for="i-transports">{{lang_transports}}</label>
+ <select multiple name="transports[]" id="i-transports" class="form-control multilist">
+ {{#transports}}
+ <option value="{{transportid}}" {{selected}}>{{title}}</option>
+ {{/transports}}
+ </select>
+ </div>
+ </div>
+ {{#filter}}
+ <div class="form-group row filter-rule-row">
+ <div class="col-md-1 col-sm-3">
+ <label>{{lang_index}}</label>
+ <span class="form-control">{{index}}</span>
+ </div>
+ <div class="col-md-2 col-sm-9">
+ <label for="key-{{index}}">
+ {{lang_filterPath}}
+ </label>
+ <input id="key-{{index}}" class="form-control filter-key" name="filter[{{index}}][path]" value="{{path}}"
+ list="filter-keys"
+ autocomplete="off" data-index="{{index}}">
+ </div>
+ <div class="col-md-1 col-sm-6">
+ <label for="op-{{index}}">
+ {{lang_filterOp}}
+ </label>
+ <select id="op-{{index}}" class="form-control op-select" name="filter[{{index}}][op]" data-index="{{index}}">
+ {{#operators}}
+ <option {{selected}}>{{name}}</option>
+ {{/operators}}
+ </select>
+ </div>
+ <div class="col-md-3 col-sm-6">
+ <label for="arg-{{index}}">
+ {{lang_filterArg}}
+ </label>
+ <input id="arg-{{index}}" class="form-control op-arg" name="filter[{{index}}][arg]" value="{{arg}}"
+ data-index="{{index}}">
+ </div>
+ <div class="col-md-5 col-sm-12 small">
+ <label>{{lang_sampleData}}</label>
+ <div id="sample-{{index}}" style="word-break:break-all"></div>
+ </div>
+ </div>
+ {{/filter}}
+ <datalist id="filter-keys">
+ </datalist>
+ <datalist id="machine-filter-keys">
+ {{#machine_keys}}
+ <option>{{.}}</option>
+ {{/machine_keys}}
+ </datalist>
+ <div>
+ <p>{{lang_hintRegex}}</p>
+ </div>
+ <div class="form-group">
+ <label for="i-subject">{{lang_subject}}</label>
+ <input id="i-subject" class="form-control" name="subject" value="{{subject}}">
+ </div>
+ <div class="form-group">
+ <label for="msg-txt">
+ {{lang_messageTemplate}}
+ </label>
+ <textarea required id="msg-txt" name="message" class="form-control" rows="10" cols="80">{{message}}</textarea>
+ <p>
+ {{lang_messageTemplateHelp}}
+ </p>
+ </div>
+ <div class="buttonbar text-right">
+ <a class="btn btn-default" href="?do=eventlog&amp;show=rules">
+ {{lang_cancel}}
+ </a>
+ <button class="btn btn-primary" type="submit" name="action" value="save-filter">
+ <span class="glyphicon glyphicon-floppy-disk"></span>
+ {{lang_save}}
+ </button>
+ </div>
+</form>
+
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ var $multilists = $("select.multilist");
+ if ($multilists.multiselect) {
+ $multilists.multiselect({
+ includeSelectAllOption: true,
+ buttonWidth: '100%',
+ buttonClass: 'form-control'
+ });
+ }
+ $('.op-select').change(function () {
+ var $t = $(this);
+ var disabled = $t.val() === '*';
+ $('.op-arg[data-index=' + $t.data('index') + ']').prop('disabled', disabled);
+ }).change();
+ var currentType = {};
+ var typeSamples = {};
+ var typeChanged = true;
+ var $type = $('#i-type');
+ var $list = $('#filter-keys');
+ var $fkInputs = $('.filter-key');
+ var $filterRows = $('.filter-rule-row');
+
+ // If type changed, fetch sample data, or use cached, and populate autocomplete
+ var typeFieldChangeUpdate = function () {
+ if (!typeChanged)
+ return;
+ typeChanged = false;
+ var typeVal = $type.val();
+ if (typeSamples[typeVal]) {
+ setAutocomplete(typeVal);
+ return;
+ }
+ $.ajax('?do=eventlog&show=rules', {
+ data: {type: typeVal, token: TOKEN},
+ method: 'POST',
+ dataType: 'json'
+ }).done(function (data) {
+ typeSamples[typeVal] = data;
+ setAutocomplete(typeVal);
+ });
+ };
+
+ // Flag if type changed
+ $type.change(function () {
+ typeChanged = true;
+ }).blur(typeFieldChangeUpdate);
+
+ // Population function
+ function setAutocomplete(type) {
+ var t = typeSamples[type];
+ var m = false;
+ $list.empty();
+ if (!t)
+ return;
+ currentType = t;
+ for (var k in t) {
+ if (!t.hasOwnProperty(k))
+ continue;
+ $list.append($('<option>').text(k));
+ if (k === 'machineuuid') m = true;
+ }
+ if (m) {
+ //$list.append($('#machine-filter-keys').clone());
+ }
+ $fkInputs.change();
+ }
+
+ // Display sample data
+ var chFn = function () {
+ var $this = $(this);
+ var wat = currentType[$this.val()];
+ if (typeof(wat) !== 'undefined') {
+ if (typeof(wat) === 'string') {
+ wat = wat.replace("\r", "\\r").replace("\n", "\\n");
+ }
+ if (wat.length > 180) {
+ wat = wat.substr(0, 180) + '...';
+ }
+ } else {
+ wat = '';
+ }
+ var index = $this.data('index');
+ $('#sample-' + index).text(wat);
+ var empties = 0;
+ $filterRows.each(function() {
+ var $this = $(this);
+ if ($this.find('.filter-key').val().length === 0) {
+ empties++;
+ if (empties > 2) {
+ $this.hide();
+ } else {
+ $this.show();
+ }
+ }
+ });
+ };
+ $fkInputs.on('input', chFn).change(chFn).each(chFn);
+ typeFieldChangeUpdate();
+ });
+</script>
diff --git a/modules-available/eventlog/templates/page-filters-edit-transport.html b/modules-available/eventlog/templates/page-filters-edit-transport.html
new file mode 100644
index 00000000..d8be6892
--- /dev/null
+++ b/modules-available/eventlog/templates/page-filters-edit-transport.html
@@ -0,0 +1,190 @@
+<h2>{{lang_editTransport}} {{#title}}–{{/title}} {{title}}</h2>
+
+<form method="post" action="?do=eventlog&amp;show=transports">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="id" value="{{transportid}}">
+
+ <div class="form-group row">
+ <div class="col-sm-6">
+ <label for="title">{{lang_title}}</label>
+ <input id="title" name="title" class="form-control" value="{{title}}" required>
+ </div>
+ <div class="col-sm-6">
+ <label for="transport-select">
+ {{lang_type}}
+ </label>
+ <select id="transport-select" class="form-control" name="type">
+ <option value="mail" {{mail_selected}}>{{lang_mail}}</option>
+ <option value="irc" {{irc_selected}}>{{lang_irc}}</option>
+ <option value="http" {{http_selected}}>{{lang_http}}</option>
+ <option value="group" {{group_selected}}>{{lang_transportGroup}}</option>
+ </select>
+ </div>
+ </div>
+ <hr>
+
+ <div class="transport-list">
+ <div id="transport-mail">
+ <div class="form-group row">
+ <div class="col-md-6">
+ <label for="mail-config">{{lang_mailConfig}}</label>
+ <select class="form-control" name="mail-config-id" id="mail-config">
+ {{^mailconfigs}}
+ <option value="0" disabled>{{lang_noMailConfig}}</option>
+ {{/mailconfigs}}
+ {{#mailconfigs}}
+ <option value="{{configid}}" {{selected}}>{{senderaddress}} @ {{host}}:{{port}}</option>
+ {{/mailconfigs}}
+ </select>
+ </div>
+ <div class="col-md-6">
+ <label for="mail-users">{{lang_mailUsers}}</label>
+ <select class="form-control multilist" name="mail-users[]" multiple id="mail-users">
+ {{#users}}
+ <option value="{{userid}}" {{selected}} {{disabled}}>{{login}} - {{fullname}} - {{email}}</option>
+ {{/users}}
+ </select>
+ </div>
+ </div>
+ <div class="form-group row">
+ <div class="col-md-12">
+ <label for="mail-extra-mails">{{lang_additionalMailAddresses}}</label>
+ <textarea class="form-control" name="mail-extra-mails" id="mail-extra-mails">{{data.mail-extra-mails}}</textarea>
+ </div>
+ </div>
+ </div>
+
+ <div id="transport-irc">
+ <div class="form-group row">
+ <div class="col-md-4 col-sm-6">
+ <label for="irc-server">{{lang_ircServer}}</label>
+ <input id="irc-server" name="irc-server" class="form-control" value="{{data.irc-server}}"
+ placeholder="irc.example.com">
+ </div>
+ <div class="col-md-4 col-sm-6">
+ <label for="irc-target">{{lang_ircTarget}}</label>
+ <input id="irc-target" name="irc-target" class="form-control" value="{{data.irc-target}}" placeholder="#foo">
+ </div>
+ <div class="col-md-4 col-sm-6">
+ <label for="irc-server-passwd">{{lang_ircServerPassword}}</label>
+ <input id="irc-server-passwd" name="irc-server-passwd" class="form-control"
+ value="{{data.irc-server-passwd}}">
+ </div>
+ </div>
+ <div class="form-group row">
+ <div class="col-md-4 col-sm-6">
+ <label for="irc-nickname">{{lang_ircNickname}}</label>
+ <input id="irc-nickname" name="irc-nickname" class="form-control" value="{{data.irc-nickname}}"
+ placeholder="Brunhilde">
+ </div>
+ </div>
+ </div>
+
+ <div id="transport-http">
+ <div class="form-group row">
+ <div class="col-md-10">
+ <label for="http-uri">{{lang_httpUri}}</label>
+ <input id="http-uri" name="http-uri" class="form-control" value="{{data.http-uri}}"
+ placeholder="https://example.com/bwlp">
+ <p>{{lang_uriUseSUBJECTandTEXThint}}</p>
+ </div>
+ <div class="col-md-2">
+ <label for="http-method">{{lang_httpMethod}}</label>
+ <select id="http-method" name="http-method" class="form-control">
+ <option {{POST_selected}}>POST</option>
+ <option {{GET_selected}}>GET</option>
+ </select>
+ </div>
+ </div>
+ <div id="post-options" class="form-group row">
+ <div class="col-md-7">
+ <label for="http-post-field">{{lang_httpPostField}}</label>
+ <input id="http-post-field" name="http-post-field" class="form-control" value="{{data.http-post-field}}"
+ placeholder="key=1234&message=%TEXT%">
+ <p>{{lang_postUseSUBJECTandTEXThint}}</p>
+ </div>
+ <div class="col-md-5">
+ <label for="http-post-format">{{lang_httpPostFormat}}</label>
+ <select id="http-post-format" name="http-post-format" class="form-control">
+ <option value="FORM" {{FORM_selected}} aria-describedby="d-fd">FORM-data (urlencode)</option>
+ <option value="JSON" {{JSON_selected}} aria-describedby="d-js">json string</option>
+ <option value="JSON_AUTO" {{JSON_AUTO_selected}} aria-describedby="d-aj">{{lang_autoJson}}</option>
+ </select>
+ <div id="d-fd"><b>FORM-data</b>: {{lang_formDataHelp}}</div>
+ <div id="d-js"><b>json string</b>: {{lang_jsonStringHelp}}</div>
+ <div id="d-aj"><b>{{lang_autoJson}}</b>: {{lang_autoJsonHelp}}</div>
+ </div>templates
+ </div>
+ <div class="form-group">
+ <label for="http-method"></label>
+ </div>
+ </div>
+
+ <div id="transport-group">
+ <div class="form-group">
+ <label for="group-list">{{lang_selectTransports}}</label>
+ <select class="form-control multilist" name="group-list[]" multiple id="group-list">
+ {{#backends}}
+ <option value="{{transportid}}" {{selected}}>{{title}}</option>
+ {{/backends}}
+ </select>
+ </div>
+ </div>
+ </div>
+ <hr>
+
+ <div class="form-group">
+ <label for="i-rules">{{lang_rules}}</label>
+ <select multiple name="rules[]" id="i-rules" class="form-control multilist">
+ {{#rules}}
+ <option value="{{ruleid}}" {{selected}}>{{title}}</option>
+ {{/rules}}
+ </select>
+ </div>
+
+ <div class="form-group">
+ <label for="description-box">{{lang_optionalDescription}}</label>
+ <textarea id="description-box" name="description" class="form-control" rows="10">{{description}}</textarea>
+ </div>
+
+ <div class="buttonbar text-right">
+ <a class="btn btn-default" href="?do=eventlog&amp;show=transports">
+ {{lang_cancel}}
+ </a>
+ <button class="btn btn-primary" type="submit" name="action" value="save-transport">
+ <span class="glyphicon glyphicon-floppy-disk"></span>
+ {{lang_save}}
+ </button>
+ </div>
+</form>
+
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ // Show proper transport options
+ $('#transport-select').change(function () {
+ $('.transport-list > div').hide();
+ $('#transport-' + $('#transport-select').val()).show();
+ }).change();
+ // Init multilist of available
+ var $multilists = $("select.multilist");
+ if ($multilists.multiselect) {
+ $multilists.multiselect({
+ includeSelectAllOption: true,
+ buttonWidth: '100%',
+ buttonClass: 'form-control'
+ });
+ }
+ // Hide POST options for GET
+ $('#http-method').change(function () {
+ if ($(this).val() === 'POST') {
+ $('#post-options').show();
+ } else {
+ $('#post-options').hide();
+ }
+ }).change();
+ // Disable POST input for JSON_AUTO
+ $('#http-post-format').change(function () {
+ $('#http-post-field').prop('disabled', $(this).val() === 'JSON_AUTO');
+ }).change();
+ });
+</script> \ No newline at end of file
diff --git a/modules-available/eventlog/templates/page-filters-mailconfigs.html b/modules-available/eventlog/templates/page-filters-mailconfigs.html
new file mode 100644
index 00000000..08901f87
--- /dev/null
+++ b/modules-available/eventlog/templates/page-filters-mailconfigs.html
@@ -0,0 +1,42 @@
+<form method="post" action="?do=eventlog&amp;show=mailconfigs">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="action" value="delete-mailconfig">
+ <table class="table">
+ <thead>
+ <tr>
+ <th class="slx-smallcol">{{lang_id}}</th>
+ <th class="slx-smallcol">{{lang_host}}</th>
+ <th class="slx-smallcol">{{lang_ssl}}</th>
+ <th>{{lang_senderAddress}}</th>
+ <th class="slx-smallcol">{{lang_edit}}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {{#configs}}
+ <tr>
+ <td>{{configid}}</td>
+ <td class="text-nowrap">{{host}}:{{port}}</td>
+ <td class="text-nowrap">{{ssl}}</td>
+ <td>{{senderaddress}}{{^senderaddress}}{{replyto}}{{/senderaddress}}</td>
+ <td class="text-nowrap">
+ <a class="btn btn-xs btn-default" href="?do=eventlog&amp;show=mailconfigs&amp;id={{configid}}">
+ <span class="glyphicon glyphicon-edit" aria-label="{{lang_edit}}"></span>
+ </a>
+ <button class="btn btn-xs btn-danger" type="submit" name="id" value="{{configid}}"
+ data-confirm="{{lang_reallyDelete}}">
+ <span class="glyphicon glyphicon-trash"></span>
+ </button>
+ </td>
+ </tr>
+ {{/configs}}
+ </tbody>
+ </table>
+
+</form>
+
+<div class="buttonbar text-right">
+ <a class="btn btn-success" href="?do=eventlog&amp;show=mailconfigs&amp;id=0">
+ <span class="glyphicon glyphicon-plus"></span>
+ {{lang_add}}
+ </a>
+</div> \ No newline at end of file
diff --git a/modules-available/eventlog/templates/page-filters-rules.html b/modules-available/eventlog/templates/page-filters-rules.html
new file mode 100644
index 00000000..56bf0871
--- /dev/null
+++ b/modules-available/eventlog/templates/page-filters-rules.html
@@ -0,0 +1,48 @@
+<form method="post" action="?do=eventlog&amp;show=rules">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="action" value="delete-filter">
+ <table class="table">
+ <thead>
+ <tr>
+ <th class="slx-smallcol">{{lang_id}}</th>
+ <th class="slx-smallcol">{{lang_type}}</th>
+ <th>{{lang_title}}</th>
+ <!--th>{{lang_details}}</th-->
+ <th class="slx-smallcol"></th>
+ <th class="slx-smallcol">{{lang_edit}}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {{#filters}}
+ <tr>
+ <td>{{ruleid}}</td>
+ <td>{{type}}</td>
+ <td class="text-nowrap">{{title}}</td>
+ <td><span class="badge">{{useCount}}</span></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}}">
+ <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}}">
+ <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}}"
+ data-confirm="{{lang_reallyDelete}}" {{perms.filter.rules.edit.disabled}}>
+ <span class="glyphicon glyphicon-trash"></span>
+ </button>
+ </td>
+ </tr>
+ {{/filters}}
+ </tbody>
+ </table>
+
+</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">
+ <span class="glyphicon glyphicon-plus"></span>
+ {{lang_add}}
+ </a>
+</div> \ No newline at end of file
diff --git a/modules-available/eventlog/templates/page-filters-transports.html b/modules-available/eventlog/templates/page-filters-transports.html
new file mode 100644
index 00000000..3047e437
--- /dev/null
+++ b/modules-available/eventlog/templates/page-filters-transports.html
@@ -0,0 +1,45 @@
+<form method="post" action="?do=eventlog&amp;show=transports">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="action" value="delete-transport">
+ <table class="table">
+ <thead>
+ <tr>
+ <th class="slx-smallcol">{{lang_id}}</th>
+ <th class="slx-smallcol">{{lang_type}}</th>
+ <th>{{lang_title}}</th>
+ <th>{{lang_details}}</th>
+ <th class="slx-smallcol"></th>
+ <th class="slx-smallcol">{{lang_edit}}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {{#transports}}
+ <tr>
+ <td>{{transportid}}</td>
+ <td>{{type}}</td>
+ <td>{{title}}</td>
+ <td class="small">{{details.toString}}</td>
+ <td><span class="badge">{{useCount}}</span></td>
+ <td class="slx-smallcol">
+ <a class="btn btn-xs btn-default"
+ href="?do=eventlog&amp;show=transports&amp;id={{transportid}}">
+ <span class="glyphicon glyphicon-edit" aria-label="{{lang_edit}}"></span>
+ </a>
+ <button class="btn btn-xs btn-danger" type="submit" name="id" value="{{transportid}}"
+ data-confirm="{{lang_reallyDelete}}">
+ <span class="glyphicon glyphicon-trash"></span>
+ </button>
+ </td>
+ </tr>
+ {{/transports}}
+ </tbody>
+ </table>
+
+</form>
+
+<div class="buttonbar text-right">
+ <a class="btn btn-success" href="?do=eventlog&amp;show=transports&amp;id=0">
+ <span class="glyphicon glyphicon-plus"></span>
+ {{lang_add}}
+ </a>
+</div> \ No newline at end of file
diff --git a/modules-available/eventlog/templates/page-header.html b/modules-available/eventlog/templates/page-header.html
new file mode 100644
index 00000000..a5e30af9
--- /dev/null
+++ b/modules-available/eventlog/templates/page-header.html
@@ -0,0 +1,16 @@
+<h1>{{lang_logAndEvents}}</h1>
+
+<ul class="nav nav-tabs">
+ <li class="{{active_log}}">
+ <a href="?do=eventlog&amp;show=log">{{lang_eventLog}}</a>
+ </li>
+ <li class="{{active_rules}}">
+ <a href="?do=eventlog&amp;show=rules">{{lang_filterRules}}</a>
+ </li>
+ <li class="{{active_transports}}">
+ <a href="?do=eventlog&amp;show=transports">{{lang_transports}}</a>
+ </li>
+ <li class="{{active_mailconfigs}}">
+ <a href="?do=eventlog&amp;show=mailconfigs">{{lang_mailconfigs}}</a>
+ </li>
+</ul> \ No newline at end of file