Code

Updated update-gosa
[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");
28 /* Set header */
29 header("Content-type: text/html; charset=UTF-8");
31 /* Set the text domain as 'messages' */
32 $domain = 'messages';
33 bindtextdomain($domain, LOCALE_DIR);
34 textdomain($domain);
36 /* Remember everything we did after the last click */
37 session::start();
38 session::set('limit_exceeded',FALSE);
40 if ($_SERVER["REQUEST_METHOD"] == "POST"){
41   @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
42 }
43 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, session::get_all(), "_SESSION");
45 /* Logged in? Simple security check */
46 if (!session::is_set('config')){
47   new log("security","login","",array(),"main.php called without session - logging out") ;
48   header ("Location: logout.php");
49   exit;
50
52 /* Check for uniqe ip address */
53 $ui= session::get('ui');
54 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
55   new log("security","login","",array(),"main.php called with session which has a changed IP address.") ;
56   header ("Location: logout.php");
57   exit;
58 }
59 $config= session::get('config');
60 $config->check_and_reload();
62 /* Enable compressed output */
63 if (isset($config->data['MAIN']['COMPRESSED']) && preg_match('/^(true|on)$/i', $config->data['MAIN']['COMPRESSED'])){
64   ob_start("ob_gzhandler");
65 }
67 /* Check for invalid sessions */
68 if(session::get('_LAST_PAGE_REQUEST') == ""){
69   session::set('_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::get('_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::destroy();
87     new log("security","login","",array(),"main.php called without session - logging out") ;
88     header ("Location: logout.php");
89     exit;
90   }
91   session::set('_LAST_PAGE_REQUEST',time());
92 }
95 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
97 /* Set template compile directory */
98 if (isset ($config->data['MAIN']['COMPILE'])){
99   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
100 } else {
101   $smarty->compile_dir= '/var/spool/gosa/';
104 /* Set default */
105 $reload_navigation = false;
107 /* Set last initialised language to current, browser settings */
108 if(!session::is_set('Last_init_lang')){
109   $reload_navigation = true;
110   session::set('Last_init_lang',get_browser_language());
113 /* If last language != current force navi reload */
114 $lang= get_browser_language();
115 if(session::get('Last_init_lang') != $lang){
116   $reload_navigation = true;
119 /* Language setup */
120 session::set('Last_init_lang',$lang);
122 /* Preset current main base */
123 if(!session::is_set('CurrentMainBase')){
124   session::set('CurrentMainBase',get_base_from_people($ui->dn));
127 putenv("LANGUAGE=");
128 putenv("LANG=$lang");
129 setlocale(LC_ALL, $lang);
130 $GLOBALS['t_language']= $lang;
131 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
133 /* Set the text domain as 'messages' */
134 $domain = 'messages';
135 bindtextdomain($domain, LOCALE_DIR);
136 textdomain($domain);
137 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
139 /* Prepare plugin list */
140 if (!session::is_set('plist')){
141   /* Initially load all classes */
142   $class_list= get_declared_classes();
143   foreach ($class_mapping as $class => $path){
144     if (!in_array($class, $class_list)){
145         if (is_readable("$BASE_DIR/$path")){
146                 require_once("$BASE_DIR/$path");
147         } else {
148                 echo sprintf(_("Fatal error: cannot locate file '%s' - please run '%s' to fix this"), "$BASE_DIR/$path", "<b>update-gosa</b>");
149                 exit;
150         }
151     }
152   }
153   
154   session::set('plist', new pluglist($config, $ui));
156   /* Load ocMapping into userinfo */
157   $tmp= new acl($config, NULL, $ui->dn);
158   $ui->ocMapping= $tmp->ocMapping;
159   session::set('ui',$ui);
161 $plist= session::get('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   new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
167   session::destroy ();
168   exit ();
171 /* Check Plugin variable */
172 if (session::is_set('plugin_dir')){
173   $old_plugin_dir= session::get('plugin_dir');
174 } else {
175   $old_plugin_dir= "";
177 if (isset($_GET['plug'])){
178   $plug= validate($_GET['plug']);
179   $plugin_dir= $plist->get_path($plug);
180   session::set('plugin_dir',$plugin_dir);
181   if ($plugin_dir == ""){
182     new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
183     header ("Location: logout.php");
184     exit;
185   }
186 } else {
188   /* set to welcome page as default plugin */
189   session::set('plugin_dir',"welcome");
190   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
193 /* Check if we need to delete a lock */
194 if ($old_plugin_dir != $plugin_dir){
195   if (is_file("$old_plugin_dir/main.inc")){
196     $remove_lock= true;
197     require_once ("$old_plugin_dir/main.inc");
198   }
200 $remove_lock= false;
202 /* Check for sizelimits */
203 eval_sizelimit();
205 /* Check for memory */
206 if (function_exists("memory_get_usage")){
207   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
208     msg_dialog::display(_("Configuration warning"), _("Running out of memory!"), WARNING_DIALOG);
209   }
212 /* Redirect on back event */
213 if ($_SERVER["REQUEST_METHOD"] == "POST"){
215   /* Look for button events that match /^back[0-9]+$/,
216      extract the number and step the correct plugin. */
217   foreach ($_POST as $key => $value){
218     if (preg_match("/^back[0-9]+$/", $key)){
219       $back= substr($key, 4);
220       header ("Location: main.php?plug=$back");
221       exit;
222     }
223   }
226 /* Redirect on password back event */
227 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
228   header ("Location: main.php");
229   exit;
232 /* Check for multiple windows logout */
233 if ($_SERVER["REQUEST_METHOD"] == "POST"){
234   if (isset($_POST['reset_session'])){
235     header ("Location: logout.php");
236     exit;
237   }
239   if (isset($_POST['cancel_lock'])){
240     session::un_set('dn');
241   }
245 /* Load department list when plugin has changed. That is some kind of
246    compromise between speed and beeing up to date */
247 if (isset($_GET['reset'])){
248   if (session::is_set('objectinfo')){
249     session::un_set('objectinfo');
250   }
253 /* Install eGOsa hooks, convert _POST to session */
254 if(isset($_GET['explorer'])){
255   session::set('eGosa',TRUE);
257 if(session::is_set('POST')){
258   $_SERVER["REQUEST_METHOD"] = "POST";
259   foreach (session::get('POST') as $key => $dummy){
260     $_POST[$key]= $dummy;
261   }
262   session::un_set('POST');
265 /* show web frontend */
266 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
267 $smarty->assign ("must", "<font class=\"must\">*</font>");
268 if (isset($plug)){
269   $plug= "?plug=$plug";
270 } else {
271   $plug= "";
273 if (session::get('js')==FALSE){
274   $smarty->assign("javascript", "false");
275   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
276 } else {
277   $smarty->assign("javascript", "true");
278   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
281 $smarty->assign ("username", $ui->username);
282 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
283 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
284 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
285 $smarty->assign ("go_out", get_template_path('images/stop.png'));
286 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
287 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
288 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
289 $smarty->assign ("go_help", get_template_path('images/help.png'));
291 /* reload navigation if language changed*/  
292 if($reload_navigation){
293   $plist->menu="";
295 $plist->gen_headlines();
296 $plist->gen_menu();
297 $smarty->assign ("menu", $plist->menu);
298 $smarty->assign ("plug", "$plug");
300 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
302 /* React on clicks */
303 if ($_SERVER["REQUEST_METHOD"] == "POST"){
305   /* 'delete_lock' is set by the lock removal dialog. We should remove the
306      lock at this point globally. Plugins do not need to remove it. */
307   if (isset($_POST['delete_lock']) && session::is_set('dn')){
308     del_lock (session::get('dn'));
310     /* Set old Post data */
311     if(session::is_set('LOCK_VARS_USED')){
312       foreach(session::get('LOCK_VARS_USED') as $name => $value){
313         $_GET[$name]  = $value;
314         $_POST[$name] = $value;
315       } 
316     }
317     session::un_set ('dn');
318   }
321   /* I don't want multiple browser windows open. One way to check it is
322      to count a hidden field and warn the user if SESSION and INPUT count
323      differ. */
324   if (isset($_POST['session_cnt'])){
325     if ($_POST['session_cnt'] != session::get('session_cnt')){
326       $smarty->display(get_template_path('conflict.tpl'));
327       exit ();
328     }
329     session::set('session_cnt', (session::get('session_cnt') + 1));
330     session::set('post_cnt' , validate($_POST['session_cnt']) + 1);
331   }
334 /* Only generate hidden click counter, if post_cnt is defined */
335 if (session::is_set('post_cnt')){
336   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".session::get('post_cnt')."\">\n";
339 /* check if we are using account expiration */
340 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
341     preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
343   $expired= ldap_expired_account($config, $ui->dn, $ui->username);
345   if ($expired == 2){
346     new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
347     msg_dialog::display(_("Password reminder"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
348   }
351 /* Load plugin */
352 if (is_file("$plugin_dir/main.inc")){
353   require_once ("$plugin_dir/main.inc");
354 } else {
355   echo sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug);
356   exit();
360 /* Print_out last ErrorMessage repeated string. */
361 if(isset($_GET['add'])){
362 msg_dialog::display("Error"   ,"Kann datei nicht schreiben, bla",ERROR_DIALOG);
363 msg_dialog::display("Warning" ,"Kann datei nicht schreiben, bla",WARNING_DIALOG);
364 msg_dialog::display("Info"    ,"Kann datei nicht schreiben, bla",INFO_DIALOG);
365 msg_dialog::display("Confirm" ,"Kann datei nicht schreiben, bla",CONFIRM_DIALOG);
368 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
369 $smarty->assign("contents", $display);
371 /* Assign erros to smarty */
372 if (session::is_set('errors')){
373   $smarty->assign("errors", session::get('errors'));
375 if ($error_collector != ""){
376   $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
377 } else {
378   $smarty->assign("php_errors", "");
381 /* Set focus to the error button if we've an error message */
382 $focus= "";
383 if (session::is_set('errors') && session::get('errors') != ""){
384   $focus= '<script language="JavaScript" type="text/javascript">';
385   $focus.= 'document.forms[0].error_accept.focus();';
386   $focus.= '</script>';
389 $focus= '<script language="JavaScript" type="text/javascript">';
390 $focus.= 'next_msg_dialog();';
391 $focus.= '</script>';
392 $smarty->assign("focus", $focus);
394 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
396 /* Save dialog filters and selected base in a cookie. 
397    So we may be able to restore the filter an base settings on reload.
398 */
399 $cookie = array();
401 if(isset($_COOKIE['GOsa_Filter_Settings'])){
402   $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
403 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
404   $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
406 if(isset($config->data['MAIN']['SAVE_FILTER']) && preg_match("/true/",$config->data['MAIN']['SAVE_FILTER'])){
407   $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
408   foreach($cookie_vars as $var){
409     if(session::is_set($var)){
410       $cookie[$ui->dn][$var] = session::get($var);
411     }
412   }
413   if(isset($_GET['plug'])){
414     $cookie[$ui->dn]['plug'] = $_GET['plug'];
415   }
416   @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
419 /* Show page... */
420 echo $display;
422 /* Save plist and config */
423 session::set('plist',$plist);
424 session::set('config',$config);
425 session::set('errorsAlreadyPosted',array());
427 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
428 ?>