aboutsummaryrefslogtreecommitdiffstats
path: root/libs/disk.php
blob: d3d3199a6b3257cb4b15cbbb78ca330603c283b5 (plain)
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
<?php
require 'Utils/Misc.class.php';

$datas = array();

if (!(exec('/bin/df | awk \'{print $2","$3","$4","$5","$6}\'', $df)))
{
    $datas[] = array(
        'total'         => 'N.A',
        'used'          => 'N.A',
        'free'          => 'N.A',
        'percent_used'  => 0,
        'mount'         => 'N.A',
    );
}
else
{
    $first_line = false;

    $mounted_points = array();

    foreach ($df as $mounted)
    {
        if ($first_line === false)
        {
            $first_line = true;
            continue;
        }

        list($total, $used, $free, $percent, $mount) = explode(',', $mounted);

        if (!in_array($mount, $mounted_points))
        {
            $mounted_points[] = trim($mount);

            $datas[] = array(
                'total'         => Misc::getSize($total * 1024),
                'used'          => Misc::getSize($used * 1024),
                'free'          => Misc::getSize($free * 1024),
                'percent_used'  => trim($percent, '%'),
                'mount'         => $mount,
            );
        }
    }

}


echo json_encode($datas);