Updates for new Hallinta and aliases master
authorJoey Schulze <joey@infodrom.org>
Thu, 21 Sep 2017 19:01:15 +0000 (21:01 +0200)
committerJoey Schulze <joey@infodrom.org>
Thu, 21 Sep 2017 19:01:15 +0000 (21:01 +0200)
alias.php [new file with mode: 0644]
domain.php
user.php
vmail.sql

diff --git a/alias.php b/alias.php
new file mode 100644 (file)
index 0000000..97cd7d8
--- /dev/null
+++ b/alias.php
@@ -0,0 +1,184 @@
+<?php
+
+
+$jscode = <<<EOC
+function user_pre_save()
+{
+  if ($('#edit_username').val() == '*') {
+    alert("Fehler aufgetreten!\\nCatch-All-Einträge sind nur bei Weiterleitungen zulässig.");
+    $('#edit_username').focus();
+    return false;
+  }
+
+  return true;
+}
+
+function user_post_insert(data)
+{
+    Hallinta.showMsg("Bitte als nächstes ein Passwort setzen die Mailbox direkt mit Mailprogram aktivieren.", {timeout: 10});
+}
+
+var passwd_popup = false;
+function passwd_setpw()
+{
+    passwd_popup.closePopup();
+
+    if (!$('#pw_pass1').val().length || !$('#pw_pass2').val().length || $('#pw_pass1').val() != $('#pw_pass2').val()) {
+       alert("Die Passwörter stimmen nicht überein!");
+       return false;
+    }
+
+    var parms = 'callback=setpw';
+    parms += '&id=' + $('#pw_id').val();
+    parms += '&passwd=' + $('#pw_pass1').val();
+
+    ajax_request('function', parms, function(data){
+       info('Passwort gespeichert');
+       Hallinta.showMsg('Neues Passwort gespeichert', {timeout: 3});
+    });
+
+    return false;
+}
+
+function passwd_set()
+{
+    if (!$('#edit_id').val().length) return false;
+
+    var width = 245;
+    var height = 163;
+    var centerDialog = false;
+
+    if (!passwd_popup) {
+       passwd_popup = new Rico.Window('<b>Neues Passwort setzen</b>', {zIndex: 100});
+       $(passwd_popup.contentDiv).html([
+           '<div class="form" style="margin-left: 10px; margin-right: 12px; padding-left: 10px; padding-bottom: 7px;">',
+           '<input type="hidden" name="pw_id" id="pw_id">',
+           '<label for="pw_email">E-Mail Adresse:</label><br>',
+           '<input type="text" name="pw_email" id="pw_email" size="23" readonly style="background:#eee;">',
+           '<div style="height: 5px;"></div>',
+           '<label for="pw_pass1">Neues Passwort:</label><br>',
+           '<input type="password" name="pw_pass1" id="pw_pass1" size="23">',
+           '<div style="height: 5px;"></div>',
+           '<label for="pw_pass2">erneut eingeben:</label><br>',
+           '<input type="password" name="pw_pass2" id="pw_pass2" size="23">',
+           '<div style="height: 5px;"></div>',
+           '<button onclick="return passwd_setpw()">Passwort setzen</button>',
+           '</div>',
+       ].join(''));
+       centerDialog = true;;
+    }
+
+    $('#pw_id').val($('#edit_id').val());
+    $('#pw_email').val($('#edit_username').val() + '@' + $('#edit_vmail_domain_id option[value="'+$('#edit_vmail_domain_id').val()+'"]').text());
+
+    $('#pw_pass1').val('');
+    $('#pw_pass2').val('');
+
+    if (centerDialog)
+        passwd_popup.centerPopup();
+    else
+        passwd_popup.openPopup();
+
+    $('#pw_pass1').focus();
+    return false;
+}
+
+EOC;
+JavaScript::instance()->add($jscode);
+JavaScript::instance()->add("Hallinta.preSave = user_pre_save;");
+JavaScript::instance()->add("Hallinta.preInsert = user_pre_save;");
+JavaScript::instance()->add("Hallinta.postInsert = user_post_insert;");
+JavaScript::instance()->add("Hallinta.fetchItemAfterInsert = true;");
+
+$mask = array(
+             'table' => 'vmail_alias',
+             'title' => 'Weiterleitungen und Listen',
+             'join' => array('vmail_domain ON vmail_domain_id = vmail_domain.id'),
+             'list' => array(
+                             'id' => array(
+                                           'name' => 'ID',
+                                           'visible' => false,
+                                           'sql' => 'vmail_alias.id',
+                                           ),
+                             'name' => array(
+                                           'name' => 'Domain',
+                                           'visible' => false,
+                                           'width' => 200,
+                                           'type' => 'text',
+                                           'filter' => 's',
+                                           ),
+                             'username' => array(
+                                           'name' => 'Username',
+                                           'visible' => false,
+                                           'width' => 200,
+                                           'type' => 'text',
+                                           'filter' => 't',
+                                           ),
+                             'email' => array(
+                                           'name' => 'Quell-Adresse',
+                                           'width' => 300,
+                                           'type' => 'text',
+                                           'filter' => 't',
+                                           'sql' => "username || '@' || name",
+                                           ),
+                             'dest' => array(
+                                           'name' => 'Ziel-Adressen',
+                                           'width' => 400,
+                                           'type' => 'text',
+                                           'filter' => 't',
+                                           'sql' => "substring(destination from 1 for 100)",
+                                           ),
+                             'active' => array(
+                                           'name' => 'aktiv',
+                                           'width' => 60,
+                                           'specs' => array('ClassName' => 'aligncenter'),
+                                           'control' => "new Rico.TableColumn.checkbox(1,0,0,1)",
+                                           ),
+                             ),
+             'edit' => array(
+                             'username' => array(
+                                           'name' => 'Usename',
+                                           'type' => 'text',
+                                           'size' => 21,
+                                           'required' => true,
+                                           ),
+                             'vmail_domain_id' => array(
+                                           'name' => 'Domain',
+                                           'type' => 'select',
+                                           'options' => 'SELECT id,name AS text FROM vmail_domain ORDER BY name',
+                                           'option_empty' => '-- select --',
+                                           'required' => true,
+                                           ),
+                             'destination' => array(
+                                           'name' => 'Ziel-Adressen',
+                                           'type' => 'textarea',
+                                           'rows' => 10,
+                                           'required' => true,
+                                           ),
+                             'active' => array(
+                                           'name' => 'Weiterleitung aktiv',
+                                           'type' => 'boolean',
+                                           ),
+                             ),
+             'callbacks' => array(
+                                 'setpw' => 'cb_setpw',
+                                 ),
+             );
+
+function passwd_encrypt($pw)
+{
+  return md5($pw);
+}
+
+function cb_setpw()
+{
+  global $db;
+
+  $sql = sprintf("UPDATE vmail_user SET password = '%s' WHERE id = %d",
+                passwd_encrypt($_POST['passwd']),
+                $_POST['id']);
+
+  $sth = $db->query($sql);
+
+  return true;
+}
index c7ba97d..1368ce6 100644 (file)
@@ -22,4 +22,3 @@ $mask = array(
                                            ),
                              ),
              );
-?>
index d3a4426..6439658 100644 (file)
--- a/user.php
+++ b/user.php
 
 $buttons = <<<EOC
 <p style="margin-top: 5px; margin-bottom: 4px; text-align: center;">
-<button class="custom" onclick="return passwd_delete()">Passwort löschen</button>
 <button class="custom" onclick="return passwd_set()">Passwort setzen</button>
 </p>
 EOC;
 
-$jscode[] = <<<EOC
-var post_save = user_post_save;
-var pre_insert = user_pre_save;
-var pre_save = user_pre_save;
-
+$jscode = <<<EOC
 function user_pre_save()
 {
-  if ($('edit_username').value == '*' && !$('edit_forward').value.length) {
-    alert("Fehler aufgetreten!\\n\\nFür Catch-All-Einträge muß zwingend\\neine Forward-Adresse angegeben werden.");
-    $('edit_forward').focus();
+  if ($('#edit_username').val() == '*') {
+    alert("Fehler aufgetreten!\\nCatch-All-Einträge sind nur bei Weiterleitungen zulässig.");
+    $('#edit_username').focus();
     return false;
   }
 
   return true;
 }
 
-function user_post_save()
-{
-  grid_update(grid);
-
-  if (!$('edit_id').value.length && !$('edit_forward').value.length)
-    alert("Bitte als nächstes ein Passwort setzen.\\nUnd danach direkt mit Mailprogram aktivieren.");
-}
-
-function passwd_delete_callback(data)
-{
-    grid_update(grid);
-    info('Preis gespeichert');
-}
-
-function passwd_delete()
+function user_post_insert(data)
 {
-    var eid = document.getElementById('edit_id');
-    if (!eid || !eid.value.length) return false;
-
-    var source = document.getElementById('source');
-    if (!source) return false;
-
-    var parms = 'source=' + source.innerHTML + '&callback=delete&';
-    parms += 'id=' + eid.value;
-
-    ajax_request('function', parms, passwd_delete_callback);
-
-    return false;
+    Hallinta.showMsg("Bitte als nächstes ein Passwort setzen die Mailbox direkt mit Mailprogram aktivieren.", {timeout: 10});
 }
 
 var passwd_popup = false;
-function passwd_setpw_callback(data)
-{
-    grid_update(grid);
-    info('Neues Passwort gespeichert');
-}
-
 function passwd_setpw()
 {
-  passwd_popup.closePopup();
+    passwd_popup.closePopup();
 
-  var pw1 = document.getElementById('pw_pass1');
-  var pw2 = document.getElementById('pw_pass2');
+    if (!$('#pw_pass1').val().length || !$('#pw_pass2').val().length || $('#pw_pass1').val() != $('#pw_pass2').val()) {
+       alert("Die Passwörter stimmen nicht überein!");
+       return false;
+    }
 
-  if (!pw1.value.length || !pw2.value.length || pw1.value != pw2.value) {
-    alert("Die Passwörter stimmen nicht überein!");
-    return false;
-  }
+    var parms = 'callback=setpw';
+    parms += '&id=' + $('#pw_id').val();
+    parms += '&passwd=' + $('#pw_pass1').val();
 
-  var source = document.getElementById('source');
-  var pw_id = document.getElementById('pw_id');
-  var pw_pass = document.getElementById('pw_pass1');
+    ajax_request('function', parms, function(data){
+       info('Passwort gespeichert');
+       Hallinta.showMsg('Neues Passwort gespeichert', {timeout: 3});
+    });
 
-  var parms = 'source=' + source.innerHTML + '&callback=setpw';
-  parms += '&id=' + pw_id.value;
-  parms += '&passwd=' + pw_pass.value;
-
-  ajax_request('function', parms, passwd_setpw_callback);
-
-  return false;
+    return false;
 }
 
 function passwd_set()
 {
-  var edit_id = document.getElementById('edit_id');
-
-  if (!edit_id.value.length) return false;
-
-  var width = 245;
-  var height = 163;
-
-  if (!passwd_popup) {
-    var options = {hideOnClick: false, canDragFunc: true };
-    passwd_popup = new Rico.Popup(options);
-    passwd_popup.createWindow('<b>Neues Passwort setzen</b>','',height+'px',width+'px');
-    passwd_popup.contentDiv.style.backgroundColor='#e0e0e0';
-    passwd_popup.contentDiv.innerHTML = [
-                                        '<div class="form" style="margin-left: 10px; margin-right: 12px; padding-left: 10px; padding-bottom: 7px;">',
-                                        '<input type="hidden" name="pw_id" id="pw_id">',
-                                        '<label for="pw_email">E-Mail Adresse:</label><br>',
-                                        '<input type="text" name="pw_email" id="pw_email" size="23" readonly>',
-                                        '<div style="height: 5px;"></div>',
-                                        '<label for="pw_pass1">Neues Passwort:</label><br>',
-                                        '<input type="password" name="pw_pass1" id="pw_pass1" size="23">',
-                                        '<div style="height: 5px;"></div>',
-                                        '<label for="pw_pass2">erneut eingeben:</label><br>',
-                                        '<input type="password" name="pw_pass2" id="pw_pass2" size="23">',
-                                        '<div style="height: 5px;"></div>',
-                                        '<button onclick="return passwd_setpw()">Passwort setzen</button>',
-                                        '</div>',
-                                        ].join('');
-  }
-
-  var edit_username = document.getElementById('edit_username');
-  var edit_vmail_domain_id = document.getElementById('edit_vmail_domain_id');
-
-  var pw_id = document.getElementById('pw_id');
-  var pw_email = document.getElementById('pw_email');
-
-  pw_id.value = edit_id.value;
-  pw_email.value = edit_username.value + '@' + edit_vmail_domain_id.options[edit_vmail_domain_id.selectedIndex].innerHTML;
-
-  var x = Math.floor((RicoUtil.windowWidth()-width)/2);
-  var y = Math.floor((RicoUtil.windowHeight()-height)/2);
-  passwd_popup.openPopup(x,y);
-
-  var pw_pass1 = document.getElementById('pw_pass1');
-  pw_pass1.value = '';
-  var pw_pass2 = document.getElementById('pw_pass2');
-  pw_pass2.value = '';
-  pw_pass1.focus();
-
-  return false;
+    if (!$('#edit_id').val().length) return false;
+
+    var width = 245;
+    var height = 163;
+    var centerDialog = false;
+
+    if (!passwd_popup) {
+       passwd_popup = new Rico.Window('<b>Neues Passwort setzen</b>', {zIndex: 100});
+       $(passwd_popup.contentDiv).html([
+           '<div class="form" style="margin-left: 10px; margin-right: 12px; padding-left: 10px; padding-bottom: 7px;">',
+           '<input type="hidden" name="pw_id" id="pw_id">',
+           '<label for="pw_email">E-Mail Adresse:</label><br>',
+           '<input type="text" name="pw_email" id="pw_email" size="23" readonly style="background:#eee;">',
+           '<div style="height: 5px;"></div>',
+           '<label for="pw_pass1">Neues Passwort:</label><br>',
+           '<input type="password" name="pw_pass1" id="pw_pass1" size="23">',
+           '<div style="height: 5px;"></div>',
+           '<label for="pw_pass2">erneut eingeben:</label><br>',
+           '<input type="password" name="pw_pass2" id="pw_pass2" size="23">',
+           '<div style="height: 5px;"></div>',
+           '<button onclick="return passwd_setpw()">Passwort setzen</button>',
+           '</div>',
+       ].join(''));
+       centerDialog = true;;
+    }
+
+    $('#pw_id').val($('#edit_id').val());
+    $('#pw_email').val($('#edit_username').val() + '@' + $('#edit_vmail_domain_id option[value="'+$('#edit_vmail_domain_id').val()+'"]').text());
+
+    $('#pw_pass1').val('');
+    $('#pw_pass2').val('');
+
+    if (centerDialog)
+        passwd_popup.centerPopup();
+    else
+        passwd_popup.openPopup();
+
+    $('#pw_pass1').focus();
+    return false;
 }
+
 EOC;
+JavaScript::instance()->add($jscode);
+JavaScript::instance()->add("Hallinta.preSave = user_pre_save;");
+JavaScript::instance()->add("Hallinta.preInsert = user_pre_save;");
+JavaScript::instance()->add("Hallinta.postInsert = user_post_insert;");
+JavaScript::instance()->add("Hallinta.fetchItemAfterInsert = true;");
 
 $mask = array(
              'table' => 'vmail_user',
-             'title' => 'Mailboxen und Weiterleitungen',
+             'title' => 'Mailboxen und Adressen',
              'join' => array('vmail_domain ON vmail_domain_id = vmail_domain.id'),
              'list' => array(
                              'id' => array(
@@ -150,30 +106,32 @@ $mask = array(
                                            'visible' => false,
                                            'sql' => 'vmail_user.id',
                                            ),
+                             'name' => array(
+                                           'name' => 'Domain',
+                                           'visible' => false,
+                                           'width' => 200,
+                                           'type' => 'text',
+                                           'filter' => 's',
+                                           ),
+                             'username' => array(
+                                           'name' => 'Username',
+                                           'visible' => false,
+                                           'width' => 200,
+                                           'type' => 'text',
+                                           'filter' => 't',
+                                           ),
                              'email' => array(
                                            'name' => 'E-Mail',
-                                           'width' => 330,
+                                           'width' => 400,
                                            'type' => 'text',
+                                           'filter' => 't',
                                            'sql' => "username || '@' || name",
-                                           'specs' => "filterUI: 't'",
-                                           ),
-                             'forward' => array(
-                                           'name' => 'Forward',
-                                           'width' => 330,
-                                           'specs' => "filterUI: 't'",
-                                           ),
-                             'pw' => array(
-                                           'name' => 'Pass',
-                                           'width' => 40,
-                                           'specs' => "ClassName: 'aligncenter'",
-                                           'control' => "new Rico.TableColumn.checkbox('t', 'f',0,1)",
-                                           'sql' => 'password IS NOT NULL AND length(password) > 0',
                                            ),
                              'active' => array(
-                                           'name' => 'on',
-                                           'width' => 40,
-                                           'specs' => "ClassName: 'aligncenter'",
-                                           'control' => "new Rico.TableColumn.checkbox(1, 0,0,1)",
+                                           'name' => 'aktiv',
+                                           'width' => 60,
+                                           'specs' => array('ClassName' => 'aligncenter'),
+                                           'control' => "new Rico.TableColumn.checkbox(1,0,0,1)",
                                            ),
                              ),
              'edit' => array(
@@ -190,23 +148,8 @@ $mask = array(
                                            'option_empty' => '-- select --',
                                            'required' => true,
                                            ),
-                             'forward' => array(
-                                           'name' => 'Forward',
-                                           'type' => 'text',
-                                           'size' => 21,
-                                           'null' => true,
-                                           ),
-/*
-                             'password' => array(
-                                           'name' => 'Passwort',
-                                           'type' => 'passwd',
-                                           'size' => 21,
-                                           'null' => true,
-                                           'func' => 'passwd_encrypt',
-                                           ),
-*/
                              'active' => array(
-                                           'name' => 'aktiviert',
+                                           'name' => 'Mailbox aktiv',
                                            'type' => 'boolean',
                                            ),
                              'buttons' => array(
@@ -216,7 +159,6 @@ $mask = array(
                                            ),
                              ),
              'callbacks' => array(
-                                 'delete' => 'cb_delete',
                                  'setpw' => 'cb_setpw',
                                  ),
              );
@@ -226,17 +168,6 @@ function passwd_encrypt($pw)
   return md5($pw);
 }
 
-function cb_delete()
-{
-  global $db;
-
-  $sql = sprintf("UPDATE vmail_user SET password = NULL WHERE id = %d", $_POST['id']);
-
-  $sth = $db->query($sql);
-
-  return true;
-}
-
 function cb_setpw()
 {
   global $db;
@@ -249,5 +180,3 @@ function cb_setpw()
 
   return true;
 }
-
-?>
index e2442d0..664c98f 100644 (file)
--- a/vmail.sql
+++ b/vmail.sql
@@ -2,7 +2,8 @@ CREATE TABLE vmail_domain (
     id SERIAL,
     name character varying(100) NOT NULL,
     sys_user character varying(10) NOT NULL,
-    sys_edit timestamp without time zone NOT NULL
+    sys_edit timestamp without time zone NOT NULL,
+    UNIQUE(name)
 );
 
 CREATE UNIQUE INDEX vmail_domain_id ON vmail_domain USING btree (id);
@@ -12,15 +13,32 @@ CREATE TABLE vmail_user (
     vmail_domain_id integer NOT NULL,
     username character varying(50) NOT NULL,
     password character varying(50),
-    forward character varying(150),
     active integer DEFAULT 0 NOT NULL,
     sys_user character varying(10) NOT NULL,
-    sys_edit timestamp without time zone NOT NULL
+    sys_edit timestamp without time zone NOT NULL,
+    UNIQUE(vmail_domain_id,username)
 );
 
 CREATE UNIQUE INDEX vmail_user_id ON vmail_user USING btree (id);
 CREATE INDEX vmail_user_vmail_domain_id ON vmail_user USING btree (vmail_domain_id);
 
+-- ALTER TABLE ONLY vmail_user
+--     ADD CONSTRAINT vmail_user_vmail_domain_id_username_key UNIQUE (vmail_domain_id, username);
+
+CREATE TABLE vmail_alias (
+    id SERIAL,
+    vmail_domain_id integer NOT NULL,
+    username character varying(50) NOT NULL,
+    destination TEXT DEFAULT NULL,
+    active integer DEFAULT 0 NOT NULL,
+    sys_user character varying(10) NOT NULL,
+    sys_edit timestamp without time zone NOT NULL,
+    UNIQUE(vmail_domain_id,username)
+);
+
+CREATE UNIQUE INDEX vmail_alias_id ON vmail_alias USING btree (id);
+CREATE INDEX vmail_alias_vmail_domain_id ON vmail_alias USING btree (vmail_domain_id);
+
 REVOKE ALL ON TABLE vmail_user FROM PUBLIC;
 GRANT SELECT ON TABLE vmail_user TO "vmail";
 GRANT ALL ON TABLE vmail_user TO "hallinta";
@@ -28,6 +46,13 @@ GRANT ALL ON TABLE vmail_user TO "hallinta";
 REVOKE ALL ON SEQUENCE vmail_user_id_seq FROM PUBLIC;
 GRANT ALL ON SEQUENCE vmail_user_id_seq TO "hallinta";
 
+REVOKE ALL ON TABLE vmail_alias FROM PUBLIC;
+GRANT SELECT ON TABLE vmail_alias TO "vmail";
+GRANT ALL ON TABLE vmail_alias TO "hallinta";
+
+REVOKE ALL ON SEQUENCE vmail_alias_id_seq FROM PUBLIC;
+GRANT ALL ON SEQUENCE vmail_alias_id_seq TO "hallinta";
+
 REVOKE ALL ON TABLE vmail_domain FROM PUBLIC;
 GRANT SELECT ON TABLE vmail_domain TO "vmail";
 GRANT ALL ON TABLE vmail_domain TO "hallinta";