Commit d459ec8f authored by A. Täffner's avatar A. Täffner

Zone-Checking improved

Implements a colored background if bind fails to load the zone due to errors
Implements a status text if errors occured
Implements not removing a zone if errors occur. instead old zone stays loaded
parent b203f3ee
......@@ -80,6 +80,20 @@ $form["tabs"]['dns_soa'] = array (
'width' => '30',
'maxlength' => '255'
),
'status' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'default' => 'PENDING',
'value' => 'PENDING'
),
'status_txt' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXTAREA',
'default' => '',
'value' => '',
'width' => '30',
'maxlength' => '10000'
),
'origin' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
......
......@@ -61,7 +61,27 @@ $liste["item"][] = array( 'field' => "active",
'width' => "",
'value' => array('Y' => "<div id=\"ir-Yes\" class=\"swap\"><span>".$app->lng('yes_txt')."</span></div>", 'N' => "<div class=\"swap\" id=\"ir-No\"><span>".$app->lng('no_txt')."</span></div>"));
$liste["item"][] = array( 'field' => "status",
'datatype' => "VARCHAR",
'formtype' => "SELECT",
'op' => "=",
'prefix' => "",
'suffix' => "",
'width' => "",
'value' => array('OK' => '', 'ERROR' => 'background-color:red', 'PENDING' => 'background-color:yellow'));
$liste["item"][] = array( 'field' => "status_txt",
'datatype' => "VARCHAR",
'formtype' => "SELECT",
'op' => "=",
'prefix' => "",
'suffix' => "",
'width' => "",
'value' => '');
$liste["item"][] = array( 'field' => "server_id",
'datatype' => "VARCHAR",
'formtype' => "SELECT",
......
......@@ -57,7 +57,7 @@
<tbody>
<tmpl_loop name="records">
<tr>
<td><a href="#" data-load-content="dns/dns_soa_edit.php?id={tmpl_var name='id'}">{tmpl_var name="active"}</td>
<td style="{tmpl_var name="status"}"><a href="#" data-load-content="dns/dns_soa_edit.php?id={tmpl_var name='id'}">{tmpl_var name="active"}</td>
<td><a href="#" data-load-content="dns/dns_soa_edit.php?id={tmpl_var name='id'}">{tmpl_var name="sys_groupid"}</a></td>
<td><a href="#" data-load-content="dns/dns_soa_edit.php?id={tmpl_var name='id'}">{tmpl_var name="server_id"}</a></td>
<td><a href="#" data-load-content="dns/dns_soa_edit.php?id={tmpl_var name='id'}">{tmpl_var name="origin"}</a></td>
......
......@@ -5,6 +5,11 @@
<legend>DNS Zone</legend>
<tmpl_if name="status_txt">
<div class="alert alert-danger clear">
<div style="white-space: pre;" class="alert-content"><tmpl_var name="status_txt"></div>
</div>
</tmpl_if>
<tmpl_if name="is_admin">
<div class="form-group">
<tmpl_if name="edit_disabled">
......@@ -137,6 +142,7 @@
</div>
<input type="hidden" name="id" value="{tmpl_var name='id'}">
<input type="hidden" name="status" value="PENDING">
<input name="serial" type="hidden" value="{tmpl_var name='serial'}">
<div class="clear"><div class="right">
......
......@@ -55,7 +55,7 @@
<tbody>
<tmpl_loop name="records">
<tr>
<td><a href="#" data-load-content="dns/dns_soa_edit.php?id={tmpl_var name='id'}">{tmpl_var name="active"}</td>
<td style="{tmpl_var name="status"}"><a href="#" title="{tmpl_var name="status_txt"}" data-load-content="dns/dns_soa_edit.php?id={tmpl_var name='id'}">{tmpl_var name="active"}</td>
<td><a href="#" data-load-content="dns/dns_soa_edit.php?id={tmpl_var name='id'}">{tmpl_var name="server_id"}</a></td>
<td><a href="#" data-load-content="dns/dns_soa_edit.php?id={tmpl_var name='id'}">{tmpl_var name="origin"}</a></td>
<td><a href="#" data-load-content="dns/dns_soa_edit.php?id={tmpl_var name='id'}">{tmpl_var name="ns"}</a></td>
......
......@@ -261,22 +261,28 @@ class bind_plugin {
$filename = escapeshellcmd($dns_config['bind_zonefiles_dir'].'/pri.'.str_replace("/", "_", substr($zone['origin'], 0, -1)));
}
file_put_contents($filename, $tpl->grab());
file_put_contents($filename.'.pending', $tpl->grab());
chown($filename, escapeshellcmd($dns_config['bind_user']));
chgrp($filename, escapeshellcmd($dns_config['bind_group']));
//* Check the zonefile
if(is_file($filename.'.err')) unlink($filename.'.err');
exec('named-checkzone '.escapeshellarg($zone['origin']).' '.escapeshellarg($filename), $out, $return_status);
$out=array();
exec('/usr/sbin/named-checkzone '.escapeshellarg($zone['origin']).' '.escapeshellarg($filename.'.pending').' 2>&1', $out, $return_status);
$statustext='';
foreach ($out as $line) $statustext .= $line."\n";
if($return_status === 0) {
$app->log("Writing BIND domain file: ".$filename, LOGLEVEL_DEBUG);
$app->db->query('UPDATE dns_soa SET status=\'OK\', status_txt=\'\' WHERE id='.$data['new']['id']);
rename($filename.'.pending', $filename);
} else {
if($dns_config['disable_bind_log'] === 'y') {
$app->log("Writing BIND domain file failed: ".$filename." ".implode(' ', $out), LOGLEVEL_DEBUG);
} else {
$app->log("Writing BIND domain file failed: ".$filename." ".implode(' ', $out), LOGLEVEL_WARN);
}
rename($filename, $filename.'.err');
$app->db->query('UPDATE dns_soa SET status=\'ERROR\', status_txt=\''.str_replace(array('"', '\''), '', $statustext).'\' WHERE id='.$data['new']['id']);
rename($filename.'.pending', $filename.'.err');
}
unset($tpl);
unset($records);
......@@ -319,9 +325,9 @@ class bind_plugin {
if(is_file($filename)) unlink($filename);
if(is_file($filename.'.err')) unlink($filename.'.err');
if(is_file($filename.'.pending')) unlink($filename.'.pending');
if(is_file($filename.'.signed')) unlink($filename.'.signed');
}
//* Restart bind nameserver if update_acl is not empty, otherwise reload it
if($data['new']['update_acl'] != '') {
$app->services->restartServiceDelayed('bind', 'restart');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment