Issues (1626)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

plugins/snmppinfo/class.snmppinfo.inc.php (11 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * SNMPPInfo Plugin
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_Plugin_SNMPPInfo
9
 * @author    Mieczyslaw Nalewaj <[email protected]>
10
 * @copyright 2011 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
12
 * @version   SVN: $Id: class.snmppinfo.inc.php 661 2012-08-27 11:26:39Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
 /**
16
 * SNMPPInfo Plugin, which displays battery state
17
 *
18
 * @category  PHP
19
 * @package   PSI_Plugin_SNMPPInfo
20
 * @author    Mieczyslaw Nalewaj <[email protected]>
21
 * @copyright 2011 phpSysInfo
22
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
23
 * @version   $Id: class.snmppinfo.inc.php 661 2012-08-27 11:26:39Z namiltd $
24
 * @link      http://phpsysinfo.sourceforge.net
25
 */
26
class SNMPPInfo extends PSI_Plugin
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
27
{
28
    /**
29
     * variable, which holds the content of the command
30
     * @var array
31
     */
32
    private $_filecontent = array();
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
    public function __construct($enc)
46
    {
47
        parent::__construct(__CLASS__, $enc);
48
        switch (strtolower(PSI_PLUGIN_SNMPPINFO_ACCESS)) {
49
        case 'command':
50
                if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) {
51
                    if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) {
52
                        $printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES);
0 ignored issues
show
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
53
                    } else {
54
                        $printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES);
55
                    }
56
                    foreach ($printers as $printer) {
57
                        CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 ".$printer." .1.3.6.1.2.1.1.5", $buffer, PSI_DEBUG);
58
                        if (strlen($buffer) > 0) {
59
                            $this->_filecontent[$printer] = $buffer;
60
61
                            CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 ".$printer." .1.3.6.1.2.1.43.11.1.1", $buffer2, PSI_DEBUG);
62
                            if (strlen($buffer2) > 0) {
63
                               $this->_filecontent[$printer] .= "\n".$buffer2;
64
                            }
65
                            CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 ".$printer." .1.3.6.1.2.1.43.18.1.1", $buffer3, PSI_DEBUG);
66
                            if (strlen($buffer3) > 0) {
67
                               $this->_filecontent[$printer] .= "\n".$buffer3;
68
                            }
69
                        }
70
                    }
71
                }
72
                break;
73
        case 'php-snmp':
74
                if (!extension_loaded("snmp")) {
75
                    $this->global_error->addError("Requirements error", "SNMPPInfo plugin requires the snmp extension to php in order to work properly");
76
                    break;
77
                }
78
                snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
79
                snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
80
                if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) {
81
                    if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) {
82
                        $printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES);
0 ignored issues
show
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
83
                    } else {
84
                        $printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES);
85
                    }
86
                    foreach ($printers as $printer) {
87
                        if (! PSI_DEBUG) {
88
                            restore_error_handler(); /* default error handler */
89
                            $old_err_rep = error_reporting();
90
                            error_reporting(E_ERROR); /* fatal errors only */
91
                        }
92
                        $bufferarr=snmprealwalk($printer, "public", ".1.3.6.1.2.1.1.5", 1000000, 1);
93
                        if (! PSI_DEBUG) {
94
                            error_reporting($old_err_rep); /* restore error level */
0 ignored issues
show
The variable $old_err_rep 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
95
                            set_error_handler('errorHandlerPsi'); /* restore error handler */
96
                        }
97
                        if (! empty($bufferarr)) {
98
                            $buffer="";
99
                            foreach ($bufferarr as $id=>$string) {
100
                                $buffer .= $id." = ".$string."\n";
101
                            }
102
103
                            if (! PSI_DEBUG) {
104
                                restore_error_handler(); /* default error handler */
105
                                $old_err_rep = error_reporting();
106
                                error_reporting(E_ERROR); /* fatal errors only */
107
                            }
108
                            $bufferarr2=snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.11.1.1", 1000000, 1);
109
                            if (! PSI_DEBUG) {
110
                                error_reporting($old_err_rep); /* restore error level */
111
                                set_error_handler('errorHandlerPsi'); /* restore error handler */
112
                            }
113 View Code Duplication
                            if (! empty($bufferarr2)) {
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.

Loading history...
114
                                foreach ($bufferarr2 as $id=>$string) {
115
                                    $buffer .= $id." = ".$string."\n";
116
                                }
117
                            }
118
119
                            if (! PSI_DEBUG) {
120
                                restore_error_handler(); /* default error handler */
121
                                $old_err_rep = error_reporting();
122
                                error_reporting(E_ERROR); /* fatal errors only */
123
                            }
124
                            $bufferarr3=snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.18.1.1", 1000000, 1);
125
                            if (! PSI_DEBUG) {
126
                                error_reporting($old_err_rep); /* restore error level */
127
                                set_error_handler('errorHandlerPsi'); /* restore error handler */
128
                            }
129 View Code Duplication
                            if (! empty($bufferarr3)) {
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.

Loading history...
130
                                foreach ($bufferarr3 as $id=>$string) {
131
                                    $buffer .= $id." = ".$string."\n";
132
                                }
133
                            }
134
135
                            if (strlen(trim($buffer)) > 0) {
136
                                $this->_filecontent[$printer] = $buffer;
137
                            }
138
                        }
139
                    }
140
                }
141
                break;
142
        case 'data':
143 View Code Duplication
                if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_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.

Loading history...
144
                    if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) {
145
                        $printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES);
0 ignored issues
show
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
146
                    } else {
147
                        $printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES);
148
                    }
149
                    $pn=0;
150
                    foreach ($printers as $printer) {
151
                        $buffer="";
152
                        if (CommonFunctions::rfts(APP_ROOT."/data/snmppinfo{$pn}.txt", $buffer) && !empty($buffer)) {
153
                            $this->_filecontent[$printer] = $buffer;
154
                        }
155
                        $pn++;
156
                    }
157
                }
158
                break;
159
            default:
160
                $this->global_error->addError("switch(PSI_PLUGIN_SNMPPINFO_ACCESS)", "Bad SNMPPInfo configuration in phpsysinfo.ini");
161
                break;
162
        }
163
    }
164
165
    /**
166
     * doing all tasks to get the required informations that the plugin needs
167
     * result is stored in an internal array
168
     *
169
     * @return void
170
     */
171
    public function execute()
172
    {
173
        if (empty($this->_filecontent)) {
174
            return;
175
        }
176
        foreach ($this->_filecontent as $printer=>$result) {
177
            $lines = preg_split('/\r?\n/', $result);
178
            foreach ($lines as $line) {
179
                if (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.11\.1\.1\.6\.1\.(.*) = STRING:\s(.*)/', $line, $data)) {
180
                    $this->_result[$printer][$data[1]]['prtMarkerSuppliesDescription']=trim($data[2], "\"");
181
                } elseif (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.11\.1\.1\.7\.1\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
182
                    $this->_result[$printer][$data[1]]['prtMarkerSuppliesSupplyUnit']=$data[2];
183
                } elseif (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.11\.1\.1\.8\.1\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
184
                    $this->_result[$printer][$data[1]]['prtMarkerSuppliesMaxCapacity']=$data[2];
185
                } elseif (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.11\.1\.1\.9\.1\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
186
                    $this->_result[$printer][$data[1]]['prtMarkerSuppliesLevel']=$data[2];
187 View Code Duplication
                } elseif (preg_match('/^\.1\.3\.6\.1\.2\.1\.1\.5\.0 = STRING:\s(.*)/', $line, $data)) {
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.

Loading history...
188
                    $this->_result[$printer][0]['prtMarkerSuppliesDescription']=trim($data[1], "\"");;
189
                } elseif (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.18\.1\.1\.8\.1\.(.*) = STRING:\s(.*)/', $line, $data)) {
190
                    $this->_result[$printer][99][$data[1]]["message"]=trim($data[2], "\"");
191 View Code Duplication
                } elseif (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.18\.1\.1\.2\.1\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
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.

Loading history...
192
                    $this->_result[$printer][99][$data[1]]["severity"]=$data[2];
193
                }
194
            }
195
        }
196
    }
197
198
    /**
199
     * generates the XML content for the plugin
200
     *
201
     * @return SimpleXMLElement entire XML content for the plugin
202
     */
203
    public function xml()
204
    {
205
        foreach ($this->_result as $printer=>$markersupplies_item) {
206
            $xmlsnmppinfo_printer = $this->xml->addChild("Printer");
207
            $xmlsnmppinfo_printer->addAttribute("Device", $printer);
208
            foreach ($markersupplies_item as $marker=>$snmppinfo_item) {
209
210
                if ($marker==0) {
211
                    $xmlsnmppinfo_printer->addAttribute("Name", $snmppinfo_item['prtMarkerSuppliesDescription']);
212
                } elseif ($marker==99) {
213
                    foreach ($snmppinfo_item as $item=>$iarr) {
214
                        if (isset($iarr["message"]) && $iarr["message"] != "") {
215
                            $xmlsnmppinfo_errors = $xmlsnmppinfo_printer->addChild("PrinterMessage");
216
                            $xmlsnmppinfo_errors->addAttribute("Message", $iarr["message"]);
217
                            $xmlsnmppinfo_errors->addAttribute("Severity", $iarr["severity"]);
218
                        }
219
                    }
220
                } else {
221
                    $xmlsnmppinfo = $xmlsnmppinfo_printer->addChild("MarkerSupplies");
222
223
                    $xmlsnmppinfo->addAttribute("Description", isset($snmppinfo_item['prtMarkerSuppliesDescription']) ? $snmppinfo_item['prtMarkerSuppliesDescription'] : "");
224
                    $xmlsnmppinfo->addAttribute("SupplyUnit", isset($snmppinfo_item['prtMarkerSuppliesSupplyUnit']) ? $snmppinfo_item['prtMarkerSuppliesSupplyUnit'] : "");
225
                    $xmlsnmppinfo->addAttribute("MaxCapacity", isset($snmppinfo_item['prtMarkerSuppliesMaxCapacity']) ? $snmppinfo_item['prtMarkerSuppliesMaxCapacity'] : "");
226
                    $xmlsnmppinfo->addAttribute("Level", isset($snmppinfo_item['prtMarkerSuppliesLevel']) ? $snmppinfo_item['prtMarkerSuppliesLevel'] : "");
227
                }
228
            }
229
        }
230
231
        return $this->xml->getSimpleXmlElement();
0 ignored issues
show
Bug Best Practice introduced by
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 my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
232
    }
233
}
234