Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
1 root 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.122.4.1 2007/08/19 09:21:57 xqus Exp $
16
// phpsysinfo release version number
17
$VERSION = "2.5.4";
18
$startTime = array_sum( explode( " ", microtime() ) );
19
 
20
define('APP_ROOT', dirname(__FILE__));
21
define('IN_PHPSYSINFO', true);
22
 
23
ini_set('magic_quotes_runtime', 'off');
24
ini_set('register_globals', 'off');
25
// ini_set('display_errors','on');
26
 
27
require_once(APP_ROOT . '/includes/class.error.inc.php');
28
$error = new Error;
29
 
30
// Figure out which OS where running on, and detect support
31
if ( file_exists( APP_ROOT . '/includes/os/class.' . PHP_OS . '.inc.php' ) ) {
32
} else {
33
  $error->addError('include(class.' . PHP_OS . '.php.inc)' , PHP_OS . ' is not currently supported', __LINE__, __FILE__ );
34
}
35
 
36
if (!extension_loaded('xml')) {
37
  $error->addError('extension_loaded(xml)', 'phpsysinfo requires the xml module for php to work', __LINE__, __FILE__);
38
} 
39
if (!extension_loaded('pcre')) {
40
  $error->addError('extension_loaded(pcre)', 'phpsysinfo requires the pcre module for php to work', __LINE__, __FILE__);
41
} 
42
 
43
if (!file_exists(APP_ROOT . '/config.php')) {
44
  $error->addError('file_exists(config.php)', 'config.php does not exist in the phpsysinfo directory.', __LINE__, __FILE__);
45
} else { 
46
  require_once(APP_ROOT . '/config.php'); 			// get the config file
47
}
48
 
49
if ( !empty( $sensor_program ) ) {
50
  $sensor_program = basename( $sensor_program );
51
  if( !file_exists( APP_ROOT . '/includes/mb/class.' . $sensor_program . '.inc.php' ) ) {
52
    $error->addError('include(class.' . htmlspecialchars($sensor_program, ENT_QUOTES) . '.inc.php)', 'specified sensor programm is not supported', __LINE__, __FILE__ );
53
  } 
54
} 
55
 
56
if ( !empty( $hddtemp_avail ) && $hddtemp_avail != "tcp" && $hddtemp_avail != "suid" ) {
57
  $error->addError('include(class.hddtemp.inc.php)', 'bad configuration in config.php for $hddtemp_avail', __LINE__, __FILE__ );
58
}
59
 
60
if( $error->ErrorsExist() ) {
61
  echo $error->ErrorsAsHTML();
62
  exit;
63
}
64
 
65
require_once(APP_ROOT . '/includes/common_functions.php'); 	// Set of common functions used through out the app
66
 
67
// commented for security
68
// Check to see if where running inside of phpGroupWare
69
//if (file_exists("../header.inc.php") && isset($_REQUEST['sessionid']) && $_REQUEST['sessionid'] && $_REQUEST['kp3'] && $_REQUEST['domain']) {
70
//  define('PHPGROUPWARE', 1);
71
//  $phpgw_info['flags'] = array('currentapp' => 'phpsysinfo-dev');
72
//  include('../header.inc.php');
73
//} else {
74
//  define('PHPGROUPWARE', 0);
75
//}
76
 
77
// DEFINE TEMPLATE_SET
78
if (isset($_POST['template'])) {
79
  $template = $_POST['template'];
80
} elseif (isset($_GET['template'])) {
81
  $template = $_GET['template'];
82
} elseif (isset($_COOKIE['template'])) {
83
  $template = $_COOKIE['template'];
84
} else {
85
  $template = $default_template; 
86
}
87
 
88
// check to see if we have a random
89
if ($template == 'random') {
90
  $buf = gdc( APP_ROOT . "/templates/" );
91
  $template = $buf[array_rand($buf, 1)];
92
}
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
    }
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 {
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
}
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
?>