Skip to content

Commit fc70a2c

Browse files
committed
Added debugging to bind plugin and fixed a few bugs.
1 parent 7dbea06 commit fc70a2c

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<tmpl_loop name='zones'>
3-
zone "<tmpl_var name='origin'>" {
3+
zone "<tmpl_var name='zone'>" {
44
type master;
5-
file "pri.<tmpl_var name='origin'>";
5+
file "<tmpl_var name='zonefile_path'>";
66
};
77
</tmpl_loop>

server/conf/bind_pri.domain.master

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$TTL {tmpl_var name='ttl'}
2-
@ IN SOA {tmpl_var name='ns'} {tmpl_var name='mbox'}. (
2+
@ IN SOA {tmpl_var name='ns'} {tmpl_var name='mbox'} (
33
{tmpl_var name='serial'} ; serial, todays date + todays serial #
44
{tmpl_var name='refresh'} ; refresh, seconds
55
{tmpl_var name='retry'} ; retry, seconds
@@ -32,9 +32,6 @@ $TTL {tmpl_var name='ttl'}
3232
<tmpl_if name="type" op='==' value='NAPTR'>
3333
{tmpl_var name='name'} NAPTR {tmpl_var name='data'}
3434
</tmpl_if>
35-
<tmpl_if name="type" op='==' value='NS'>
36-
{tmpl_var name='name'} NS {tmpl_var name='data'}
37-
</tmpl_if>
3835
<tmpl_if name="type" op='==' value='PTR'>
3936
{tmpl_var name='name'} PTR {tmpl_var name='data'}
4037
</tmpl_if>

server/plugins-available/bind_plugin.inc.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ function soa_insert($event_name,$data) {
8383
function soa_update($event_name,$data) {
8484
global $app, $conf;
8585

86+
//* Load libraries
87+
$app->uses("getconf,tpl");
88+
8689
//* load the server configuration options
87-
$app->uses("getconf");
8890
$dns_config = $app->getconf->get_server_config($conf["server_id"], 'dns');
8991

9092
//* Write the domain file
@@ -94,24 +96,25 @@ function soa_update($event_name,$data) {
9496
$zone = $data['new'];
9597
$tpl->setVar($zone);
9698

97-
$records = $app->db->queryAllRecords("SELECT * FROM dns_rr WHERE zone = ".$zone['id']);
98-
$tpl->setLoop('records',$records);
99+
$records = $app->db->queryAllRecords("SELECT * FROM dns_rr WHERE zone = ".$zone['id']." AND active = 'Y'");
100+
$tpl->setLoop('zones',$records);
99101

100-
$filename = escapeshellcmd($dns_config['bind_zonefiles_dir'].'/pri.'.$zone['origin']);
102+
$filename = escapeshellcmd($dns_config['bind_zonefiles_dir'].'/pri.'.substr($zone['origin'],0,-1));
103+
$app->log("Writing BIND domain file: ".$filename,LOGLEVEL_DEBUG);
101104
file_put_contents($filename,$tpl->grab());
102105
exec('chown '.escapeshellcmd($dns_config['bind_user']).':'.escapeshellcmd($dns_config['bind_group']).' '.$filename);
103106
unset($tpl);
104107
unset($records);
105108
unset($zone);
106109

107110
//* rebuild the named.conf file if the origin has changed or when the origin is inserted.
108-
if($this->action == 'insert' || $data['old']['origin'] != $data['new']['origin']) {
111+
//if($this->action == 'insert' || $data['old']['origin'] != $data['new']['origin']) {
109112
$this->write_named_conf($data,$dns_config);
110-
}
113+
//}
111114

112115
//* Delete old domain file, if domain name has been changed
113116
if($data['old']['origin'] != $data['new']['origin']) {
114-
$filename = $dns_config['bind_zonefiles_dir'].'/pri.'.$data['old']['origin'];
117+
$filename = $dns_config['bind_zonefiles_dir'].'/pri.'.substr($data['old']['origin'],0,-1);
115118
if(is_file($filename)) unset($filename);
116119
}
117120

@@ -133,6 +136,7 @@ function soa_delete($event_name,$data) {
133136
//* Delete the domain file
134137
$filename = $dns_config['bind_zonefiles_dir'].'/pri.'.$data['old']['origin'];
135138
if(is_file($filename)) unset($filename);
139+
$app->log("Deleting BIND domain file: ".$filename,LOGLEVEL_DEBUG);
136140

137141
//* Reload bind nameserver
138142
$app->services->restartServiceDelayed('bind','reload');
@@ -180,14 +184,24 @@ function rr_delete($event_name,$data) {
180184
function write_named_conf($data, $dns_config) {
181185
global $app, $conf;
182186

183-
$zones = $app->db->queryAllRecords("SELECT origin FROM dns_soa WHERE active = 'Y'");
187+
$tmps = $app->db->queryAllRecords("SELECT origin FROM dns_soa WHERE active = 'Y'");
188+
$zones = array();
189+
foreach($tmps as $tmp) {
190+
$zones[] = array( 'zone' => substr($tmp['origin'],0,-1),
191+
'zonefile_path' => $dns_config['bind_zonefiles_dir'].'/pri.'.substr($tmp['origin'],0,-1)
192+
);
193+
}
184194

185195
$tpl = new tpl();
186196
$tpl->newTemplate("bind_named.conf.local.master");
187197
$tpl->setLoop('zones',$zones);
188198

189199
file_put_contents($dns_config['named_conf_local_path'],$tpl->grab());
200+
$app->log("Writing BIND named.conf.local file: ".$dns_config['named_conf_local_path'],LOGLEVEL_DEBUG);
201+
190202
unset($tpl);
203+
unset($zones);
204+
unset($tmps);
191205

192206
}
193207

0 commit comments

Comments
 (0)