2775 |
rexy |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* XML Generator class
|
|
|
4 |
*
|
|
|
5 |
* PHP version 5
|
|
|
6 |
*
|
|
|
7 |
* @category PHP
|
|
|
8 |
* @package PSI_XML
|
|
|
9 |
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
|
|
|
10 |
* @copyright 2009 phpSysInfo
|
|
|
11 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
|
|
12 |
* @version SVN: $Id: class.WebpageXML.inc.php 661 2012-08-27 11:26:39Z namiltd $
|
|
|
13 |
* @link http://phpsysinfo.sourceforge.net
|
|
|
14 |
*/
|
|
|
15 |
/**
|
|
|
16 |
* class for xml output
|
|
|
17 |
*
|
|
|
18 |
* @category PHP
|
|
|
19 |
* @package PSI_XML
|
|
|
20 |
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
|
|
|
21 |
* @copyright 2009 phpSysInfo
|
|
|
22 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
|
|
23 |
* @version Release: 3.0
|
|
|
24 |
* @link http://phpsysinfo.sourceforge.net
|
|
|
25 |
*/
|
|
|
26 |
class WebpageXML extends Output implements PSI_Interface_Output
|
|
|
27 |
{
|
|
|
28 |
/**
|
|
|
29 |
* xml object that holds the generated xml
|
|
|
30 |
*
|
|
|
31 |
* @var XML
|
|
|
32 |
*/
|
|
|
33 |
private $_xml;
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* complete xml
|
|
|
37 |
*
|
|
|
38 |
* @var boolean
|
|
|
39 |
*/
|
|
|
40 |
private $_completeXML = false;
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* name of the plugin
|
|
|
44 |
*
|
|
|
45 |
* @var string
|
|
|
46 |
*/
|
|
|
47 |
private $_pluginName = null;
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* name of the block
|
|
|
51 |
*
|
|
|
52 |
* @var string
|
|
|
53 |
*/
|
|
|
54 |
private $_blockName = null;
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* generate the output
|
|
|
58 |
*
|
|
|
59 |
* @return void
|
|
|
60 |
*/
|
|
|
61 |
private function _prepare()
|
|
|
62 |
{
|
|
|
63 |
if ($this->_pluginName === null) {
|
3100 |
rexy |
64 |
if ((PSI_OS == 'Linux') && defined('PSI_SSH_HOSTNAME') && defined('PSI_SSH_USER') && defined('PSI_SSH_PASSWORD')) {
|
|
|
65 |
$fgthost = preg_split("/:/", PSI_SSH_HOSTNAME, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
66 |
define('PSI_EMU_HOSTNAME', trim($fgthost[0]));
|
|
|
67 |
if (isset($fgthost[1]) && (trim($fgthost[1] !== ''))) {
|
|
|
68 |
define('PSI_EMU_PORT', trim($fgthost[1]));
|
|
|
69 |
} else {
|
|
|
70 |
define('PSI_EMU_PORT', 22);
|
|
|
71 |
}
|
|
|
72 |
define('PSI_EMU_USER', PSI_SSH_USER);
|
|
|
73 |
define('PSI_EMU_PASSWORD', PSI_SSH_PASSWORD);
|
|
|
74 |
if (defined('PSI_SSH_ADD_PATHS')) {
|
|
|
75 |
define('PSI_EMU_ADD_PATHS', PSI_SSH_ADD_PATHS);
|
|
|
76 |
}
|
|
|
77 |
if (defined('PSI_SSH_ADD_OPTIONS')) {
|
|
|
78 |
define('PSI_EMU_ADD_OPTIONS', PSI_SSH_ADD_OPTIONS);
|
|
|
79 |
}
|
|
|
80 |
if (!file_exists(PSI_APP_ROOT.'/includes/os/class.Linux.inc.php')) {
|
|
|
81 |
$this->error->addError("file_exists(class.Linux.inc.php)", "Linux is not currently supported");
|
|
|
82 |
}
|
|
|
83 |
} elseif (((PSI_OS == 'WINNT') || (PSI_OS == 'Linux')) && defined('PSI_WMI_HOSTNAME')) {
|
2976 |
rexy |
84 |
define('PSI_EMU_HOSTNAME', PSI_WMI_HOSTNAME);
|
|
|
85 |
if (defined('PSI_WMI_USER') && defined('PSI_WMI_PASSWORD')) {
|
|
|
86 |
define('PSI_EMU_USER', PSI_WMI_USER);
|
|
|
87 |
define('PSI_EMU_PASSWORD', PSI_WMI_PASSWORD);
|
|
|
88 |
} else {
|
|
|
89 |
define('PSI_EMU_USER', null);
|
|
|
90 |
define('PSI_EMU_PASSWORD', null);
|
|
|
91 |
}
|
|
|
92 |
if (!file_exists(PSI_APP_ROOT.'/includes/os/class.WINNT.inc.php')) {
|
|
|
93 |
$this->error->addError("file_exists(class.WINNT.inc.php)", "WINNT is not currently supported");
|
|
|
94 |
}
|
|
|
95 |
} else {
|
|
|
96 |
// Figure out which OS we are running on, and detect support
|
|
|
97 |
if (!file_exists(PSI_APP_ROOT.'/includes/os/class.'.PSI_OS.'.inc.php')) {
|
|
|
98 |
$this->error->addError("file_exists(class.".PSI_OS.".inc.php)", PSI_OS." is not currently supported");
|
|
|
99 |
}
|
2775 |
rexy |
100 |
}
|
|
|
101 |
|
|
|
102 |
if (!defined('PSI_MBINFO') && (!$this->_blockName || in_array($this->_blockName, array('voltage','current','temperature','fans','power','other')))) {
|
|
|
103 |
// check if there is a valid sensor configuration in phpsysinfo.ini
|
|
|
104 |
$foundsp = array();
|
|
|
105 |
if (defined('PSI_SENSOR_PROGRAM') && is_string(PSI_SENSOR_PROGRAM)) {
|
|
|
106 |
if (preg_match(ARRAY_EXP, PSI_SENSOR_PROGRAM)) {
|
|
|
107 |
$sensorprograms = eval(strtolower(PSI_SENSOR_PROGRAM));
|
|
|
108 |
} else {
|
|
|
109 |
$sensorprograms = array(strtolower(PSI_SENSOR_PROGRAM));
|
|
|
110 |
}
|
|
|
111 |
foreach ($sensorprograms as $sensorprogram) {
|
|
|
112 |
if (!file_exists(PSI_APP_ROOT.'/includes/mb/class.'.$sensorprogram.'.inc.php')) {
|
|
|
113 |
$this->error->addError("file_exists(class.".htmlspecialchars($sensorprogram).".inc.php)", "specified sensor program is not supported");
|
|
|
114 |
} else {
|
|
|
115 |
$foundsp[] = $sensorprogram;
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* motherboard information
|
|
|
122 |
*
|
|
|
123 |
* @var string serialized array
|
|
|
124 |
*/
|
|
|
125 |
define('PSI_MBINFO', serialize($foundsp));
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
if (!defined('PSI_UPSINFO') && (!$this->_blockName || ($this->_blockName==='ups'))) {
|
|
|
129 |
// check if there is a valid ups configuration in phpsysinfo.ini
|
|
|
130 |
$foundup = array();
|
|
|
131 |
if (defined('PSI_UPS_PROGRAM') && is_string(PSI_UPS_PROGRAM)) {
|
|
|
132 |
if (preg_match(ARRAY_EXP, PSI_UPS_PROGRAM)) {
|
|
|
133 |
$upsprograms = eval(strtolower(PSI_UPS_PROGRAM));
|
|
|
134 |
} else {
|
|
|
135 |
$upsprograms = array(strtolower(PSI_UPS_PROGRAM));
|
|
|
136 |
}
|
|
|
137 |
foreach ($upsprograms as $upsprogram) {
|
|
|
138 |
if (!file_exists(PSI_APP_ROOT.'/includes/ups/class.'.$upsprogram.'.inc.php')) {
|
|
|
139 |
$this->error->addError("file_exists(class.".htmlspecialchars($upsprogram).".inc.php)", "specified UPS program is not supported");
|
|
|
140 |
} else {
|
|
|
141 |
$foundup[] = $upsprogram;
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
/**
|
|
|
146 |
* ups information
|
|
|
147 |
*
|
|
|
148 |
* @var string serialized array
|
|
|
149 |
*/
|
|
|
150 |
define('PSI_UPSINFO', serialize($foundup));
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
// if there are errors stop executing the script until they are fixed
|
|
|
154 |
if ($this->error->errorsExist()) {
|
|
|
155 |
$this->error->errorsAsXML();
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
// Create the XML
|
|
|
159 |
$this->_xml = new XML($this->_completeXML, '', $this->_blockName);
|
|
|
160 |
} else {
|
2976 |
rexy |
161 |
if ((PSI_OS == 'WINNT') || (PSI_OS == 'Linux')) {
|
|
|
162 |
$plugname = strtoupper(trim($this->_pluginName));
|
3100 |
rexy |
163 |
if ((PSI_OS == 'Linux') && defined('PSI_PLUGIN_'.$plugname.'_SSH_HOSTNAME') && defined('PSI_PLUGIN_'.$plugname.'_SSH_USER') && defined('PSI_PLUGIN_'.$plugname.'_SSH_PASSWORD')) {
|
|
|
164 |
$fgthost = preg_split("/:/", constant('PSI_PLUGIN_'.$plugname.'_SSH_HOSTNAME'), -1, PREG_SPLIT_NO_EMPTY);
|
|
|
165 |
define('PSI_EMU_HOSTNAME', trim($fgthost[0]));
|
|
|
166 |
if (isset($fgthost[1]) && (trim($fgthost[1] !== ''))) {
|
|
|
167 |
define('PSI_EMU_PORT', trim($fgthost[1]));
|
|
|
168 |
} else {
|
|
|
169 |
define('PSI_EMU_PORT', 22);
|
|
|
170 |
}
|
|
|
171 |
define('PSI_EMU_USER', constant('PSI_PLUGIN_'.$plugname.'_SSH_USER'));
|
|
|
172 |
define('PSI_EMU_PASSWORD', constant('PSI_PLUGIN_'.$plugname.'_SSH_PASSWORD'));
|
|
|
173 |
if (defined('PSI_PLUGIN_'.$plugname.'_SSH_ADD_PATHS')) {
|
|
|
174 |
define('PSI_EMU_ADD_PATHS', constant('PSI_PLUGIN_'.$plugname.'_SSH_ADD_PATHS'));
|
|
|
175 |
}
|
|
|
176 |
if (defined('PSI_PLUGIN_'.$plugname.'_SSH_ADD_OPTIONS')) {
|
|
|
177 |
define('PSI_EMU_ADD_OPTIONS', constant('PSI_PLUGIN_'.$plugname.'_SSH_ADD_OPTIONS'));
|
|
|
178 |
}
|
|
|
179 |
} elseif (defined('PSI_PLUGIN_'.$plugname.'_WMI_HOSTNAME')) {
|
2976 |
rexy |
180 |
define('PSI_EMU_HOSTNAME', constant('PSI_PLUGIN_'.$plugname.'_WMI_HOSTNAME'));
|
|
|
181 |
if (defined('PSI_PLUGIN_'.$plugname.'_WMI_USER') && defined('PSI_PLUGIN_'.$plugname.'_WMI_PASSWORD')) {
|
|
|
182 |
define('PSI_EMU_USER', constant('PSI_PLUGIN_'.$plugname.'_WMI_USER'));
|
|
|
183 |
define('PSI_EMU_PASSWORD', constant('PSI_PLUGIN_'.$plugname.'_WMI_PASSWORD'));
|
|
|
184 |
} else {
|
|
|
185 |
define('PSI_EMU_USER', null);
|
|
|
186 |
define('PSI_EMU_PASSWORD', null);
|
|
|
187 |
}
|
3100 |
rexy |
188 |
} elseif ((PSI_OS == 'Linux') && defined('PSI_SSH_HOSTNAME') && defined('PSI_SSH_USER') && defined('PSI_SSH_PASSWORD')) {
|
|
|
189 |
$fgthost = preg_split("/:/", PSI_SSH_HOSTNAME, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
190 |
define('PSI_EMU_HOSTNAME', trim($fgthost[0]));
|
|
|
191 |
if (isset($fgthost[1]) && (trim($fgthost[1] !== ''))) {
|
|
|
192 |
define('PSI_EMU_PORT', trim($fgthost[1]));
|
|
|
193 |
} else {
|
|
|
194 |
define('PSI_EMU_PORT', 22);
|
|
|
195 |
}
|
|
|
196 |
define('PSI_EMU_USER', PSI_SSH_USER);
|
|
|
197 |
define('PSI_EMU_PASSWORD', PSI_SSH_PASSWORD);
|
|
|
198 |
if (defined('PSI_SSH_ADD_PATHS')) {
|
|
|
199 |
define('PSI_EMU_ADD_PATHS', PSI_SSH_ADD_PATHS);
|
|
|
200 |
}
|
|
|
201 |
if (defined('PSI_SSH_ADD_OPTIONS')) {
|
|
|
202 |
define('PSI_EMU_ADD_OPTIONS', PSI_SSH_ADD_OPTIONS);
|
|
|
203 |
}
|
2976 |
rexy |
204 |
} elseif (defined('PSI_WMI_HOSTNAME')) {
|
|
|
205 |
define('PSI_EMU_HOSTNAME', PSI_WMI_HOSTNAME);
|
|
|
206 |
if (defined('PSI_WMI_USER') && defined('PSI_WMI_PASSWORD')) {
|
|
|
207 |
define('PSI_EMU_USER', PSI_WMI_USER);
|
|
|
208 |
define('PSI_EMU_PASSWORD', PSI_WMI_PASSWORD);
|
|
|
209 |
} else {
|
|
|
210 |
define('PSI_EMU_USER', null);
|
|
|
211 |
define('PSI_EMU_PASSWORD', null);
|
|
|
212 |
}
|
|
|
213 |
}
|
|
|
214 |
}
|
|
|
215 |
|
2775 |
rexy |
216 |
// Create the XML
|
|
|
217 |
$this->_xml = new XML(false, $this->_pluginName);
|
|
|
218 |
}
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
/**
|
|
|
222 |
* render the output
|
|
|
223 |
*
|
|
|
224 |
* @return void
|
|
|
225 |
*/
|
|
|
226 |
public function run()
|
|
|
227 |
{
|
3037 |
rexy |
228 |
header('Cache-Control: no-cache, must-revalidate');
|
|
|
229 |
header('Content-Type: text/xml');
|
2775 |
rexy |
230 |
$xml = $this->_xml->getXml();
|
|
|
231 |
echo $xml->asXML();
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
/**
|
|
|
235 |
* get XML as pure string
|
|
|
236 |
*
|
|
|
237 |
* @return string
|
|
|
238 |
*/
|
|
|
239 |
public function getXMLString()
|
|
|
240 |
{
|
|
|
241 |
$xml = $this->_xml->getXml();
|
|
|
242 |
|
|
|
243 |
return $xml->asXML();
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
/**
|
|
|
247 |
* get json string
|
|
|
248 |
*
|
|
|
249 |
* @return string
|
|
|
250 |
*/
|
|
|
251 |
public function getJsonString()
|
|
|
252 |
{
|
|
|
253 |
if (defined('PSI_JSON_ISSUE') && (PSI_JSON_ISSUE)) {
|
|
|
254 |
return json_encode(simplexml_load_string(str_replace(">", ">\n", $this->getXMLString()))); // solving json_encode issue
|
|
|
255 |
} else {
|
|
|
256 |
return json_encode(simplexml_load_string($this->getXMLString()));
|
|
|
257 |
}
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
/**
|
|
|
261 |
* get array
|
|
|
262 |
*
|
|
|
263 |
* @return array
|
|
|
264 |
*/
|
|
|
265 |
public function getArray()
|
|
|
266 |
{
|
|
|
267 |
return json_decode($this->getJsonString());
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
/**
|
|
|
271 |
* set parameters for the XML generation process
|
|
|
272 |
*
|
|
|
273 |
* @param string $plugin name of the plugin, block or 'complete' for all plugins
|
|
|
274 |
*
|
|
|
275 |
* @return void
|
|
|
276 |
*/
|
|
|
277 |
public function __construct($plugin = "")
|
|
|
278 |
{
|
|
|
279 |
parent::__construct();
|
|
|
280 |
|
|
|
281 |
if (is_string($plugin) && ($plugin !== "")) {
|
3037 |
rexy |
282 |
if (preg_match('/[^A-Za-z]/', $plugin)) {
|
|
|
283 |
$this->_blockName = ' '; // mask wrong plugin name
|
|
|
284 |
} elseif (($plugin = strtolower($plugin)) === "complete") {
|
2775 |
rexy |
285 |
$this->_completeXML = true;
|
3037 |
rexy |
286 |
} elseif (in_array($plugin, array('vitals','hardware','memory','filesystem','network','voltage','current','temperature','fans','power','other','ups'))) {
|
|
|
287 |
$this->_blockName = $plugin;
|
|
|
288 |
} elseif (in_array($plugin, CommonFunctions::getPlugins())) {
|
|
|
289 |
$this->_pluginName = $plugin;
|
2775 |
rexy |
290 |
} else {
|
3037 |
rexy |
291 |
$this->_blockName = ' '; // disable all blocks
|
2775 |
rexy |
292 |
}
|
|
|
293 |
}
|
|
|
294 |
$this->_prepare();
|
|
|
295 |
}
|
|
|
296 |
}
|