-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdu.php
53 lines (42 loc) · 1.59 KB
/
du.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
// parameters to be configured
$username = "owcncloud";
$password = "p455w0rd";
$hostname = "localhost";
$database = "owncloud";
$location = "/var/www/owncloud/data/"; // do not remove the trailing backslash
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db($database, $dbhandle)
or die("Could not select owncloud");
//execute the SQL query and return records
$allusers = mysql_query("select distinct userid from oc_preferences where configkey = 'lastLogin' ;");
while ($row = mysql_fetch_array($allusers)) {
$allus = $row{'userid'};
//check on disk to see directory size
$dirname = $location.$allus;
$io = popen ( '/usr/bin/du -sb ' . $dirname, 'r' );
$size = fgets ( $io, 4096);
$sizecurb = substr ( $size, 0, strpos ( $size, "\t" ) );
pclose ( $io );
// check if user has higher then default quota
$quota = mysql_query("select configvalue from oc_preferences where configkey = 'quota' and userid = '$allus' ;");
$actquot = mysql_fetch_array($quota);
//quota prolly in GB values, for nagios i want bytes
if (strpos($actquot{'configvalue'},'GB') !== false) {
list($sizecur, $unit) = explode(" ", $actquot{'configvalue'});
$maxquot = $sizecur * 1024 * 1024 * 1024;
}
//user has no custom quota, use the system default of 10 GB
else {
$maxquot = 10 * 1024 * 1024 * 1024;
}
//print username, current usage in bytes, and the max available space in bytes
echo $allus.",".$sizecurb.",".$maxquot."
";
}
//close the connection
mysql_close($dbhandle);
?>