Subversion Repositories ALCASAR

Rev

Rev 3037 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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