Code

Updated login and a couple of styles
[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::global_set('runtime_cache',array());
42 session::set('limit_exceeded',FALSE);
44 pathNavigator::clear();
46 if ($_SERVER["REQUEST_METHOD"] == "POST"){
47   @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
48 }
49 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, session::get_all(), "_SESSION");
51 /* Logged in? Simple security check */
52 if (!session::global_is_set('config')){
53   new log("security","login","",array(),"main.php called without session - logging out") ;
54   header ("Location: logout.php");
55   exit;
56
58 /* Check for uniqe ip address */
59 $ui= session::global_get('ui');
60 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
61   new log("security","login","",array(),"main.php called with session which has a changed IP address.") ;
62   header ("Location: logout.php");
63   exit;
64 }
65 $config= session::global_get('config');
66 $config->check_and_reload();
68 /* Enable compressed output */
69 if ($config->get_cfg_value("sendCompressedOutput") == "true"){
70   ob_start("ob_gzhandler");
71 }
73 /* Check for invalid sessions */
74 if(session::global_get('_LAST_PAGE_REQUEST') == ""){
75   session::global_set('_LAST_PAGE_REQUEST',time());
76 }else{
78   /* check GOsa.conf for defined session lifetime */
79   $max_life= $config->get_cfg_value("sessionLifetime", 60*60*2);
81   /* get time difference between last page reload */
82   $request_time = (time()- session::global_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::destroy();
89     new log("security","login","",array(),"main.php called without session - logging out") ;
90     header ("Location: logout.php");
91     exit;
92   }
93   session::global_set('_LAST_PAGE_REQUEST',time());
94 }
97 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
99 /* Set template compile directory */
100 $smarty->compile_dir= $config->get_cfg_value("templateCompileDirectory", '/var/spool/gosa');
102 /* Set default */
103 $reload_navigation = false;
105 /* Set last initialised language to current, browser settings */
106 if(!session::global_is_set('Last_init_lang')){
107   $reload_navigation = true;
108   session::global_set('Last_init_lang',get_browser_language());
111 /* If last language != current force navi reload */
112 $lang= get_browser_language();
113 if(session::global_get('Last_init_lang') != $lang){
114   $reload_navigation = true;
117 /* Language setup */
118 session::global_set('Last_init_lang',$lang);
120 /* Preset current main base */
121 if(!session::global_is_set('CurrentMainBase')){
122   session::global_set('CurrentMainBase',get_base_from_people($ui->dn));
125 putenv("LANGUAGE=");
126 putenv("LANG=$lang");
127 setlocale(LC_ALL, $lang);
128 $GLOBALS['t_language']= $lang;
129 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
131 /* Check if the config is up to date */
132 $config->check_config_version();
134 /* Set the text domain as 'messages' */
135 $domain = 'messages';
136 bindtextdomain($domain, LOCALE_DIR);
137 textdomain($domain);
138 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
140 /* Prepare plugin list */
141 if (!session::global_is_set('plist')){
142   /* Initially load all classes */
143   $class_list= get_declared_classes();
144   foreach ($class_mapping as $class => $path){
145     if (!in_array($class, $class_list)){
146       if (is_readable("$BASE_DIR/$path")){
147         require_once("$BASE_DIR/$path");
148       } else {
149         msg_dialog::display(_("Fatal error"),
150             sprintf(_("Cannot locate file '%s' - please run '%s' to fix this"),
151               "$BASE_DIR/$path", "<b>update-gosa</b>"), FATAL_ERROR_DIALOG);
152         exit;
153       }
154     }
155   }
157   session::global_set('plist', new pluglist($config, $ui));
159   /* Load ocMapping into userinfo */
160   $tmp= new acl($config, NULL, $ui->dn);
161   $ui->ocMapping= $tmp->ocMapping;
162   session::global_set('ui',$ui);
164 $plist= session::global_get('plist');
166 /* Check for register globals */
167 if (isset($global_check) && $config->get_cfg_value("forceglobals") == "true"){
168   msg_dialog::display(
169             _("PHP configuration"),
170             _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."),
171             FATAL_ERROR_DIALOG);
173   new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
174   session::destroy ();
175   exit;
178 /* Check Plugin variable */
179 if (session::global_is_set('plugin_dir')){
180   $old_plugin_dir= session::global_get('plugin_dir');
181 } else {
182   $old_plugin_dir= "";
184 if (isset($_GET['plug']) && $plist->plugin_access_allowed($_GET['plug'])){
185   $plug= validate($_GET['plug']);
186   $plugin_dir= $plist->get_path($plug);
187   session::global_set('plugin_dir',$plugin_dir);
188   if ($plugin_dir == ""){
189     new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
190     header ("Location: logout.php");
191     exit;
192   }
193 } else {
195   /* set to welcome page as default plugin */
196   session::global_set('plugin_dir',"welcome");
197   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
200 /* Handle plugin locks.
201     - Remove the plugin from session if we switched to another. (cleanup) 
202     - Remove all created locks if "reset" was posted.
203     - Remove all created locks if we switched to another plugin.
204 */
205 $cleanup    = FALSE;
206 $remove_lock= FALSE;
208 /* Check if we have changed the selected plugin 
209 */
210 if($old_plugin_dir != $plugin_dir && $old_plugin_dir != ""){
211   if (is_file("$old_plugin_dir/main.inc")){
212     $cleanup = $remove_lock = TRUE;
213     require ("$old_plugin_dir/main.inc");
214     $cleanup = $remove_lock = FALSE;
215   }
216 }else // elseif
218 /* Reset was posted, remove all created locks for the current plugin
219 */
220 if((isset($_GET['reset']) && $_GET['reset'] == 1) || isset($_POST['delete_lock'])){
221   $remove_lock = TRUE;
224 /* Check for sizelimits */
225 eval_sizelimit();
227 /* Check for memory */
228 if (function_exists("memory_get_usage")){
229   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
230     msg_dialog::display(_("Configuration error"), _("Running out of memory!"), WARNING_DIALOG);
231   }
234 /* Redirect on back event */
235 if ($_SERVER["REQUEST_METHOD"] == "POST"){
237   /* Look for button events that match /^back[0-9]+$/,
238      extract the number and step the correct plugin. */
239   foreach ($_POST as $key => $value){
240     if (preg_match("/^back[0-9]+$/", $key)){
241       $back= substr($key, 4);
242       header ("Location: main.php?plug=$back");
243       exit;
244     }
245   }
248 /* Redirect on password back event */
249 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
250   header ("Location: main.php");
251   exit;
254 /* Check for multiple windows logout */
255 if ($_SERVER["REQUEST_METHOD"] == "POST"){
256   if (isset($_POST['reset_session'])){
257     header ("Location: logout.php");
258     exit;
259   }
263 /* Load department list when plugin has changed. That is some kind of
264    compromise between speed and beeing up to date */
265 if (isset($_GET['reset'])){
266   set_object_info();
269 /* show web frontend */
270 $smarty->assign ("logo", image("themes/modern/images/logo.png"));
271 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
272 $smarty->assign ("lang", preg_replace('/_.*$/', '', $lang));
273 $smarty->assign ("must", "<span class='required'>*</span>");
274 if (isset($plug)){
275   $plug= "?plug=$plug";
276 } else {
277   $plug= "";
279 if (session::global_get('js')==FALSE){
280   $smarty->assign("javascript", "false");
281   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
282 } else {
283   $smarty->assign("javascript", "true");
284   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
287 if($ui->ignore_acl_for_current_user()){
288   $smarty->assign ("loggedin", "<font color='red'>"._("ACLs are disabled")."</font>&nbsp;".sprintf(_("You're logged in as %s"), "<span>".$ui->cn." [".$ui->username."]</span>"));
289 }else{
290   $smarty->assign ("loggedin", sprintf(_("You're logged in as %s"), "<span>".$ui->cn." [".$ui->username."]</span>"));
292 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
293 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
294 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
295 $smarty->assign ("go_out", get_template_path('images/logout.png'));
296 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
297 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
298 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
299 $smarty->assign ("go_help", get_template_path('images/help.png'));
301 /* reload navigation if language changed*/  
302 if($reload_navigation){
303   $plist->menu="";
305 $smarty->assign ("menu", $plist->gen_menu());
306 $smarty->assign ("plug", "$plug");
308 $smarty->assign("iePngWorkaround", $config->get_cfg_value("iePngWorkaround","false" ) == "true");
309 $smarty->assign("usePrototype", "false");
311 /* React on clicks */
312 if ($_SERVER["REQUEST_METHOD"] == "POST"){
313   if (isset($_POST['delete_lock']) || isset($_POST['open_readonly'])){
315     /* Set old Post data */
316     if(session::global_is_set('LOCK_VARS_USED_GET')){
317       foreach(session::global_get('LOCK_VARS_USED_GET') as $name => $value){
318         $_GET[$name]  = $value;
319       } 
320     } 
321     if(session::global_is_set('LOCK_VARS_USED_POST')){
322       foreach(session::global_get('LOCK_VARS_USED_POST') as $name => $value){
323         $_POST[$name] = $value;
324       } 
325     }
326     if(session::global_is_set('LOCK_VARS_USED_REQUEST')){
327       foreach(session::global_get('LOCK_VARS_USED_REQUEST') as $name => $value){
328         $_REQUEST[$name] = $value;
329       } 
330     }
331   }
334 /* check if we are using account expiration */
335 if ($config->get_cfg_value("handleExpiredAccounts") == "true"){
336   $expired= ldap_expired_account($config, $ui->dn, $ui->username);
338   if ($expired == 2){
339     new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
340     msg_dialog::display(_("Password change"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
341   }
344 /* Load plugin */
345 if (is_file("$plugin_dir/main.inc")){
346   $display ="";
347   require ("$plugin_dir/main.inc");
348 } else {
349   msg_dialog::display(
350       _("Plugin"),
351       sprintf(_("FATAL: Cannot find any plugin definitions for plugin '%s'!"), $plug),
352       FATAL_ERROR_DIALOG);
353   exit();
357 /* Print_out last ErrorMessage repeated string. */
358 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
359 $smarty->assign ("pathMenu", $plist->genPathMenu());
360 $smarty->assign("contents", $display);
362 /* If there's some post, take a look if everything is there... */
363 if (isset($_POST) && count($_POST)){
364   if (!isset($_POST['php_c_check'])){
365     msg_dialog::display(
366             _("Configuration Error"),
367             sprintf(_("FATAL: not all POST variables have been transfered by PHP - please inform your administrator!")),
368             FATAL_ERROR_DIALOG);
369     exit();
370   }
373 /* Assign erros to smarty */
374 if (session::is_set('errors')){
375   $smarty->assign("errors", session::get('errors'));
377 if ($error_collector != ""){
378   $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
379 } else {
380   $smarty->assign("php_errors", "");
383 /* Set focus to the error button if we've an error message */
384 $focus= "";
385 if (session::is_set('errors') && session::get('errors') != ""){
386   $focus= '<script language="JavaScript" type="text/javascript">';
387   $focus.= 'document.forms[0].error_accept.focus();';
388   $focus.= '</script>';
391 $focus= '<script language="JavaScript" type="text/javascript">';
392 $focus.= 'next_msg_dialog();';
393 $focus.= '</script>';
394 $smarty->assign("focus", $focus);
396 /* Set channel if needed */
397 #TODO: * move all global session calls to global_
398 #      * create a new channel where needed (mostly management dialogues)
399 #      * remove regulary created channels when not needed anymore
400 #      * take a look at external php calls (i.e. get fax, ldif, etc.)
401 #      * handle aborted sessions (by pressing anachors i.e. Main, Menu, etc.)
402 #      * check lock removals, is "dn" global or not in this case?
403 #      * last page request -> global or not?
404 #      * check that filters are still global
405 #      * maxC global?
406 if (isset($_POST['_channel_'])){
407         echo "DEBUG - current channel: ".$_POST['_channel_'];
408         $smarty->assign("channel", $_POST['_channel_']);
409 } else {
410         $smarty->assign("channel", "");
413 $display= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl')).
414           $smarty->fetch(get_template_path('framework.tpl'));
416 /* Save dialog filters and selected base in a cookie. 
417    So we may be able to restore the filter an base settings on reload.
418 */
419 $cookie = array();
421 if(isset($_COOKIE['GOsa_Filter_Settings'])){
422   $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
423 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
424   $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
427 /* Save filters? */
428 if($config->get_cfg_value("storeFilterSettings") == "true"){
429   $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
430   foreach($cookie_vars as $var){
431     if(session::global_is_set($var)){
432       $cookie[$ui->dn][$var] = session::global_get($var);
433     }
434   }
435   if(isset($_GET['plug'])){
436     $cookie[$ui->dn]['plug'] = $_GET['plug'];
437   }
438   @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
441 /* Show page... */
442 echo $display;
444 /* Save plist and config */
445 session::global_set('plist',$plist);
446 session::global_set('config',$config);
447 session::set('errorsAlreadyPosted',array());
449 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
450 ?>