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 | * DMRaid Plugin |
||
4 | * |
||
5 | * PHP version 5 |
||
6 | * |
||
7 | * @category PHP |
||
8 | * @package PSI_Plugin_DMRaid |
||
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.dmraid.inc.php 661 2012-08-27 11:26:39Z namiltd $ |
||
13 | * @link http://phpsysinfo.sourceforge.net |
||
14 | */ |
||
15 | /** |
||
16 | * dmraid Plugin, which displays software RAID status |
||
17 | * |
||
18 | * @category PHP |
||
19 | * @package PSI_Plugin_DMRaid |
||
20 | * @author Michael Cramer <[email protected]> |
||
21 | * @copyright 2009 phpSysInfo |
||
22 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
||
23 | * @version Release: 3.0 |
||
24 | * @link http://phpsysinfo.sourceforge.net |
||
25 | */ |
||
26 | class DMRaid extends PSI_Plugin |
||
0 ignored issues
–
show
|
|||
27 | { |
||
28 | /** |
||
29 | * variable, which holds the content of the command |
||
30 | * @var array |
||
31 | */ |
||
32 | private $_filecontent = ""; |
||
33 | |||
34 | /** |
||
35 | * variable, which holds the result before the xml is generated out of this array |
||
36 | * @var array |
||
37 | */ |
||
38 | private $_result = array(); |
||
39 | |||
40 | /** |
||
41 | * read the data into an internal array and also call the parent constructor |
||
42 | * |
||
43 | * @param String $enc encoding |
||
44 | */ |
||
45 | 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. ![]() |
|||
46 | { |
||
47 | $buffer = ""; |
||
48 | parent::__construct(__CLASS__, $enc); |
||
49 | switch (strtolower(PSI_PLUGIN_DMRAID_ACCESS)) { |
||
50 | case 'command': |
||
51 | CommonFunctions::executeProgram("dmraid", "-s -vv 2>&1", $buffer); |
||
52 | break; |
||
53 | case 'data': |
||
54 | CommonFunctions::rfts(APP_ROOT."/data/dmraid.txt", $buffer); |
||
55 | break; |
||
56 | default: |
||
57 | $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_DMRAID_ACCESS"); |
||
58 | break; |
||
59 | } |
||
60 | if (trim($buffer) != "") { |
||
61 | $this->_filecontent = preg_split("/(\r?\n\*\*\* )|(\r?\n--> )/", $buffer, -1, PREG_SPLIT_NO_EMPTY); |
||
62 | } else { |
||
63 | $this->_filecontent = array(); |
||
64 | } |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * doing all tasks to get the required informations that the plugin needs |
||
69 | * result is stored in an internal array<br>the array is build like a tree, |
||
70 | * so that it is possible to get only a specific process with the childs |
||
71 | * |
||
72 | * @return void |
||
73 | */ |
||
74 | public function execute() |
||
75 | { |
||
76 | if (empty($this->_filecontent)) { |
||
77 | return; |
||
78 | } |
||
79 | $group = ""; |
||
80 | foreach ($this->_filecontent as $block) { |
||
81 | if (preg_match('/^(NOTICE: )|(ERROR: )/m', $block)) { |
||
82 | $group = ""; |
||
83 | $lines = preg_split("/\r?\n/", $block, -1, PREG_SPLIT_NO_EMPTY); |
||
84 | foreach ($lines as $line) { |
||
85 | if (preg_match('/^NOTICE: added\s+\/dev\/(.+)\s+to RAID set\s+\"(.+)\"/', $line, $partition)) { |
||
86 | $this->_result['devices'][$partition[2]]['partitions'][$partition[1]]['status'] = "ok"; |
||
87 | } elseif (preg_match('/^ERROR: .* device\s+\/dev\/(.+)\s+(.+)\s+in RAID set\s+\"(.+)\"/', $line, $partition)) { |
||
88 | if ($partition[2]=="broken") { |
||
89 | $this->_result['devices'][$partition[3]]['partitions'][$partition[1]]['status'] = 'F'; |
||
90 | View Code Duplication | } else { |
|
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. ![]() |
|||
91 | $this->_result['devices'][$partition[3]]['partitions'][$partition[1]]['status'] = 'W'; |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | } else { |
||
96 | if (preg_match('/^Group superset\s+(.+)/m', $block, $arrname)) { |
||
97 | $group = trim($arrname[1]); |
||
98 | } |
||
99 | if (preg_match('/^name\s*:\s*(.*)/m', $block, $arrname)) { |
||
100 | if ($group=="") { |
||
101 | $group = trim($arrname[1]); |
||
102 | } |
||
103 | $this->_result['devices'][$group]['name'] = $arrname[1]; |
||
104 | View Code Duplication | if (preg_match('/^size\s*:\s*(.*)/m', $block, $size)) { |
|
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. ![]() |
|||
105 | $this->_result['devices'][$group]['size'] = trim($size[1]); |
||
106 | } |
||
107 | View Code Duplication | if (preg_match('/^stride\s*:\s*(.*)/m', $block, $stride)) { |
|
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. ![]() |
|||
108 | $this->_result['devices'][$group]['stride'] = trim($stride[1]); |
||
109 | } |
||
110 | View Code Duplication | if (preg_match('/^type\s*:\s*(.*)/m', $block, $type)) { |
|
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. ![]() |
|||
111 | $this->_result['devices'][$group]['type'] = trim($type[1]); |
||
112 | } |
||
113 | View Code Duplication | if (preg_match('/^status\s*:\s*(.*)/m', $block, $status)) { |
|
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. ![]() |
|||
114 | $this->_result['devices'][$group]['status'] = trim($status[1]); |
||
115 | } |
||
116 | View Code Duplication | if (preg_match('/^subsets\s*:\s*(.*)/m', $block, $subsets)) { |
|
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. ![]() |
|||
117 | $this->_result['devices'][$group]['subsets'] = trim($subsets[1]); |
||
118 | } |
||
119 | View Code Duplication | if (preg_match('/^devs\s*:\s*(.*)/m', $block, $devs)) { |
|
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. ![]() |
|||
120 | $this->_result['devices'][$group]['devs'] = trim($devs[1]); |
||
121 | } |
||
122 | View Code Duplication | if (preg_match('/^spares\s*:\s*(.*)/m', $block, $spares)) { |
|
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. ![]() |
|||
123 | $this->_result['devices'][$group]['spares'] = trim($spares[1]); |
||
124 | } |
||
125 | $group = ""; |
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * generates the XML content for the plugin |
||
133 | * |
||
134 | * @return SimpleXMLObject entire XML content for the plugin |
||
0 ignored issues
–
show
|
|||
135 | */ |
||
136 | public function xml() |
||
137 | { |
||
138 | if (empty($this->_result)) { |
||
139 | 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 ![]() |
|||
140 | } |
||
141 | $hideRaids = array(); |
||
142 | View Code Duplication | if (defined('PSI_PLUGIN_DMRAID_HIDE_RAID_DEVICES') && is_string(PSI_PLUGIN_DMRAID_HIDE_RAID_DEVICES)) { |
|
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. ![]() |
|||
143 | if (preg_match(ARRAY_EXP, PSI_PLUGIN_DMRAID_HIDE_RAID_DEVICES)) { |
||
144 | $hideRaids = eval(PSI_PLUGIN_DMRAID_HIDE_RAID_DEVICES); |
||
0 ignored issues
–
show
It is generally not recommended to use
eval unless absolutely required.
On one hand, ![]() |
|||
145 | } else { |
||
146 | $hideRaids = array(PSI_PLUGIN_DMRAID_HIDE_RAID_DEVICES); |
||
147 | } |
||
148 | } |
||
149 | foreach ($this->_result['devices'] as $key=>$device) { |
||
150 | if (!in_array($key, $hideRaids, true)) { |
||
151 | $dev = $this->xml->addChild("Raid"); |
||
152 | $dev->addAttribute("Device_Name", $key); |
||
153 | $dev->addAttribute("Type", $device["type"]); |
||
154 | $dev->addAttribute("Disk_Status", $device["status"]); |
||
155 | $dev->addAttribute("Name", $device["name"]); |
||
156 | $dev->addAttribute("Size", $device["size"]); |
||
157 | $dev->addAttribute("Stride", $device["stride"]); |
||
158 | $dev->addAttribute("Subsets", $device["subsets"]); |
||
159 | $dev->addAttribute("Devs", $device["devs"]); |
||
160 | $dev->addAttribute("Spares", $device["spares"]); |
||
161 | $disks = $dev->addChild("Disks"); |
||
162 | View Code Duplication | if (isset($device['partitions']) && sizeof($device['partitions']>0)) foreach ($device['partitions'] as $diskkey=>$disk) { |
|
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. ![]() |
|||
163 | $disktemp = $disks->addChild("Disk"); |
||
164 | $disktemp->addAttribute("Name", $diskkey); |
||
165 | if ($device["status"]=='ok') { |
||
166 | $disktemp->addAttribute("Status", $disk['status']); |
||
167 | } else { |
||
168 | $disktemp->addAttribute("Status", 'W'); |
||
169 | } |
||
170 | } |
||
171 | } |
||
172 | } |
||
173 | |||
174 | 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 ![]() |
|||
175 | } |
||
176 | } |
||
177 |
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.