From cfa94c58379905e85f8c0a57ce95534e91a2369f Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sat, 18 Jun 2011 19:03:20 +0200 Subject: [PATCH 01/10] Added new settings for disk quota, refs #814 Signed-off-by: Florian Aders (EleRas) --- install/froxlor.sql | 9 ++++-- .../updates/froxlor/0.9/update_0.9.inc.php | 32 +++++++++++++------ lib/tables.inc.php | 2 +- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/install/froxlor.sql b/install/froxlor.sql index 8c711708..7a1c9030 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -468,7 +468,7 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('syste INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'vmail_homedir', '/var/customers/mail/'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'bindconf_directory', '/etc/bind/'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'bindreload_command', '/etc/init.d/bind9 reload'); -INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('panel', 'version', '0.9.21'); +INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('panel', 'version', '0.9.22-svn1'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'hostname', 'SERVERNAME'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('login', 'maxloginattempts', '3'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('login', 'deactivatetime', '900'); @@ -632,6 +632,11 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('syste INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'backup_ftp_user', ''); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'backup_ftp_pass', ''); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'backup_ftp_passive', '1'); +INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_enabled', '0'); +INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_repquota_path', '/usr/sbin/repquota'); +INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_quotatool_path', '/usr/bin/quotatool'); +INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_customer_partition', '/dev/root'); + # -------------------------------------------------------- # @@ -1019,7 +1024,7 @@ CREATE TABLE IF NOT EXISTS `aps_temp_settings` ( DROP TABLE IF EXISTS `cronjobs_run`; CREATE TABLE IF NOT EXISTS `cronjobs_run` ( `id` bigint(20) NOT NULL auto_increment, - `module` varchar(250) NOT NULL, + `module` varchar(250) NOT NULL, `cronfile` varchar(250) NOT NULL, `lastrun` int(15) NOT NULL DEFAULT '0', `interval` varchar(100) NOT NULL DEFAULT '5 MINUTE', diff --git a/install/updates/froxlor/0.9/update_0.9.inc.php b/install/updates/froxlor/0.9/update_0.9.inc.php index 4d6fcab1..f068bda9 100644 --- a/install/updates/froxlor/0.9/update_0.9.inc.php +++ b/install/updates/froxlor/0.9/update_0.9.inc.php @@ -1382,7 +1382,7 @@ if(isFroxlorVersion('0.9.16')) } $check = $db->query_first("SELECT `varname` FROM `" . TABLE_PANEL_TEMPLATES . "` WHERE `varname`='trafficninetypercent_mailbody';"); if(isset($check['varname']) && $check['varname'] == 'trafficninetypercent_mailbody') - { + { $db->query("UPDATE `" . TABLE_PANEL_TEMPLATES . "` SET `varname` = 'trafficmaxpercent_mailbody' WHERE `varname`='trafficninetypercent_mailbody';"); } lastStepStatus(0); @@ -1400,7 +1400,7 @@ if(isFroxlorVersion('0.9.17-svn1')) `fid` int(11) NOT NULL, `docrootsettings` text NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM;"); +) ENGINE=MyISAM;"); $db->query("CREATE TABLE IF NOT EXISTS `domain_docrootsettings` ( `id` int(5) NOT NULL auto_increment, `fid` int(11) NOT NULL, @@ -1495,11 +1495,11 @@ if(isFroxlorVersion('0.9.19')) { showUpdateStep("Updating from 0.9.19 to 0.9.20-svn1"); lastStepStatus(0); - + showUpdateStep("Adding new setting for domain validation"); $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('system', 'validate_domain', '1')"); lastStepStatus(0); - + updateToVersion('0.9.20-svn1'); } @@ -1549,7 +1549,7 @@ if(isFroxlorVersion('0.9.20.1')) lastStepStatus(0); showUpdateStep("Fixing possible broken tables"); - + // The customer-table may miss the columns, if installed a fresh 0.9.20 or 0.9.20.1 - add them $result = $db->query("DESCRIBE `" . TABLE_PANEL_CUSTOMERS . "`"); $columnfound = 0; @@ -1593,7 +1593,7 @@ if(isFroxlorVersion('0.9.20.1-svn1') || isFroxlorVersion('0.9.20.2-svn1')) // add table column for gender $db->query("ALTER TABLE `" . TABLE_PANEL_CUSTOMERS . "` ADD `gender` INT( 1 ) NOT NULL DEFAULT '0' AFTER `firstname`"); - + lastStepStatus(0); @@ -1604,10 +1604,10 @@ if(isFroxlorVersion('0.9.21-svn1')) { showUpdateStep("Updating from 0.9.21-svn1 to 0.9.21-svn2"); lastStepStatus(0); - + /* add new setting: backup FTP mode */ $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('system', 'backup_ftp_passive', '1')"); - + lastStepStatus(0); updateToVersion('0.9.21-svn2'); @@ -1617,6 +1617,20 @@ if(isFroxlorVersion('0.9.21-svn2')) { showUpdateStep("Updating from 0.9.21-svn2 to 0.9.21"); lastStepStatus(0); - + updateToVersion('0.9.21'); } + +if(isFroxlorVersion('0.9.21')) +{ + showUpdateStep("Updating from 0.9.21 to 0.9.22-svn1"); + lastStepStatus(0); + + /* add new settings for diskspacequota - support */ + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_enabled', '0');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_repquota_path', '/usr/sbin/repquota');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_quotatool_path', '/usr/bin/quotatool');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_customer_partition', '/dev/root');"); + + updateToVersion('0.9.22-svn1'); +} diff --git a/lib/tables.inc.php b/lib/tables.inc.php index e6c9ae36..44465169 100644 --- a/lib/tables.inc.php +++ b/lib/tables.inc.php @@ -73,6 +73,6 @@ define('PACKAGE_ENABLED', 2); // VERSION INFO -$version = '0.9.21'; +$version = '0.9.22-svn1'; $dbversion = '2'; $branding = ''; From 7a28108475c0107769bf5e3886df8f2740424ded Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sat, 18 Jun 2011 19:42:01 +0200 Subject: [PATCH 02/10] Added usage of filesystem - quota to diskusage - calculation and added a new task to cron_tasks.php for setting the quota, refs #814 Signed-off-by: Florian Aders (EleRas) --- lng/english.lng.php | 7 +++ lng/german.lng.php | 7 +++ scripts/jobs/cron_tasks.php | 97 +++++++++++++++++++++++++++++------ scripts/jobs/cron_traffic.php | 79 ++++++++++++++++++++-------- 4 files changed, 155 insertions(+), 35 deletions(-) diff --git a/lng/english.lng.php b/lng/english.lng.php index 42cc1ece..d3fd6b87 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1877,3 +1877,10 @@ $lng['country']['EH'] = "Western Sahara"; $lng['country']['YE'] = "Yemen"; $lng['country']['ZM'] = "Zambia"; $lng['country']['ZW'] = "Zimbabwe"; + +// ADDED IN FROXLOR 0.9.22-svn1 +$lng['diskquota'] = 'Quota'; +$lng['serversettings']['diskquota_enabled'] = 'Quota activated?'; +$lng['serversettings']['diskquota_repquota_path']['description'] = 'Path to the repquota - tool'; +$lng['serversettings']['diskquota_quotatool_path']['description'] = 'Path to quotatool'; +$lng['serversettings']['diskquota_customer_partition']['description'] = 'Partition, on which the customer files are stored'; \ No newline at end of file diff --git a/lng/german.lng.php b/lng/german.lng.php index b5c46ced..50ce1386 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1608,3 +1608,10 @@ $lng['gender']['female'] = 'Frau'; $lng['gender']['undef'] = ''; $lng['serversettings']['backup_ftp_passive_mode'] = 'Passiven Übertragungsmodus verwenden'; $lng['serversettings']['backup_bigfile'] = 'Backup von Kundenverzeichnissen und Datenbanken in eine Datei speichern, statt zu splitten?'; + +// ADDED IN FROXLOR 0.9.22-svn1 +$lng['diskquota'] = 'Quota'; +$lng['serversettings']['diskquota_enabled'] = 'Quota aktiviert?'; +$lng['serversettings']['diskquota_repquota_path']['description'] = 'Pfad zu dem repquota - Tool'; +$lng['serversettings']['diskquota_quotatool_path']['description'] = 'Pfad zu quotatool'; +$lng['serversettings']['diskquota_customer_partition']['description'] = 'Partition, auf welcher die Kundendaten liegen'; \ No newline at end of file diff --git a/scripts/jobs/cron_tasks.php b/scripts/jobs/cron_tasks.php index b1dc7ab0..7bd1e055 100644 --- a/scripts/jobs/cron_tasks.php +++ b/scripts/jobs/cron_tasks.php @@ -64,7 +64,7 @@ while($row = $db->fetch_array($result_tasks)) * (e.g. awstats not installed yet or whatever) * fixes #45 */ - if (is_dir($awstatsclean['path'])) + if (is_dir($awstatsclean['path'])) { $awstatsclean['dir'] = dir($awstatsclean['path']); while($awstatsclean['entry'] = $awstatsclean['dir']->read()) { @@ -98,7 +98,7 @@ while($row = $db->fetch_array($result_tasks)) { $configdir = makeCorrectDir($settings['system']['mod_fcgid_configdir']); - if (is_dir($configdir)) + if (is_dir($configdir)) { $its = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($configdir) @@ -108,14 +108,14 @@ while($row = $db->fetch_array($result_tasks)) // look for php-fcgi-starter files // and take immutable-flag away from them // so we can delete them :) - foreach ($its as $fullFileName => $it ) + foreach ($its as $fullFileName => $it ) { - if ($it->isFile() && $it->getFilename() == 'php-fcgi-starter') + if ($it->isFile() && $it->getFilename() == 'php-fcgi-starter') { removeImmutable($its->getPathname()); } } - // now get rid of old stuff + // now get rid of old stuff //(but append /* so we don't delete the directory) $configdir.='/*'; safe_exec('rm -rf '. makeCorrectFile($configdir)); @@ -127,9 +127,9 @@ while($row = $db->fetch_array($result_tasks)) { $configdir = makeCorrectDir($settings['phpfpm']['configdir']); - if (is_dir($configdir)) + if (is_dir($configdir)) { - // now get rid of old stuff + // now get rid of old stuff //(but append /* so we don't delete the directory) $configdir.='/*'; safe_exec('rm -rf '. makeCorrectFile($configdir)); @@ -211,7 +211,7 @@ while($row = $db->fetch_array($result_tasks)) $cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: mkdir -p ' . escapeshellarg($userhomedir . 'webalizer')); safe_exec('mkdir -p ' . escapeshellarg($userhomedir . 'webalizer')); } - + // maildir $cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: mkdir -p ' . escapeshellarg($usermaildir)); safe_exec('mkdir -p ' . escapeshellarg($usermaildir)); @@ -318,8 +318,8 @@ while($row = $db->fetch_array($result_tasks)) { // e.g. /var/www/php-fcgi-starter/web1/ $configdir = makeCorrectDir($settings['system']['mod_fcgid_configdir'] . '/' . $row['data']['loginname'] . '/'); - - if (is_dir($configdir)) + + if (is_dir($configdir)) { $its = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($configdir) @@ -329,16 +329,16 @@ while($row = $db->fetch_array($result_tasks)) // look for php-fcgi-starter files // and take immutable-flag away from them // so we can delete them :) - foreach ($its as $fullFileName => $it ) + foreach ($its as $fullFileName => $it ) { - if ($it->isFile() && $it->getFilename() == 'php-fcgi-starter') + if ($it->isFile() && $it->getFilename() == 'php-fcgi-starter') { removeImmutable($its->getPathname()); } } // now get rid of old stuff safe_exec('rm -rf '. escapeshellarg($configdir)); - } + } } } } @@ -409,7 +409,7 @@ while($row = $db->fetch_array($result_tasks)) */ elseif ($row['type'] == '9') { - + fwrite($debugHandler, ' cron_tasks: Task9 started - creating backup dir protection' . "\n"); $cronlog->logAction(CRON_ACTION, LOG_INFO, 'Task9 started - creating backup dir protection'); @@ -457,7 +457,74 @@ while($row = $db->fetch_array($result_tasks)) } } } - + + } + } + + /** + * TYPE=10 Set the filesystem - quota + */ + elseif ($row['type'] == '10') + { + if ($settings['system']['diskquota_enabled']) + { + fwrite($debugHandler, ' cron_tasks: Task10 started - setting filesystem quota' . "\n"); + $cronlog->logAction(CRON_ACTION, LOG_INFO, 'Task10 started - setting filesystem quota'); + + # Fetch all quota in the desired partition + exec($settings['system']['diskquota_repquota_path'] . " -n " . escapeshellarg($settings['system']['diskquota_customer_partition']), $repquota); + + $usedquota = array(); + foreach ($repquota as $tmpquota) + { + # Let's see if the line matches a quota - line + if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\ddays)?\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) + { + # It matches - put it into an array with userid as key (for easy lookup later) + $usedquota[$matches[1]] = array( + 'block' => array( + 'used' => $matches[2], + 'soft' => $matches[3], + 'hard' => $matches[4], + 'grace' => $matches[5] + ), + 'file' => array( + 'used' => $matches[6], + 'soft' => $matches[7], + 'hard' => $matches[8], + 'grace' => $matches[9] + ), + ); + } + } + + # Select all customers Froxlor knows about + $result = $db->query("SELECT `guid`, `loginname`, `diskspace` FROM `" . TABLE_PANEL_CUSTOMERS . "`;"); + while($row = $db->fetch_array($result)) + { + # We do not want to set a quota for root by accident + if ($row['guid'] != 0) + { + # The user has no quota in Froxlor, but on the filesystem + if (($row['diskspace'] == 0 || $row['diskspace'] == -1024) && $usedquota[$row['guid']]['block']['hard'] != 0) + { + $cronlog->logAction(CRON_ACTION, LOG_NOTICE, "Disabling quota for " . $row['loginname']); + safe_exec($settings['system']['diskquota_quotatool_path'] . " -u " . $row['guid'] . " -bl 0 -q 0 " . escapeshellarg($settings['system']['diskquota_customer_partition'])); + } + + # The user quota in Froxlor is different than on the filesystem + elseif($row['diskspace'] != $usedquota[$row['guid']]['block']['hard'] && $row['diskspace'] != -1024) + { + $cronlog->logAction(CRON_ACTION, LOG_NOTICE, "Setting quota for " . $row['loginname'] . " from " . $usedquota[$row['guid']]['block']['hard'] . " to " . $row['diskspace']); + safe_exec($settings['system']['diskquota_quotatool_path'] . " -u " . $row['guid'] . " -bl " . $row['diskspace'] . " -q " . $row['diskspace'] . " " . escapeshellarg($settings['system']['diskquota_customer_partition'])); + } + } + } + } + else + { + fwrite($debugHandler, ' cron_tasks: Task10 skipped - filesystem quota not enabled' . "\n"); + $cronlog->logAction(CRON_ACTION, LOG_INFO, 'Task10 skipped - filesystem quota not enabled'); } } } diff --git a/scripts/jobs/cron_traffic.php b/scripts/jobs/cron_traffic.php index abd6f68f..c6505751 100644 --- a/scripts/jobs/cron_traffic.php +++ b/scripts/jobs/cron_traffic.php @@ -80,7 +80,7 @@ while($row_database = $db->fetch_array($databases)) $databases_list[] = strtolower($databases_list_row['Database']); } } - + if(in_array(strtolower($row_database['databasename']), $databases_list)) { $mysql_usage_result = $db_root->query("SHOW TABLE STATUS FROM `" . $db_root->escape($row_database['databasename']) . "`"); @@ -102,7 +102,36 @@ while($row_database = $db->fetch_array($databases)) $db_root->close(); +# We are using the file-system quota, this will speed up the diskusage - collection +if ($settings['system']['diskquota_enabled']) +{ + # Fetch all quota in the desired partition + exec("repquota -n " . $settings['system']['diskquota_customer_partition'], $repquota); + $usedquota = array(); + foreach ($repquota as $tmpquota) + { + # Let's see if the line matches a quota - line + if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\ddays)?\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) + { + # It matches - put it into an array with userid as key (for easy lookup later) + $usedquota[$matches[1]] = array( + 'block' => array( + 'used' => $matches[2], + 'soft' => $matches[3], + 'hard' => $matches[4], + 'grace' => $matches[5] + ), + 'file' => array( + 'used' => $matches[6], + 'soft' => $matches[7], + 'hard' => $matches[8], + 'grace' => $matches[9] + ), + ); + } + } +} $result = $db->query("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` ORDER BY `customerid` ASC"); while($row = $db->fetch_array($result)) @@ -179,7 +208,7 @@ while($row = $db->fetch_array($result)) safeSQLLogfile($domainlist[$row['customerid']], $row['loginname']); } - // callAwstatsGetTraffic is called ONLY HERE and + // callAwstatsGetTraffic is called ONLY HERE and // *not* also in the special-logfiles-loop, because the function // will iterate through all customer-domains and the awstats-configs // know the logfile-name, #246 @@ -191,7 +220,7 @@ while($row = $db->fetch_array($result)) { $httptraffic+= floatval(callWebalizerGetTraffic($row['loginname'], $row['documentroot'] . '/webalizer/', $caption, $domainlist[$row['customerid']])); } - + // make the stuff readable for the customer, #258 makeChownWithNewStats($row); @@ -207,7 +236,7 @@ while($row = $db->fetch_array($result)) $db->close(); require_once ($pathtophpfiles . '/lib/userdata.inc.php'); $db = new db($sql['host'], $sql['user'], $sql['password'], $sql['db']); - + if ($db->link_id == 0) { fclose($debugHandler); unlink($lockfile); @@ -285,23 +314,33 @@ while($row = $db->fetch_array($result)) fwrite($debugHandler, 'calculating webspace usage for ' . $row['loginname'] . "\n"); $webspaceusage = 0; - - if(file_exists($row['documentroot']) && is_dir($row['documentroot'])) + + # Using repquota, it's faster using this tool than using du traversing the complete directory + if ($settings['system']['diskquota_enabled']) { - $back = safe_exec('du -sk ' . escapeshellarg($row['documentroot']) . ''); - foreach($back as $backrow) - { - $webspaceusage = explode(' ', $backrow); - } - - $webspaceusage = floatval($webspaceusage['0']); - unset($back); + # We may use the array we created earlier, the used diskspace is stored in [][block][used] + $webspaceusage = floatval($usedquota[$row['guid']]['block']['used']); } else { - fwrite($debugHandler, 'documentroot ' . $row['documentroot'] . ' does not exist' . "\n"); + # Use the old fashioned way with "du" + if(file_exists($row['documentroot']) && is_dir($row['documentroot'])) + { + $back = safe_exec('du -sk ' . escapeshellarg($row['documentroot']) . ''); + foreach($back as $backrow) + { + $webspaceusage = explode(' ', $backrow); + } + + $webspaceusage = floatval($webspaceusage['0']); + unset($back); + } + else + { + fwrite($debugHandler, 'documentroot ' . $row['documentroot'] . ' does not exist' . "\n"); + } } - + /** * MailSpace-Usage */ @@ -317,7 +356,7 @@ while($row = $db->fetch_array($result)) { $emailusage = explode(' ', $backrow); } - + $emailusage = floatval($emailusage['0']); unset($back); } @@ -380,11 +419,11 @@ while($row = $db->fetch_array($result)) */ $db->query("UPDATE `" . TABLE_FTP_QUOTATALLIES . "` SET `bytes_in_used`='" . (float)$current_diskspace['all'] . "'*1024 WHERE `name` = '" . $row['loginname'] . "' OR `name` LIKE '" . $row['loginname'] . $settings['customer']['ftpprefix'] . "%'"); - + /** * Pureftpd Quota */ - + if($settings['system']['ftpserver'] == "pureftpd") { $result_quota = $db->query("SELECT homedir FROM `" . TABLE_FTP_USERS . "` WHERE customerid = '" . $row['customerid'] . "'"); @@ -400,7 +439,7 @@ while($row = $db->fetch_array($result)) $user = $row['guid']; $group = $row['guid']; } - + while($row_quota = $db->fetch_array($result_quota)) { $quotafile = "" . $row_quota['homedir'] . ".ftpquota"; From 8019629a28b8cca8da4158a8207e0bbc36852e85 Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sat, 18 Jun 2011 19:48:16 +0200 Subject: [PATCH 03/10] Added task 10 (setting filesystem - quota) where necessary, fixes #814 Signed-off-by: Florian Aders (EleRas) --- admin_customers.php | 185 ++++++++++++++++++++++++-------------------- 1 file changed, 101 insertions(+), 84 deletions(-) diff --git a/admin_customers.php b/admin_customers.php index 7e5ae3b1..f2f92f8f 100644 --- a/admin_customers.php +++ b/admin_customers.php @@ -42,7 +42,7 @@ if($page == 'customers' { // clear request data unset($_SESSION['requestData']); - + $log->logAction(ADM_ACTION, LOG_NOTICE, "viewed admin_customers"); $fields = array( 'c.loginname' => $lng['login']['username'], @@ -83,11 +83,11 @@ if($page == 'customers' $fields['c.tickets'] = $lng['customer']['tickets']; $fields['c.tickets_used'] = $lng['customer']['tickets'] . ' (' . $lng['panel']['used'] . ')'; } - + if($settings['autoresponder']['autoresponder_active'] == 1) { $fields['c.email_autoresponder'] = $lng['customer']['autoresponder']; - $fields['c.email_autoresponder_used'] = $lng['customer']['autoresponder'] . ' (' . $lng['panel']['used'] . ')'; + $fields['c.email_autoresponder_used'] = $lng['customer']['autoresponder'] . ' (' . $lng['panel']['used'] . ')'; } */ @@ -175,11 +175,11 @@ if($page == 'customers' if(isset($_POST['send']) && $_POST['send'] == 'send') { - $result = $db->query("UPDATE - `" . TABLE_PANEL_CUSTOMERS . "` - SET - `loginfail_count` = '0' - WHERE + $result = $db->query("UPDATE + `" . TABLE_PANEL_CUSTOMERS . "` + SET + `loginfail_count` = '0' + WHERE `customerid`= '" . (int)$id . "'" ); redirectTo($filename, Array('page' => $page, 's' => $s)); @@ -259,7 +259,7 @@ if($page == 'customers' // remove all package related settings $db->query("DELETE FROM `".TABLE_APS_SETTINGS."` WHERE `InstanceID` = '".(int)$apsrow['ID']."'"); // maybe some leftovers in the tasks - $db->query("DELETE FROM `".TABLE_APS_TASKS."` WHERE `InstanceID` = '".(int)$apsrow['ID']."'"); + $db->query("DELETE FROM `".TABLE_APS_TASKS."` WHERE `InstanceID` = '".(int)$apsrow['ID']."'"); } // now remove all user instances $db->query("DELETE FROM `".TABLE_APS_INSTANCES."` WHERE `CustomerID`='".(int)$id."'"); @@ -330,13 +330,19 @@ if($page == 'customers' $log->logAction(ADM_ACTION, LOG_INFO, "deleted user '" . $result['loginname'] . "'"); inserttask('1'); inserttask('4'); - + if(isset($_POST['delete_userfiles']) && (int)$_POST['delete_userfiles'] == 1) { inserttask('6', $result['loginname']); } - + + # Using filesystem - quota, insert a task which cleans the filesystem - quota + if ($settings['system']['diskquota_enabled']) + { + inserttask('10'); + } + /* * move old tickets to archive */ @@ -354,8 +360,8 @@ if($page == 'customers' $mainticket->Archive(); $log->logAction(ADM_ACTION, LOG_NOTICE, "archived ticket '" . $mainticket->Get('subject') . "'"); } - } - + } + redirectTo($filename, Array('page' => $page, 's' => $s)); } else @@ -439,7 +445,7 @@ if($page == 'customers' { $email_quota = - 1; } - + if($settings['autoresponder']['autoresponder_active'] == '1') { $email_autoresponder = intval_ressource($_POST['email_autoresponder']); @@ -455,13 +461,13 @@ if($page == 'customers' } $email_imap = 0; - if(isset($_POST['email_imap'])) + if(isset($_POST['email_imap'])) $email_imap = intval_ressource($_POST['email_imap']); - + $email_pop3 = 0; - if(isset($_POST['email_pop3'])) + if(isset($_POST['email_pop3'])) $email_pop3 = intval_ressource($_POST['email_pop3']); - + $ftps = 0; if(isset($_POST['ftps'])) $ftps = intval_ressource($_POST['ftps']); @@ -499,7 +505,7 @@ if($page == 'customers' { $number_of_aps_packages = 0; } - + $createstdsubdomain = 0; if(isset($_POST['createstdsubdomain'])) $createstdsubdomain = intval($_POST['createstdsubdomain']); @@ -510,37 +516,37 @@ if($page == 'customers' { $password = validatePassword($password); } - + $backup_allowed = 0; if(isset($_POST['backup_allowed'])) $backup_allowed = intval($_POST['backup_allowed']); - + if ($backup_allowed != 0) { $backup_allowed = 1; } - + // gender out of range? [0,2] if ($gender < 0 || $gender > 2) { $gender = 0; } - + $sendpassword = 0; if(isset($_POST['sendpassword'])) $sendpassword = intval($_POST['sendpassword']); - + $phpenabled = 0; if(isset($_POST['phpenabled'])) $phpenabled = intval($_POST['phpenabled']); - + $perlenabled = 0; if(isset($_POST['perlenabled'])) $perlenabled = intval($_POST['perlenabled']); - + $store_defaultindex = 0; if(isset($_POST['store_defaultindex'])) $store_defaultindex = intval($_POST['store_defaultindex']); - + $diskspace = $diskspace * 1024; $traffic = $traffic * 1024 * 1024; @@ -658,40 +664,40 @@ if($page == 'customers' $_theme = $settings['panel']['default_theme']; $result = $db->query( - "INSERT INTO `" . TABLE_PANEL_CUSTOMERS . "` SET - `adminid` = '" . (int)$userinfo['adminid'] . "', - `loginname` = '" . $db->escape($loginname) . "', - `password` = '" . md5($password) . "', - `name` = '" . $db->escape($name) . "', - `firstname` = '" . $db->escape($firstname) . "', + "INSERT INTO `" . TABLE_PANEL_CUSTOMERS . "` SET + `adminid` = '" . (int)$userinfo['adminid'] . "', + `loginname` = '" . $db->escape($loginname) . "', + `password` = '" . md5($password) . "', + `name` = '" . $db->escape($name) . "', + `firstname` = '" . $db->escape($firstname) . "', `gender` = '" . (int)$gender . "', - `company` = '" . $db->escape($company) . "', - `street` = '" . $db->escape($street) . "', - `zipcode` = '" . $db->escape($zipcode) . "', - `city` = '" . $db->escape($city) . "', - `phone` = '" . $db->escape($phone) . "', - `fax` = '" . $db->escape($fax) . "', - `email` = '" . $db->escape($email) . "', - `customernumber` = '" . $db->escape($customernumber) . "', - `def_language` = '" . $db->escape($def_language) . "', - `documentroot` = '" . $db->escape($documentroot) . "', - `guid` = '" . $db->escape($guid) . "', - `diskspace` = '" . $db->escape($diskspace) . "', - `traffic` = '" . $db->escape($traffic) . "', - `subdomains` = '" . $db->escape($subdomains) . "', - `emails` = '" . $db->escape($emails) . "', - `email_accounts` = '" . $db->escape($email_accounts) . "', - `email_forwarders` = '" . $db->escape($email_forwarders) . "', - `email_quota` = '" . $db->escape($email_quota) . "', - `ftps` = '" . $db->escape($ftps) . "', - `tickets` = '" . $db->escape($tickets) . "', - `mysqls` = '" . $db->escape($mysqls) . "', - `standardsubdomain` = '0', - `phpenabled` = '" . $db->escape($phpenabled) . "', - `imap` = '" . $db->escape($email_imap) . "', - `pop3` = '" . $db->escape($email_pop3) . "', - `aps_packages` = '" . (int)$number_of_aps_packages . "', - `perlenabled` = '" . $db->escape($perlenabled) . "', + `company` = '" . $db->escape($company) . "', + `street` = '" . $db->escape($street) . "', + `zipcode` = '" . $db->escape($zipcode) . "', + `city` = '" . $db->escape($city) . "', + `phone` = '" . $db->escape($phone) . "', + `fax` = '" . $db->escape($fax) . "', + `email` = '" . $db->escape($email) . "', + `customernumber` = '" . $db->escape($customernumber) . "', + `def_language` = '" . $db->escape($def_language) . "', + `documentroot` = '" . $db->escape($documentroot) . "', + `guid` = '" . $db->escape($guid) . "', + `diskspace` = '" . $db->escape($diskspace) . "', + `traffic` = '" . $db->escape($traffic) . "', + `subdomains` = '" . $db->escape($subdomains) . "', + `emails` = '" . $db->escape($emails) . "', + `email_accounts` = '" . $db->escape($email_accounts) . "', + `email_forwarders` = '" . $db->escape($email_forwarders) . "', + `email_quota` = '" . $db->escape($email_quota) . "', + `ftps` = '" . $db->escape($ftps) . "', + `tickets` = '" . $db->escape($tickets) . "', + `mysqls` = '" . $db->escape($mysqls) . "', + `standardsubdomain` = '0', + `phpenabled` = '" . $db->escape($phpenabled) . "', + `imap` = '" . $db->escape($email_imap) . "', + `pop3` = '" . $db->escape($email_pop3) . "', + `aps_packages` = '" . (int)$number_of_aps_packages . "', + `perlenabled` = '" . $db->escape($perlenabled) . "', `email_autoresponder` = '" . $db->escape($email_autoresponder) . "', `backup_allowed` = '" . $db->escape($backup_allowed) . "', `theme` = '" . $db->escape($_theme) . "'" @@ -768,6 +774,11 @@ if($page == 'customers' $log->logAction(ADM_ACTION, LOG_INFO, "added user '" . $loginname . "'"); inserttask('2', $loginname, $guid, $guid, $store_defaultindex); + # Using filesystem - quota, insert a task which cleans the filesystem - quota + if ($settings['system']['diskquota_enabled']) + { + inserttask('10'); + } // Add htpasswd for the webalizer stats if(CRYPT_STD_DES == 1) @@ -809,16 +820,16 @@ if($page == 'customers' $_stdsubdomain = $loginname . '.' . $settings['system']['hostname']; } - $db->query("INSERT INTO `" . TABLE_PANEL_DOMAINS . "` SET " . + $db->query("INSERT INTO `" . TABLE_PANEL_DOMAINS . "` SET " . "`domain` = '". $db->escape($_stdsubdomain) . "', " . "`customerid` = '" . (int)$customerid . "', " . - "`adminid` = '" . (int)$userinfo['adminid'] . "', " . + "`adminid` = '" . (int)$userinfo['adminid'] . "', " . "`parentdomainid` = '-1', " . - "`ipandport` = '" . $db->escape($settings['system']['defaultip']) . "', " . - "`documentroot` = '" . $db->escape($documentroot) . "', " . + "`ipandport` = '" . $db->escape($settings['system']['defaultip']) . "', " . + "`documentroot` = '" . $db->escape($documentroot) . "', " . "`zonefile` = '', " . "`isemaildomain` = '0', " . - "`caneditdomain` = '0', " . + "`caneditdomain` = '0', " . "`openbasedir` = '1', " . "`safemode` = '1', " . "`speciallogfile` = '0', " . @@ -904,11 +915,11 @@ if($page == 'customers' #$perlenabled = makeyesno('perlenabled', '1', '0', '0'); #$store_defaultindex = makeyesno('store_defaultindex', '1', '0', '1'); $backup_allowed = makeyesno('backup_allowed', '1', '0', '0'); - + $gender_options = makeoption($lng['gender']['undef'], 0, true, true, true); $gender_options .= makeoption($lng['gender']['male'], 1, null, true, true); $gender_options .= makeoption($lng['gender']['female'], 2, null, true, true); - + $customer_add_data = include_once dirname(__FILE__).'/lib/formfields/admin/customer/formfield.customer_add.php'; $customer_add_form = htmlform::genHTMLForm($customer_add_data); @@ -1010,16 +1021,16 @@ if($page == 'customers' else { $email_autoresponder = 0; - } + } $email_imap = 0; - if(isset($_POST['email_imap'])) + if(isset($_POST['email_imap'])) $email_imap = intval_ressource($_POST['email_imap']); - + $email_pop3 = 0; - if(isset($_POST['email_pop3'])) + if(isset($_POST['email_pop3'])) $email_pop3 = intval_ressource($_POST['email_pop3']); - + $ftps = 0; if(isset($_POST['ftps'])) $ftps = intval_ressource($_POST['ftps']); @@ -1036,11 +1047,11 @@ if($page == 'customers' { $tickets = - 1; } - + $backup_allowed = 0; if (isset($_POST['backup_allowed'])) $backup_allowed = intval($_POST['backup_allowed']); - + if($backup_allowed != '0'){ $backup_allowed = 1; } @@ -1049,7 +1060,7 @@ if($page == 'customers' if ($gender < 0 || $gender > 2) { $gender = 0; } - + $mysqls = 0; if(isset($_POST['mysqls'])) $mysqls = intval_ressource($_POST['mysqls']); @@ -1060,7 +1071,7 @@ if($page == 'customers' } if($settings['aps']['aps_active'] == '1') - { + { $number_of_aps_packages = intval_ressource($_POST['number_of_aps_packages']); if(isset($_POST['number_of_aps_packages_ul'])) @@ -1076,15 +1087,15 @@ if($page == 'customers' $createstdsubdomain = 0; if(isset($_POST['createstdsubdomain'])) $createstdsubdomain = intval($_POST['createstdsubdomain']); - + $deactivated = 0; if(isset($_POST['deactivated'])) $deactivated = intval($_POST['deactivated']); - + $phpenabled = 0; if(isset($_POST['phpenabled'])) $phpenabled = intval($_POST['phpenabled']); - + $perlenabled = 0; if(isset($_POST['perlenabled'])) $perlenabled = intval($_POST['perlenabled']); @@ -1210,7 +1221,7 @@ if($page == 'customers' $db->query("UPDATE `" . TABLE_MAIL_USERS . "` SET `postfix`='" . (($deactivated) ? 'N' : 'Y') . "', `pop3`='" . (($deactivated) ? '0' : '1') . "', `imap`='" . (($deactivated) ? '0' : '1') . "' WHERE `customerid`='" . (int)$id . "'"); $db->query("UPDATE `" . TABLE_FTP_USERS . "` SET `login_enabled`='" . (($deactivated) ? 'N' : 'Y') . "' WHERE `customerid`='" . (int)$id . "'"); $db->query("UPDATE `" . TABLE_PANEL_DOMAINS . "` SET `deactivated`='" . (int)$deactivated . "' WHERE `customerid`='" . (int)$id . "'"); - + /* Retrieve customer's databases */ $databases = $db->query("SELECT * FROM " . TABLE_PANEL_DATABASES . " WHERE customerid='" . (int)$id . "' ORDER BY `dbserver`"); $db_root = new db($sql_root[0]['host'], $sql_root[0]['user'], $sql_root[0]['password'], ''); @@ -1232,7 +1243,7 @@ if($page == 'customers' foreach(array_unique(explode(',', $settings['system']['mysql_access_host'])) as $mysql_access_host) { $mysql_access_host = trim($mysql_access_host); - + /* Prevent access, if deactivated */ if($deactivated) { @@ -1240,7 +1251,7 @@ if($page == 'customers' $db_root->query('REVOKE ALL PRIVILEGES ON `' . str_replace('_', '\_', $db_root->escape($row_database['databasename'])) . '` . * FROM `' . $db_root->escape($row_database['databasename']) . '`@`' . $db_root->escape($mysql_access_host) . '`'); } else /* Otherwise grant access */ - { + { $db_root->query('GRANT ALL PRIVILEGES ON `' . $db_root->escape($row_database['databasename']) .'`.* TO `' . $db_root->escape($row_database['databasename']) . '`@`' . $db_root->escape($mysql_access_host) . '`'); $db_root->query('GRANT ALL PRIVILEGES ON `' . str_replace('_', '\_', $db_root->escape($row_database['databasename'])) . '` . * TO `' . $db_root->escape($row_database['databasename']) . '`@`' . $db_root->escape($mysql_access_host) . '`'); } @@ -1250,7 +1261,7 @@ if($page == 'customers' /* At last flush the new privileges */ $db_root->query('FLUSH PRIVILEGES;'); $db_root->close(); - + $log->logAction(ADM_ACTION, LOG_INFO, "deactivated user '" . $result['loginname'] . "'"); inserttask('1'); } @@ -1273,6 +1284,12 @@ if($page == 'customers' $db->query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `name`='" . $db->escape($name) . "', `firstname`='" . $db->escape($firstname) . "', `gender`='" . $db->escape($gender) . "', `company`='" . $db->escape($company) . "', `street`='" . $db->escape($street) . "', `zipcode`='" . $db->escape($zipcode) . "', `city`='" . $db->escape($city) . "', `phone`='" . $db->escape($phone) . "', `fax`='" . $db->escape($fax) . "', `email`='" . $db->escape($email) . "', `customernumber`='" . $db->escape($customernumber) . "', `def_language`='" . $db->escape($def_language) . "', `password` = '" . $password . "', `diskspace`='" . $db->escape($diskspace) . "', `traffic`='" . $db->escape($traffic) . "', `subdomains`='" . $db->escape($subdomains) . "', `emails`='" . $db->escape($emails) . "', `email_accounts` = '" . $db->escape($email_accounts) . "', `email_forwarders`='" . $db->escape($email_forwarders) . "', `ftps`='" . $db->escape($ftps) . "', `tickets`='" . $db->escape($tickets) . "', `mysqls`='" . $db->escape($mysqls) . "', `deactivated`='" . $db->escape($deactivated) . "', `phpenabled`='" . $db->escape($phpenabled) . "', `email_quota`='" . $db->escape($email_quota) . "', `imap`='" . $db->escape($email_imap) . "', `pop3`='" . $db->escape($email_pop3) . "', `aps_packages`='" . (int)$number_of_aps_packages . "', `perlenabled`='" . $db->escape($perlenabled) . "', `email_autoresponder`='" . $db->escape($email_autoresponder) . "', `backup_allowed`='" . $db->escape($backup_allowed) . "' WHERE `customerid`='" . (int)$id . "'"); $admin_update_query = "UPDATE `" . TABLE_PANEL_ADMINS . "` SET `customers_used` = `customers_used` "; + # Using filesystem - quota, insert a task which cleans the filesystem - quota + if ($settings['system']['diskquota_enabled']) + { + inserttask('10'); + } + if($mysqls != '-1' || $result['mysqls'] != '-1') { @@ -1568,7 +1585,7 @@ if($page == 'customers' $gender_options = makeoption($lng['gender']['undef'], 0, ($result['gender'] == '0' ? true : false), true, true); $gender_options .= makeoption($lng['gender']['male'], 1, ($result['gender'] == '1' ? true : false), true, true); $gender_options .= makeoption($lng['gender']['female'], 2, ($result['gender'] == '2' ? true : false), true, true); - + $customer_edit_data = include_once dirname(__FILE__).'/lib/formfields/admin/customer/formfield.customer_edit.php'; $customer_edit_form = htmlform::genHTMLForm($customer_edit_data); From 30344b0dce137c7b8cfc8b774d21f0d5a6ad2add Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sat, 18 Jun 2011 19:52:47 +0200 Subject: [PATCH 04/10] Forgot to add settings, fixes #814 Signed-off-by: Florian Aders (EleRas) --- actions/admin/settings/220.quota.php | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 actions/admin/settings/220.quota.php diff --git a/actions/admin/settings/220.quota.php b/actions/admin/settings/220.quota.php new file mode 100644 index 00000000..f29e1a00 --- /dev/null +++ b/actions/admin/settings/220.quota.php @@ -0,0 +1,60 @@ + (2011-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Settings + * + */ + +return array( + 'groups' => array( + 'diskquota' => array( + 'title' => $lng['diskquota'], + 'fields' => array( + 'diskquota_enabled' => array( + 'label' => $lng['serversettings']['diskquota_enabled'], + 'settinggroup' => 'system', + 'varname' => 'diskquota_enabled', + 'type' => 'bool', + 'default' => false, + 'save_method' => 'storeSettingField', + 'overview_option' => true + ), + 'diskquota_repquota_path' => array( + 'label' => $lng['serversettings']['diskquota_repquota_path']['description'], + 'settinggroup' => 'system', + 'varname' => 'diskquota_repquota_path', + 'type' => 'string', + 'default' => '/usr/sbin/repquota', + 'save_method' => 'storeSettingField', + ), + 'diskquota_quotatool_path' => array( + 'label' => $lng['serversettings']['diskquota_quotatool_path']['description'], + 'settinggroup' => 'system', + 'varname' => 'diskquota_quotatool_path', + 'type' => 'string', + 'default' => '/usr/bin/quotatool', + 'save_method' => 'storeSettingField', + ), + 'diskquota_customer_partition' => array( + 'label' => $lng['serversettings']['diskquota_customer_partition']['description'], + 'settinggroup' => 'system', + 'varname' => 'diskquota_customer_partition', + 'type' => 'string', + 'default' => '/dev/root', + 'save_method' => 'storeSettingField', + ), + ), + ), + ), + ); + +?> From 8bfdd0bc14e17ede5998058cde2a608bdaed7e7a Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sat, 18 Jun 2011 19:54:43 +0200 Subject: [PATCH 05/10] Update filesystem - quota when config-updates shall be written as well, refs #814 Signed-off-by: Florian Aders (EleRas) --- admin_settings.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/admin_settings.php b/admin_settings.php index 2ea64dd0..9ccc5f44 100644 --- a/admin_settings.php +++ b/admin_settings.php @@ -32,7 +32,7 @@ if(($page == 'settings' || $page == 'overview') { $settings_data = loadConfigArrayDir('./actions/admin/settings/'); $settings = loadSettings($settings_data, $db); - + if(isset($_POST['send']) && $_POST['send'] == 'send') { @@ -64,10 +64,10 @@ if(($page == 'settings' || $page == 'overview') $settings_part = false; $only_enabledisable = true; } - + if(processFormEx( - $settings_data, - $_POST, + $settings_data, + $_POST, array('filename' => $filename, 'action' => $action, 'page' => $page), $_part, $settings_all, @@ -86,24 +86,24 @@ if(($page == 'settings' || $page == 'overview') else { $_part = isset($_GET['part']) ? $_GET['part'] : ''; - + if($_part == '') { $_part = isset($_POST['part']) ? $_POST['part'] : ''; } $fields = buildFormEx($settings_data, $_part); - + $settings_page = ''; if($_part == '') { eval("\$settings_page .= \"" . getTemplate("settings/settings_overview") . "\";"); - } + } else { eval("\$settings_page .= \"" . getTemplate("settings/settings") . "\";"); } - + eval("echo \"" . getTemplate("settings/settings_form_begin") . "\";"); eval("echo \$settings_page;"); eval("echo \"" . getTemplate("settings/settings_form_end") . "\";"); @@ -121,6 +121,7 @@ elseif($page == 'rebuildconfigs' inserttask('4'); inserttask('5'); inserttask('9'); + inserttask('10'); standard_success('rebuildingconfigs', '', array('filename' => 'admin_index.php')); } else From 8599ff775b58230527712f97afaf3ed424f2f6e5 Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sat, 18 Jun 2011 20:01:51 +0200 Subject: [PATCH 06/10] Tell Froxlor there exists a task-type 10, refs #814 Signed-off-by: Florian Aders (EleRas) --- lib/functions/froxlor/function.inserttask.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/functions/froxlor/function.inserttask.php b/lib/functions/froxlor/function.inserttask.php index 4cdfe7a2..91b9c8f5 100644 --- a/lib/functions/froxlor/function.inserttask.php +++ b/lib/functions/froxlor/function.inserttask.php @@ -35,7 +35,8 @@ function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = ' || $type == '3' || $type == '4' || $type == '5' - || $type == '9') + || $type == '9' + || $type == '10') { $db->query('DELETE FROM `' . TABLE_PANEL_TASKS . '` WHERE `type`="' . $type . '"'); $db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`) VALUES ("' . $type . '")'); From aae635bf5dbf280ecb6cbcb94b1b2f752705ba1c Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sat, 18 Jun 2011 22:53:27 +0200 Subject: [PATCH 07/10] More secure way to get the used quota, refs #814 Signed-off-by: Florian Aders (EleRas) --- scripts/jobs/cron_tasks.php | 4 ++-- scripts/jobs/cron_traffic.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/jobs/cron_tasks.php b/scripts/jobs/cron_tasks.php index 7bd1e055..8c40e00b 100644 --- a/scripts/jobs/cron_tasks.php +++ b/scripts/jobs/cron_tasks.php @@ -472,13 +472,13 @@ while($row = $db->fetch_array($result_tasks)) $cronlog->logAction(CRON_ACTION, LOG_INFO, 'Task10 started - setting filesystem quota'); # Fetch all quota in the desired partition - exec($settings['system']['diskquota_repquota_path'] . " -n " . escapeshellarg($settings['system']['diskquota_customer_partition']), $repquota); + exec($settings['system']['diskquota_repquota_path'] . " -np " . escapeshellarg($settings['system']['diskquota_customer_partition']), $repquota); $usedquota = array(); foreach ($repquota as $tmpquota) { # Let's see if the line matches a quota - line - if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\ddays)?\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) + if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) { # It matches - put it into an array with userid as key (for easy lookup later) $usedquota[$matches[1]] = array( diff --git a/scripts/jobs/cron_traffic.php b/scripts/jobs/cron_traffic.php index c6505751..3a4bd2c4 100644 --- a/scripts/jobs/cron_traffic.php +++ b/scripts/jobs/cron_traffic.php @@ -106,13 +106,13 @@ $db_root->close(); if ($settings['system']['diskquota_enabled']) { # Fetch all quota in the desired partition - exec("repquota -n " . $settings['system']['diskquota_customer_partition'], $repquota); + exec("repquota -np " . $settings['system']['diskquota_customer_partition'], $repquota); $usedquota = array(); foreach ($repquota as $tmpquota) { # Let's see if the line matches a quota - line - if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\ddays)?\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) + if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) { # It matches - put it into an array with userid as key (for easy lookup later) $usedquota[$matches[1]] = array( From 1836132c2893f9236d3c06c7f51a7a096888a38e Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sat, 18 Jun 2011 23:06:39 +0200 Subject: [PATCH 08/10] Use setting instead of hardcoded name, refs #814 Signed-off-by: Florian Aders (EleRas) --- scripts/jobs/cron_traffic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/jobs/cron_traffic.php b/scripts/jobs/cron_traffic.php index 3a4bd2c4..472f86eb 100644 --- a/scripts/jobs/cron_traffic.php +++ b/scripts/jobs/cron_traffic.php @@ -106,7 +106,7 @@ $db_root->close(); if ($settings['system']['diskquota_enabled']) { # Fetch all quota in the desired partition - exec("repquota -np " . $settings['system']['diskquota_customer_partition'], $repquota); + exec($settings['system']['diskquota_repquota_path'] . " -np " . $settings['system']['diskquota_customer_partition'], $repquota); $usedquota = array(); foreach ($repquota as $tmpquota) From eb984c2f4ca143dd95ad1a3a403c84818d20ec45 Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sun, 19 Jun 2011 11:31:00 +0200 Subject: [PATCH 09/10] Moved redundant code into single function, refs #814 Signed-off-by: Florian Aders (EleRas) --- .../froxlor/function.getFilesystemQuota.php | 53 +++++++++++++++++++ scripts/jobs/cron_tasks.php | 27 +--------- scripts/jobs/cron_traffic.php | 28 +--------- 3 files changed, 56 insertions(+), 52 deletions(-) create mode 100644 lib/functions/froxlor/function.getFilesystemQuota.php diff --git a/lib/functions/froxlor/function.getFilesystemQuota.php b/lib/functions/froxlor/function.getFilesystemQuota.php new file mode 100644 index 00000000..ef0471c6 --- /dev/null +++ b/lib/functions/froxlor/function.getFilesystemQuota.php @@ -0,0 +1,53 @@ + (2011-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Functions + * + */ + +function getFilesystemQuota() +{ + global $settings; + if ($settings['system']['diskquota_enabled']) + { + # Fetch all quota in the desired partition + exec($settings['system']['diskquota_repquota_path'] . " -np " . escapeshellarg($settings['system']['diskquota_customer_partition']), $repquota); + + $usedquota = array(); + foreach ($repquota as $tmpquota) + { + # Let's see if the line matches a quota - line + if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) + { + # It matches - put it into an array with userid as key (for easy lookup later) + $usedquota[$matches[1]] = array( + 'block' => array( + 'used' => $matches[2], + 'soft' => $matches[3], + 'hard' => $matches[4], + 'grace' => $matches[5] + ), + 'file' => array( + 'used' => $matches[6], + 'soft' => $matches[7], + 'hard' => $matches[8], + 'grace' => $matches[9] + ), + ); + } + } + + return $usedquota; + } + return false; +} \ No newline at end of file diff --git a/scripts/jobs/cron_tasks.php b/scripts/jobs/cron_tasks.php index 8c40e00b..079bd00c 100644 --- a/scripts/jobs/cron_tasks.php +++ b/scripts/jobs/cron_tasks.php @@ -471,32 +471,7 @@ while($row = $db->fetch_array($result_tasks)) fwrite($debugHandler, ' cron_tasks: Task10 started - setting filesystem quota' . "\n"); $cronlog->logAction(CRON_ACTION, LOG_INFO, 'Task10 started - setting filesystem quota'); - # Fetch all quota in the desired partition - exec($settings['system']['diskquota_repquota_path'] . " -np " . escapeshellarg($settings['system']['diskquota_customer_partition']), $repquota); - - $usedquota = array(); - foreach ($repquota as $tmpquota) - { - # Let's see if the line matches a quota - line - if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) - { - # It matches - put it into an array with userid as key (for easy lookup later) - $usedquota[$matches[1]] = array( - 'block' => array( - 'used' => $matches[2], - 'soft' => $matches[3], - 'hard' => $matches[4], - 'grace' => $matches[5] - ), - 'file' => array( - 'used' => $matches[6], - 'soft' => $matches[7], - 'hard' => $matches[8], - 'grace' => $matches[9] - ), - ); - } - } + $usedquota = getFilesystemQuota(); # Select all customers Froxlor knows about $result = $db->query("SELECT `guid`, `loginname`, `diskspace` FROM `" . TABLE_PANEL_CUSTOMERS . "`;"); diff --git a/scripts/jobs/cron_traffic.php b/scripts/jobs/cron_traffic.php index 472f86eb..5eecf378 100644 --- a/scripts/jobs/cron_traffic.php +++ b/scripts/jobs/cron_traffic.php @@ -105,33 +105,9 @@ $db_root->close(); # We are using the file-system quota, this will speed up the diskusage - collection if ($settings['system']['diskquota_enabled']) { - # Fetch all quota in the desired partition - exec($settings['system']['diskquota_repquota_path'] . " -np " . $settings['system']['diskquota_customer_partition'], $repquota); - - $usedquota = array(); - foreach ($repquota as $tmpquota) - { - # Let's see if the line matches a quota - line - if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) - { - # It matches - put it into an array with userid as key (for easy lookup later) - $usedquota[$matches[1]] = array( - 'block' => array( - 'used' => $matches[2], - 'soft' => $matches[3], - 'hard' => $matches[4], - 'grace' => $matches[5] - ), - 'file' => array( - 'used' => $matches[6], - 'soft' => $matches[7], - 'hard' => $matches[8], - 'grace' => $matches[9] - ), - ); - } - } + $usedquota = getFilesystemQuota(); } + $result = $db->query("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` ORDER BY `customerid` ASC"); while($row = $db->fetch_array($result)) From a23260fb7f34e365ae96d9b7f0eb7543f3d0e27c Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sun, 19 Jun 2011 13:43:56 +0200 Subject: [PATCH 10/10] Added task 10 to description of outstanding tasks, refs #814 Signed-off-by: Florian Aders (EleRas) --- .../froxlor/function.CronjobFunctions.php | 57 +++++++++++-------- lng/english.lng.php | 5 +- lng/german.lng.php | 5 +- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/lib/functions/froxlor/function.CronjobFunctions.php b/lib/functions/froxlor/function.CronjobFunctions.php index 79cff04e..04aee62a 100644 --- a/lib/functions/froxlor/function.CronjobFunctions.php +++ b/lib/functions/froxlor/function.CronjobFunctions.php @@ -18,18 +18,18 @@ /* * Function getNextCronjobs * - * checks which cronjobs have to be executed + * checks which cronjobs have to be executed * * @return array array of cron-files which are to be executed */ function getNextCronjobs() { global $db; - + $query = "SELECT `id`, `cronfile` FROM `".TABLE_PANEL_CRONRUNS."` WHERE `interval` <> '0' AND `isactive` = '1' AND ("; $intervals = getIntervalOptions(); - + $x = 0; foreach($intervals as $name => $ival) { @@ -37,23 +37,23 @@ function getNextCronjobs() if($x == 0) { $query.= '(UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(`lastrun`), INTERVAL '.$ival.')) <= UNIX_TIMESTAMP() AND `interval`=\''.$ival.'\')'; - } else { + } else { $query.= ' OR (UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(`lastrun`), INTERVAL '.$ival.')) <= UNIX_TIMESTAMP() AND `interval`=\''.$ival.'\')'; } $x++; } - + $query.= ');'; - + $result = $db->query($query); - + $cron_files = array(); while($row = $db->fetch_array($result)) { $cron_files[] = $row['cronfile']; $db->query("UPDATE `".TABLE_PANEL_CRONRUNS."` SET `lastrun` = UNIX_TIMESTAMP() WHERE `id` ='".(int)$row['id']."';"); } - + return $cron_files; } @@ -63,10 +63,10 @@ function includeCronjobs($debugHandler, $pathtophpfiles) global $settings; $cronjobs = getNextCronjobs(); - + $jobs_to_run = array(); $cron_path = makeCorrectDir($pathtophpfiles.'/scripts/jobs/'); - + if($cronjobs !== false && is_array($cronjobs) && isset($cronjobs[0])) @@ -77,7 +77,7 @@ function includeCronjobs($debugHandler, $pathtophpfiles) $jobs_to_run[] = $cron_file; } } - + return $jobs_to_run; } @@ -103,7 +103,7 @@ function getIntervalOptions() $cronlog->logAction(CRON_ACTION, LOG_ERROR, "Invalid SQL-Interval ".$row['interval']." detected. Please fix this in the database."); } } - + return $cron_intervals; } @@ -111,14 +111,14 @@ function getIntervalOptions() function getCronjobsLastRun() { global $db, $lng; - + $query = "SELECT `lastrun`, `desc_lng_key` FROM `".TABLE_PANEL_CRONRUNS."` WHERE `isactive` = '1' ORDER BY `cronfile` ASC"; $result = $db->query($query); - + $cronjobs_last_run = ''; while($row = $db->fetch_array($result)) - { + { $lastrun = $lng['cronjobs']['notyetrun']; if($row['lastrun'] > 0) { $lastrun = date('d.m.Y H:i:s', $row['lastrun']); @@ -129,18 +129,18 @@ function getCronjobsLastRun() eval("\$cronjobs_last_run .= \"" . getTemplate("index/overview_item") . "\";"); } - + return $cronjobs_last_run; } function toggleCronStatus($module = null, $isactive = 0) { global $db; - + if($isactive != 1) { $isactive = 0; } - + $query = "UPDATE `".TABLE_PANEL_CRONRUNS."` SET `isactive` = '".(int)$isactive."' WHERE `module` = '".$module."'"; $db->query($query); @@ -149,10 +149,10 @@ function toggleCronStatus($module = null, $isactive = 0) function getOutstandingTasks() { global $db, $lng; - + $query = "SELECT * FROM `".TABLE_PANEL_TASKS."` ORDER BY `type` ASC"; $result = $db->query($query); - + $value = '
    '; $tasks = ''; while($row = $db->fetch_array($result)) @@ -161,7 +161,7 @@ function getOutstandingTasks() { $row['data'] = unserialize($row['data']); } - + /* * rebuilding webserver-configuration */ @@ -208,16 +208,23 @@ function getOutstandingTasks() } $task_desc = $lng['tasks']['deleting_customerfiles']; $task_desc = str_replace('%loginname%', $loginname, $task_desc); - } + } + /* + * Set FS - quota + */ + elseif($row['type'] == '10') + { + $task_desc = $lng['tasks']['diskspace_set_quota']; + } if($task_desc != '') { $tasks .= '
  • '.$task_desc.'
  • '; } } - + $query2 = "SELECT DISTINCT `Task` FROM `".TABLE_APS_TASKS."` ORDER BY `Task` ASC"; $result2 = $db->query($query2); - + while($row2 = $db->fetch_array($result2)) { /* @@ -262,7 +269,7 @@ function getOutstandingTasks() { $task_desc = $lng['tasks']['aps_task_sysdownload']; } - + if($task_desc != '') { $tasks .= '
  • '.$task_desc.'
  • '; } diff --git a/lng/english.lng.php b/lng/english.lng.php index d3fd6b87..43811fc2 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1881,6 +1881,7 @@ $lng['country']['ZW'] = "Zimbabwe"; // ADDED IN FROXLOR 0.9.22-svn1 $lng['diskquota'] = 'Quota'; $lng['serversettings']['diskquota_enabled'] = 'Quota activated?'; -$lng['serversettings']['diskquota_repquota_path']['description'] = 'Path to the repquota - tool'; +$lng['serversettings']['diskquota_repquota_path']['description'] = 'Path to repquota'; $lng['serversettings']['diskquota_quotatool_path']['description'] = 'Path to quotatool'; -$lng['serversettings']['diskquota_customer_partition']['description'] = 'Partition, on which the customer files are stored'; \ No newline at end of file +$lng['serversettings']['diskquota_customer_partition']['description'] = 'Partition, on which the customer files are stored'; +$lng['tasks']['diskspace_set_quota'] = 'Set quota on filesystem'; \ No newline at end of file diff --git a/lng/german.lng.php b/lng/german.lng.php index 50ce1386..ea579e73 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1612,6 +1612,7 @@ $lng['serversettings']['backup_bigfile'] = 'Backup von Kundenverzeichnissen und // ADDED IN FROXLOR 0.9.22-svn1 $lng['diskquota'] = 'Quota'; $lng['serversettings']['diskquota_enabled'] = 'Quota aktiviert?'; -$lng['serversettings']['diskquota_repquota_path']['description'] = 'Pfad zu dem repquota - Tool'; +$lng['serversettings']['diskquota_repquota_path']['description'] = 'Pfad zu repquota'; $lng['serversettings']['diskquota_quotatool_path']['description'] = 'Pfad zu quotatool'; -$lng['serversettings']['diskquota_customer_partition']['description'] = 'Partition, auf welcher die Kundendaten liegen'; \ No newline at end of file +$lng['serversettings']['diskquota_customer_partition']['description'] = 'Partition, auf welcher die Kundendaten liegen'; +$lng['tasks']['diskspace_set_quota'] = 'Quota auf dem Dateisystem setzen'; \ No newline at end of file