Subversion Repositories ALCASAR

Rev

Rev 324 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

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