auth->check_module_permissions('dns');
// Loading the template
$app->uses('tpl,validate_dns');
$app->tpl->newTemplate("form.tpl.htm");
$app->tpl->setInclude('content_tpl','templates/dns_import.htm');
$app->load_language_file('/web/dns/lib/lang/'.$_SESSION['s']['language'].'_dns_wizard.lng');
// import variables
$template_id = (isset($_POST['template_id']))?intval($_POST['template_id']):0;
$sys_groupid = (isset($_POST['client_group_id']))?intval($_POST['client_group_id']):0;
$domain = (isset($_POST['domain'])&&!empty($_POST['domain']))?$_POST['domain']:NULL;
// get the correct server_id
if($_SESSION['s']['user']['typ'] == 'admin') {
$server_id = (isset($_POST['server_id']))?intval($_POST['server_id']):1;
} else {
$client_group_id = $_SESSION["s"]["user"]["default_group"];
$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");
$server_id = $client["default_dnsserver"];
}
// Load the templates
$records = $app->db->queryAllRecords("SELECT * FROM dns_template WHERE visible = 'Y'");
$template_id_option = '';
$n = 0;
foreach($records as $rec){
$checked = ($rec['template_id'] == $template_id)?' SELECTED':'';
$template_id_option .= '';
if($n == 0 && $template_id == 0) $template_id = $rec['template_id'];
$n++;
}
unset($n);
$app->tpl->setVar("template_id_option",$template_id_option);
// If the user is administrator
if($_SESSION['s']['user']['typ'] == 'admin') {
// Load the list of servers
$records = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE mirror_server_id = 0 AND dns_server = 1 ORDER BY server_name");
$server_id_option = '';
foreach($records as $rec){
$checked = ($rec['server_id'] == $server_id)?' SELECTED':'';
$server_id_option .= '';
}
$app->tpl->setVar("server_id",$server_id_option);
// load the list of clients
$sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0 ORDER BY name";
$clients = $app->db->queryAllRecords($sql);
$client_select = '';
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "";
if(is_array($clients)) {
foreach( $clients as $client) {
$selected = ($client["groupid"] == $sys_groupid)?'SELECTED':'';
$client_select .= "\r\n";
}
}
$app->tpl->setVar("client_group_id",$client_select);
}
if ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
// Get the limits of the client
$client_group_id = $_SESSION["s"]["user"]["default_group"];
$client = $app->db->queryOneRecord("SELECT client.client_id, contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
// load the list of clients
$sql = "SELECT groupid, name FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ".$client['client_id'];
$clients = $app->db->queryAllRecords($sql);
$tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$client['client_id']);
$client_select = '';
if(is_array($clients)) {
foreach( $clients as $client) {
$selected = ($client["groupid"] == $sys_groupid)?'SELECTED':'';
$client_select .= "\r\n";
}
}
$app->tpl->setVar("client_group_id",$client_select);
}
// Import the zone-file
//if(1=="1")
if(isset($_FILES['file']['name']) && is_uploaded_file($_FILES['file']['tmp_name']))
{
$sql = "SELECT server_name FROM `server` WHERE server_id=".intval($server_id)." OR mirror_server_id=".intval($server_id)." ORDER BY server_name ASC";
$servers = $app->db->queryAllRecords($sql);
for ($i=0;$i 1)
{
$s++;
$line = str_replace("\t",NULL,$line);
if (!empty($line))
{
print(strpos(";",$line));
$line = substr($line,0,strpos($line,";"));
if ($s == 1)
$soa['serial'] = $line;
else if ($s == 2)
$soa['refresh'] = $line;
else if ($s == 3)
$soa['retry'] = $line;
else if ($s == 4)
$soa['expire'] = $line;
else if ($s == 5)
$soa['ttl'] = $line;
}
}
else
{
$line = str_replace("\t",",",$line);
$recs = explode(",",$line);
foreach ($recs as $key => $rec)
{
$rec = trim($rec);
//name type data aux ttl active
if ($key == 0)
{
if ($rec == '@' || $rec == "")
{
$rec = $name;
}
$soa['name'] = $rec;
}
if ($key != 0 && strtolower($rec) == 'soa')
{
$typekeys[$s] = $key;
}
else if ($key > $typekey[$r])
{
if ($rec != ""&&$rec != "(")
{
$rec = explode(" ",$rec);
$soa['ns'] = $servers[0]['server_name'];
$soa['mbox'] = $rec[1];
}
}
}
}
}
else
{
$line = str_replace("\n","",trim($line));
if (!empty($line))
{
preg_match_all('/(.*?)\s*IN\s*(A|CNAME|MX|TXT|NS|AAAA)\s*(.*)/',$line, $recs);
if ($recs[1][0] == '@' || trim($recs[1][0]) == "")
{
$recs[1][0] = $name;
}
$dns_rr[$r]['name'] = $recs[1][0];
$dns_rr[$r]['type'] = $recs[2][0];
if (strtolower($dns_rr[$r]['type'])=='mx')
{
$recs[3][0] = str_replace(" ","\t",$recs[3][0]);
$mx[$r] = explode("\t",$recs[3][0]);
for ($m=1;$m');
print_r($dns_rr);
print('');
// Insert the soa record
$sys_userid = $_SESSION['s']['user']['userid'];
$origin = $app->db->quote($soa['name']);
$ns = $app->db->quote($soa['ns']);
$mbox = $app->db->quote($soa['mbox']);
$refresh = $app->db->quote($soa['refresh']);
$retry = $app->db->quote($soa['retry']);
$expire = $app->db->quote($soa['expire']);
$minimum = $app->db->quote($soa['ttl']);
$ttl = $app->db->quote($soa['ttl']);
$xfer = $app->db->quote('');
$serial = $app->db->quote(intval($soa['serial'])+1);
$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', '$xfer')";
$dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');
// Insert the dns_rr records
if(is_array($dns_rr) && $dns_soa_id > 0)
{
foreach($dns_rr as $rr)
{
$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');
}
}
header('Location: /dns/dns_soa_edit.php?id='.$dns_soa_id);
}
$app->tpl->setVar('msg',$msg);
$app->tpl->setVar('error',$error);
$app->tpl->setVar("title",'Import Zone Files');
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dns_wizard.lng';
include($lng_file);
$app->tpl->setVar($wb);
$app->tpl_defaults();
$app->tpl->pparse();
?>