Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

class.WebpageXML.inc.php 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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
  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
  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. * only plugin xml
  36. *
  37. * @var boolean
  38. */
  39. private $_pluginRequest = false;
  40. /**
  41. * complete xml
  42. *
  43. * @var boolean
  44. */
  45. private $_completeXML = false;
  46. /**
  47. * name of the plugin
  48. *
  49. * @var string
  50. */
  51. private $_pluginName = null;
  52. /**
  53. * generate the output
  54. *
  55. * @return void
  56. */
  57. private function _prepare()
  58. {
  59. if (!$this->_pluginRequest) {
  60. // Figure out which OS we are running on, and detect support
  61. if (!file_exists(APP_ROOT.'/includes/os/class.'.PSI_OS.'.inc.php')) {
  62. $this->error->addError("file_exists(class.".PSI_OS.".inc.php)", PSI_OS." is not currently supported");
  63. }
  64. // check if there is a valid sensor configuration in config.php
  65. $foundsp = array();
  66. if ( defined('PSI_SENSOR_PROGRAM') && is_string(PSI_SENSOR_PROGRAM) ) {
  67. if (preg_match(ARRAY_EXP, PSI_SENSOR_PROGRAM)) {
  68. $sensorprograms = eval(strtolower(PSI_SENSOR_PROGRAM));
  69. } else {
  70. $sensorprograms = array(strtolower(PSI_SENSOR_PROGRAM));
  71. }
  72. foreach ($sensorprograms as $sensorprogram) {
  73. if (!file_exists(APP_ROOT.'/includes/mb/class.'.$sensorprogram.'.inc.php')) {
  74. $this->error->addError("file_exists(class.".htmlspecialchars($sensorprogram).".inc.php)", "specified sensor program is not supported");
  75. } else {
  76. $foundsp[] = $sensorprogram;
  77. }
  78. }
  79. }
  80. /**
  81. * motherboard information
  82. *
  83. * @var serialized array
  84. */
  85. define('PSI_MBINFO', serialize($foundsp));
  86. // check if there is a valid hddtemp configuration in config.php
  87. $found = false;
  88. if (PSI_HDD_TEMP !== false) {
  89. $found = true;
  90. }
  91. /**
  92. * hddtemp information available or not
  93. *
  94. * @var boolean
  95. */
  96. define('PSI_HDDTEMP', $found);
  97. // check if there is a valid ups configuration in config.php
  98. $foundup = array();
  99. if ( defined('PSI_UPS_PROGRAM') && is_string(PSI_UPS_PROGRAM) ) {
  100. if (preg_match(ARRAY_EXP, PSI_UPS_PROGRAM)) {
  101. $upsprograms = eval(strtolower(PSI_UPS_PROGRAM));
  102. } else {
  103. $upsprograms = array(strtolower(PSI_UPS_PROGRAM));
  104. }
  105. foreach ($upsprograms as $upsprogram) {
  106. if (!file_exists(APP_ROOT.'/includes/ups/class.'.$upsprogram.'.inc.php')) {
  107. $this->error->addError("file_exists(class.".htmlspecialchars($upsprogram).".inc.php)", "specified UPS program is not supported");
  108. } else {
  109. $foundup[] = $upsprogram;
  110. }
  111. }
  112. }
  113. /**
  114. * ups information
  115. *
  116. * @var serialized array
  117. */
  118. define('PSI_UPSINFO', serialize($foundup));
  119. // if there are errors stop executing the script until they are fixed
  120. if ($this->error->errorsExist()) {
  121. $this->error->errorsAsXML();
  122. }
  123. }
  124. // Create the XML
  125. if ($this->_pluginRequest) {
  126. $this->_xml = new XML(false, $this->_pluginName);
  127. } else {
  128. $this->_xml = new XML($this->_completeXML);
  129. }
  130. }
  131. /**
  132. * render the output
  133. *
  134. * @return void
  135. */
  136. public function run()
  137. {
  138. header("Cache-Control: no-cache, must-revalidate\n");
  139. header("Content-Type: text/xml\n\n");
  140. $xml = $this->_xml->getXml();
  141. echo $xml->asXML();
  142. }
  143. /**
  144. * get XML as pure string
  145. *
  146. * @return string
  147. */
  148. public function getXMLString()
  149. {
  150. $xml = $this->_xml->getXml();
  151. return $xml->asXML();
  152. }
  153. /**
  154. * set parameters for the XML generation process
  155. *
  156. * @param boolean $completeXML switch for complete xml with all plugins
  157. * @param string $plugin name of the plugin
  158. *
  159. * @return void
  160. */
  161. public function __construct($completeXML, $plugin = null)
  162. {
  163. parent::__construct();
  164. if ($completeXML) {
  165. $this->_completeXML = true;
  166. }
  167. if ($plugin) {
  168. if (in_array(strtolower($plugin), CommonFunctions::getPlugins())) {
  169. $this->_pluginName = $plugin;
  170. $this->_pluginRequest = true;
  171. }
  172. }
  173. $this->_prepare();
  174. }
  175. }