Code

Updated schemaCheck in configRegistry
[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();
67 $config->configRegistry->reload();
68 $config->configRegistry->validateSchemata($force=FALSE,$disableIncompatiblePlugins=TRUE,$errorMessages= TRUE);
70 /* Enable compressed output */
71 if ($config->get_cfg_value("core","sendCompressedOutput") == "true"){
72   ob_start("ob_gzhandler");
73 }
75 /* Check for invalid sessions */
76 if(session::global_get('_LAST_PAGE_REQUEST') == ""){
77   session::global_set('_LAST_PAGE_REQUEST',time());
78 }else{
80   /* check GOsa.conf for defined session lifetime */
81   $max_life= $config->get_cfg_value("core","sessionLifetime");
83   /* get time difference between last page reload */
84   $request_time = (time()- session::global_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::global_set('_LAST_PAGE_REQUEST',time());
96 }
99 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
101 /* Set template compile directory */
102 $smarty->compile_dir= $config->get_cfg_value("core","templateCompileDirectory");
103 $smarty->error_unassigned= true;
105 /* Set default */
106 $reload_navigation = false;
108 /* Set last initialised language to current, browser settings */
109 if(!session::global_is_set('Last_init_lang')){
110   $reload_navigation = true;
111   session::global_set('Last_init_lang',get_browser_language());
114 /* If last language != current force navi reload */
115 $lang= get_browser_language();
116 if(session::global_get('Last_init_lang') != $lang){
117   $reload_navigation = true;
120 /* Language setup */
121 session::global_set('Last_init_lang',$lang);
123 /* Preset current main base */
124 if(!session::global_is_set('CurrentMainBase')){
125   session::global_set('CurrentMainBase',get_base_from_people($ui->dn));
128 putenv("LANGUAGE=");
129 putenv("LANG=$lang");
130 setlocale(LC_ALL, $lang);
131 $GLOBALS['t_language']= $lang;
132 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
134 /* Check if the config is up to date */
135 $config->check_config_version();
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::global_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               bold("$BASE_DIR/$path"), bold("update-gosa")), FATAL_ERROR_DIALOG);
155         exit;
156       }
157     }
158   }
160   session::global_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::global_set('ui',$ui);
167 $plist= session::global_get('plist');
169 /* Check for register globals */
170 if (isset($global_check) && $config->boolValueIsTrue("core","forceGlobals")){
171   msg_dialog::display(
172             _("PHP configuration"),
173             _("FATAL: Register globals is active. Please fix this in order to continue."),
174             FATAL_ERROR_DIALOG);
176   new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
177   session::destroy ();
178   exit;
181 /* Check Plugin variable */
182 if (session::global_is_set('plugin_dir')){
183   $old_plugin_dir= session::global_get('plugin_dir');
184 } else {
185   $old_plugin_dir= "";
187 if (isset($_GET['plug']) && $plist->plugin_access_allowed($_GET['plug'])){
188   $plug= validate($_GET['plug']);
189   $plugin_dir= $plist->get_path($plug);
190   session::global_set('plugin_dir',$plugin_dir);
191   if ($plugin_dir == ""){
192     new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
193     header ("Location: logout.php");
194     exit;
195   }
196 } else {
198   /* set to welcome page as default plugin */
199   session::global_set('plugin_dir',"welcome");
200   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
203 /* Handle plugin locks.
204     - Remove the plugin from session if we switched to another. (cleanup) 
205     - Remove all created locks if "reset" was posted.
206     - Remove all created locks if we switched to another plugin.
207 */
208 $cleanup    = FALSE;
209 $remove_lock= FALSE;
211 /* Check if we have changed the selected plugin 
212 */
213 if($old_plugin_dir != $plugin_dir && $old_plugin_dir != ""){
214   if (is_file("$old_plugin_dir/main.inc")){
215     $cleanup = $remove_lock = TRUE;
216     require ("$old_plugin_dir/main.inc");
217     $cleanup = $remove_lock = FALSE;
218   }
219 }else // elseif
221 /* Reset was posted, remove all created locks for the current plugin
222 */
223 if((isset($_GET['reset']) && $_GET['reset'] == 1) || isset($_POST['delete_lock'])){
224   $remove_lock = TRUE;
227 /* Check for sizelimits */
228 eval_sizelimit();
230 /* Check for memory */
231 if (function_exists("memory_get_usage")){
232   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
233     msg_dialog::display(_("Configuration error"), _("Running out of memory!"), WARNING_DIALOG);
234   }
237 /* Redirect on back event */
238 if ($_SERVER["REQUEST_METHOD"] == "POST"){
240   /* Look for button events that match /^back[0-9]+$/,
241      extract the number and step the correct plugin. */
242   foreach ($_POST as $key => $value){
243     if (preg_match("/^back[0-9]+$/", $key)){
244       $back= substr($key, 4);
245       header ("Location: main.php?plug=$back");
246       exit;
247     }
248   }
251 /* Redirect on password back event */
252 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
253   header ("Location: main.php");
254   exit;
257 /* Check for multiple windows logout */
258 if ($_SERVER["REQUEST_METHOD"] == "POST"){
259   if (isset($_POST['reset_session'])){
260     header ("Location: logout.php");
261     exit;
262   }
266 /* Load department list when plugin has changed. That is some kind of
267    compromise between speed and beeing up to date */
268 if (isset($_GET['reset'])){
269   set_object_info();
272 /* show web frontend */
273 $smarty->assign ("title","GOsa");
274 $smarty->assign ("logo", image(get_template_path("images/logo.png")));
275 $smarty->assign ("logoutimage", get_template_path("images/btn-logout.png"));
276 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
277 $smarty->assign ("lang", preg_replace('/_.*$/', '', $lang));
278 $smarty->assign ("must", "<span class='required'>*</span>");
279 if (isset($plug)){
280   $plug= "?plug=$plug";
281 } else {
282   $plug= "";
284 if (session::global_get('js')==FALSE){
285   $smarty->assign("javascript", "false");
286   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
287 } else {
288   $smarty->assign("javascript", "true");
289   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
292 if($ui->ignore_acl_for_current_user()){
293   $smarty->assign ("loggedin", "<font color='red'>"._("ACLs are disabled")."</font>&nbsp;".sprintf(_("You're logged in as %s"), "<span>".$ui->cn." [".$ui->username."]</span>"));
294 }else{
295   $smarty->assign ("loggedin", sprintf(_("You're logged in as %s"), "<span>".$ui->cn." [".$ui->username."]</span>"));
297 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
298 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
299 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
300 $smarty->assign ("go_out", get_template_path('images/logout.png'));
301 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
302 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
303 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
304 $smarty->assign ("go_help", get_template_path('images/help.png'));
306 /* reload navigation if language changed*/  
307 if($reload_navigation){
308   $plist->menu="";
310 $smarty->assign ("menu", $plist->gen_menu());
311 $smarty->assign ("plug", "$plug");
314 /* React on clicks */
315 if ($_SERVER["REQUEST_METHOD"] == "POST"){
316   if (isset($_POST['delete_lock']) || isset($_POST['open_readonly'])){
318     /* Set old Post data */
319     if(session::global_is_set('LOCK_VARS_USED_GET')){
320       foreach(session::global_get('LOCK_VARS_USED_GET') as $name => $value){
321         $_GET[$name]  = $value;
322       } 
323     } 
324     if(session::global_is_set('LOCK_VARS_USED_POST')){
325       foreach(session::global_get('LOCK_VARS_USED_POST') as $name => $value){
326         $_POST[$name] = $value;
327       } 
328     }
329     if(session::global_is_set('LOCK_VARS_USED_REQUEST')){
330       foreach(session::global_get('LOCK_VARS_USED_REQUEST') as $name => $value){
331         $_REQUEST[$name] = $value;
332       } 
333     }
334   }
337 /* check if we are using account expiration */
338 if ($config->get_cfg_value("core","handleExpiredAccounts") == "true"){
339   $expired= ldap_expired_account($config, $ui->dn, $ui->username);
341   if ($expired == 2){
342     new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
343     msg_dialog::display(_("Password change"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
344   }
347 /* Load plugin */
348 if (is_file("$plugin_dir/main.inc")){
349   $display ="";
350   require ("$plugin_dir/main.inc");
351 } else {
352   msg_dialog::display(
353       _("Plugin"),
354       sprintf(_("FATAL: Cannot find any plugin definitions for plugin %s!"), bold($plug)),
355       FATAL_ERROR_DIALOG);
356   exit();
360 /* Print_out last ErrorMessage repeated string. */
361 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
362 $smarty->assign ("pathMenu", $plist->genPathMenu());
363 $smarty->assign("contents", $display);
364 $smarty->assign("sessionLifetime", $config->get_cfg_value('core','sessionLifetime'));
366 /* If there's some post, take a look if everything is there... */
367 if (isset($_POST) && count($_POST)){
368   if (!isset($_POST['php_c_check'])){
369     msg_dialog::display(
370             _("Configuration Error"),
371             sprintf(_("FATAL: not all POST variables have been transfered by PHP - please inform your administrator!")),
372             FATAL_ERROR_DIALOG);
373     exit();
374   }
377 /* Assign erros to smarty */
378 if (session::is_set('errors')){
379   $smarty->assign("errors", session::get('errors'));
381 if ($error_collector != ""){
382   $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
383 } else {
384   $smarty->assign("php_errors", "");
387 /* Set focus to the error button if we've an error message */
388 $focus= "";
389 if (session::is_set('errors') && session::get('errors') != ""){
390   $focus= '<script language="JavaScript" type="text/javascript">';
391   $focus.= 'document.forms[0].error_accept.focus();';
392   $focus.= '</script>';
395 $focus= '<script language="JavaScript" type="text/javascript">';
396 $focus.= 'next_msg_dialog();';
397 $focus.= '</script>';
398 $smarty->assign("focus", $focus);
400 /* Set channel if needed */
401 #TODO: * move all global session calls to global_
402 #      * create a new channel where needed (mostly management dialogues)
403 #      * remove regulary created channels when not needed anymore
404 #      * take a look at external php calls (i.e. get fax, ldif, etc.)
405 #      * handle aborted sessions (by pressing anachors i.e. Main, Menu, etc.)
406 #      * check lock removals, is "dn" global or not in this case?
407 #      * last page request -> global or not?
408 #      * check that filters are still global
409 #      * maxC global?
410 if (isset($_POST['_channel_'])){
411         echo "DEBUG - current channel: ".$_POST['_channel_'];
412         $smarty->assign("channel", $_POST['_channel_']);
413 } else {
414         $smarty->assign("channel", "");
417 $display= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl')).
418           $smarty->fetch(get_template_path('framework.tpl'));
420 /* Save dialog filters and selected base in a cookie. 
421    So we may be able to restore the filter an base settings on reload.
422 */
423 $cookie = array();
425 if(isset($_COOKIE['GOsa_Filter_Settings'])){
426   $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
427 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
428   $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
431 /* Save filters? */
432 if($config->get_cfg_value("core","storeFilterSettings") == "true"){
433   $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
434   foreach($cookie_vars as $var){
435     if(session::global_is_set($var)){
436       $cookie[$ui->dn][$var] = session::global_get($var);
437     }
438   }
439   if(isset($_GET['plug'])){
440     $cookie[$ui->dn]['plug'] = $_GET['plug'];
441   }
442   @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
445 /* Show page... */
446 echo $display;
448 /* Save plist and config */
449 session::global_set('plist',$plist);
450 session::global_set('config',$config);
451 session::set('errorsAlreadyPosted',array());
453 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
454 ?>