Merge branch 'quota'
This commit is contained in:
60
actions/admin/settings/220.quota.php
Normal file
60
actions/admin/settings/220.quota.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2011 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (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',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
?>
|
||||
@@ -337,6 +337,12 @@ if($page == 'customers'
|
||||
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
|
||||
*/
|
||||
@@ -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)
|
||||
@@ -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')
|
||||
{
|
||||
|
||||
@@ -121,6 +121,7 @@ elseif($page == 'rebuildconfigs'
|
||||
inserttask('4');
|
||||
inserttask('5');
|
||||
inserttask('9');
|
||||
inserttask('10');
|
||||
standard_success('rebuildingconfigs', '', array('filename' => 'admin_index.php'));
|
||||
}
|
||||
else
|
||||
|
||||
@@ -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');
|
||||
|
||||
# --------------------------------------------------------
|
||||
|
||||
#
|
||||
|
||||
@@ -1620,3 +1620,17 @@ if(isFroxlorVersion('0.9.21-svn2'))
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
@@ -209,6 +209,13 @@ 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 .= '<li>'.$task_desc.'</li>';
|
||||
|
||||
53
lib/functions/froxlor/function.getFilesystemQuota.php
Normal file
53
lib/functions/froxlor/function.getFilesystemQuota.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2011 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (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;
|
||||
}
|
||||
@@ -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 . '")');
|
||||
|
||||
@@ -73,6 +73,6 @@ define('PACKAGE_ENABLED', 2);
|
||||
|
||||
// VERSION INFO
|
||||
|
||||
$version = '0.9.21';
|
||||
$version = '0.9.22-svn1';
|
||||
$dbversion = '2';
|
||||
$branding = '';
|
||||
|
||||
@@ -1877,3 +1877,11 @@ $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 repquota';
|
||||
$lng['serversettings']['diskquota_quotatool_path']['description'] = 'Path to quotatool';
|
||||
$lng['serversettings']['diskquota_customer_partition']['description'] = 'Partition, on which the customer files are stored';
|
||||
$lng['tasks']['diskspace_set_quota'] = 'Set quota on filesystem';
|
||||
@@ -1608,3 +1608,11 @@ $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 repquota';
|
||||
$lng['serversettings']['diskquota_quotatool_path']['description'] = 'Pfad zu quotatool';
|
||||
$lng['serversettings']['diskquota_customer_partition']['description'] = 'Partition, auf welcher die Kundendaten liegen';
|
||||
$lng['tasks']['diskspace_set_quota'] = 'Quota auf dem Dateisystem setzen';
|
||||
@@ -460,6 +460,48 @@ 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');
|
||||
|
||||
$usedquota = getFilesystemQuota();
|
||||
|
||||
# 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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($db->num_rows($result_tasks) != 0)
|
||||
|
||||
@@ -102,6 +102,11 @@ 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'])
|
||||
{
|
||||
$usedquota = getFilesystemQuota();
|
||||
}
|
||||
|
||||
$result = $db->query("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` ORDER BY `customerid` ASC");
|
||||
|
||||
@@ -286,6 +291,15 @@ while($row = $db->fetch_array($result))
|
||||
fwrite($debugHandler, 'calculating webspace usage for ' . $row['loginname'] . "\n");
|
||||
$webspaceusage = 0;
|
||||
|
||||
# Using repquota, it's faster using this tool than using du traversing the complete directory
|
||||
if ($settings['system']['diskquota_enabled'])
|
||||
{
|
||||
# We may use the array we created earlier, the used diskspace is stored in [<guid>][block][used]
|
||||
$webspaceusage = floatval($usedquota[$row['guid']]['block']['used']);
|
||||
}
|
||||
else
|
||||
{
|
||||
# Use the old fashioned way with "du"
|
||||
if(file_exists($row['documentroot']) && is_dir($row['documentroot']))
|
||||
{
|
||||
$back = safe_exec('du -sk ' . escapeshellarg($row['documentroot']) . '');
|
||||
@@ -301,6 +315,7 @@ while($row = $db->fetch_array($result))
|
||||
{
|
||||
fwrite($debugHandler, 'documentroot ' . $row['documentroot'] . ' does not exist' . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MailSpace-Usage
|
||||
|
||||
Reference in New Issue
Block a user