Skip to content

Commit 3a11d23

Browse files
author
Marius Cramer
committed
- changed code to use new method of passing values to datalogUpdate and datalogInsert
1 parent a6e3ae8 commit 3a11d23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+527
-245
lines changed

interface/lib/classes/aps_crawler.inc.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public function startCrawler()
357357
if(file_exists($old_folder)) $this->removeDirectory($old_folder);
358358

359359
$tmp = $app->db->queryOneRecord("SELECT id FROM aps_packages WHERE name = ? AND CONCAT(version, '-', CAST(`release` AS CHAR)) = ?", $app_name, $ex_ver);
360-
$app->db->datalogUpdate('aps_packages', "package_status = ".PACKAGE_OUTDATED, 'id', $tmp['id']);
360+
$app->db->datalogUpdate('aps_packages', array("package_status" => PACKAGE_OUTDATED), 'id', $tmp['id']);
361361
unset($tmp);
362362
}
363363

@@ -537,7 +537,7 @@ public function parseFolderToDB()
537537
$diff = array_diff($existing_packages, $pkg_list);
538538
foreach($diff as $todelete) {
539539
$tmp = $app->db->queryOneRecord("SELECT id FROM aps_packages WHERE path = ?", $todelete);
540-
$app->db->datalogUpdate('aps_packages', "package_status = ".PACKAGE_ERROR_NOMETA, 'id', $tmp['id']);
540+
$app->db->datalogUpdate('aps_packages', array("package_status" => PACKAGE_ERROR_NOMETA), 'id', $tmp['id']);
541541
unset($tmp);
542542
}
543543

@@ -569,11 +569,15 @@ public function parseFolderToDB()
569569

570570
// Insert only if data is complete
571571
if($pkg != '' && $pkg_name != '' && $pkg_category != '' && $pkg_version != '' && $pkg_release != '' && $pkg_url){
572-
$insert_data = "(`path`, `name`, `category`, `version`, `release`, `package_url`, `package_status`) VALUES
573-
('".$app->db->quote($pkg)."', '".$app->db->quote($pkg_name)."',
574-
'".$app->db->quote($pkg_category)."', '".$app->db->quote($pkg_version)."',
575-
".$app->db->quote($pkg_release).", '".$app->db->quote($pkg_url)."', ".PACKAGE_ENABLED.");";
576-
572+
$insert_data = array(
573+
"path" => $pkg,
574+
"name" => $pkg_name,
575+
"category" => $pkg_category,
576+
"version" => $pkg_version,
577+
"release" => $pkg_release,
578+
"package_url" => $pkg_url,
579+
"package_status" => PACKAGE_ENABLED
580+
);
577581
$app->db->datalogInsert('aps_packages', $insert_data, 'id');
578582
} else {
579583
if(file_exists($this->interface_pkg_dir.'/'.$pkg)) $this->removeDirectory($this->interface_pkg_dir.'/'.$pkg);

interface/lib/classes/aps_guicontroller.inc.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,12 @@ public function createPackageInstance($settings, $packageid)
356356
//* Set PHP mode to php-fcgi and enable suexec in website on apache servers / set PHP mode to PHP-FPM on nginx servers
357357
if($web_config['server_type'] == 'apache') {
358358
if(($websrv['php'] != 'fast-cgi' || $websrv['suexec'] != 'y') && $websrv['php'] != 'php-fpm') {
359-
$app->db->datalogUpdate('web_domain', "php = 'fast-cgi', suexec = 'y'", 'domain_id', $websrv['domain_id']);
359+
$app->db->datalogUpdate('web_domain', array("php" => 'fast-cgi', "suexec" => 'y'), 'domain_id', $websrv['domain_id']);
360360
}
361361
} else {
362362
// nginx
363363
if($websrv['php'] != 'php-fpm' && $websrv['php'] != 'fast-cgi') {
364-
$app->db->datalogUpdate('web_domain', "php = 'php-fpm'", 'domain_id', $websrv['domain_id']);
364+
$app->db->datalogUpdate('web_domain', array("php" => 'php-fpm'), 'domain_id', $websrv['domain_id']);
365365
}
366366
}
367367

@@ -378,19 +378,34 @@ public function createPackageInstance($settings, $packageid)
378378
}
379379

380380
//* Insert new package instance
381-
$insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `customer_id`, `package_id`, `instance_status`) VALUES (".$app->functions->intval($websrv['sys_userid']).", ".$app->functions->intval($websrv['sys_groupid']).", 'riud', '".$app->db->quote($websrv['sys_perm_group'])."', '', ".$app->db->quote($webserver_id).",".$app->db->quote($customerid).", ".$app->db->quote($packageid).", ".INSTANCE_PENDING.")";
381+
$insert_data = array(
382+
"sys_userid" => $websrv['sys_userid'],
383+
"sys_groupid" => $websrv['sys_groupid'],
384+
"sys_perm_user" => 'riud',
385+
"sys_perm_group" => $websrv['sys_perm_group'],
386+
"sys_perm_other" => '',
387+
"server_id" => $webserver_id,
388+
"customer_id" => $customerid,
389+
"package_id" => $packageid,
390+
"instance_status" => INSTANCE_PENDING
391+
);
382392
$InstanceID = $app->db->datalogInsert('aps_instances', $insert_data, 'id');
383393

384394
//* Insert all package settings
385395
if(is_array($settings)) {
386396
foreach($settings as $key => $value) {
387-
$insert_data = "(server_id, instance_id, name, value) VALUES (".$app->db->quote($webserver_id).",".$app->db->quote($InstanceID).", '".$app->db->quote($key)."', '".$app->db->quote($value)."')";
397+
$insert_data = array(
398+
"server_id" => $webserver_id,
399+
"instance_id" => $InstanceID,
400+
"name" => $key,
401+
"value" => $value
402+
);
388403
$app->db->datalogInsert('aps_instances_settings', $insert_data, 'id');
389404
}
390405
}
391406

392407
//* Set package status to install afetr we inserted the settings
393-
$app->db->datalogUpdate('aps_instances', "instance_status = ".INSTANCE_INSTALL, 'id', $InstanceID);
408+
$app->db->datalogUpdate('aps_instances', array("instance_status" => INSTANCE_INSTALL), 'id', $InstanceID);
394409
}
395410

396411
/**
@@ -413,7 +428,7 @@ public function deleteInstance($instanceid, $keepdatabase = false)
413428
if($tmp['cnt'] < 1) $app->db->datalogDelete('web_database_user', 'database_user_id', $database_user);
414429
}
415430

416-
$app->db->datalogUpdate('aps_instances', "instance_status = ".INSTANCE_REMOVE, 'id', $instanceid);
431+
$app->db->datalogUpdate('aps_instances', array("instance_status" => INSTANCE_REMOVE), 'id', $instanceid);
417432

418433
}
419434

interface/lib/classes/db_mysql.inc.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,17 @@ public function _build_query_string($sQuery = '') {
137137
} else {
138138
if(is_int($sValue) || is_float($sValue)) {
139139
$sTxt = $sValue;
140-
} elseif(is_string($sValue) && (strcmp($sValue, '#NULL#') == 0)) {
140+
} elseif(is_null($sValue) || (is_string($sValue) && (strcmp($sValue, '#NULL#') == 0))) {
141141
$sTxt = 'NULL';
142142
} elseif(is_array($sValue)) {
143-
$sTxt = '';
144-
foreach($sValue as $sVal) $sTxt .= ',\'' . $this->escape($sVal) . '\'';
145-
$sTxt = '(' . substr($sTxt, 1) . ')';
146-
if($sTxt == '()') $sTxt = '(0)';
143+
if(isset($sValue['SQL'])) {
144+
$sTxt = $sValue['SQL'];
145+
} else {
146+
$sTxt = '';
147+
foreach($sValue as $sVal) $sTxt .= ',\'' . $this->escape($sVal) . '\'';
148+
$sTxt = '(' . substr($sTxt, 1) . ')';
149+
if($sTxt == '()') $sTxt = '(0)';
150+
}
147151
} else {
148152
$sTxt = '\'' . $this->escape($sValue) . '\'';
149153
}
@@ -578,7 +582,6 @@ public function datalogSave($db_table, $action, $primary_field, $primary_id, $re
578582
if(!preg_match('/^[a-zA-Z0-9\-\_\.]{1,64}$/',$db_table)) $app->error('Invalid table name '.$db_table);
579583
if(!preg_match('/^[a-zA-Z0-9\-\_]{1,64}$/',$primary_field)) $app->error('Invalid primary field '.$primary_field.' in table '.$db_table);
580584

581-
$primary_field = $this->quote($primary_field);
582585
$primary_id = intval($primary_id);
583586

584587
if($force_update == true) {
@@ -643,6 +646,7 @@ public function datalogInsert($tablename, $insert_data, $index_field) {
643646
/* TODO: deprecate this method! */
644647
$insert_data_str = $insert_data;
645648
$this->query("INSERT INTO ?? $insert_data_str", $tablename);
649+
$app->log("deprecated use of passing values to datalogInsert() - table " . $tablename, 1);
646650
}
647651

648652
$old_rec = array();
@@ -679,6 +683,7 @@ public function datalogUpdate($tablename, $update_data, $index_field, $index_val
679683
/* TODO: deprecate this method! */
680684
$update_data_str = $update_data;
681685
$this->query("UPDATE ?? SET $update_data_str WHERE ?? = ?", $tablename, $index_field, $index_value);
686+
$app->log("deprecated use of passing values to datalogUpdate() - table " . $tablename, 1);
682687
}
683688

684689
$new_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);

interface/lib/classes/remote.d/dns.inc.php

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ public function dns_templatezone_add($session_id, $client_id, $template_id, $dom
9595
if($section == 'dns_records') {
9696
$parts = explode('|', $row);
9797
$dns_rr[] = array(
98-
'name' => $app->db->quote($parts[1]),
99-
'type' => $app->db->quote($parts[0]),
100-
'data' => $app->db->quote($parts[2]),
101-
'aux' => $app->db->quote($parts[3]),
102-
'ttl' => $app->db->quote($parts[4])
98+
'name' => $parts[1],
99+
'type' => $parts[0],
100+
'data' => $parts[2],
101+
'aux' => $parts[3],
102+
'ttl' => $parts[4]
103103
);
104104
}
105105
}
@@ -121,26 +121,58 @@ public function dns_templatezone_add($session_id, $client_id, $template_id, $dom
121121
$sys_userid = $tmp['userid'];
122122
$sys_groupid = $tmp['default_group'];
123123
unset($tmp);
124-
$origin = $app->db->quote($vars['origin']);
125-
$ns = $app->db->quote($vars['ns']);
126-
$mbox = $app->db->quote(str_replace('@', '.', $vars['mbox']));
127-
$refresh = $app->db->quote($vars['refresh']);
128-
$retry = $app->db->quote($vars['retry']);
129-
$expire = $app->db->quote($vars['expire']);
130-
$minimum = $app->db->quote($vars['minimum']);
131-
$ttl = $app->db->quote($vars['ttl']);
132-
$xfer = $app->db->quote($vars['xfer']);
133-
$also_notify = $app->db->quote($vars['also_notify']);
134-
$update_acl = $app->db->quote($vars['update_acl']);
124+
$origin = $vars['origin'];
125+
$ns = $vars['ns'];
126+
$mbox = str_replace('@', '.', $vars['mbox']);
127+
$refresh = $vars['refresh'];
128+
$retry = $vars['retry'];
129+
$expire = $vars['expire'];
130+
$minimum = $vars['minimum'];
131+
$ttl = $vars['ttl'];
132+
$xfer = $vars['xfer'];
133+
$also_notify = $vars['also_notify'];
134+
$update_acl = $vars['update_acl'];
135135
$serial = $app->validate_dns->increase_serial(0);
136-
$insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `origin`, `ns`, `mbox`, `serial`, `refresh`, `retry`, `expire`, `minimum`, `ttl`, `active`, `xfer`, `also_notify`, `update_acl`) VALUES
137-
('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$origin', '$ns', '$mbox', '$serial', '$refresh', '$retry', '$expire', '$minimum', '$ttl', 'Y', '$xfer', '$also_notify', '$update_acl')";
136+
$insert_data = array(
137+
"sys_userid" => $sys_userid,
138+
"sys_groupid" => $sys_groupid,
139+
"sys_perm_user" => 'riud',
140+
"sys_perm_group" => 'riud',
141+
"sys_perm_other" => '',
142+
"server_id" => $server_id,
143+
"origin" => $origin,
144+
"ns" => $ns,
145+
"mbox" => $mbox,
146+
"serial" => $serial,
147+
"refresh" => $refresh,
148+
"retry" => $retry,
149+
"expire" => $expire,
150+
"minimum" => $minimum,
151+
"ttl" => $ttl,
152+
"active" => 'Y',
153+
"xfer" => $xfer,
154+
"also_notify" => $also_notify,
155+
"update_acl" => $update_acl
156+
);
138157
$dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');
139158
// Insert the dns_rr records
140159
if(is_array($dns_rr) && $dns_soa_id > 0) {
141160
foreach($dns_rr as $rr) {
142-
$insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `zone`, `name`, `type`, `data`, `aux`, `ttl`, `active`) VALUES
143-
('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$dns_soa_id', '$rr[name]', '$rr[type]', '$rr[data]', '$rr[aux]', '$rr[ttl]', 'Y')";
161+
$insert_data = array(
162+
"sys_userid" => $sys_userid,
163+
"sys_groupid" => $sys_groupid,
164+
"sys_perm_user" => 'riud',
165+
"sys_perm_group" => 'riud',
166+
"sys_perm_other" => '',
167+
"server_id" => $server_id,
168+
"zone" => $dns_soa_id,
169+
"name" => $rr['name'],
170+
"type" => $rr['type'],
171+
"data" => $rr['data'],
172+
"aux" => $rr['aux'],
173+
"ttl" => $rr['ttl'],
174+
"active" => 'Y'
175+
);
144176
$dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
145177
}
146178
}

interface/lib/classes/remote.d/sites.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ public function sites_database_user_delete($session_id, $primary_id)
266266

267267
$records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE database_user_id = ?", $primary_id);
268268
foreach($records as $rec) {
269-
$app->db->datalogUpdate('web_database', 'database_user_id=NULL', 'database_id', $rec['database_id']);
269+
$app->db->datalogUpdate('web_database', array('database_user_id' => null), 'database_id', $rec['database_id']);
270270

271271
}
272272
$records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE database_ro_user_id = ?", $primary_id);
273273
foreach($records as $rec) {
274-
$app->db->datalogUpdate('web_database', 'database_ro_user_id=NULL', 'database_id', $rec['database_id']);
274+
$app->db->datalogUpdate('web_database', array('database_ro_user_id' => null), 'database_id', $rec['database_id']);
275275
}
276276

277277
return $affected_rows;

interface/lib/classes/remoting_lib.inc.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,22 +238,23 @@ function getDataRecord($primary_id) {
238238
$sql_offset = 0;
239239
$sql_limit = 0;
240240
$sql_where = '';
241+
$params = array($this->formDef['db_table']);
241242
foreach($primary_id as $key => $val) {
242-
$key = $app->db->quote($key);
243-
$val = $app->db->quote($val);
244243
if($key == '#OFFSET#') $sql_offset = $app->functions->intval($val);
245244
elseif($key == '#LIMIT#') $sql_limit = $app->functions->intval($val);
246245
elseif(stristr($val, '%')) {
247-
$sql_where .= "$key like '$val' AND ";
246+
$sql_where .= "? like ? AND ";
248247
} else {
249-
$sql_where .= "$key = '$val' AND ";
248+
$sql_where .= "? = ? AND ";
250249
}
250+
$params[] = $key;
251+
$params[] = $val;
251252
}
252253
$sql_where = substr($sql_where, 0, -5);
253254
if($sql_where == '') $sql_where = '1';
254255
$sql = "SELECT * FROM ?? WHERE ".$sql_where. " AND " . $this->getAuthSQL('r', $this->formDef['db_table']);
255256
if($sql_offset >= 0 && $sql_limit > 0) $sql .= ' LIMIT ' . $sql_offset . ',' . $sql_limit;
256-
return $app->db->queryAllRecords($sql, $this->formDef['db_table']);
257+
return $app->db->queryAllRecords($sql, true, $params);
257258
} else {
258259
$this->errorMessage = 'The ID must be either an integer or an array.';
259260
return array();

interface/lib/classes/tform_base.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ function validateField($field_name, $field_value, $validators) {
11081108
* @param primary_id
11091109
* @return record
11101110
*/
1111+
/* TODO: check for double quoting */
11111112
protected function _getSQL($record, $tab, $action = 'INSERT', $primary_id = 0, $sql_ext_where = '', $api = false) {
11121113

11131114
global $app;

interface/lib/plugins/mail_mail_domain_plugin.inc.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,36 +73,35 @@ function mail_mail_domain_edit($event_name, $page_form) {
7373
$mail_parts = explode("@", $rec['email']);
7474
$maildir = str_replace("[domain]", $page_form->dataRecord['domain'], $mail_config["maildir_path"]);
7575
$maildir = str_replace("[localpart]", $mail_parts[0], $maildir);
76-
$maildir = $app->db->quote($maildir);
77-
$email = $app->db->quote($mail_parts[0].'@'.$page_form->dataRecord['domain']);
78-
$app->db->datalogUpdate('mail_user', "maildir = '$maildir', email = '$email', sys_userid = $client_user_id, sys_groupid = '$sys_groupid'", 'mailuser_id', $rec['mailuser_id']);
76+
$email = $mail_parts[0].'@'.$page_form->dataRecord['domain'];
77+
$app->db->datalogUpdate('mail_user', array("maildir" => $maildir, "email" => $email, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'mailuser_id', $rec['mailuser_id']);
7978
}
8079
}
8180

8281
//* Update the aliases
8382
$forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source LIKE ? OR destination LIKE ?", "%@" . $page_form->oldDataRecord['domain'], "%@" . $page_form->oldDataRecord['domain']);
8483
if(is_array($forwardings)) {
8584
foreach($forwardings as $rec) {
86-
$destination = $app->db->quote(str_replace($page_form->oldDataRecord['domain'], $page_form->dataRecord['domain'], $rec['destination']));
87-
$source = $app->db->quote(str_replace($page_form->oldDataRecord['domain'], $page_form->dataRecord['domain'], $rec['source']));
88-
$app->db->datalogUpdate('mail_forwarding', "source = '$source', destination = '$destination', sys_userid = $client_user_id, sys_groupid = '$sys_groupid'", 'forwarding_id', $rec['forwarding_id']);
85+
$destination = str_replace($page_form->oldDataRecord['domain'], $page_form->dataRecord['domain'], $rec['destination']);
86+
$source = str_replace($page_form->oldDataRecord['domain'], $page_form->dataRecord['domain'], $rec['source']);
87+
$app->db->datalogUpdate('mail_forwarding', array("source" => $source, "destination" => $destination, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'forwarding_id', $rec['forwarding_id']);
8988
}
9089
}
9190

9291
//* Update the mailinglist
9392
$mailing_lists = $app->db->queryAllRecords("SELECT mailinglist_id FROM mail_mailinglist WHERE domain = ?", $page_form->oldDataRecord['domain']);
9493
if(is_array($mailing_lists)) {
9594
foreach($mailing_lists as $rec) {
96-
$app->db->datalogUpdate('mail_mailinglist', "sys_userid = $client_user_id, sys_groupid = '$sys_groupid'", 'mailinglist_id', $rec['mailinglist_id']);
95+
$app->db->datalogUpdate('mail_mailinglist', array("sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'mailinglist_id', $rec['mailinglist_id']);
9796
}
9897
}
9998

10099
//* Update the mailget records
101100
$mail_gets = $app->db->queryAllRecords("SELECT mailget_id, destination FROM mail_get WHERE destination LIKE ?", "%@" . $page_form->oldDataRecord['domain']);
102101
if(is_array($mail_gets)) {
103102
foreach($mail_gets as $rec) {
104-
$destination = $app->db->quote(str_replace($page_form->oldDataRecord['domain'], $page_form->dataRecord['domain'], $rec['destination']));
105-
$app->db->datalogUpdate('mail_get', "destination = '$destination', sys_userid = $client_user_id, sys_groupid = '$sys_groupid'", 'mailget_id', $rec['mailget_id']);
103+
$destination = str_replace($page_form->oldDataRecord['domain'], $page_form->dataRecord['domain'], $rec['destination']);
104+
$app->db->datalogUpdate('mail_get', array("destination" => $destination, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'mailget_id', $rec['mailget_id']);
106105
}
107106
}
108107

0 commit comments

Comments
 (0)