diff --git a/.editorconfig b/.editorconfig index 6d861c6..cb70ad6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..2260283 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,8 @@ + + + PHP_CodeSniffer configuration + + + + + diff --git a/local/bin/phpcs b/local/bin/phpcs new file mode 100755 index 0000000..63fbe7b Binary files /dev/null and b/local/bin/phpcs differ diff --git a/local/bin/x-quota-usage.php b/local/bin/x-quota-usage.php index 777c9d4..87d422b 100755 --- a/local/bin/x-quota-usage.php +++ b/local/bin/x-quota-usage.php @@ -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"; } -