commit | author | age
|
3dbcc3
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2008, 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 |
|
b1a6a5
|
31 |
require_once '../../lib/config.inc.php'; |
MC |
32 |
require_once '../../lib/app.inc.php'; |
3dbcc3
|
33 |
|
T |
34 |
//* Check permissions for module |
|
35 |
$app->auth->check_module_permissions('dns'); |
|
36 |
|
|
37 |
|
|
38 |
// Loading the template |
b33d7d
|
39 |
$app->uses('tpl,validate_dns,tform'); |
3dbcc3
|
40 |
$app->tpl->newTemplate("form.tpl.htm"); |
b1a6a5
|
41 |
$app->tpl->setInclude('content_tpl', 'templates/dns_wizard.htm'); |
44d2a7
|
42 |
$app->load_language_file('/web/dns/lib/lang/'.$_SESSION['s']['language'].'_dns_wizard.lng'); |
3dbcc3
|
43 |
|
b33d7d
|
44 |
// Check if dns record limit has been reached. We will check only users, not admins |
TB |
45 |
if($_SESSION["s"]["user"]["typ"] == 'user') { |
|
46 |
$app->tform->formDef['db_table_idx'] = 'id'; |
|
47 |
$app->tform->formDef['db_table'] = 'dns_soa'; |
|
48 |
if(!$app->tform->checkClientLimit('limit_dns_zone')) { |
|
49 |
$app->error($app->lng('limit_dns_zone_txt')); |
|
50 |
} |
|
51 |
if(!$app->tform->checkResellerLimit('limit_dns_zone')) { |
|
52 |
$app->error('Reseller: '.$app->lng('limit_dns_zone_txt')); |
|
53 |
} |
|
54 |
} |
|
55 |
|
3dbcc3
|
56 |
// import variables |
65ea2e
|
57 |
$template_id = (isset($_POST['template_id']))?$app->functions->intval($_POST['template_id']):0; |
M |
58 |
$sys_groupid = (isset($_POST['client_group_id']))?$app->functions->intval($_POST['client_group_id']):0; |
3dbcc3
|
59 |
|
T |
60 |
// get the correct server_id |
bd6659
|
61 |
if (isset($_POST['server_id'])) { |
SJ |
62 |
$server_id = $app->functions->intval($_POST['server_id']); |
|
63 |
$post_server_id = true; |
1a2cbf
|
64 |
} elseif (isset($_POST['server_id_value'])) { |
MC |
65 |
$server_id = $app->functions->intval($_POST['server_id_value']); |
|
66 |
$post_server_id = true; |
3dbcc3
|
67 |
} else { |
41d7d1
|
68 |
$settings = $app->getconf->get_global_config('dns'); |
SC |
69 |
$server_id = $app->functions->intval($settings['default_dnsserver']); |
bd6659
|
70 |
$post_server_id = false; |
SJ |
71 |
} |
3dbcc3
|
72 |
|
T |
73 |
// Load the templates |
222ea2
|
74 |
$records = $app->db->queryAllRecords("SELECT * FROM dns_template WHERE visible = 'Y' ORDER BY name ASC"); |
3dbcc3
|
75 |
$template_id_option = ''; |
T |
76 |
$n = 0; |
|
77 |
foreach($records as $rec){ |
|
78 |
$checked = ($rec['template_id'] == $template_id)?' SELECTED':''; |
|
79 |
$template_id_option .= '<option value="'.$rec['template_id'].'"'.$checked.'>'.$rec['name'].'</option>'; |
|
80 |
if($n == 0 && $template_id == 0) $template_id = $rec['template_id']; |
|
81 |
$n++; |
|
82 |
} |
|
83 |
unset($n); |
b1a6a5
|
84 |
$app->tpl->setVar("template_id_option", $template_id_option); |
3dbcc3
|
85 |
|
3e94c8
|
86 |
$app->uses('ini_parser,getconf'); |
SC |
87 |
$domains_settings = $app->getconf->get_global_config('domains'); |
|
88 |
|
3dbcc3
|
89 |
// If the user is administrator |
T |
90 |
if($_SESSION['s']['user']['typ'] == 'admin') { |
b1a6a5
|
91 |
|
3dbcc3
|
92 |
// Load the list of servers |
0da7c5
|
93 |
$records = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE mirror_server_id = 0 AND dns_server = 1 ORDER BY server_name"); |
3dbcc3
|
94 |
$server_id_option = ''; |
T |
95 |
foreach($records as $rec){ |
|
96 |
$checked = ($rec['server_id'] == $server_id)?' SELECTED':''; |
|
97 |
$server_id_option .= '<option value="'.$rec['server_id'].'"'.$checked.'>'.$rec['server_name'].'</option>'; |
|
98 |
} |
b1a6a5
|
99 |
$app->tpl->setVar("server_id", $server_id_option); |
MC |
100 |
|
3e94c8
|
101 |
if ($domains_settings['use_domain_module'] != 'y') { |
SC |
102 |
// load the list of clients |
|
103 |
$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"; |
|
104 |
$clients = $app->db->queryAllRecords($sql); |
|
105 |
$client_select = ''; |
|
106 |
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>"; |
|
107 |
if(is_array($clients)) { |
|
108 |
foreach( $clients as $client) { |
|
109 |
$selected = ($client["groupid"] == $sys_groupid)?'SELECTED':''; |
|
110 |
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n"; |
|
111 |
} |
3dbcc3
|
112 |
} |
T |
113 |
|
3e94c8
|
114 |
$app->tpl->setVar("client_group_id", $client_select); |
SC |
115 |
} |
3dbcc3
|
116 |
} |
T |
117 |
|
0fd51f
|
118 |
if ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
b1a6a5
|
119 |
|
0fd51f
|
120 |
// Get the limits of the client |
604c0c
|
121 |
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
cc7a82
|
122 |
$client = $app->db->queryOneRecord("SELECT client.client_id, 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, sys_group.name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
0fd51f
|
123 |
|
b1a6a5
|
124 |
|
3e94c8
|
125 |
if ($domains_settings['use_domain_module'] != 'y') { |
SC |
126 |
// load the list of clients |
cc7a82
|
127 |
$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 |
128 |
$clients = $app->db->queryAllRecords($sql, $client['client_id']); |
|
129 |
$tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client['client_id']); |
3e94c8
|
130 |
$client_select = '<option value="'.$tmp['groupid'].'">'.$client['contactname'].'</option>'; |
SC |
131 |
if(is_array($clients)) { |
|
132 |
foreach( $clients as $client) { |
|
133 |
$selected = ($client["groupid"] == $sys_groupid)?'SELECTED':''; |
|
134 |
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n"; |
|
135 |
} |
0fd51f
|
136 |
} |
T |
137 |
|
3e94c8
|
138 |
$app->tpl->setVar("client_group_id", $client_select); |
SC |
139 |
} |
0fd51f
|
140 |
} |
T |
141 |
|
bd6659
|
142 |
if($_SESSION["s"]["user"]["typ"] != 'admin') |
775c05
|
143 |
{ |
MC |
144 |
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
cc7a82
|
145 |
$client_dns = $app->db->queryOneRecord("SELECT dns_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
bd6659
|
146 |
|
SJ |
147 |
$client_dns['dns_servers_ids'] = explode(',', $client_dns['dns_servers']); |
|
148 |
|
|
149 |
$only_one_server = count($client_dns['dns_servers_ids']) === 1; |
|
150 |
$app->tpl->setVar('only_one_server', $only_one_server); |
|
151 |
|
|
152 |
if ($only_one_server) { |
|
153 |
$app->tpl->setVar('server_id_value', $client_dns['dns_servers_ids'][0]); |
|
154 |
} |
|
155 |
|
cc7a82
|
156 |
$sql = "SELECT server_id, server_name FROM server WHERE server_id IN ?"; |
MC |
157 |
$dns_servers = $app->db->queryAllRecords($sql, $client_dns['dns_servers_ids']); |
bd6659
|
158 |
|
SJ |
159 |
$options_dns_servers = ""; |
|
160 |
|
|
161 |
foreach ($dns_servers as $dns_server) { |
75b7fc
|
162 |
$options_dns_servers .= '<option value="'.$dns_server['server_id'].'"'.($_POST['server_id'] == $dns_server['server_id'] ? ' selected="selected"' : '').'>'.$dns_server['server_name'].'</option>'; |
bd6659
|
163 |
} |
SJ |
164 |
|
|
165 |
$app->tpl->setVar("server_id", $options_dns_servers); |
|
166 |
unset($options_dns_servers); |
|
167 |
|
|
168 |
} |
0fd51f
|
169 |
|
cc7a82
|
170 |
$template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = ?", $template_id); |
b1a6a5
|
171 |
$fields = explode(',', $template_record['fields']); |
3dbcc3
|
172 |
if(is_array($fields)) { |
T |
173 |
foreach($fields as $field) { |
b1a6a5
|
174 |
$app->tpl->setVar($field."_VISIBLE", 1); |
3dbcc3
|
175 |
$field = strtolower($field); |
b1a6a5
|
176 |
$app->tpl->setVar($field, $_POST[$field]); |
3dbcc3
|
177 |
} |
T |
178 |
} |
|
179 |
|
021ef6
|
180 |
/* |
SC |
181 |
* Now we have to check, if we should use the domain-module to select the domain |
|
182 |
* or not |
|
183 |
*/ |
3e94c8
|
184 |
if ($domains_settings['use_domain_module'] == 'y') { |
021ef6
|
185 |
/* |
SC |
186 |
* The domain-module is in use. |
|
187 |
*/ |
9ec304
|
188 |
$domains = $app->tools_sites->getDomainModuleDomains("dns_soa"); |
021ef6
|
189 |
$domain_select = ''; |
SC |
190 |
if(is_array($domains) && sizeof($domains) > 0) { |
|
191 |
/* We have domains in the list, so create the drop-down-list */ |
|
192 |
foreach( $domains as $domain) { |
|
193 |
$domain_select .= "<option value=" . $domain['domain_id'] ; |
|
194 |
if ($domain['domain'] == $_POST['domain']) { |
|
195 |
$domain_select .= " selected"; |
|
196 |
} |
|
197 |
$domain_select .= ">" . $app->functions->idn_decode($domain['domain']) . ".</option>\r\n"; |
|
198 |
} |
|
199 |
} |
|
200 |
else { |
|
201 |
/* |
|
202 |
* We have no domains in the domain-list. This means, we can not add ANY new domain. |
|
203 |
* To avoid, that the variable "domain_option" is empty and so the user can |
|
204 |
* free enter a domain, we have to create a empty option! |
|
205 |
*/ |
|
206 |
$domain_select .= "<option value=''></option>\r\n"; |
|
207 |
} |
|
208 |
$app->tpl->setVar("domain_option", $domain_select); |
|
209 |
} |
|
210 |
|
3dbcc3
|
211 |
if($_POST['create'] == 1) { |
69a57d
|
212 |
|
TB |
213 |
//* CSRF Check |
|
214 |
$app->auth->csrf_token_check(); |
|
215 |
|
3dbcc3
|
216 |
$error = ''; |
b1a6a5
|
217 |
|
015dff
|
218 |
if ($post_server_id) |
bd6659
|
219 |
{ |
c6d29c
|
220 |
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
cc7a82
|
221 |
$client = $app->db->queryOneRecord("SELECT dns_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
bd6659
|
222 |
|
SJ |
223 |
$client['dns_servers_ids'] = explode(',', $client['dns_servers']); |
|
224 |
|
|
225 |
// Check if chosen server is in authorized servers for this client |
|
226 |
if (!(is_array($client['dns_servers_ids']) && in_array($server_id, $client['dns_servers_ids'])) && $_SESSION["s"]["user"]["typ"] != 'admin') { |
|
227 |
$error .= $app->lng('error_not_allowed_server_id').'<br />'; |
|
228 |
} |
|
229 |
} |
|
230 |
else |
|
231 |
{ |
|
232 |
$error .= $app->lng('error_no_server_id').'<br />'; |
|
233 |
} |
015dff
|
234 |
|
992797
|
235 |
// apply filters |
MC |
236 |
if(isset($_POST['domain']) && $_POST['domain'] != ''){ |
021ef6
|
237 |
/* check if the domain module is used - and check if the selected domain can be used! */ |
3e94c8
|
238 |
if ($domains_settings['use_domain_module'] == 'y') { |
SC |
239 |
if ($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
240 |
$_POST['client_group_id'] = $app->tools_sites->getClientIdForDomain($_POST['domain']); |
|
241 |
} |
021ef6
|
242 |
$domain_check = $app->tools_sites->checkDomainModuleDomain($_POST['domain']); |
SC |
243 |
if(!$domain_check) { |
|
244 |
// invalid domain selected |
|
245 |
$_POST['domain'] = ''; |
|
246 |
} else { |
|
247 |
$_POST['domain'] = $domain_check; |
|
248 |
} |
|
249 |
} else { |
|
250 |
$_POST['domain'] = $app->functions->idn_encode($_POST['domain']); |
|
251 |
$_POST['domain'] = strtolower($_POST['domain']); |
|
252 |
} |
992797
|
253 |
} |
MC |
254 |
if(isset($_POST['ns1']) && $_POST['ns1'] != ''){ |
|
255 |
$_POST['ns1'] = $app->functions->idn_encode($_POST['ns1']); |
|
256 |
$_POST['ns1'] = strtolower($_POST['ns1']); |
|
257 |
} |
|
258 |
if(isset($_POST['ns2']) && $_POST['ns2'] != ''){ |
|
259 |
$_POST['ns2'] = $app->functions->idn_encode($_POST['ns2']); |
|
260 |
$_POST['ns2'] = strtolower($_POST['ns2']); |
|
261 |
} |
|
262 |
if(isset($_POST['email']) && $_POST['email'] != ''){ |
|
263 |
$_POST['email'] = $app->functions->idn_encode($_POST['email']); |
|
264 |
$_POST['email'] = strtolower($_POST['email']); |
|
265 |
} |
b1a6a5
|
266 |
|
MC |
267 |
|
44d2a7
|
268 |
if(isset($_POST['domain']) && $_POST['domain'] == '') $error .= $app->lng('error_domain_empty').'<br />'; |
b1a6a5
|
269 |
elseif(isset($_POST['domain']) && !preg_match('/^[\w\.\-]{2,64}\.[a-zA-Z0-9\-]{2,30}$/', $_POST['domain'])) $error .= $app->lng('error_domain_regex').'<br />'; |
72695f
|
270 |
|
44d2a7
|
271 |
if(isset($_POST['ip']) && $_POST['ip'] == '') $error .= $app->lng('error_ip_empty').'<br />'; |
72695f
|
272 |
|
604d25
|
273 |
if(isset($_POST['ipv6']) && $_POST['ipv6'] == '') $error .= $app->lng('error_ipv6_empty').'<br />'; |
CS |
274 |
|
44d2a7
|
275 |
if(isset($_POST['ns1']) && $_POST['ns1'] == '') $error .= $app->lng('error_ns1_empty').'<br />'; |
b1a6a5
|
276 |
elseif(isset($_POST['ns1']) && !preg_match('/^[\w\.\-]{2,64}\.[a-zA-Z0-9]{2,30}$/', $_POST['ns1'])) $error .= $app->lng('error_ns1_regex').'<br />'; |
72695f
|
277 |
|
44d2a7
|
278 |
if(isset($_POST['ns2']) && $_POST['ns2'] == '') $error .= $app->lng('error_ns2_empty').'<br />'; |
b1a6a5
|
279 |
elseif(isset($_POST['ns2']) && !preg_match('/^[\w\.\-]{2,64}\.[a-zA-Z0-9]{2,30}$/', $_POST['ns2'])) $error .= $app->lng('error_ns2_regex').'<br />'; |
72695f
|
280 |
|
44d2a7
|
281 |
if(isset($_POST['email']) && $_POST['email'] == '') $error .= $app->lng('error_email_empty').'<br />'; |
9f9a0c
|
282 |
elseif(isset($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) $error .= $app->lng('error_email_regex').'<br />'; |
b1a6a5
|
283 |
|
10b4c8
|
284 |
// make sure that the record belongs to the client group and not the admin group when admin inserts it |
721fb2
|
285 |
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($_POST['client_group_id'])) { |
65ea2e
|
286 |
$sys_groupid = $app->functions->intval($_POST['client_group_id']); |
721fb2
|
287 |
} elseif($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($_POST['client_group_id'])) { |
65ea2e
|
288 |
$sys_groupid = $app->functions->intval($_POST['client_group_id']); |
721fb2
|
289 |
} else { |
T |
290 |
$sys_groupid = $_SESSION["s"]["user"]["default_group"]; |
|
291 |
} |
b1a6a5
|
292 |
|
8fb58f
|
293 |
$tform_def_file = "form/dns_soa.tform.php"; |
T |
294 |
$app->uses('tform'); |
|
295 |
$app->tform->loadFormDef($tform_def_file); |
b1a6a5
|
296 |
|
616d34
|
297 |
if($_SESSION['s']['user']['typ'] != 'admin') { |
T |
298 |
if(!$app->tform->checkClientLimit('limit_dns_zone')) { |
|
299 |
$error .= $app->tform->wordbook["limit_dns_zone_txt"]; |
|
300 |
} |
|
301 |
if(!$app->tform->checkResellerLimit('limit_dns_zone')) { |
|
302 |
$error .= $app->tform->wordbook["limit_dns_zone_txt"]; |
|
303 |
} |
3cebc3
|
304 |
} |
b1a6a5
|
305 |
|
MC |
306 |
|
3dbcc3
|
307 |
// replace template placeholders |
T |
308 |
$tpl_content = $template_record['template']; |
b1a6a5
|
309 |
if($_POST['domain'] != '') $tpl_content = str_replace('{DOMAIN}', $_POST['domain'], $tpl_content); |
MC |
310 |
if($_POST['ip'] != '') $tpl_content = str_replace('{IP}', $_POST['ip'], $tpl_content); |
604d25
|
311 |
if($_POST['ipv6'] != '') $tpl_content = str_replace('{IPV6}',$_POST['ipv6'],$tpl_content); |
b1a6a5
|
312 |
if($_POST['ns1'] != '') $tpl_content = str_replace('{NS1}', $_POST['ns1'], $tpl_content); |
MC |
313 |
if($_POST['ns2'] != '') $tpl_content = str_replace('{NS2}', $_POST['ns2'], $tpl_content); |
|
314 |
if($_POST['email'] != '') $tpl_content = str_replace('{EMAIL}', $_POST['email'], $tpl_content); |
28cd07
|
315 |
$enable_dnssec = (($_POST['dnssec'] == 'Y') ? 'Y' : 'N'); |
b1a6a5
|
316 |
if(isset($_POST['dkim']) && preg_match('/^[\w\.\-\/]{2,255}\.[a-zA-Z0-9\-]{2,30}[\.]{0,1}$/', $_POST['domain'])) { |
5588af
|
317 |
$sql = $app->db->queryOneRecord("SELECT dkim_public, dkim_selector FROM mail_domain WHERE domain = ? AND dkim = 'y' AND ".$app->tform->getAuthSQL('r'), $_POST['domain']); |
76be2b
|
318 |
$public_key = $sql['dkim_public']; |
b1a6a5
|
319 |
if ($public_key!='') { |
76be2b
|
320 |
if (empty($sql['dkim_selector'])) $sql['dkim_selector'] = 'default'; |
FS |
321 |
$dns_record=str_replace(array("\r\n", "\n", "\r", "-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----"), '', $public_key); |
|
322 |
$tpl_content .= "\n".'TXT|'.$sql['dkim_selector'].'._domainkey.'.$_POST['domain'].'.|v=DKIM1; t=s; p='.$dns_record; |
b1a6a5
|
323 |
} |
MC |
324 |
} |
|
325 |
|
992797
|
326 |
// Parse the template |
b1a6a5
|
327 |
$tpl_rows = explode("\n", $tpl_content); |
3dbcc3
|
328 |
$section = ''; |
T |
329 |
$vars = array(); |
d63cea
|
330 |
$vars['xfer']=''; |
3dbcc3
|
331 |
$dns_rr = array(); |
T |
332 |
foreach($tpl_rows as $row) { |
|
333 |
$row = trim($row); |
b1a6a5
|
334 |
if(substr($row, 0, 1) == '[') { |
3dbcc3
|
335 |
if($row == '[ZONE]') { |
T |
336 |
$section = 'zone'; |
|
337 |
} elseif($row == '[DNS_RECORDS]') { |
|
338 |
$section = 'dns_records'; |
|
339 |
} else { |
|
340 |
die('Unknown section type'); |
|
341 |
} |
|
342 |
} else { |
|
343 |
if($row != '') { |
|
344 |
// Handle zone section |
|
345 |
if($section == 'zone') { |
b1a6a5
|
346 |
$parts = explode('=', $row); |
3dbcc3
|
347 |
$key = trim($parts[0]); |
T |
348 |
$val = trim($parts[1]); |
|
349 |
if($key != '') $vars[$key] = $val; |
|
350 |
} |
|
351 |
// Handle DNS Record rows |
|
352 |
if($section == 'dns_records') { |
b1a6a5
|
353 |
$parts = explode('|', $row); |
3dbcc3
|
354 |
$dns_rr[] = array( |
3a11d2
|
355 |
'name' => $parts[1], |
MC |
356 |
'type' => $parts[0], |
|
357 |
'data' => $parts[2], |
|
358 |
'aux' => $parts[3], |
|
359 |
'ttl' => $parts[4] |
3dbcc3
|
360 |
); |
T |
361 |
} |
|
362 |
} |
|
363 |
} |
b1a6a5
|
364 |
|
3dbcc3
|
365 |
} // end foreach |
b1a6a5
|
366 |
|
44d2a7
|
367 |
if($vars['origin'] == '') $error .= $app->lng('error_origin_empty').'<br />'; |
T |
368 |
if($vars['ns'] == '') $error .= $app->lng('error_ns_empty').'<br />'; |
|
369 |
if($vars['mbox'] == '') $error .= $app->lng('error_mbox_empty').'<br />'; |
|
370 |
if($vars['refresh'] == '') $error .= $app->lng('error_refresh_empty').'<br />'; |
|
371 |
if($vars['retry'] == '') $error .= $app->lng('error_retry_empty').'<br />'; |
|
372 |
if($vars['expire'] == '') $error .= $app->lng('error_expire_empty').'<br />'; |
|
373 |
if($vars['minimum'] == '') $error .= $app->lng('error_minimum_empty').'<br />'; |
|
374 |
if($vars['ttl'] == '') $error .= $app->lng('error_ttl_empty').'<br />'; |
b1a6a5
|
375 |
|
3dbcc3
|
376 |
if($error == '') { |
T |
377 |
// Insert the soa record |
|
378 |
$sys_userid = $_SESSION['s']['user']['userid']; |
3a11d2
|
379 |
$origin = $vars['origin']; |
MC |
380 |
$ns = $vars['ns']; |
|
381 |
$mbox = str_replace('@', '.', $vars['mbox']); |
|
382 |
$refresh = $vars['refresh']; |
|
383 |
$retry = $vars['retry']; |
|
384 |
$expire = $vars['expire']; |
|
385 |
$minimum = $vars['minimum']; |
|
386 |
$ttl = $vars['ttl']; |
|
387 |
$xfer = $vars['xfer']; |
|
388 |
$also_notify = $vars['also_notify']; |
|
389 |
$update_acl = $vars['update_acl']; |
3dbcc3
|
390 |
$serial = $app->validate_dns->increase_serial(0); |
b1a6a5
|
391 |
|
3a11d2
|
392 |
$insert_data = array( |
MC |
393 |
"sys_userid" => $sys_userid, |
|
394 |
"sys_groupid" => $sys_groupid, |
|
395 |
"sys_perm_user" => 'riud', |
|
396 |
"sys_perm_group" => 'riud', |
|
397 |
"sys_perm_other" => '', |
|
398 |
"server_id" => $server_id, |
|
399 |
"origin" => $origin, |
|
400 |
"ns" => $ns, |
|
401 |
"mbox" => $mbox, |
|
402 |
"serial" => $serial, |
|
403 |
"refresh" => $refresh, |
|
404 |
"retry" => $retry, |
|
405 |
"expire" => $expire, |
|
406 |
"minimum" => $minimum, |
|
407 |
"ttl" => $ttl, |
|
408 |
"active" => 'Y', |
|
409 |
"xfer" => $xfer, |
|
410 |
"also_notify" => $also_notify, |
28cd07
|
411 |
"update_acl" => $update_acl, |
AT |
412 |
"dnssec_wanted" => $enable_dnssec |
3a11d2
|
413 |
); |
3dbcc3
|
414 |
$dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id'); |
b1a6a5
|
415 |
|
3dbcc3
|
416 |
// Insert the dns_rr records |
T |
417 |
if(is_array($dns_rr) && $dns_soa_id > 0) { |
|
418 |
foreach($dns_rr as $rr) { |
3a11d2
|
419 |
$insert_data = array( |
MC |
420 |
"sys_userid" => $sys_userid, |
|
421 |
"sys_groupid" => $sys_groupid, |
|
422 |
"sys_perm_user" => 'riud', |
|
423 |
"sys_perm_group" => 'riud', |
|
424 |
"sys_perm_other" => '', |
|
425 |
"server_id" => $server_id, |
|
426 |
"zone" => $dns_soa_id, |
|
427 |
"name" => $rr['name'], |
|
428 |
"type" => $rr['type'], |
|
429 |
"data" => $rr['data'], |
|
430 |
"aux" => $rr['aux'], |
|
431 |
"ttl" => $rr['ttl'], |
|
432 |
"active" => 'Y' |
|
433 |
); |
3dbcc3
|
434 |
$dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id'); |
T |
435 |
} |
|
436 |
} |
b1a6a5
|
437 |
|
3dbcc3
|
438 |
header("Location: dns_soa_list.php"); |
T |
439 |
exit; |
b1a6a5
|
440 |
|
3dbcc3
|
441 |
} else { |
b1a6a5
|
442 |
$app->tpl->setVar("error", $error); |
3dbcc3
|
443 |
} |
b1a6a5
|
444 |
|
3dbcc3
|
445 |
} |
T |
446 |
|
|
447 |
|
|
448 |
|
b1a6a5
|
449 |
$app->tpl->setVar("title", 'DNS Wizard'); |
3dbcc3
|
450 |
|
69a57d
|
451 |
//* SET csrf token |
TB |
452 |
$csrf_token = $app->auth->csrf_token_get('dns_wizard'); |
|
453 |
$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); |
|
454 |
$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); |
|
455 |
|
3dbcc3
|
456 |
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dns_wizard.lng'; |
b1a6a5
|
457 |
include $lng_file; |
3dbcc3
|
458 |
$app->tpl->setVar($wb); |
T |
459 |
|
|
460 |
$app->tpl_defaults(); |
992797
|
461 |
$app->tpl->pparse(); |
MC |
462 |
|
|
463 |
|
e95eee
|
464 |
?> |