Issues (4)

Security Analysis    no request data  

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.

src/Sysinfo/Snapshot.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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 23 and the first side effect is on line 140.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
Copyright 2016 Anton Petersson
4
5
This file is part of Sysinfo.
6
7
Sysinfo is free software: you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
11
12
Sysinfo is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with Sysinfo.  If not, see <http://www.gnu.org/licenses/>.
19
*/
20
21
namespace Anpk12\Sysinfo;
22
23
class Snapshot
24
{
25
    private $procDir;
26 3
    function __construct($procDir='/proc')
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
27
    {
28 3
        $this->procDir = $procDir;
29 3
        $this->readLoadAvg();
30 3
        $this->readMeminfo();
31 3
    }
32
33
    private $loadavgData = [];
34 3
    private function readLoadAvg()
35
    {
36 3
        $f = fopen($this->procDir . "/loadavg", "r");
37 3
        if ( !$f )
38 3
            throw new Exception("failed to read loadavg");
39 3
        if ( ($str = fgets($f)) != FALSE )
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $str = fgets($f) of type string to the boolean FALSE. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
40 3
        {
41 3
            $this->loadavgData = explode(" ", $str);
42 3
            unset($this->loadavgData[3]);
43 3
            unset($this->loadavgData[4]);
44 3
        }
45 3
        fclose($f);
46 3
    }
47
48 2
    public function loadavg()
49
    {
50 2
        return $this->loadavgData;
51
    }
52
53
    private $meminfoData = [];
54 3
    private function readMeminfo()
55
    {
56 3
        $f = fopen($this->procDir . "/meminfo", "r");
57 3
        $this->meminfoData = [];
58 3
        if ( !$f )
59 3
            throw new Exception("failed to read meminfo");
60 3
        while ( ($str = fgets($f)) != FALSE )
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $str = fgets($f) of type string to the boolean FALSE. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
61
        {
62 3
            $numMatches = preg_match_all(
63 3
            "/([[:alpha:]()_0-9]+):\s+([0-9]+)(?:\s([[:alpha:]]+)){0,1}/",
64 3
                $str, $entry, PREG_SPLIT_DELIM_CAPTURE);
65 3
            if ( $numMatches > 0 )
66 3
            {
67 3
                $key = $entry[0][1];
68 3
                $newEntry = array('value' => $entry[0][2]);
69 3
                if ( isset($entry[0][3]) )
70 3
                {
71 3
                    $newEntry['unit'] = $entry[0][3];
72 3
                }
73 3
                $this->meminfoData[$key] = $newEntry;
74 3
            }
75 3
        }
76 3
        fclose($f);
77 3
    }
78
79
    /**
80
    Return all info from /proc/meminfo
81
    */
82 2
    public function meminfo()
83
    {
84 2
        return $this->meminfoData;
85
    }
86
87 1
    public function memTotal()
88
    {
89 1
        return $this->meminfoData['MemTotal'];
90
    }
91
92 1
    public function memAvailable()
93
    {
94 1
        return  $this->meminfoData['MemAvailable'];
95
    }
96
97 1
    public function htmlReport($summary=false)
98
    {
99 1
        $report = "<h2>Host system stats</h2>";
100 1
        $report .= "<h3>Memory</h3>";
101 1
        if ( $summary === true )
102 1
        {
103 1
            $mema = $this->memAvailable();
104 1
            $memt = $this->memTotal();
105 1
            $report .= "<p><strong>".entryStr($mema)."</strong> available
106 1
                out of a total of <strong>".entryStr($memt)."</strong></p>";
107 1
        } else
108
        {
109 1
            $report .= $this->memHtmlReport();
110
        }
111
112 1
        $report .= "<h3>Load</h3>";
113 1
        $loadavg = $this->loadavg();
114
        $report .= "<p>Average number of jobs in run queue or 
115
            waiting for disk I/O the last 1, 5, and 15 minutes: <strong>"
116 1
            .$loadavg[0]."</strong>, <strong>".$loadavg[1]."</strong>, <strong>".$loadavg[2]."</strong></p>";
117
118 1
        return $report;
119
    }
120 1
    public function memHtmlReport()
121
    {
122 1
        $mem = $this->meminfo();
123
124 1
        $html = '<table>';
125 1
        foreach ( $mem as $key => $entry )
126
        {
127 1
            $html .= '<tr>';
128 1
            $html .= '<td class="sysinfo_key">'.$key.
129 1
                '</td><td class="sysinfo_value">'.$entry['value'] .'</td>';
130 1
            if ( isset($entry['unit']) )
131 1
            {
132 1
                $html .= '<td class="sysinfo_unit">'.$entry['unit'].'</td>';
133 1
            }
134 1
            $html .= '</tr>';
135 1
        }
136 1
        $html .= '</table>';
137
138 1
        return $html;
139
    }
140
};
141
142
function entryStr($entry)
143
{
144 1
    return $entry['value'].$entry['unit'];
145
}
146
147