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) <eleras@froxlor.org>
This commit is contained in:
Florian Aders (EleRas)
2011-06-18 19:42:01 +02:00
parent cfa94c5837
commit 7a28108475
4 changed files with 155 additions and 35 deletions

View File

@@ -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';

View File

@@ -1608,3 +1608,10 @@ $lng['gender']['female'] = 'Frau';
$lng['gender']['undef'] = '';
$lng['serversettings']['backup_ftp_passive_mode'] = 'Passiven &Uuml;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';

View File

@@ -460,6 +460,73 @@ 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');
}
}
}
if($db->num_rows($result_tasks) != 0)

View File

@@ -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))
@@ -286,6 +315,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 +339,7 @@ while($row = $db->fetch_array($result))
{
fwrite($debugHandler, 'documentroot ' . $row['documentroot'] . ' does not exist' . "\n");
}
}
/**
* MailSpace-Usage