Code

Added branches container for old stuff
[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_config_version();
65 $config->check_and_reload();
67 /* Enable compressed output */
68 if ($config->get_cfg_value("compressed") == "true"){
69   ob_start("ob_gzhandler");
70 }
72 /* Check for invalid sessions */
73 if(session::get('_LAST_PAGE_REQUEST') == ""){
74   session::set('_LAST_PAGE_REQUEST',time());
75 }else{
77   /* check GOsa.conf for defined session lifetime */
78   $max_life= $config->get_cfg_value("session_lifetime", 60*60*2);
80   /* get time difference between last page reload */
81   $request_time = (time()- session::get('_LAST_PAGE_REQUEST'));
83   /* If page wasn't reloaded for more than max_life seconds 
84    * kill session
85    */
86   if($request_time > $max_life){
87     session::destroy();
88     new log("security","login","",array(),"main.php called without session - logging out") ;
89     header ("Location: logout.php");
90     exit;
91   }
92   session::set('_LAST_PAGE_REQUEST',time());
93 }
96 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
98 /* Set template compile directory */
99 $smarty->compile_dir= $config->get_cfg_value("compile", '/var/spool/gosa');
101 /* Set default */
102 $reload_navigation = false;
104 /* Set last initialised language to current, browser settings */
105 if(!session::is_set('Last_init_lang')){
106   $reload_navigation = true;
107   session::set('Last_init_lang',get_browser_language());
110 /* If last language != current force navi reload */
111 $lang= get_browser_language();
112 if(session::get('Last_init_lang') != $lang){
113   $reload_navigation = true;
116 /* Language setup */
117 session::set('Last_init_lang',$lang);
119 /* Preset current main base */
120 if(!session::is_set('CurrentMainBase')){
121   session::set('CurrentMainBase',get_base_from_people($ui->dn));
124 putenv("LANGUAGE=");
125 putenv("LANG=$lang");
126 setlocale(LC_ALL, $lang);
127 $GLOBALS['t_language']= $lang;
128 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
130 /* Set the text domain as 'messages' */
131 $domain = 'messages';
132 bindtextdomain($domain, LOCALE_DIR);
133 textdomain($domain);
134 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
136 /* Prepare plugin list */
137 if (!session::is_set('plist')){
138   /* Initially load all classes */
139   $class_list= get_declared_classes();
140   foreach ($class_mapping as $class => $path){
141     if (!in_array($class, $class_list)){
142       if (is_readable("$BASE_DIR/$path")){
143         require_once("$BASE_DIR/$path");
144       } else {
145         msg_dialog::display(_("Fatal error"),
146             sprintf(_("Cannot locate file '%s' - please run '%s' to fix this"),
147               "$BASE_DIR/$path", "<b>update-gosa</b>"), FATAL_ERROR_DIALOG);
148         exit;
149       }
150     }
151   }
153   session::set('plist', new pluglist($config, $ui));
155   /* Load ocMapping into userinfo */
156   $tmp= new acl($config, NULL, $ui->dn);
157   $ui->ocMapping= $tmp->ocMapping;
158   session::set('ui',$ui);
160 $plist= session::get('plist');
162 /* Check for register globals */
163 if (isset($global_check) && $config->get_cfg_value("forceglobals") == "true"){
164   msg_dialog::display(
165             _("PHP configuration"),
166             _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."),
167             FATAL_ERROR_DIALOG);
169   new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
170   session::destroy ();
171   exit;
174 /* Check Plugin variable */
175 if (session::is_set('plugin_dir')){
176   $old_plugin_dir= session::get('plugin_dir');
177 } else {
178   $old_plugin_dir= "";
180 if (isset($_GET['plug']) && $plist->plugin_access_allowed($_GET['plug'])){
181   $plug= validate($_GET['plug']);
182   $plugin_dir= $plist->get_path($plug);
183   session::set('plugin_dir',$plugin_dir);
184   if ($plugin_dir == ""){
185     new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
186     header ("Location: logout.php");
187     exit;
188   }
189 } else {
191   /* set to welcome page as default plugin */
192   session::set('plugin_dir',"welcome");
193   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
196 /* Check if we need to delete a lock */
197 if ($old_plugin_dir != $plugin_dir && $old_plugin_dir != ""){
198   if (is_file("$old_plugin_dir/main.inc")){
199     $remove_lock= true;
200     require_once ("$old_plugin_dir/main.inc");
201   }
203 $remove_lock= false;
205 /* Check for sizelimits */
206 eval_sizelimit();
208 /* Check for memory */
209 if (function_exists("memory_get_usage")){
210   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
211     msg_dialog::display(_("Configuration error"), _("Running out of memory!"), WARNING_DIALOG);
212   }
215 /* Redirect on back event */
216 if ($_SERVER["REQUEST_METHOD"] == "POST"){
218   /* Look for button events that match /^back[0-9]+$/,
219      extract the number and step the correct plugin. */
220   foreach ($_POST as $key => $value){
221     if (preg_match("/^back[0-9]+$/", $key)){
222       $back= substr($key, 4);
223       header ("Location: main.php?plug=$back");
224       exit;
225     }
226   }
229 /* Redirect on password back event */
230 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
231   header ("Location: main.php");
232   exit;
235 /* Check for multiple windows logout */
236 if ($_SERVER["REQUEST_METHOD"] == "POST"){
237   if (isset($_POST['reset_session'])){
238     header ("Location: logout.php");
239     exit;
240   }
242   if (isset($_POST['cancel_lock'])){
243     session::un_set('dn');
244   }
248 /* Load department list when plugin has changed. That is some kind of
249    compromise between speed and beeing up to date */
250 if (isset($_GET['reset'])){
251   if (session::is_set('objectinfo')){
252     session::un_set('objectinfo');
253   }
256 /* Install eGOsa hooks, convert _POST to session */
257 if(isset($_GET['explorer'])){
258   session::set('eGosa',TRUE);
260 if(session::is_set('POST')){
261   $_SERVER["REQUEST_METHOD"] = "POST";
262   foreach (session::get('POST') as $key => $dummy){
263     $_POST[$key]= $dummy;
264   }
265   session::un_set('POST');
268 /* show web frontend */
269 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
270 $smarty->assign ("must", "<font class=\"must\">*</font>");
271 if (isset($plug)){
272   $plug= "?plug=$plug";
273 } else {
274   $plug= "";
276 if (session::get('js')==FALSE){
277   $smarty->assign("javascript", "false");
278   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
279 } else {
280   $smarty->assign("javascript", "true");
281   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
284 if($ui->ignore_acl_for_current_user()){
285   $smarty->assign ("username", "<font color='#FF0000';>"._("User ACL checks disabled")."</font>&nbsp;".$ui->username);
286 }else{
287   $smarty->assign ("username", $ui->username);
289 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
290 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
291 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
292 $smarty->assign ("go_out", get_template_path('images/logout.png'));
293 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
294 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
295 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
296 $smarty->assign ("go_help", get_template_path('images/help.png'));
298 /* reload navigation if language changed*/  
299 if($reload_navigation){
300   $plist->menu="";
302 $plist->gen_headlines();
303 $plist->gen_menu();
304 $smarty->assign ("menu", $plist->menu);
305 $smarty->assign ("plug", "$plug");
307 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
309 /* React on clicks */
310 if ($_SERVER["REQUEST_METHOD"] == "POST"){
312   /* 'delete_lock' is set by the lock removal dialog. We should remove the
313      lock at this point globally. Plugins do not need to remove it. */
314   if (isset($_POST['delete_lock']) && session::is_set('dn')){
315     del_lock (session::get('dn'));
317     /* Set old Post data */
318     if(session::is_set('LOCK_VARS_USED')){
319       foreach(session::get('LOCK_VARS_USED') as $name => $value){
320         $_GET[$name]  = $value;
321         $_POST[$name] = $value;
322       } 
323     }
324     session::un_set ('dn');
325   }
328   /* I don't want multiple browser windows open. One way to check it is
329      to count a hidden field and warn the user if SESSION and INPUT count
330      differ. */
331   if (isset($_POST['session_cnt'])){
332     if ($_POST['session_cnt'] != session::get('session_cnt')){
333       $smarty->display(get_template_path('conflict.tpl'));
334       exit ();
335     }
336     session::set('session_cnt', (session::get('session_cnt') + 1));
337     session::set('post_cnt' , validate($_POST['session_cnt']) + 1);
338   }
341 /* Only generate hidden click counter, if post_cnt is defined */
342 if (session::is_set('post_cnt')){
343   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".session::get('post_cnt')."\">\n";
346 /* check if we are using account expiration */
347 if ($config->get_cfg_value("account_expiration") == "true"){
348   $expired= ldap_expired_account($config, $ui->dn, $ui->username);
350   if ($expired == 2){
351     new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
352     msg_dialog::display(_("Password change"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
353   }
356 /* Load plugin */
357 if (is_file("$plugin_dir/main.inc")){
358   require_once ("$plugin_dir/main.inc");
359 } else {
360   msg_dialog::display(
361             _("Plugin"),
362             sprintf(_("FATAL: Cannot find any plugin definitions for plugin '%s'!"), $plug),
363             FATAL_ERROR_DIALOG);
364   exit();
368 /* Print_out last ErrorMessage repeated string. */
369 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
370 $smarty->assign("contents", $display);
372 /* If there's some post, take a look if everything is there... */
373 if (isset($_POST) && count($_POST)){
374   if (!isset($_POST['php_c_check'])){
375     msg_dialog::display(
376             _("Configuration Error"),
377             sprintf(_("FATAL: not all POST variables have been transfered by PHP - please inform your administrator!")),
378             FATAL_ERROR_DIALOG);
379     exit();
380   }
383 /* Assign erros to smarty */
384 if (session::is_set('errors')){
385   $smarty->assign("errors", session::get('errors'));
387 if ($error_collector != ""){
388   $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
389 } else {
390   $smarty->assign("php_errors", "");
393 /* Set focus to the error button if we've an error message */
394 $focus= "";
395 if (session::is_set('errors') && session::get('errors') != ""){
396   $focus= '<script language="JavaScript" type="text/javascript">';
397   $focus.= 'document.forms[0].error_accept.focus();';
398   $focus.= '</script>';
401 $focus= '<script language="JavaScript" type="text/javascript">';
402 $focus.= 'next_msg_dialog();';
403 $focus.= '</script>';
404 $smarty->assign("focus", $focus);
406 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
408 /* Save dialog filters and selected base in a cookie. 
409    So we may be able to restore the filter an base settings on reload.
410 */
411 $cookie = array();
413 if(isset($_COOKIE['GOsa_Filter_Settings'])){
414   $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
415 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
416   $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
419 /* Save filters? */
420 if($config->get_cfg_value("save_filter") == "true"){
421   $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
422   foreach($cookie_vars as $var){
423     if(session::is_set($var)){
424       $cookie[$ui->dn][$var] = session::get($var);
425     }
426   }
427   if(isset($_GET['plug'])){
428     $cookie[$ui->dn]['plug'] = $_GET['plug'];
429   }
430   @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
433 /* Show page... */
434 echo $display;
436 /* Save plist and config */
437 session::set('plist',$plist);
438 session::set('config',$config);
439 session::set('errorsAlreadyPosted',array());
441 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
442 ?>