summaryrefslogtreecommitdiffstats
path: root/modules-available/dozmod
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/dozmod')
-rw-r--r--modules-available/dozmod/lang/de/messages.json5
-rw-r--r--modules-available/dozmod/lang/de/template-tags.json6
-rw-r--r--modules-available/dozmod/lang/en/messages.json5
-rw-r--r--modules-available/dozmod/pages/networkrules.inc.php77
-rw-r--r--modules-available/dozmod/templates/networkrules-edit.html98
-rw-r--r--modules-available/dozmod/templates/networkrules.html6
6 files changed, 136 insertions, 61 deletions
diff --git a/modules-available/dozmod/lang/de/messages.json b/modules-available/dozmod/lang/de/messages.json
index 805472d0..076e36d5 100644
--- a/modules-available/dozmod/lang/de/messages.json
+++ b/modules-available/dozmod/lang/de/messages.json
@@ -12,10 +12,11 @@
"ldap-invalid-filter-id": "Ung\u00fcltige LDAP Filter ID",
"mail-config-saved": "Mail-Konfiguration gespeichert",
"networkrule-deleted": "Netzwerk-Regel gel\u00f6scht",
+ "networkrule-empty-set": "Leeres Regelset; nicht gespeichert",
"networkrule-invalid-direction": "Ung\u00fcltige Richtung: {{0}}",
+ "networkrule-invalid-host": "Ung\u00fcltiger Host: {{0}}; Zeile ignoriert",
+ "networkrule-invalid-port": "Ung\u00fcltiger Port: {{0}}; Zeile ignoriert",
"networkrule-invalid-ruleid": "Nicht-existierende Regel: {{0}}",
- "networkrule-missing-host": "Fehlende Hostangabe",
- "networkrule-missing-port": "Fehlende Portangabe",
"networkrule-saved": "Netzwerk-Regel gespeichert",
"networkshare-deleted": "Netzlaufwerk gel\u00f6scht",
"networkshare-invalid-auth-type": "Ung\u00fcltiger Authentifizierungs-Typ: {{0}}",
diff --git a/modules-available/dozmod/lang/de/template-tags.json b/modules-available/dozmod/lang/de/template-tags.json
index 81c4b9da..63824cf0 100644
--- a/modules-available/dozmod/lang/de/template-tags.json
+++ b/modules-available/dozmod/lang/de/template-tags.json
@@ -1,7 +1,7 @@
{
"lang_actionTarget": "Aktionsziel",
"lang_active": "Aktiv",
- "lang_addRule": "Netzwerk-Regel hinzuf\u00fcgen",
+ "lang_addRule": "Netzwerkregel hinzuf\u00fcgen",
"lang_addShare": "Netzlaufwerk hinzuf\u00fcgen",
"lang_allowLoginByDefault": "Login standardm\u00e4\u00dfig erlauben",
"lang_allowLoginDescription": "Wenn diese Option aktiviert ist, k\u00f6nnen sich alle Mitarbeiter der Einrichtung \u00fcber die bwLehrpool-Suite anmelden und VMs\/Veranstaltungen verwalten. Wenn Sie diese Option deaktivieren, m\u00fcssen Sie in der Untersektion \"Benutzer und Berechtigungen\" jeden Benutzer nach dem ersten Loginversuch manuell freischalten.",
@@ -26,7 +26,7 @@
"lang_description_delete_images": "Diese Liste zeigt VMs, die entweder abgelaufen sind, oder deren Datei besch\u00e4digt, verschoben oder gel\u00f6scht wurde. Diese Images sind zur Zeit im Lehrpool nicht verf\u00fcgbar, ihre endg\u00fcltige L\u00f6schung muss aber manuell best\u00e4tigt werden, um gr\u00f6\u00dfere Katastrophen durch Softwarefehler, verstellte Systemuhren etc. zu vermeiden.",
"lang_direction": "Richtung",
"lang_dozmodLogHeading": "bwLehrpool-Suite Aktionslog",
- "lang_editNetworkrule": "Netzwerk-Regel bearbeiten",
+ "lang_editNetworkrule": "Netzwerkregel bearbeiten",
"lang_editNetworkshare": "Netzlaufwerk bearbeiten",
"lang_editScript": "Startscript bearbeiten",
"lang_email": "EMail",
@@ -69,7 +69,7 @@
"lang_miscOptions": "Verschiedene Einstellungen",
"lang_modified": "Modifiziert",
"lang_name": "Name",
- "lang_networkrules": "Netzwerk-Regeln",
+ "lang_networkrules": "Netzwerkregeln",
"lang_networkrulesIntro": "Hier k\u00f6nnen Sie vordefinierte Regelsets f\u00fcr das Firewalling verwalten. Nutzer der bwLehrpool-Suite k\u00f6nnen auf diese Regelsets zur\u00fcckgreifen, um den Netzwerkzugriff ihrer Veranstaltungen einzuschr\u00e4nken.",
"lang_networkshares": "Netzlaufwerke",
"lang_networksharesIntro": "Hier k\u00f6nnen Sie vordefinierte Netzlaufwerke anlegen, die den Nutzern der bwLehrpool-Suite zur Auswahl gestellt werden. Es ist den Nutzern der bwLehrpool-Suite weiterhin m\u00f6glich, komplett eigene Netzwerkfreigaben zu definieren. Die Angaben hier sollen lediglich das Hinzuf\u00fcgen h\u00e4ufig genutzter Laufwerke vereinfachen, bzw. das \u00c4ndern eines Netzwerkpfades vereinfachen, da in diesem Fall nur der Zentrale Eintrag hier angepasst werden muss, und nicht mehr wie zuvor jede Veranstaltung einzeln.",
diff --git a/modules-available/dozmod/lang/en/messages.json b/modules-available/dozmod/lang/en/messages.json
index 2d813efc..1300c60d 100644
--- a/modules-available/dozmod/lang/en/messages.json
+++ b/modules-available/dozmod/lang/en/messages.json
@@ -12,10 +12,11 @@
"ldap-invalid-filter-id": "Invalid LDAP filter id",
"mail-config-saved": "Mail config saved",
"networkrule-deleted": "Network rule deleted",
+ "networkrule-empty-set": "Empty ruleset; not saved",
"networkrule-invalid-direction": "Invalid direction: {{0}}",
+ "networkrule-invalid-host": "Invalid host: {{0}}, ignoring row",
+ "networkrule-invalid-port": "Invalid port: {{0}}, ignoring row",
"networkrule-invalid-ruleid": "Invalid rule id: {{0}}",
- "networkrule-missing-host": "Missing host",
- "networkrule-missing-port": "Missing port",
"networkrule-saved": "Network rule saved",
"networkshare-deleted": "Network share deleted",
"networkshare-invalid-auth-type": "Invalid auth type: {{0}}",
diff --git a/modules-available/dozmod/pages/networkrules.inc.php b/modules-available/dozmod/pages/networkrules.inc.php
index 6011e3ff..710e90a9 100644
--- a/modules-available/dozmod/pages/networkrules.inc.php
+++ b/modules-available/dozmod/pages/networkrules.inc.php
@@ -11,7 +11,7 @@ class SubPage
User::assertPermission('networkrules.save');
$ruleid = Request::post('ruleid', false, 'int');
if ($ruleid !== false) {
- $res = Database::exec('DELETE FROM sat.presetnetworkrules WHERE ruleid = :ruleid', ['ruleid' => $ruleid]);
+ $res = Database::exec('DELETE FROM sat.presetnetworkrule WHERE ruleid = :ruleid', ['ruleid' => $ruleid]);
if ($res !== false) {
Message::addSuccess('networkrule-deleted');
}
@@ -20,28 +20,43 @@ class SubPage
User::assertPermission('networkrules.save');
$ruleid = Request::post('ruleid', 0, 'int');
$rulename = Request::post('rulename', '', 'string');
- $host = Request::post('host', '', 'string');
- $port = Request::post('port', '', 'string');
- $direction = Request::post('direction', '', 'string');
+ $hosts = Request::post('host', false, 'array');
+ $ports = Request::post('port', false, 'array');
+ $directions = Request::post('direction', false, 'array');
- if (!in_array($direction, ['IN', 'OUT'], true)) {
- Message::addError('networkrule-invalid-direction', $direction);
- } elseif (empty($host)) {
- Message::addError('networkrule-missing-host');
- } elseif (empty($port)) {
- Message::addError('networkrule-missing-port');
+ $data = [];
+ foreach (array_keys($hosts) as $key) {
+ if (!isset($hosts[$key]) || !isset($ports[$key]) || !isset($directions[$key]))
+ continue;
+ if (!in_array($directions[$key], ['IN', 'OUT'], true)) {
+ Message::addWarning('networkrule-invalid-direction', $directions[$key]);
+ continue;
+ }
+ settype($ports[$key], 'int');
+ if ($ports[$key] < 0 || $ports[$key] > 65535) {
+ Message::addWarning('networkrule-invalid-port', $ports[$key]);
+ continue;
+ }
+ if (empty($hosts[$key]) || strpos($hosts[$key], ' ') !== false) { // Rather sloppy...
+ Message::addWarning('networkrule-invalid-host', $hosts[$key]);
+ continue;
+ }
+ $data[] = [
+ 'host' => $hosts[$key],
+ 'port' => $ports[$key],
+ 'direction' => $directions[$key],
+ ];
+ }
+ if (empty($data)) {
+ Message::addError('networkrule-empty-set');
} else {
- $data = json_encode([
- 'host' => $host,
- 'port' => $port,
- 'direction' => $direction
- ]);
+ $data = json_encode($data);
if ($ruleid !== 0) {
- Database::exec('UPDATE sat.presetnetworkrules SET rulename = :rulename, ruledata = :data'
- .' WHERE ruleid = :ruleid', compact('ruleid', 'rulename', 'data'));
+ Database::exec('UPDATE sat.presetnetworkrule SET rulename = :rulename, ruledata = :data'
+ . ' WHERE ruleid = :ruleid', compact('ruleid', 'rulename', 'data'));
} else {
- Database::exec('INSERT INTO sat.presetnetworkrules (rulename, ruledata)'
- .' VALUES (:rulename, :data)', compact('rulename', 'data'));
+ Database::exec('INSERT INTO sat.presetnetworkrule (rulename, ruledata)'
+ . ' VALUES (:rulename, :data)', compact('rulename', 'data'));
}
Message::addSuccess('networkrule-saved');
}
@@ -57,14 +72,10 @@ class SubPage
$show = Request::get('show', 'list', 'string');
if ($show === 'list') {
$res = Database::simpleQuery('SELECT ruleid, rulename, ruledata
- FROM sat.presetnetworkrules ORDER BY rulename ASC');
+ FROM sat.presetnetworkrule ORDER BY rulename ASC');
$rows = array();
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $dec = json_decode($row['ruledata'], true);
- if (!is_array($dec)) {
- $dec = [];
- }
- $rows[] = $row + $dec;
+ $rows[] = $row;
}
Render::addTemplate('networkrules', [
'networkrules' => $rows,
@@ -76,20 +87,22 @@ class SubPage
$data = [];
} else {
$data = Database::queryFirst('SELECT ruleid, rulename, ruledata
- FROM sat.presetnetworkrules WHERE ruleid = :ruleid', ['ruleid' => $ruleid]);
+ FROM sat.presetnetworkrule WHERE ruleid = :ruleid', ['ruleid' => $ruleid]);
if ($data === false) {
Message::addError('networkrule-invalid-ruleid', $ruleid);
Util::redirect('?do=dozmod&section=networkrules');
}
$dec = json_decode($data['ruledata'], true);
- if (is_array($dec)) {
- $data += $dec;
+ if (!is_array($dec) || !isset($dec[0])) {
+ $dec = [[]];
}
- if ($data['direction'] === 'IN') {
- $data['inSelected'] = 'selected';
- } else {
- $data['outSelected'] = 'selected';
+ $data['rules'] = $dec;
+ $i = 0;
+ foreach ($data['rules'] as &$rule) {
+ $rule['index'] = ++$i;
+ $rule[$rule['direction'] . '_selected'] = 'selected';
}
+ unset($rule);
}
Render::addTemplate('networkrules-edit', $data);
}
diff --git a/modules-available/dozmod/templates/networkrules-edit.html b/modules-available/dozmod/templates/networkrules-edit.html
index c04e2825..1d4404cc 100644
--- a/modules-available/dozmod/templates/networkrules-edit.html
+++ b/modules-available/dozmod/templates/networkrules-edit.html
@@ -14,21 +14,68 @@
<label class="input-group-addon" for="rulename">{{lang_name}}</label>
<input required type="text" name="rulename" id="rulename" class="form-control" value="{{rulename}}">
</div>
- <div class="input-group">
- <label class="input-group-addon" for="host">{{lang_host}}</label>
- <input required type="text" name="host" id="host" class="form-control" value="{{host}}">
- </div>
- <div class="input-group">
- <label class="input-group-addon" for="port">{{lang_port}}</label>
- <input required type="number" name="port" id="port" class="form-control" value="{{port}}">
- </div>
- <div class="input-group">
- <label class="input-group-addon" for="direction">{{lang_direction}}</label>
- <select class="form-control" name="direction" id="direction">
- <option {{inSelected}} value="IN">IN</option>
- <option {{outSelected}} value="OUT">OUT</option>
- </select>
- </div>
+ <br>
+ <table class="table" id="main-table">
+ <thead>
+ <tr>
+ <th>{{lang_host}}</th>
+ <th>{{lang_port}}</th>
+ <th>{{lang_direction}}</th>
+ <th class="slx-smallcol"></th>
+ </tr>
+ </thead>
+ {{#rules}}
+ <tbody>
+ <tr>
+ <td>
+ <input required type="text" name="host[{{index}}]" class="form-control" value="{{host}}">
+ </td>
+ <td>
+ <input required type="number" name="port[{{index}}]" class="form-control" value="{{port}}">
+ </td>
+ <td>
+ <select class="form-control" name="direction[{{index}}]">
+ <option {{IN_selected}} value="IN">IN</option>
+ <option {{OUT_selected}} value="OUT">OUT</option>
+ </select>
+ </td>
+ <td>
+ <button type="button" class="btn btn-sm btn-danger btn-del-row">
+ <span class="glyphicon glyphicon-remove"></span>
+ </button>
+ </td>
+ </tr>
+ {{/rules}}
+ <tr class="hidden" id="rule-template">
+ <td>
+ <input type="text" class="form-control">
+ </td>
+ <td>
+ <input type="number" class="form-control">
+ </td>
+ <td>
+ <select class="form-control">
+ <option {{IN_selected}} value="IN">IN</option>
+ <option {{OUT_selected}} value="OUT">OUT</option>
+ </select>
+ </td>
+ <td>
+ <button type="button" class="btn btn-sm btn-danger btn-del-row">
+ <span class="glyphicon glyphicon-remove"></span>
+ </button>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="4">
+ <div class="pull-right">
+ <button id="btn-add" class="btn btn-sm btn-success" type="button">
+ <span class="glyphicon glyphicon-plus-sign"></span>
+ </button>
+ </div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
<div class="text-right" style="margin-top: 20px">
<a href="?do=dozmod&amp;section=networkrules" class="btn btn-default">
{{lang_cancel}}
@@ -40,4 +87,23 @@
</div>
</form>
</div>
-</div> \ No newline at end of file
+</div>
+
+<script>
+ document.addEventListener('DOMContentLoaded', function() {
+ var $template = $('#rule-template');
+ var newAddIndex = 0;
+ $('#btn-add').click(function () {
+ var $new = $template.clone(true);
+ newAddIndex++;
+ $new.find('input[type=text]').prop('name', 'host[n' + newAddIndex + ']').prop('required', true);
+ $new.find('input[type=number]').prop('name', 'port[n' + newAddIndex + ']').prop('required', true);
+ $new.find('select').prop('name', 'direction[n' + newAddIndex + ']').prop('required', true);
+ $new.insertBefore($template);
+ $new.removeClass('hidden');
+ });
+ $('.btn-del-row').click(function() {
+ $(this).closest('tr').remove();
+ });
+ });
+</script> \ No newline at end of file
diff --git a/modules-available/dozmod/templates/networkrules.html b/modules-available/dozmod/templates/networkrules.html
index 4344ff4f..eb16a7ed 100644
--- a/modules-available/dozmod/templates/networkrules.html
+++ b/modules-available/dozmod/templates/networkrules.html
@@ -8,9 +8,6 @@
<thead>
<tr>
<th>{{lang_name}}</th>
- <th>{{lang_host}}</th>
- <th>{{lang_port}}</th>
- <th>{{lang_direction}}</th>
{{#hasEditPermissions}}
<th class="slx-smallcol">{{lang_edit}}</th>
<th class="slx-smallcol">{{lang_delete}}</th>
@@ -21,9 +18,6 @@
{{#networkrules}}
<tr>
<td>{{rulename}}</td>
- <td>{{host}}</td>
- <td>{{port}}</td>
- <td>{{direction}}</td>
{{#hasEditPermissions}}
<td align="center">
<a href="?do=dozmod&amp;section=networkrules&amp;show=edit&amp;ruleid={{ruleid}}" class="btn btn-xs btn-primary">