Skip to content

Commit 2a31970

Browse files
committed
Convert zone_file_prefix() and zone_file_prefix() into a config option
This preserves the default for non-gentoo systems.
1 parent 165cc8b commit 2a31970

File tree

4 files changed

+45
-27
lines changed

4 files changed

+45
-27
lines changed

install/tpl/server.ini.master

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ bind_user=root
128128
bind_group=bind
129129
bind_zonefiles_dir=/etc/bind
130130
bind_keyfiles_dir=/etc/bind
131+
bind_zonefiles_masterprefix=pri.
132+
bind_zonefiles_slaveprefix=slave/sec.
131133
named_conf_path=/etc/bind/named.conf
132134
named_conf_local_path=/etc/bind/named.conf.local
133135
disable_bind_log=n

interface/web/admin/form/server_config.tform.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,30 @@
15391539
'width' => '40',
15401540
'maxlength' => '255'
15411541
),
1542+
'bind_zonefiles_masterprefix' => array(
1543+
'datatype' => 'VARCHAR',
1544+
'formtype' => 'TEXT',
1545+
'default' => '',
1546+
'validators' => array( 0 => array ( 'type' => 'REGEX',
1547+
'regex' => '/^\/[a-zA-Z0-9\.\-\_\/]{1,128}$/',
1548+
'errmsg'=> 'bind_zonefiles_masterprefix_error_regex'),
1549+
),
1550+
'value' => '',
1551+
'width' => '40',
1552+
'maxlength' => '255'
1553+
),
1554+
'bind_zonefiles_slaveprefix' => array(
1555+
'datatype' => 'VARCHAR',
1556+
'formtype' => 'TEXT',
1557+
'default' => '',
1558+
'validators' => array( 0 => array ( 'type' => 'REGEX',
1559+
'regex' => '/^\/[a-zA-Z0-9\.\-\_\/]{1,128}$/',
1560+
'errmsg'=> 'bind_zonefiles_slaveprefix_error_regex'),
1561+
),
1562+
'value' => '',
1563+
'width' => '40',
1564+
'maxlength' => '255'
1565+
),
15421566
'named_conf_path' => array(
15431567
'datatype' => 'VARCHAR',
15441568
'formtype' => 'TEXT',

interface/web/admin/templates/server_config_dns_edit.htm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
<div class="form-group">
1515
<label for="bind_keyfiles_dir" class="col-sm-3 control-label">{tmpl_var name='bind_keyfiles_dir_txt'}</label>
1616
<div class="col-sm-9"><input type="text" name="bind_keyfiles_dir" id="bind_keyfiles_dir" value="{tmpl_var name='bind_keyfiles_dir'}" class="form-control" /></div></div>
17+
<div class="form-group">
18+
<label for="bind_zonefiles_masterprefix" class="col-sm-3 control-label">{tmpl_var name='bind_zonefiles_masterprefix_txt'}</label>
19+
<div class="col-sm-9"><input type="text" name="bind_zonefiles_masterprefix" id="bind_zonefiles_masterprefix" value="{tmpl_var name='bind_zonefiles_masterprefix'}" class="form-control" /></div></div>
20+
<div class="form-group">
21+
<label for="bind_zonefiles_slaveprefix" class="col-sm-3 control-label">{tmpl_var name='bind_zonefiles_slaveprefix_txt'}</label>
22+
<div class="col-sm-9"><input type="text" name="bind_zonefiles_slaveprefix" id="bind_zonefiles_slaveprefix" value="{tmpl_var name='bind_zonefiles_slaveprefix'}" class="form-control" /></div></div>
1723
<div class="form-group">
1824
<label for="named_conf_path" class="col-sm-3 control-label">{tmpl_var name='named_conf_path_txt'}</label>
1925
<div class="col-sm-9"><input type="text" name="named_conf_path" id="named_conf_path" value="{tmpl_var name='named_conf_path'}" class="form-control" /></div></div>

server/plugins-available/bind_plugin.inc.php

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function soa_dnssec_create(&$data) {
8787
$dns_config = $app->getconf->get_server_config($conf["server_id"], 'dns');
8888

8989
$domain = substr($data['new']['origin'], 0, strlen($data['new']['origin'])-1);
90-
if (!file_exists($dns_config['bind_zonefiles_dir'].'/'.$this->zone_file_prefix().$domain)) return false;
90+
if (!file_exists($dns_config['bind_zonefiles_dir'].'/'.$dns_config['bind_zonefiles_masterprefix'].$domain)) return false;
9191

9292
//* Check Entropy
9393
if (file_get_contents('/proc/sys/kernel/random/entropy_avail') < 400) {
@@ -136,7 +136,7 @@ function soa_dnssec_sign(&$data) {
136136
//* load the server configuration options
137137
$dns_config = $app->getconf->get_server_config($conf["server_id"], 'dns');
138138

139-
$filespre = $this->zone_file_prefix();
139+
$filespre = $dns_config['bind_zonefiles_masterprefix'];
140140
$domain = substr($data['new']['origin'], 0, strlen($data['new']['origin'])-1);
141141
if (!file_exists($dns_config['bind_zonefiles_dir'].'/'.$filespre.$domain)) return false;
142142

@@ -202,7 +202,7 @@ function soa_dnssec_update(&$data, $new=false) {
202202
//* load the server configuration options
203203
$dns_config = $app->getconf->get_server_config($conf["server_id"], 'dns');
204204

205-
$filespre = $this->zone_file_prefix();
205+
$filespre = $dns_config['bind_zonefiles_masterprefix'];
206206
$domain = substr($data['new']['origin'], 0, strlen($data['new']['origin'])-1);
207207
if (!file_exists($dns_config['bind_zonefiles_dir'].'/'.$filespre.$domain)) return false;
208208

@@ -241,7 +241,7 @@ function soa_dnssec_delete(&$data) {
241241
foreach($key_files as $file) {
242242
unlink($file);
243243
}
244-
unlink($dns_config['bind_zonefiles_dir'].'/'.$this->zone_file_prefix().$domain.'.signed');
244+
unlink($dns_config['bind_zonefiles_dir'].'/'.$dns_config['bind_zonefiles_masterprefix'].$domain.'.signed');
245245
unlink($dns_config['bind_keyfiles_dir'].'/dsset-'.$domain.'.');
246246

247247
if ($app->dbmaster !== $app->db) $app->dbmaster->query('UPDATE dns_soa SET dnssec_info=\'\', dnssec_initialized=\'N\' WHERE id=?', intval($data['new']['id']));
@@ -325,7 +325,7 @@ function soa_update($event_name, $data) {
325325
}
326326
$tpl->setLoop('zones', $records);
327327

328-
$filename = $dns_config['bind_zonefiles_dir'].'/' . $this->zone_file_prefix() . str_replace("/", "_", substr($zone['origin'], 0, -1));
328+
$filename = $dns_config['bind_zonefiles_dir'].'/' . $dns_config['bind_zonefiles_masterprefix'] . str_replace("/", "_", substr($zone['origin'], 0, -1));
329329

330330
$old_zonefile = @file_get_contents($filename);
331331
file_put_contents($filename, $tpl->grab());
@@ -371,7 +371,7 @@ function soa_update($event_name, $data) {
371371
} elseif ($data['new']['dnssec_wanted'] == 'Y' && $data['old']['dnssec_initialized'] == 'N') {
372372
$this->soa_dnssec_create($data);
373373
} elseif ($data['new']['dnssec_wanted'] == 'N' && $data['old']['dnssec_initialized'] == 'Y') { //delete old signed file if dnssec is no longer wanted
374-
$filename = $dns_config['bind_zonefiles_dir'].'/' . $this->zone_file_prefix() . str_replace("/", "_", substr($data['old']['origin'], 0, -1));
374+
$filename = $dns_config['bind_zonefiles_dir'].'/' . $dns_config['bind_zonefiles_masterprefix'] . str_replace("/", "_", substr($data['old']['origin'], 0, -1));
375375
if(is_file($filename.'.signed')) unlink($filename.'.signed');
376376
} elseif ($data['new']['dnssec_wanted'] == 'Y') {
377377
$this->soa_dnssec_update($data);
@@ -385,7 +385,7 @@ function soa_update($event_name, $data) {
385385

386386
//* Delete old domain file, if domain name has been changed
387387
if($data['old']['origin'] != $data['new']['origin']) {
388-
$filename = $dns_config['bind_zonefiles_dir'].'/' . $this->zone_file_prefix() . str_replace("/", "_", substr($data['old']['origin'], 0, -1));
388+
$filename = $dns_config['bind_zonefiles_dir'].'/' . $dns_config['bind_zonefiles_masterprefix'] . str_replace("/", "_", substr($data['old']['origin'], 0, -1));
389389

390390
if(is_file($filename)) unlink($filename);
391391
if(is_file($filename.'.err')) unlink($filename.'.err');
@@ -412,7 +412,7 @@ function soa_delete($event_name, $data) {
412412
$this->write_named_conf($data, $dns_config);
413413

414414
//* Delete the domain file
415-
$zone_file_name = $dns_config['bind_zonefiles_dir'].'/' . $this->zone_file_prefix() . str_replace("/", "_", substr($data['old']['origin'], 0, -1));
415+
$zone_file_name = $dns_config['bind_zonefiles_dir'].'/' . $dns_config['bind_zonefiles_masterprefix'] . str_replace("/", "_", substr($data['old']['origin'], 0, -1));
416416
if(is_file($zone_file_name)) unlink($zone_file_name);
417417
if(is_file($zone_file_name.'.err')) unlink($zone_file_name.'.err');
418418
$app->log("Deleting BIND domain file: ".$zone_file_name, LOGLEVEL_DEBUG);
@@ -452,12 +452,12 @@ function slave_update($event_name, $data) {
452452

453453
//* Delete old domain file, if domain name has been changed
454454
if($data['old']['origin'] != $data['new']['origin']) {
455-
$filename = $dns_config['bind_zonefiles_dir'].'/' . $this->zone_file_prefix() . str_replace("/", "_", substr($data['old']['origin'], 0, -1));
455+
$filename = $dns_config['bind_zonefiles_dir'].'/' . $dns_config['bind_zonefiles_masterprefix'] . str_replace("/", "_", substr($data['old']['origin'], 0, -1));
456456
if(is_file($filename)) unset($filename);
457457
}
458458

459459
//* Ensure that the named slave directory is writable by the named user
460-
$slave_record_dir = $dns_config['bind_zonefiles_dir'].'/'.$this->slave_zone_file_prefix();
460+
$slave_record_dir = $dns_config['bind_zonefiles_dir'].'/'.$dns_config['bind_zonefiles_slaveprefix'];
461461
if(!@is_dir($slave_record_dir)) mkdir($slave_record_dir, 0770);
462462
chown($slave_record_dir, $dns_config['bind_user']);
463463
chgrp($slave_record_dir, $dns_config['bind_group']);
@@ -479,7 +479,7 @@ function slave_delete($event_name, $data) {
479479
$this->write_named_conf($data, $dns_config);
480480

481481
//* Delete the domain file
482-
$zone_file_name = $dns_config['bind_zonefiles_dir'].'/' . $this->slave_zone_file_prefix() . str_replace("/", "_", substr($data['old']['origin'], 0, -1));
482+
$zone_file_name = $dns_config['bind_zonefiles_dir'].'/' . $dns_config['bind_zonefiles_slaveprefix'] . str_replace("/", "_", substr($data['old']['origin'], 0, -1));
483483
if(is_file($zone_file_name)) unlink($zone_file_name);
484484
$app->log("Deleting BIND domain file for secondary zone: ".$zone_file_name, LOGLEVEL_DEBUG);
485485

@@ -536,8 +536,8 @@ function write_named_conf($data, $dns_config) {
536536

537537
//* Check if the current zone that triggered this function has at least one NS record
538538

539-
$pri_zonefiles_path = $dns_config['bind_zonefiles_dir'].'/'.$this->zone_file_prefix();
540-
$sec_zonefiles_path = $dns_config['bind_zonefiles_dir'].'/'.$this->slave_zone_file_prefix();
539+
$pri_zonefiles_path = $dns_config['bind_zonefiles_dir'].'/'.$dns_config['bind_zonefiles_masterprefix'];
540+
$sec_zonefiles_path = $dns_config['bind_zonefiles_dir'].'/'.$dns_config['bind_zonefiles_slaveprefix'];
541541

542542
//* Loop trough zones
543543
foreach($tmps as $tmp) {
@@ -600,20 +600,6 @@ function write_named_conf($data, $dns_config) {
600600
unset($tmps);
601601

602602
}
603-
604-
605-
function zone_file_prefix() {
606-
//TODO : change this when distribution information has been integrated into server record
607-
return (file_exists('/etc/gentoo-release')) ? 'pri/' : 'pri.';
608-
}
609-
function slave_zone_file_prefix() {
610-
//TODO : change this when distribution information has been integrated into server record
611-
return (file_exists('/etc/gentoo-release')) ? 'sec/' : 'slave/sec.';
612-
}
613-
614-
615-
616-
617603
} // end class
618604

619605
?>

0 commit comments

Comments
 (0)