Code

Added execution time to main.php
[gosa.git] / html / main.php
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 /* Basic setup, remove eventually registered sessions */
22 $start = microtime();
23 $timing= array();
24 require_once ("../include/php_setup.inc");
25 require_once ("functions.inc");
26 require_once ("functions_FAI.inc");
27 header("Content-type: text/html; charset=UTF-8");
29 /* Find all class files and include them */
30 get_dir_list("$BASE_DIR/plugins");
32 /* Set the text domain as 'messages' */
33 $domain = 'messages';
34 bindtextdomain($domain, "$BASE_DIR/locale");
35 textdomain($domain);
37 /* Set cookie lifetime to one day (The parameter is in seconds ) */
38 session_set_cookie_params(24*60*60);
40 /* Set cache limter to one day (parameter is minutes !!)*/
41 session_cache_expire(60*24);  // default is 180
43 /* Set session max lifetime, to prevent the garbage collector to delete session before timeout.
44     !! The garbage collector is a cron job on debian systems, the cronjob will fetch the timeout from 
45     the php.ini, so if you use debian, you must hardcode session.gc_maxlifetime in your php.ini */
46 ini_set("session.gc_maxlifetime",24*60*60);
48 /* Remember everything we did after the last click */
49 session_start ();
51 $_SESSION['limit_exceeded'] =FALSE;
53 if ($_SERVER["REQUEST_METHOD"] == "POST"){
54   @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
55 }
56 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_SESSION, "_SESSION");
58 /* Logged in? Simple security check */
59 if (!isset($_SESSION['config'])){
60   gosa_log ("main.php called without session - logging out");
61   header ("Location: logout.php");
62   exit;
63
65 /* Reset errors */
66 $_SESSION['errors']             = "";
67 $_SESSION['errorsAlreadyPosted']= array();
68 $_SESSION['LastError']          = "";
70 /* Check for uniqe ip address */
71 $ui= $_SESSION["ui"];
72 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
73   gosa_log ("main.php called with session which has a changed IP address.", 3);
74   header ("Location: logout.php");
75   exit;
76 }
77 $config= $_SESSION['config'];
80 /* Check for invalid sessions */
81 if(empty($_SESSION['_LAST_PAGE_REQUEST'])){
82   $_SESSION['_LAST_PAGE_REQUEST']= time();
83 }else{
85   /* check GOsa.conf for defined session lifetime */
86   if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
87     $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
88   }else{
89     $max_life = 60*60*2;
90   }
92   /* get time difference between last page reload */
93   $request_time = (time()-$_SESSION['_LAST_PAGE_REQUEST']);
95   /* If page wasn't reloaded for more than max_life seconds 
96    * kill session
97    */
98   if($request_time > $max_life){
99     session_unset();
100     gosa_log ("main.php called without session - logging out");
101     header ("Location: logout.php");
102     exit;
103   }
104   $_SESSION['_LAST_PAGE_REQUEST'] = time();
108 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
110 /* Set template compile directory */
111 if (isset ($config->data['MAIN']['COMPILE'])){
112   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
113 } else {
114   $smarty->compile_dir= '/var/spool/gosa/';
117 /* Set default */
118 $reload_navigation = false;
120 /* Set last initialised language to current, browser settings */
121 if((!isset($_SESSION['Last_init_lang']))){
122   $reload_navigation = true;
123   $_SESSION['Last_init_lang'] = get_browser_language();
126 /* Language setup */
127 if ($config->data['MAIN']['LANG'] == ""){
128   
129   /* If last language != current force navi reload */
130   if($_SESSION['Last_init_lang'] != get_browser_language()){
131     $reload_navigation = true;
132   }
133   $lang= get_browser_language();
134   $_SESSION['Last_init_lang'] = $lang;
135 } else {
136   $lang= $config->data['MAIN']['LANG'];
139 /* Preset current main base */
140 if(!isset($_SESSION['CurrentMainBase'])){
141   $_SESSION['CurrentMainBase']= get_base_from_people($ui->dn);
144 $lang.=".UTF-8";
145 putenv("LANGUAGE=");
146 putenv("LANG=$lang");
147 setlocale(LC_ALL, $lang);
148 $GLOBALS['t_language']= $lang;
149 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
151 /* Set the text domain as 'messages' */
152 $domain = 'messages';
153 bindtextdomain($domain, "$BASE_DIR/locale");
154 textdomain($domain);
155 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
157 /* Prepare plugin list */
158 if (!isset($_SESSION['plist'])){
159   $_SESSION['plist']= new pluglist($config, $ui);
160   
161   /* Load ocMapping into userinfo */
162   $tmp= new acl($config, NULL, $ui->dn);
163   $ui->ocMapping= $tmp->ocMapping;
164   $_SESSION['ui']= $ui;
166 $plist= $_SESSION['plist'];
168 /* Check for register globals */
169 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
170   echo _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator.");
171   gosa_log ("Register globals is on. For security reasons, this should be turned off.");
172   session_destroy ();
173   exit ();
176 /* Check Plugin variable */
177 if (isset($_SESSION['plugin_dir'])){
178   $old_plugin_dir= $_SESSION['plugin_dir'];
179 } else {
180   $old_plugin_dir= "";
182 if (isset($_GET['plug'])){
183   $plug= validate($_GET['plug']);
184   $plugin_dir= $plist->get_path($plug);
185   $_SESSION['plugin_dir']= $plugin_dir;
186   if ($plugin_dir == ""){
187     gosa_log ("main.php called with invalid plug parameter \"$plug\"", 3);
188     header ("Location: logout.php");
189     exit;
190   }
191 } else {
192   /* set to welcome page as default plugin */
193   $_SESSION['plugin_dir']= "welcome";
194   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
197 /* Check if we need to delete a lock */
198 if ($old_plugin_dir != $plugin_dir){
199   if (is_file("$old_plugin_dir/main.inc")){
200     $remove_lock= true;
201     require_once ("$old_plugin_dir/main.inc");
202   }
204 $remove_lock= false;
206 /* Check for sizelimits */
207 eval_sizelimit();
209 /* Check for memory */
210 if (function_exists("memory_get_usage")){
211   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
212     print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
213   }
216 /* Redirect on back event */
217 if ($_SERVER["REQUEST_METHOD"] == "POST"){
219   /* Look for button events that match /^back[0-9]+$/,
220      extract the number and step the correct plugin. */
221   foreach ($_POST as $key => $value){
222     if (preg_match("/^back[0-9]+$/", $key)){
223       $back= substr($key, 4);
224       header ("Location: main.php?plug=$back");
225       exit;
226     }
227   }
230 /* Redirect on password back event */
231 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
232   header ("Location: main.php");
233   exit;
236 /* Check for multiple windows logout */
237 if ($_SERVER["REQUEST_METHOD"] == "POST"){
238   if (isset($_POST['reset_session'])){
239     header ("Location: logout.php");
240     exit;
241   }
243   if (isset($_POST['cancel_lock'])){
244     unset ($_SESSION['dn']);
245   }
249 /* Load department list when plugin has changed. That is some kind of
250    compromise between speed and beeing up to date */
251 if (isset($_GET['reset'])){
252   if (isset($_SESSION['objectinfo'])){
253     unset ($_SESSION['objectinfo']);
254   }
257 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
258 if(isset($_GET['explorer'])){
259   $_SESSION{'eGosa'}=1;
261 if(isset($_SESSION['POST'])){
262   $_SERVER["REQUEST_METHOD"] = "POST";
263   foreach ($_SESSION['POST'] as $key => $dummy){
264     $_POST[$key]=$_SESSION['POST'][$key];
265   }
266   unset($_SESSION['POST']);
269 /* show web frontend */
270 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
271 $smarty->assign ("must", "<font class=\"must\">*</font>");
272 if (isset($plug)){
273   $plug= "?plug=$plug";
274 } else {
275   $plug= "";
277 if ($_SESSION['js']==FALSE){
278   $smarty->assign("javascript", "false");
279   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
280 } else {
281   $smarty->assign("javascript", "true");
282   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
285 $smarty->assign ("username", $ui->username);
286 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
287 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
288 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
289 $smarty->assign ("go_out", get_template_path('images/stop.png'));
290 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
291 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
292 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
293 $smarty->assign ("go_help", get_template_path('images/help.png'));
295 /* reload navigation if language changed*/  
296 if($reload_navigation){
297   $plist->menu="";;
299 $plist->gen_headlines();
300 $plist->gen_menu();
301 $smarty->assign ("menu", $plist->menu);
302 $smarty->assign ("plug", "$plug");
304 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
306 /* React on clicks */
307 if ($_SERVER["REQUEST_METHOD"] == "POST"){
309   /* 'delete_lock' is set by the lock removal dialog. We should remove the
310      lock at this point globally. Plugins do not need to remove it. */
311   if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
312     del_lock ($_SESSION['dn']);
314     /* Set old Post data */
315     if(isset($_SESSION['LOCK_VARS_USED'])){
316       foreach($_SESSION['LOCK_VARS_USED'] as $name => $value){
317         $_GET[$name]  = $value;
318         $_POST[$name] = $value;
319       } 
320     }
321     sess_del ('dn');
322   }
325   /* I don't want multiple browser windows open. One way to check it is
326      to count a hidden field and warn the user if SESSION and INPUT count
327      differ. */
328   if (isset($_POST['session_cnt'])){
329     if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
330       $smarty->display(get_template_path('conflict.tpl'));
331       exit ();
332     }
333     $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
334     $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
335   }
338 /* Only generate hidden click counter, if post_cnt is defined */
339 if (isset ($_SESSION['post_cnt'])){
340   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
343 $start = microtime();
345 /* Load plugin */
346 if (is_file("$plugin_dir/main.inc")){
347   require_once ("$plugin_dir/main.inc");
348 } else {
349   echo sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug);
350   exit();
353 /* Close div/tables */
355   /* check if we are using account expiration */
357   if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
358       preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
359     
360       $expired= ldap_expired_account($config, $ui->dn, $ui->username);
362       if ($expired == 2){
363         gosa_log ("password for user \"$ui->username\" is about to expire");
364         print_red(_("Your password is about to expire, please change your password"));
365       }
366   }
367   
368 /* Print_out last ErrorMessage repeated string. */
369 print_red(NULL);
371 $smarty->assign("contents", $display.get_MicroTimeDiff($start,microtime()));
373 if (isset($_SESSION['errors'])){
374   $smarty->assign("errors", $_SESSION['errors']);
376 if ($error_collector != ""){
377   $smarty->assign("php_errors", $error_collector."</div>");
378 } else {
379   $smarty->assign("php_errors", "");
381 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
383 if ((isset($config->data['MAIN']['W3CTEST']) && preg_match('/true/i', $config->data['MAIN']['W3CTEST']))&&(!empty($display))&&(is_callable("tidy_parse_string"))) {
384   tidy_parse_string(utf8_decode($display));
385   $err = nl2br(htmlentities(tidy_get_error_buffer()));
386   
387   if($err){
388     echo "<table summary=\"\" width=\"100%\" style='background-color:#E0E0E0;border-bottom:1px solid black'><tr><td><img alt=\"W3C\"            align=\"middle\" src='images/warning.png'>&nbsp;<font style='font-size:14px;font-weight:bold'>"._("Generating this page caused the W3C          conformance checker to raise some errors!")."</font></td><td align=right><button onClick='toggle(\"w3cbox\")'>"._("Toggle information")."</     button></td></tr></table><div id='w3cbox' style='width:100%; position:absolute; z-index:0; visibility: hidden; background-color:white; border-  bottom:1px solid black;'>";
389     echo $err."</div>";
390   }
392   tidy_clean_repair($display);
395 /* Show page... */
396 echo $display;
398 /* Save plist and config */
399 $_SESSION['plist']= $plist;
400 $_SESSION['config']= $config;
402 /* Echo compilation time * /
403 $r = split(" ",$start);
404 $ms = $r[0];
405 $s= $r[1];
407 $re = split(" ",microtime());
408 $mse = $re[0];
409 $se= $re[1];
411 $add = 0;
412 if(($mse -$ms)<0){
413   $se --;
414   $add = 1;
416 echo ($se -$s).",";
417 echo (int)(($add+($mse -$ms))*1000)." s";
418 */
419 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
420 ?>