commit | author | age
|
e94a9f
|
1 |
<?php |
T |
2 |
/* |
|
3 |
Copyright (c) 2008, 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 |
|
7fe908
|
30 |
require_once '../../lib/config.inc.php'; |
MC |
31 |
require_once '../../lib/app.inc.php'; |
e94a9f
|
32 |
|
T |
33 |
//* Check permissions for module |
|
34 |
$app->auth->check_module_permissions('admin'); |
|
35 |
|
|
36 |
//* This is only allowed for administrators |
|
37 |
if(!$app->auth->is_admin()) die('only allowed for administrators.'); |
|
38 |
|
|
39 |
$app->uses('tpl,validate_dns'); |
|
40 |
|
|
41 |
$app->tpl->newTemplate('form.tpl.htm'); |
|
42 |
$app->tpl->setInclude('content_tpl', 'templates/dns_import_tupa.htm'); |
|
43 |
$msg = ''; |
|
44 |
$error = ''; |
|
45 |
|
|
46 |
// Resyncing dns zones |
|
47 |
if(isset($_POST['start']) && $_POST['start'] == 1) { |
5af0cf
|
48 |
|
TB |
49 |
//* CSRF Check |
|
50 |
$app->auth->csrf_token_check(); |
7fe908
|
51 |
|
e94a9f
|
52 |
//* Set variable sin template |
7fe908
|
53 |
$app->tpl->setVar('dbhost', $_POST['dbhost']); |
MC |
54 |
$app->tpl->setVar('dbname', $_POST['dbname']); |
|
55 |
$app->tpl->setVar('dbuser', $_POST['dbuser']); |
|
56 |
$app->tpl->setVar('dbpassword', $_POST['dbpassword']); |
|
57 |
|
e94a9f
|
58 |
//* Establish connection to external database |
T |
59 |
$msg .= 'Connecting to external database...<br />'; |
7fe908
|
60 |
|
e94a9f
|
61 |
//* Backup DB login details |
5e5755
|
62 |
/*$conf_bak['db_host'] = $conf['db_host']; |
e94a9f
|
63 |
$conf_bak['db_database'] = $conf['db_database']; |
T |
64 |
$conf_bak['db_user'] = $conf['db_user']; |
5e5755
|
65 |
$conf_bak['db_password'] = $conf['db_password'];*/ |
7fe908
|
66 |
|
e94a9f
|
67 |
//* Set external Login details |
5e5755
|
68 |
$conf['imp_db_host'] = $_POST['dbhost']; |
M |
69 |
$conf['imp_db_database'] = $_POST['dbname']; |
|
70 |
$conf['imp_db_user'] = $_POST['dbuser']; |
|
71 |
$conf['imp_db_password'] = $_POST['dbpassword']; |
7fe908
|
72 |
$conf['imp_db_charset'] = $conf['db_charset']; |
MC |
73 |
$conf['imp_db_new_link'] = $conf['db_new_link']; |
|
74 |
$conf['imp_db_client_flags'] = $conf['db_client_flags']; |
|
75 |
|
e94a9f
|
76 |
//* create new db object |
5e5755
|
77 |
$exdb = new db('imp'); |
7fe908
|
78 |
|
e94a9f
|
79 |
$server_id = 1; |
T |
80 |
$sys_userid = 1; |
|
81 |
$sys_groupid = 1; |
7fe908
|
82 |
|
e94a9f
|
83 |
function addot($text) { |
T |
84 |
return trim($text) . '.'; |
|
85 |
} |
7fe908
|
86 |
|
e94a9f
|
87 |
//* Connect to DB |
562ed3
|
88 |
if($exdb !== false) { |
e94a9f
|
89 |
$domains = $exdb->queryAllRecords("SELECT * FROM domains WHERE type = 'MASTER'"); |
T |
90 |
if(is_array($domains)) { |
|
91 |
foreach($domains as $domain) { |
cc7a82
|
92 |
$soa = $exdb->queryOneRecord("SELECT * FROM records WHERE type = 'SOA' AND domain_id = ?", $domain['id']); |
e94a9f
|
93 |
if(is_array($soa)) { |
7fe908
|
94 |
$parts = explode(' ', $soa['content']); |
3a11d2
|
95 |
$origin = addot($soa['name']); |
MC |
96 |
$ns = addot($parts[0]); |
|
97 |
$mbox = addot($parts[1]); |
|
98 |
$serial = $parts[2]; |
e94a9f
|
99 |
$refresh = 7200; |
T |
100 |
$retry = 540; |
|
101 |
$expire = 604800; |
b41803
|
102 |
$minimum = 3600; |
3a11d2
|
103 |
$ttl = $soa['ttl']; |
7fe908
|
104 |
|
3a11d2
|
105 |
$insert_data = array( |
MC |
106 |
"sys_userid" => $sys_userid, |
|
107 |
"sys_groupid" => $sys_groupid, |
|
108 |
"sys_perm_user" => 'riud', |
|
109 |
"sys_perm_group" => 'riud', |
|
110 |
"sys_perm_other" => '', |
|
111 |
"server_id" => $server_id, |
|
112 |
"origin" => $origin, |
|
113 |
"ns" => $ns, |
|
114 |
"mbox" => $mbox, |
|
115 |
"serial" => $serial, |
|
116 |
"refresh" => $refresh, |
|
117 |
"retry" => $retry, |
|
118 |
"expire" => $expire, |
|
119 |
"minimum" => $minimum, |
|
120 |
"ttl" => $ttl, |
|
121 |
"active" => 'Y', |
|
122 |
"xfer" => '' |
|
123 |
); |
e94a9f
|
124 |
$dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id'); |
T |
125 |
unset($parts); |
|
126 |
$msg .= 'Import Zone: '.$soa['name'].'<br />'; |
7fe908
|
127 |
|
e94a9f
|
128 |
//* Process the other records |
cc7a82
|
129 |
$records = $exdb->queryAllRecords("SELECT * FROM records WHERE type != 'SOA' AND domain_id = ?", $domain['id']); |
e94a9f
|
130 |
if(is_array($records)) { |
T |
131 |
foreach($records as $rec) { |
|
132 |
$rr = array(); |
7fe908
|
133 |
|
3a11d2
|
134 |
$rr['name'] = addot($rec['name']); |
MC |
135 |
$rr['type'] = $rec['type']; |
|
136 |
$rr['aux'] = $rec['prio']; |
|
137 |
$rr['ttl'] = $rec['ttl']; |
7fe908
|
138 |
|
e94a9f
|
139 |
if($rec['type'] == 'NS' || $rec['type'] == 'MX' || $rec['type'] == 'CNAME') { |
3a11d2
|
140 |
$rr['data'] = addot($rec['content']); |
e94a9f
|
141 |
} else { |
3a11d2
|
142 |
$rr['data'] = $rec['content']; |
e94a9f
|
143 |
} |
7fe908
|
144 |
|
3a11d2
|
145 |
$insert_data = array( |
MC |
146 |
"sys_userid" => $sys_userid, |
|
147 |
"sys_groupid" => $sys_groupid, |
|
148 |
"sys_perm_user" => 'riud', |
|
149 |
"sys_perm_group" => 'riud', |
|
150 |
"sys_perm_other" => '', |
|
151 |
"server_id" => $server_id, |
|
152 |
"zone" => $dns_soa_id, |
|
153 |
"name" => $rr['name'], |
|
154 |
"type" => $rr['type'], |
|
155 |
"data" => $rr['data'], |
|
156 |
"aux" => $rr['aux'], |
|
157 |
"ttl" => $rr['ttl'], |
|
158 |
"active" => 'Y' |
|
159 |
); |
e94a9f
|
160 |
$dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id'); |
T |
161 |
//$msg .= $insert_data.'<br />'; |
7fe908
|
162 |
|
e94a9f
|
163 |
} |
T |
164 |
} |
|
165 |
} |
7fe908
|
166 |
|
e94a9f
|
167 |
} |
T |
168 |
} |
7fe908
|
169 |
|
MC |
170 |
|
|
171 |
|
e94a9f
|
172 |
} else { |
T |
173 |
$error .= $exdb->errorMessage; |
|
174 |
} |
7fe908
|
175 |
|
e94a9f
|
176 |
//* restore db login details |
5e5755
|
177 |
/*$conf['db_host'] = $conf_bak['db_host']; |
e94a9f
|
178 |
$conf['db_database'] = $conf_bak['db_database']; |
T |
179 |
$conf['db_user'] = $conf_bak['db_user']; |
5e5755
|
180 |
$conf['db_password'] = $conf_bak['db_password'];*/ |
7fe908
|
181 |
|
e94a9f
|
182 |
} |
T |
183 |
|
7fe908
|
184 |
$app->tpl->setVar('msg', $msg); |
MC |
185 |
$app->tpl->setVar('error', $error); |
e94a9f
|
186 |
|
5af0cf
|
187 |
//* SET csrf token |
TB |
188 |
$csrf_token = $app->auth->csrf_token_get('dns_import'); |
|
189 |
$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); |
|
190 |
$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); |
e94a9f
|
191 |
|
T |
192 |
$app->tpl_defaults(); |
|
193 |
$app->tpl->pparse(); |
|
194 |
|
|
195 |
|
7fe908
|
196 |
?> |