Marius Cramer
2015-04-15 3a11d23a2f32a1b9b2ec43429917c000017c5eff
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) {
7fe908 48
e94a9f 49     //* Set variable sin template
7fe908 50     $app->tpl->setVar('dbhost', $_POST['dbhost']);
MC 51     $app->tpl->setVar('dbname', $_POST['dbname']);
52     $app->tpl->setVar('dbuser', $_POST['dbuser']);
53     $app->tpl->setVar('dbpassword', $_POST['dbpassword']);
54
e94a9f 55     //* Establish connection to external database
T 56     $msg .= 'Connecting to external database...<br />';
7fe908 57
e94a9f 58     //* Backup DB login details
5e5755 59     /*$conf_bak['db_host'] = $conf['db_host'];
e94a9f 60     $conf_bak['db_database'] = $conf['db_database'];
T 61     $conf_bak['db_user'] = $conf['db_user'];
5e5755 62     $conf_bak['db_password'] = $conf['db_password'];*/
7fe908 63
e94a9f 64     //* Set external Login details
5e5755 65     $conf['imp_db_host'] = $_POST['dbhost'];
M 66     $conf['imp_db_database'] = $_POST['dbname'];
67     $conf['imp_db_user'] = $_POST['dbuser'];
68     $conf['imp_db_password'] = $_POST['dbpassword'];
7fe908 69     $conf['imp_db_charset'] = $conf['db_charset'];
MC 70     $conf['imp_db_new_link'] = $conf['db_new_link'];
71     $conf['imp_db_client_flags'] = $conf['db_client_flags'];
72
e94a9f 73     //* create new db object
5e5755 74     $exdb = new db('imp');
7fe908 75
e94a9f 76     $server_id = 1;
T 77     $sys_userid = 1;
78     $sys_groupid = 1;
7fe908 79
e94a9f 80     function addot($text) {
T 81         return trim($text) . '.';
82     }
7fe908 83
e94a9f 84     //* Connect to DB
562ed3 85     if($exdb !== false) {
e94a9f 86         $domains = $exdb->queryAllRecords("SELECT * FROM domains WHERE type = 'MASTER'");
T 87         if(is_array($domains)) {
88             foreach($domains as $domain) {
cc7a82 89                 $soa = $exdb->queryOneRecord("SELECT * FROM records WHERE type = 'SOA' AND domain_id = ?", $domain['id']);
e94a9f 90                 if(is_array($soa)) {
7fe908 91                     $parts = explode(' ', $soa['content']);
3a11d2 92                     $origin = addot($soa['name']);
MC 93                     $ns = addot($parts[0]);
94                     $mbox = addot($parts[1]);
95                     $serial = $parts[2];
e94a9f 96                     $refresh = 7200;
T 97                     $retry =  540;
98                     $expire = 604800;
99                     $minimum = 86400;
3a11d2 100                     $ttl = $soa['ttl'];
7fe908 101
3a11d2 102                     $insert_data = array(
MC 103                         "sys_userid" => $sys_userid,
104                         "sys_groupid" => $sys_groupid,
105                         "sys_perm_user" => 'riud',
106                         "sys_perm_group" => 'riud',
107                         "sys_perm_other" => '',
108                         "server_id" => $server_id,
109                         "origin" => $origin,
110                         "ns" => $ns,
111                         "mbox" => $mbox,
112                         "serial" => $serial,
113                         "refresh" => $refresh,
114                         "retry" => $retry,
115                         "expire" => $expire,
116                         "minimum" => $minimum,
117                         "ttl" => $ttl,
118                         "active" => 'Y',
119                         "xfer" => ''
120                     );
e94a9f 121                     $dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');
T 122                     unset($parts);
123                     $msg .= 'Import Zone: '.$soa['name'].'<br />';
7fe908 124
e94a9f 125                     //* Process the other records
cc7a82 126                     $records = $exdb->queryAllRecords("SELECT * FROM records WHERE type != 'SOA' AND domain_id = ?", $domain['id']);
e94a9f 127                     if(is_array($records)) {
T 128                         foreach($records as $rec) {
129                             $rr = array();
7fe908 130
3a11d2 131                             $rr['name'] = addot($rec['name']);
MC 132                             $rr['type'] = $rec['type'];
133                             $rr['aux'] = $rec['prio'];
134                             $rr['ttl'] = $rec['ttl'];
7fe908 135
e94a9f 136                             if($rec['type'] == 'NS' || $rec['type'] == 'MX' || $rec['type'] == 'CNAME') {
3a11d2 137                                 $rr['data'] = addot($rec['content']);
e94a9f 138                             } else {
3a11d2 139                                 $rr['data'] = $rec['content'];
e94a9f 140                             }
7fe908 141
3a11d2 142                             $insert_data = array(
MC 143                                 "sys_userid" => $sys_userid,
144                                 "sys_groupid" => $sys_groupid,
145                                 "sys_perm_user" => 'riud',
146                                 "sys_perm_group" => 'riud',
147                                 "sys_perm_other" => '',
148                                 "server_id" => $server_id,
149                                 "zone" => $dns_soa_id,
150                                 "name" => $rr['name'],
151                                 "type" => $rr['type'],
152                                 "data" => $rr['data'],
153                                 "aux" => $rr['aux'],
154                                 "ttl" => $rr['ttl'],
155                                 "active" => 'Y'
156                             );
e94a9f 157                             $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
T 158                             //$msg .= $insert_data.'<br />';
7fe908 159
e94a9f 160                         }
T 161                     }
162                 }
7fe908 163
e94a9f 164             }
T 165         }
7fe908 166
MC 167
168
e94a9f 169     } else {
T 170         $error .= $exdb->errorMessage;
171     }
7fe908 172
e94a9f 173     //* restore db login details
5e5755 174     /*$conf['db_host'] = $conf_bak['db_host'];
e94a9f 175     $conf['db_database'] = $conf_bak['db_database'];
T 176     $conf['db_user'] = $conf_bak['db_user'];
5e5755 177     $conf['db_password'] = $conf_bak['db_password'];*/
7fe908 178
e94a9f 179 }
T 180
7fe908 181 $app->tpl->setVar('msg', $msg);
MC 182 $app->tpl->setVar('error', $error);
e94a9f 183
T 184
185 $app->tpl_defaults();
186 $app->tpl->pparse();
187
188
7fe908 189 ?>