2e415ce94f7824770209cc9dbca94c979a7c2641
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 (isset($config->data['MAIN']['COMPRESSED']) && preg_match('/^(true|on)$/i', $config->data['MAIN']['COMPRESSED']) && !isset($_GET['no_output_compression'])){
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 if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
79 $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
80 }else{
81 $max_life = 60*60*2;
82 }
84 /* get time difference between last page reload */
85 $request_time = (time()- session::get('_LAST_PAGE_REQUEST'));
87 /* If page wasn't reloaded for more than max_life seconds
88 * kill session
89 */
90 if($request_time > $max_life){
91 session::destroy();
92 new log("security","login","",array(),"main.php called without session - logging out") ;
93 header ("Location: logout.php");
94 exit;
95 }
96 session::set('_LAST_PAGE_REQUEST',time());
97 }
100 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
102 /* Set template compile directory */
103 if (isset ($config->data['MAIN']['COMPILE'])){
104 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
105 } else {
106 $smarty->compile_dir= '/var/spool/gosa/';
107 }
109 /* Set default */
110 $reload_navigation = false;
112 /* Set last initialised language to current, browser settings */
113 if(!session::is_set('Last_init_lang')){
114 $reload_navigation = true;
115 session::set('Last_init_lang',get_browser_language());
116 }
118 /* If last language != current force navi reload */
119 $lang= get_browser_language();
120 if(session::get('Last_init_lang') != $lang){
121 $reload_navigation = true;
122 }
124 /* Language setup */
125 session::set('Last_init_lang',$lang);
127 /* Preset current main base */
128 if(!session::is_set('CurrentMainBase')){
129 session::set('CurrentMainBase',get_base_from_people($ui->dn));
130 }
132 putenv("LANGUAGE=");
133 putenv("LANG=$lang");
134 setlocale(LC_ALL, $lang);
135 $GLOBALS['t_language']= $lang;
136 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
138 /* Set the text domain as 'messages' */
139 $domain = 'messages';
140 bindtextdomain($domain, LOCALE_DIR);
141 textdomain($domain);
142 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
144 /* Prepare plugin list */
145 if (!session::is_set('plist')){
146 /* Initially load all classes */
147 $class_list= get_declared_classes();
148 foreach ($class_mapping as $class => $path){
149 if (!in_array($class, $class_list)){
150 if (is_readable("$BASE_DIR/$path")){
151 require_once("$BASE_DIR/$path");
152 } else {
153 msg_dialog::display(_("Fatal error"),
154 sprintf(_("Cannot locate file '%s' - please run '%s' to fix this"),
155 "$BASE_DIR/$path", "<b>update-gosa</b>"), FATAL_ERROR_DIALOG);
156 exit;
157 }
158 }
159 }
161 session::set('plist', new pluglist($config, $ui));
163 /* Load ocMapping into userinfo */
164 $tmp= new acl($config, NULL, $ui->dn);
165 $ui->ocMapping= $tmp->ocMapping;
166 session::set('ui',$ui);
167 }
168 $plist= session::get('plist');
169 /* Check for register globals */
170 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
171 msg_dialog::display(
172 _("PHP configuration"),
173 _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."),
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;
179 }
181 /* Check Plugin variable */
182 if (session::is_set('plugin_dir')){
183 $old_plugin_dir= session::get('plugin_dir');
184 } else {
185 $old_plugin_dir= "";
186 }
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::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::set('plugin_dir',"welcome");
200 $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
201 }
203 /* Check if we need to delete a lock */
204 if ($old_plugin_dir != $plugin_dir && $old_plugin_dir != ""){
205 if (is_file("$old_plugin_dir/main.inc")){
206 $remove_lock= true;
207 require_once ("$old_plugin_dir/main.inc");
208 }
209 }
210 $remove_lock= false;
212 /* Check for sizelimits */
213 eval_sizelimit();
215 /* Check for memory */
216 if (function_exists("memory_get_usage")){
217 if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
218 msg_dialog::display(_("Configuration error"), _("Running out of memory!"), WARNING_DIALOG);
219 }
220 }
222 /* Redirect on back event */
223 if ($_SERVER["REQUEST_METHOD"] == "POST"){
225 /* Look for button events that match /^back[0-9]+$/,
226 extract the number and step the correct plugin. */
227 foreach ($_POST as $key => $value){
228 if (preg_match("/^back[0-9]+$/", $key)){
229 $back= substr($key, 4);
230 header ("Location: main.php?plug=$back");
231 exit;
232 }
233 }
234 }
236 /* Redirect on password back event */
237 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
238 header ("Location: main.php");
239 exit;
240 }
242 /* Check for multiple windows logout */
243 if ($_SERVER["REQUEST_METHOD"] == "POST"){
244 if (isset($_POST['reset_session'])){
245 header ("Location: logout.php");
246 exit;
247 }
249 if (isset($_POST['cancel_lock'])){
250 session::un_set('dn');
251 }
252 }
255 /* Load department list when plugin has changed. That is some kind of
256 compromise between speed and beeing up to date */
257 if (isset($_GET['reset'])){
258 if (session::is_set('objectinfo')){
259 session::un_set('objectinfo');
260 }
261 }
263 /* Install eGOsa hooks, convert _POST to session */
264 if(isset($_GET['explorer'])){
265 session::set('eGosa',TRUE);
266 }
267 if(session::is_set('POST')){
268 $_SERVER["REQUEST_METHOD"] = "POST";
269 foreach (session::get('POST') as $key => $dummy){
270 $_POST[$key]= $dummy;
271 }
272 session::un_set('POST');
273 }
275 /* show web frontend */
276 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
277 $smarty->assign ("must", "<font class=\"must\">*</font>");
278 if (isset($plug)){
279 $plug= "?plug=$plug";
280 } else {
281 $plug= "";
282 }
283 if (session::get('js')==FALSE){
284 $smarty->assign("javascript", "false");
285 $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
286 } else {
287 $smarty->assign("javascript", "true");
288 $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
289 }
291 if($ui->ignore_acl_for_current_user()){
292 $smarty->assign ("username", "<font color='#FF0000';>"._("User ACL checks disabled")."</font> ".$ui->username);
293 }else{
294 $smarty->assign ("username", $ui->username);
295 }
296 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
297 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
298 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
299 $smarty->assign ("go_out", get_template_path('images/logout.png'));
300 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
301 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
302 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
303 $smarty->assign ("go_help", get_template_path('images/help.png'));
305 /* reload navigation if language changed*/
306 if($reload_navigation){
307 $plist->menu="";
308 }
309 $plist->gen_headlines();
310 $plist->gen_menu();
311 $smarty->assign ("menu", $plist->menu);
312 $smarty->assign ("plug", "$plug");
314 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
316 /* React on clicks */
317 if ($_SERVER["REQUEST_METHOD"] == "POST"){
319 /* 'delete_lock' is set by the lock removal dialog. We should remove the
320 lock at this point globally. Plugins do not need to remove it. */
321 if (isset($_POST['delete_lock']) && session::is_set('dn')){
322 del_lock (session::get('dn'));
324 /* Set old Post data */
325 if(session::is_set('LOCK_VARS_USED')){
326 foreach(session::get('LOCK_VARS_USED') as $name => $value){
327 $_GET[$name] = $value;
328 $_POST[$name] = $value;
329 }
330 }
331 session::un_set ('dn');
332 }
335 /* I don't want multiple browser windows open. One way to check it is
336 to count a hidden field and warn the user if SESSION and INPUT count
337 differ. */
338 if (isset($_POST['session_cnt'])){
339 if ($_POST['session_cnt'] != session::get('session_cnt')){
340 $smarty->display(get_template_path('conflict.tpl'));
341 exit ();
342 }
343 session::set('session_cnt', (session::get('session_cnt') + 1));
344 session::set('post_cnt' , validate($_POST['session_cnt']) + 1);
345 }
346 }
348 /* Only generate hidden click counter, if post_cnt is defined */
349 if (session::is_set('post_cnt')){
350 echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".session::get('post_cnt')."\">\n";
351 }
353 /* check if we are using account expiration */
354 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
355 preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
357 $expired= ldap_expired_account($config, $ui->dn, $ui->username);
359 if ($expired == 2){
360 new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
361 msg_dialog::display(_("Password change"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
362 }
363 }
365 /* Load plugin */
366 if (is_file("$plugin_dir/main.inc")){
367 require_once ("$plugin_dir/main.inc");
368 } else {
369 msg_dialog::display(
370 _("Plugin"),
371 sprintf(_("FATAL: Cannot find any plugin definitions for plugin '%s'!"), $plug),
372 FATAL_ERROR_DIALOG);
373 exit();
374 }
377 /* Print_out last ErrorMessage repeated string. */
378 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
379 $smarty->assign("contents", $display);
381 /* Assign erros to smarty */
382 if (session::is_set('errors')){
383 $smarty->assign("errors", session::get('errors'));
384 }
385 if ($error_collector != ""){
386 $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
387 } else {
388 $smarty->assign("php_errors", "");
389 }
391 /* Set focus to the error button if we've an error message */
392 $focus= "";
393 if (session::is_set('errors') && session::get('errors') != ""){
394 $focus= '<script language="JavaScript" type="text/javascript">';
395 $focus.= 'document.forms[0].error_accept.focus();';
396 $focus.= '</script>';
397 }
399 $focus= '<script language="JavaScript" type="text/javascript">';
400 $focus.= 'next_msg_dialog();';
401 $focus.= '</script>';
402 $smarty->assign("focus", $focus);
404 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
406 /* Save dialog filters and selected base in a cookie.
407 So we may be able to restore the filter an base settings on reload.
408 */
409 $cookie = array();
411 if(isset($_COOKIE['GOsa_Filter_Settings'])){
412 $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
413 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
414 $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
415 }
416 if(isset($config->data['MAIN']['SAVE_FILTER']) && preg_match("/true/",$config->data['MAIN']['SAVE_FILTER'])){
417 $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
418 foreach($cookie_vars as $var){
419 if(session::is_set($var)){
420 $cookie[$ui->dn][$var] = session::get($var);
421 }
422 }
423 if(isset($_GET['plug'])){
424 $cookie[$ui->dn]['plug'] = $_GET['plug'];
425 }
426 @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
427 }
429 /* Show page... */
430 echo $display;
432 /* Save plist and config */
433 session::set('plist',$plist);
434 session::set('config',$config);
435 session::set('errorsAlreadyPosted',array());
437 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
438 ?>