This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 |
||
0 ignored issues
–
show
|
|||
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) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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); |
||
0 ignored issues
–
show
The variable
$buffer does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
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) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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(); |
||
0 ignored issues
–
show
The return type of
return $this->xml->getSimpleXmlElement(); (SimpleXMLElement ) is incompatible with the return type declared by the interface PSI_Interface_Plugin::xml of type SimpleXMLObject .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
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.