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.

phpsysinfo/includes/ups/class.nut.inc.php (4 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
 * Nut class
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_UPS
9
 * @author    Artem Volk <[email protected]>
10
 * @author    Anders Häggström <[email protected]>
11
 * @copyright 2009 phpSysInfo
12
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
13
 * @version   SVN: $Id: class.nut.inc.php 661 2012-08-27 11:26:39Z namiltd $
14
 * @link      http://phpsysinfo.sourceforge.net
15
 */
16
 /**
17
 * getting ups information from upsc program
18
 *
19
 * @category  PHP
20
 * @package   PSI_UPS
21
 * @author    Artem Volk <[email protected]>
22
 * @author    Anders Häggström <[email protected]>
23
 * @copyright 2009 phpSysInfo
24
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
25
 * @version   Release: 3.0
26
 * @link      http://phpsysinfo.sourceforge.net
27
 */
28
class Nut extends UPS
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...
29
{
30
    /**
31
     * internal storage for all gathered data
32
     *
33
     * @var array
34
     */
35
    private $_output = array();
36
37
    /**
38
     * get all information from all configured ups and store output in internal array
39
     */
40
    public function __construct()
41
    {
42
        parent::__construct();
43
        if (defined('PSI_UPS_NUT_LIST') && is_string(PSI_UPS_NUT_LIST)) {
44
            if (preg_match(ARRAY_EXP, PSI_UPS_NUT_LIST)) {
45
                $upses = eval(PSI_UPS_NUT_LIST);
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...
46
            } else {
47
                $upses = array(PSI_UPS_NUT_LIST);
48
            }
49
            foreach ($upses as $ups) {
50
                CommonFunctions::executeProgram('upsc', '-l '.trim($ups), $output);
51
                $ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
52
                foreach ($ups_names as $ups_name) {
53
                    CommonFunctions::executeProgram('upsc', trim($ups_name).'@'.trim($ups), $temp);
54
                    if (! empty($temp)) {
55
                        $this->_output[trim($ups_name).'@'.trim($ups)] = $temp;
56
                    }
57
                }
58
            }
59
        } else { //use default if address and port not defined
60
            CommonFunctions::executeProgram('upsc', '-l', $output);
61
            $ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
62 View Code Duplication
            foreach ($ups_names as $ups_name) {
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...
63
                CommonFunctions::executeProgram('upsc', trim($ups_name), $temp);
64
                if (! empty($temp)) {
65
                    $this->_output[trim($ups_name)] = $temp;
66
                }
67
            }
68
        }
69
    }
70
71
    /**
72
     * parse the input and store data in resultset for xml generation
73
     *
74
     * @return array
0 ignored issues
show
Should the return type not be array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
75
     */
76
    private function _info()
77
    {
78
        if (! empty($this->_output)) {
79
            foreach ($this->_output as $name=>$value) {
80
                $temp = preg_split("/\n/", $value, -1, PREG_SPLIT_NO_EMPTY);
81
                $ups_data = array();
82
                foreach ($temp as $value) {
83
                    $line = preg_split('/: /', $value, 2);
84
                    $ups_data[$line[0]] = isset($line[1]) ? trim($line[1]) : '';
85
                }
86
                $dev = new UPSDevice();
87
                //General
88
                $dev->setName($name);
89
                if (isset($ups_data['ups.model'])) {
90
                    $dev->setModel($ups_data['ups.model']);
91
                }
92
                if (isset($ups_data['driver.name'])) {
93
                    $dev->setMode($ups_data['driver.name']);
94
                }
95
                if (isset($ups_data['ups.status'])) {
96
                    $dev->setStatus($ups_data['ups.status']);
97
                }
98
99
                //Line
100
                if (isset($ups_data['input.voltage'])) {
101
                    $dev->setLineVoltage($ups_data['input.voltage']);
102
                }
103
                if (isset($ups_data['input.frequency'])) {
104
                    $dev->setLineFrequency($ups_data['input.frequency']);
105
                }
106
                if (isset($ups_data['ups.load'])) {
107
                    $dev->setLoad($ups_data['ups.load']);
108
                }
109
110
                //Battery
111
                if (isset($ups_data['battery.voltage'])) {
112
                    $dev->setBatteryVoltage($ups_data['battery.voltage']);
113
                }
114
                if (isset($ups_data['battery.charge'])) {
115
                    $dev->setBatterCharge($ups_data['battery.charge']);
116
                }
117
                if (isset($ups_data['battery.runtime'])) {
118
                    $dev->setTimeLeft(round($ups_data['battery.runtime']/60, 2));
119
                }
120
121
                //Temperature
122
                if (isset($ups_data['ups.temperature'])) {
123
                    $dev->setTemperatur($ups_data['ups.temperature']);
124
                }
125
126
                $this->upsinfo->setUpsDevices($dev);
127
            }
128
        }
129
    }
130
131
    /**
132
     * get the information
133
     *
134
     * @see PSI_Interface_UPS::build()
135
     *
136
     * @return Void
137
     */
138
    public function build()
139
    {
140
        $this->_info();
141
    }
142
}
143