|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
echo "<!DOCTYPE html>"; |
|
3
|
|
|
echo "<meta charset=\"UTF-8\">"; |
|
4
|
|
|
echo "<title> </title>"; |
|
5
|
|
|
echo "<body>"; |
|
6
|
|
|
|
|
7
|
|
|
define('APP_ROOT', dirname(__FILE__).'/..'); |
|
8
|
|
|
require_once APP_ROOT.'/includes/interface/class.PSI_Interface_OS.inc.php'; |
|
9
|
|
|
require_once APP_ROOT.'/includes/os/class.OS.inc.php'; |
|
10
|
|
|
require_once APP_ROOT.'/includes/to/class.System.inc.php'; |
|
11
|
|
|
require_once APP_ROOT.'/includes/os/class.Linux.inc.php'; |
|
12
|
|
|
define('PSI_USE_VHOST', false); |
|
13
|
|
|
define('PSI_DEBUG', false); |
|
14
|
|
|
define('PSI_LOAD_BAR', false); |
|
15
|
|
|
|
|
16
|
|
|
$log_file = ""; |
|
17
|
|
|
$lsb = true; //enable detection lsb_release -a |
|
18
|
|
|
$lsbfile = true; //enable detection /etc/lsb-release |
|
19
|
|
|
|
|
20
|
|
|
class PSI_Error |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
public static function singleton() |
|
23
|
|
|
{ |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
class Parser |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
public static function lspci() |
|
30
|
|
|
{ |
|
31
|
|
|
return array(); |
|
32
|
|
|
} |
|
33
|
|
|
public static function df() |
|
34
|
|
|
{ |
|
35
|
|
|
return array(); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
class CommonFunctions |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
private static function _parse_log_file($string) |
|
42
|
|
|
{ |
|
43
|
|
|
global $log_file; |
|
|
|
|
|
|
44
|
|
|
if (file_exists($log_file)) { |
|
45
|
|
|
$contents = @file_get_contents($log_file); |
|
46
|
|
|
$contents = preg_replace("/\r\n/", "\n", $contents); |
|
47
|
|
View Code Duplication |
if ($contents && preg_match("/^\-\-\-\-\-\-\-\-\-\-".preg_quote($string, '/')."\-\-\-\-\-\-\-\-\-\-\n/m", $contents, $matches, PREG_OFFSET_CAPTURE)) { |
|
|
|
|
|
|
48
|
|
|
$findIndex = $matches[0][1]; |
|
49
|
|
|
if (preg_match("/\n/m", $contents, $matches, PREG_OFFSET_CAPTURE, $findIndex)) { |
|
50
|
|
|
$startIndex = $matches[0][1]+1; |
|
51
|
|
|
if (preg_match("/^\-\-\-\-\-\-\-\-\-\-/m", $contents, $matches, PREG_OFFSET_CAPTURE, $startIndex)) { |
|
52
|
|
|
$stopIndex = $matches[0][1]; |
|
53
|
|
|
|
|
54
|
|
|
return substr($contents, $startIndex, $stopIndex-$startIndex); |
|
55
|
|
|
} else { |
|
56
|
|
|
return substr($contents, $startIndex); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
global $lsb; |
|
|
|
|
|
|
68
|
|
|
global $lsbfile; |
|
|
|
|
|
|
69
|
|
|
if ($lsb || $lsbfile || ($strFileName != "/etc/lsb-release")) { |
|
70
|
|
|
$strRet=self::_parse_log_file($strFileName); |
|
71
|
|
|
if ($strRet && ($intLines == 1) && (strpos($strRet, "\n") !== false)) { |
|
|
|
|
|
|
72
|
|
|
$strRet=trim(substr($strRet, 0, strpos($strRet, "\n"))); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $strRet; |
|
76
|
|
|
} else { |
|
77
|
|
|
return false; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true) |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
global $lsb; |
|
|
|
|
|
|
84
|
|
|
$strBuffer = ''; |
|
85
|
|
|
if ($strProgramname=='lsb_release') { |
|
86
|
|
|
return $lsb && ($strBuffer = self::_parse_log_file('lsb_release -a')); |
|
87
|
|
|
} else { |
|
88
|
|
|
return $strBuffer = self::_parse_log_file($strProgramname); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public static function fileexists($strFileName) |
|
93
|
|
|
{ |
|
94
|
|
|
global $log_file; |
|
|
|
|
|
|
95
|
|
|
global $lsb; |
|
|
|
|
|
|
96
|
|
|
global $lsbfile; |
|
|
|
|
|
|
97
|
|
|
if (file_exists($log_file) |
|
98
|
|
|
&& ($lsb || $lsbfile || ($strFileName != "/etc/lsb-release")) |
|
99
|
|
|
&& ($contents = @file_get_contents($log_file)) |
|
100
|
|
|
&& preg_match("/^\-\-\-\-\-\-\-\-\-\-".preg_quote($strFileName, '/')."\-\-\-\-\-\-\-\-\-\-\r?\n/m", $contents)) { |
|
101
|
|
|
return true; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return false; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public static function gdc() |
|
108
|
|
|
{ |
|
109
|
|
|
return array(); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
class _Linux extends Linux |
|
|
|
|
|
|
114
|
|
|
{ |
|
115
|
|
|
public function build() |
|
116
|
|
|
{ |
|
117
|
|
|
parent::_distro(); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
$system = new _Linux(); |
|
122
|
|
|
if ($handle = opendir(APP_ROOT.'/sample/distrotest')) { |
|
123
|
|
|
echo "<table cellpadding=\"2\" border=\"1\" CELLSPACING=\"0\""; |
|
124
|
|
|
echo "<tr>"; |
|
125
|
|
|
echo "<td>Distrotest sample</td>"; |
|
126
|
|
|
echo "<td>Distro Name</td>"; |
|
127
|
|
|
echo "<td>Distro Icon</td>"; |
|
128
|
|
|
echo "<td>Distro Name (no lsb_release)</td>"; |
|
129
|
|
|
echo "<td>Distro Icon (no lsb_release)</td>"; |
|
130
|
|
|
echo "<td>Distro Name (no lsb_release and no /etc/lsb-release)</td>"; |
|
131
|
|
|
echo "<td>Distro Icon (no lsb_release and no /etc/lsb-release)</td>"; |
|
132
|
|
|
echo "</tr>"; |
|
133
|
|
|
while (false !== ($entry = readdir($handle))) { |
|
134
|
|
|
if (($entry!=".")&&($entry!="..")) { |
|
135
|
|
|
if ($shandle = opendir(APP_ROOT."/sample/distrotest/$entry")) { |
|
136
|
|
|
while (false !== ($sentry = readdir($shandle))) { |
|
137
|
|
|
if (($sentry!=".")&&($sentry!="..")) { |
|
138
|
|
|
$log_file=APP_ROOT.'/sample/distrotest/'.$entry.'/'.$sentry; |
|
139
|
|
|
echo "<tr>"; |
|
140
|
|
|
echo "<td>".$entry.'/'.$sentry."</td>"; |
|
141
|
|
|
|
|
142
|
|
|
$lsb = true; |
|
143
|
|
|
$lsbfile = true; |
|
144
|
|
|
$sys=$system->getSys(); |
|
145
|
|
|
$distro=$sys->getDistribution(); |
|
146
|
|
|
$icon=$sys->getDistributionIcon(); |
|
147
|
|
|
if ($icon == '') $icon="unknown.png"; |
|
148
|
|
|
if ($icon != $entry.'.png') |
|
149
|
|
|
echo "<td style='color:red'>"; |
|
150
|
|
|
else |
|
151
|
|
|
echo "<td>"; |
|
152
|
|
|
echo $distro."</td>"; |
|
153
|
|
|
if ($icon != $entry.'.png') |
|
154
|
|
|
echo "<td style='color:red'>"; |
|
155
|
|
|
else |
|
156
|
|
|
echo "<td>"; |
|
157
|
|
|
echo "<img src=\"../gfx/images/".$icon."\" height=\"16\" width=\"16\">"; |
|
158
|
|
|
echo $icon."</td>"; |
|
159
|
|
|
$sys->setDistribution(""); |
|
160
|
|
|
$sys->setDistributionIcon(""); |
|
161
|
|
|
|
|
162
|
|
|
$lsb = false; |
|
163
|
|
|
$lsbfile = true; |
|
164
|
|
|
$sys=$system->getSys(); |
|
165
|
|
|
$distro=$sys->getDistribution(); |
|
166
|
|
|
$icon=$sys->getDistributionIcon(); |
|
167
|
|
|
if ($icon == '') $icon="unknown.png"; |
|
168
|
|
|
if ($icon != $entry.'.png') |
|
169
|
|
|
echo "<td style='color:red'>"; |
|
170
|
|
|
else |
|
171
|
|
|
echo "<td>"; |
|
172
|
|
|
echo $distro."</td>"; |
|
173
|
|
|
if ($icon != $entry.'.png') |
|
174
|
|
|
echo "<td style='color:red'>"; |
|
175
|
|
|
else |
|
176
|
|
|
echo "<td>"; |
|
177
|
|
|
echo "<img src=\"../gfx/images/".$icon."\" height=\"16\" width=\"16\">"; |
|
178
|
|
|
echo $icon."</td>"; |
|
179
|
|
|
$sys->setDistribution(""); |
|
180
|
|
|
$sys->setDistributionIcon(""); |
|
181
|
|
|
|
|
182
|
|
|
$lsb = false; |
|
183
|
|
|
$lsbfile = false; |
|
184
|
|
|
$sys=$system->getSys(); |
|
185
|
|
|
$distro=$sys->getDistribution(); |
|
186
|
|
|
$icon=$sys->getDistributionIcon(); |
|
187
|
|
|
if ($icon == '') $icon="unknown.png"; |
|
188
|
|
|
if ($icon != $entry.'.png') |
|
189
|
|
|
echo "<td style='color:red'>"; |
|
190
|
|
|
else |
|
191
|
|
|
echo "<td>"; |
|
192
|
|
|
echo $distro."</td>"; |
|
193
|
|
|
if ($icon != $entry.'.png') |
|
194
|
|
|
echo "<td style='color:red'>"; |
|
195
|
|
|
else |
|
196
|
|
|
echo "<td>"; |
|
197
|
|
|
echo "<img src=\"../gfx/images/".$icon."\" height=\"16\" width=\"16\">"; |
|
198
|
|
|
echo $icon."</td>"; |
|
199
|
|
|
$sys->setDistribution(""); |
|
200
|
|
|
$sys->setDistributionIcon(""); |
|
201
|
|
|
|
|
202
|
|
|
echo "</tr>"; |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
closedir($shandle); |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
echo "</table>"; |
|
210
|
|
|
closedir($handle); |
|
211
|
|
|
} |
|
212
|
|
|
echo "</body>"; |
|
213
|
|
|
|
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.