Code

Just war the user once about the password expiration.
[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 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::global_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::global_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::global_get('config');
64 $config->check_and_reload();
66 /* Enable compressed output */
67 if ($config->get_cfg_value("sendCompressedOutput") == "true"){
68   ob_start("ob_gzhandler");
69 }
71 /* Check for invalid sessions */
72 if(session::global_get('_LAST_PAGE_REQUEST') == ""){
73   session::global_set('_LAST_PAGE_REQUEST',time());
74 }else{
76   /* check GOsa.conf for defined session lifetime */
77   $max_life= $config->get_cfg_value("sessionLifetime", 60*60*2);
79   /* get time difference between last page reload */
80   $request_time = (time()- session::global_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::global_set('_LAST_PAGE_REQUEST',time());
92 }
95 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
97 /* Set template compile directory */
98 $smarty->compile_dir= $config->get_cfg_value("templateCompileDirectory", '/var/spool/gosa');
100 /* Set default */
101 $reload_navigation = false;
103 /* Set last initialised language to current, browser settings */
104 if(!session::global_is_set('Last_init_lang')){
105   $reload_navigation = true;
106   session::global_set('Last_init_lang',get_browser_language());
109 /* If last language != current force navi reload */
110 $lang= get_browser_language();
111 if(session::global_get('Last_init_lang') != $lang){
112   $reload_navigation = true;
115 /* Language setup */
116 session::global_set('Last_init_lang',$lang);
118 /* Preset current main base */
119 if(!session::global_is_set('CurrentMainBase')){
120   session::global_set('CurrentMainBase',get_base_from_people($ui->dn));
123 putenv("LANGUAGE=");
124 putenv("LANG=$lang");
125 setlocale(LC_ALL, $lang);
126 $GLOBALS['t_language']= $lang;
127 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
129 /* Check if the config is up to date */
130 $config->check_config_version();
132 /* Set the text domain as 'messages' */
133 $domain = 'messages';
134 bindtextdomain($domain, LOCALE_DIR);
135 textdomain($domain);
136 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
138 /* Prepare plugin list */
139 if (!session::global_is_set('plist')){
140   /* Initially load all classes */
141   $class_list= get_declared_classes();
142   foreach ($class_mapping as $class => $path){
143     if (!in_array($class, $class_list)){
144       if (is_readable("$BASE_DIR/$path")){
145         require_once("$BASE_DIR/$path");
146       } else {
147         msg_dialog::display(_("Fatal error"),
148             sprintf(_("Cannot locate file '%s' - please run '%s' to fix this"),
149               "$BASE_DIR/$path", "<b>update-gosa</b>"), FATAL_ERROR_DIALOG);
150         exit;
151       }
152     }
153   }
155   session::global_set('plist', new pluglist($config, $ui));
157   /* Load ocMapping into userinfo */
158   $tmp= new acl($config, NULL, $ui->dn);
159   $ui->ocMapping= $tmp->ocMapping;
160   session::global_set('ui',$ui);
162 $plist= session::global_get('plist');
164 /* Check for register globals */
165 if (isset($global_check) && $config->get_cfg_value("forceglobals") == "true"){
166   msg_dialog::display(
167             _("PHP configuration"),
168             _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."),
169             FATAL_ERROR_DIALOG);
171   new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
172   session::destroy ();
173   exit;
176 /* Check Plugin variable */
177 if (session::global_is_set('plugin_dir')){
178   $old_plugin_dir= session::global_get('plugin_dir');
179 } else {
180   $old_plugin_dir= "";
183 /* reload navigation if language changed*/  
184 if($reload_navigation){
185   $plist->menu="";
187 $plist->gen_headlines();
188 $plist->gen_menu();
190 /* check if we are using account expiration */
191 $smarty->assign("hideMenus", FALSE);
192 if ($config->get_cfg_value("handleExpiredAccounts") == "true"){
193     $expired= ldap_expired_account($config, $ui->dn, $ui->username);
194     if ($expired == POSIX_WARN_ABOUT_EXPIRATION && !session::is_set('POSIX_WARN_ABOUT_EXPIRATION__DONE')){
196         // The users password is about to xpire soon, display a warning message.
197         new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
198         msg_dialog::display(_("Password change"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
199         session::set('POSIX_WARN_ABOUT_EXPIRATION__DONE', TRUE);
200     
201     } elseif ($expired == POSIX_FORCE_PASSWORD_CHANGE){
203         // The password is expired, we are now going to enforce a new one from the user.
205         // Hide the GOsa menus to avoid leaving the enforced password change dialog.
206         $smarty->assign("hideMenus", TRUE);
207         $plug = (isset($_GET['plug'])) ? $_GET['plug'] : null;
209         // Search for the 'password' class and set its id as active plug.
210         foreach ($plist->dirlist as $key => $value){
211             if (preg_match("/\bpassword\b/i",$value)){
212                 if($plug != $key) {
213                     $_GET['plug'] = $key;
214                 }
215                 break;
216             }
217         }
218     }
222 if (isset($_GET['plug']) && $plist->plugin_access_allowed($_GET['plug'])){
223   $plug= validate($_GET['plug']);
224   $plugin_dir= $plist->get_path($plug);
225   session::global_set('plugin_dir',$plugin_dir);
226   if ($plugin_dir == ""){
227     new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
228     header ("Location: logout.php");
229     exit;
230   }
231 } else {
233   /* set to welcome page as default plugin */
234   session::global_set('plugin_dir',"welcome");
235   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
238 /* Handle plugin locks.
239     - Remove the plugin from session if we switched to another. (cleanup) 
240     - Remove all created locks if "reset" was posted.
241     - Remove all created locks if we switched to another plugin.
242 */
243 $cleanup    = FALSE;
244 $remove_lock= FALSE;
246 /* Check if we have changed the selected plugin 
247 */
248 if($old_plugin_dir != $plugin_dir && $old_plugin_dir != ""){
249   if (is_file("$old_plugin_dir/main.inc")){
250     $cleanup = $remove_lock = TRUE;
251     require ("$old_plugin_dir/main.inc");
252     $cleanup = $remove_lock = FALSE;
253   }
254 }else // elseif
256 /* Reset was posted, remove all created locks for the current plugin
257 */
258 if((isset($_GET['reset']) && $_GET['reset'] == 1) || isset($_POST['delete_lock'])){
259   $remove_lock = TRUE;
262 /* Check for sizelimits */
263 eval_sizelimit();
265 /* Check for memory */
266 if (function_exists("memory_get_usage")){
267   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
268     msg_dialog::display(_("Configuration error"), _("Running out of memory!"), WARNING_DIALOG);
269   }
272 /* Redirect on back event */
273 if ($_SERVER["REQUEST_METHOD"] == "POST"){
275   /* Look for button events that match /^back[0-9]+$/,
276      extract the number and step the correct plugin. */
277   foreach ($_POST as $key => $value){
278     if (preg_match("/^back[0-9]+$/", $key)){
279       $back= substr($key, 4);
280       header ("Location: main.php?plug=$back");
281       exit;
282     }
283   }
286 /* Redirect on password back event */
287 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
288   header ("Location: main.php");
289   exit;
292 /* Check for multiple windows logout */
293 if ($_SERVER["REQUEST_METHOD"] == "POST"){
294   if (isset($_POST['reset_session'])){
295     header ("Location: logout.php");
296     exit;
297   }
301 /* Load department list when plugin has changed. That is some kind of
302    compromise between speed and beeing up to date */
303 if (isset($_GET['reset'])){
304   set_object_info();
307 /* show web frontend */
308 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
309 $smarty->assign ("lang", preg_replace('/_.*$/', '', $lang));
310 $smarty->assign ("must", "<font class=\"must\">*</font>");
311 if (isset($plug)){
312   $plug= "?plug=$plug";
313 } else {
314   $plug= "";
316 if (session::global_get('js')==FALSE){
317   $smarty->assign("javascript", "false");
318   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
319 } else {
320   $smarty->assign("javascript", "true");
321   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
324 if($ui->ignore_acl_for_current_user()){
325   $smarty->assign ("username", "<font color='#FF0000';>"._("User ACL checks disabled")."</font>&nbsp;".$ui->username);
326 }else{
327   $smarty->assign ("username", $ui->username);
329 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
330 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
331 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
332 $smarty->assign ("go_out", get_template_path('images/logout.png'));
333 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
334 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
335 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
336 $smarty->assign ("go_help", get_template_path('images/help.png'));
338 $smarty->assign ("menu", $plist->menu);
339 $smarty->assign ("plug", "$plug");
341 $smarty->assign("iePngWorkaround", $config->get_cfg_value("iePngWorkaround","false" ) == "true");
342 $smarty->assign("usePrototype", "false");
344 /* React on clicks */
345 if ($_SERVER["REQUEST_METHOD"] == "POST"){
346   if (isset($_POST['delete_lock']) || isset($_POST['open_readonly'])){
348     /* Set old Post data */
349     if(session::global_is_set('LOCK_VARS_USED_GET')){
350       foreach(session::global_get('LOCK_VARS_USED_GET') as $name => $value){
351         $_GET[$name]  = $value;
352       } 
353     } 
354     if(session::global_is_set('LOCK_VARS_USED_POST')){
355       foreach(session::global_get('LOCK_VARS_USED_POST') as $name => $value){
356         $_POST[$name] = $value;
357       } 
358     }
359     if(session::global_is_set('LOCK_VARS_USED_REQUEST')){
360       foreach(session::global_get('LOCK_VARS_USED_REQUEST') as $name => $value){
361         $_REQUEST[$name] = $value;
362       } 
363     }
364   }
367 /* Load plugin */
368 if (is_file("$plugin_dir/main.inc")){
369   $display ="";
370   require ("$plugin_dir/main.inc");
371 } else {
372   msg_dialog::display(
373       _("Plugin"),
374       sprintf(_("FATAL: Cannot find any plugin definitions for plugin '%s'!"), $plug),
375       FATAL_ERROR_DIALOG);
376   exit();
380 /* Print_out last ErrorMessage repeated string. */
381 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
382 $smarty->assign("contents", $display);
384 /* If there's some post, take a look if everything is there... */
385 if (isset($_POST) && count($_POST)){
386   if (!isset($_POST['php_c_check'])){
387     msg_dialog::display(
388             _("Configuration Error"),
389             sprintf(_("FATAL: not all POST variables have been transfered by PHP - please inform your administrator!")),
390             FATAL_ERROR_DIALOG);
391     exit();
392   }
395 /* Assign erros to smarty */
396 if (session::is_set('errors')){
397   $smarty->assign("errors", session::get('errors'));
399 if ($error_collector != ""){
400   $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
401 } else {
402   $smarty->assign("php_errors", "");
405 /* Set focus to the error button if we've an error message */
406 $focus= "";
407 if (session::is_set('errors') && session::get('errors') != ""){
408   $focus= '<script language="JavaScript" type="text/javascript">';
409   $focus.= 'document.forms[0].error_accept.focus();';
410   $focus.= '</script>';
413 $focus= '<script language="JavaScript" type="text/javascript">';
414 $focus.= 'next_msg_dialog();';
415 $focus.= '</script>';
416 $smarty->assign("focus", $focus);
418 /* Set channel if needed */
419 #TODO: * move all global session calls to global_
420 #      * create a new channel where needed (mostly management dialogues)
421 #      * remove regulary created channels when not needed anymore
422 #      * take a look at external php calls (i.e. get fax, ldif, etc.)
423 #      * handle aborted sessions (by pressing anachors i.e. Main, Menu, etc.)
424 #      * check lock removals, is "dn" global or not in this case?
425 #      * last page request -> global or not?
426 #      * check that filters are still global
427 #      * maxC global?
428 if (isset($_POST['_channel_'])){
429         echo "DEBUG - current channel: ".$_POST['_channel_'];
430         $smarty->assign("channel", $_POST['_channel_']);
431 } else {
432         $smarty->assign("channel", "");
435 $display= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl')).
436           $smarty->fetch(get_template_path('framework.tpl'));
438 /* Save dialog filters and selected base in a cookie. 
439    So we may be able to restore the filter an base settings on reload.
440 */
441 $cookie = array();
443 if(isset($_COOKIE['GOsa_Filter_Settings'])){
444   $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
445 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
446   $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
449 /* Save filters? */
450 if($config->get_cfg_value("storeFilterSettings") == "true"){
451   $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
452   foreach($cookie_vars as $var){
453     if(session::global_is_set($var)){
454       $cookie[$ui->dn][$var] = session::global_get($var);
455     }
456   }
457   if(isset($_GET['plug'])){
458     $cookie[$ui->dn]['plug'] = $_GET['plug'];
459   }
460   @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
463 /* Show page... */
464 echo $display;
466 /* Save plist and config */
467 session::global_set('plist',$plist);
468 session::global_set('config',$config);
469 session::set('errorsAlreadyPosted',array());
471 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
472 ?>