summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2015-09-04 19:04:11 +0200
committerSimon Rettberg2015-09-04 19:04:11 +0200
commit879ac33ee4731833dbbe609b8432b1fa1e5bd961 (patch)
tree478ab5a9fed7977742f891e8103a395a0f61b2e3
parentMany changes (diff)
downloadslx-admin-879ac33ee4731833dbbe609b8432b1fa1e5bd961.tar.gz
slx-admin-879ac33ee4731833dbbe609b8432b1fa1e5bd961.tar.xz
slx-admin-879ac33ee4731833dbbe609b8432b1fa1e5bd961.zip
Add dozmod config page
-rw-r--r--modules/dozmod.inc.php117
-rw-r--r--templates/dozmod/mailconfig.html86
-rw-r--r--templates/dozmod/userlist.html34
3 files changed, 237 insertions, 0 deletions
diff --git a/modules/dozmod.inc.php b/modules/dozmod.inc.php
new file mode 100644
index 00000000..a4fbf57c
--- /dev/null
+++ b/modules/dozmod.inc.php
@@ -0,0 +1,117 @@
+<?php
+
+class Page_DozMod extends Page
+{
+
+ protected function doPreprocess()
+ {
+ User::load();
+
+ if (!User::hasPermission('superadmin')) {
+ Message::addError('no-permission');
+ Util::redirect('?do=Main');
+ }
+
+ $action = Request::post('action');
+
+ if ($action === 'mail') {
+ $this->mailHandler();
+ } else if ($action === 'setuser') {
+ $this->makeAdmin();
+ }
+ }
+
+ protected function doRender()
+ {
+ // Mail config
+ $conf = Database::queryFirst('SELECT value FROM sat.configuration WHERE parameter = :param', array('param' => 'mailconfig'));
+ if ($conf != null) {
+ $conf = @json_decode($conf['value'], true);
+ if (is_array($conf)) {
+ $conf['set_' . $conf['ssl']] = 'selected="selected"';
+ }
+ }
+ Render::addTemplate('dozmod/mailconfig', $conf);
+ // User list for making people admin
+ $this->listUsers();
+ }
+
+ private function cleanMailArray()
+ {
+ $keys = array('host', 'port', 'ssl', 'senderAddress', 'replyTo', 'username', 'password', 'serverName');
+ $data = array();
+ foreach ($keys as $key) {
+ $data[$key] = Request::post($key, '');
+ settype($data[$key], 'string');
+ if (is_numeric($data[$key])) {
+ settype($data[$key], 'int');
+ }
+ }
+ return $data;
+ }
+
+ protected function doAjax()
+ {
+ $do = Request::post('button');
+ if ($do === 'test') {
+ // Prepare array
+ $data = $this->cleanMailArray();
+ Header('Content-Type: text/plain; charset=utf-8');
+ $data['recipient'] = Request::post('recipient', '');
+ if (!preg_match('/.+@.+\..+/', $data['recipient'])) {
+ $result = 'No recipient given!';
+ } else {
+ $result = Download::asStringPost('http://127.0.0.1:9080/do/mailtest', $data, 2, $code);
+ }
+ die($result);
+ }
+ }
+
+ private function mailHandler()
+ {
+ // Check action
+ $do = Request::post('button');
+ if ($do === 'save') {
+ // Prepare array
+ $data = $this->cleanMailArray();
+ $data = json_encode($data);
+ Database::exec('INSERT INTO sat.configuration (parameter, value)'
+ . ' VALUES (:param, :value)'
+ . ' ON DUPLICATE KEY UPDATE value = VALUES(value)', array(
+ 'param' => 'mailconfig',
+ 'value' => $data
+ ));
+ Message::addSuccess('mail-config-saved');
+ Util::redirect('?do=DozMod');
+ }
+ }
+
+ private function listUsers()
+ {
+ $res = Database::simpleQuery('SELECT userid, firstname, lastname, email, lastlogin, user.canlogin, issuperuser, emailnotifications,'
+ . ' organization.displayname AS orgname FROM sat.user'
+ . ' LEFT JOIN sat.organization USING (organizationid)'
+ . ' ORDER BY lastname ASC, firstname ASC');
+ $rows = array();
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $row['isbanned'] = $this->checked($row['canlogin'] == 0);
+ $row['issuperuser'] = $this->checked($row['issuperuser']);
+ $row['emailnotifications'] = $this->checked($row['emailnotifications']);
+ $row['lastlogin'] = date('d.m.Y', $row['lastlogin']);
+ $rows[] = $row;
+ }
+ Render::addTemplate('dozmod/userlist', array('users' => $rows));
+ }
+
+ private function checked($val) {
+ if ($val)
+ return 'checked="checked"';
+ return '';
+ }
+
+ private function makeAdmin()
+ {
+
+ }
+
+}
diff --git a/templates/dozmod/mailconfig.html b/templates/dozmod/mailconfig.html
new file mode 100644
index 00000000..58d45a0f
--- /dev/null
+++ b/templates/dozmod/mailconfig.html
@@ -0,0 +1,86 @@
+<h2>{{lang_mailConfigHeadline}}</h2>
+
+<div class="panel panel-default">
+ <div class="panel-heading">
+ {{lang_mailConfig}}
+ </div>
+ <div class="panel-body">
+ <form action="?do=DozMod" method="post" id="mailconf">
+ <div class="input-group">
+ <label class="input-group-addon slx-ga2" for="host-id">{{lang_host}} *</label>
+ <input type="text" name="host" id ="host-id" class="form-control" placeholder="smtp.example.com" value="{{host}}">
+ </div>
+ <div class="input-group">
+ <label class="input-group-addon slx-ga2" for="port-id">{{lang_port}} *</label>
+ <input type="text" name="port" id ="port-id" class="form-control" placeholder="465" value="{{port}}">
+ </div>
+ <div class="input-group">
+ <label class="input-group-addon slx-ga2" for="ssl-id">{{lang_ssl}} *</label>
+ <select class="form-control" name="ssl" id="ssl-id">
+ <option value="NONE" {{set_NONE}}>{{lang_sslNone}}</option>
+ <option value="IMPLICIT" {{set_IMPLICIT}}>{{lang_sslImplicit}}</option>
+ <option value="EXPLICIT" {{set_EXPLICIT}}>{{lang_sslExplicit}}</option>
+ </select>
+ </div>
+ <div class="input-group">
+ <label class="input-group-addon slx-ga2" for="senderAddress-id">{{lang_senderAddress}} *</label>
+ <input type="text" name="senderAddress" id ="senderAddress-id" class="form-control" placeholder="smtp-username@hs-example.com" value="{{senderAddress}}">
+ </div>
+ <div class="input-group">
+ <label class="input-group-addon slx-ga2" for="serverName-id">{{lang_senderName}}</label>
+ <input type="text" name="serverName" id ="serverName-id" class="form-control" placeholder="bwLehrpool HS Example" value="{{serverName}}">
+ </div>
+ <div class="input-group">
+ <label class="input-group-addon slx-ga2" for="replyTo-id">{{lang_replyTo}}</label>
+ <input type="text" name="replyTo" id ="replyTo-id" class="form-control" placeholder="helpdesk@hs-example.com" value="{{replyTo}}">
+ </div>
+ <div class="input-group">
+ <label class="input-group-addon slx-ga2" for="username-id">{{lang_username}}</label>
+ <input type="text" name="username" id ="username-id" class="form-control" placeholder="smtp-username" value="{{username}}">
+ </div>
+ <div class="input-group">
+ <label class="input-group-addon slx-ga2" for="password-id">{{lang_password}}</label>
+ <input type="{{password_type}}" name="password" id ="password-id" class="form-control" placeholder="geheim" value="{{password}}">
+ </div>
+ <p>{{lang_asteriskRequired}}</p>
+ <br>
+ <p>{{lang_testConfiguration}}</p>
+ <div class="input-group">
+ <label class="input-group-addon slx-ga2" for="test-id">{{lang_testRecipient}}</label>
+ <input type="text" name="recipient" id ="test-id" class="form-control" placeholder="test@example.com" value="">
+ </div>
+ <br>
+ <button class="btn btn-primary btn-sm" type="button" id="test-button" name="button" value="test" onclick="slxTestConfig()">{{lang_test}}</button>
+ <span id="test-spin" style="display:none"><span class="glyphicon glyphicon-refresh slx-rotation"></span></span>
+ <pre id="test-output" style="display:none"></pre>
+ <button class="btn btn-primary btn-sm" type="submit" name="button" value="save">{{lang_save}}</button>
+ <br>
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="action" value="mail">
+ </form>
+ </div>
+</div>
+
+<script type="text/javascript"><!--
+function slxTestConfig() {
+ $('#test-button').prop('disabled', true);
+ $('#test-spin').css('display', '');
+ var str = $('#mailconf').serialize();
+ str += '&button=test';
+ console.log(str);
+ $.post('?do=DozMod', str).done(function(data) {
+ console.log('Success');
+ console.log(data);
+ checkRes(data);
+ }).fail(function() {
+ checkRes('DozMod refused the connection');
+ }).always(function() {
+ $('#test-button').prop('disabled', false);
+ $('#test-spin').css('display', 'none');
+ });
+ }
+
+ function checkRes(text) {
+ $('#test-output').css('display', '').text(text);
+ }
+// --> </script> \ No newline at end of file
diff --git a/templates/dozmod/userlist.html b/templates/dozmod/userlist.html
new file mode 100644
index 00000000..addb7edf
--- /dev/null
+++ b/templates/dozmod/userlist.html
@@ -0,0 +1,34 @@
+<h2>{{lang_userList}}</h2>
+
+<div class="table-responsive">
+ <form method="post" action="?do=DozMod">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="action" value="setuser">
+ <table class="table table-stripped table-condensed">
+ <thead>
+ <tr>
+ <th>{{lang_user}}</th>
+ <th>{{lang_organization}}</th>
+ <th>{{lang_lastLogin}}</th>
+ <th>{{lang_email}}</th>
+ <th><span class="glyphicon glyphicon-envelope" title="{{lang_emailNotifications}}"></span></th>
+ <th><span class="glyphicon glyphicon-king" title="{{lang_superUser}}"></span></th>
+ <th><span class="glyphicon glyphicon-ban-circle" title="{{lang_isBanned}}"></span></th>
+ </tr>
+ </thead>
+ <tbody>
+ {{#users}}
+ <tr>
+ <td class="text-left slx-nowrap">{{lastname}}, {{firstname}}</td>
+ <td class="text-left slx-nowrap">{{orgname}}</td>
+ <td class="text-left slx-nowrap">{{lastlogin}}</td>
+ <td class="text-left slx-nowrap"><a href="mailto:{{email}}">{{email}}</a></td>
+ <td><input type="checkbox" {{emailnotifications}}></td>
+ <td><input type="checkbox" {{issuperuser}}></td>
+ <td><input type="checkbox" {{isbanned}}></td>
+ </tr>
+ {{/users}}
+ </tbody>
+ </table>
+ </form>
+</div> \ No newline at end of file