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