From 37b29231e47a0c4458dc1c15d98588f16f07e1e2 Mon Sep 17 00:00:00 2001
From: Marius Cramer <m.cramer@pixcept.de>
Date: Thu, 06 Aug 2015 03:18:44 -0400
Subject: [PATCH] - don't set password via remoting if field is empty

---
 interface/lib/classes/client_templates.inc.php |   38 +++++++++++++++++++++-----------------
 1 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/interface/lib/classes/client_templates.inc.php b/interface/lib/classes/client_templates.inc.php
index 993936b..e3141d7 100644
--- a/interface/lib/classes/client_templates.inc.php
+++ b/interface/lib/classes/client_templates.inc.php
@@ -49,7 +49,7 @@
 
 		if($old_style == true) {
 			// we have to take care of this in an other way
-			$in_db = $app->db->queryAllRecords('SELECT `assigned_template_id`, `client_template_id` FROM `client_template_assigned` WHERE `client_id` = ' . $app->functions->intval($clientId));
+			$in_db = $app->db->queryAllRecords('SELECT `assigned_template_id`, `client_template_id` FROM `client_template_assigned` WHERE `client_id` = ?', $clientId);
 			if(is_array($in_db) && count($in_db) > 0) {
 				foreach($in_db as $item) {
 					if(array_key_exists($item['client_template_id'], $needed_types) == false) $needed_types[$item['client_template_id']] = 0;
@@ -61,24 +61,24 @@
 				if($count > 0) {
 					// add new template to client (includes those from old-style without assigned_template_id)
 					for($i = $count; $i > 0; $i--) {
-						$app->db->query('INSERT INTO `client_template_assigned` (`client_id`, `client_template_id`) VALUES (' . $app->functions->intval($clientId) . ', ' . $app->functions->intval($tpl_id) . ')');
+						$app->db->query('INSERT INTO `client_template_assigned` (`client_id`, `client_template_id`) VALUES (?, ?)', $clientId, $tpl_id);
 					}
 				} elseif($count < 0) {
 					// remove old ones
 					for($i = $count; $i < 0; $i++) {
-						$app->db->query('DELETE FROM `client_template_assigned` WHERE client_id = ' . $app->functions->intval($clientId) . ' AND client_template_id = ' . $app->functions->intval($tpl_id) . ' LIMIT 1');
+						$app->db->query('DELETE FROM `client_template_assigned` WHERE client_id = ? AND client_template_id = ? LIMIT 1', $clientId, $tpl_id);
 					}
 				}
 			}
 		} else {
 			// we have to take care of this in an other way
-			$in_db = $app->db->queryAllRecords('SELECT `assigned_template_id`, `client_template_id` FROM `client_template_assigned` WHERE `client_id` = ' . $app->functions->intval($clientId));
+			$in_db = $app->db->queryAllRecords('SELECT `assigned_template_id`, `client_template_id` FROM `client_template_assigned` WHERE `client_id` = ?', $clientId);
 			if(is_array($in_db) && count($in_db) > 0) {
 				// check which templates were removed from this client
 				foreach($in_db as $item) {
 					if(in_array($item['assigned_template_id'], $used_assigned) == false) {
 						// delete this one
-						$app->db->query('DELETE FROM `client_template_assigned` WHERE `assigned_template_id` = ' . $app->functions->intval($item['assigned_template_id']));
+						$app->db->query('DELETE FROM `client_template_assigned` WHERE `assigned_template_id` = ?', $item['assigned_template_id']);
 					}
 				}
 			}
@@ -86,7 +86,7 @@
 			if(count($new_tpl) > 0) {
 				foreach($new_tpl as $item) {
 					// add new template to client (includes those from old-style without assigned_template_id)
-					$app->db->query('INSERT INTO `client_template_assigned` (`client_id`, `client_template_id`) VALUES (' . $app->functions->intval($clientId) . ', ' . $app->functions->intval($item) . ')');
+					$app->db->query('INSERT INTO `client_template_assigned` (`client_id`, `client_template_id`) VALUES (?, ?)', $clientId, $item);
 				}
 			}
 		}
@@ -106,8 +106,8 @@
 		/*
          * Get the master-template for the client
          */
-		$sql = "SELECT template_master, template_additional,limit_client FROM client WHERE client_id = " . $app->functions->intval($clientId);
-		$record = $app->db->queryOneRecord($sql);
+		$sql = "SELECT template_master, template_additional,limit_client FROM client WHERE client_id = ?";
+		$record = $app->db->queryOneRecord($sql, $clientId);
 		$masterTemplateId = $record['template_master'];
 		$is_reseller = ($record['limit_client'] != 0)?true:false;
 
@@ -115,15 +115,15 @@
 			// we have to call the update_client_templates function
 			$templates = explode('/', $record['template_additional']);
 			$this->update_client_templates($clientId, $templates);
-			$app->db->query('UPDATE `client` SET `template_additional` = \'\' WHERE `client_id` = ' . $app->functions->intval($clientId));
+			$app->db->query('UPDATE `client` SET `template_additional` = \'\' WHERE `client_id` = ?', $clientId);
 		}
 
 		/*
          * if the master-Template is custom there is NO changing
          */
 		if ($masterTemplateId > 0){
-			$sql = "SELECT * FROM client_template WHERE template_id = " . $app->functions->intval($masterTemplateId);
-			$limits = $app->db->queryOneRecord($sql);
+			$sql = "SELECT * FROM client_template WHERE template_id = ?";
+			$limits = $app->db->queryOneRecord($sql, $masterTemplateId);
 		} else {
 			// if there is no master template it makes NO SENSE adding sub templates.
 			// adding subtemplates are stored in client limits, so they would add up
@@ -136,11 +136,11 @@
          * if != -1)
          */
 		$addTpl = explode('/', $additionalTemplateStr);
-		$addTpls = $app->db->queryAllRecords('SELECT `client_template_id` FROM `client_template_assigned` WHERE `client_id` = ' . $app->functions->intval($clientId));
+		$addTpls = $app->db->queryAllRecords('SELECT `client_template_id` FROM `client_template_assigned` WHERE `client_id` = ?', $clientId);
 		foreach ($addTpls as $addTpl){
 			$item = $addTpl['client_template_id'];
-			$sql = "SELECT * FROM client_template WHERE template_id = " . $app->functions->intval($item);
-			$addLimits = $app->db->queryOneRecord($sql);
+			$sql = "SELECT * FROM client_template WHERE template_id = ?";
+			$addLimits = $app->db->queryOneRecord($sql, $item);
 			$app->log('Template processing subtemplate ' . $item . ' for client ' . $clientId, LOGLEVEL_DEBUG);
 			/* maybe the template is deleted in the meantime */
 			if (is_array($addLimits)){
@@ -232,6 +232,7 @@
          * Write all back to the database
          */
 		$update = '';
+		$update_values = array();
 		if(!$is_reseller) unset($limits['limit_client']); // Only Resellers may have limit_client set in template to ensure that we do not convert a client to reseller accidently.
 		foreach($limits as $k => $v){
 			if (strpos($k, 'default') !== false and $v == 0) {
@@ -239,13 +240,16 @@
 			}
 			if ((strpos($k, 'limit') !== false or strpos($k, 'default') !== false or $k == 'ssh_chroot' or $k == 'web_php_options' or $k == 'force_suexec') && !is_array($v)){
 				if ($update != '') $update .= ', ';
-				$update .= '`' . $k . "`='" . $v . "'";
+				$update .= '?? = ?';
+				$update_values[] = $k;
+				$update_values[] = $v;
 			}
 		}
+		$update_values[] = $clientId;
 		$app->log('Template processed for client ' . $clientId . ', update string: ' . $update, LOGLEVEL_DEBUG);
 		if($update != '') {
-			$sql = 'UPDATE client SET ' . $update . " WHERE client_id = " . $app->functions->intval($clientId);
-			$app->db->query($sql);
+			$sql = 'UPDATE client SET ' . $update . " WHERE client_id = ?";
+			$app->db->query($sql, true, $update_values);
 		}
 		unset($form);
 	}

--
Gitblit v1.9.1