diff --git a/lib/functions/filedir/function.fileImmutable.php b/lib/functions/filedir/function.fileImmutable.php index 84668804..2195ff89 100644 --- a/lib/functions/filedir/function.fileImmutable.php +++ b/lib/functions/filedir/function.fileImmutable.php @@ -22,8 +22,7 @@ * * @return boolean */ -function setImmutable($filename = null) -{ +function setImmutable($filename = null) { safe_exec(_getImmutableFunction(false).escapeshellarg($filename)); } @@ -34,8 +33,7 @@ function setImmutable($filename = null) * * @return boolean */ -function removeImmutable($filename = null) -{ +function removeImmutable($filename = null) { safe_exec(_getImmutableFunction(true).escapeshellarg($filename)); } @@ -47,19 +45,12 @@ function removeImmutable($filename = null) * * @return string functionname + parameter (not the file) */ -function _getImmutableFunction($remove = false) -{ - $output = array(); - $return_var = 0; - exec('which chattr 2>&1', $output, $return_var); +function _getImmutableFunction($remove = false) { - if((int)$return_var != 0) - { + if (isFreeBSD()) { // FreeBSD style return 'chflags '.(($remove === true) ? 'noschg ' : 'schg '); - } - else - { + } else { // Linux style return 'chattr '.(($remove === true) ? '-i ' : '+i '); } diff --git a/lib/functions/froxlor/function.getFilesystemQuota.php b/lib/functions/froxlor/function.getFilesystemQuota.php index 6738967a..f8805533 100644 --- a/lib/functions/froxlor/function.getFilesystemQuota.php +++ b/lib/functions/froxlor/function.getFilesystemQuota.php @@ -17,32 +17,47 @@ function getFilesystemQuota() { + // enabled at all? 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 - 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(); 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)) { + if (preg_match($quota_line_regex, $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] + 'grace' => (isFreeBSD() ? '0' : $matches[5]) ), 'file' => array( 'used' => $matches[6], 'soft' => $matches[7], 'hard' => $matches[8], - 'grace' => $matches[9] + 'grace' => (isFreeBSD() ? '0' : $matches[9]) ), ); } } + return $usedquota; } return false; diff --git a/lib/functions/system/function.isFreeBSD.php b/lib/functions/system/function.isFreeBSD.php new file mode 100644 index 00000000..5f2245fa --- /dev/null +++ b/lib/functions/system/function.isFreeBSD.php @@ -0,0 +1,33 @@ + (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; +} diff --git a/scripts/jobs/cron_tasks.php b/scripts/jobs/cron_tasks.php index 4da4f5f7..89485382 100644 --- a/scripts/jobs/cron_tasks.php +++ b/scripts/jobs/cron_tasks.php @@ -346,14 +346,22 @@ while ($row = $result_tasks_stmt->fetch(PDO::FETCH_ASSOC)) { && $usedquota[$row['guid']]['block']['hard'] != 0 ) { $cronlog->logAction(CRON_ACTION, LOG_NOTICE, "Disabling quota for " . $row['loginname']); - safe_exec(Settings::Get('system.diskquota_quotatool_path') . " -u " . $row['guid'] . " -bl 0 -q 0 " . escapeshellarg(Settings::Get('system.diskquota_customer_partition'))); + 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'))); + } } // 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::Get('system.diskquota_quotatool_path') . " -u " . $row['guid'] . " -bl " . $row['diskspace'] . " -q " . $row['diskspace'] . " " . escapeshellarg(Settings::Get('system.diskquota_customer_partition'))); + 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'))); + } } } }