Code

9a47467c43fe7d2fa71a62f3bbe3c8d4b75138ad
[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 $object_id = "";
36 bindtextdomain($domain, LOCALE_DIR);
37 textdomain($domain);
39 /* Remember everything we did after the last click */
40 session::start();
41 session::set('errorsAlreadyPosted',array());
42 session::set('runtime_cache',array());
43 session::set('limit_exceeded',FALSE);
45 if ($_SERVER["REQUEST_METHOD"] == "POST"){
46   @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
47 }
48 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, session::get_all(), "_SESSION");
50 /* Logged in? Simple security check */
51 if (!session::is_set('config')){
52   new log("security","login","",array(),"main.php called without session - logging out") ;
53   header ("Location: logout.php");
54   exit;
55
57 /* Check for uniqe ip address */
58 $ui= session::get('ui');
59 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
60   new log("security","login","",array(),"main.php called with session which has a changed IP address.") ;
61   header ("Location: logout.php");
62   exit;
63 }
64 $config= session::get('config');
65 $config->check_config_version();
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::get('_LAST_PAGE_REQUEST') == ""){
75   session::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::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::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::is_set('Last_init_lang')){
107   $reload_navigation = true;
108   session::set('Last_init_lang',get_browser_language());
111 /* If last language != current force navi reload */
112 $lang= get_browser_language();
113 if(session::get('Last_init_lang') != $lang){
114   $reload_navigation = true;
117 /* Language setup */
118 session::set('Last_init_lang',$lang);
120 /* Preset current main base */
121 if(!session::is_set('CurrentMainBase')){
122   session::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 /* Set the text domain as 'messages' */
132 $domain = 'messages';
133 bindtextdomain($domain, LOCALE_DIR);
134 textdomain($domain);
135 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
137 /* Prepare plugin list */
138 if (!session::is_set('plist')){
139   /* Initially load all classes */
140   $class_list= get_declared_classes();
141   foreach ($class_mapping as $class => $path){
142     if (!in_array($class, $class_list)){
143       if (is_readable("$BASE_DIR/$path")){
144         require_once("$BASE_DIR/$path");
145       } else {
146         msg_dialog::display(_("Fatal error"),
147             sprintf(_("Cannot locate file '%s' - please run '%s' to fix this"),
148               "$BASE_DIR/$path", "<b>update-gosa</b>"), FATAL_ERROR_DIALOG);
149         exit;
150       }
151     }
152   }
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->get_cfg_value("forceglobals") == "true"){
165   msg_dialog::display(
166             _("PHP configuration"),
167             _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."),
168             FATAL_ERROR_DIALOG);
170   new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
171   session::destroy ();
172   exit;
175 /* Check Plugin variable */
176 if (session::is_set('plugin_dir')){
177   $old_plugin_dir= session::get('plugin_dir');
178 } else {
179   $old_plugin_dir= "";
182 if (isset($_GET['plug'])){
183   $plug=preg_replace("/:.*$/","",validate($_GET['plug'])); 
184   if($plist->plugin_access_allowed($plug)){
185     $plugin_dir= $plist->get_path($plug);
186     session::set('plugin_dir',$plugin_dir);
187     if ($plugin_dir == ""){
188       new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
189       header ("Location: logout.php");
190       exit;
191     }
192   }else{
193     session::set('plugin_dir',"welcome");
194     $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
195   }
196 } else {
197   session::set('plugin_dir',"welcome");
198   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
201 /* Check if we need to delete a lock */
202 if ($old_plugin_dir != $plugin_dir && $old_plugin_dir != ""){
203   if (is_file("$old_plugin_dir/main.inc")){
204     $remove_lock= true;
205     require_once ("$old_plugin_dir/main.inc");
206   }
208 $remove_lock= false;
210 /* Check for sizelimits */
211 eval_sizelimit();
213 /* Check for memory */
214 if (function_exists("memory_get_usage")){
215   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
216     msg_dialog::display(_("Configuration error"), _("Running out of memory!"), WARNING_DIALOG);
217   }
220 /* Redirect on back event */
221 if ($_SERVER["REQUEST_METHOD"] == "POST"){
223   /* Look for button events that match /^back[0-9]+$/,
224      extract the number and step the correct plugin. */
225   foreach ($_POST as $key => $value){
226     if (preg_match("/^back[0-9]+$/", $key)){
227       $back= substr($key, 4);
228       header ("Location: main.php?plug=$back");
229       exit;
230     }
231   }
234 /* Redirect on password back event */
235 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
236   header ("Location: main.php");
237   exit;
240 /* Check for multiple windows logout */
241 if ($_SERVER["REQUEST_METHOD"] == "POST"){
242   if (isset($_POST['reset_session'])){
243     header ("Location: logout.php");
244     exit;
245   }
247   if (isset($_POST['cancel_lock'])){
248     session::un_set('dn');
249   }
253 /* Load department list when plugin has changed. That is some kind of
254    compromise between speed and beeing up to date */
255 if (isset($_GET['reset'])){
256   if (session::is_set('objectinfo')){
257     session::un_set('objectinfo');
258   }
261 /* Install eGOsa hooks, convert _POST to session */
262 if(isset($_GET['explorer'])){
263   session::set('eGosa',TRUE);
265 if(session::is_set('POST')){
266   $_SERVER["REQUEST_METHOD"] = "POST";
267   foreach (session::get('POST') as $key => $dummy){
268     $_POST[$key]= $dummy;
269   }
270   session::un_set('POST');
273 /* show web frontend */
274 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
275 $smarty->assign ("must", "<font class=\"must\">*</font>");
276 if (isset($plug)){
277   $plug= "?plug=$plug";
278 } else {
279   $plug= "";
281 if (session::get('js')==FALSE){
282   $smarty->assign("javascript", "false");
283   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
284 } else {
285   $smarty->assign("javascript", "true");
286   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
289 if($ui->ignore_acl_for_current_user()){
290   $smarty->assign ("username", "<font color='#FF0000';>"._("User ACL checks disabled")."</font>&nbsp;".$ui->username);
291 }else{
292   $smarty->assign ("username", $ui->username);
294 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
295 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
296 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
297 $smarty->assign ("go_out", get_template_path('images/logout.png'));
298 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
299 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
300 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
301 $smarty->assign ("go_help", get_template_path('images/help.png'));
303 /* reload navigation if language changed*/  
304 if($reload_navigation){
305   $plist->menu="";
307 $plist->gen_headlines();
308 $plist->gen_menu();
309 $smarty->assign ("menu", $plist->menu);
310 $smarty->assign ("plug", "$plug");
312 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
314 /* React on clicks */
315 if ($_SERVER["REQUEST_METHOD"] == "POST"){
317   /* 'delete_lock' is set by the lock removal dialog. We should remove the
318      lock at this point globally. Plugins do not need to remove it. */
319   if (isset($_POST['delete_lock']) && session::is_set('dn')){
320     del_lock (session::get('dn'));
322   }
323   if (isset($_POST['delete_lock']) || isset($_POST['open_readonly'])){
325     /* Set old Post data */
326     if(session::is_set('LOCK_VARS_USED')){
327       foreach(session::get('LOCK_VARS_USED') as $name => $value){
328         $_GET[$name]  = $value;
329         $_POST[$name] = $value;
330       } 
331     }
332     session::un_set ('dn');
333   }
336   /* I don't want multiple browser windows open. One way to check it is
337      to count a hidden field and warn the user if SESSION and INPUT count
338      differ. */
339   if (isset($_POST['session_cnt'])){
340     if ($_POST['session_cnt'] != session::get('session_cnt')){
341       $smarty->display(get_template_path('conflict.tpl'));
342       exit ();
343     }
344     session::set('session_cnt', (session::get('session_cnt') + 1));
345     session::set('post_cnt' , validate($_POST['session_cnt']) + 1);
346   }
349 /* Only generate hidden click counter, if post_cnt is defined */
350 if (session::is_set('post_cnt')){
351   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".session::get('post_cnt')."\">\n";
354 /* check if we are using account expiration */
355 if ($config->get_cfg_value("handleExpiredAccounts") == "true"){
356   $expired= ldap_expired_account($config, $ui->dn, $ui->username);
358   if ($expired == 2){
359     new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
360     msg_dialog::display(_("Password change"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
361   }
364 /* Load plugin */
365 if (is_file("$plugin_dir/main.inc")){
366   $o_id = get_current_object_id();
367   if(!empty($o_id)){
368     $plug .= ":".base64_encode($o_id);
369     $_GET['plug'] .= ":".base64_encode($o_id);
370   }
371   require_once ("$plugin_dir/main.inc");
372 } else {
373   msg_dialog::display(
374             _("Plugin"),
375             sprintf(_("FATAL: Cannot find any plugin definitions for plugin '%s'!"), $plug),
376             FATAL_ERROR_DIALOG);
377   exit();
381 /* Print_out last ErrorMessage repeated string. */
382 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
383 $smarty->assign("contents", $display);
385 /* If there's some post, take a look if everything is there... */
386 if (isset($_POST) && count($_POST)){
387   if (!isset($_POST['php_c_check'])){
388     msg_dialog::display(
389             _("Configuration Error"),
390             sprintf(_("FATAL: not all POST variables have been transfered by PHP - please inform your administrator!")),
391             FATAL_ERROR_DIALOG);
392     exit();
393   }
396 /* Assign erros to smarty */
397 if (session::is_set('errors')){
398   $smarty->assign("errors", session::get('errors'));
400 if ($error_collector != ""){
401   $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
402 } else {
403   $smarty->assign("php_errors", "");
406 /* Set focus to the error button if we've an error message */
407 $focus= "";
408 if (session::is_set('errors') && session::get('errors') != ""){
409   $focus= '<script language="JavaScript" type="text/javascript">';
410   $focus.= 'document.forms[0].error_accept.focus();';
411   $focus.= '</script>';
414 $focus= '<script language="JavaScript" type="text/javascript">';
415 $focus.= 'next_msg_dialog();';
416 $focus.= '</script>';
417 $smarty->assign("focus", $focus);
418 $o_id = get_current_object_id();
419 if(!empty($o_id)){
420   $smarty->assign("object_id", base64_encode($o_id));
421 }else{
422   $smarty->assign("object_id", "");
425 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
427 /* Save dialog filters and selected base in a cookie. 
428    So we may be able to restore the filter an base settings on reload.
429 */
430 $cookie = array();
432 if(isset($_COOKIE['GOsa_Filter_Settings'])){
433   $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
434 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
435   $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
438 /* Save filters? */
439 if($config->get_cfg_value("storeFilterSettings") == "true"){
440   $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
441   foreach($cookie_vars as $var){
442     if(session::is_set($var)){
443       $cookie[$ui->dn][$var] = session::get($var);
444     }
445   }
446   if(isset($_GET['plug'])){
447     $cookie[$ui->dn]['plug'] = $_GET['plug'];
448   }
449   @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
452 /* Show page... */
453 echo $display;
455 /* Save plist and config */
456 session::set('plist',$plist);
457 session::set('config',$config);
458 session::set('errorsAlreadyPosted',array());
460 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
461 ?>