Subversion Repositories ALCASAR

Rev

Rev 2775 | Rev 3037 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2775 Rev 2976
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 == 'WINNT') || (PSI_OS == 'Linux')) && defined('PSI_WMI_HOSTNAME')) {
-
 
65
                define('PSI_EMU_HOSTNAME', PSI_WMI_HOSTNAME);
-
 
66
                if (defined('PSI_WMI_USER') && defined('PSI_WMI_PASSWORD')) {
-
 
67
                    define('PSI_EMU_USER', PSI_WMI_USER);
-
 
68
                    define('PSI_EMU_PASSWORD', PSI_WMI_PASSWORD);
-
 
69
                } else {
-
 
70
                    define('PSI_EMU_USER', null);
-
 
71
                    define('PSI_EMU_PASSWORD', null);
-
 
72
                }
-
 
73
                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");
-
 
75
                }
-
 
76
            } else {
64
            // Figure out which OS we are running on, and detect support
77
                // Figure out which OS we are running on, and detect support
65
            if (!file_exists(PSI_APP_ROOT.'/includes/os/class.'.PSI_OS.'.inc.php')) {
78
                if (!file_exists(PSI_APP_ROOT.'/includes/os/class.'.PSI_OS.'.inc.php')) {
66
                $this->error->addError("file_exists(class.".PSI_OS.".inc.php)", PSI_OS." is not currently supported");
79
                    $this->error->addError("file_exists(class.".PSI_OS.".inc.php)", PSI_OS." is not currently supported");
-
 
80
                }
67
            }
81
            }
68
 
82
 
69
            if (!defined('PSI_MBINFO') && (!$this->_blockName || in_array($this->_blockName, array('voltage','current','temperature','fans','power','other')))) {
83
            if (!defined('PSI_MBINFO') && (!$this->_blockName || in_array($this->_blockName, array('voltage','current','temperature','fans','power','other')))) {
70
                // check if there is a valid sensor configuration in phpsysinfo.ini
84
                // check if there is a valid sensor configuration in phpsysinfo.ini
71
                $foundsp = array();
85
                $foundsp = array();
72
                if (defined('PSI_SENSOR_PROGRAM') && is_string(PSI_SENSOR_PROGRAM)) {
86
                if (defined('PSI_SENSOR_PROGRAM') && is_string(PSI_SENSOR_PROGRAM)) {
73
                    if (preg_match(ARRAY_EXP, PSI_SENSOR_PROGRAM)) {
87
                    if (preg_match(ARRAY_EXP, PSI_SENSOR_PROGRAM)) {
74
                        $sensorprograms = eval(strtolower(PSI_SENSOR_PROGRAM));
88
                        $sensorprograms = eval(strtolower(PSI_SENSOR_PROGRAM));
75
                    } else {
89
                    } else {
76
                        $sensorprograms = array(strtolower(PSI_SENSOR_PROGRAM));
90
                        $sensorprograms = array(strtolower(PSI_SENSOR_PROGRAM));
77
                    }
91
                    }
78
                    foreach ($sensorprograms as $sensorprogram) {
92
                    foreach ($sensorprograms as $sensorprogram) {
79
                        if (!file_exists(PSI_APP_ROOT.'/includes/mb/class.'.$sensorprogram.'.inc.php')) {
93
                        if (!file_exists(PSI_APP_ROOT.'/includes/mb/class.'.$sensorprogram.'.inc.php')) {
80
                            $this->error->addError("file_exists(class.".htmlspecialchars($sensorprogram).".inc.php)", "specified sensor program is not supported");
94
                            $this->error->addError("file_exists(class.".htmlspecialchars($sensorprogram).".inc.php)", "specified sensor program is not supported");
81
                        } else {
95
                        } else {
82
                            $foundsp[] = $sensorprogram;
96
                            $foundsp[] = $sensorprogram;
83
                        }
97
                        }
84
                    }
98
                    }
85
                }
99
                }
86
 
100
 
87
                /**
101
                /**
88
                 * motherboard information
102
                 * motherboard information
89
                 *
103
                 *
90
                 * @var string serialized array
104
                 * @var string serialized array
91
                 */
105
                 */
92
                define('PSI_MBINFO', serialize($foundsp));
106
                define('PSI_MBINFO', serialize($foundsp));
93
            }
107
            }
94
 
108
 
95
            if (!defined('PSI_UPSINFO') && (!$this->_blockName || ($this->_blockName==='ups'))) {
109
            if (!defined('PSI_UPSINFO') && (!$this->_blockName || ($this->_blockName==='ups'))) {
96
                // check if there is a valid ups configuration in phpsysinfo.ini
110
                // check if there is a valid ups configuration in phpsysinfo.ini
97
                $foundup = array();
111
                $foundup = array();
98
                if (defined('PSI_UPS_PROGRAM') && is_string(PSI_UPS_PROGRAM)) {
112
                if (defined('PSI_UPS_PROGRAM') && is_string(PSI_UPS_PROGRAM)) {
99
                    if (preg_match(ARRAY_EXP, PSI_UPS_PROGRAM)) {
113
                    if (preg_match(ARRAY_EXP, PSI_UPS_PROGRAM)) {
100
                        $upsprograms = eval(strtolower(PSI_UPS_PROGRAM));
114
                        $upsprograms = eval(strtolower(PSI_UPS_PROGRAM));
101
                    } else {
115
                    } else {
102
                        $upsprograms = array(strtolower(PSI_UPS_PROGRAM));
116
                        $upsprograms = array(strtolower(PSI_UPS_PROGRAM));
103
                    }
117
                    }
104
                    foreach ($upsprograms as $upsprogram) {
118
                    foreach ($upsprograms as $upsprogram) {
105
                        if (!file_exists(PSI_APP_ROOT.'/includes/ups/class.'.$upsprogram.'.inc.php')) {
119
                        if (!file_exists(PSI_APP_ROOT.'/includes/ups/class.'.$upsprogram.'.inc.php')) {
106
                            $this->error->addError("file_exists(class.".htmlspecialchars($upsprogram).".inc.php)", "specified UPS program is not supported");
120
                            $this->error->addError("file_exists(class.".htmlspecialchars($upsprogram).".inc.php)", "specified UPS program is not supported");
107
                        } else {
121
                        } else {
108
                            $foundup[] = $upsprogram;
122
                            $foundup[] = $upsprogram;
109
                        }
123
                        }
110
                    }
124
                    }
111
                }
125
                }
112
                /**
126
                /**
113
                 * ups information
127
                 * ups information
114
                 *
128
                 *
115
                 * @var string serialized array
129
                 * @var string serialized array
116
                 */
130
                 */
117
                define('PSI_UPSINFO', serialize($foundup));
131
                define('PSI_UPSINFO', serialize($foundup));
118
            }
132
            }
119
 
133
 
120
            // if there are errors stop executing the script until they are fixed
134
            // if there are errors stop executing the script until they are fixed
121
            if ($this->error->errorsExist()) {
135
            if ($this->error->errorsExist()) {
122
                $this->error->errorsAsXML();
136
                $this->error->errorsAsXML();
123
            }
137
            }
124
 
138
 
125
            // Create the XML
139
            // Create the XML
126
            $this->_xml = new XML($this->_completeXML, '', $this->_blockName);
140
            $this->_xml = new XML($this->_completeXML, '', $this->_blockName);
127
        } else {
141
        } else {
-
 
142
            if ((PSI_OS == 'WINNT') || (PSI_OS == 'Linux')) {
-
 
143
                $plugname = strtoupper(trim($this->_pluginName));
-
 
144
                if (defined('PSI_PLUGIN_'.$plugname.'_WMI_HOSTNAME')) {
-
 
145
                    define('PSI_EMU_HOSTNAME', constant('PSI_PLUGIN_'.$plugname.'_WMI_HOSTNAME'));
-
 
146
                    if (defined('PSI_PLUGIN_'.$plugname.'_WMI_USER') && defined('PSI_PLUGIN_'.$plugname.'_WMI_PASSWORD')) {
-
 
147
                        define('PSI_EMU_USER', constant('PSI_PLUGIN_'.$plugname.'_WMI_USER'));
-
 
148
                        define('PSI_EMU_PASSWORD', constant('PSI_PLUGIN_'.$plugname.'_WMI_PASSWORD'));
-
 
149
                    } else {
-
 
150
                        define('PSI_EMU_USER', null);
-
 
151
                        define('PSI_EMU_PASSWORD', null);
-
 
152
                    }
-
 
153
                } elseif (defined('PSI_WMI_HOSTNAME')) {
-
 
154
                    define('PSI_EMU_HOSTNAME', PSI_WMI_HOSTNAME);
-
 
155
                    if (defined('PSI_WMI_USER') && defined('PSI_WMI_PASSWORD')) {
-
 
156
                        define('PSI_EMU_USER', PSI_WMI_USER);
-
 
157
                        define('PSI_EMU_PASSWORD', PSI_WMI_PASSWORD);
-
 
158
                    } else {
-
 
159
                        define('PSI_EMU_USER', null);
-
 
160
                        define('PSI_EMU_PASSWORD', null);
-
 
161
                    }
-
 
162
                }
-
 
163
            }
-
 
164
 
128
            // Create the XML
165
            // Create the XML
129
            $this->_xml = new XML(false, $this->_pluginName);
166
            $this->_xml = new XML(false, $this->_pluginName);
130
        }
167
        }
131
    }
168
    }
132
 
169
 
133
    /**
170
    /**
134
     * render the output
171
     * render the output
135
     *
172
     *
136
     * @return void
173
     * @return void
137
     */
174
     */
138
    public function run()
175
    public function run()
139
    {
176
    {
140
        header("Cache-Control: no-cache, must-revalidate\n");
177
        header("Cache-Control: no-cache, must-revalidate\n");
141
        header("Content-Type: text/xml\n\n");
178
        header("Content-Type: text/xml\n\n");
142
        $xml = $this->_xml->getXml();
179
        $xml = $this->_xml->getXml();
143
        echo $xml->asXML();
180
        echo $xml->asXML();
144
    }
181
    }
145
 
182
 
146
    /**
183
    /**
147
     * get XML as pure string
184
     * get XML as pure string
148
     *
185
     *
149
     * @return string
186
     * @return string
150
     */
187
     */
151
    public function getXMLString()
188
    public function getXMLString()
152
    {
189
    {
153
        $xml = $this->_xml->getXml();
190
        $xml = $this->_xml->getXml();
154
 
191
 
155
        return $xml->asXML();
192
        return $xml->asXML();
156
    }
193
    }
157
 
194
 
158
    /**
195
    /**
159
     * get json string
196
     * get json string
160
     *
197
     *
161
     * @return string
198
     * @return string
162
     */
199
     */
163
    public function getJsonString()
200
    public function getJsonString()
164
    {
201
    {
165
        if (defined('PSI_JSON_ISSUE') && (PSI_JSON_ISSUE)) {
202
        if (defined('PSI_JSON_ISSUE') && (PSI_JSON_ISSUE)) {
166
            return json_encode(simplexml_load_string(str_replace(">", ">\n", $this->getXMLString()))); // solving json_encode issue
203
            return json_encode(simplexml_load_string(str_replace(">", ">\n", $this->getXMLString()))); // solving json_encode issue
167
        } else {
204
        } else {
168
            return json_encode(simplexml_load_string($this->getXMLString()));
205
            return json_encode(simplexml_load_string($this->getXMLString()));
169
        }
206
        }
170
    }
207
    }
171
 
208
 
172
    /**
209
    /**
173
     * get array
210
     * get array
174
     *
211
     *
175
     * @return array
212
     * @return array
176
     */
213
     */
177
    public function getArray()
214
    public function getArray()
178
    {
215
    {
179
        return json_decode($this->getJsonString());
216
        return json_decode($this->getJsonString());
180
    }
217
    }
181
 
218
 
182
    /**
219
    /**
183
     * set parameters for the XML generation process
220
     * set parameters for the XML generation process
184
     *
221
     *
185
     * @param string $plugin name of the plugin, block or 'complete' for all plugins
222
     * @param string $plugin name of the plugin, block or 'complete' for all plugins
186
     *
223
     *
187
     * @return void
224
     * @return void
188
     */
225
     */
189
    public function __construct($plugin = "")
226
    public function __construct($plugin = "")
190
    {
227
    {
191
        parent::__construct();
228
        parent::__construct();
192
 
229
 
193
        if (is_string($plugin) && ($plugin !== "")) {
230
        if (is_string($plugin) && ($plugin !== "")) {
194
            $plugin = strtolower($plugin);
231
            $plugin = strtolower($plugin);
195
            if ($plugin === "complete") {
232
            if ($plugin === "complete") {
196
                $this->_completeXML = true;
233
                $this->_completeXML = true;
197
            } else {
234
            } else {
198
                $validblocks = array('vitals','hardware','memory','filesystem','network','voltage','current','temperature','fans','power','other','ups');
235
                $validblocks = array('vitals','hardware','memory','filesystem','network','voltage','current','temperature','fans','power','other','ups');
199
                if (in_array($plugin, $validblocks)) {
236
                if (in_array($plugin, $validblocks)) {
200
                    $this->_blockName = $plugin;
237
                    $this->_blockName = $plugin;
201
                } elseif (in_array($plugin, CommonFunctions::getPlugins())) {
238
                } elseif (in_array($plugin, CommonFunctions::getPlugins())) {
202
                    $this->_pluginName = $plugin;
239
                    $this->_pluginName = $plugin;
203
                } else {
240
                } else {
204
                    $this->_blockName = ' '; //disable all blocks
241
                    $this->_blockName = ' '; //disable all blocks
205
                }
242
                }
206
            }
243
            }
207
        }
244
        }
208
        $this->_prepare();
245
        $this->_prepare();
209
    }
246
    }
210
}
247
}
211
 
248