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.apcupsd.inc.php (5 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
 * Apcupsd class
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_UPS
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.apcupsd.inc.php 661 2012-08-27 11:26:39Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
 /**
16
 * getting ups information from apcupsd program
17
 *
18
 * @category  PHP
19
 * @package   PSI_UPS
20
 * @author    Michael Cramer <[email protected]>
21
 * @author    Artem Volk <[email protected]>
22
 * @copyright 2009 phpSysInfo
23
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
24
 * @version   Release: 3.0
25
 * @link      http://phpsysinfo.sourceforge.net
26
 */
27
class Apcupsd 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...
28
{
29
    /**
30
     * internal storage for all gathered data
31
     *
32
     * @var Array
33
     */
34
    private $_output = array();
35
36
    /**
37
     * get all information from all configured ups in phpsysinfo.ini and store output in internal array
38
     */
39
    public function __construct()
40
    {
41
        parent::__construct();
42
        if (defined('PSI_UPS_APCUPSD_LIST') && is_string(PSI_UPS_APCUPSD_LIST)) {
43
            if (preg_match(ARRAY_EXP, PSI_UPS_APCUPSD_LIST)) {
44
                $upses = eval(PSI_UPS_APCUPSD_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...
45
            } else {
46
                $upses = array(PSI_UPS_APCUPSD_LIST);
47
            }
48 View Code Duplication
            foreach ($upses as $ups) {
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...
49
                CommonFunctions::executeProgram('apcaccess', 'status '.trim($ups), $temp);
50
                if (! empty($temp)) {
51
                    $this->_output[] = $temp;
52
                }
53
            }
54
        } else { //use default if address and port not defined
55
            CommonFunctions::executeProgram('apcaccess', 'status', $temp);
56
            if (! empty($temp)) {
57
                $this->_output[] = $temp;
58
            }
59
        }
60
    }
61
62
    /**
63
     * parse the input and store data in resultset for xml generation
64
     *
65
     * @return Void
66
     */
67
    private function _info()
68
    {
69
        foreach ($this->_output as $ups) {
70
71
            $dev = new UPSDevice();
72
73
            // General info
74
            if (preg_match('/^UPSNAME\s*:\s*(.*)$/m', $ups, $data)) {
75
                $dev->setName(trim($data[1]));
76
            }
77
            if (preg_match('/^MODEL\s*:\s*(.*)$/m', $ups, $data)) {
78
                $model=trim($data[1]);
79
                if (preg_match('/^APCMODEL\s*:\s*(.*)$/m', $ups, $data)) {
80
                    $dev->setModel($model.' ('.trim($data[1]).')');
81
                } else {
82
                    $dev->setModel($model);
83
                }
84
            }
85
            if (preg_match('/^UPSMODE\s*:\s*(.*)$/m', $ups, $data)) {
86
                $dev->setMode(trim($data[1]));
87
            }
88
            if (preg_match('/^STARTTIME\s*:\s*(.*)$/m', $ups, $data)) {
89
                $dev->setStartTime(trim($data[1]));
90
            }
91
            if (preg_match('/^STATUS\s*:\s*(.*)$/m', $ups, $data)) {
92
                $dev->setStatus(trim($data[1]));
93
            }
94
            if (preg_match('/^ITEMP\s*:\s*(.*)$/m', $ups, $data)) {
95
                $dev->setTemperatur(trim($data[1]));
96
            }
97
            // Outages
98
            if (preg_match('/^NUMXFERS\s*:\s*(.*)$/m', $ups, $data)) {
99
                $dev->setOutages(trim($data[1]));
100
            }
101
            if (preg_match('/^LASTXFER\s*:\s*(.*)$/m', $ups, $data)) {
102
                $dev->setLastOutage(trim($data[1]));
103
            }
104
            if (preg_match('/^XOFFBATT\s*:\s*(.*)$/m', $ups, $data)) {
105
                $dev->setLastOutageFinish(trim($data[1]));
106
            }
107
            // Line
108
            if (preg_match('/^LINEV\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
109
                $dev->setLineVoltage(trim($data[1]));
110
            }
111
            if (preg_match('/^LINEFREQ\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
112
                $dev->setLineFrequency(trim($data[1]));
113
            }
114
            if (preg_match('/^LOADPCT\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
115
                $dev->setLoad(trim($data[1]));
116
            }
117
            // Battery
118
            if (preg_match('/^BATTDATE\s*:\s*(.*)$/m', $ups, $data)) {
119
                $dev->setBatteryDate(trim($data[1]));
0 ignored issues
show
trim($data[1]) is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
120
            }
121
            if (preg_match('/^BATTV\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
122
                $dev->setBatteryVoltage(trim($data[1]));
0 ignored issues
show
trim($data[1]) is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
123
            }
124
            if (preg_match('/^BCHARGE\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
125
                $dev->setBatterCharge(trim($data[1]));
126
            }
127
            if (preg_match('/^TIMELEFT\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
128
                $dev->setTimeLeft(trim($data[1]));
129
            }
130
            $this->upsinfo->setUpsDevices($dev);
131
        }
132
    }
133
134
    /**
135
     * get the information
136
     *
137
     * @see PSI_Interface_UPS::build()
138
     *
139
     * @return Void
140
     */
141
    public function build()
142
    {
143
        $this->_info();
144
    }
145
}
146