Skip to content

Commit 35b30fa

Browse files
author
Marius Cramer
committed
Merge branch 'master' into 'master'
Master
2 parents cd9e802 + 623d691 commit 35b30fa

14 files changed

+247
-27
lines changed

interface/web/dns/dns_dkim_edit.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ function onShowNew() {
5858

5959
// Get the limits of the client
6060
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
61-
$client = $app->db->queryOneRecord("SELECT limit_dns_record FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
61+
$client = $app->db->queryOneRecord("SELECT limit_dns_record FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
6262

6363
// Check if the user may add another record.
6464
if($client["limit_dns_record"] >= 0) {
65-
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = $client_group_id");
65+
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = ?", $client_group_id);
6666
if($tmp["number"] >= $client["limit_dns_record"]) {
6767
$app->error($app->tform->wordbook["limit_dns_record_txt"]);
6868
}
@@ -75,18 +75,18 @@ function onShowNew() {
7575
function onSubmit() {
7676
global $app, $conf;
7777
// Get the parent soa record of the domain
78-
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = '".$app->functions->intval($_POST["zone"])."' AND ".$app->tform->getAuthSQL('r'));
78+
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND ".$app->tform->getAuthSQL('r'), $app->functions->intval($_POST["zone"]));
7979
// Check if Domain belongs to user
8080
if($soa["id"] != $_POST["zone"]) $app->tform->errorMessage .= $app->tform->wordbook["no_zone_perm"];
8181

8282
// Check the client limits, if user is not the admin
8383
if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
8484
// Get the limits of the client
8585
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
86-
$client = $app->db->queryOneRecord("SELECT limit_dns_record FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
86+
$client = $app->db->queryOneRecord("SELECT limit_dns_record FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
8787
// Check if the user may add another record.
8888
if($this->id == 0 && $client["limit_dns_record"] >= 0) {
89-
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = $client_group_id");
89+
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = ?", $client_group_id);
9090
if($tmp["number"] >= $client["limit_dns_record"]) {
9191
$app->error($app->tform->wordbook["limit_dns_record_txt"]);
9292
}
@@ -101,12 +101,12 @@ function onSubmit() {
101101
$this->dataRecord['name']='default._domainkey.'.$this->dataRecord['name'];
102102

103103
// Update the serial number and timestamp of the RR record
104-
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
104+
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ?", $this->id);
105105
$this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
106106
$this->dataRecord["stamp"] = date('Y-m-d H:i:s');
107107

108108
// check for duplicate entry
109-
$check=$app->db->queryOneRecord("SELECT * FROM dns_rr WHERE zone = ".$this->dataRecord["zone"]." AND type = '".$this->dataRecord["type"]."' AND data ='".$this->dataRecord["data"]."' AND name = '".$this->dataRecord['name']."'");
109+
$check=$app->db->queryOneRecord("SELECT * FROM dns_rr WHERE zone = ? AND type = ? AND data = ? AND name = ?", $this->dataRecord['zone'], $this->dataRecord['type'], $this->dataRecord['data'], $this->dataRecord['name']);
110110
if ($check!='') $app->tform->errorMessage .= $app->tform->wordbook["record_exists_txt"];
111111
if (empty($this->dataRecord['data'])) $app->tform->errorMessage .= $app->tform->wordbook["dkim_disabled_txt"];
112112
parent::onSubmit();
@@ -116,7 +116,7 @@ function onAfterInsert() {
116116
global $app, $conf;
117117

118118
//* Set the sys_groupid of the rr record to be the same then the sys_groupid of the soa record
119-
$soa = $app->db->queryOneRecord("SELECT sys_groupid,serial FROM dns_soa WHERE id = '".$app->functions->intval($this->dataRecord["zone"])."' AND ".$app->tform->getAuthSQL('r'));
119+
$soa = $app->db->queryOneRecord("SELECT sys_groupid,serial FROM dns_soa WHERE id = ? AND ".$app->tform->getAuthSQL('r'), $app->functions->intval($this->dataRecord['zone']));
120120
$app->db->datalogUpdate('dns_rr', "sys_groupid = ".$soa['sys_groupid'], 'id', $this->id);
121121

122122
//* Update the serial number of the SOA record
@@ -129,7 +129,7 @@ function onAfterUpdate() {
129129
global $app, $conf;
130130

131131
//* Update the serial number of the SOA record
132-
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = '".$app->functions->intval($this->dataRecord["zone"])."' AND ".$app->tform->getAuthSQL('r'));
132+
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ? AND ".$app->tform->getAuthSQL('r'), $app->functions->intval($this->dataRecord["zone"]));
133133
$soa_id = $app->functions->intval($_POST["zone"]);
134134
$serial = $app->validate_dns->increase_serial($soa["serial"]);
135135
$app->db->datalogUpdate('dns_soa', "serial = $serial", 'id', $soa_id);

interface/web/dns/dns_dkim_get.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ function pub_key($pubkey) {
8282

8383
if (ctype_digit($_POST['zone'])) {
8484
// Get the parent soa record of the domain
85-
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = '".$app->db->quote($_POST['zone'])."' AND ".$app->tform->getAuthSQL('r'));
85+
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND ".$app->tform->getAuthSQL('r'), $_POST['zone']);
8686

87-
$public_key=$app->db->queryOneRecord("SELECT dkim_public FROM mail_domain WHERE domain = '".substr_replace($soa['origin'],'',-1)."' AND dkim = 'Y' AND ".$app->tform->getAuthSQL('r'));
87+
$public_key=$app->db->queryOneRecord("SELECT dkim_public FROM mail_domain WHERE domain = ? AND dkim = 'Y' AND ".$app->tform->getAuthSQL('r'), substr_replace($soa['origin'],'',-1));
8888

8989
$public_key=pub_key($public_key);
9090

interface/web/dns/dns_wizard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
$public_key=$app->db->queryOneRecord("SELECT dkim_public FROM mail_domain WHERE domain = '".$app->db->quote($_POST['domain'])."' AND dkim = 'y' AND ".$app->tform->getAuthSQL('r'));
249249
if ($public_key!='') {
250250
$dns_record=str_replace(array("\r\n", "\n", "\r", "-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----"), '', $public_key['dkim_public']);
251-
$tpl_content = str_replace('TXT|'.$_POST['domain'].'.|{DKIM}', 'TXT|default._domainkey.'.$_POST['domain'].'.|v=DKIM1; t=s; p='.$dns_record, $tpl_content);
251+
$tpl_content = str_replace('TXT|'.$_POST['domain'].'|{DKIM}', 'TXT|default._domainkey.'.$_POST['domain'].'.|v=DKIM1; t=s; p='.$dns_record, $tpl_content);
252252
}
253253
}
254254

interface/web/mail/mail_user_edit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ function onAfterUpdate() {
323323

324324
//* Change backup options when user mail backup options have been changed
325325
if(isset($this->dataRecord['backup_interval']) && ($this->dataRecord['backup_interval'] != $this->oldDataRecord['backup_interval'] || $this->dataRecord['backup_copies'] != $this->oldDataRecord['backup_copies'])) {
326-
$backup_interval = $this->dataRecord['backup_interval'];
327-
$backup_copies = $this->dataRecord['backup_copies'];
326+
$backup_interval = $app->db->quote($this->dataRecord['backup_interval']);
327+
$backup_copies = $app->functions->intval($this->dataRecord['backup_copies']);
328328
$app->db->datalogUpdate('mail_user', "backup_interval = '$backup_interval', backup_copies = '$backup_copies'", 'mailuser_id', $rec['mailuser_id']);
329329
unset($backup_copies);
330330
unset($backup_interval);

interface/web/sites/database_edit.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function onShowEnd() {
7373

7474
// Get the limits of the client
7575
$client_group_id = $_SESSION["s"]["user"]["default_group"];
76-
$client = $app->db->queryOneRecord("SELECT db_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
76+
$client = $app->db->queryOneRecord("SELECT db_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
7777

7878
// Set the webserver to the default server of the client
7979
$tmp = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE server_id IN ($client[db_servers])");
@@ -96,7 +96,7 @@ function onShowEnd() {
9696

9797
// Get the limits of the client
9898
$client_group_id = $_SESSION["s"]["user"]["default_group"];
99-
$client = $app->db->queryOneRecord("SELECT client.client_id, limit_web_domain, db_servers, contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
99+
$client = $app->db->queryOneRecord("SELECT client.client_id, limit_web_domain, db_servers, contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
100100

101101
// Set the webserver to the default server of the client
102102
$tmp = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE server_id IN ($client[db_servers])");
@@ -150,6 +150,7 @@ function onShowEnd() {
150150
$app->tpl->setVar("edit_disabled", 1);
151151
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]);
152152
$app->tpl->setVar("database_charset_value", $this->dataRecord["database_charset"]);
153+
$app->tpl->setVar("limit_database_quota", $this->dataRecord["database_quota"]);
153154
} else {
154155
$app->tpl->setVar("edit_disabled", 0);
155156
}
@@ -171,9 +172,31 @@ function onSubmit() {
171172
// When the record is updated
172173
if($this->id > 0) {
173174
// restore the server ID if the user is not admin and record is edited
174-
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE database_id = ".$app->functions->intval($this->id));
175+
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE database_id = ?", $app->functions->intval($this->id));
175176
$this->dataRecord["server_id"] = $tmp["server_id"];
176177
unset($tmp);
178+
//* Check client quota
179+
if ($client['limit_database_quota'] >= 0) {
180+
//* get the database prefix
181+
$app->uses('getconf,tools_sites');
182+
$global_config = $app->getconf->get_global_config('sites');
183+
$dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord);
184+
//* get quota from other databases
185+
$tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = ? AND database_name <> ?", $client_group_id, $dbname_prefix.$this->dataRecord['database_name']);
186+
$used_quota = $app->functions->intval($tmp['db_quota']);
187+
$new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]);
188+
if(($used_quota + $new_db_quota > $client['limit_database_quota']) || ($new_db_quota < 0 && $client['limit_database_quota'] >= 0)) {
189+
$max_free_quota = floor($client['limit_database_quota'] - $used_quota);
190+
if($max_free_quota < 0) {
191+
$max_free_quota = 0;
192+
}
193+
$app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB<br>";
194+
$this->dataRecord['database_quota'] = $max_free_quota;
195+
}
196+
unset($tmp);
197+
unset($global_config);
198+
unset($dbname_prefix);
199+
}
177200
// When the record is inserted
178201
} else {
179202
$client['db_servers_ids'] = explode(',', $client['db_servers']);
@@ -185,15 +208,15 @@ function onSubmit() {
185208

186209
// Check if the user may add another database
187210
if($client["limit_database"] >= 0) {
188-
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = $client_group_id");
211+
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = ?", $client_group_id);
189212
if($tmp["number"] >= $client["limit_database"]) {
190213
$app->error($app->tform->wordbook["limit_database_txt"]);
191214
}
192215
}
193216

194-
// Check client quota
195-
if ($client['limit_database_quota'] >= 0) {
196-
$tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = $client_group_id");
217+
//* Check client quota
218+
if ($client['limit_database_quota'] >= 0) {
219+
$tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = ?", $client_group_id);
197220
$db_quota = $tmp['db_quota'];
198221
$new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]);
199222
if(($db_quota + $new_db_quota > $client['limit_database_quota']) || ($new_db_quota < 0 && $client['limit_database_quota'] >= 0)) {
@@ -300,7 +323,7 @@ function onBeforeUpdate() {
300323
}
301324
*/
302325

303-
if($this->dataRecord['remote_access'] != 'y'){
326+
if(isset($this->dataRecord['remote_access']) && $this->dataRecord['remote_access'] != 'y'){
304327
$this->dataRecord['remote_ips'] = $server_config['ip_address'];
305328
$this->dataRecord['remote_access'] = 'y';
306329
} else {
@@ -387,7 +410,7 @@ function onBeforeInsert() {
387410
}
388411
*/
389412

390-
if($this->dataRecord['remote_access'] != 'y'){
413+
if(isset($this->dataRecord['remote_access']) && $this->dataRecord['remote_access'] != 'y'){
391414
$this->dataRecord['remote_ips'] = $server_config['ip_address'];
392415
$this->dataRecord['remote_access'] = 'y';
393416
} else {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
require_once '../../lib/config.inc.php';
3+
require_once '../../lib/app.inc.php';
4+
5+
/******************************************
6+
* Begin Form configuration
7+
******************************************/
8+
9+
$list_def_file = "list/database_quota_stats.list.php";
10+
11+
/******************************************
12+
* End Form configuration
13+
******************************************/
14+
15+
//* Check permissions for module
16+
$app->auth->check_module_permissions('mail');
17+
18+
$app->load('listform_actions','functions');
19+
20+
$tmp_rec = $app->db->queryOneRecord("SELECT data from monitor_data WHERE type = 'database_size' ORDER BY created DESC");
21+
$monitor_data = array();
22+
$tmp_array = unserialize($tmp_rec['data']);
23+
24+
foreach($tmp_array as $database_name => $data) {
25+
$db_name = $data['database_name'];
26+
27+
$temp = $app->db->queryOneRecord("SELECT client.username, web_database.database_quota FROM web_database, sys_group, client WHERE web_database.sys_groupid = sys_group.groupid AND sys_group.client_id = client.client_id AND web_database.database_name = ?'", $db_name);
28+
29+
$monitor_data[$db_name]['database_name'] = $data['database_name'];
30+
$monitor_data[$db_name]['client']=$temp['username'];
31+
$monitor_data[$db_name]['used'] = $data['size'];
32+
$monitor_data[$db_name]['quota']=$temp['database_quota'];
33+
34+
unset($temp);
35+
}
36+
37+
class list_action extends listform_actions {
38+
39+
function prepareDataRow($rec) {
40+
global $app, $monitor_data;
41+
42+
$rec = $app->listform->decode($rec);
43+
44+
//* Alternating datarow colors
45+
$this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF';
46+
$rec['bgcolor'] = $this->DataRowColor;
47+
48+
$database_name = $rec['database_name'];
49+
50+
$rec['database'] = isset($monitor_data[$database_name]['database_name']) ? $monitor_data[$database_name]['database_name'] : array(1 => 0);
51+
$rec['client'] = isset($monitor_data[$database_name]['client']) ? $monitor_data[$database_name]['client'] : array(1 => 0);
52+
$rec['used'] = isset($monitor_data[$database_name]['used']) ? $monitor_data[$database_name]['used'] : array(1 => 0);
53+
$rec['quota'] = isset($monitor_data[$database_name]['quota']) ? $monitor_data[$database_name]['quota'] : array(1 => 0);
54+
55+
if (!is_numeric($rec['used'])) $rec['used']=$rec['used'][1];
56+
57+
if($rec['quota'] == 0){
58+
$rec['quota'] = $app->lng('unlimited');
59+
$rec['percentage'] = '';
60+
} else {
61+
$rec['percentage'] = round(100 * $rec['used'] / ( $rec['quota']*1024*1024) ).'%';
62+
$rec['quota'] .= ' MB';
63+
}
64+
65+
if ($rec['used'] > 0) $rec['used'] = $app->functions->formatBytes($rec['used']);
66+
67+
$rec['id'] = $rec[$this->idx_key];
68+
return $rec;
69+
70+
}
71+
72+
}
73+
74+
$list = new list_action;
75+
$list->SQLExtWhere = "";
76+
77+
$list->onLoad();
78+
79+
?>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb["database_txt"] = 'Database';
3+
$wb["client_txt"] = 'Client';
4+
$wb["used_txt"] = 'Used space';
5+
$wb["quota_txt"] = 'Quota';
6+
$wb["percentage_txt"] = 'Used in %';
7+
?>

interface/web/sites/lib/module.conf.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@
184184
'link' => 'sites/user_quota_stats.php',
185185
'html_id' => 'user_quota_stats');
186186

187+
$items[] = array( 'title' => 'Database quota',
188+
'target' => 'content',
189+
'link' => 'sites/database_quota_stats.php',
190+
'html_id' => 'databse_quota_stats');
191+
187192
$module['nav'][] = array( 'title' => 'Statistics',
188193
'open' => 1,
189194
'items' => $items);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
// Name of the list
4+
$liste["name"] = "database_quota_stats";
5+
6+
// Database table
7+
$liste["table"] = "web_database";
8+
9+
// Index index field of the database table
10+
$liste["table_idx"] = "database_id";
11+
12+
// Search Field Prefix
13+
$liste["search_prefix"] = "search_";
14+
15+
// Records per page
16+
$liste["records_per_page"] = "15";
17+
18+
// Script File of the list
19+
$liste["file"] = "database_quota_stats.php";
20+
21+
// Script file of the edit form
22+
$liste["edit_file"] = "database_edit.php";
23+
24+
// Paging Template
25+
$liste["paging_tpl"] = "templates/paging.tpl.htm";
26+
27+
// Enable auth
28+
$liste["auth"] = "yes";
29+
30+
// mark columns for php sorting (no real mySQL columns)
31+
$liste["phpsort"] = array('used_sort', 'files');
32+
33+
34+
/*****************************************************
35+
* Suchfelder
36+
*****************************************************/
37+
38+
//$liste["item"][] = array( 'field' => "domain",
39+
$liste["item"][] = array( 'field' => "database_name",
40+
'datatype' => "VARCHAR",
41+
'filters' => array( 0 => array( 'event' => 'SHOW',
42+
'type' => 'IDNTOUTF8')
43+
),
44+
'formtype' => "TEXT",
45+
'op' => "like",
46+
'prefix' => "%",
47+
'suffix' => "%",
48+
'width' => "",
49+
'value' => ""
50+
);
51+
52+
?>

0 commit comments

Comments
 (0)