From 81d79a79e4b29e9314b64b2e4c49b48ae8319767 Mon Sep 17 00:00:00 2001
From: ftimme <ft@falkotimme.com>
Date: Tue, 11 Oct 2011 08:50:45 -0400
Subject: [PATCH] - WebDAV Users: show only domains that run on Apache (because nginx does not have full WebDAV support).

---
 server/plugins-available/bind_plugin.inc.php |   65 +++++++++++++++++++++++++++-----
 1 files changed, 55 insertions(+), 10 deletions(-)

diff --git a/server/plugins-available/bind_plugin.inc.php b/server/plugins-available/bind_plugin.inc.php
index 02a301a..9d67eda 100644
--- a/server/plugins-available/bind_plugin.inc.php
+++ b/server/plugins-available/bind_plugin.inc.php
@@ -105,8 +105,14 @@
 			$records = $app->db->queryAllRecords("SELECT * FROM dns_rr WHERE zone = ".$zone['id']." AND active = 'Y'");
 			$tpl->setLoop('zones',$records);
 			
-		
-			$filename = escapeshellcmd($dns_config['bind_zonefiles_dir'].'/pri.'.substr($zone['origin'],0,-1));
+			//TODO : change this when distribution information has been integrated into server record
+        	if (file_exists('/etc/gentoo-release')) {
+        		$filename = escapeshellcmd($dns_config['bind_zonefiles_dir'].'/pri/'.substr($zone['origin'],0,-1));
+        	}
+        	else {
+        		$filename = escapeshellcmd($dns_config['bind_zonefiles_dir'].'/pri.'.substr($zone['origin'],0,-1));
+        	}
+        	
 			$app->log("Writing BIND domain file: ".$filename,LOGLEVEL_DEBUG);
 			file_put_contents($filename,$tpl->grab());
 			chown($filename, escapeshellcmd($dns_config['bind_user']));
@@ -124,7 +130,14 @@
 		
 		//* Delete old domain file, if domain name has been changed
 		if($data['old']['origin'] != $data['new']['origin']) {
-			$filename = $dns_config['bind_zonefiles_dir'].'/pri.'.substr($data['old']['origin'],0,-1);
+			//TODO : change this when distribution information has been integrated into server record
+        	if (file_exists('/etc/gentoo-release')) {
+        		$filename = $dns_config['bind_zonefiles_dir'].'/pri/'.substr($data['old']['origin'],0,-1);
+        	}
+        	else {
+        		$filename = $dns_config['bind_zonefiles_dir'].'/pri.'.substr($data['old']['origin'],0,-1);
+        	}
+			
 			if(is_file($filename)) unset($filename);
 		}
 		
@@ -144,7 +157,14 @@
 		$this->write_named_conf($data,$dns_config);
 		
 		//* Delete the domain file
-		$zone_file_name = $dns_config['bind_zonefiles_dir'].'/pri.'.substr($data['old']['origin'],0,-1);
+		//TODO : change this when distribution information has been integrated into server record
+        if (file_exists('/etc/gentoo-release')) {
+        	$zone_file_name = $dns_config['bind_zonefiles_dir'].'/pri/'.substr($data['old']['origin'],0,-1);
+        }
+        else {
+        	$zone_file_name = $dns_config['bind_zonefiles_dir'].'/pri.'.substr($data['old']['origin'],0,-1);
+        }
+		
 		if(is_file($zone_file_name)) unlink($zone_file_name);
 		$app->log("Deleting BIND domain file: ".$zone_file_name,LOGLEVEL_DEBUG);
 		
@@ -177,7 +197,14 @@
 		
 		//* Delete old domain file, if domain name has been changed
 		if($data['old']['origin'] != $data['new']['origin']) {
-			$filename = $dns_config['bind_zonefiles_dir'].'/slave/sec.'.substr($data['old']['origin'],0,-1);
+			//TODO : change this when distribution information has been integrated into server record
+	        if (file_exists('/etc/gentoo-release')) {
+	        	$filename = $dns_config['bind_zonefiles_dir'].'/sec/'.substr($data['old']['origin'],0,-1);
+	        }
+	        else {
+	        	$filename = $dns_config['bind_zonefiles_dir'].'/slave/sec.'.substr($data['old']['origin'],0,-1);
+	        }
+			
 			if(is_file($filename)) unset($filename);
 		}
 		
@@ -198,7 +225,14 @@
 		$this->write_named_conf($data,$dns_config);
 		
 		//* Delete the domain file
-		$zone_file_name = $dns_config['bind_zonefiles_dir'].'/slave/sec.'.substr($data['old']['origin'],0,-1);
+		//TODO : change this when distribution information has been integrated into server record
+	    if (file_exists('/etc/gentoo-release')) {
+	    	$zone_file_name = $dns_config['bind_zonefiles_dir'].'/sec/'.substr($data['old']['origin'],0,-1);
+	    }
+	    else {
+	    	$zone_file_name = $dns_config['bind_zonefiles_dir'].'/slave/sec.'.substr($data['old']['origin'],0,-1);
+	    }
+		
 		if(is_file($zone_file_name)) unlink($zone_file_name);
 		$app->log("Deleting BIND domain file for secondary zone: ".$zone_file_name,LOGLEVEL_DEBUG);
 		
@@ -236,7 +270,7 @@
 		global $app, $conf;
 		
 		//* Get the data of the soa and call soa_update
-		$tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ".$data['old']['zone']);
+		$tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ".intval($data['old']['zone']));
 		$data["new"] = $tmp;
 		$data["old"] = $tmp;
 		$this->action = 'update';
@@ -254,12 +288,23 @@
 		$zones = array();
 		
 		//* Check if the current zone that triggered this function has at least one NS record
-		$rec_num = $app->db->queryOneRecord("SELECT count(id) as ns FROM dns_rr WHERE type = 'NS' AND zone = ".$data['new']['id']." AND active = 'Y'");
+		$rec_num = $app->db->queryOneRecord("SELECT count(id) as ns FROM dns_rr WHERE type = 'NS' AND zone = ".intval($data['new']['id'])." AND active = 'Y'");
 		if($rec_num['ns'] == 0) {
 			$exclude_zone = $data['new']['origin'];
 		} else {
 			$exclude_zone = '';
 		}
+		
+		//TODO : change this when distribution information has been integrated into server record
+	    if (file_exists('/etc/gentoo-release')) {
+	    	$pri_zonefiles_path = $dns_config['bind_zonefiles_dir'].'/pri/';
+	    	$sec_zonefiles_path = $dns_config['bind_zonefiles_dir'].'/sec/';
+	    	
+	    }
+	    else {
+	    	$pri_zonefiles_path = $dns_config['bind_zonefiles_dir'].'/pri.';
+	    	$sec_zonefiles_path = $dns_config['bind_zonefiles_dir'].'/slave/sec.';
+	    }
 
 		//* Loop trough zones
 		foreach($tmps as $tmp) {
@@ -274,7 +319,7 @@
 			
 			if($tmp['origin'] != $exclude_zone) {
 				$zones[] = array(	'zone' => substr($tmp['origin'],0,-1),
-									'zonefile_path' => $dns_config['bind_zonefiles_dir'].'/pri.'.substr($tmp['origin'],0,-1),
+									'zonefile_path' => $pri_zonefiles_path.substr($tmp['origin'],0,-1),
 									'options' => $options
 								);
 			}
@@ -299,7 +344,7 @@
 
 			
 			$zones_sec[] = array(	'zone' => substr($tmp['origin'],0,-1),
-									'zonefile_path' => $dns_config['bind_zonefiles_dir'].'/slave/sec.'.substr($tmp['origin'],0,-1),
+									'zonefile_path' => $sec_zonefiles_path.substr($tmp['origin'],0,-1),
 									'options' => $options
 								);
 

--
Gitblit v1.9.1