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) { |
|
92 |
$soa = $exdb->queryOneRecord("SELECT * FROM records WHERE type = 'SOA' AND domain_id = ".$domain['id']); |
|
93 |
if(is_array($soa)) { |
7fe908
|
94 |
$parts = explode(' ', $soa['content']); |
604c0c
|
95 |
$origin = $app->db->quote(addot($soa['name'])); |
TB |
96 |
$ns = $app->db->quote(addot($parts[0])); |
|
97 |
$mbox = $app->db->quote(addot($parts[1])); |
|
98 |
$serial = $app->db->quote($parts[2]); |
e94a9f
|
99 |
$refresh = 7200; |
T |
100 |
$retry = 540; |
|
101 |
$expire = 604800; |
|
102 |
$minimum = 86400; |
604c0c
|
103 |
$ttl = $app->db->quote($soa['ttl']); |
7fe908
|
104 |
|
e94a9f
|
105 |
$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 |
T |
106 |
('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$origin', '$ns', '$mbox', '$serial', '$refresh', '$retry', '$expire', '$minimum', '$ttl', 'Y', '')"; |
|
107 |
$dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id'); |
|
108 |
unset($parts); |
|
109 |
$msg .= 'Import Zone: '.$soa['name'].'<br />'; |
7fe908
|
110 |
|
e94a9f
|
111 |
//* Process the other records |
T |
112 |
$records = $exdb->queryAllRecords("SELECT * FROM records WHERE type != 'SOA' AND domain_id = ".$domain['id']); |
|
113 |
if(is_array($records)) { |
|
114 |
foreach($records as $rec) { |
|
115 |
$rr = array(); |
7fe908
|
116 |
|
604c0c
|
117 |
$rr['name'] = $app->db->quote(addot($rec['name'])); |
TB |
118 |
$rr['type'] = $app->db->quote($rec['type']); |
|
119 |
$rr['aux'] = $app->db->quote($rec['prio']); |
|
120 |
$rr['ttl'] = $app->db->quote($rec['ttl']); |
7fe908
|
121 |
|
e94a9f
|
122 |
if($rec['type'] == 'NS' || $rec['type'] == 'MX' || $rec['type'] == 'CNAME') { |
604c0c
|
123 |
$rr['data'] = $app->db->quote(addot($rec['content'])); |
e94a9f
|
124 |
} else { |
604c0c
|
125 |
$rr['data'] = $app->db->quote($rec['content']); |
e94a9f
|
126 |
} |
7fe908
|
127 |
|
e94a9f
|
128 |
$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 |
T |
129 |
('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$dns_soa_id', '$rr[name]', '$rr[type]', '$rr[data]', '$rr[aux]', '$rr[ttl]', 'Y')"; |
|
130 |
$dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id'); |
|
131 |
//$msg .= $insert_data.'<br />'; |
7fe908
|
132 |
|
e94a9f
|
133 |
} |
T |
134 |
} |
|
135 |
} |
7fe908
|
136 |
|
e94a9f
|
137 |
} |
T |
138 |
} |
7fe908
|
139 |
|
MC |
140 |
|
|
141 |
|
e94a9f
|
142 |
} else { |
T |
143 |
$error .= $exdb->errorMessage; |
|
144 |
} |
7fe908
|
145 |
|
e94a9f
|
146 |
//* restore db login details |
5e5755
|
147 |
/*$conf['db_host'] = $conf_bak['db_host']; |
e94a9f
|
148 |
$conf['db_database'] = $conf_bak['db_database']; |
T |
149 |
$conf['db_user'] = $conf_bak['db_user']; |
5e5755
|
150 |
$conf['db_password'] = $conf_bak['db_password'];*/ |
7fe908
|
151 |
|
e94a9f
|
152 |
} |
T |
153 |
|
7fe908
|
154 |
$app->tpl->setVar('msg', $msg); |
MC |
155 |
$app->tpl->setVar('error', $error); |
e94a9f
|
156 |
|
5af0cf
|
157 |
//* SET csrf token |
TB |
158 |
$csrf_token = $app->auth->csrf_token_get('dns_import'); |
|
159 |
$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); |
|
160 |
$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); |
e94a9f
|
161 |
|
T |
162 |
$app->tpl_defaults(); |
|
163 |
$app->tpl->pparse(); |
|
164 |
|
|
165 |
|
7fe908
|
166 |
?> |