Code

Udpated JS focus,
[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 header("Content-type: text/html; charset=UTF-8");
28 /* Find all class files and include them */
29 get_dir_list("$BASE_DIR/plugins");
31 /* Set the text domain as 'messages' */
32 $domain = 'messages';
33 bindtextdomain($domain, "$BASE_DIR/locale");
34 textdomain($domain);
36 /* Set cookie lifetime to one day (The parameter is in seconds ) */
37 session_set_cookie_params(24*60*60);
39 /* Set cache limter to one day (parameter is minutes !!)*/
40 session_cache_expire(60*24);  // default is 180
42 /* Set session max lifetime, to prevent the garbage collector to delete session before timeout.
43     !! The garbage collector is a cron job on debian systems, the cronjob will fetch the timeout from 
44     the php.ini, so if you use debian, you must hardcode session.gc_maxlifetime in your php.ini */
45 ini_set("session.gc_maxlifetime",24*60*60);
47 /* Remember everything we did after the last click */
48 session_start ();
50 $_SESSION['limit_exceeded'] =FALSE;
52 if ($_SERVER["REQUEST_METHOD"] == "POST"){
53   @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
54 }
55 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_SESSION, "_SESSION");
57 /* Logged in? Simple security check */
58 if (!isset($_SESSION['config'])){
59   gosa_log ("main.php called without session - logging out");
60   header ("Location: logout.php");
61   exit;
62
64 /* Reset errors */
65 $_SESSION['errors']             = "";
66 $_SESSION['errorsAlreadyPosted']= array();
67 $_SESSION['LastError']          = "";
69 /* Check for uniqe ip address */
70 $ui= $_SESSION["ui"];
71 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
72   gosa_log ("main.php called with session which has a changed IP address.", 3);
73   header ("Location: logout.php");
74   exit;
75 }
76 $config= $_SESSION['config'];
79 /* Check for invalid sessions */
80 if(empty($_SESSION['_LAST_PAGE_REQUEST'])){
81   $_SESSION['_LAST_PAGE_REQUEST']= time();
82 }else{
84   /* check GOsa.conf for defined session lifetime */
85   if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
86     $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
87   }else{
88     $max_life = 60*60*2;
89   }
91   /* get time difference between last page reload */
92   $request_time = (time()-$_SESSION['_LAST_PAGE_REQUEST']);
94   /* If page wasn't reloaded for more than max_life seconds 
95    * kill session
96    */
97   if($request_time > $max_life){
98     session_unset();
99     gosa_log ("main.php called without session - logging out");
100     header ("Location: logout.php");
101     exit;
102   }
103   $_SESSION['_LAST_PAGE_REQUEST'] = time();
107 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
109 /* Set template compile directory */
110 if (isset ($config->data['MAIN']['COMPILE'])){
111   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
112 } else {
113   $smarty->compile_dir= '/var/spool/gosa/';
116 /* Set default */
117 $reload_navigation = false;
119 /* Set last initialised language to current, browser settings */
120 if((!isset($_SESSION['Last_init_lang']))){
121   $reload_navigation = true;
122   $_SESSION['Last_init_lang'] = get_browser_language();
125 /* Language setup */
126 if ($config->data['MAIN']['LANG'] == ""){
127   
128   /* If last language != current force navi reload */
129   if($_SESSION['Last_init_lang'] != get_browser_language()){
130     $reload_navigation = true;
131   }
132   $lang= get_browser_language();
133   $_SESSION['Last_init_lang'] = $lang;
134 } else {
135   $lang= $config->data['MAIN']['LANG'];
138 $lang.=".UTF-8";
140 putenv("LANGUAGE=");
141 putenv("LANG=$lang");
142 setlocale(LC_ALL, $lang);
143 $GLOBALS['t_language']= $lang;
144 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
146 /* Set the text domain as 'messages' */
147 $domain = 'messages';
148 bindtextdomain($domain, "$BASE_DIR/locale");
149 textdomain($domain);
150 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
152 /* Preset current main base */
153 if(!isset($_SESSION['CurrentMainBase'])){
154   $_SESSION['CurrentMainBase']= get_base_from_people($ui->dn);
157 /* Prepare plugin list */
158 if (!isset($_SESSION['plist'])){
159   $_SESSION['plist']= new pluglist($config, $ui);
161 $plist= $_SESSION['plist'];
163 /* Check for register globals */
164 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
165   echo _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator.");
166   gosa_log ("Register globals is on. For security reasons, this should be turned off.");
167   session_destroy ();
168   exit ();
171 /* Check Plugin variable */
172 if (isset($_SESSION['plugin_dir'])){
173   $old_plugin_dir= $_SESSION['plugin_dir'];
174 } else {
175   $old_plugin_dir= "";
178 /* reload navigation if language changed*/  
179 if($reload_navigation){
180   $plist->menu="";;
182 $plist->gen_headlines();
183 $plist->gen_menu();
186 if (isset($_GET['plug'])){
187   $plug= validate($_GET['plug']);
189   if(!in_array_ics($plug,$plist->allowed_plug_ids)){
190     $plug = key($plist->allowed_plug_ids);
191   }
193   $plugin_dir= $plist->get_path($plug);
194   $_SESSION['plugin_dir']= $plugin_dir;
195   if ($plugin_dir == ""){
196     gosa_log ("main.php called with invalid plug parameter \"$plug\"", 3);
197     header ("Location: logout.php");
198     exit;
199   }
200 } else {
201   /* set to welcome page as default plugin */
202   $_SESSION['plugin_dir']= "welcome";
203   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
206 /* Check if we need to delete a lock */
207 if ($old_plugin_dir != $plugin_dir){
208   if (is_file("$old_plugin_dir/main.inc")){
209     $remove_lock= true;
210     require_once ("$old_plugin_dir/main.inc");
211   }
213 $remove_lock= false;
215 /* Check for sizelimits */
216 eval_sizelimit();
218 /* Check for memory */
219 if (function_exists("memory_get_usage")){
220   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
221     print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
222   }
225 /* Redirect on back event */
226 if ($_SERVER["REQUEST_METHOD"] == "POST"){
228   /* Look for button events that match /^back[0-9]+$/,
229      extract the number and step the correct plugin. */
230   foreach ($_POST as $key => $value){
231     if (preg_match("/^back[0-9]+$/", $key)){
232       $back= substr($key, 4);
233       header ("Location: main.php?plug=$back");
234       exit;
235     }
236   }
239 /* Redirect on password back event */
240 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
241   header ("Location: main.php");
242   exit;
245 /* Check for multiple windows logout */
246 if ($_SERVER["REQUEST_METHOD"] == "POST"){
247   if (isset($_POST['reset_session'])){
248     header ("Location: logout.php");
249     exit;
250   }
252   if (isset($_POST['cancel_lock'])){
253     unset ($_SESSION['dn']);
254   }
258 /* Load department list when plugin has changed. That is some kind of
259    compromise between speed and beeing up to date */
260 if (isset($_GET['reset'])){
261   if (isset($_SESSION['objectinfo'])){
262     unset ($_SESSION['objectinfo']);
263   }
266 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
267 if(isset($_GET['explorer'])){
268   $_SESSION{'eGosa'}=1;
270 if(isset($_SESSION['POST'])){
271   $_SERVER["REQUEST_METHOD"] = "POST";
272   foreach ($_SESSION['POST'] as $key => $dummy){
273     $_POST[$key]=$_SESSION['POST'][$key];
274   }
275   unset($_SESSION['POST']);
278 /* show web frontend */
279 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
280 $smarty->assign ("must", "<font class=\"must\">*</font>");
281 if (isset($plug)){
282   $plug= "?plug=$plug";
283 } else {
284   $plug= "";
286 if ($_SESSION['js']==FALSE){
287   $smarty->assign("javascript", "false");
288   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
289 } else {
290   $smarty->assign("javascript", "true");
291   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
294 $smarty->assign ("username", $ui->username);
295 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
296 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
297 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
298 $smarty->assign ("go_out", get_template_path('images/stop.png'));
299 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
300 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
301 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
302 $smarty->assign ("go_help", get_template_path('images/help.png'));
304 $smarty->assign ("menu", $plist->menu);
305 $smarty->assign ("plug", "$plug");
307 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
309 /* React on clicks */
310 if ($_SERVER["REQUEST_METHOD"] == "POST"){
312   /* 'delete_lock' is set by the lock removal dialog. We should remove the
313      lock at this point globally. Plugins do not need to remove it. */
314   if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
315     del_lock ($_SESSION['dn']);
317     /* Set old Post data */
318     if(isset($_SESSION['LOCK_VARS_USED'])){
319       foreach($_SESSION['LOCK_VARS_USED'] as $name => $value){
320         $_GET[$name]  = $value;
321         $_POST[$name] = $value;
322       } 
323     }
324     sess_del ('dn');
325   }
328   /* I don't want multiple browser windows open. One way to check it is
329      to count a hidden field and warn the user if SESSION and INPUT count
330      differ. */
331   if (isset($_POST['session_cnt'])){
332     if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
333       $smarty->display(get_template_path('conflict.tpl'));
334       exit ();
335     }
336     $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
337     $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
338   }
341 /* Only generate hidden click counter, if post_cnt is defined */
342 if (isset ($_SESSION['post_cnt'])){
343   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
346 /* Load plugin */
347 if (is_file("$plugin_dir/main.inc")){
348   require_once ("$plugin_dir/main.inc");
349 } else {
350   echo sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug);
351   exit();
354 /* Close div/tables */
356   /* check if we are using account expiration */
358   if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
359       preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
360     
361       $expired= ldap_expired_account($config, $ui->dn, $ui->username);
363       if ($expired == 2){
364         gosa_log ("password for user \"$ui->username\" is about to expire");
365         print_red(_("Your password is about to expire, please change your password"));
366       }
367   }
368   
369 /* Print_out last ErrorMessage repeated string. */
370 print_red(NULL);
372 $smarty->assign("contents", $display);
374 if (isset($_SESSION['errors'])){
375   $smarty->assign("errors", $_SESSION['errors']);
378 if ($error_collector != ""){
379   $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
380 } else {
381   $smarty->assign("php_errors", "");
384 /* Set focus to the error button if we've an error message */
385 $focus= "";
386 if (isset($_SESSION['errors']) && $_SESSION['errors'] != ""){
387   $focus= '<script language="JavaScript" type="text/javascript">';
388   $focus.= 'document.forms[0].error_accept.focus();';
389   $focus.= '</script>';
391 $smarty->assign("focus", $focus);
393 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
395 if ((isset($config->data['MAIN']['W3CTEST']) && preg_match('/true/i', $config->data['MAIN']['W3CTEST']))&&(!empty($display))&&(is_callable("tidy_parse_string"))) {
396   tidy_parse_string(utf8_decode($display));
397   $err = nl2br(htmlentities(tidy_get_error_buffer()));
398   
399   if($err){
400     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;'>";
401     echo $err."</div>";
402   }
404   tidy_clean_repair($display);
407 /* Show page... */
408 echo $display;
410 /* Save plist and config */
411 $_SESSION['plist']= $plist;
412 $_SESSION['config']= $config;
415 /* Echo compilation time * /
416 $r = split(" ",$start);
417 $ms = $r[0];
418 $s= $r[1];
420 $re = split(" ",microtime());
421 $mse = $re[0];
422 $se= $re[1];
424 $add = 0;
425 if(($mse -$ms)<0){
426   $se --;
427   $add = 1;
429 echo ($se -$s).",";
430 echo (int)(($add+($mse -$ms))*1000)." s";
431 */
432 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
433 ?>