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 /* Find all class files and include them */
33 get_dir_list("$BASE_DIR/plugins");
35 /* Set the text domain as 'messages' */
36 $domain = 'messages';
37 bindtextdomain($domain, "$BASE_DIR/locale");
38 textdomain($domain);
40 /* Set cookie lifetime to one day (The parameter is in seconds ) */
41 session_set_cookie_params(24*60*60);
43 /* Set cache limter to one day (parameter is minutes !!)*/
44 session_cache_expire(60*24); // default is 180
46 /* Set session max lifetime, to prevent the garbage collector to delete session before timeout.
47 !! The garbage collector is a cron job on debian systems, the cronjob will fetch the timeout from
48 the php.ini, so if you use debian, you must hardcode session.gc_maxlifetime in your php.ini */
49 ini_set("session.gc_maxlifetime",24*60*60);
51 /* Remember everything we did after the last click */
52 session_start ();
54 $_SESSION['limit_exceeded'] =FALSE;
56 if ($_SERVER["REQUEST_METHOD"] == "POST"){
57 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
58 }
59 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_SESSION, "_SESSION");
61 /* Logged in? Simple security check */
62 if (!isset($_SESSION['config'])){
63 new log("security","login","",array(),"main.php called without session - logging out") ;
64 header ("Location: logout.php");
65 exit;
66 }
68 /* Reset errors */
69 $_SESSION['errors'] = "";
70 $_SESSION['errorsAlreadyPosted']= array();
71 $_SESSION['LastError'] = "";
73 /* Check for uniqe ip address */
74 $ui= $_SESSION["ui"];
75 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
76 new log("security","login","",array(),"main.php called with session which has a changed IP address.") ;
77 header ("Location: logout.php");
78 exit;
79 }
80 $config= $_SESSION['config'];
82 /* Check for invalid sessions */
83 if(empty($_SESSION['_LAST_PAGE_REQUEST'])){
84 $_SESSION['_LAST_PAGE_REQUEST']= time();
85 }else{
87 /* check GOsa.conf for defined session lifetime */
88 if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
89 $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
90 }else{
91 $max_life = 60*60*2;
92 }
94 /* get time difference between last page reload */
95 $request_time = (time()-$_SESSION['_LAST_PAGE_REQUEST']);
97 /* If page wasn't reloaded for more than max_life seconds
98 * kill session
99 */
100 if($request_time > $max_life){
101 session_unset();
102 new log("security","login","",array(),"main.php called without session - logging out") ;
103 header ("Location: logout.php");
104 exit;
105 }
106 $_SESSION['_LAST_PAGE_REQUEST'] = time();
107 }
110 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
112 /* Set template compile directory */
113 if (isset ($config->data['MAIN']['COMPILE'])){
114 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
115 } else {
116 $smarty->compile_dir= '/var/spool/gosa/';
117 }
119 /* Set default */
120 $reload_navigation = false;
122 /* Set last initialised language to current, browser settings */
123 if((!isset($_SESSION['Last_init_lang']))){
124 $reload_navigation = true;
125 $_SESSION['Last_init_lang'] = get_browser_language();
126 }
128 /* Language setup */
129 if ($config->data['MAIN']['LANG'] == ""){
131 /* If last language != current force navi reload */
132 if($_SESSION['Last_init_lang'] != get_browser_language()){
133 $reload_navigation = true;
134 }
135 $lang= get_browser_language();
136 $_SESSION['Last_init_lang'] = $lang;
137 } else {
138 $lang= $config->data['MAIN']['LANG'];
139 }
141 /* Preset current main base */
142 if(!isset($_SESSION['CurrentMainBase'])){
143 $_SESSION['CurrentMainBase']= get_base_from_people($ui->dn);
144 }
146 putenv("LANGUAGE=");
147 putenv("LANG=$lang");
148 setlocale(LC_ALL, $lang);
149 $GLOBALS['t_language']= $lang;
150 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
152 /* Set the text domain as 'messages' */
153 $domain = 'messages';
154 bindtextdomain($domain, "$BASE_DIR/locale");
155 textdomain($domain);
156 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
158 /* Prepare plugin list */
159 if (!isset($_SESSION['plist'])){
160 $_SESSION['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['ui']= $ui;
166 }
167 $plist= $_SESSION['plist'];
169 /* Check for register globals */
170 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
171 echo _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator.");
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 (isset($_SESSION['plugin_dir'])){
179 $old_plugin_dir= $_SESSION['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['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 {
193 /* set to welcome page as default plugin */
194 $_SESSION['plugin_dir']= "welcome";
195 $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
196 }
198 /* Check if we need to delete a lock */
199 if ($old_plugin_dir != $plugin_dir){
200 if (is_file("$old_plugin_dir/main.inc")){
201 $remove_lock= true;
202 require_once ("$old_plugin_dir/main.inc");
203 }
204 }
205 $remove_lock= false;
207 /* Check for sizelimits */
208 eval_sizelimit();
210 /* Check for memory */
211 if (function_exists("memory_get_usage")){
212 if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
213 print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
214 }
215 }
217 /* Redirect on back event */
218 if ($_SERVER["REQUEST_METHOD"] == "POST"){
220 /* Look for button events that match /^back[0-9]+$/,
221 extract the number and step the correct plugin. */
222 foreach ($_POST as $key => $value){
223 if (preg_match("/^back[0-9]+$/", $key)){
224 $back= substr($key, 4);
225 header ("Location: main.php?plug=$back");
226 exit;
227 }
228 }
229 }
231 /* Redirect on password back event */
232 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
233 header ("Location: main.php");
234 exit;
235 }
237 /* Check for multiple windows logout */
238 if ($_SERVER["REQUEST_METHOD"] == "POST"){
239 if (isset($_POST['reset_session'])){
240 header ("Location: logout.php");
241 exit;
242 }
244 if (isset($_POST['cancel_lock'])){
245 unset ($_SESSION['dn']);
246 }
247 }
250 /* Load department list when plugin has changed. That is some kind of
251 compromise between speed and beeing up to date */
252 if (isset($_GET['reset'])){
253 if (isset($_SESSION['objectinfo'])){
254 unset ($_SESSION['objectinfo']);
255 }
256 }
258 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
259 if(isset($_GET['explorer'])){
260 $_SESSION{'eGosa'}=1;
261 }
262 if(isset($_SESSION['POST'])){
263 $_SERVER["REQUEST_METHOD"] = "POST";
264 foreach ($_SESSION['POST'] as $key => $dummy){
265 $_POST[$key]=$_SESSION['POST'][$key];
266 }
267 unset($_SESSION['POST']);
268 }
270 /* show web frontend */
271 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
272 $smarty->assign ("must", "<font class=\"must\">*</font>");
273 if (isset($plug)){
274 $plug= "?plug=$plug";
275 } else {
276 $plug= "";
277 }
278 if ($_SESSION['js']==FALSE){
279 $smarty->assign("javascript", "false");
280 $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
281 } else {
282 $smarty->assign("javascript", "true");
283 $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
284 }
286 $smarty->assign ("username", $ui->username);
287 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
288 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
289 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
290 $smarty->assign ("go_out", get_template_path('images/stop.png'));
291 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
292 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
293 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
294 $smarty->assign ("go_help", get_template_path('images/help.png'));
296 /* reload navigation if language changed*/
297 if($reload_navigation){
298 $plist->menu="";;
299 }
300 $plist->gen_headlines();
301 $plist->gen_menu();
302 $smarty->assign ("menu", $plist->menu);
303 $smarty->assign ("plug", "$plug");
305 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
307 /* React on clicks */
308 if ($_SERVER["REQUEST_METHOD"] == "POST"){
310 /* 'delete_lock' is set by the lock removal dialog. We should remove the
311 lock at this point globally. Plugins do not need to remove it. */
312 if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
313 del_lock ($_SESSION['dn']);
315 /* Set old Post data */
316 if(isset($_SESSION['LOCK_VARS_USED'])){
317 foreach($_SESSION['LOCK_VARS_USED'] as $name => $value){
318 $_GET[$name] = $value;
319 $_POST[$name] = $value;
320 }
321 }
322 sess_del ('dn');
323 }
326 /* I don't want multiple browser windows open. One way to check it is
327 to count a hidden field and warn the user if SESSION and INPUT count
328 differ. */
329 if (isset($_POST['session_cnt'])){
330 if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
331 $smarty->display(get_template_path('conflict.tpl'));
332 exit ();
333 }
334 $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
335 $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
336 }
337 }
339 /* Only generate hidden click counter, if post_cnt is defined */
340 if (isset ($_SESSION['post_cnt'])){
341 echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
342 }
344 /* check if we are using account expiration */
345 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
346 preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
348 $expired= ldap_expired_account($config, $ui->dn, $ui->username);
350 if ($expired == 2){
351 new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
352 print_red(_("Your password is about to expire, please change your password"));
353 }
354 }
356 /* Load plugin */
357 if (is_file("$plugin_dir/main.inc")){
358 require_once ("$plugin_dir/main.inc");
359 } else {
360 echo sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug);
361 exit();
362 }
365 /* Print_out last ErrorMessage repeated string. */
367 $smarty->assign("contents", $display);
369 /* Assign erros to smarty */
370 if (isset($_SESSION['errors'])){
371 $smarty->assign("errors", $_SESSION['errors']);
372 }
373 if ($error_collector != ""){
374 $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
375 } else {
376 $smarty->assign("php_errors", "");
377 }
379 /* Set focus to the error button if we've an error message */
380 $focus= "";
381 if (isset($_SESSION['errors']) && $_SESSION['errors'] != ""){
382 $focus= '<script language="JavaScript" type="text/javascript">';
383 $focus.= 'document.forms[0].error_accept.focus();';
384 $focus.= '</script>';
385 }
386 $smarty->assign("focus", $focus);
388 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
390 /* Show page... */
391 echo $display;
393 /* Save plist and config */
394 $_SESSION['plist']= $plist;
395 $_SESSION['config']= $config;
397 /* Echo compilation time */
398 //echo "<p align='right'>".get_MicroTimeDiff($start,microtime())."</p>";
400 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
401 ?>