From 3d229b05ddfb1b75b10a7e8f66d3b1b847d4afd2 Mon Sep 17 00:00:00 2001 From: tbrehm Date: Sun, 25 Oct 2009 12:44:48 +0000 Subject: [PATCH] Added: FS#613 - Add email domain aliases --- install/sql/ispconfig3.sql | 4 +- interface/web/client/form/client.tform.php | 14 ++ .../web/client/form/client_template.tform.php | 14 ++ interface/web/client/lib/lang/en_client.lng | 2 + .../client/lib/lang/en_client_template.lng | 110 +++++++------- .../client/templates/client_edit_limits.htm | 4 + .../templates/client_template_edit_limits.htm | 4 + .../web/mail/form/mail_aliasdomain.tform.php | 113 ++++++++++++++ .../web/mail/lib/lang/en_mail_aliasdomain.lng | 11 ++ .../lib/lang/en_mail_aliasdomain_list.lng | 8 + interface/web/mail/lib/module.conf.php | 4 + .../web/mail/list/mail_aliasdomain.list.php | 79 ++++++++++ interface/web/mail/mail_aliasdomain_del.php | 51 +++++++ interface/web/mail/mail_aliasdomain_edit.php | 141 ++++++++++++++++++ interface/web/mail/mail_aliasdomain_list.php | 26 ++++ .../mail/templates/mail_aliasdomain_edit.htm | 37 +++++ .../mail/templates/mail_aliasdomain_list.htm | 57 +++++++ 17 files changed, 624 insertions(+), 55 deletions(-) create mode 100644 interface/web/mail/form/mail_aliasdomain.tform.php create mode 100644 interface/web/mail/lib/lang/en_mail_aliasdomain.lng create mode 100644 interface/web/mail/lib/lang/en_mail_aliasdomain_list.lng create mode 100644 interface/web/mail/list/mail_aliasdomain.list.php create mode 100644 interface/web/mail/mail_aliasdomain_del.php create mode 100644 interface/web/mail/mail_aliasdomain_edit.php create mode 100644 interface/web/mail/mail_aliasdomain_list.php create mode 100644 interface/web/mail/templates/mail_aliasdomain_edit.htm create mode 100644 interface/web/mail/templates/mail_aliasdomain_list.htm diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql index ef4ee7167..84ee26375 100644 --- a/install/sql/ispconfig3.sql +++ b/install/sql/ispconfig3.sql @@ -69,6 +69,7 @@ CREATE TABLE `client` ( `limit_maildomain` int(11) NOT NULL default '-1', `limit_mailbox` int(11) NOT NULL default '-1', `limit_mailalias` int(11) NOT NULL default '-1', + `limit_mailaliasdomain` int(11) NOT NULL default '-1', `limit_mailforward` int(11) NOT NULL default '-1', `limit_mailcatchall` int(11) NOT NULL default '-1', `limit_mailrouting` int(11) NOT NULL default '0', @@ -125,6 +126,7 @@ CREATE TABLE `client_template` ( `limit_maildomain` int(11) NOT NULL default '-1', `limit_mailbox` int(11) NOT NULL default '-1', `limit_mailalias` int(11) NOT NULL default '-1', + `limit_mailaliasdomain` int(11) NOT NULL default '-1', `limit_mailforward` int(11) NOT NULL default '-1', `limit_mailcatchall` int(11) NOT NULL default '-1', `limit_mailrouting` int(11) NOT NULL default '0', @@ -389,7 +391,7 @@ CREATE TABLE `mail_forwarding` ( `server_id` int(11) unsigned NOT NULL default '0', `source` varchar(255) NOT NULL, `destination` text NOT NULL default '', - `type` enum('alias','forward','catchall') NOT NULL default 'alias', + `type` enum('alias','aliasdomain','forward','catchall') NOT NULL default 'alias', `active` enum('n','y') NOT NULL, PRIMARY KEY (`forwarding_id`), KEY `server_id` (`server_id`,`source`) diff --git a/interface/web/client/form/client.tform.php b/interface/web/client/form/client.tform.php index 4d369cef9..9a7b6e088 100644 --- a/interface/web/client/form/client.tform.php +++ b/interface/web/client/form/client.tform.php @@ -364,6 +364,20 @@ $form["tabs"]['limits'] = array ( 'rows' => '', 'cols' => '' ), + 'limit_mailaliasdomain' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'ISINT', + 'errmsg'=> 'limit_mailaliasdomain_error_notint'), + ), + 'default' => '-1', + 'value' => '', + 'separator' => '', + 'width' => '10', + 'maxlength' => '10', + 'rows' => '', + 'cols' => '' + ), 'limit_mailforward' => array ( 'datatype' => 'INTEGER', 'formtype' => 'TEXT', diff --git a/interface/web/client/form/client_template.tform.php b/interface/web/client/form/client_template.tform.php index 5f34c58ff..e26f037e3 100644 --- a/interface/web/client/form/client_template.tform.php +++ b/interface/web/client/form/client_template.tform.php @@ -143,6 +143,20 @@ $form["tabs"]['limits'] = array ( 'rows' => '', 'cols' => '' ), + 'limit_mailaliasdomain' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'ISINT', + 'errmsg'=> 'limit_mailaliasdomain_error_notint'), + ), + 'default' => '-1', + 'value' => '', + 'separator' => '', + 'width' => '10', + 'maxlength' => '10', + 'rows' => '', + 'cols' => '' + ), 'limit_mailforward' => array ( 'datatype' => 'INTEGER', 'formtype' => 'TEXT', diff --git a/interface/web/client/lib/lang/en_client.lng b/interface/web/client/lib/lang/en_client.lng index 03cec3fee..4be403341 100644 --- a/interface/web/client/lib/lang/en_client.lng +++ b/interface/web/client/lib/lang/en_client.lng @@ -2,6 +2,7 @@ $wb["limit_maildomain_txt"] = 'Max. number of email domains'; $wb["limit_mailbox_txt"] = 'Max. number of mailboxes'; $wb["limit_mailalias_txt"] = 'Max. number of email aliases'; +$wb["limit_mailaliasdomain_txt"] = 'Max. number of domain aliases'; $wb["limit_mailforward_txt"] = 'Max. number of email forwarders'; $wb["limit_mailcatchall_txt"] = 'Max. number of email catchall accounts'; $wb["limit_mailrouting_txt"] = 'Max. number of email routes'; @@ -61,6 +62,7 @@ $wb["username_error_unique"] = 'The username must be unique.'; $wb["limit_maildomain_error_notint"] = 'The email domain limit must be a number.'; $wb["limit_mailbox_error_notint"] = 'The mailbox limit must be a number.'; $wb["limit_mailalias_error_notint"] = 'The email alias limit must be a number.'; +$wb["limit_mailaliasdomain_error_notint"] = 'The email domain alias limit must be a number.'; $wb["limit_mailforward_error_notint"] = 'The email forward limit must be a number.'; $wb["limit_mailcatchall_error_notint"] = 'The email catchall limit must be a number.'; $wb["limit_mailrouting_error_notint"] = 'The email routing limit must be a number.'; diff --git a/interface/web/client/lib/lang/en_client_template.lng b/interface/web/client/lib/lang/en_client_template.lng index 6d9ee1115..d403dfda5 100644 --- a/interface/web/client/lib/lang/en_client_template.lng +++ b/interface/web/client/lib/lang/en_client_template.lng @@ -1,55 +1,57 @@ - \ No newline at end of file diff --git a/interface/web/client/templates/client_edit_limits.htm b/interface/web/client/templates/client_edit_limits.htm index 839627e8f..2927ca4d0 100644 --- a/interface/web/client/templates/client_edit_limits.htm +++ b/interface/web/client/templates/client_edit_limits.htm @@ -53,6 +53,10 @@ +
+ + +
diff --git a/interface/web/client/templates/client_template_edit_limits.htm b/interface/web/client/templates/client_template_edit_limits.htm index 1ee1a1e48..81f259542 100644 --- a/interface/web/client/templates/client_template_edit_limits.htm +++ b/interface/web/client/templates/client_template_edit_limits.htm @@ -18,6 +18,10 @@
+ + +
+
diff --git a/interface/web/mail/form/mail_aliasdomain.tform.php b/interface/web/mail/form/mail_aliasdomain.tform.php new file mode 100644 index 000000000..ae06013d9 --- /dev/null +++ b/interface/web/mail/form/mail_aliasdomain.tform.php @@ -0,0 +1,113 @@ + 0 id must match with id of current user +$form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user +$form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete +$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete +$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete + +$form["tabs"]['alias'] = array ( + 'title' => "Domain Alias", + 'width' => 100, + 'template' => "templates/mail_aliasdomain_edit.htm", + 'fields' => array ( + ################################## + # Begin Datatable fields + ################################## + 'server_id' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'source' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'source_error_empty'), + 1 => array ( 'type' => 'UNIQUE', + 'errmsg'=> 'source_error_unique'), + 2 => array ( 'type' => 'REGEX', + 'regex' => '/^\@[\w\.\-]{2,64}\.[a-zA-Z]{2,10}$/', + 'errmsg'=> 'source_error_regex'), + ), + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'destination' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'type' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => '', + 'value' => array('alias' => 'Alias','forward'=>'Forward') + ), + 'active' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'y', + 'value' => array(0 => 'n',1 => 'y') + ), + ################################## + # ENDE Datatable fields + ################################## + ) +); + + + +?> \ No newline at end of file diff --git a/interface/web/mail/lib/lang/en_mail_aliasdomain.lng b/interface/web/mail/lib/lang/en_mail_aliasdomain.lng new file mode 100644 index 000000000..241eb64ce --- /dev/null +++ b/interface/web/mail/lib/lang/en_mail_aliasdomain.lng @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/interface/web/mail/lib/lang/en_mail_aliasdomain_list.lng b/interface/web/mail/lib/lang/en_mail_aliasdomain_list.lng new file mode 100644 index 000000000..8ebfa7dec --- /dev/null +++ b/interface/web/mail/lib/lang/en_mail_aliasdomain_list.lng @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/interface/web/mail/lib/module.conf.php b/interface/web/mail/lib/module.conf.php index 54d0e05f1..82e7a39b9 100644 --- a/interface/web/mail/lib/module.conf.php +++ b/interface/web/mail/lib/module.conf.php @@ -14,6 +14,10 @@ $items[] = array( 'title' => 'Domain', 'target' => 'content', 'link' => 'mail/mail_domain_list.php'); +$items[] = array( 'title' => 'Domain Alias', + 'target' => 'content', + 'link' => 'mail/mail_aliasdomain_list.php'); + $items[] = array( 'title' => 'Email Mailbox', 'target' => 'content', 'link' => 'mail/mail_user_list.php'); diff --git a/interface/web/mail/list/mail_aliasdomain.list.php b/interface/web/mail/list/mail_aliasdomain.list.php new file mode 100644 index 000000000..690b6f3da --- /dev/null +++ b/interface/web/mail/list/mail_aliasdomain.list.php @@ -0,0 +1,79 @@ + "active", + 'datatype' => "VARCHAR", + 'formtype' => "SELECT", + 'op' => "=", + 'prefix' => "", + 'suffix' => "", + 'width' => "", + 'value' => array('y' => "
Yes
", 'n' => "
No
")); + + +$liste["item"][] = array( 'field' => "source", + 'datatype' => "VARCHAR", + 'formtype' => "TEXT", + 'op' => "like", + 'prefix' => "%", + 'suffix' => "%", + 'width' => "", + 'value' => ""); + +$liste["item"][] = array( 'field' => "destination", + 'datatype' => "VARCHAR", + 'formtype' => "TEXT", + 'op' => "like", + 'prefix' => "%", + 'suffix' => "%", + 'width' => "", + 'value' => ""); + + +?> \ No newline at end of file diff --git a/interface/web/mail/mail_aliasdomain_del.php b/interface/web/mail/mail_aliasdomain_del.php new file mode 100644 index 000000000..fba0aea36 --- /dev/null +++ b/interface/web/mail/mail_aliasdomain_del.php @@ -0,0 +1,51 @@ +auth->check_module_permissions('mail'); + +$app->uses("tform_actions"); +$app->tform_actions->onDelete(); + +?> \ No newline at end of file diff --git a/interface/web/mail/mail_aliasdomain_edit.php b/interface/web/mail/mail_aliasdomain_edit.php new file mode 100644 index 000000000..e993c4db8 --- /dev/null +++ b/interface/web/mail/mail_aliasdomain_edit.php @@ -0,0 +1,141 @@ +auth->check_module_permissions('mail'); + +// Loading classes +$app->uses('tpl,tform,tform_actions'); +$app->load('tform_actions'); + +class page_action extends tform_actions { + + function onShowNew() { + global $app, $conf; + + // we will check only users, not admins + if($_SESSION["s"]["user"]["typ"] == 'user') { + if(!$app->tform->checkClientLimit('limit_mailaliasdomain',"type = 'aliasdomain'")) { + $app->error($app->tform->wordbook["limit_mailaliasdomain_txt"]); + } + if(!$app->tform->checkResellerLimit('limit_mailaliasdomain',"type = 'aliasdomain'")) { + $app->error('Reseller: '.$app->tform->wordbook["limit_mailaliasdomain_txt"]); + } + } + + parent::onShowNew(); + } + + function onShowEnd() { + global $app, $conf; + + $source_domain = substr($this->dataRecord["source"],1); + $destination_domain = substr($this->dataRecord["destination"],1); + + // Getting Domains of the user + $sql = "SELECT domain FROM mail_domain WHERE ".$app->tform->getAuthSQL('r').' ORDER BY domain'; + $domains = $app->db->queryAllRecords($sql); + + $source_select = ''; + $destination_select = ''; + if(is_array($domains)) { + foreach( $domains as $domain) { + $selected = ($domain["domain"] == @$source_domain)?'SELECTED':''; + $source_select .= "\r\n"; + $selected = ($domain["domain"] == @$destination_domain)?'SELECTED':''; + $destination_select .= "\r\n"; + } + } + $app->tpl->setVar("source_domain",$source_select); + $app->tpl->setVar("destination_domain",$destination_select); + + parent::onShowEnd(); + } + + function onSubmit() { + global $app, $conf; + + // Check if source Domain belongs to user + $domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($_POST["source"])."' AND ".$app->tform->getAuthSQL('r')); + if($domain["domain"] != $_POST["source"]) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"]; + + // Check if the destination domain belongs to the user + $domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($_POST["destination"])."' AND ".$app->tform->getAuthSQL('r')); + if($domain["domain"] != $_POST["destination"]) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"]; + + // Check the client limits, if user is not the admin + if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin + if(!$app->tform->checkClientLimit('limit_mailaliasdomain',"type = 'aliasdomain'")) { + $app->error($app->tform->wordbook["limit_mailaliasdomain_txt"]); + } + if(!$app->tform->checkResellerLimit('limit_mailaliasdomain',"type = 'aliasdomain'")) { + $app->error('Reseller: '.$app->tform->wordbook["limit_mailaliasdomain_txt"]); + } + } // end if user is not admin + + if($this->dataRecord["source"] == $this->dataRecord["destination"]) $app->tform->errorMessage .= $app->tform->wordbook["source_destination_identical_txt"]; + + // compose the source and destination field + $this->dataRecord["source"] = "@".$app->db->quote($this->dataRecord["source"]); + $this->dataRecord["destination"] = "@".$app->db->quote($this->dataRecord["destination"]); + // Set the server id of the mailbox = server ID of mail domain. + $this->dataRecord["server_id"] = $domain["server_id"]; + + parent::onSubmit(); + } + + function onAfterInsert() { + global $app; + + $domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain = '".$app->db->quote($_POST["destination"])."' AND ".$app->tform->getAuthSQL('r')); + $app->db->query("update mail_forwarding SET sys_groupid = ".$domain['sys_groupid']." WHERE forwarding_id = ".$this->id); + + } + + +} + +$page = new page_action; +$page->onLoad(); + +?> \ No newline at end of file diff --git a/interface/web/mail/mail_aliasdomain_list.php b/interface/web/mail/mail_aliasdomain_list.php new file mode 100644 index 000000000..8998afad0 --- /dev/null +++ b/interface/web/mail/mail_aliasdomain_list.php @@ -0,0 +1,26 @@ +auth->check_module_permissions('mail'); + +$app->uses('listform_actions'); + +// Limit the results to alias domains +$app->listform_actions->SQLExtWhere = "type = 'aliasdomain'"; + +$app->listform_actions->onLoad(); + + +?> \ No newline at end of file diff --git a/interface/web/mail/templates/mail_aliasdomain_edit.htm b/interface/web/mail/templates/mail_aliasdomain_edit.htm new file mode 100644 index 000000000..4f6a6b053 --- /dev/null +++ b/interface/web/mail/templates/mail_aliasdomain_edit.htm @@ -0,0 +1,37 @@ +

+

+ +
+ +
+
+
+ + +
+
+ + +
+
+

{tmpl_var name='active_txt'}

+
+ {tmpl_var name='active'} +
+
+
+ + + + +
+ + +
+
+ +
diff --git a/interface/web/mail/templates/mail_aliasdomain_list.htm b/interface/web/mail/templates/mail_aliasdomain_list.htm new file mode 100644 index 000000000..2bf29dbb1 --- /dev/null +++ b/interface/web/mail/templates/mail_aliasdomain_list.htm @@ -0,0 +1,57 @@ +

+

+ +
+ +
+
{tmpl_var name="toolsarea_head_txt"} +
+ +
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
{tmpl_var name="active"}{tmpl_var name="source"}{tmpl_var name="destination"} + +
+
+
+ +
-- GitLab