From 3728fe9875cd266700bd5db9249ae48f08861373 Mon Sep 17 00:00:00 2001 From: tbrehm Date: Mon, 7 May 2012 15:29:12 +0000 Subject: [PATCH] Added tool to import dns records from PowerDNS tupa controlpanel. --- interface/web/tools/dns_import_tupa.php | 156 ++++++++++++++++++ interface/web/tools/lib/lang/en.lng | 2 + .../web/tools/lib/menu.d/import.menu.php | 6 +- .../web/tools/templates/dns_import_tupa.htm | 56 +++++++ 4 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 interface/web/tools/dns_import_tupa.php create mode 100644 interface/web/tools/templates/dns_import_tupa.htm diff --git a/interface/web/tools/dns_import_tupa.php b/interface/web/tools/dns_import_tupa.php new file mode 100644 index 000000000..2e2cbcb8e --- /dev/null +++ b/interface/web/tools/dns_import_tupa.php @@ -0,0 +1,156 @@ +auth->check_module_permissions('admin'); + +//* This is only allowed for administrators +if(!$app->auth->is_admin()) die('only allowed for administrators.'); + +$app->uses('tpl,validate_dns'); + +$app->tpl->newTemplate('form.tpl.htm'); +$app->tpl->setInclude('content_tpl', 'templates/dns_import_tupa.htm'); +$msg = ''; +$error = ''; + +// Resyncing dns zones +if(isset($_POST['start']) && $_POST['start'] == 1) { + + //* Set variable sin template + $app->tpl->setVar('dbhost',$_POST['dbhost']); + $app->tpl->setVar('dbname',$_POST['dbname']); + $app->tpl->setVar('dbuser',$_POST['dbuser']); + $app->tpl->setVar('dbpassword',$_POST['dbpassword']); + + //* Establish connection to external database + $msg .= 'Connecting to external database...
'; + + //* Backup DB login details + $conf_bak['db_host'] = $conf['db_host']; + $conf_bak['db_database'] = $conf['db_database']; + $conf_bak['db_user'] = $conf['db_user']; + $conf_bak['db_password'] = $conf['db_password']; + + //* Set external Login details + $conf['db_host'] = $_POST['dbhost']; + $conf['db_database'] = $_POST['dbname']; + $conf['db_user'] = $_POST['dbuser']; + $conf['db_password'] = $_POST['dbpassword']; + + //* create new db object + $exdb = new db(); + + $server_id = 1; + $sys_userid = 1; + $sys_groupid = 1; + + function addot($text) { + return trim($text) . '.'; + } + + //* Connect to DB + if($exdb->connect()) { + $domains = $exdb->queryAllRecords("SELECT * FROM domains WHERE type = 'MASTER'"); + if(is_array($domains)) { + foreach($domains as $domain) { + $soa = $exdb->queryOneRecord("SELECT * FROM records WHERE type = 'SOA' AND domain_id = ".$domain['id']); + if(is_array($soa)) { + $parts = explode(' ',$soa['content']); + $origin = addot($soa['name']); + $ns = addot($parts[0]); + $mbox = addot($parts[1]); + $serial = $parts[2]; + $refresh = 7200; + $retry = 540; + $expire = 604800; + $minimum = 86400; + $ttl = $soa['ttl']; + + $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 + ('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$origin', '$ns', '$mbox', '$serial', '$refresh', '$retry', '$expire', '$minimum', '$ttl', 'Y', '')"; + $dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id'); + unset($parts); + $msg .= 'Import Zone: '.$soa['name'].'
'; + + //* Process the other records + $records = $exdb->queryAllRecords("SELECT * FROM records WHERE type != 'SOA' AND domain_id = ".$domain['id']); + if(is_array($records)) { + foreach($records as $rec) { + $rr = array(); + + $rr['name'] = addot($rec['name']); + $rr['type'] = $rec['type']; + $rr['aux'] = $rec['prio']; + $rr['ttl'] = $rec['ttl']; + + if($rec['type'] == 'NS' || $rec['type'] == 'MX' || $rec['type'] == 'CNAME') { + $rr['data'] = addot($rec['content']); + } else { + $rr['data'] = $rec['content']; + } + + $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 + ('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$dns_soa_id', '$rr[name]', '$rr[type]', '$rr[data]', '$rr[aux]', '$rr[ttl]', 'Y')"; + $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id'); + //$msg .= $insert_data.'
'; + + } + } + } + + } + } + + + + } else { + $error .= $exdb->errorMessage; + } + + //* restore db login details + $conf['db_host'] = $conf_bak['db_host']; + $conf['db_database'] = $conf_bak['db_database']; + $conf['db_user'] = $conf_bak['db_user']; + $conf['db_password'] = $conf_bak['db_password']; + +} + +$app->tpl->setVar('msg',$msg); +$app->tpl->setVar('error',$error); + + +$app->tpl_defaults(); +$app->tpl->pparse(); + + +?> \ No newline at end of file diff --git a/interface/web/tools/lib/lang/en.lng b/interface/web/tools/lib/lang/en.lng index 597be726c..fee9301c0 100644 --- a/interface/web/tools/lib/lang/en.lng +++ b/interface/web/tools/lib/lang/en.lng @@ -7,4 +7,6 @@ $wb['ispconfig_tools_note'] = 'This module allows you to change the password and $wb['Sync Tools'] = 'Sync Tools'; $wb['Resync'] = 'Resync'; $wb['Import'] = 'Import'; +$wb['ISPConfig 3 mail'] = 'ISPConfig 3 mail'; +$wb['PDNS Tupa'] = 'PowerDNS Tupa'; ?> \ No newline at end of file diff --git a/interface/web/tools/lib/menu.d/import.menu.php b/interface/web/tools/lib/menu.d/import.menu.php index 086fd6355..cf5f9ebe3 100644 --- a/interface/web/tools/lib/menu.d/import.menu.php +++ b/interface/web/tools/lib/menu.d/import.menu.php @@ -7,11 +7,15 @@ if($app->auth->is_admin()) { $items = array(); -$items[] = array( 'title' => 'ISPConfig 3', +$items[] = array( 'title' => 'ISPConfig 3 mail', 'target' => 'content', 'link' => 'tools/import_ispconfig.php'); +$items[] = array( 'title' => 'PDNS Tupa', + 'target' => 'content', + 'link' => 'tools/dns_import_tupa.php'); + $module['nav'][] = array( 'title' => 'Import', 'open' => 1, 'items' => $items); diff --git a/interface/web/tools/templates/dns_import_tupa.htm b/interface/web/tools/templates/dns_import_tupa.htm new file mode 100644 index 000000000..d616eba4d --- /dev/null +++ b/interface/web/tools/templates/dns_import_tupa.htm @@ -0,0 +1,56 @@ +

Import DNS recods from Tupa PowerDNS controlpanel

+

+ +
+ +
+
PowerDNS Tupa import +
+

Tupa database hostname

+
+ +
+
+
+

Tupa database name

+
+ +
+
+
+

Tupa database user

+
+ +
+
+
+

Tupa database password

+
+ +
+
+ +
+

Import DNS Records

+
+ +
+
+
+ + +

+
+ +

ERROR

+
+ + + +
+ + +
+
+ +
-- GitLab