Code

745a2d2d79994fe5407b9a2da70852befaad9113
[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 /* Enable compressed output */
80 if (isset($config->data['MAIN']['COMPRESSED']) && preg_match('/^(true|on)$/i', $config->data['MAIN']['COMPRESSED'])){
81   ob_start("ob_gzhandler");
82 }
84 /* Check for invalid sessions */
85 if(empty($_SESSION['_LAST_PAGE_REQUEST'])){
86   $_SESSION['_LAST_PAGE_REQUEST']= time();
87 }else{
89   /* check GOsa.conf for defined session lifetime */
90   if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
91     $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
92   }else{
93     $max_life = 60*60*2;
94   }
96   /* get time difference between last page reload */
97   $request_time = (time()-$_SESSION['_LAST_PAGE_REQUEST']);
99   /* If page wasn't reloaded for more than max_life seconds 
100    * kill session
101    */
102   if($request_time > $max_life){
103     session_unset();
104     new log("security","login","",array(),"main.php called without session - logging out") ;
105     header ("Location: logout.php");
106     exit;
107   }
108   $_SESSION['_LAST_PAGE_REQUEST'] = time();
112 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
114 /* Set template compile directory */
115 if (isset ($config->data['MAIN']['COMPILE'])){
116   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
117 } else {
118   $smarty->compile_dir= '/var/spool/gosa/';
121 /* Set default */
122 $reload_navigation = false;
124 /* Set last initialised language to current, browser settings */
125 if((!isset($_SESSION['Last_init_lang']))){
126   $reload_navigation = true;
127   $_SESSION['Last_init_lang'] = get_browser_language();
130 /* If last language != current force navi reload */
131 $lang= get_browser_language();
132 if($_SESSION['Last_init_lang'] != $lang){
133   $reload_navigation = true;
136 /* Language setup */
137 $_SESSION['Last_init_lang'] = $lang;
139 /* Preset current main base */
140 if(!isset($_SESSION['CurrentMainBase'])){
141   $_SESSION['CurrentMainBase']= get_base_from_people($ui->dn);
144 putenv("LANGUAGE=");
145 putenv("LANG=$lang");
146 setlocale(LC_ALL, $lang);
147 $GLOBALS['t_language']= $lang;
148 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
150 /* Set the text domain as 'messages' */
151 $domain = 'messages';
152 bindtextdomain($domain, "$BASE_DIR/locale");
153 textdomain($domain);
154 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
156 /* Prepare plugin list */
157 if (!isset($_SESSION['plist'])){
158   /* Initially load all classes */
159   $class_list= get_declared_classes();
160   foreach ($class_mapping as $class => $path){
161     if (!in_array($class, $class_list)){
162         require_once("$BASE_DIR/$path");
163     }
164   }
165   
166   $_SESSION['plist']= new pluglist($config, $ui);
168   /* Load ocMapping into userinfo */
169   $tmp= new acl($config, NULL, $ui->dn);
170   $ui->ocMapping= $tmp->ocMapping;
171   $_SESSION['ui']= $ui;
173 $plist= $_SESSION['plist'];
175 /* Check for register globals */
176 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
177   echo _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator.");
178   new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
179   session_destroy ();
180   exit ();
183 /* Check Plugin variable */
184 if (isset($_SESSION['plugin_dir'])){
185   $old_plugin_dir= $_SESSION['plugin_dir'];
186 } else {
187   $old_plugin_dir= "";
189 if (isset($_GET['plug'])){
190   $plug= validate($_GET['plug']);
191   $plugin_dir= $plist->get_path($plug);
192   $_SESSION['plugin_dir']= $plugin_dir;
193   if ($plugin_dir == ""){
194     new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
195     header ("Location: logout.php");
196     exit;
197   }
198 } else {
199   /* set to welcome page as default plugin */
200   $_SESSION['plugin_dir']= "welcome";
201   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
204 /* Check if we need to delete a lock */
205 if ($old_plugin_dir != $plugin_dir){
206   if (is_file("$old_plugin_dir/main.inc")){
207     $remove_lock= true;
208     require_once ("$old_plugin_dir/main.inc");
209   }
211 $remove_lock= false;
213 /* Check for sizelimits */
214 eval_sizelimit();
216 /* Check for memory */
217 if (function_exists("memory_get_usage")){
218   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
219     print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
220   }
223 /* Redirect on back event */
224 if ($_SERVER["REQUEST_METHOD"] == "POST"){
226   /* Look for button events that match /^back[0-9]+$/,
227      extract the number and step the correct plugin. */
228   foreach ($_POST as $key => $value){
229     if (preg_match("/^back[0-9]+$/", $key)){
230       $back= substr($key, 4);
231       header ("Location: main.php?plug=$back");
232       exit;
233     }
234   }
237 /* Redirect on password back event */
238 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
239   header ("Location: main.php");
240   exit;
243 /* Check for multiple windows logout */
244 if ($_SERVER["REQUEST_METHOD"] == "POST"){
245   if (isset($_POST['reset_session'])){
246     header ("Location: logout.php");
247     exit;
248   }
250   if (isset($_POST['cancel_lock'])){
251     unset ($_SESSION['dn']);
252   }
256 /* Load department list when plugin has changed. That is some kind of
257    compromise between speed and beeing up to date */
258 if (isset($_GET['reset'])){
259   if (isset($_SESSION['objectinfo'])){
260     unset ($_SESSION['objectinfo']);
261   }
264 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
265 if(isset($_GET['explorer'])){
266   $_SESSION{'eGosa'}=1;
268 if(isset($_SESSION['POST'])){
269   $_SERVER["REQUEST_METHOD"] = "POST";
270   foreach ($_SESSION['POST'] as $key => $dummy){
271     $_POST[$key]=$_SESSION['POST'][$key];
272   }
273   unset($_SESSION['POST']);
276 /* show web frontend */
277 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
278 $smarty->assign ("must", "<font class=\"must\">*</font>");
279 if (isset($plug)){
280   $plug= "?plug=$plug";
281 } else {
282   $plug= "";
284 if ($_SESSION['js']==FALSE){
285   $smarty->assign("javascript", "false");
286   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
287 } else {
288   $smarty->assign("javascript", "true");
289   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
292 $smarty->assign ("username", $ui->username);
293 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
294 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
295 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
296 $smarty->assign ("go_out", get_template_path('images/stop.png'));
297 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
298 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
299 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
300 $smarty->assign ("go_help", get_template_path('images/help.png'));
302 /* reload navigation if language changed*/  
303 if($reload_navigation){
304   $plist->menu="";;
306 $plist->gen_headlines();
307 $plist->gen_menu();
308 $smarty->assign ("menu", $plist->menu);
309 $smarty->assign ("plug", "$plug");
311 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
313 /* React on clicks */
314 if ($_SERVER["REQUEST_METHOD"] == "POST"){
316   /* 'delete_lock' is set by the lock removal dialog. We should remove the
317      lock at this point globally. Plugins do not need to remove it. */
318   if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
319     del_lock ($_SESSION['dn']);
321     /* Set old Post data */
322     if(isset($_SESSION['LOCK_VARS_USED'])){
323       foreach($_SESSION['LOCK_VARS_USED'] as $name => $value){
324         $_GET[$name]  = $value;
325         $_POST[$name] = $value;
326       } 
327     }
328     sess_del ('dn');
329   }
332   /* I don't want multiple browser windows open. One way to check it is
333      to count a hidden field and warn the user if SESSION and INPUT count
334      differ. */
335   if (isset($_POST['session_cnt'])){
336     if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
337       $smarty->display(get_template_path('conflict.tpl'));
338       exit ();
339     }
340     $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
341     $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
342   }
345 /* Only generate hidden click counter, if post_cnt is defined */
346 if (isset ($_SESSION['post_cnt'])){
347   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
350 /* check if we are using account expiration */
351 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
352     preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
354   $expired= ldap_expired_account($config, $ui->dn, $ui->username);
356   if ($expired == 2){
357     new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
358     print_red(_("Your password is about to expire, please change your password"));
359   }
362 /* Load plugin */
363 if (is_file("$plugin_dir/main.inc")){
364   require_once ("$plugin_dir/main.inc");
365 } else {
366   echo sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug);
367   exit();
371 /* Print_out last ErrorMessage repeated string. */
372 if(isset($_GET['add'])){
373 msg_dialog::display("Error"   ,"Kann datei nicht schreiben, bla",ERROR_DIALOG);
374 msg_dialog::display("Warning" ,"Kann datei nicht schreiben, bla",WARNING_DIALOG);
375 msg_dialog::display("Info"    ,"Kann datei nicht schreiben, bla",INFO_DIALOG);
376 msg_dialog::display("Confirm" ,"Kann datei nicht schreiben, bla",CONFIRM_DIALOG);
379 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
380 $smarty->assign("contents", $display);
382 /* Assign erros to smarty */
383 if (isset($_SESSION['errors'])){
384   $smarty->assign("errors", $_SESSION['errors']);
386 if ($error_collector != ""){
387   $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
388 } else {
389   $smarty->assign("php_errors", "");
392 /* Set focus to the error button if we've an error message */
393 $focus= "";
394 if (isset($_SESSION['errors']) && $_SESSION['errors'] != ""){
395   $focus= '<script language="JavaScript" type="text/javascript">';
396   $focus.= 'document.forms[0].error_accept.focus();';
397   $focus.= '</script>';
400  $focus= '<script language="JavaScript" type="text/javascript">';
401   $focus.= 'next_msg_dialog();';
402   $focus.= '</script>';
405 $smarty->assign("focus", $focus);
407 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
409 /* Save dialog filters and selected base in a cookie. 
410    So we may be able to restore the filter an base settings on reload.
411 */
412 if(isset($config->data['MAIN']['SAVE_FILTER']) && preg_match("/true/",$config->data['MAIN']['SAVE_FILTER'])){
413   $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
414   foreach($cookie_vars as $var){
415     if(isset($_SESSION[$var])){
416       @setcookie($var,base64_encode(serialize($_SESSION[$var])),time()+ 60*60*24*30);
417     }
418   }
421 /* Show page... */
422 echo $display;
424 /* Save plist and config */
425 $_SESSION['plist']= $plist;
426 $_SESSION['config']= $config;
428 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
429 ?>