Code

d604d994b0992c797cd7e5462107d08e6e9289ea
[gosa.git] / gosa-core / 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 /* Remember everything we did after the last click */
38 restore_error_handler();
39 session::start();
40 session::set('limit_exceeded',FALSE);
42 if ($_SERVER["REQUEST_METHOD"] == "POST"){
43   @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
44 }
45 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, session::get_all(), "_SESSION");
47 /* Logged in? Simple security check */
48 if (!session::is_set('config')){
49   new log("security","login","",array(),"main.php called without session - logging out") ;
50   header ("Location: logout.php");
51   exit;
52
54 /* Check for uniqe ip address */
55 $ui= session::get('ui');
56 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
57   new log("security","login","",array(),"main.php called with session which has a changed IP address.") ;
58   header ("Location: logout.php");
59   exit;
60 }
61 $config= session::get('config');
62 $config->check_and_reload();
64 /* Enable compressed output */
65 if (isset($config->data['MAIN']['COMPRESSED']) && preg_match('/^(true|on)$/i', $config->data['MAIN']['COMPRESSED'])){
66   ob_start("ob_gzhandler");
67 }
69 /* Check for invalid sessions */
70 if(session::get('_LAST_PAGE_REQUEST') == ""){
71   session::set('_LAST_PAGE_REQUEST',time());
72 }else{
74   /* check GOsa.conf for defined session lifetime */
75   if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
76     $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
77   }else{
78     $max_life = 60*60*2;
79   }
81   /* get time difference between last page reload */
82   $request_time = (time()- session::get('_LAST_PAGE_REQUEST'));
84   /* If page wasn't reloaded for more than max_life seconds 
85    * kill session
86    */
87   if($request_time > $max_life){
88     session_unset();
89     new log("security","login","",array(),"main.php called without session - logging out") ;
90     header ("Location: logout.php");
91     exit;
92   }
93   session::set('_LAST_PAGE_REQUEST',time());
94 }
97 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
99 /* Set template compile directory */
100 if (isset ($config->data['MAIN']['COMPILE'])){
101   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
102 } else {
103   $smarty->compile_dir= '/var/spool/gosa/';
106 /* Set default */
107 $reload_navigation = false;
109 /* Set last initialised language to current, browser settings */
110 if(!session::is_set('Last_init_lang')){
111   $reload_navigation = true;
112   session::set('Last_init_lang',get_browser_language());
115 /* If last language != current force navi reload */
116 $lang= get_browser_language();
117 if(session::get('Last_init_lang',$lang)){
118   $reload_navigation = true;
121 /* Language setup */
122 session::set('Last_init_lang',$lang);
124 /* Preset current main base */
125 if(session::is_set('CurrentMainBase')){
126   session::set('CurrentMainBase',get_base_from_people($ui->dn));
129 putenv("LANGUAGE=");
130 putenv("LANG=$lang");
131 setlocale(LC_ALL, $lang);
132 $GLOBALS['t_language']= $lang;
133 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
135 /* Set the text domain as 'messages' */
136 $domain = 'messages';
137 bindtextdomain($domain, "$BASE_DIR/locale");
138 textdomain($domain);
139 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
141 /* Prepare plugin list */
142 if (!session::is_set('plist')){
143   /* Initially load all classes */
144   $class_list= get_declared_classes();
145   foreach ($class_mapping as $class => $path){
146     if (!in_array($class, $class_list)){
147         require_once("$BASE_DIR/$path");
148     }
149   }
150   
151   session::set('plist', new pluglist($config, $ui));
153   /* Load ocMapping into userinfo */
154   $tmp= new acl($config, NULL, $ui->dn);
155   $ui->ocMapping= $tmp->ocMapping;
156   session::set('ui',$ui);
158 $plist= session::get('plist');
160 /* Check for register globals */
161 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
162   echo _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator.");
163   new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
164   session_destroy ();
165   exit ();
168 /* Check Plugin variable */
169 if (session::is_set('plugin_dir')){
170   $old_plugin_dir= session::get('plugin_dir');
171 } else {
172   $old_plugin_dir= "";
174 if (isset($_GET['plug'])){
175   $plug= validate($_GET['plug']);
176   $plugin_dir= $plist->get_path($plug);
177   session::set('plugin_dir',$plugin_dir);
178   if ($plugin_dir == ""){
179     new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
180     header ("Location: logout.php");
181     exit;
182   }
183 } else {
185   /* set to welcome page as default plugin */
186   session::set('plugin_dir',"welcome");
187   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
190 /* Check if we need to delete a lock */
191 if ($old_plugin_dir != $plugin_dir){
192   if (is_file("$old_plugin_dir/main.inc")){
193     $remove_lock= true;
194     require_once ("$old_plugin_dir/main.inc");
195   }
197 $remove_lock= false;
199 /* Check for sizelimits */
200 eval_sizelimit();
202 /* Check for memory */
203 if (function_exists("memory_get_usage")){
204   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
205     print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
206   }
209 /* Redirect on back event */
210 if ($_SERVER["REQUEST_METHOD"] == "POST"){
212   /* Look for button events that match /^back[0-9]+$/,
213      extract the number and step the correct plugin. */
214   foreach ($_POST as $key => $value){
215     if (preg_match("/^back[0-9]+$/", $key)){
216       $back= substr($key, 4);
217       header ("Location: main.php?plug=$back");
218       exit;
219     }
220   }
223 /* Redirect on password back event */
224 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
225   header ("Location: main.php");
226   exit;
229 /* Check for multiple windows logout */
230 if ($_SERVER["REQUEST_METHOD"] == "POST"){
231   if (isset($_POST['reset_session'])){
232     header ("Location: logout.php");
233     exit;
234   }
236   if (isset($_POST['cancel_lock'])){
237     session::un_set('dn');
238   }
242 /* Load department list when plugin has changed. That is some kind of
243    compromise between speed and beeing up to date */
244 if (isset($_GET['reset'])){
245   if (session::is_set('objectinfo')){
246     session::un_set('objectinfo');
247   }
250 /* Install eGOsa hooks, convert _POST to session */
251 if(isset($_GET['explorer'])){
252   session::set('eGosa',TRUE);
254 if(session::is_set('POST')){
255   $_SERVER["REQUEST_METHOD"] = "POST";
256   foreach (session::get('POST') as $key => $dummy){
257     $_POST[$key]= $dummy;
258   }
259   session::un_set('POST');
262 /* show web frontend */
263 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
264 $smarty->assign ("must", "<font class=\"must\">*</font>");
265 if (isset($plug)){
266   $plug= "?plug=$plug";
267 } else {
268   $plug= "";
270 if (session::get('js')==FALSE){
271   $smarty->assign("javascript", "false");
272   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
273 } else {
274   $smarty->assign("javascript", "true");
275   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
278 $smarty->assign ("username", $ui->username);
279 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
280 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
281 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
282 $smarty->assign ("go_out", get_template_path('images/stop.png'));
283 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
284 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
285 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
286 $smarty->assign ("go_help", get_template_path('images/help.png'));
288 /* reload navigation if language changed*/  
289 if($reload_navigation){
290   $plist->menu="";;
292 $plist->gen_headlines();
293 $plist->gen_menu();
294 $smarty->assign ("menu", $plist->menu);
295 $smarty->assign ("plug", "$plug");
297 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
299 /* React on clicks */
300 if ($_SERVER["REQUEST_METHOD"] == "POST"){
302   /* 'delete_lock' is set by the lock removal dialog. We should remove the
303      lock at this point globally. Plugins do not need to remove it. */
304   if (isset($_POST['delete_lock']) && session::is_set('dn')){
305     del_lock (session::get('dn'));
307     /* Set old Post data */
308     if(session::is_set('LOCK_VARS_USED')){
309       foreach(session::get('LOCK_VARS_USED') as $name => $value){
310         $_GET[$name]  = $value;
311         $_POST[$name] = $value;
312       } 
313     }
314     sess_del ('dn');
315   }
318   /* I don't want multiple browser windows open. One way to check it is
319      to count a hidden field and warn the user if SESSION and INPUT count
320      differ. */
321   if (isset($_POST['session_cnt'])){
322     if ($_POST['session_cnt'] != session::get('session_cnt')){
323       $smarty->display(get_template_path('conflict.tpl'));
324       exit ();
325     }
326     session::set('session_cnt', (session::get('session_cnt') + 1));
327     session::set('post_cnt' , validate($_POST['session_cnt']) + 1);
328   }
331 /* Only generate hidden click counter, if post_cnt is defined */
332 if (session::is_set('post_cnt')){
333   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".session::get('post_cnt')."\">\n";
336 /* check if we are using account expiration */
337 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
338     preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
340   $expired= ldap_expired_account($config, $ui->dn, $ui->username);
342   if ($expired == 2){
343     new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
344     print_red(_("Your password is about to expire, please change your password"));
345   }
348 /* Load plugin */
349 if (is_file("$plugin_dir/main.inc")){
350   require_once ("$plugin_dir/main.inc");
351 } else {
352   echo sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug);
353   exit();
357 /* Print_out last ErrorMessage repeated string. */
358 if(isset($_GET['add'])){
359 msg_dialog::display("Error"   ,"Kann datei nicht schreiben, bla",ERROR_DIALOG);
360 msg_dialog::display("Warning" ,"Kann datei nicht schreiben, bla",WARNING_DIALOG);
361 msg_dialog::display("Info"    ,"Kann datei nicht schreiben, bla",INFO_DIALOG);
362 msg_dialog::display("Confirm" ,"Kann datei nicht schreiben, bla",CONFIRM_DIALOG);
365 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
366 $smarty->assign("contents", $display);
368 /* Assign erros to smarty */
369 if (session::is_set('errors')){
370   $smarty->assign("errors", session::get('errors'));
372 if ($error_collector != ""){
373   $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
374 } else {
375   $smarty->assign("php_errors", "");
378 /* Set focus to the error button if we've an error message */
379 $focus= "";
380 if (session::is_set('errors') && session::get('errors') != ""){
381   $focus= '<script language="JavaScript" type="text/javascript">';
382   $focus.= 'document.forms[0].error_accept.focus();';
383   $focus.= '</script>';
386 $focus= '<script language="JavaScript" type="text/javascript">';
387 $focus.= 'next_msg_dialog();';
388 $focus.= '</script>';
389 $smarty->assign("focus", $focus);
391 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
393 /* Save dialog filters and selected base in a cookie. 
394    So we may be able to restore the filter an base settings on reload.
395 */
396 $cookie = array();
398 if(isset($_COOKIE['GOsa_Filter_Settings'])){
399   $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
400 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
401   $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
403 if(isset($config->data['MAIN']['SAVE_FILTER']) && preg_match("/true/",$config->data['MAIN']['SAVE_FILTER'])){
404   $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
405   foreach($cookie_vars as $var){
406     if(session::is_set($var)){
407       $cookie[$ui->dn][$var] = session::get($var);
408     }
409   }
410   if(isset($_GET['plug'])){
411     $cookie[$ui->dn]['plug'] = $_GET['plug'];
412   }
413   @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
416 /* Show page... */
417 echo $display;
419 /* Save plist and config */
420 session::set('plist',$plist);
421 session::set('config',$config);
422 session::set('errorsAlreadyPosted',array());
424 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
425 ?>