Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
a59731 1 <?php
D 2
3 /*
4 Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 /******************************************
32 * Begin Form configuration
33 ******************************************/
34
35 $tform_def_file = "form/dns_slave.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';
a59731 43
D 44 //* Check permissions for module
45 $app->auth->check_module_permissions('dns');
46
47 // Loading classes
48 $app->uses('tpl,tform,tform_actions,validate_dns');
49 $app->load('tform_actions');
50
51 class page_action extends tform_actions {
7fe908 52
a59731 53     function onShowNew() {
D 54         global $app, $conf;
7fe908 55
a59731 56         // we will check only users, not admins
D 57         if($_SESSION["s"]["user"]["typ"] == 'user') {
58             if(!$app->tform->checkClientLimit('limit_dns_slave_zone')) {
59                 $app->error($app->tform->wordbook["limit_dns_slave_zone_txt"]);
60             }
61             if(!$app->tform->checkResellerLimit('limit_dns_slave_zone')) {
62                 $app->error('Reseller: '.$app->tform->wordbook["limit_dns_slave_zone_txt"]);
63             }
41d7d1 64         } else {
SC 65             $settings = $app->getconf->get_global_config('dns');
66             $app->tform->formDef['tabs']['dns_slave']['fields']['server_id']['default'] = intval($settings['default_slave_dnsserver']);
a59731 67         }
7fe908 68
a59731 69         parent::onShowNew();
D 70     }
7fe908 71
a59731 72     function onShowEnd() {
D 73         global $app, $conf;
7fe908 74
3e94c8 75         $app->uses('ini_parser,getconf');
SC 76         $settings = $app->getconf->get_global_config('domains');
77
78         /*
79          * Now we have to check, if we should use the domain-module to select the domain
80          * or not
81          */
82         if ($settings['use_domain_module'] != 'y') {
83             // If user is admin, we will allow him to select to whom this record belongs
84             if($_SESSION["s"]["user"]["typ"] == 'admin') {
85                 // Getting Domains of the user
86                 $sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
87                 $clients = $app->db->queryAllRecords($sql);
88                 $client_select = '';
89                 if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>";
90                 //$tmp_data_record = $app->tform->getDataRecord($this->id);
91                 if(is_array($clients)) {
92                     foreach( $clients as $client) {
93                         $selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
94                         $client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
95                     }
a59731 96                 }
3e94c8 97                 $app->tpl->setVar("client_group_id", $client_select);
SC 98             } else if($app->auth->has_clients($_SESSION['s']['user']['userid'])) {
7fe908 99
MC 100                 // Get the limits of the client
35509d 101                 $client_group_id = intval($_SESSION["s"]["user"]["default_group"]);
cc7a82 102                 $client = $app->db->queryOneRecord("SELECT client.client_id, sys_group.name, client.contact_name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
7fe908 103
MC 104                 // Fill the client select field
cc7a82 105                 $sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ? ORDER BY client.company_name, client.contact_name, sys_group.name";
MC 106                 $clients = $app->db->queryAllRecords($sql, $client['client_id']);
107                 $tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client['client_id']);
7fe908 108                 $client_select = '<option value="'.$tmp['groupid'].'">'.$client['contactname'].'</option>';
MC 109                 //$tmp_data_record = $app->tform->getDataRecord($this->id);
110                 if(is_array($clients)) {
111                     foreach( $clients as $client) {
112                         $selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
113                         $client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
114                     }
a59731 115                 }
7fe908 116                 $app->tpl->setVar("client_group_id", $client_select);
MC 117
a59731 118             }
3e94c8 119         } else {
021ef6 120             /*
SC 121              * The domain-module is in use.
122             */
9ec304 123             $domains = $app->tools_sites->getDomainModuleDomains("dns_slave", $this->dataRecord["origin"]);
021ef6 124             $domain_select = '';
SC 125             if(is_array($domains) && sizeof($domains) > 0) {
126                 /* We have domains in the list, so create the drop-down-list */
127                 foreach( $domains as $domain) {
128                     $domain_select .= "<option value=" . $domain['domain_id'] ;
129                     if ($domain['domain'].'.' == $this->dataRecord["origin"]) {
130                         $domain_select .= " selected";
131                     }
132                     $domain_select .= ">" . $app->functions->idn_decode($domain['domain']) . ".</option>\r\n";
133                 }
134             }
135             else {
136                 /*
137                  * We have no domains in the domain-list. This means, we can not add ANY new domain.
138                  * To avoid, that the variable "domain_option" is empty and so the user can
139                  * free enter a domain, we have to create a empty option!
140                 */
141                 $domain_select .= "<option value=''></option>\r\n";
142             }
143             $app->tpl->setVar("domain_option", $domain_select);
144         }
145
355efb 146         if($this->id > 0) {
T 147             //* we are editing a existing record
148             $app->tpl->setVar("edit_disabled", 1);
149             $app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]);
150         } else {
151             $app->tpl->setVar("edit_disabled", 0);
152         }
7fe908 153
a59731 154         parent::onShowEnd();
D 155     }
7fe908 156
a59731 157     function onSubmit() {
D 158         global $app, $conf;
7fe908 159
021ef6 160         /* check if the domain module is used - and check if the selected domain can be used! */
SC 161         $app->uses('ini_parser,getconf');
162         $settings = $app->getconf->get_global_config('domains');
163         if ($settings['use_domain_module'] == 'y') {
3e94c8 164             if ($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
SC 165                 $this->dataRecord['client_group_id'] = $app->tools_sites->getClientIdForDomain($this->dataRecord['origin']);
166             }
021ef6 167             $domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['origin']);
SC 168             if(!$domain_check) {
169                 // invalid domain selected
170                 $app->tform->errorMessage .= $app->tform->lng("origin_error_empty")."<br />";
171             } else {
172                 $this->dataRecord['origin'] = $domain_check.'.';
173             }
174         }
175
a59731 176         if($_SESSION["s"]["user"]["typ"] != 'admin') {
D 177             // Get the limits of the client
35509d 178             $client_group_id = intval($_SESSION["s"]["user"]["default_group"]);
cc7a82 179             $client = $app->db->queryOneRecord("SELECT limit_dns_slave_zone, default_slave_dnsserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
7fe908 180
a59731 181             // When the record is updated
D 182             if($this->id > 0) {
183                 // restore the server ID if the user is not admin and record is edited
cc7a82 184                 $tmp = $app->db->queryOneRecord("SELECT server_id FROM dns_slave WHERE id = ?", $this->id);
a59731 185                 $this->dataRecord["server_id"] = $tmp["server_id"];
D 186                 unset($tmp);
7fe908 187                 // When the record is inserted
a59731 188             } else {
D 189                 // set the server ID to the default dnsserver of the client
615a0a 190                 $this->dataRecord["server_id"] = $client["default_slave_dnsserver"];
7fe908 191
a59731 192                 // Check if the user may add anoter secondary domain.
1ca823 193                 if(!$app->tform->checkClientLimit('limit_dns_slave_zone')) {
T 194                     $app->error($app->tform->wordbook["limit_dns_slave_zone_txt"]);
195                 }
196                 if(!$app->tform->checkResellerLimit('limit_dns_slave_zone')) {
197                     $app->error('Reseller: '.$app->tform->wordbook["limit_dns_slave_zone_txt"]);
a59731 198                 }
D 199             }
200         }
7fe908 201
a59731 202         //* Check if the zone name has a dot at the end
7fe908 203         if(strlen($this->dataRecord["origin"]) > 0 && substr($this->dataRecord["origin"], -1, 1) != '.') $this->dataRecord["origin"] .= '.';
MC 204
205         //* Check if a primary zone with the same name already exists
cc7a82 206         $tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_soa WHERE origin = ? AND server_id = ?", $this->dataRecord["origin"], $this->dataRecord["server_id"]);
a59731 207         if($tmp["number"] > 0) {
7fe908 208             $app->error($app->tform->wordbook["origin_error_unique"]);
a59731 209         }
D 210
211         parent::onSubmit();
212     }
7fe908 213
3f478f 214     function onInsert() {
T 215         global $app, $conf;
7fe908 216
3f478f 217         // Check if record is existing already
cc7a82 218         $duplicate_slave = $app->db->queryOneRecord("SELECT * FROM dns_slave WHERE origin = ? AND server_id = ? AND ".$app->tform->getAuthSQL('r'), $this->dataRecord["origin"], $this->dataRecord["server_id"]);
7fe908 219
3f478f 220         if(is_array($duplicate_slave) && !empty($duplicate_slave)) $app->error($app->tform->wordbook["origin_error_unique"]);
7fe908 221
3f478f 222         parent::onInsert();
T 223     }
7fe908 224
a59731 225 }
D 226
227 $page = new page_action;
228 $page->onLoad();
229
230 ?>