Chore(tools): Added phpcs & fixed x-quota-usage

This commit is contained in:
2023-05-08 13:01:28 +03:00
parent 1a8c32bf4c
commit 66c31c3d3f
4 changed files with 24 additions and 22 deletions

View File

@@ -8,6 +8,9 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.php]
indent_size = 4
[.git{ignore,modules}]
indent_style = tab
indent_size = 1

8
.phpcs.xml Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<description>PHP_CodeSniffer configuration</description>
<rule ref="PSR12">
<exclude name="PSR12.Operators.OperatorSpacing"/>
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/>
</rule>
</ruleset>

BIN
local/bin/phpcs Executable file

Binary file not shown.

View File

@@ -8,24 +8,16 @@ $quota = '';
$output = [];
$fsCharLenght = 0;
if ($debug) {
$quota = "Disk quotas for user viir (uid 2913):
Filesystem blocks quota limit grace files quota limit grace
10.0.0.89:/www/webroots/2 8277615 52428800 52428800 0 0 0
10.0.0.179:/users1/users/2 1999431 52428800 52428800 0 0 0
10.0.0.90:/siilo/2 24835106 524288000 524288000 0 0 0";
} else {
// $quota = system("quota -w");
$quota = shell_exec("quota -w");
}
$quota = shell_exec("quota -w");
function pad($i, $n = 3, $p = ' ') {
function pad($i, $n = 3, $p = ' ')
{
return str_pad($i, $n, $p, STR_PAD_LEFT);
}
if (empty($quota)) {
var_dump($quota);
die("quota was empty\n");
var_dump($quota);
die("quota was empty\n");
}
$quota = explode("\n", $quota);
@@ -41,34 +33,34 @@ foreach ($quota as $lineNum => $line) {
if (count($values) != 4) {
continue;
}
$result = array_combine(['fs', 'used', 'quota', 'limit'], $values);
$result['used_percentage'] = round($result['used'] / $result['quota'] * 100, 3);
$result['used_gb'] = round($result['used'] / 1024 / 1024, 2);
$result['quota_gb'] = round($result['quota'] / 1024 / 1024, 2);
$char = strlen($result['fs']);
if ($char > $fsCharLenght) {
$fsCharLenght = $char;
}
$output[] = $result;
}
if (!empty($output)) {
$header = sprintf("%s | %s | %s | %s",
$header = sprintf(
"%s | %s | %s | %s",
str_pad("Mount", $fsCharLenght),
'Usage%',
'Used/Total',
'Bar'
);
$headerWidth = strlen($header);
echo "\n" . $header . "\n";
echo str_repeat('-', $headerWidth + 24) . "\n";
foreach ($output as $i) {
$barUsed = round($i['used_percentage']) / 4;
echo sprintf(
@@ -82,4 +74,3 @@ if (!empty($output)) {
echo "\n\n";
}