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 /* Set cookie lifetime to one day (The parameter is in seconds ) */
38 session_set_cookie_params(24*60*60);
40 /* Set cache limter to one day (parameter is minutes !!)*/
41 session_cache_expire(60*24); // default is 180
43 /* Set session max lifetime, to prevent the garbage collector to delete session before timeout.
44 !! The garbage collector is a cron job on debian systems, the cronjob will fetch the timeout from
45 the php.ini, so if you use debian, you must hardcode session.gc_maxlifetime in your php.ini */
46 ini_set("session.gc_maxlifetime",24*60*60);
48 /* Remember everything we did after the last click */
49 session_start ();
51 $_SESSION['limit_exceeded'] =FALSE;
53 if ($_SERVER["REQUEST_METHOD"] == "POST"){
54 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
55 }
56 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_SESSION, "_SESSION");
58 /* Logged in? Simple security check */
59 if (!isset($_SESSION['config'])){
60 new log("security","login","",array(),"main.php called without session - logging out") ;
61 header ("Location: logout.php");
62 exit;
63 }
65 /* Check for uniqe ip address */
66 $ui= $_SESSION["ui"];
67 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
68 new log("security","login","",array(),"main.php called with session which has a changed IP address.") ;
69 header ("Location: logout.php");
70 exit;
71 }
72 $config= $_SESSION['config'];
73 $config->check_and_reload();
75 /* Enable compressed output */
76 if (isset($config->data['MAIN']['COMPRESSED']) && preg_match('/^(true|on)$/i', $config->data['MAIN']['COMPRESSED'])){
77 ob_start("ob_gzhandler");
78 }
80 /* Check for invalid sessions */
81 if(empty($_SESSION['_LAST_PAGE_REQUEST'])){
82 $_SESSION['_LAST_PAGE_REQUEST']= time();
83 }else{
85 /* check GOsa.conf for defined session lifetime */
86 if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
87 $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
88 }else{
89 $max_life = 60*60*2;
90 }
92 /* get time difference between last page reload */
93 $request_time = (time()-$_SESSION['_LAST_PAGE_REQUEST']);
95 /* If page wasn't reloaded for more than max_life seconds
96 * kill session
97 */
98 if($request_time > $max_life){
99 session_unset();
100 new log("security","login","",array(),"main.php called without session - logging out") ;
101 header ("Location: logout.php");
102 exit;
103 }
104 $_SESSION['_LAST_PAGE_REQUEST'] = time();
105 }
108 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
110 /* Set template compile directory */
111 if (isset ($config->data['MAIN']['COMPILE'])){
112 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
113 } else {
114 $smarty->compile_dir= '/var/spool/gosa/';
115 }
117 /* Set default */
118 $reload_navigation = false;
120 /* Set last initialised language to current, browser settings */
121 if((!isset($_SESSION['Last_init_lang']))){
122 $reload_navigation = true;
123 $_SESSION['Last_init_lang'] = get_browser_language();
124 }
126 /* If last language != current force navi reload */
127 $lang= get_browser_language();
128 if($_SESSION['Last_init_lang'] != $lang){
129 $reload_navigation = true;
130 }
132 /* Language setup */
133 $_SESSION['Last_init_lang'] = $lang;
135 /* Preset current main base */
136 if(!isset($_SESSION['CurrentMainBase'])){
137 $_SESSION['CurrentMainBase']= get_base_from_people($ui->dn);
138 }
140 putenv("LANGUAGE=");
141 putenv("LANG=$lang");
142 setlocale(LC_ALL, $lang);
143 $GLOBALS['t_language']= $lang;
144 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
146 /* Set the text domain as 'messages' */
147 $domain = 'messages';
148 bindtextdomain($domain, "$BASE_DIR/locale");
149 textdomain($domain);
150 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
152 /* Prepare plugin list */
153 if (!isset($_SESSION['plist'])){
154 /* Initially load all classes */
155 $class_list= get_declared_classes();
156 foreach ($class_mapping as $class => $path){
157 if (!in_array($class, $class_list)){
158 require_once("$BASE_DIR/$path");
159 }
160 }
162 $_SESSION['plist']= new pluglist($config, $ui);
164 /* Load ocMapping into userinfo */
165 $tmp= new acl($config, NULL, $ui->dn);
166 $ui->ocMapping= $tmp->ocMapping;
167 $_SESSION['ui']= $ui;
168 }
169 $plist= $_SESSION['plist'];
171 /* Check for register globals */
172 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
173 echo _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator.");
174 new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
175 session_destroy ();
176 exit ();
177 }
179 /* Check Plugin variable */
180 if (isset($_SESSION['plugin_dir'])){
181 $old_plugin_dir= $_SESSION['plugin_dir'];
182 } else {
183 $old_plugin_dir= "";
184 }
185 if (isset($_GET['plug'])){
186 $plug= validate($_GET['plug']);
187 $plugin_dir= $plist->get_path($plug);
188 $_SESSION['plugin_dir']= $plugin_dir;
189 if ($plugin_dir == ""){
190 new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
191 header ("Location: logout.php");
192 exit;
193 }
194 } else {
195 /* set to welcome page as default plugin */
196 $_SESSION['plugin_dir']= "welcome";
197 $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
198 }
200 /* Check if we need to delete a lock */
201 if ($old_plugin_dir != $plugin_dir){
202 if (is_file("$old_plugin_dir/main.inc")){
203 $remove_lock= true;
204 require_once ("$old_plugin_dir/main.inc");
205 }
206 }
207 $remove_lock= false;
209 /* Check for sizelimits */
210 eval_sizelimit();
212 /* Check for memory */
213 if (function_exists("memory_get_usage")){
214 if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
215 print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
216 }
217 }
219 /* Redirect on back event */
220 if ($_SERVER["REQUEST_METHOD"] == "POST"){
222 /* Look for button events that match /^back[0-9]+$/,
223 extract the number and step the correct plugin. */
224 foreach ($_POST as $key => $value){
225 if (preg_match("/^back[0-9]+$/", $key)){
226 $back= substr($key, 4);
227 header ("Location: main.php?plug=$back");
228 exit;
229 }
230 }
231 }
233 /* Redirect on password back event */
234 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
235 header ("Location: main.php");
236 exit;
237 }
239 /* Check for multiple windows logout */
240 if ($_SERVER["REQUEST_METHOD"] == "POST"){
241 if (isset($_POST['reset_session'])){
242 header ("Location: logout.php");
243 exit;
244 }
246 if (isset($_POST['cancel_lock'])){
247 unset ($_SESSION['dn']);
248 }
249 }
252 /* Load department list when plugin has changed. That is some kind of
253 compromise between speed and beeing up to date */
254 if (isset($_GET['reset'])){
255 if (isset($_SESSION['objectinfo'])){
256 unset ($_SESSION['objectinfo']);
257 }
258 }
260 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
261 if(isset($_GET['explorer'])){
262 $_SESSION{'eGosa'}=1;
263 }
264 if(isset($_SESSION['POST'])){
265 $_SERVER["REQUEST_METHOD"] = "POST";
266 foreach ($_SESSION['POST'] as $key => $dummy){
267 $_POST[$key]=$_SESSION['POST'][$key];
268 }
269 unset($_SESSION['POST']);
270 }
272 /* show web frontend */
273 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
274 $smarty->assign ("must", "<font class=\"must\">*</font>");
275 if (isset($plug)){
276 $plug= "?plug=$plug";
277 } else {
278 $plug= "";
279 }
280 if ($_SESSION['js']==FALSE){
281 $smarty->assign("javascript", "false");
282 $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
283 } else {
284 $smarty->assign("javascript", "true");
285 $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
286 }
288 $smarty->assign ("username", $ui->username);
289 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
290 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
291 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
292 $smarty->assign ("go_out", get_template_path('images/stop.png'));
293 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
294 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
295 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
296 $smarty->assign ("go_help", get_template_path('images/help.png'));
298 /* reload navigation if language changed*/
299 if($reload_navigation){
300 $plist->menu="";;
301 }
302 $plist->gen_headlines();
303 $plist->gen_menu();
304 $smarty->assign ("menu", $plist->menu);
305 $smarty->assign ("plug", "$plug");
307 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
309 /* React on clicks */
310 if ($_SERVER["REQUEST_METHOD"] == "POST"){
312 /* 'delete_lock' is set by the lock removal dialog. We should remove the
313 lock at this point globally. Plugins do not need to remove it. */
314 if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
315 del_lock ($_SESSION['dn']);
317 /* Set old Post data */
318 if(isset($_SESSION['LOCK_VARS_USED'])){
319 foreach($_SESSION['LOCK_VARS_USED'] as $name => $value){
320 $_GET[$name] = $value;
321 $_POST[$name] = $value;
322 }
323 }
324 sess_del ('dn');
325 }
328 /* I don't want multiple browser windows open. One way to check it is
329 to count a hidden field and warn the user if SESSION and INPUT count
330 differ. */
331 if (isset($_POST['session_cnt'])){
332 if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
333 $smarty->display(get_template_path('conflict.tpl'));
334 exit ();
335 }
336 $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
337 $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
338 }
339 }
341 /* Only generate hidden click counter, if post_cnt is defined */
342 if (isset ($_SESSION['post_cnt'])){
343 echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
344 }
346 /* check if we are using account expiration */
347 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
348 preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
350 $expired= ldap_expired_account($config, $ui->dn, $ui->username);
352 if ($expired == 2){
353 new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
354 print_red(_("Your password is about to expire, please change your password"));
355 }
356 }
358 /* Load plugin */
359 if (is_file("$plugin_dir/main.inc")){
360 require_once ("$plugin_dir/main.inc");
361 } else {
362 echo sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug);
363 exit();
364 }
367 /* Print_out last ErrorMessage repeated string. */
368 if(isset($_GET['add'])){
369 msg_dialog::display("Error" ,"Kann datei nicht schreiben, bla",ERROR_DIALOG);
370 msg_dialog::display("Warning" ,"Kann datei nicht schreiben, bla",WARNING_DIALOG);
371 msg_dialog::display("Info" ,"Kann datei nicht schreiben, bla",INFO_DIALOG);
372 msg_dialog::display("Confirm" ,"Kann datei nicht schreiben, bla",CONFIRM_DIALOG);
373 }
375 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
376 $smarty->assign("contents", $display);
378 /* Assign erros to smarty */
379 if (isset($_SESSION['errors'])){
380 $smarty->assign("errors", $_SESSION['errors']);
381 }
382 if ($error_collector != ""){
383 $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
384 } else {
385 $smarty->assign("php_errors", "");
386 }
388 /* Set focus to the error button if we've an error message */
389 $focus= "";
390 if (isset($_SESSION['errors']) && $_SESSION['errors'] != ""){
391 $focus= '<script language="JavaScript" type="text/javascript">';
392 $focus.= 'document.forms[0].error_accept.focus();';
393 $focus.= '</script>';
394 }
396 $focus= '<script language="JavaScript" type="text/javascript">';
397 $focus.= 'next_msg_dialog();';
398 $focus.= '</script>';
399 $smarty->assign("focus", $focus);
401 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
403 /* Save dialog filters and selected base in a cookie.
404 So we may be able to restore the filter an base settings on reload.
405 */
406 $cookie = array();
408 if(isset($_COOKIE['GOsa_Filter_Settings'])){
409 $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
410 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
411 $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
412 }
413 if(isset($config->data['MAIN']['SAVE_FILTER']) && preg_match("/true/",$config->data['MAIN']['SAVE_FILTER'])){
414 $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
415 foreach($cookie_vars as $var){
416 if(isset($_SESSION[$var])){
417 $cookie[$ui->dn][$var] = $_SESSION[$var];
418 }
419 }
420 if(isset($_GET['plug'])){
421 $cookie[$ui->dn]['plug'] = $_GET['plug'];
422 }
423 setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
424 }
426 /* Show page... */
427 echo $display;
429 /* Save plist and config */
430 $_SESSION['plist']= $plist;
431 $_SESSION['config']= $config;
432 $_SESSION['errorsAlreadyPosted']= array();
434 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
435 ?>