365763c9c3f639bdf34df1a41fc8ac4bdc443879
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 require_once ("functions_FAI.inc");
27 header("Content-type: text/html; charset=UTF-8");
29 /* Find all class files and include them */
30 get_dir_list("$BASE_DIR/plugins");
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 gosa_log ("main.php called without session - logging out");
61 header ("Location: logout.php");
62 exit;
63 }
65 /* Reset errors */
66 $_SESSION['errors'] = "";
67 $_SESSION['errorsAlreadyPosted']= array();
68 $_SESSION['LastError'] = "";
70 /* Check for uniqe ip address */
71 $ui= $_SESSION["ui"];
72 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
73 gosa_log ("main.php called with session which has a changed IP address.", 3);
74 header ("Location: logout.php");
75 exit;
76 }
77 $config= $_SESSION['config'];
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 gosa_log ("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 /* 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 /* Preset current main base */
140 if(!isset($_SESSION['CurrentMainBase'])){
141 $_SESSION['CurrentMainBase']= get_base_from_people($ui->dn);
142 }
144 $lang.=".UTF-8";
145 putenv("LANGUAGE=");
146 putenv("LANG=$lang");
147 setlocale(LC_ALL, $lang);
148 $GLOBALS['t_language']= $lang;
149 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
151 /* Set the text domain as 'messages' */
152 $domain = 'messages';
153 bindtextdomain($domain, "$BASE_DIR/locale");
154 textdomain($domain);
155 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
157 /* Prepare plugin list */
158 if (!isset($_SESSION['plist'])){
159 $_SESSION['plist']= new pluglist($config, $ui);
160 }
161 $plist= $_SESSION['plist'];
163 /* Check for register globals */
164 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
165 echo _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator.");
166 gosa_log ("Register globals is on. For security reasons, this should be turned off.");
167 session_destroy ();
168 exit ();
169 }
171 /* Check Plugin variable */
172 if (isset($_SESSION['plugin_dir'])){
173 $old_plugin_dir= $_SESSION['plugin_dir'];
174 } else {
175 $old_plugin_dir= "";
176 }
177 if (isset($_GET['plug'])){
178 $plug= validate($_GET['plug']);
179 $plugin_dir= $plist->get_path($plug);
180 $_SESSION['plugin_dir']= $plugin_dir;
181 if ($plugin_dir == ""){
182 gosa_log ("main.php called with invalid plug parameter \"$plug\"", 3);
183 header ("Location: logout.php");
184 exit;
185 }
186 } else {
187 /* set to welcome page as default plugin */
188 $_SESSION['plugin_dir']= "welcome";
189 $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
190 }
192 /* Check if we need to delete a lock */
193 if ($old_plugin_dir != $plugin_dir){
194 if (is_file("$old_plugin_dir/main.inc")){
195 $remove_lock= true;
196 require_once ("$old_plugin_dir/main.inc");
197 }
198 }
199 $remove_lock= false;
201 /* Check for sizelimits */
202 eval_sizelimit();
204 /* Check for memory */
205 if (function_exists("memory_get_usage")){
206 if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
207 print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
208 }
209 }
211 /* Redirect on back event */
212 if ($_SERVER["REQUEST_METHOD"] == "POST"){
214 /* Look for button events that match /^back[0-9]+$/,
215 extract the number and step the correct plugin. */
216 foreach ($_POST as $key => $value){
217 if (preg_match("/^back[0-9]+$/", $key)){
218 $back= substr($key, 4);
219 header ("Location: main.php?plug=$back");
220 exit;
221 }
222 }
223 }
225 /* Redirect on password back event */
226 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
227 header ("Location: main.php");
228 exit;
229 }
231 /* Check for multiple windows logout */
232 if ($_SERVER["REQUEST_METHOD"] == "POST"){
233 if (isset($_POST['reset_session'])){
234 header ("Location: logout.php");
235 exit;
236 }
238 if (isset($_POST['cancel_lock'])){
239 unset ($_SESSION['dn']);
240 }
241 }
244 /* Load department list when plugin has changed. That is some kind of
245 compromise between speed and beeing up to date */
246 if (isset($_GET['reset'])){
247 if (isset($_SESSION['objectinfo'])){
248 unset ($_SESSION['objectinfo']);
249 }
250 }
252 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
253 if(isset($_GET['explorer'])){
254 $_SESSION{'eGosa'}=1;
255 }
256 if(isset($_SESSION['POST'])){
257 $_SERVER["REQUEST_METHOD"] = "POST";
258 foreach ($_SESSION['POST'] as $key => $dummy){
259 $_POST[$key]=$_SESSION['POST'][$key];
260 }
261 unset($_SESSION['POST']);
262 }
264 /* show web frontend */
265 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
266 $smarty->assign ("must", "<font class=\"must\">*</font>");
267 if (isset($plug)){
268 $plug= "?plug=$plug";
269 } else {
270 $plug= "";
271 }
272 if ($_SESSION['js']==FALSE){
273 $smarty->assign("javascript", "false");
274 $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
275 } else {
276 $smarty->assign("javascript", "true");
277 $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
278 }
280 $smarty->assign ("username", $ui->username);
281 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
282 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
283 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
284 $smarty->assign ("go_out", get_template_path('images/stop.png'));
285 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
286 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
287 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
288 $smarty->assign ("go_help", get_template_path('images/help.png'));
290 /* reload navigation if language changed*/
291 if($reload_navigation){
292 $plist->menu="";;
293 }
294 $plist->gen_headlines();
295 $plist->gen_menu();
296 $smarty->assign ("menu", $plist->menu);
297 $smarty->assign ("plug", "$plug");
299 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
301 /* React on clicks */
302 if ($_SERVER["REQUEST_METHOD"] == "POST"){
304 /* 'delete_lock' is set by the lock removal dialog. We should remove the
305 lock at this point globally. Plugins do not need to remove it. */
306 if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
307 del_lock ($_SESSION['dn']);
309 /* Set old Post data */
310 if(isset($_SESSION['LOCK_VARS_USED'])){
311 foreach($_SESSION['LOCK_VARS_USED'] as $name => $value){
312 $_GET[$name] = $value;
313 $_POST[$name] = $value;
314 }
315 }
316 sess_del ('dn');
317 }
320 /* I don't want multiple browser windows open. One way to check it is
321 to count a hidden field and warn the user if SESSION and INPUT count
322 differ. */
323 if (isset($_POST['session_cnt'])){
324 if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
325 $smarty->display(get_template_path('conflict.tpl'));
326 exit ();
327 }
328 $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
329 $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
330 }
331 }
333 /* Only generate hidden click counter, if post_cnt is defined */
334 if (isset ($_SESSION['post_cnt'])){
335 echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
336 }
338 /* Load plugin */
339 if (is_file("$plugin_dir/main.inc")){
340 require_once ("$plugin_dir/main.inc");
341 } else {
342 echo sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug);
343 exit();
344 }
346 /* Close div/tables */
348 /* check if we are using account expiration */
350 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
351 preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
353 $expired= ldap_expired_account($config, $ui->dn, $ui->username);
355 if ($expired == 2){
356 gosa_log ("password for user \"$ui->username\" is about to expire");
357 print_red(_("Your password is about to expire, please change your password"));
358 }
359 }
361 /* Print_out last ErrorMessage repeated string. */
362 print_red(NULL);
364 $smarty->assign("contents", $display);
366 if (isset($_SESSION['errors'])){
367 $smarty->assign("errors", $_SESSION['errors']);
368 }
369 if ($error_collector != ""){
370 $smarty->assign("php_errors", $error_collector."</div>");
371 } else {
372 $smarty->assign("php_errors", "");
373 }
374 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
376 if ((isset($config->data['MAIN']['W3CTEST']) && preg_match('/true/i', $config->data['MAIN']['W3CTEST']))&&(!empty($display))&&(is_callable("tidy_parse_string"))) {
377 tidy_parse_string(utf8_decode($display));
378 $err = nl2br(htmlentities(tidy_get_error_buffer()));
380 if($err){
381 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;'>";
382 echo $err."</div>";
383 }
385 tidy_clean_repair($display);
386 }
388 /* Show page... */
389 echo $display;
391 /* Save plist and config */
392 $_SESSION['plist']= $plist;
393 $_SESSION['config']= $config;
395 /* Echo compilation time * /
396 $r = split(" ",$start);
397 $ms = $r[0];
398 $s= $r[1];
400 $re = split(" ",microtime());
401 $mse = $re[0];
402 $se= $re[1];
404 $add = 0;
405 if(($mse -$ms)<0){
406 $se --;
407 $add = 1;
408 }
409 echo ($se -$s).",";
410 echo (int)(($add+($mse -$ms))*1000)." s";
411 */
412 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
413 ?>