Code

f9c2cc6e7d93e4517ce3ad36fb592389b0ad034e
[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 /* Save start time */
22 $start = microtime();
24 /* Basic setup, remove eventually registered sessions */
25 require_once ("../include/php_setup.inc");
26 require_once ("functions.inc");
27 require_once ("functions_FAI.inc");
29 /* Set header */
30 header("Content-type: text/html; charset=UTF-8");
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   new log("security","login","",array(),"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   new log("security","login","",array(),"main.php called with session which has a changed IP address.") ;
74   header ("Location: logout.php");
75   exit;
76 }
77 $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     new log("security","login","",array(),"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 /* If last language != current force navi reload */
126 $lang= get_browser_language();
127 if($_SESSION['Last_init_lang'] != $lang){
128   $reload_navigation = true;
131 /* Language setup */
132 $_SESSION['Last_init_lang'] = $lang;
134 /* Preset current main base */
135 if(!isset($_SESSION['CurrentMainBase'])){
136   $_SESSION['CurrentMainBase']= get_base_from_people($ui->dn);
139 putenv("LANGUAGE=");
140 putenv("LANG=$lang");
141 setlocale(LC_ALL, $lang);
142 $GLOBALS['t_language']= $lang;
143 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
145 /* Set the text domain as 'messages' */
146 $domain = 'messages';
147 bindtextdomain($domain, "$BASE_DIR/locale");
148 textdomain($domain);
149 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
151 /* Prepare plugin list */
152 if (!isset($_SESSION['plist'])){
153   /* Initially load all classes */
154   $class_list= get_declared_classes();
155   foreach ($class_mapping as $class => $path){
156     if (!in_array($class, $class_list)){
157         require_once("$BASE_DIR/$path");
158     }
159   }
160   
161   $_SESSION['plist']= new pluglist($config, $ui);
163   /* Load ocMapping into userinfo */
164   $tmp= new acl($config, NULL, $ui->dn);
165   $ui->ocMapping= $tmp->ocMapping;
166   $_SESSION['ui']= $ui;
168 $plist= $_SESSION['plist'];
170 /* Check for register globals */
171 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
172   echo _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator.");
173   new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
174   session_destroy ();
175   exit ();
178 /* Check Plugin variable */
179 if (isset($_SESSION['plugin_dir'])){
180   $old_plugin_dir= $_SESSION['plugin_dir'];
181 } else {
182   $old_plugin_dir= "";
184 if (isset($_GET['plug'])){
185   $plug= validate($_GET['plug']);
186   $plugin_dir= $plist->get_path($plug);
187   $_SESSION['plugin_dir']= $plugin_dir;
188   if ($plugin_dir == ""){
189     new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
190     header ("Location: logout.php");
191     exit;
192   }
193 } else {
194   /* set to welcome page as default plugin */
195   $_SESSION['plugin_dir']= "welcome";
196   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
199 /* Check if we need to delete a lock */
200 if ($old_plugin_dir != $plugin_dir){
201   if (is_file("$old_plugin_dir/main.inc")){
202     $remove_lock= true;
203     require_once ("$old_plugin_dir/main.inc");
204   }
206 $remove_lock= false;
208 /* Check for sizelimits */
209 eval_sizelimit();
211 /* Check for memory */
212 if (function_exists("memory_get_usage")){
213   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
214     print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
215   }
218 /* Redirect on back event */
219 if ($_SERVER["REQUEST_METHOD"] == "POST"){
221   /* Look for button events that match /^back[0-9]+$/,
222      extract the number and step the correct plugin. */
223   foreach ($_POST as $key => $value){
224     if (preg_match("/^back[0-9]+$/", $key)){
225       $back= substr($key, 4);
226       header ("Location: main.php?plug=$back");
227       exit;
228     }
229   }
232 /* Redirect on password back event */
233 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
234   header ("Location: main.php");
235   exit;
238 /* Check for multiple windows logout */
239 if ($_SERVER["REQUEST_METHOD"] == "POST"){
240   if (isset($_POST['reset_session'])){
241     header ("Location: logout.php");
242     exit;
243   }
245   if (isset($_POST['cancel_lock'])){
246     unset ($_SESSION['dn']);
247   }
251 /* Load department list when plugin has changed. That is some kind of
252    compromise between speed and beeing up to date */
253 if (isset($_GET['reset'])){
254   if (isset($_SESSION['objectinfo'])){
255     unset ($_SESSION['objectinfo']);
256   }
259 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
260 if(isset($_GET['explorer'])){
261   $_SESSION{'eGosa'}=1;
263 if(isset($_SESSION['POST'])){
264   $_SERVER["REQUEST_METHOD"] = "POST";
265   foreach ($_SESSION['POST'] as $key => $dummy){
266     $_POST[$key]=$_SESSION['POST'][$key];
267   }
268   unset($_SESSION['POST']);
271 /* show web frontend */
272 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
273 $smarty->assign ("must", "<font class=\"must\">*</font>");
274 if (isset($plug)){
275   $plug= "?plug=$plug";
276 } else {
277   $plug= "";
279 if ($_SESSION['js']==FALSE){
280   $smarty->assign("javascript", "false");
281   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
282 } else {
283   $smarty->assign("javascript", "true");
284   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
287 $smarty->assign ("username", $ui->username);
288 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
289 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
290 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
291 $smarty->assign ("go_out", get_template_path('images/stop.png'));
292 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
293 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
294 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
295 $smarty->assign ("go_help", get_template_path('images/help.png'));
297 /* reload navigation if language changed*/  
298 if($reload_navigation){
299   $plist->menu="";;
301 $plist->gen_headlines();
302 $plist->gen_menu();
303 $smarty->assign ("menu", $plist->menu);
304 $smarty->assign ("plug", "$plug");
306 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
308 /* React on clicks */
309 if ($_SERVER["REQUEST_METHOD"] == "POST"){
311   /* 'delete_lock' is set by the lock removal dialog. We should remove the
312      lock at this point globally. Plugins do not need to remove it. */
313   if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
314     del_lock ($_SESSION['dn']);
316     /* Set old Post data */
317     if(isset($_SESSION['LOCK_VARS_USED'])){
318       foreach($_SESSION['LOCK_VARS_USED'] as $name => $value){
319         $_GET[$name]  = $value;
320         $_POST[$name] = $value;
321       } 
322     }
323     sess_del ('dn');
324   }
327   /* I don't want multiple browser windows open. One way to check it is
328      to count a hidden field and warn the user if SESSION and INPUT count
329      differ. */
330   if (isset($_POST['session_cnt'])){
331     if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
332       $smarty->display(get_template_path('conflict.tpl'));
333       exit ();
334     }
335     $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
336     $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
337   }
340 /* Only generate hidden click counter, if post_cnt is defined */
341 if (isset ($_SESSION['post_cnt'])){
342   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
345 /* check if we are using account expiration */
346 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
347     preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
349   $expired= ldap_expired_account($config, $ui->dn, $ui->username);
351   if ($expired == 2){
352     new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
353     print_red(_("Your password is about to expire, please change your password"));
354   }
357 /* Load plugin */
358 if (is_file("$plugin_dir/main.inc")){
359   require_once ("$plugin_dir/main.inc");
360 } else {
361   echo sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug);
362   exit();
366 /* Print_out last ErrorMessage repeated string. */
367 if(isset($_GET['add'])){
368 msg_dialog::display("Error"   ,"Kann datei nicht schreiben, bla",ERROR_DIALOG);
369 msg_dialog::display("Warning" ,"Kann datei nicht schreiben, bla",WARNING_DIALOG);
370 msg_dialog::display("Info"    ,"Kann datei nicht schreiben, bla",INFO_DIALOG);
371 msg_dialog::display("Confirm" ,"Kann datei nicht schreiben, bla",CONFIRM_DIALOG);
374 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
375 $smarty->assign("contents", $display);
377 /* Assign erros to smarty */
378 if (isset($_SESSION['errors'])){
379   $smarty->assign("errors", $_SESSION['errors']);
381 if ($error_collector != ""){
382   $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
383 } else {
384   $smarty->assign("php_errors", "");
387 /* Set focus to the error button if we've an error message */
388 $focus= "";
389 if (isset($_SESSION['errors']) && $_SESSION['errors'] != ""){
390   $focus= '<script language="JavaScript" type="text/javascript">';
391   $focus.= 'document.forms[0].error_accept.focus();';
392   $focus.= '</script>';
395  $focus= '<script language="JavaScript" type="text/javascript">';
396   $focus.= 'next_msg_dialog();';
397   $focus.= '</script>';
400 $smarty->assign("focus", $focus);
402 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
404 /* Save dialog filters and selected base in a cookie. 
405    So we may be able to restore the filter an base settings on reload.
406 */
407 if(isset($config->data['MAIN']['SAVE_FILTER']) && preg_match("/true/",$config->data['MAIN']['SAVE_FILTER'])){
408   $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
409   foreach($cookie_vars as $var){
410     if(isset($_SESSION[$var])){
411       @setcookie($var,base64_encode(serialize($_SESSION[$var])),time()+ 60*60*24*30);
412     }
413   }
416 /* Show page... */
417 echo $display;
419 /* Save plist and config */
420 $_SESSION['plist']= $plist;
421 $_SESSION['config']= $config;
423 /* Echo compilation time */
424 #echo "<p align='right'>".get_MicroTimeDiff($start,microtime())."</p>";
426 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
427 ?>