diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql index 71f84b142273d62f9d24baa65efa9f0d045d4343..f2744e5700949a0c5c30c1d6c8e890a8808e2bfa 100644 --- a/install/sql/ispconfig3.sql +++ b/install/sql/ispconfig3.sql @@ -214,6 +214,7 @@ CREATE TABLE `client` ( `default_dbserver` int(11) NOT NULL DEFAULT '1', `dns_servers` blob NOT NULL DEFAULT '', `limit_database` int(11) NOT NULL DEFAULT '-1', + `limit_database_quota` int(11) NOT NULL default '-1', `limit_cron` int(11) NOT NULL DEFAULT '0', `limit_cron_type` enum('url','chrooted','full') NOT NULL DEFAULT 'url', `limit_cron_frequency` int(11) NOT NULL DEFAULT '5', @@ -317,6 +318,7 @@ CREATE TABLE `client_template` ( `limit_dns_slave_zone` int(11) NOT NULL default '-1', `limit_dns_record` int(11) NOT NULL default '-1', `limit_database` int(11) NOT NULL default '-1', + `limit_database_quota` int(11) NOT NULL default '-1', `limit_cron` int(11) NOT NULL default '0', `limit_cron_type` enum('url','chrooted','full') NOT NULL default 'url', `limit_cron_frequency` int(11) NOT NULL default '5', @@ -1757,6 +1759,7 @@ CREATE TABLE `web_database` ( `type` varchar(16) NOT NULL DEFAULT 'y', `database_name` varchar(64) DEFAULT NULL, `database_name_prefix` varchar(50) NOT NULL default '', + `database_quota` int(11) unsigned DEFAULT NULL, `database_user_id` int(11) unsigned DEFAULT NULL, `database_ro_user_id` int(11) unsigned DEFAULT NULL, `database_charset` varchar(64) DEFAULT NULL, diff --git a/install/tpl/server.ini.master b/install/tpl/server.ini.master index 0d578e1582803cc2f9fe4c6f00b5ddeef3d11a4b..0822d20b4fd4bf9da68df07f1bf9a21e25187fbc 100644 --- a/install/tpl/server.ini.master +++ b/install/tpl/server.ini.master @@ -101,6 +101,8 @@ php_ini_check_minutes=1 overquota_notify_admin=y overquota_notify_client=y overquota_notify_freq=7 +overquota_db_notify_admin=y +overquota_db_notify_client=y overquota_notify_onok=n [dns] diff --git a/interface/lib/classes/tools_monitor.inc.php b/interface/lib/classes/tools_monitor.inc.php index fe316cee2e6292d26745209a330edb56a316a4db..db8c91ec2a83eb4ee2e8dc2a6128fef8fcddf565 100644 --- a/interface/lib/classes/tools_monitor.inc.php +++ b/interface/lib/classes/tools_monitor.inc.php @@ -124,32 +124,35 @@ class tools_monitor { $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'database_size' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); if(isset($record['data'])) { $data = unserialize($record['data']); - /* - Format the data - */ + //* format the data $html = '
- - - +
+ '; foreach($data as $line) { $html .= ''; if ($line['size'] > 0) $line['size'] = $app->functions->formatBytes($line['size']); - $t=$app->db->queryOneRecord("SELECT username FROM client WHERE sys_groupid = ".$line['client_id']); - $line['client_id']=$t['username']; - unset($t); + + //* get the client + $line['client']=$app->db->queryOneRecord("SELECT client.username 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='".$line['database_name']."'")['username']; + + //* get the domain + $line['domain']=$app->db->queryOneRecord("SELECT domain FROM web_domain WHERE domain_id=(SELECT parent_domain_id FROM web_database WHERE database_name='".$line['database_name']."')")['domain']; + + //* remove the sys_groupid from output + unset($line['sys_groupid']); + foreach ($line as $item) { $html .= ''; } $html .= ''; } - $html .= '
'.$app->lng("monitor_database_name_txt").' '.$app->lng("monitor_database_size_txt").' '.$app->lng("monitor_database_client_txt").''.$app->lng("monitor_database_domain_txt").'
' . $item . '
'; - $html .= '
'; + $html .= ''; } else { $html = '

'.$app->lng("no_data_database_size_txt").'

'; } diff --git a/interface/web/admin/form/server_config.tform.php b/interface/web/admin/form/server_config.tform.php index 5b270c6b29f324e5644e2b133653820eed4493d6..98337b95a05f267bdd079378d31fdbb0312ba642 100644 --- a/interface/web/admin/form/server_config.tform.php +++ b/interface/web/admin/form/server_config.tform.php @@ -688,6 +688,18 @@ $form["tabs"]['web'] = array( 'default' => 'y', 'value' => array(0 => 'n', 1 => 'y') ), + 'overquota_db_notify_admin' => array( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'y', + 'value' => array(0 => 'n', 1 => 'y') + ), + 'overquota_db_notify_client' => array( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'y', + 'value' => array(0 => 'n', 1 => 'y') + ), 'overquota_notify_freq' => array( 'datatype' => 'INTEGER', 'formtype' => 'TEXT', diff --git a/interface/web/admin/lib/lang/en_server_config.lng b/interface/web/admin/lib/lang/en_server_config.lng index 108437207d06013c8ddbb6391244105d4e61db0f..68f5e454fdeeb2bda5e5354050e966dd522b578f 100644 --- a/interface/web/admin/lib/lang/en_server_config.lng +++ b/interface/web/admin/lib/lang/en_server_config.lng @@ -197,4 +197,6 @@ $wb["v6_prefix_length"] = 'Prefix too long according to defined IPv6 '; $wb['backup_dir_is_mount_txt'] = 'Backup directory is a mount?'; $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounted'; $wb['backup_delete_txt'] = 'Delete backups on domain/website delete'; +$wb["overquota_db_notify_admin_txt"] = 'Send DB quota warnings to admin'; +$wb["overquota_db_notify_client_txt"] = 'Send DB quota warnings to client'; ?> diff --git a/interface/web/admin/templates/server_config_web_edit.htm b/interface/web/admin/templates/server_config_web_edit.htm index ece9d7ddabb86ac78e5b20e82e2dc102811e5dc8..d813952dfcae52a07ac267c5931f9181de97ca2b 100644 --- a/interface/web/admin/templates/server_config_web_edit.htm +++ b/interface/web/admin/templates/server_config_web_edit.htm @@ -125,6 +125,18 @@ {tmpl_var name='overquota_notify_client'} +
+

{tmpl_var name='overquota_db_notify_admin_txt'}

+
+ {tmpl_var name='overquota_db_notify_admin'} +
+
+
+

{tmpl_var name='overquota_db_notify_client_txt'}

+
+ {tmpl_var name='overquota_db_notify_client'} +
+
 {tmpl_var name='overquota_notify_freq_note_txt'} diff --git a/interface/web/client/form/client.tform.php b/interface/web/client/form/client.tform.php index aeb89fe5e69ffc9711e45b4ee152f152ff66c476..a05f95199fcd7637c86beca83dd92ed46c52bb21 100644 --- a/interface/web/client/form/client.tform.php +++ b/interface/web/client/form/client.tform.php @@ -1093,6 +1093,20 @@ $form["tabs"]['limits'] = array ( 'rows' => '', 'cols' => '' ), + 'limit_database_quota' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'ISINT', + 'errmsg'=> 'limit_database_quota_error_notint'), + ), + 'default' => '-1', + 'value' => '', + 'separator' => '', + 'width' => '10', + 'maxlength' => '10', + 'rows' => '', + 'cols' => '' + ), 'limit_cron' => array ( 'datatype' => 'INTEGER', 'formtype' => 'TEXT', diff --git a/interface/web/client/form/client_template.tform.php b/interface/web/client/form/client_template.tform.php index f9d9f6b2c0d499d6c79a19dbe0487aa5bceac352..f55b501d374863dbe42b9be6576cb8bc8a2ff897 100644 --- a/interface/web/client/form/client_template.tform.php +++ b/interface/web/client/form/client_template.tform.php @@ -557,6 +557,20 @@ $form["tabs"]['limits'] = array ( 'rows' => '', 'cols' => '' ), + 'limit_database_quota' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'ISINT', + 'errmsg'=> 'limit_database_quota_error_notint'), + ), + 'default' => '-1', + 'value' => '', + 'separator' => '', + 'width' => '10', + 'maxlength' => '10', + 'rows' => '', + 'cols' => '' + ), 'limit_cron' => array ( 'datatype' => 'INTEGER', 'formtype' => 'TEXT', diff --git a/interface/web/client/lib/lang/en_client.lng b/interface/web/client/lib/lang/en_client.lng index a9565a32e493a2718d4ae3d930dad4f39464a2ed..7e8dd6504a6392187965066ef4bb24130c45b22f 100644 --- a/interface/web/client/lib/lang/en_client.lng +++ b/interface/web/client/lib/lang/en_client.lng @@ -172,4 +172,6 @@ $wb['added_by_txt'] = 'Added by'; $wb['added_date_txt'] = 'Added date'; $wb['parent_client_id_txt'] = 'Client of reseller'; $wb['none_txt'] = 'none'; +$wb['limit_database_quota_txt'] = 'Database quota'; +$wb['limit_database_quota_error_notint'] = 'The database quota limit must be a number.'; ?> diff --git a/interface/web/client/lib/lang/en_client_template.lng b/interface/web/client/lib/lang/en_client_template.lng index 0eef4700bf0bb88c39a12d7b072debb9d418d0ee..3c6691dc2b4f2012cb77a707e36161ddd602393f 100644 --- a/interface/web/client/lib/lang/en_client_template.lng +++ b/interface/web/client/lib/lang/en_client_template.lng @@ -89,5 +89,7 @@ $wb['aps_limits_txt'] = 'APS Installer Limits'; $wb['limit_aps_txt'] = 'Max. number of APS instances'; $wb['limit_aps_error_notint'] = 'The APS instances limit must be a number.'; $wb['limit_domainmodule_txt'] = 'Domainmodule Limit'; -$wb['client_limits_txt'] = 'Client Limits' -?> \ No newline at end of file +$wb['client_limits_txt'] = 'Client Limits'; +$wb['limit_database_quota_txt'] = 'Database quota'; +$wb['limit_database_quota_error_notint'] = 'The database quota limit must be a number.'; +?> diff --git a/interface/web/client/templates/client_edit_limits.htm b/interface/web/client/templates/client_edit_limits.htm index c97e03f53e225366f0477ebb9f9cd85d0a9f51d8..01dae6405d04960ce96b8bfdbeb32cd8e7bf839c 100644 --- a/interface/web/client/templates/client_edit_limits.htm +++ b/interface/web/client/templates/client_edit_limits.htm @@ -229,6 +229,10 @@
+
+ +  MB +
{tmpl_var name='cron_job_limits_txt'}
diff --git a/interface/web/client/templates/client_template_edit_limits.htm b/interface/web/client/templates/client_template_edit_limits.htm index 1eea39900407dba216fc2f6761236cbd7012316a..244014649261d77c27b67c41fa44fed12978de97 100644 --- a/interface/web/client/templates/client_template_edit_limits.htm +++ b/interface/web/client/templates/client_template_edit_limits.htm @@ -171,6 +171,10 @@
+
+ +  MB +
{tmpl_var name='cron_job_limits_txt'}
@@ -247,4 +251,4 @@
- \ No newline at end of file + diff --git a/interface/web/sites/database_edit.php b/interface/web/sites/database_edit.php index 22493515bbffe9680c5cbfa250f8791f66dd3592..6ae8856ec5b92055c594deb14a8e4d178cc0aa1e 100644 --- a/interface/web/sites/database_edit.php +++ b/interface/web/sites/database_edit.php @@ -166,7 +166,7 @@ class page_action extends tform_actions { if($_SESSION["s"]["user"]["typ"] != 'admin') { // Get the limits of the client $client_group_id = $_SESSION["s"]["user"]["default_group"]; - $client = $app->db->queryOneRecord("SELECT db_servers, limit_database FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); + $client = $app->db->queryOneRecord("SELECT db_servers, limit_database, limit_database_quota FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.groupid = $client_group_id"); // When the record is updated if($this->id > 0) { @@ -191,6 +191,20 @@ class page_action extends tform_actions { } } + // Check client quota + if ($client['limit_database_quota'] >= 0) { + $tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = $client_group_id"); + $db_quota = $tmp['db_quota']; + $new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]); + if(($db_quota + $new_db_quota > $client['limit_database_quota']) || ($new_db_quota < 0 && $client['limit_database_quota'] >= 0)) { + $max_free_quota = floor($client['limit_database_quota'] - $db_quota); + if($max_free_quota < 0) $max_free_quota = 0; + $app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB
"; + $this->dataRecord['database_quota'] = $max_free_quota; + } + unset($tmp); + } + } } else { // check if client of database parent domain is client of db user! diff --git a/interface/web/sites/form/database.tform.php b/interface/web/sites/form/database.tform.php index 5207fd5b38cfda45795b90ffa73f4aefb625a047..79b0a96c7ed9cfeef60f68c8a9061059c95fc38f 100644 --- a/interface/web/sites/form/database.tform.php +++ b/interface/web/sites/form/database.tform.php @@ -79,7 +79,7 @@ $form["tabs"]['database'] = array ( 'formtype' => 'SELECT', 'default' => '', 'datasource' => array ( 'type' => 'SQL', - 'querystring' => "SELECT web_domain.domain_id, CONCAT(web_domain.domain, ' :: ', server.server_name) AS parent_domain FROM web_domain, server WHERE web_domain.type = 'vhost' AND web_domain.server_id = server.server_id AND {AUTHSQL::web_domain} ORDER BY web_domain.domain", + 'querystring' => "SELECT web_domain.domain_id, CONCAT(web_domain.domain, ' :: ', server.server_name) AS parent_domain FROM web_domain, server WHERE web_domain.type = 'vhost' AND web_domain.server_id = server.server_id AND {AUTHSQL} ORDER BY web_domain.domain", 'keyfield'=> 'domain_id', 'valuefield'=> 'parent_domain' ), @@ -117,6 +117,20 @@ $form["tabs"]['database'] = array ( 'width' => '30', 'maxlength' => '25' ), + 'database_quota' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'ISINT', + 'errmsg'=> 'limit_database_quota_error_notint'), + ), + 'default' => '-1', + 'value' => '', + 'separator' => '', + 'width' => '10', + 'maxlength' => '10', + 'rows' => '', + 'cols' => '' + ), 'database_user_id' => array ( 'datatype' => 'INTEGER', 'formtype' => 'SELECT', diff --git a/interface/web/sites/lib/lang/en_database.lng b/interface/web/sites/lib/lang/en_database.lng index 521e8c40fad3bb0f8a2e556ee26f1bb1d5108a76..e29f5b6be5b2d1b831c6c4f529f3bed2b4a91b5d 100644 --- a/interface/web/sites/lib/lang/en_database.lng +++ b/interface/web/sites/lib/lang/en_database.lng @@ -43,4 +43,7 @@ $wb['globalsearch_noresults_text_txt'] = "No results."; $wb['globalsearch_noresults_limit_txt'] = "0 results"; $wb['globalsearch_searchfield_watermark_txt'] = "Search"; $wb['globalsearch_suggestions_text_txt'] = "Suggestions"; +$wb['limit_database_quota_txt'] = 'Database quota'; +$wb['limit_database_quota_error_notint'] = 'The database quota limit must be a number.'; +$wb['limit_database_quota_free_txt']='Max. available DB quota '; ?> diff --git a/interface/web/sites/templates/database_edit.htm b/interface/web/sites/templates/database_edit.htm index 6b7afc94b0b1e11ef89446ca84baef38f718a2fc..3e1489cf92990eb7d1a3f2ee5c62353e1caf4a88 100644 --- a/interface/web/sites/templates/database_edit.htm +++ b/interface/web/sites/templates/database_edit.htm @@ -62,6 +62,10 @@ +
+ +  MB +