-
Notifications
You must be signed in to change notification settings - Fork 0
/
quota
40 lines (39 loc) · 1.57 KB
/
quota
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/php-cli
<?php
/*
cPanel NFS quota emulator
Copyright 2013, Cahri (http://www.cahri.com/)
Author: Julien Tessier
Licensed under LGPL (http://www.gnu.org/licenses/lgpl.html)
Version 1.0.1
*/
if(PHP_SAPI !== 'cli') die('Not running from CLI');
$user = $_SERVER['argv'][1];
if (is_numeric($user)) {
$u_id = $user;
if (!exec('getent passwd '.escapeshellarg($u_id))) die("invalid user\n");
} else {
if (!$u_id = exec('id -u '.escapeshellarg($user))) die("invalid user\n");
}
$blocks_used = $blocks_soft = $blocks_hard = $blocks_grace = $inodes_used = $inodes_soft = $inodes_hard = $inodes_grace = 0;
unset($lines);
exec('/usr/bin/quota -u '.escapeshellarg($u_id).' -vw 2>/dev/null', $lines, $ret);
if ($ret) continue;
array_shift($lines);
array_shift($lines);
foreach($lines as $line) {
$cols = preg_split('/\s+/', trim($line));
$blocks_used += (int)$cols[1];
$blocks_soft += (int)$cols[2];
$blocks_hard += (int)$cols[3];
$inodes_used += (int)$cols[4];
$inodes_soft += (int)$cols[5];
$inodes_hard += (int)$cols[6];
}
if (isset($_SERVER['argv'][2]) && $_SERVER['argv'][2] == 'fromrepquota') { // this script is called by safe_fetch_repquota
printf("%s -- %d %d %d %d %d %d %d %d\n", $user, $blocks_used, $blocks_soft, $blocks_hard, $blocks_grace, $inodes_used, $inodes_soft, $inodes_hard, $inodes_grace);
} else {
print("dev blocks quota limit grace files quota limit grace\n");
printf("/dev/root %d %d %d %d %d %d %d %d\n", $blocks_used, $blocks_soft, $blocks_hard, $blocks_grace, $inodes_used, $inodes_soft, $inodes_hard, $inodes_grace);
}
?>