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 /* Basic setup, remove eventually registered sessions */
22 $start = microtime();
23 $timing= array();
24 require_once ("../include/php_setup.inc");
25 require_once ("functions.inc");
26 header("Content-type: text/html; charset=UTF-8");
28 /* Find all class files and include them */
29 get_dir_list("$BASE_DIR/plugins");
31 /* Set the text domain as 'messages' */
32 $domain = 'messages';
33 bindtextdomain($domain, "$BASE_DIR/locale");
34 textdomain($domain);
36 /* Set cookie lifetime to one day (The parameter is in seconds ) */
37 session_set_cookie_params(24*60*60);
39 /* Set cache limter to one day (parameter is minutes !!)*/
40 session_cache_expire(60*24); // default is 180
42 /* Set session max lifetime, to prevent the garbage collector to delete session before timeout.
43 !! The garbage collector is a cron job on debian systems, the cronjob will fetch the timeout from
44 the php.ini, so if you use debian, you must hardcode session.gc_maxlifetime in your php.ini */
45 ini_set("session.gc_maxlifetime",24*60*60);
47 /* Remember everything we did after the last click */
48 session_start ();
50 $_SESSION['limit_exceeded'] =FALSE;
52 if ($_SERVER["REQUEST_METHOD"] == "POST"){
53 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
54 }
55 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_SESSION, "_SESSION");
57 /* Logged in? Simple security check */
58 if (!isset($_SESSION['config'])){
59 gosa_log ("main.php called without session - logging out");
60 header ("Location: logout.php");
61 exit;
62 }
64 /* Reset errors */
65 $_SESSION['errors'] = "";
66 $_SESSION['errorsAlreadyPosted']= array();
67 $_SESSION['LastError'] = "";
69 /* Check for uniqe ip address */
70 $ui= $_SESSION["ui"];
71 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
72 gosa_log ("main.php called with session which has a changed IP address.", 3);
73 header ("Location: logout.php");
74 exit;
75 }
76 $config= $_SESSION['config'];
79 /* Check for invalid sessions */
80 if(empty($_SESSION['_LAST_PAGE_REQUEST'])){
81 $_SESSION['_LAST_PAGE_REQUEST']= time();
82 }else{
84 /* check GOsa.conf for defined session lifetime */
85 if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
86 $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
87 }else{
88 $max_life = 60*60*2;
89 }
91 /* get time difference between last page reload */
92 $request_time = (time()-$_SESSION['_LAST_PAGE_REQUEST']);
94 /* If page wasn't reloaded for more than max_life seconds
95 * kill session
96 */
97 if($request_time > $max_life){
98 session_unset();
99 gosa_log ("main.php called without session - logging out");
100 header ("Location: logout.php");
101 exit;
102 }
103 // echo "Session was ".$request_time." s inactive";
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 /* Language setup */
127 if ($config->data['MAIN']['LANG'] == ""){
129 /* If last language != current force navi reload */
130 if($_SESSION['Last_init_lang'] != get_browser_language()){
131 $reload_navigation = true;
132 }
133 $lang= get_browser_language();
134 $_SESSION['Last_init_lang'] = $lang;
135 } else {
136 $lang= $config->data['MAIN']['LANG'];
137 }
139 $lang.=".UTF-8";
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 $_SESSION['plist']= new pluglist($config, $ui);
155 }
156 $plist= $_SESSION['plist'];
158 /* Check for register globals */
159 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
160 print_red (_("Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."));
161 echo $_SESSION['errors'];
162 gosa_log ("Register globals is on. For security reasons, this should be turned off.");
163 session_destroy ();
164 exit ();
165 }
167 /* Check Plugin variable */
168 if (isset($_SESSION['plugin_dir'])){
169 $old_plugin_dir= $_SESSION['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['plugin_dir']= $plugin_dir;
177 if ($plugin_dir == ""){
178 gosa_log ("main.php called with invalid plug parameter \"$plug\"", 3);
179 header ("Location: logout.php");
180 exit;
181 }
182 } else {
183 /* set to welcome page as default plugin */
184 $_SESSION['plugin_dir']= "welcome";
185 $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
186 }
188 /* Check if we need to delete a lock */
189 if ($old_plugin_dir != $plugin_dir){
190 if (is_file("$old_plugin_dir/main.inc")){
191 $remove_lock= true;
192 require_once ("$old_plugin_dir/main.inc");
193 }
194 }
195 $remove_lock= false;
197 /* Check for sizelimits */
198 eval_sizelimit();
200 /* Check for memory */
201 if (function_exists("memory_get_usage")){
202 if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
203 print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
204 }
205 }
207 /* Redirect on back event */
208 if ($_SERVER["REQUEST_METHOD"] == "POST"){
210 /* Look for button events that match /^back[0-9]+$/,
211 extract the number and step the correct plugin. */
212 foreach ($_POST as $key => $value){
213 if (preg_match("/^back[0-9]+$/", $key)){
214 $back= substr($key, 4);
215 header ("Location: main.php?plug=$back");
216 exit;
217 }
218 }
219 }
221 /* Redirect on password back event */
222 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
223 header ("Location: main.php");
224 exit;
225 }
227 /* Check for multiple windows logout */
228 if ($_SERVER["REQUEST_METHOD"] == "POST"){
229 if (isset($_POST['reset_session'])){
230 header ("Location: logout.php");
231 exit;
232 }
234 if (isset($_POST['cancel_lock'])){
235 unset ($_SESSION['dn']);
236 }
237 }
240 /* Load department list when plugin has changed. That is some kind of
241 compromise between speed and beeing up to date */
242 if (isset($_GET['reset'])){
243 if (isset($_SESSION['objectinfo'])){
244 unset ($_SESSION['objectinfo']);
245 }
246 }
248 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
249 if(isset($_GET['explorer'])){
250 $_SESSION{'eGosa'}=1;
251 }
252 if(isset($_SESSION['POST'])){
253 $_SERVER["REQUEST_METHOD"] = "POST";
254 foreach ($_SESSION['POST'] as $key => $dummy){
255 $_POST[$key]=$_SESSION['POST'][$key];
256 }
257 unset($_SESSION['POST']);
258 }
260 /* show web frontend */
261 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
262 $smarty->assign ("must", "<font class=\"must\">*</font>");
263 if (isset($plug)){
264 $plug= "?plug=$plug";
265 } else {
266 $plug= "";
267 }
268 if ($_SESSION['js']==FALSE){
269 $smarty->assign("javascript", "false");
270 $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
271 } else {
272 $smarty->assign("javascript", "true");
273 $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
274 }
276 $smarty->assign ("username", $ui->username);
277 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
278 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
279 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
280 $smarty->assign ("go_out", get_template_path('images/stop.png'));
281 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
282 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
283 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
284 $smarty->assign ("go_help", get_template_path('images/help.png'));
286 /* reload navigation if language changed*/
287 if($reload_navigation){
288 $plist->menu="";;
289 }
290 $plist->gen_headlines();
291 $plist->gen_menu();
292 $smarty->assign ("menu", $plist->menu);
293 $smarty->assign ("plug", "$plug");
295 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
297 /* React on clicks */
298 if ($_SERVER["REQUEST_METHOD"] == "POST"){
300 /* 'delete_lock' is set by the lock removal dialog. We should remove the
301 lock at this point globally. Plugins do not need to remove it. */
302 if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
303 del_lock ($_SESSION['dn']);
305 /* Set old Post data */
306 if(isset($_SESSION['LOCK_VARS_USED'])){
307 foreach($_SESSION['LOCK_VARS_USED'] as $name => $value){
308 $_GET[$name] = $value;
309 $_POST[$name] = $value;
310 }
311 }
312 sess_del ('dn');
313 }
316 /* I don't want multiple browser windows open. One way to check it is
317 to count a hidden field and warn the user if SESSION and INPUT count
318 differ. */
319 if (isset($_POST['session_cnt'])){
320 if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
321 $smarty->display(get_template_path('conflict.tpl'));
322 exit ();
323 }
324 $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
325 $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
326 }
327 }
329 /* Only generate hidden click counter, if post_cnt is defined */
330 if (isset ($_SESSION['post_cnt'])){
331 echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
332 }
334 /* Load plugin */
335 if (is_file("$plugin_dir/main.inc")){
336 require_once ("$plugin_dir/main.inc");
337 } else {
338 print_red(sprintf(_("Can't find any plugin definitions for plugin '%s'!"), $plug));
339 echo $_SESSION['errors'];
340 exit();
341 }
343 /* Close div/tables */
345 /* 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 gosa_log ("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 /* Print_out last ErrorMessage repeated string.
359 */
360 print_red(NULL);
362 $smarty->assign("contents", $display);
364 if (isset($_SESSION['errors'])){
365 $smarty->assign("errors", $_SESSION['errors']);
366 }
367 if ($error_collector != ""){
368 $smarty->assign("php_errors", $error_collector."</div>");
369 } else {
370 $smarty->assign("php_errors", "");
371 }
372 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
374 if ((isset($config->data['MAIN']['W3CTEST']) && preg_match('/true/i', $config->data['MAIN']['W3CTEST']))&&(!empty($display))&&(is_callable("tidy_parse_string"))) {
375 tidy_parse_string(utf8_decode($display));
376 $err = nl2br(htmlentities(tidy_get_error_buffer()));
378 if($err){
379 echo "<table summary=\"\" width=\"100%\" style='background-color:#E0E0E0;border-bottom:1px solid black'><tr><td><img alt=\"W3C\" align=\"middle\" src='images/warning.png'> <font style='font-size:14px;font-weight:bold'>"._("Generating this page caused the W3C conformance checker to raise some errors!")."</font></td><td align=right><button onClick='toggle(\"w3cbox\")'>"._("Toggle information")."</ button></td></tr></table><div id='w3cbox' style='width:100%; position:absolute; z-index:0; visibility: hidden; background-color:white; border- bottom:1px solid black;'>";
380 echo $err."</div>";
381 }
383 tidy_clean_repair($display);
384 }
386 /* Show page... */
387 echo $display;
389 /* Save plist and config */
390 $_SESSION['plist']= $plist;
391 $_SESSION['config']= $config;
394 /* Echo compilation time * /
395 $r = split(" ",$start);
396 $ms = $r[0];
397 $s= $r[1];
399 $re = split(" ",microtime());
400 $mse = $re[0];
401 $se= $re[1];
403 $add = 0;
404 if(($mse -$ms)<0){
405 $se --;
406 $add = 1;
407 }
408 echo ($se -$s).",";
409 echo (int)(($add+($mse -$ms))*1000)." s";
410 */
411 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
412 ?>