Code

Updated object groups
[gosa.git] / gosa-core / html / main.php
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 /* Save start time */
24 $start = microtime();
26 /* Basic setup, remove eventually registered sessions */
27 require_once ("../include/php_setup.inc");
28 require_once ("functions.inc");
30 /* Set header */
31 header("Content-type: text/html; charset=UTF-8");
33 /* Set the text domain as 'messages' */
34 $domain = 'messages';
35 bindtextdomain($domain, LOCALE_DIR);
36 textdomain($domain);
38 /* Remember everything we did after the last click */
39 session::start();
40 session::set('errorsAlreadyPosted',array());
41 session::set('runtime_cache',array());
42 session::set('limit_exceeded',FALSE);
44 if ($_SERVER["REQUEST_METHOD"] == "POST"){
45   @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
46 }
47 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, session::get_all(), "_SESSION");
49 /* Logged in? Simple security check */
50 if (!session::is_set('config')){
51   new log("security","login","",array(),"main.php called without session - logging out") ;
52   header ("Location: logout.php");
53   exit;
54
56 /* Check for uniqe ip address */
57 $ui= session::get('ui');
58 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
59   new log("security","login","",array(),"main.php called with session which has a changed IP address.") ;
60   header ("Location: logout.php");
61   exit;
62 }
63 $config= session::get('config');
64 $config->check_and_reload();
66 /* Enable compressed output */
67 if (isset($config->data['MAIN']['COMPRESSED']) && preg_match('/^(true|on)$/i', $config->data['MAIN']['COMPRESSED']) && !isset($_GET['no_output_compression'])){
68   ob_start("ob_gzhandler");
69 }
71 /* Check for invalid sessions */
72 if(session::get('_LAST_PAGE_REQUEST') == ""){
73   session::set('_LAST_PAGE_REQUEST',time());
74 }else{
76   /* check GOsa.conf for defined session lifetime */
77   if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
78     $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
79   }else{
80     $max_life = 60*60*2;
81   }
83   /* get time difference between last page reload */
84   $request_time = (time()- session::get('_LAST_PAGE_REQUEST'));
86   /* If page wasn't reloaded for more than max_life seconds 
87    * kill session
88    */
89   if($request_time > $max_life){
90     session::destroy();
91     new log("security","login","",array(),"main.php called without session - logging out") ;
92     header ("Location: logout.php");
93     exit;
94   }
95   session::set('_LAST_PAGE_REQUEST',time());
96 }
99 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
101 /* Set template compile directory */
102 if (isset ($config->data['MAIN']['COMPILE'])){
103   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
104 } else {
105   $smarty->compile_dir= '/var/spool/gosa/';
108 /* Set default */
109 $reload_navigation = false;
111 /* Set last initialised language to current, browser settings */
112 if(!session::is_set('Last_init_lang')){
113   $reload_navigation = true;
114   session::set('Last_init_lang',get_browser_language());
117 /* If last language != current force navi reload */
118 $lang= get_browser_language();
119 if(session::get('Last_init_lang') != $lang){
120   $reload_navigation = true;
123 /* Language setup */
124 session::set('Last_init_lang',$lang);
126 /* Preset current main base */
127 if(!session::is_set('CurrentMainBase')){
128   session::set('CurrentMainBase',get_base_from_people($ui->dn));
131 putenv("LANGUAGE=");
132 putenv("LANG=$lang");
133 setlocale(LC_ALL, $lang);
134 $GLOBALS['t_language']= $lang;
135 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
137 /* Set the text domain as 'messages' */
138 $domain = 'messages';
139 bindtextdomain($domain, LOCALE_DIR);
140 textdomain($domain);
141 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
143 /* Prepare plugin list */
144 if (!session::is_set('plist')){
145   /* Initially load all classes */
146   $class_list= get_declared_classes();
147   foreach ($class_mapping as $class => $path){
148     if (!in_array($class, $class_list)){
149       if (is_readable("$BASE_DIR/$path")){
150         require_once("$BASE_DIR/$path");
151       } else {
152         msg_dialog::display(_("Fatal error"),
153             sprintf(_("Cannot locate file '%s' - please run '%s' to fix this"),
154               "$BASE_DIR/$path", "<b>update-gosa</b>"), FATAL_ERROR_DIALOG);
155         exit;
156       }
157     }
158   }
160   session::set('plist', new pluglist($config, $ui));
162   /* Load ocMapping into userinfo */
163   $tmp= new acl($config, NULL, $ui->dn);
164   $ui->ocMapping= $tmp->ocMapping;
165   session::set('ui',$ui);
167 $plist= session::get('plist');
168 /* Check for register globals */
169 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
170   msg_dialog::display(
171             _("PHP configuration"),
172             _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."),
173             FATAL_ERROR_DIALOG);
175   new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
176   session::destroy ();
177   exit;
180 /* Check Plugin variable */
181 if (session::is_set('plugin_dir')){
182   $old_plugin_dir= session::get('plugin_dir');
183 } else {
184   $old_plugin_dir= "";
186 if (isset($_GET['plug'])){
187   $plug= validate($_GET['plug']);
188   $plugin_dir= $plist->get_path($plug);
189   session::set('plugin_dir',$plugin_dir);
190   if ($plugin_dir == ""){
191     new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
192     header ("Location: logout.php");
193     exit;
194   }
195 } else {
197   /* set to welcome page as default plugin */
198   session::set('plugin_dir',"welcome");
199   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
202 /* Check if we need to delete a lock */
203 if ($old_plugin_dir != $plugin_dir){
204   if (is_file("$old_plugin_dir/main.inc")){
205     $remove_lock= true;
206     require_once ("$old_plugin_dir/main.inc");
207   }
209 $remove_lock= false;
211 /* Check for sizelimits */
212 eval_sizelimit();
214 /* Check for memory */
215 if (function_exists("memory_get_usage")){
216   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
217     msg_dialog::display(_("Configuration error"), _("Running out of memory!"), WARNING_DIALOG);
218   }
221 /* Redirect on back event */
222 if ($_SERVER["REQUEST_METHOD"] == "POST"){
224   /* Look for button events that match /^back[0-9]+$/,
225      extract the number and step the correct plugin. */
226   foreach ($_POST as $key => $value){
227     if (preg_match("/^back[0-9]+$/", $key)){
228       $back= substr($key, 4);
229       header ("Location: main.php?plug=$back");
230       exit;
231     }
232   }
235 /* Redirect on password back event */
236 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
237   header ("Location: main.php");
238   exit;
241 /* Check for multiple windows logout */
242 if ($_SERVER["REQUEST_METHOD"] == "POST"){
243   if (isset($_POST['reset_session'])){
244     header ("Location: logout.php");
245     exit;
246   }
248   if (isset($_POST['cancel_lock'])){
249     session::un_set('dn');
250   }
254 /* Load department list when plugin has changed. That is some kind of
255    compromise between speed and beeing up to date */
256 if (isset($_GET['reset'])){
257   if (session::is_set('objectinfo')){
258     session::un_set('objectinfo');
259   }
262 /* Install eGOsa hooks, convert _POST to session */
263 if(isset($_GET['explorer'])){
264   session::set('eGosa',TRUE);
266 if(session::is_set('POST')){
267   $_SERVER["REQUEST_METHOD"] = "POST";
268   foreach (session::get('POST') as $key => $dummy){
269     $_POST[$key]= $dummy;
270   }
271   session::un_set('POST');
274 /* show web frontend */
275 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
276 $smarty->assign ("must", "<font class=\"must\">*</font>");
277 if (isset($plug)){
278   $plug= "?plug=$plug";
279 } else {
280   $plug= "";
282 if (session::get('js')==FALSE){
283   $smarty->assign("javascript", "false");
284   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
285 } else {
286   $smarty->assign("javascript", "true");
287   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
290 $smarty->assign ("username", $ui->username);
291 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
292 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
293 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
294 $smarty->assign ("go_out", get_template_path('images/logout.png'));
295 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
296 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
297 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
298 $smarty->assign ("go_help", get_template_path('images/help.png'));
300 /* reload navigation if language changed*/  
301 if($reload_navigation){
302   $plist->menu="";
304 $plist->gen_headlines();
305 $plist->gen_menu();
306 $smarty->assign ("menu", $plist->menu);
307 $smarty->assign ("plug", "$plug");
309 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
311 /* React on clicks */
312 if ($_SERVER["REQUEST_METHOD"] == "POST"){
314   /* 'delete_lock' is set by the lock removal dialog. We should remove the
315      lock at this point globally. Plugins do not need to remove it. */
316   if (isset($_POST['delete_lock']) && session::is_set('dn')){
317     del_lock (session::get('dn'));
319     /* Set old Post data */
320     if(session::is_set('LOCK_VARS_USED')){
321       foreach(session::get('LOCK_VARS_USED') as $name => $value){
322         $_GET[$name]  = $value;
323         $_POST[$name] = $value;
324       } 
325     }
326     session::un_set ('dn');
327   }
330   /* I don't want multiple browser windows open. One way to check it is
331      to count a hidden field and warn the user if SESSION and INPUT count
332      differ. */
333   if (isset($_POST['session_cnt'])){
334     if ($_POST['session_cnt'] != session::get('session_cnt')){
335       $smarty->display(get_template_path('conflict.tpl'));
336       exit ();
337     }
338     session::set('session_cnt', (session::get('session_cnt') + 1));
339     session::set('post_cnt' , validate($_POST['session_cnt']) + 1);
340   }
343 /* Only generate hidden click counter, if post_cnt is defined */
344 if (session::is_set('post_cnt')){
345   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".session::get('post_cnt')."\">\n";
348 /* check if we are using account expiration */
349 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
350     preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
352   $expired= ldap_expired_account($config, $ui->dn, $ui->username);
354   if ($expired == 2){
355     new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
356     msg_dialog::display(_("Password change"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
357   }
360 /* Load plugin */
361 if (is_file("$plugin_dir/main.inc")){
362   require_once ("$plugin_dir/main.inc");
363 } else {
364   msg_dialog::display(
365             _("Plugin"),
366             sprintf(_("FATAL: Cannot find any plugin definitions for plugin '%s'!"), $plug),
367             FATAL_ERROR_DIALOG);
368   exit();
372 /* Print_out last ErrorMessage repeated string. */
373 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
374 $smarty->assign("contents", $display);
376 /* Assign erros to smarty */
377 if (session::is_set('errors')){
378   $smarty->assign("errors", session::get('errors'));
380 if ($error_collector != ""){
381   $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
382 } else {
383   $smarty->assign("php_errors", "");
386 /* Set focus to the error button if we've an error message */
387 $focus= "";
388 if (session::is_set('errors') && session::get('errors') != ""){
389   $focus= '<script language="JavaScript" type="text/javascript">';
390   $focus.= 'document.forms[0].error_accept.focus();';
391   $focus.= '</script>';
394 $focus= '<script language="JavaScript" type="text/javascript">';
395 $focus.= 'next_msg_dialog();';
396 $focus.= '</script>';
397 $smarty->assign("focus", $focus);
399 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
401 /* Save dialog filters and selected base in a cookie. 
402    So we may be able to restore the filter an base settings on reload.
403 */
404 $cookie = array();
406 if(isset($_COOKIE['GOsa_Filter_Settings'])){
407   $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
408 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
409   $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
411 if(isset($config->data['MAIN']['SAVE_FILTER']) && preg_match("/true/",$config->data['MAIN']['SAVE_FILTER'])){
412   $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
413   foreach($cookie_vars as $var){
414     if(session::is_set($var)){
415       $cookie[$ui->dn][$var] = session::get($var);
416     }
417   }
418   if(isset($_GET['plug'])){
419     $cookie[$ui->dn]['plug'] = $_GET['plug'];
420   }
421   @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
424 /* Show page... */
425 echo $display;
427 /* Save plist and config */
428 session::set('plist',$plist);
429 session::set('config',$config);
430 session::set('errorsAlreadyPosted',array());
432 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
433 ?>