Code

New Session lifetime management
[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 $timing= array();
23 require_once ("../include/php_setup.inc");
24 require_once ("functions.inc");
25 header("Content-type: text/html; charset=UTF-8");
27 /* Find all class files and include them */
28 get_dir_list("$BASE_DIR/plugins");
30 /* Set the text domain as 'messages' */
31 $domain = 'messages';
32 bindtextdomain($domain, "$BASE_DIR/locale");
33 textdomain($domain);
35 /* Set cookie lifetime to one day */
36 session_set_cookie_params(24*60*60);
38 /* Remember everything we did after the last click */
39 session_start ();
42 if ($_SERVER["REQUEST_METHOD"] == "POST"){
43   @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
44 }
45 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_SESSION, "_SESSION");
47 /* Logged in? Simple security check */
48 if (!isset($_SESSION['config'])){
49   gosa_log ("main.php called without session - logging out");
50   header ("Location: logout.php");
51   exit;
52
54 /* Reset errors */
55 $_SESSION['errors']= "";
57 /* Check for uniqe ip address */
58 $ui= $_SESSION["ui"];
59 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
60   gosa_log ("main.php called with session which has a changed IP address.", 3);
61   header ("Location: logout.php");
62   exit;
63 }
64 $config= $_SESSION['config'];
67 /* Check for invalid sessions */
68 if(empty($_SESSION['_LAST_PAGE_REQUEST'])){
69   $_SESSION['_LAST_PAGE_REQUEST']= time();
70 }else{
72   /* check GOsa.conf for defined session lifetime */
73   if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
74     $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
75   }else{
76     $max_life = 60*60*2;
77   }
79   /* get time difference between last page reload */
80   $request_time = (time()-$_SESSION['_LAST_PAGE_REQUEST']);
82   /* If page wasn't reloaded for more than max_life seconds 
83    * kill session
84    */
85   if($request_time > $max_life){
86     session_unset();
87     gosa_log ("main.php called without session - logging out");
88     header ("Location: logout.php");
89     exit;
90   }
91   //echo "Session was ".$request_time." s inactive";
92   $_SESSION['_LAST_PAGE_REQUEST'] = time();
93 }
96 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
98 /* Set template compile directory */
99 if (isset ($config->data['MAIN']['COMPILE'])){
100   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
101 } else {
102   $smarty->compile_dir= '/var/spool/gosa/';
105 /* Set default */
106 $reload_navigation = false;
108 /* Set last initialised language to current, browser settings */
109 if((!isset($_SESSION['Last_init_lang']))){
110   $reload_navigation = true;
111   $_SESSION['Last_init_lang'] = get_browser_language();
114 /* Language setup */
115 if ($config->data['MAIN']['LANG'] == ""){
116   
117   /* If last language != current force navi reload */
118   if($_SESSION['Last_init_lang'] != get_browser_language()){
119     $reload_navigation = true;
120   }
121   $lang= get_browser_language();
122   $_SESSION['Last_init_lang'] = $lang;
123 } else {
124   $lang= $config->data['MAIN']['LANG'];
127 $lang.=".UTF-8";
128 putenv("LANGUAGE=");
129 putenv("LANG=$lang");
130 setlocale(LC_ALL, $lang);
131 $GLOBALS['t_language']= $lang;
132 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
134 /* Set the text domain as 'messages' */
135 $domain = 'messages';
136 bindtextdomain($domain, "$BASE_DIR/locale");
137 textdomain($domain);
138 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
140 /* Prepare plugin list */
141 if (!isset($_SESSION['plist'])){
142   $_SESSION['plist']= new pluglist($config, $ui);
144 $plist= $_SESSION['plist'];
146 /* Check for register globals */
147 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
148   print_red (_("Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."));
149   echo $_SESSION['errors'];
150   gosa_log ("Register globals is on. For security reasons, this should be turned off.");
151   session_destroy ();
152   exit ();
155 /* Check Plugin variable */
156 if (isset($_SESSION['plugin_dir'])){
157   $old_plugin_dir= $_SESSION['plugin_dir'];
158 } else {
159   $old_plugin_dir= "";
161 if (isset($_GET['plug'])){
162   $plug= validate($_GET['plug']);
163   $plugin_dir= $plist->get_path($plug);
164   $_SESSION['plugin_dir']= $plugin_dir;
165   if ($plugin_dir == ""){
166     gosa_log ("main.php called with invalid plug parameter \"$plug\"", 3);
167     header ("Location: logout.php");
168     exit;
169   }
170 } else {
171   /* set to welcome page as default plugin */
172   $_SESSION['plugin_dir']= "welcome";
173   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
176 /* Check if we need to delete a lock */
177 if ($old_plugin_dir != $plugin_dir){
178   if (is_file("$old_plugin_dir/main.inc")){
179     $remove_lock= true;
180     require_once ("$old_plugin_dir/main.inc");
181   }
183 $remove_lock= false;
185 /* Check for sizelimits */
186 eval_sizelimit();
188 /* Check for memory */
189 if (function_exists("memory_get_usage")){
190   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
191     print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
192   }
195 /* Redirect on back event */
196 if ($_SERVER["REQUEST_METHOD"] == "POST"){
198   /* Look for button events that match /^back[0-9]+$/,
199      extract the number and step the correct plugin. */
200   foreach ($_POST as $key => $value){
201     if (preg_match("/^back[0-9]+$/", $key)){
202       $back= substr($key, 4);
203       header ("Location: main.php?plug=$back");
204       exit;
205     }
206   }
209 /* Redirect on password back event */
210 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
211   header ("Location: main.php");
212   exit;
215 /* Check for multiple windows logout */
216 if ($_SERVER["REQUEST_METHOD"] == "POST"){
217   if (isset($_POST['reset_session'])){
218     header ("Location: logout.php");
219     exit;
220   }
222   if (isset($_POST['cancel_lock'])){
223     unset ($_SESSION['dn']);
224   }
228 /* Load department list when plugin has changed. That is some kind of
229    compromise between speed and beeing up to date */
230 if (isset($_GET['reset'])){
231   $config->departments= get_departments();
232   $config->make_idepartments ();
233   if (isset($_SESSION['objectinfo'])){
234     unset ($_SESSION['objectinfo']);
235   }
238 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
239 if(isset($_GET['explorer'])){
240   $_SESSION{'eGosa'}=1;
242 if(isset($_SESSION['POST'])){
243   $_SERVER["REQUEST_METHOD"] = "POST";
244   foreach ($_SESSION['POST'] as $key => $dummy){
245     $_POST[$key]=$_SESSION['POST'][$key];
246   }
247   unset($_SESSION['POST']);
250 /* show web frontend */
251 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
252 $smarty->assign ("must", "<font class=\"must\">*</font>");
253 if (isset($plug)){
254   $plug= "?plug=$plug";
255 } else {
256   $plug= "";
258 if ($_SESSION['js']==FALSE){
259   $smarty->assign("javascript", "false");
260   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
261 } else {
262   $smarty->assign("javascript", "true");
263   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
266 $smarty->assign ("username", $ui->username);
267 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
268 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
269 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
270 $smarty->assign ("go_out", get_template_path('images/stop.png'));
271 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
272 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
273 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
274 $smarty->assign ("go_help", get_template_path('images/help.png'));
276 /* reload navigation if language changed*/  
277 if($reload_navigation){
278   $plist->menu="";;
280 $plist->gen_headlines();
281 $plist->gen_menu();
282 $smarty->assign ("menu", $plist->menu);
283 $smarty->assign ("plug", "$plug");
285 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
288 /* React on clicks */
289 if ($_SERVER["REQUEST_METHOD"] == "POST"){
291   /* 'delete_lock' is set by the lock removal dialog. We should remove the
292      lock at this point globally. Plugins do not need to remove it. */
293   if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
294     del_lock ($_SESSION['dn']);
295     sess_del ('dn');
296   }
299   /* I don't want multiple browser windows open. One way to check it is
300      to count a hidden field and warn the user if SESSION and INPUT count
301      differ. */
302   if (isset($_POST['session_cnt'])){
303     if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
304       $smarty->display(get_template_path('conflict.tpl'));
305       exit ();
306     }
307     $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
308     $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
309   }
312 /* Only generate hidden click counter, if post_cnt is defined */
313 if (isset ($_SESSION['post_cnt'])){
314   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
317 /* Load plugin */
318 if (is_file("$plugin_dir/main.inc")){
319   require_once ("$plugin_dir/main.inc");
320 } else {
321   print_red(sprintf(_("Can't find any plugin definitions for plugin '%s'!"), $plug));
322   echo $_SESSION['errors'];
323   exit();
326 /* Close div/tables */
327 $smarty->assign("contents", $display);
328 if (isset($_SESSION['errors'])){
329   $smarty->assign("errors", $_SESSION['errors']);
331 if ($error_collector != ""){
332   $smarty->assign("php_errors", $error_collector."</div>");
333 } else {
334   $smarty->assign("php_errors", "");
336 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
338 if ((isset($config->data['MAIN']['W3CTEST']) && preg_match('/true/i', $config->data['MAIN']['W3CTEST']))&&(!empty($display))&&(is_callable("tidy_parse_string"))) {
339   tidy_parse_string(utf8_decode($display));
340   $err = nl2br(htmlentities(tidy_get_error_buffer()));
341   
342   if($err){
343     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;'>";
344     echo $err."</div>";
345   }
347   tidy_clean_repair($display);
350 /* Show page... */
351 echo $display;
353 /* Save plist */
354 $_SESSION['plist']= $plist;
356 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
357 ?>