From d22ace159de3f21cdd3ba41d477ad53ca32747b1 Mon Sep 17 00:00:00 2001 From: Joey Schulze Date: Thu, 21 Sep 2017 21:01:15 +0200 Subject: [PATCH 1/1] Updates for new Hallinta and aliases --- alias.php | 184 ++++++++++++++++++++++++++++++++++++++++ domain.php | 1 - user.php | 243 +++++++++++++++++++---------------------------------- vmail.sql | 31 ++++++- 4 files changed, 298 insertions(+), 161 deletions(-) create mode 100644 alias.php diff --git a/alias.php b/alias.php new file mode 100644 index 0000000..97cd7d8 --- /dev/null +++ b/alias.php @@ -0,0 +1,184 @@ +Neues Passwort setzen', {zIndex: 100}); + $(passwd_popup.contentDiv).html([ + '
', + '', + '
', + '', + '
', + '
', + '', + '
', + '
', + '', + '
', + '', + '
', + ].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; +} diff --git a/domain.php b/domain.php index c7ba97d..1368ce6 100644 --- a/domain.php +++ b/domain.php @@ -22,4 +22,3 @@ $mask = array( ), ), ); -?> diff --git a/user.php b/user.php index d3a4426..6439658 100644 --- a/user.php +++ b/user.php @@ -3,146 +3,102 @@ $buttons = << -

EOC; -$jscode[] = <<Neues Passwort setzen','',height+'px',width+'px'); - passwd_popup.contentDiv.style.backgroundColor='#e0e0e0'; - passwd_popup.contentDiv.innerHTML = [ - '
', - '', - '
', - '', - '
', - '
', - '', - '
', - '
', - '', - '
', - '', - '
', - ].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('Neues Passwort setzen', {zIndex: 100}); + $(passwd_popup.contentDiv).html([ + '
', + '', + '
', + '', + '
', + '
', + '', + '
', + '
', + '', + '
', + '', + '
', + ].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; } - -?> diff --git a/vmail.sql b/vmail.sql index e2442d0..664c98f 100644 --- 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"; -- 2.20.1