Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
2782 rexy 1
<?php
2
/**
3
 * Quotas Plugin, which displays all quotas on the machine
4
 * display all quotas in a sortable table with the current values which are determined by
5
 * calling the "repquota" command line utility, another way is to provide
6
 * a file with the output of the repquota utility, so there is no need to run a execute by the
7
 * webserver, the format of the command is written down in the phpsysinfo.ini file, where also
8
 * the method of getting the information is configured
9
 *
10
 * @category  PHP
11
 * @package   PSI_Plugin_Quotas
12
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
13
 * @copyright 2009 phpSysInfo
14
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
15
 * @version   Release: 3.0
16
 * @link      http://phpsysinfo.sourceforge.net
17
 */
18
class Quotas extends PSI_Plugin
19
{
20
    /**
21
     * variable, which holds the content of the command
22
     * @var array
23
     */
24
    private $_filecontent = array();
25
 
26
    /**
27
     * variable, which holds the result before the xml is generated out of this array
28
     * @var array
29
     */
30
    private $_result = array();
31
 
32
    /**
33
     * read the data into an internal array and also call the parent constructor
34
     *
35
     * @param String $enc target encoding
36
     */
37
    public function __construct($enc)
38
    {
39
        parent::__construct(__CLASS__, $enc);
40
        switch (strtolower(PSI_PLUGIN_QUOTAS_ACCESS)) {
41
        case 'command':
42
            CommonFunctions::executeProgram("repquota", "-au", $buffer, PSI_DEBUG);
43
            break;
44
        case 'data':
45
            CommonFunctions::rfts(PSI_APP_ROOT."/data/quotas.txt", $buffer);
46
            break;
47
        default:
48
            $this->global_error->addConfigError("__construct()", "[quotas] ACCESS");
49
            break;
50
        }
51
        if (trim($buffer) != "") {
52
            $this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
53
            unset($this->_filecontent[0]);
54
        } else {
55
            $this->_filecontent = array();
56
        }
57
    }
58
 
59
    /**
60
     * doing all tasks to get the required informations that the plugin needs
61
     * result is stored in an internal array<br>the array is build like a tree,
62
     * so that it is possible to get only a specific process with the childs
63
     *
64
     * @return void
65
     */
66
    public function execute()
67
    {
68
        $i = 0;
69
        $quotas = array();
70
        foreach ($this->_filecontent as $thisline) {
71
            $thisline = preg_replace("/([\s]--)/", "", $thisline);
72
            $thisline = preg_split("/(\s)/", $thisline, -1, PREG_SPLIT_NO_EMPTY);
73
            if (count($thisline) == 7) {
74
                $quotas[$i]['user'] = str_replace("--", "", $thisline[0]);
75
                $quotas[$i]['byte_used'] = $thisline[1] * 1024;
76
                $quotas[$i]['byte_soft'] = $thisline[2] * 1024;
77
                $quotas[$i]['byte_hard'] = $thisline[3] * 1024;
78
                if ($thisline[3] != 0) {
79
                    $quotas[$i]['byte_percent_used'] = round((($quotas[$i]['byte_used'] / $quotas[$i]['byte_hard']) * 100), 1);
80
                } else {
81
                    $quotas[$i]['byte_percent_used'] = 0;
82
                }
83
                $quotas[$i]['file_used'] = $thisline[4];
84
                $quotas[$i]['file_soft'] = $thisline[5];
85
                $quotas[$i]['file_hard'] = $thisline[6];
86
                if ($thisline[6] != 0) {
87
                    $quotas[$i]['file_percent_used'] = round((($quotas[$i]['file_used'] / $quotas[$i]['file_hard']) * 100), 1);
88
                } else {
89
                    $quotas[$i]['file_percent_used'] = 0;
90
                }
91
                $i++;
92
            }
93
        }
94
        $this->_result = $quotas;
95
    }
96
 
97
    /**
98
     * generates the XML content for the plugin
99
     *
100
     * @return SimpleXMLElement entire XML content for the plugin
101
     */
102
    public function xml()
103
    {
104
        foreach ($this->_result as $quota) {
105
            $quotaChild = $this->xml->addChild("Quota");
106
            $quotaChild->addAttribute("User", $quota['user']);
107
            $quotaChild->addAttribute("ByteUsed", $quota['byte_used']);
108
            $quotaChild->addAttribute("ByteSoft", $quota['byte_soft']);
109
            $quotaChild->addAttribute("ByteHard", $quota['byte_hard']);
110
            $quotaChild->addAttribute("BytePercentUsed", $quota['byte_percent_used']);
111
            $quotaChild->addAttribute("FileUsed", $quota['file_used']);
112
            $quotaChild->addAttribute("FileSoft", $quota['file_soft']);
113
            $quotaChild->addAttribute("FileHard", $quota['file_hard']);
114
            $quotaChild->addAttribute("FilePercentUsed", $quota['file_percent_used']);
115
        }
116
 
117
        return $this->xml->getSimpleXmlElement();
118
    }
119
}