summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2018-12-03 14:58:25 +0100
committerSimon Rettberg2018-12-03 14:58:25 +0100
commit3104f69bd48bd7241a5ae1077f9f8f8720572bb3 (patch)
tree30b31f00b22efa29c21110d93afe11e53e922f0b
parent[locationinfo] HiS: Check if event has any planned dates (diff)
downloadslx-admin-3104f69bd48bd7241a5ae1077f9f8f8720572bb3.tar.gz
slx-admin-3104f69bd48bd7241a5ae1077f9f8f8720572bb3.tar.xz
slx-admin-3104f69bd48bd7241a5ae1077f9f8f8720572bb3.zip
[dozmod] Networkshares: New DB scheme, error checks
-rw-r--r--modules-available/dozmod/pages/networkshares.inc.php89
-rw-r--r--modules-available/dozmod/templates/ldapfilters.html5
-rw-r--r--modules-available/dozmod/templates/networkshares-edit.html21
-rw-r--r--modules-available/dozmod/templates/networkshares.html32
4 files changed, 107 insertions, 40 deletions
diff --git a/modules-available/dozmod/pages/networkshares.inc.php b/modules-available/dozmod/pages/networkshares.inc.php
index d0bbe03a..659321b4 100644
--- a/modules-available/dozmod/pages/networkshares.inc.php
+++ b/modules-available/dozmod/pages/networkshares.inc.php
@@ -10,32 +10,51 @@ class SubPage
if ($action === 'delete') {
User::assertPermission('networkshares.save');
$shareid = Request::post('shareid', false, 'int');
- if ($shareid) {
+ if ($shareid !== false) {
$res = Database::exec('DELETE FROM sat.presetnetworkshare WHERE shareid = :shareid', ['shareid' => $shareid]);
- if ($res) Message::addSuccess('networkshare-deleted');
+ if ($res !== false) {
+ Message::addSuccess('networkshare-deleted');
+ }
}
} else if ($action === 'save') {
User::assertPermission('networkshares.save');
- $shareid = Request::post('shareid', false, 'int');
- $sharename = Request::post('sharename', false, 'string');
+ $shareid = Request::post('shareid', 0, 'int');
+ $sharename = Request::post('sharename', '', 'string');
$path = Request::post('path', false, 'string');
- $target = Request::post('target', null, 'string');
- $username = Request::post('username', null, 'string');
- $password = Request::post('password', null, 'string');
- if ($sharename && $path) {
- if ($shareid) {
- Database::exec('UPDATE sat.presetnetworkshare SET sharename = :sharename, path = :path, target = :target, username = :username, password = :password'
- .' WHERE shareid = :shareid', compact('shareid', 'sharename', 'path', 'target', 'username', 'password'));
+ $target = Request::post('target', '', 'string');
+ $authType = Request::post('auth', '', 'string');
+ $username = Request::post('username', '', 'string');
+ $password = Request::post('password', '', 'string');
+ if (!in_array($authType, ['LOGIN_USER', 'OTHER_USER'], true)) {
+ Message::addError('networkshare-invalid-auth-type', $authType);
+ } elseif (empty($path)) {
+ Message::addError('networkshare-missing-path');
+ } else {
+ $data = json_encode([
+ 'auth' => $authType,
+ 'path' => $path,
+ 'displayname' => $sharename,
+ 'mountpoint' => $target,
+ 'username' => $username,
+ 'password' => $password,
+ ]);
+ if ($shareid !== 0) {
+ Database::exec('UPDATE sat.presetnetworkshare SET sharename = :sharename, sharedata = :data'
+ .' WHERE shareid = :shareid', compact('shareid', 'sharename', 'data'));
} else {
- Database::exec('INSERT INTO sat.presetnetworkshare (sharename, path, target, username, password, active)'
- .' VALUES (:sharename, :path, :target, :username, :password, 0)', compact('sharename', 'path', 'target', 'username', 'password'));
+ Database::exec('INSERT INTO sat.presetnetworkshare (sharename, sharedata, active)'
+ .' VALUES (:sharename, :data, 1)', compact('sharename', 'data'));
}
Message::addSuccess('networkshare-saved');
}
- } else if ($action === 'toggleActive') {
+ } else if ($action === 'activate' || $action === 'deactivate') {
User::assertPermission('networkshares.save');
$shareid = Request::post('shareid', false, 'int');
- Database::exec('UPDATE sat.presetnetworkshare SET active = !active WHERE shareid = :shareid', compact('shareid'));
+ $active = ($action === 'activate' ? 1 : 0);
+ Database::exec('UPDATE sat.presetnetworkshare SET active = :active WHERE shareid = :shareid', compact('active', 'shareid'));
+ }
+ if (Request::isPost()) {
+ Util::redirect('?do=dozmod&section=networkshares');
}
User::assertPermission('networkshares.view');
}
@@ -44,18 +63,44 @@ class SubPage
{
$show = Request::get('show', 'list', 'string');
if ($show === 'list') {
- $res = Database::simpleQuery('SELECT * FROM sat.presetnetworkshare;');
+ $res = Database::simpleQuery('SELECT shareid, sharename, sharedata, active
+ FROM sat.presetnetworkshare ORDER BY sharename ASC');
$rows = array();
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $row['specificUser'] = $row['username'] && $row['password'];
- $rows[] = $row;
+ $dec = json_decode($row['sharedata'], true);
+ if (!is_array($dec)) {
+ $dec = [];
+ }
+ if ($dec['auth'] === 'LOGIN_USER') {
+ $row['loginAsUser'] = true;
+ }
+ $rows[] = $row + $dec;
}
- Render::addTemplate('networkshares', ['networkshares' => $rows, 'hasEditPermissions' => User::hasPermission('networkshares.save')]);
+ Render::addTemplate('networkshares', [
+ 'networkshares' => $rows,
+ 'hasEditPermissions' => User::hasPermission('networkshares.save')
+ ]);
} else if ($show === 'edit') {
$shareid = Request::get('shareid', 0, 'int');
- $data = Database::queryFirst('SELECT * FROM sat.presetnetworkshare WHERE shareid = :shareid', ['shareid' => $shareid]);
- if ($data['username'] && $data['password']) $data['specificUser'] = 'selected';
- else $data['loggedInUser'] = 'selected';
+ if ($shareid === 0) {
+ $data = [];
+ } else {
+ $data = Database::queryFirst('SELECT shareid, sharename, sharedata
+ FROM sat.presetnetworkshare WHERE shareid = :shareid', ['shareid' => $shareid]);
+ if ($data === false) {
+ Message::addError('networkshare-invalid-shareid', $shareid);
+ Util::redirect('?do=dozmod&section=networkshares');
+ }
+ $dec = json_decode($data['sharedata'], true);
+ if (is_array($dec)) {
+ $data += $dec;
+ }
+ if ($data['auth'] === 'LOGIN_USER') {
+ $data['loggedInUser_selected'] = 'selected';
+ } else {
+ $data['specificUser_selected'] = 'selected';
+ }
+ }
Render::addTemplate('networkshares-edit', $data);
}
}
diff --git a/modules-available/dozmod/templates/ldapfilters.html b/modules-available/dozmod/templates/ldapfilters.html
index 49ecc222..06be33a5 100644
--- a/modules-available/dozmod/templates/ldapfilters.html
+++ b/modules-available/dozmod/templates/ldapfilters.html
@@ -1,4 +1,9 @@
<h1>{{lang_ldapfilters}}</h1>
+
+<p>
+ {{lang_ldapfiltersIntro}}
+</p>
+
<table class="table">
<thead>
<tr>
diff --git a/modules-available/dozmod/templates/networkshares-edit.html b/modules-available/dozmod/templates/networkshares-edit.html
index 32aa902f..cc89dbcc 100644
--- a/modules-available/dozmod/templates/networkshares-edit.html
+++ b/modules-available/dozmod/templates/networkshares-edit.html
@@ -21,7 +21,7 @@
<div class="input-group">
<label class="input-group-addon" for="target">{{lang_target}}</label>
<select class="form-control" name="target" id="target">
- <option value="" ></option>
+ <option value="-">{{lang_none}}</option>
<option value="D">D:</option><option value="E">E:</option><option value="F">F:</option>
<option value="G">G:</option><option value="H">H:</option><option value="I">I:</option>
<option value="J">J:</option><option value="K">K:</option><option value="L">L:</option>
@@ -30,22 +30,23 @@
<option value="S">S:</option><option value="T">T:</option><option value="U">U:</option>
<option value="V">V:</option><option value="W">W:</option><option value="X">X:</option>
<option value="Y">Y:</option><option value="Z">Z:</option>
+ <option value="PRINTER">{{lang_printer}}</option>
</select>
</div>
<div class="input-group">
<label class="input-group-addon" for="auth">{{lang_authMethod}}</label>
- <select class="form-control" id="auth">
- <option value="loggedInUser" {{loggedInUser}}>{{lang_loggedInUser}}</option>
- <option value="specificUser" {{specificUser}}>{{lang_specificUser}}</option>
+ <select class="form-control" name="auth" id="auth">
+ <option value="LOGIN_USER" {{loggedInUser_selected}}>{{lang_loggedInUser}}</option>
+ <option value="OTHER_USER" {{specificUser_selected}}>{{lang_specificUser}}</option>
</select>
</div>
<div class="input-group">
<label class="input-group-addon" for="username">{{lang_username}}</label>
- <input required type="text" name="username" id ="username" class="form-control" value="{{username}}" {{#loggedInUser}}disabled{{/loggedInUser}}>
+ <input required type="text" name="username" id ="username" class="form-control" value="{{username}}" {{#loggedInUser_selected}}disabled{{/loggedInUser_selected}}>
</div>
<div class="input-group">
<label class="input-group-addon" for="password">{{lang_password}}</label>
- <input required type="password" name="password" id ="password" class="form-control" value="{{password}}" {{#loggedInUser}}disabled{{/loggedInUser}}>
+ <input required type="password" name="password" id ="password" class="form-control" value="{{password}}" {{#loggedInUser_selected}}disabled{{/loggedInUser_selected}}>
</div>
<div class="text-right" style="margin-top: 20px">
<a href="?do=dozmod&amp;section=networkshares" class="btn btn-default">
@@ -64,21 +65,19 @@
document.addEventListener("DOMContentLoaded", function () {
- $('#target').val('{{target}}');
+ $('#target').val('{{mountpoint}}');
$('#auth').change(function () {
var username = $('#username');
var password = $('#password');
- if ($(this).val() === 'specificUser') {
+ if ($(this).val() === 'OTHER_USER') {
username.prop('disabled', false);
password.prop('disabled', false);
} else {
username.prop('disabled', true);
password.prop('disabled', true);
- username.val('');
- password.val('');
}
- });
+ }).change();
})
diff --git a/modules-available/dozmod/templates/networkshares.html b/modules-available/dozmod/templates/networkshares.html
index 48506b4e..aaafa256 100644
--- a/modules-available/dozmod/templates/networkshares.html
+++ b/modules-available/dozmod/templates/networkshares.html
@@ -1,5 +1,9 @@
<h1>{{lang_networkshares}}</h1>
+<p>
+ {{lang_networksharesIntro}}
+</p>
+
<table class="table">
<thead>
<tr>
@@ -20,18 +24,32 @@
<tr>
<td>{{sharename}}</td>
<td>{{path}}</td>
- <td>{{#target}}{{.}}:{{/target}}</td>
- <td>{{#specificUser}}{{lang_specificUser}}{{/specificUser}}{{^specificUser}}{{lang_loggedInUser}}{{/specificUser}}</td>
- <td>{{#specificUser}}{{username}}{{/specificUser}}</td>
+ <td>{{mountpoint}}</td>
+ <td>
+ {{#loginAsUser}}{{lang_loggedInUser}}{{/loginAsUser}}
+ {{^loginAsUser}}{{lang_specificUser}}{{/loginAsUser}}
+ </td>
+ <td>
+ {{^loginAsUser}}{{username}}{{/loginAsUser}}
+ </td>
{{#hasEditPermissions}}
- <td align="center">
+ <td class="text-nowrap">
<form method="post" action="?do=dozmod">
<input type="hidden" name="token" value="{{token}}">
<input type="hidden" name="section" value="networkshares">
<input type="hidden" name="shareid" value="{{shareid}}">
- <button type="submit" name="action" value="toggleActive" class="btn btn-xs {{^active}}btn-default{{/active}}{{#active}}btn-info{{/active}}">
- <span class="glyphicon {{^active}}glyphicon-flag{{/active}}{{#active}}glyphicon-ok{{/active}}"></span>
- </button>
+ {{#active}}
+ <span class="glyphicon glyphicon-ok text-success"></span>
+ <button type="submit" name="action" value="deactivate" class="btn btn-xs btn-default">
+ <span class="glyphicon glyphicon-remove"></span>
+ </button>
+ {{/active}}
+ {{^active}}
+ <span class="glyphicon glyphicon-remove text-danger"></span>
+ <button type="submit" name="action" value="activate" class="btn btn-xs btn-default">
+ <span class="glyphicon glyphicon-ok"></span>
+ </button>
+ {{/active}}
</form>
</td>
<td align="center">