56f5aa89749deaac493cb8287d31667e69116b3e
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");
27 require_once ("functions_FAI.inc");
29 /* Set header */
30 header("Content-type: text/html; charset=UTF-8");
32 /* Set the text domain as 'messages' */
33 $domain = 'messages';
34 bindtextdomain($domain, "$BASE_DIR/locale");
35 textdomain($domain);
37 /* Remember everything we did after the last click */
38 session::start();
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, "$BASE_DIR/locale");
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 require_once("$BASE_DIR/$path");
147 }
148 }
150 session::set('plist', new pluglist($config, $ui));
152 /* Load ocMapping into userinfo */
153 $tmp= new acl($config, NULL, $ui->dn);
154 $ui->ocMapping= $tmp->ocMapping;
155 session::set('ui',$ui);
156 }
157 $plist= session::get('plist');
159 /* Check for register globals */
160 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
161 echo _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator.");
162 new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
163 session::destroy ();
164 exit ();
165 }
167 /* Check Plugin variable */
168 if (session::is_set('plugin_dir')){
169 $old_plugin_dir= session::get('plugin_dir');
170 } else {
171 $old_plugin_dir= "";
172 }
173 if (isset($_GET['plug'])){
174 $plug= validate($_GET['plug']);
175 $plugin_dir= $plist->get_path($plug);
176 session::set('plugin_dir',$plugin_dir);
177 if ($plugin_dir == ""){
178 new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
179 header ("Location: logout.php");
180 exit;
181 }
182 } else {
184 /* set to welcome page as default plugin */
185 session::set('plugin_dir',"welcome");
186 $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
187 }
189 /* Check if we need to delete a lock */
190 if ($old_plugin_dir != $plugin_dir){
191 if (is_file("$old_plugin_dir/main.inc")){
192 $remove_lock= true;
193 require_once ("$old_plugin_dir/main.inc");
194 }
195 }
196 $remove_lock= false;
198 /* Check for sizelimits */
199 eval_sizelimit();
201 /* Check for memory */
202 if (function_exists("memory_get_usage")){
203 if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
204 msg_dialog::display(_("Configuration warning"), _("Running out of memory!"), WARNING_DIALOG);
205 }
206 }
208 /* Redirect on back event */
209 if ($_SERVER["REQUEST_METHOD"] == "POST"){
211 /* Look for button events that match /^back[0-9]+$/,
212 extract the number and step the correct plugin. */
213 foreach ($_POST as $key => $value){
214 if (preg_match("/^back[0-9]+$/", $key)){
215 $back= substr($key, 4);
216 header ("Location: main.php?plug=$back");
217 exit;
218 }
219 }
220 }
222 /* Redirect on password back event */
223 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
224 header ("Location: main.php");
225 exit;
226 }
228 /* Check for multiple windows logout */
229 if ($_SERVER["REQUEST_METHOD"] == "POST"){
230 if (isset($_POST['reset_session'])){
231 header ("Location: logout.php");
232 exit;
233 }
235 if (isset($_POST['cancel_lock'])){
236 session::un_set('dn');
237 }
238 }
241 /* Load department list when plugin has changed. That is some kind of
242 compromise between speed and beeing up to date */
243 if (isset($_GET['reset'])){
244 if (session::is_set('objectinfo')){
245 session::un_set('objectinfo');
246 }
247 }
249 /* Install eGOsa hooks, convert _POST to session */
250 if(isset($_GET['explorer'])){
251 session::set('eGosa',TRUE);
252 }
253 if(session::is_set('POST')){
254 $_SERVER["REQUEST_METHOD"] = "POST";
255 foreach (session::get('POST') as $key => $dummy){
256 $_POST[$key]= $dummy;
257 }
258 session::un_set('POST');
259 }
261 /* show web frontend */
262 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
263 $smarty->assign ("must", "<font class=\"must\">*</font>");
264 if (isset($plug)){
265 $plug= "?plug=$plug";
266 } else {
267 $plug= "";
268 }
269 if (session::get('js')==FALSE){
270 $smarty->assign("javascript", "false");
271 $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
272 } else {
273 $smarty->assign("javascript", "true");
274 $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
275 }
277 $smarty->assign ("username", $ui->username);
278 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
279 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
280 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
281 $smarty->assign ("go_out", get_template_path('images/stop.png'));
282 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
283 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
284 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
285 $smarty->assign ("go_help", get_template_path('images/help.png'));
287 /* reload navigation if language changed*/
288 if($reload_navigation){
289 $plist->menu="";;
290 }
291 $plist->gen_headlines();
292 $plist->gen_menu();
293 $smarty->assign ("menu", $plist->menu);
294 $smarty->assign ("plug", "$plug");
296 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
298 /* React on clicks */
299 if ($_SERVER["REQUEST_METHOD"] == "POST"){
301 /* 'delete_lock' is set by the lock removal dialog. We should remove the
302 lock at this point globally. Plugins do not need to remove it. */
303 if (isset($_POST['delete_lock']) && session::is_set('dn')){
304 del_lock (session::get('dn'));
306 /* Set old Post data */
307 if(session::is_set('LOCK_VARS_USED')){
308 foreach(session::get('LOCK_VARS_USED') as $name => $value){
309 $_GET[$name] = $value;
310 $_POST[$name] = $value;
311 }
312 }
313 session::un_set ('dn');
314 }
317 /* I don't want multiple browser windows open. One way to check it is
318 to count a hidden field and warn the user if SESSION and INPUT count
319 differ. */
320 if (isset($_POST['session_cnt'])){
321 if ($_POST['session_cnt'] != session::get('session_cnt')){
322 $smarty->display(get_template_path('conflict.tpl'));
323 exit ();
324 }
325 session::set('session_cnt', (session::get('session_cnt') + 1));
326 session::set('post_cnt' , validate($_POST['session_cnt']) + 1);
327 }
328 }
330 /* Only generate hidden click counter, if post_cnt is defined */
331 if (session::is_set('post_cnt')){
332 echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".session::get('post_cnt')."\">\n";
333 }
335 /* check if we are using account expiration */
336 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
337 preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
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 reminder"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
344 }
345 }
347 /* Load plugin */
348 if (is_file("$plugin_dir/main.inc")){
349 require_once ("$plugin_dir/main.inc");
350 } else {
351 echo sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug);
352 exit();
353 }
356 /* Print_out last ErrorMessage repeated string. */
357 if(isset($_GET['add'])){
358 msg_dialog::display("Error" ,"Kann datei nicht schreiben, bla",ERROR_DIALOG);
359 msg_dialog::display("Warning" ,"Kann datei nicht schreiben, bla",WARNING_DIALOG);
360 msg_dialog::display("Info" ,"Kann datei nicht schreiben, bla",INFO_DIALOG);
361 msg_dialog::display("Confirm" ,"Kann datei nicht schreiben, bla",CONFIRM_DIALOG);
362 }
364 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
365 $smarty->assign("contents", $display);
367 /* Assign erros to smarty */
368 if (session::is_set('errors')){
369 $smarty->assign("errors", session::get('errors'));
370 }
371 if ($error_collector != ""){
372 $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
373 } else {
374 $smarty->assign("php_errors", "");
375 }
377 /* Set focus to the error button if we've an error message */
378 $focus= "";
379 if (session::is_set('errors') && session::get('errors') != ""){
380 $focus= '<script language="JavaScript" type="text/javascript">';
381 $focus.= 'document.forms[0].error_accept.focus();';
382 $focus.= '</script>';
383 }
385 $focus= '<script language="JavaScript" type="text/javascript">';
386 $focus.= 'next_msg_dialog();';
387 $focus.= '</script>';
388 $smarty->assign("focus", $focus);
390 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
392 /* Save dialog filters and selected base in a cookie.
393 So we may be able to restore the filter an base settings on reload.
394 */
395 $cookie = array();
397 if(isset($_COOKIE['GOsa_Filter_Settings'])){
398 $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
399 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
400 $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
401 }
402 if(isset($config->data['MAIN']['SAVE_FILTER']) && preg_match("/true/",$config->data['MAIN']['SAVE_FILTER'])){
403 $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
404 foreach($cookie_vars as $var){
405 if(session::is_set($var)){
406 $cookie[$ui->dn][$var] = session::get($var);
407 }
408 }
409 if(isset($_GET['plug'])){
410 $cookie[$ui->dn]['plug'] = $_GET['plug'];
411 }
412 @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
413 }
415 /* Show page... */
416 echo $display;
418 /* Save plist and config */
419 session::set('plist',$plist);
420 session::set('config',$config);
421 session::set('errorsAlreadyPosted',array());
423 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
424 ?>