diff options
author | Simon Rettberg | 2021-06-25 16:21:17 +0200 |
---|---|---|
committer | Simon Rettberg | 2021-06-25 16:21:17 +0200 |
commit | 32f0677dbca9e3347b931c1d0105eb37aa57e90d (patch) | |
tree | ddad4562e7ee8439a24e2462d44614692bb71d14 /modules-available/eventlog/pages/mailconfigs.inc.php | |
parent | Update .idea (diff) | |
download | slx-admin-32f0677dbca9e3347b931c1d0105eb37aa57e90d.tar.gz slx-admin-32f0677dbca9e3347b931c1d0105eb37aa57e90d.tar.xz slx-admin-32f0677dbca9e3347b931c1d0105eb37aa57e90d.zip |
[eventlog] Add event filtering and notification system
Diffstat (limited to 'modules-available/eventlog/pages/mailconfigs.inc.php')
-rw-r--r-- | modules-available/eventlog/pages/mailconfigs.inc.php | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/modules-available/eventlog/pages/mailconfigs.inc.php b/modules-available/eventlog/pages/mailconfigs.inc.php new file mode 100644 index 00000000..6d5d20b6 --- /dev/null +++ b/modules-available/eventlog/pages/mailconfigs.inc.php @@ -0,0 +1,98 @@ +<?php + +class SubPage +{ + + const OP_LIST = ['=', '!=', '<', '<=', '>', '>=', 'regex']; + + public static function doPreprocess() + { + if (Request::isPost()) { + $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() + { + $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) + { + 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 |