PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/System/systemconfig.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 324 lines | 240 code | 31 blank | 53 comment | 66 complexity | 816777483982336a4ede7ddb35789a6a MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. // phpSysInfo - A PHP System Information Script
  3. // http://phpsysinfo.sourceforge.net/
  4. // This program is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU General Public License
  6. // as published by the Free Software Foundation; either version 2
  7. // of the License, or (at your option) any later version.
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // You should have received a copy of the GNU General Public License
  13. // along with this program; if not, write to the Free Software
  14. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. // $Id: index.php,v 1.113 2006/04/17 15:24:46 bigmichi1 Exp $
  16. // phpsysinfo release version number
  17. $VERSION = "2.5.2_rc2";
  18. $startTime = array_sum( explode( " ", microtime() ) );
  19. global $app_strings;
  20. define('IN_PHPSYSINFO', true);
  21. ini_set('magic_quotes_runtime', 'off');
  22. ini_set('register_globals', 'off');
  23. // ini_set('display_errors','on');
  24. define('APP_ROOT', getcwd().'/modules/System');
  25. require_once(APP_ROOT . '/includes/class.error.inc.php');
  26. $error = new Error;
  27. // Figure out which OS where running on, and detect support
  28. if ( file_exists( APP_ROOT . '/includes/os/class.' . PHP_OS . '.inc.php' ) ) {
  29. } else {
  30. $error->addError('include(class.' . PHP_OS . '.php.inc)' , PHP_OS . ' is not currently supported', __LINE__, __FILE__ );
  31. }
  32. if (!extension_loaded('xml')) {
  33. $error->addError('extension_loaded(xml)', 'phpsysinfo requires the xml module for php to work', __LINE__, __FILE__);
  34. }
  35. if (!extension_loaded('pcre')) {
  36. $error->addError('extension_loaded(pcre)', 'phpsysinfo requires the pcre module for php to work', __LINE__, __FILE__);
  37. }
  38. if (!file_exists(APP_ROOT . '/config.php')) {
  39. $error->addError('file_exists(config.php)', 'config.php does not exist in the phpsysinfo directory.', __LINE__, __FILE__);
  40. } else {
  41. require_once(APP_ROOT . '/config.php'); // get the config file
  42. }
  43. if ( !empty( $sensor_program ) ) {
  44. $sensor_program = basename( $sensor_program );
  45. if( !file_exists( APP_ROOT . '/includes/mb/class.' . $sensor_program . '.inc.php' ) ) {
  46. $error->addError('include(class.' . htmlspecialchars($sensor_program, ENT_QUOTES) . '.inc.php)', 'specified sensor programm is not supported', __LINE__, __FILE__ );
  47. }
  48. }
  49. if ( !empty( $hddtemp_avail ) && $hddtemp_avail != "tcp" && $hddtemp_avail != "suid" ) {
  50. $error->addError('include(class.hddtemp.inc.php)', 'bad configuration in config.php for $hddtemp_avail', __LINE__, __FILE__ );
  51. }
  52. if( $error->ErrorsExist() ) {
  53. echo $error->ErrorsAsHTML();
  54. exit;
  55. }
  56. require_once(APP_ROOT . '/includes/common_functions.php'); // Set of common functions used through out the app
  57. // commented for security
  58. // Check to see if where running inside of phpGroupWare
  59. //if (file_exists("../header.inc.php") && isset($_REQUEST['sessionid']) && $_REQUEST['sessionid'] && $_REQUEST['kp3'] && $_REQUEST['domain']) {
  60. // define('PHPGROUPWARE', 1);
  61. // $phpgw_info['flags'] = array('currentapp' => 'phpsysinfo-dev');
  62. // include('../header.inc.php');
  63. //} else {
  64. // define('PHPGROUPWARE', 0);
  65. //}
  66. // DEFINE TEMPLATE_SET
  67. if (isset($_POST['template'])) {
  68. $template = $_POST['template'];
  69. } elseif (isset($_GET['template'])) {
  70. $template = $_GET['template'];
  71. } elseif (isset($_COOKIE['template'])) {
  72. $template = $_COOKIE['template'];
  73. } else {
  74. $template = $default_template;
  75. }
  76. // check to see if we have a random
  77. if ($template == 'random') {
  78. $buf = gdc( APP_ROOT . "/templates/" );
  79. $template = $buf[array_rand($buf, 1)];
  80. }
  81. if ($template != 'xml' && $template != 'wml') {
  82. // figure out if the template exists
  83. $template = basename(APP_ROOT .'/templates/' . $template);
  84. if (!file_exists(APP_ROOT . "/templates/" . $template)) {
  85. // use default if not exists.
  86. $template = $default_template;
  87. }
  88. // Store the current template name in a cookie, set expire date to 30 days later
  89. // if template is xml then skip
  90. @setcookie("template", $template, (time() + 60 * 60 * 24 * 30));
  91. $_COOKIE['template'] = $template; //update COOKIE Var
  92. }
  93. // get our current language
  94. // default to english, but this is negotiable.
  95. if ($template == "wml") {
  96. $lng = "en";
  97. } elseif (isset($_POST['lng'])) {
  98. $lng = $_POST['lng'];
  99. } elseif (isset($_GET['lng'])) {
  100. $lng = $_GET['lng'];
  101. } elseif (isset($_COOKIE['lng'])) {
  102. $lng = $_COOKIE['lng'];
  103. } else {
  104. $lng = $default_lng;
  105. }
  106. if ($lng == 'browser') {
  107. // see if the browser knows the right languange.
  108. if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  109. $plng = split(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
  110. if (count($plng) > 0) {
  111. while (list($k, $v) = each($plng)) {
  112. $k = split(';', $v, 1);
  113. $k = split('-', $k[0]);
  114. if (file_exists(APP_ROOT . '/includes/lang/' . $k[0] . '.php')) {
  115. $lng = $k[0];
  116. break;
  117. }
  118. }
  119. }
  120. }
  121. }
  122. $lng = basename($lng);
  123. if (file_exists(APP_ROOT . '/includes/lang/' . $lng . '.php')) {
  124. $charset = $app_strings['LBL_CHARSET'];
  125. require_once(APP_ROOT . '/includes/lang/' . $lng . '.php'); // get our language include
  126. // Store the current language selection in a cookie, set expire date to 30 days later
  127. @setcookie("lng", $lng, (time() + 60 * 60 * 24 * 30));
  128. $_COOKIE['lng'] = $lng; //update COOKIE Var
  129. } else {
  130. $error->addError('include(' . $lng . ')', 'we do not support this language', __LINE__, __FILE__ );
  131. $lng = $default_lng;
  132. }
  133. // include the files and create the instances
  134. define('TEMPLATE_SET', $template);
  135. require_once( APP_ROOT . '/includes/os/class.' . PHP_OS . '.inc.php' );
  136. $sysinfo = new sysinfo;
  137. if( !empty( $sensor_program ) ) {
  138. require_once(APP_ROOT . '/includes/mb/class.' . $sensor_program . '.inc.php');
  139. $mbinfo = new mbinfo;
  140. }
  141. if ( !empty($hddtemp_avail ) ) {
  142. require_once(APP_ROOT . '/includes/mb/class.hddtemp.inc.php');
  143. }
  144. require_once(APP_ROOT . '/includes/xml/vitals.php');
  145. require_once(APP_ROOT . '/includes/xml/network.php');
  146. require_once(APP_ROOT . '/includes/xml/hardware.php');
  147. require_once(APP_ROOT . '/includes/xml/memory.php');
  148. require_once(APP_ROOT . '/includes/xml/filesystems.php');
  149. require_once(APP_ROOT . '/includes/xml/mbinfo.php');
  150. require_once(APP_ROOT . '/includes/xml/hddtemp.php');
  151. // build the xml
  152. $xml = "<?xml version=\"1.0\" encoding=\"".$app_strings['LBL_CHARSET']."\"?>\n";
  153. $xml .= "<!DOCTYPE phpsysinfo SYSTEM \"phpsysinfo.dtd\">\n\n";
  154. $xml .= created_by();
  155. $xml .= "<phpsysinfo>\n";
  156. $xml .= " <Generation version=\"$VERSION\" timestamp=\"" . time() . "\"/>\n";
  157. $xml .= xml_vitals();
  158. $xml .= xml_network();
  159. $xml .= xml_hardware($hddtemp_devices);
  160. $xml .= xml_memory();
  161. $xml .= xml_filesystems();
  162. if ( !empty( $sensor_program ) ) {
  163. $xml .= xml_mbtemp();
  164. $xml .= xml_mbfans();
  165. $xml .= xml_mbvoltage();
  166. };
  167. if ( !empty($hddtemp_avail ) ) {
  168. $hddtemp = new hddtemp($hddtemp_devices);
  169. $xml .= xml_hddtemp($hddtemp);
  170. }
  171. $xml .= "</phpsysinfo>";
  172. replace_specialchars($xml);
  173. // output
  174. if (TEMPLATE_SET == 'xml') {
  175. // just printout the XML and exit
  176. header("Content-Type: text/xml\n\n");
  177. print $xml;
  178. } elseif (TEMPLATE_SET == 'wml') {
  179. require_once(APP_ROOT . '/includes/XPath.class.php');
  180. $XPath = new XPath();
  181. $XPath->importFromString($xml);
  182. header("Content-type: text/vnd.wap.wml; charset=".$app_strings['LBL_CHARSET']);
  183. header("");
  184. header("Cache-Control: no-cache, must-revalidate");
  185. header("Pragma: no-cache");
  186. echo "<?xml version='1.0' encoding='".$app_strings['LBL_CHARSET']."'?>\n";
  187. echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\" >\n";
  188. echo "<wml>\n";
  189. echo "<card id=\"start\" title=\"phpSysInfo - Menu\">\n";
  190. echo "<p><a href=\"#vitals\">" . $text['vitals'] . "</a></p>\n";
  191. echo "<p><a href=\"#network\">" . $text['netusage'] . "</a></p>\n";
  192. echo "<p><a href=\"#memory\">" . $text['memusage'] . "</a></p>\n";
  193. echo "<p><a href=\"#filesystem\">" . $text['fs'] . "</a></p>\n";
  194. if (!empty($sensor_program) || (isset($hddtemp_avail) && $hddtemp_avail)) {
  195. echo "<p><a href=\"#temp\">" . $text['temperature'] . "</a></p>\n";
  196. }
  197. if (!empty($sensor_program)) {
  198. echo "<p><a href=\"#fans\">" . $text['fans'] . "</a></p>\n";
  199. echo "<p><a href=\"#volt\">" . $text['voltage'] . "</a></p>\n";
  200. }
  201. echo "</card>\n";
  202. echo wml_vitals();
  203. echo wml_network();
  204. echo wml_memory();
  205. echo wml_filesystem();
  206. $temp = "";
  207. if (!empty($sensor_program)) {
  208. echo wml_mbfans();
  209. echo wml_mbvoltage();
  210. $temp .= wml_mbtemp();
  211. }
  212. if (isset($hddtemp_avail) && $hddtemp_avail)
  213. if ($XPath->match("/phpsysinfo/HDDTemp/Item"))
  214. $temp .= wml_hddtemp();
  215. if(strlen($temp) > 0)
  216. echo "<card id=\"temp\" title=\"" . $text['temperature'] . "\">" . $temp . "</card>";
  217. echo "</wml>\n";
  218. } else {
  219. $image_height = get_gif_image_height(APP_ROOT . '/templates/' . TEMPLATE_SET . '/images/bar_middle.gif');
  220. define('BAR_HEIGHT', $image_height);
  221. // if (PHPGROUPWARE != 1) {
  222. require_once(APP_ROOT . '/includes/class.Template.inc.php'); // template library
  223. // }
  224. // fire up the template engine
  225. $tpl = new Template(APP_ROOT . '/templates/' . TEMPLATE_SET);
  226. $tpl->set_file(array('form' => 'form.tpl'));
  227. // print out a box of information
  228. function makebox ($title, $content)
  229. {
  230. if (empty($content)) {
  231. return "";
  232. } else {
  233. global $webpath;
  234. $textdir = direction();
  235. $t = new Template(APP_ROOT . '/templates/' . TEMPLATE_SET);
  236. $t->set_file(array('box' => 'box.tpl'));
  237. $t->set_var('title', $title);
  238. $t->set_var('content', $content);
  239. $t->set_var('webpath', $webpath);
  240. $t->set_var('text_dir', $textdir['direction']);
  241. return $t->parse('out', 'box');
  242. }
  243. }
  244. // Fire off the XPath class
  245. require_once(APP_ROOT . '/includes/XPath.class.php');
  246. $XPath = new XPath();
  247. $XPath->importFromString($xml);
  248. // let the page begin.
  249. require_once(APP_ROOT . '/includes/system_header.php');
  250. if ( $error->ErrorsExist() && isset($showerrors) && $showerrors ) {
  251. $tpl->set_var('errors', makebox("ERRORS", $error->ErrorsAsHTML() ));
  252. }
  253. $tpl->set_var('title', $text['title'] . ': ' . $XPath->getData('/phpsysinfo/Vitals/Hostname') . ' (' . $XPath->getData('/phpsysinfo/Vitals/IPAddr') . ')');
  254. $tpl->set_var('vitals', makebox($text['vitals'], html_vitals()));
  255. $tpl->set_var('network', makebox($text['netusage'], html_network()));
  256. $tpl->set_var('hardware', makebox($text['hardware'], html_hardware()));
  257. $tpl->set_var('memory', makebox($text['memusage'], html_memory()));
  258. $tpl->set_var('filesystems', makebox($text['fs'], html_filesystems()));
  259. // Timo van Roermund: change the condition for showing the temperature, voltage and fans section
  260. $html_temp = "";
  261. if (!empty($sensor_program)) {
  262. if ($XPath->match("/phpsysinfo/MBinfo/Temperature/Item")) {
  263. $html_temp = html_mbtemp();
  264. }
  265. if ($XPath->match("/phpsysinfo/MBinfo/Fans/Item")) {
  266. $tpl->set_var('mbfans', makebox($text['fans'], html_mbfans()));
  267. } else {
  268. $tpl->set_var('mbfans', '');
  269. };
  270. if ($XPath->match("/phpsysinfo/MBinfo/Voltage/Item")) {
  271. $tpl->set_var('mbvoltage', makebox($text['voltage'], html_mbvoltage()));
  272. } else {
  273. $tpl->set_var('mbvoltage', '');
  274. };
  275. }
  276. if (isset($hddtemp_avail) && $hddtemp_avail) {
  277. if ($XPath->match("/phpsysinfo/HDDTemp/Item")) {
  278. $html_temp .= html_hddtemp();
  279. };
  280. }
  281. if (strlen($html_temp) > 0) {
  282. $tpl->set_var('mbtemp', makebox($text['temperature'], "\n<table width=\"100%\">\n" . $html_temp . "</table>\n"));
  283. }
  284. // parse our the template
  285. $tpl->pfp('out', 'form');
  286. // finally our print our footer
  287. // if (PHPGROUPWARE == 1) {
  288. // $phpgw->common->phpgw_footer();
  289. // } else {
  290. require_once(APP_ROOT . '/includes/system_footer.php');
  291. // }
  292. }
  293. ?>