fix quota on freebsd, thanks to skotti's patch. fixes #1377

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2014-02-21 08:04:26 +01:00
parent c59fe0e4ad
commit e650be3814
4 changed files with 67 additions and 20 deletions

View File

@@ -22,8 +22,7 @@
* *
* @return boolean * @return boolean
*/ */
function setImmutable($filename = null) function setImmutable($filename = null) {
{
safe_exec(_getImmutableFunction(false).escapeshellarg($filename)); safe_exec(_getImmutableFunction(false).escapeshellarg($filename));
} }
@@ -34,8 +33,7 @@ function setImmutable($filename = null)
* *
* @return boolean * @return boolean
*/ */
function removeImmutable($filename = null) function removeImmutable($filename = null) {
{
safe_exec(_getImmutableFunction(true).escapeshellarg($filename)); safe_exec(_getImmutableFunction(true).escapeshellarg($filename));
} }
@@ -47,19 +45,12 @@ function removeImmutable($filename = null)
* *
* @return string functionname + parameter (not the file) * @return string functionname + parameter (not the file)
*/ */
function _getImmutableFunction($remove = false) function _getImmutableFunction($remove = false) {
{
$output = array();
$return_var = 0;
exec('which chattr 2>&1', $output, $return_var);
if((int)$return_var != 0) if (isFreeBSD()) {
{
// FreeBSD style // FreeBSD style
return 'chflags '.(($remove === true) ? 'noschg ' : 'schg '); return 'chflags '.(($remove === true) ? 'noschg ' : 'schg ');
} } else {
else
{
// Linux style // Linux style
return 'chattr '.(($remove === true) ? '-i ' : '+i '); return 'chattr '.(($remove === true) ? '-i ' : '+i ');
} }

View File

@@ -17,32 +17,47 @@
function getFilesystemQuota() { function getFilesystemQuota() {
// enabled at all?
if (Settings::Get('system.diskquota_enabled')) { if (Settings::Get('system.diskquota_enabled')) {
// set linux defaults
$repquota_params = "-np";
//$quota_line_regex = "/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)/i";
$quota_line_regex = "/^#([0-9]+)\s+[+-]{2}\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/i";
// check for freebsd - which needs other values
if (isFreeBSD()) {
$repquota_params = "-nu";
$quota_line_regex = "/^([0-9]+)\s+[+-]{2}\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)/i";
}
// Fetch all quota in the desired partition // Fetch all quota in the desired partition
exec(Settings::Get('system.diskquota_repquota_path') . " -np " . escapeshellarg(Settings::Get('system.diskquota_customer_partition')), $repquota); exec(Settings::Get('system.diskquota_repquota_path') . " " . $repquota_params . " " . escapeshellarg(Settings::Get('system.diskquota_customer_partition')), $repquota);
$usedquota = array(); $usedquota = array();
foreach ($repquota as $tmpquota) { foreach ($repquota as $tmpquota) {
// Let's see if the line matches a quota - line // 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)) { if (preg_match($quota_line_regex, $tmpquota, $matches)) {
// It matches - put it into an array with userid as key (for easy lookup later) // It matches - put it into an array with userid as key (for easy lookup later)
$usedquota[$matches[1]] = array( $usedquota[$matches[1]] = array(
'block' => array( 'block' => array(
'used' => $matches[2], 'used' => $matches[2],
'soft' => $matches[3], 'soft' => $matches[3],
'hard' => $matches[4], 'hard' => $matches[4],
'grace' => $matches[5] 'grace' => (isFreeBSD() ? '0' : $matches[5])
), ),
'file' => array( 'file' => array(
'used' => $matches[6], 'used' => $matches[6],
'soft' => $matches[7], 'soft' => $matches[7],
'hard' => $matches[8], 'hard' => $matches[8],
'grace' => $matches[9] 'grace' => (isFreeBSD() ? '0' : $matches[9])
), ),
); );
} }
} }
return $usedquota; return $usedquota;
} }
return false; return false;

View File

@@ -0,0 +1,33 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2014 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> (2014-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
/**
* check if the system is FreeBSD (if exact)
* or BSD-based (NetBSD, OpenBSD, etc. if exact = false [default])
*
* @param boolean $exact whether to check explicitly for FreeBSD or *BSD
*
* @return boolean
*/
function isFreeBSD($exact = false) {
if (($exact && PHP_OS == 'FreeBSD')
|| (!$exact && stristr(PHP_OS, 'BSD'))
) {
return true;
}
return false;
}

View File

@@ -346,18 +346,26 @@ while ($row = $result_tasks_stmt->fetch(PDO::FETCH_ASSOC)) {
&& $usedquota[$row['guid']]['block']['hard'] != 0 && $usedquota[$row['guid']]['block']['hard'] != 0
) { ) {
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, "Disabling quota for " . $row['loginname']); $cronlog->logAction(CRON_ACTION, LOG_NOTICE, "Disabling quota for " . $row['loginname']);
if (isFreeBSD()) {
safe_exec(Settings::Get('system.diskquota_quotatool_path') . " -e " . escapeshellarg(Settings::Get('system.diskquota_customer_partition')) . ":0:0 " . $row['guid']);
} else {
safe_exec(Settings::Get('system.diskquota_quotatool_path') . " -u " . $row['guid'] . " -bl 0 -q 0 " . escapeshellarg(Settings::Get('system.diskquota_customer_partition'))); safe_exec(Settings::Get('system.diskquota_quotatool_path') . " -u " . $row['guid'] . " -bl 0 -q 0 " . escapeshellarg(Settings::Get('system.diskquota_customer_partition')));
} }
}
// The user quota in Froxlor is different than on the filesystem // The user quota in Froxlor is different than on the filesystem
elseif ($row['diskspace'] != $usedquota[$row['guid']]['block']['hard'] elseif ($row['diskspace'] != $usedquota[$row['guid']]['block']['hard']
&& $row['diskspace'] != -1024 && $row['diskspace'] != -1024
) { ) {
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, "Setting quota for " . $row['loginname'] . " from " . $usedquota[$row['guid']]['block']['hard'] . " to " . $row['diskspace']); $cronlog->logAction(CRON_ACTION, LOG_NOTICE, "Setting quota for " . $row['loginname'] . " from " . $usedquota[$row['guid']]['block']['hard'] . " to " . $row['diskspace']);
if (isFreeBSD()) {
safe_exec(Settings::Get('system.diskquota_quotatool_path') . " -e " . escapeshellarg(Settings::Get('system.diskquota_customer_partition')) . ":" . $row['diskspace'] . ":" . $row['diskspace'] . " " . $row['guid']);
} else {
safe_exec(Settings::Get('system.diskquota_quotatool_path') . " -u " . $row['guid'] . " -bl " . $row['diskspace'] . " -q " . $row['diskspace'] . " " . escapeshellarg(Settings::Get('system.diskquota_customer_partition'))); safe_exec(Settings::Get('system.diskquota_quotatool_path') . " -u " . $row['guid'] . " -bl " . $row['diskspace'] . " -q " . $row['diskspace'] . " " . escapeshellarg(Settings::Get('system.diskquota_customer_partition')));
} }
} }
} }
} }
}
} }
if ($num_results != 0) { if ($num_results != 0) {