From 7eade0da5ec04ec86a89aed3c98e27cba3dae491 Mon Sep 17 00:00:00 2001
From: Florian Schaal <florian@schaal-24.de>
Date: Thu, 07 May 2015 08:33:08 -0400
Subject: [PATCH]  avoid the second use of query in install.php

---
 server/plugins-available/bind_plugin.inc.php |   21 +++++++--------------
 1 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/server/plugins-available/bind_plugin.inc.php b/server/plugins-available/bind_plugin.inc.php
index dd7021c..3b55dbc 100644
--- a/server/plugins-available/bind_plugin.inc.php
+++ b/server/plugins-available/bind_plugin.inc.php
@@ -102,10 +102,11 @@
 			$zone = $data['new'];
 			$tpl->setVar($zone);
 
-			$records = $app->db->queryAllRecords("SELECT * FROM dns_rr WHERE zone = ".$zone['id']." AND active = 'Y'");
+			$records = $app->db->queryAllRecords("SELECT * FROM dns_rr WHERE zone = ? AND active = 'Y'", $zone['id']);
 			if(is_array($records) && !empty($records)){
 				for($i=0;$i<sizeof($records);$i++){
 					if($records[$i]['ttl'] == 0) $records[$i]['ttl'] = '';
+					if($records[$i]['name'] == '') $records[$i]['name'] = '@';
 					//* Split TXT records, if nescessary
 					if($records[$i]['type'] == 'TXT' && strlen($records[$i]['data']) > 255) {
 						$records[$i]['data'] = implode('" "',str_split( $records[$i]['data'], 255));
@@ -280,7 +281,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['new']['zone']);
+		$tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ?", $data['new']['zone']);
 		$data["new"] = $tmp;
 		$data["old"] = $tmp;
 		$this->action = 'update';
@@ -292,7 +293,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['new']['zone']);
+		$tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ?", $data['new']['zone']);
 		$data["new"] = $tmp;
 		$data["old"] = $tmp;
 		$this->action = 'update';
@@ -304,7 +305,7 @@
 		global $app, $conf;
 
 		//* Get the data of the soa and call soa_update
-		$tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ".intval($data['old']['zone']));
+		$tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ?", $data['old']['zone']);
 		$data["new"] = $tmp;
 		$data["old"] = $tmp;
 		$this->action = 'update';
@@ -318,18 +319,10 @@
 		global $app, $conf;
 
 		//* Only write the master file for the current server
-		$tmps = $app->db->queryAllRecords("SELECT origin, xfer, also_notify, update_acl FROM dns_soa WHERE active = 'Y' AND server_id=".$conf["server_id"]);
+		$tmps = $app->db->queryAllRecords("SELECT origin, xfer, also_notify, update_acl FROM dns_soa WHERE active = 'Y' AND server_id=?", $conf["server_id"]);
 		$zones = array();
 
 		//* Check if the current zone that triggered this function has at least one NS record
-		/* Has been replaced by a better zone check
-		$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')) {
@@ -369,7 +362,7 @@
 		$tpl->setLoop('zones', $zones);
 
 		//* And loop through the secondary zones, but only for the current server
-		$tmps_sec = $app->db->queryAllRecords("SELECT origin, xfer, ns FROM dns_slave WHERE active = 'Y' AND server_id=".$conf["server_id"]);
+		$tmps_sec = $app->db->queryAllRecords("SELECT origin, xfer, ns FROM dns_slave WHERE active = 'Y' AND server_id=?", $conf["server_id"]);
 		$zones_sec = array();
 
 		foreach($tmps_sec as $tmp) {

--
Gitblit v1.9.1