Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
3d229b 1 <?php
T 2 /*
3 Copyright (c) 2005 - 2009, Till Brehm, projektfarm Gmbh
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
8
9     * Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright notice,
12       this list of conditions and the following disclaimer in the documentation
13       and/or other materials provided with the distribution.
14     * Neither the name of ISPConfig nor the names of its contributors
15       may be used to endorse or promote products derived from this software without
16       specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30
31 /******************************************
32 * Begin Form configuration
33 ******************************************/
34
35 $tform_def_file = "form/mail_aliasdomain.tform.php";
36
37 /******************************************
38 * End Form configuration
39 ******************************************/
40
7fe908 41 require_once '../../lib/config.inc.php';
MC 42 require_once '../../lib/app.inc.php';
3d229b 43
T 44 //* Check permissions for module
45 $app->auth->check_module_permissions('mail');
46
47 // Loading classes
48 $app->uses('tpl,tform,tform_actions');
49 $app->load('tform_actions');
50
51 class page_action extends tform_actions {
7fe908 52
3d229b 53     function onShowNew() {
T 54         global $app, $conf;
7fe908 55
3d229b 56         // we will check only users, not admins
T 57         if($_SESSION["s"]["user"]["typ"] == 'user') {
7fe908 58             if(!$app->tform->checkClientLimit('limit_mailaliasdomain', "type = 'aliasdomain'")) {
3d229b 59                 $app->error($app->tform->wordbook["limit_mailaliasdomain_txt"]);
T 60             }
7fe908 61             if(!$app->tform->checkResellerLimit('limit_mailaliasdomain', "type = 'aliasdomain'")) {
3d229b 62                 $app->error('Reseller: '.$app->tform->wordbook["limit_mailaliasdomain_txt"]);
T 63             }
64         }
7fe908 65
3d229b 66         parent::onShowNew();
T 67     }
7fe908 68
3d229b 69     function onShowEnd() {
T 70         global $app, $conf;
7fe908 71
MC 72         $source_domain = $app->functions->idn_decode(substr($this->dataRecord["source"], 1));
73         $destination_domain = $app->functions->idn_decode(substr($this->dataRecord["destination"], 1));
74
3d229b 75         // Getting Domains of the user
T 76         $sql = "SELECT domain FROM mail_domain WHERE ".$app->tform->getAuthSQL('r').' ORDER BY domain';
77         $domains = $app->db->queryAllRecords($sql);
7fe908 78
3d229b 79         $source_select = '';
T 80         $destination_select = '';
81         if(is_array($domains)) {
82             foreach( $domains as $domain) {
7fe908 83                 $domain['domain'] = $app->functions->idn_decode($domain['domain']);
3d229b 84                 $selected = ($domain["domain"] == @$source_domain)?'SELECTED':'';
T 85                 $source_select .= "<option value='$domain[domain]' $selected>$domain[domain]</option>\r\n";
86                 $selected = ($domain["domain"] == @$destination_domain)?'SELECTED':'';
87                 $destination_select .= "<option value='$domain[domain]' $selected>$domain[domain]</option>\r\n";
88             }
89         }
7fe908 90         $app->tpl->setVar("source_domain", $source_select);
MC 91         $app->tpl->setVar("destination_domain", $destination_select);
92
3d229b 93         parent::onShowEnd();
T 94     }
7fe908 95
3d229b 96     function onSubmit() {
T 97         global $app, $conf;
7fe908 98
3d229b 99         // Check if source Domain belongs to user
2af58c 100         $domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = ? AND ".$app->tform->getAuthSQL('r'), $app->functions->idn_encode($_POST["source"]));
d6363b 101         if($domain["domain"] != $app->functions->idn_encode($_POST["source"])) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"];
7fe908 102
3d229b 103         // Check if the destination domain belongs to the user
2af58c 104         $domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = ? AND ".$app->tform->getAuthSQL('r'), $app->functions->idn_encode($_POST["destination"]));
d6363b 105         if($domain["domain"] != $app->functions->idn_encode($_POST["destination"])) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"];
7fe908 106
3d229b 107         // Check the client limits, if user is not the admin
T 108         if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
7fe908 109             if(!$app->tform->checkClientLimit('limit_mailaliasdomain', "type = 'aliasdomain'")) {
3d229b 110                 $app->error($app->tform->wordbook["limit_mailaliasdomain_txt"]);
T 111             }
7fe908 112             if(!$app->tform->checkResellerLimit('limit_mailaliasdomain', "type = 'aliasdomain'")) {
3d229b 113                 $app->error('Reseller: '.$app->tform->wordbook["limit_mailaliasdomain_txt"]);
T 114             }
115         } // end if user is not admin
7fe908 116
3d229b 117         if($this->dataRecord["source"] == $this->dataRecord["destination"]) $app->tform->errorMessage .= $app->tform->wordbook["source_destination_identical_txt"];
2af58c 118         
MC 119         /* TODO: check if this quoting is correkt! */
3d229b 120         // compose the source and destination field
3a11d2 121         $this->dataRecord["source"] = "@".$this->dataRecord["source"];
MC 122         $this->dataRecord["destination"] = "@".$this->dataRecord["destination"];
3d229b 123         // Set the server id of the mailbox = server ID of mail domain.
604c0c 124         $this->dataRecord["server_id"] = $app->functions->intval($domain["server_id"]);
7fe908 125
3d229b 126         parent::onSubmit();
T 127     }
7fe908 128
3d229b 129     function onAfterInsert() {
T 130         global $app;
7fe908 131
2af58c 132         $domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain = ? AND ".$app->tform->getAuthSQL('r'), $app->functions->idn_encode($_POST["destination"]));
MC 133         $app->db->query("update mail_forwarding SET sys_groupid = ? WHERE forwarding_id = ?", $domain['sys_groupid'], $this->id);
7fe908 134
3d229b 135     }
7fe908 136
MC 137
3d229b 138 }
T 139
140 $page = new page_action;
141 $page->onLoad();
142
7fe908 143 ?>