commit | author | age
|
68e917
|
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 |
|
|
31 |
require_once('../../lib/config.inc.php'); |
|
32 |
require_once('../../lib/app.inc.php'); |
|
33 |
|
|
34 |
//* Check permissions for module |
|
35 |
$app->auth->check_module_permissions('dns'); |
|
36 |
|
|
37 |
|
|
38 |
// Loading the template |
|
39 |
$app->uses('tpl,validate_dns'); |
|
40 |
$app->tpl->newTemplate("form.tpl.htm"); |
|
41 |
$app->tpl->setInclude('content_tpl','templates/dns_wizard.htm'); |
949e7e
|
42 |
$app->load_language_file('/web/dns/lib/lang/'.$_SESSION['s']['language'].'_dns_wizard.lng'); |
68e917
|
43 |
|
T |
44 |
// import variables |
|
45 |
$template_id = (isset($_POST['template_id']))?intval($_POST['template_id']):0; |
|
46 |
$sys_groupid = (isset($_POST['client_group_id']))?intval($_POST['client_group_id']):0; |
|
47 |
|
|
48 |
// get the correct server_id |
|
49 |
if($_SESSION['s']['user']['typ'] == 'admin') { |
|
50 |
$server_id = (isset($_POST['server_id']))?intval($_POST['server_id']):1; |
|
51 |
} else { |
|
52 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
|
53 |
$client = $app->db->queryOneRecord("SELECT default_dnsserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); |
|
54 |
$server_id = $client["default_dnsserver"]; |
|
55 |
} |
|
56 |
|
|
57 |
|
|
58 |
// Load the templates |
|
59 |
$records = $app->db->queryAllRecords("SELECT * FROM dns_template WHERE visible = 'Y'"); |
|
60 |
$template_id_option = ''; |
|
61 |
$n = 0; |
|
62 |
foreach($records as $rec){ |
|
63 |
$checked = ($rec['template_id'] == $template_id)?' SELECTED':''; |
|
64 |
$template_id_option .= '<option value="'.$rec['template_id'].'"'.$checked.'>'.$rec['name'].'</option>'; |
|
65 |
if($n == 0 && $template_id == 0) $template_id = $rec['template_id']; |
|
66 |
$n++; |
|
67 |
} |
|
68 |
unset($n); |
|
69 |
$app->tpl->setVar("template_id_option",$template_id_option); |
|
70 |
|
|
71 |
// If the user is administrator |
|
72 |
if($_SESSION['s']['user']['typ'] == 'admin') { |
|
73 |
|
|
74 |
// Load the list of servers |
|
75 |
$records = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE dns_server = 1 ORDER BY server_name"); |
|
76 |
$server_id_option = ''; |
|
77 |
foreach($records as $rec){ |
|
78 |
$checked = ($rec['server_id'] == $server_id)?' SELECTED':''; |
|
79 |
$server_id_option .= '<option value="'.$rec['server_id'].'"'.$checked.'>'.$rec['server_name'].'</option>'; |
|
80 |
} |
|
81 |
$app->tpl->setVar("server_id",$server_id_option); |
|
82 |
|
|
83 |
// load the list of clients |
|
84 |
$sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0"; |
|
85 |
$clients = $app->db->queryAllRecords($sql); |
|
86 |
$client_select = ''; |
|
87 |
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>"; |
|
88 |
if(is_array($clients)) { |
|
89 |
foreach( $clients as $client) { |
|
90 |
$selected = ($client["groupid"] == $sys_groupid)?'SELECTED':''; |
|
91 |
$client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n"; |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
$app->tpl->setVar("client_group_id",$client_select); |
|
96 |
|
|
97 |
} |
|
98 |
|
|
99 |
$template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = '$template_id'"); |
|
100 |
$fields = explode(',',$template_record['fields']); |
|
101 |
if(is_array($fields)) { |
|
102 |
foreach($fields as $field) { |
|
103 |
$app->tpl->setVar($field."_VISIBLE",1); |
|
104 |
$field = strtolower($field); |
|
105 |
$app->tpl->setVar($field,$_POST[$field]); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
if($_POST['create'] == 1) { |
|
110 |
|
|
111 |
$error = ''; |
|
112 |
|
949e7e
|
113 |
if(isset($_POST['domain']) && $_POST['domain'] == '') $error .= $app->lng('error_domain_empty').'<br />'; |
T |
114 |
if(isset($_POST['ip']) && $_POST['ip'] == '') $error .= $app->lng('error_ip_empty').'<br />'; |
|
115 |
if(isset($_POST['ns1']) && $_POST['ns1'] == '') $error .= $app->lng('error_ns1_empty').'<br />'; |
|
116 |
if(isset($_POST['ns2']) && $_POST['ns2'] == '') $error .= $app->lng('error_ns2_empty').'<br />'; |
|
117 |
if(isset($_POST['email']) && $_POST['email'] == '') $error .= $app->lng('error_email_empty').'<br />'; |
68e917
|
118 |
|
T |
119 |
|
|
120 |
// replace template placeholders |
|
121 |
$tpl_content = $template_record['template']; |
|
122 |
if($_POST['domain'] != '') $tpl_content = str_replace('{DOMAIN}',$_POST['domain'],$tpl_content); |
|
123 |
if($_POST['ip'] != '') $tpl_content = str_replace('{IP}',$_POST['ip'],$tpl_content); |
|
124 |
if($_POST['ns1'] != '') $tpl_content = str_replace('{NS1}',$_POST['ns1'],$tpl_content); |
|
125 |
if($_POST['ns2'] != '') $tpl_content = str_replace('{NS2}',$_POST['ns2'],$tpl_content); |
|
126 |
if($_POST['email'] != '') $tpl_content = str_replace('{EMAIL}',$_POST['email'],$tpl_content); |
|
127 |
|
|
128 |
// Parse the template |
|
129 |
$tpl_rows = explode("\n",$tpl_content); |
|
130 |
$section = ''; |
|
131 |
$vars = array(); |
|
132 |
$dns_rr = array(); |
|
133 |
foreach($tpl_rows as $row) { |
|
134 |
$row = trim($row); |
|
135 |
if(substr($row,0,1) == '[') { |
|
136 |
if($row == '[ZONE]') { |
|
137 |
$section = 'zone'; |
|
138 |
} elseif($row == '[DNS_RECORDS]') { |
|
139 |
$section = 'dns_records'; |
|
140 |
} else { |
|
141 |
die('Unknown section type'); |
|
142 |
} |
|
143 |
} else { |
|
144 |
if($row != '') { |
|
145 |
// Handle zone section |
|
146 |
if($section == 'zone') { |
|
147 |
$parts = explode('=',$row); |
|
148 |
$key = trim($parts[0]); |
|
149 |
$val = trim($parts[1]); |
|
150 |
if($key != '') $vars[$key] = $val; |
|
151 |
} |
|
152 |
// Handle DNS Record rows |
|
153 |
if($section == 'dns_records') { |
|
154 |
$parts = explode('|',$row); |
|
155 |
$dns_rr[] = array( |
|
156 |
'name' => $app->db->quote($parts[1]), |
|
157 |
'type' => $app->db->quote($parts[0]), |
|
158 |
'data' => $app->db->quote($parts[2]), |
|
159 |
'aux' => $app->db->quote($parts[3]), |
|
160 |
'ttl' => $app->db->quote($parts[4]) |
|
161 |
); |
|
162 |
} |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
} // end foreach |
|
167 |
|
949e7e
|
168 |
if($vars['origin'] == '') $error .= $app->lng('error_origin_empty').'<br />'; |
T |
169 |
if($vars['ns'] == '') $error .= $app->lng('error_ns_empty').'<br />'; |
|
170 |
if($vars['mbox'] == '') $error .= $app->lng('error_mbox_empty').'<br />'; |
|
171 |
if($vars['refresh'] == '') $error .= $app->lng('error_refresh_empty').'<br />'; |
|
172 |
if($vars['retry'] == '') $error .= $app->lng('error_retry_empty').'<br />'; |
|
173 |
if($vars['expire'] == '') $error .= $app->lng('error_expire_empty').'<br />'; |
|
174 |
if($vars['minimum'] == '') $error .= $app->lng('error_minimum_empty').'<br />'; |
|
175 |
if($vars['ttl'] == '') $error .= $app->lng('error_ttl_empty').'<br />'; |
68e917
|
176 |
|
T |
177 |
if($error == '') { |
|
178 |
// Insert the soa record |
|
179 |
$sys_userid = $_SESSION['s']['user']['userid']; |
|
180 |
$origin = $app->db->quote($vars['origin']); |
|
181 |
$ns = $app->db->quote($vars['ns']); |
|
182 |
$mbox = $app->db->quote(str_replace('@','.',$vars['mbox'])); |
|
183 |
$refresh = $app->db->quote($vars['refresh']); |
|
184 |
$retry = $app->db->quote($vars['retry']); |
|
185 |
$expire = $app->db->quote($vars['expire']); |
|
186 |
$minimum = $app->db->quote($vars['minimum']); |
|
187 |
$ttl = $app->db->quote($vars['ttl']); |
|
188 |
$xfer = $app->db->quote($vars['xfer']); |
|
189 |
$serial = $app->validate_dns->increase_serial(0); |
|
190 |
|
|
191 |
$insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `origin`, `ns`, `mbox`, `serial`, `refresh`, `retry`, `expire`, `minimum`, `ttl`, `active`, `xfer`) VALUES |
|
192 |
('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$origin', '$ns', '$mbox', '$serial', '$refresh', '$retry', '$expire', '$minimum', '$ttl', 'Y', '$xfer')"; |
|
193 |
$dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id'); |
|
194 |
|
|
195 |
// Insert the dns_rr records |
|
196 |
if(is_array($dns_rr) && $dns_soa_id > 0) { |
|
197 |
foreach($dns_rr as $rr) { |
|
198 |
$insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `zone`, `name`, `type`, `data`, `aux`, `ttl`, `active`) VALUES |
|
199 |
('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$dns_soa_id', '$rr[name]', '$rr[type]', '$rr[data]', '$rr[aux]', '$rr[ttl]', 'Y')"; |
|
200 |
$dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id'); |
|
201 |
} |
|
202 |
} |
|
203 |
|
|
204 |
header("Location: dns_soa_list.php"); |
|
205 |
exit; |
|
206 |
|
|
207 |
} else { |
|
208 |
$app->tpl->setVar("error",$error); |
|
209 |
} |
|
210 |
|
|
211 |
} |
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
$app->tpl->setVar("title",'DNS Wizard'); |
|
216 |
|
|
217 |
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dns_wizard.lng'; |
|
218 |
include($lng_file); |
|
219 |
$app->tpl->setVar($wb); |
|
220 |
|
|
221 |
$app->tpl_defaults(); |
|
222 |
$app->tpl->pparse(); |
|
223 |
|
|
224 |
|
13d323
|
225 |
?> |