1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 /* Save start time */
22 $start = microtime();
24 /* Basic setup, remove eventually registered sessions */
25 require_once ("../include/php_setup.inc");
26 require_once ("functions.inc");
28 /* Set header */
29 header("Content-type: text/html; charset=UTF-8");
31 /* Set the text domain as 'messages' */
32 $domain = 'messages';
33 bindtextdomain($domain, LOCALE_DIR);
34 textdomain($domain);
36 /* Remember everything we did after the last click */
37 session::start();
38 session::set('errorsAlreadyPosted',array());
39 session::set('limit_exceeded',FALSE);
41 if ($_SERVER["REQUEST_METHOD"] == "POST"){
42 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
43 }
44 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, session::get_all(), "_SESSION");
46 /* Logged in? Simple security check */
47 if (!session::is_set('config')){
48 new log("security","login","",array(),"main.php called without session - logging out") ;
49 header ("Location: logout.php");
50 exit;
51 }
53 /* Check for uniqe ip address */
54 $ui= session::get('ui');
55 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
56 new log("security","login","",array(),"main.php called with session which has a changed IP address.") ;
57 header ("Location: logout.php");
58 exit;
59 }
60 $config= session::get('config');
61 $config->check_and_reload();
63 /* Enable compressed output */
64 if (isset($config->data['MAIN']['COMPRESSED']) && preg_match('/^(true|on)$/i', $config->data['MAIN']['COMPRESSED'])){
65 ob_start("ob_gzhandler");
66 }
68 /* Check for invalid sessions */
69 if(session::get('_LAST_PAGE_REQUEST') == ""){
70 session::set('_LAST_PAGE_REQUEST',time());
71 }else{
73 /* check GOsa.conf for defined session lifetime */
74 if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
75 $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
76 }else{
77 $max_life = 60*60*2;
78 }
80 /* get time difference between last page reload */
81 $request_time = (time()- session::get('_LAST_PAGE_REQUEST'));
83 /* If page wasn't reloaded for more than max_life seconds
84 * kill session
85 */
86 if($request_time > $max_life){
87 session::destroy();
88 new log("security","login","",array(),"main.php called without session - logging out") ;
89 header ("Location: logout.php");
90 exit;
91 }
92 session::set('_LAST_PAGE_REQUEST',time());
93 }
96 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
98 /* Set template compile directory */
99 if (isset ($config->data['MAIN']['COMPILE'])){
100 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
101 } else {
102 $smarty->compile_dir= '/var/spool/gosa/';
103 }
105 /* Set default */
106 $reload_navigation = false;
108 /* Set last initialised language to current, browser settings */
109 if(!session::is_set('Last_init_lang')){
110 $reload_navigation = true;
111 session::set('Last_init_lang',get_browser_language());
112 }
114 /* If last language != current force navi reload */
115 $lang= get_browser_language();
116 if(session::get('Last_init_lang') != $lang){
117 $reload_navigation = true;
118 }
120 /* Language setup */
121 session::set('Last_init_lang',$lang);
123 /* Preset current main base */
124 if(!session::is_set('CurrentMainBase')){
125 session::set('CurrentMainBase',get_base_from_people($ui->dn));
126 }
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 /* 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::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(_("Could not location file."),
150 sprintf(_("Fatal error: 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::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::set('ui',$ui);
163 }
164 $plist= session::get('plist');
165 /* Check for register globals */
166 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
167 msg_dialog::display(
168 _("PHP configuration"),
169 _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."),
170 FATAL_ERROR_DIALOG);
172 new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
173 session::destroy ();
174 exit;
175 }
177 /* Check Plugin variable */
178 if (session::is_set('plugin_dir')){
179 $old_plugin_dir= session::get('plugin_dir');
180 } else {
181 $old_plugin_dir= "";
182 }
183 if (isset($_GET['plug'])){
184 $plug= validate($_GET['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 {
194 /* set to welcome page as default plugin */
195 session::set('plugin_dir',"welcome");
196 $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
197 }
199 /* Check if we need to delete a lock */
200 if ($old_plugin_dir != $plugin_dir){
201 if (is_file("$old_plugin_dir/main.inc")){
202 $remove_lock= true;
203 require_once ("$old_plugin_dir/main.inc");
204 }
205 }
206 $remove_lock= false;
208 /* Check for sizelimits */
209 eval_sizelimit();
211 /* Check for memory */
212 if (function_exists("memory_get_usage")){
213 if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
214 msg_dialog::display(_("Configuration warning"), _("Running out of memory!"), WARNING_DIALOG);
215 }
216 }
218 /* Redirect on back event */
219 if ($_SERVER["REQUEST_METHOD"] == "POST"){
221 /* Look for button events that match /^back[0-9]+$/,
222 extract the number and step the correct plugin. */
223 foreach ($_POST as $key => $value){
224 if (preg_match("/^back[0-9]+$/", $key)){
225 $back= substr($key, 4);
226 header ("Location: main.php?plug=$back");
227 exit;
228 }
229 }
230 }
232 /* Redirect on password back event */
233 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
234 header ("Location: main.php");
235 exit;
236 }
238 /* Check for multiple windows logout */
239 if ($_SERVER["REQUEST_METHOD"] == "POST"){
240 if (isset($_POST['reset_session'])){
241 header ("Location: logout.php");
242 exit;
243 }
245 if (isset($_POST['cancel_lock'])){
246 session::un_set('dn');
247 }
248 }
251 /* Load department list when plugin has changed. That is some kind of
252 compromise between speed and beeing up to date */
253 if (isset($_GET['reset'])){
254 if (session::is_set('objectinfo')){
255 session::un_set('objectinfo');
256 }
257 }
259 /* Install eGOsa hooks, convert _POST to session */
260 if(isset($_GET['explorer'])){
261 session::set('eGosa',TRUE);
262 }
263 if(session::is_set('POST')){
264 $_SERVER["REQUEST_METHOD"] = "POST";
265 foreach (session::get('POST') as $key => $dummy){
266 $_POST[$key]= $dummy;
267 }
268 session::un_set('POST');
269 }
271 /* show web frontend */
272 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
273 $smarty->assign ("must", "<font class=\"must\">*</font>");
274 if (isset($plug)){
275 $plug= "?plug=$plug";
276 } else {
277 $plug= "";
278 }
279 if (session::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');\"");
285 }
287 $smarty->assign ("username", $ui->username);
288 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
289 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
290 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
291 $smarty->assign ("go_out", get_template_path('images/stop.png'));
292 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
293 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
294 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
295 $smarty->assign ("go_help", get_template_path('images/help.png'));
297 /* reload navigation if language changed*/
298 if($reload_navigation){
299 $plist->menu="";
300 }
301 $plist->gen_headlines();
302 $plist->gen_menu();
303 $smarty->assign ("menu", $plist->menu);
304 $smarty->assign ("plug", "$plug");
306 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
308 /* React on clicks */
309 if ($_SERVER["REQUEST_METHOD"] == "POST"){
311 /* 'delete_lock' is set by the lock removal dialog. We should remove the
312 lock at this point globally. Plugins do not need to remove it. */
313 if (isset($_POST['delete_lock']) && session::is_set('dn')){
314 del_lock (session::get('dn'));
316 /* Set old Post data */
317 if(session::is_set('LOCK_VARS_USED')){
318 foreach(session::get('LOCK_VARS_USED') as $name => $value){
319 $_GET[$name] = $value;
320 $_POST[$name] = $value;
321 }
322 }
323 session::un_set ('dn');
324 }
327 /* I don't want multiple browser windows open. One way to check it is
328 to count a hidden field and warn the user if SESSION and INPUT count
329 differ. */
330 if (isset($_POST['session_cnt'])){
331 if ($_POST['session_cnt'] != session::get('session_cnt')){
332 $smarty->display(get_template_path('conflict.tpl'));
333 exit ();
334 }
335 session::set('session_cnt', (session::get('session_cnt') + 1));
336 session::set('post_cnt' , validate($_POST['session_cnt']) + 1);
337 }
338 }
340 /* Only generate hidden click counter, if post_cnt is defined */
341 if (session::is_set('post_cnt')){
342 echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".session::get('post_cnt')."\">\n";
343 }
345 /* check if we are using account expiration */
346 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
347 preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
349 $expired= ldap_expired_account($config, $ui->dn, $ui->username);
351 if ($expired == 2){
352 new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
353 msg_dialog::display(_("Password reminder"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
354 }
355 }
357 /* Load plugin */
358 if (is_file("$plugin_dir/main.inc")){
359 require_once ("$plugin_dir/main.inc");
360 } else {
361 msg_dialog::display(
362 _("Plugin"),
363 sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug),
364 FATAL_ERROR_DIALOG);
365 exit();
366 }
369 /* Print_out last ErrorMessage repeated string. */
370 if(isset($_GET['add'])){
371 msg_dialog::display("Error" ,"Kann datei nicht schreiben, bla",ERROR_DIALOG);
372 msg_dialog::display("Warning" ,"Kann datei nicht schreiben, bla",WARNING_DIALOG);
373 msg_dialog::display("Info" ,"Kann datei nicht schreiben, bla",INFO_DIALOG);
374 msg_dialog::display("Confirm" ,"Kann datei nicht schreiben, bla",CONFIRM_DIALOG);
375 }
377 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
378 $smarty->assign("contents", $display);
380 /* Assign erros to smarty */
381 if (session::is_set('errors')){
382 $smarty->assign("errors", session::get('errors'));
383 }
384 if ($error_collector != ""){
385 $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
386 } else {
387 $smarty->assign("php_errors", "");
388 }
390 /* Set focus to the error button if we've an error message */
391 $focus= "";
392 if (session::is_set('errors') && session::get('errors') != ""){
393 $focus= '<script language="JavaScript" type="text/javascript">';
394 $focus.= 'document.forms[0].error_accept.focus();';
395 $focus.= '</script>';
396 }
398 $focus= '<script language="JavaScript" type="text/javascript">';
399 $focus.= 'next_msg_dialog();';
400 $focus.= '</script>';
401 $smarty->assign("focus", $focus);
403 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
405 /* Save dialog filters and selected base in a cookie.
406 So we may be able to restore the filter an base settings on reload.
407 */
408 $cookie = array();
410 if(isset($_COOKIE['GOsa_Filter_Settings'])){
411 $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
412 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
413 $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
414 }
415 if(isset($config->data['MAIN']['SAVE_FILTER']) && preg_match("/true/",$config->data['MAIN']['SAVE_FILTER'])){
416 $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
417 foreach($cookie_vars as $var){
418 if(session::is_set($var)){
419 $cookie[$ui->dn][$var] = session::get($var);
420 }
421 }
422 if(isset($_GET['plug'])){
423 $cookie[$ui->dn]['plug'] = $_GET['plug'];
424 }
425 @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
426 }
428 /* Show page... */
429 echo $display;
431 /* Save plist and config */
432 session::set('plist',$plist);
433 session::set('config',$config);
434 session::set('errorsAlreadyPosted',array());
436 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
437 ?>