Code

Updated print_red error output, every message is now displayed only once.
[gosa.git] / html / main.php
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 */
37 session_set_cookie_params(24*60*60);
39 /* Remember everything we did after the last click */
40 session_start ();
43 if ($_SERVER["REQUEST_METHOD"] == "POST"){
44   @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
45 }
46 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_SESSION, "_SESSION");
48 /* Logged in? Simple security check */
49 if (!isset($_SESSION['config'])){
50   gosa_log ("main.php called without session - logging out");
51   header ("Location: logout.php");
52   exit;
53
55 /* Reset errors */
56 $_SESSION['errors']= "";
57 $_SESSION['errorsAlreadyPosted']= array();
58 $_SESSION['LastError']  ="";
60 /* Check for uniqe ip address */
61 $ui= $_SESSION["ui"];
62 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
63   gosa_log ("main.php called with session which has a changed IP address.", 3);
64   header ("Location: logout.php");
65   exit;
66 }
67 $config= $_SESSION['config'];
70 /* Check for invalid sessions */
71 if(empty($_SESSION['_LAST_PAGE_REQUEST'])){
72   $_SESSION['_LAST_PAGE_REQUEST']= time();
73 }else{
75   /* check GOsa.conf for defined session lifetime */
76   if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
77     $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
78   }else{
79     $max_life = 60*60*2;
80   }
82   /* get time difference between last page reload */
83   $request_time = (time()-$_SESSION['_LAST_PAGE_REQUEST']);
85   /* If page wasn't reloaded for more than max_life seconds 
86    * kill session
87    */
88   if($request_time > $max_life){
89     session_unset();
90     gosa_log ("main.php called without session - logging out");
91     header ("Location: logout.php");
92     exit;
93   }
94 //  echo "Session was ".$request_time." s inactive";
95   $_SESSION['_LAST_PAGE_REQUEST'] = time();
96 }
99 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
101 /* Set template compile directory */
102 if (isset ($config->data['MAIN']['COMPILE'])){
103   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
104 } else {
105   $smarty->compile_dir= '/var/spool/gosa/';
108 /* Set default */
109 $reload_navigation = false;
111 /* Set last initialised language to current, browser settings */
112 if((!isset($_SESSION['Last_init_lang']))){
113   $reload_navigation = true;
114   $_SESSION['Last_init_lang'] = get_browser_language();
117 /* Language setup */
118 if ($config->data['MAIN']['LANG'] == ""){
119   
120   /* If last language != current force navi reload */
121   if($_SESSION['Last_init_lang'] != get_browser_language()){
122     $reload_navigation = true;
123   }
124   $lang= get_browser_language();
125   $_SESSION['Last_init_lang'] = $lang;
126 } else {
127   $lang= $config->data['MAIN']['LANG'];
130 $lang.=".UTF-8";
131 putenv("LANGUAGE=");
132 putenv("LANG=$lang");
133 setlocale(LC_ALL, $lang);
134 $GLOBALS['t_language']= $lang;
135 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
137 /* Set the text domain as 'messages' */
138 $domain = 'messages';
139 bindtextdomain($domain, "$BASE_DIR/locale");
140 textdomain($domain);
141 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
143 /* Prepare plugin list */
144 if (!isset($_SESSION['plist'])){
145   $_SESSION['plist']= new pluglist($config, $ui);
147 $plist= $_SESSION['plist'];
149 /* Check for register globals */
150 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
151   print_red (_("Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."));
152   echo $_SESSION['errors'];
153   gosa_log ("Register globals is on. For security reasons, this should be turned off.");
154   session_destroy ();
155   exit ();
158 /* Check Plugin variable */
159 if (isset($_SESSION['plugin_dir'])){
160   $old_plugin_dir= $_SESSION['plugin_dir'];
161 } else {
162   $old_plugin_dir= "";
164 if (isset($_GET['plug'])){
165   $plug= validate($_GET['plug']);
166   $plugin_dir= $plist->get_path($plug);
167   $_SESSION['plugin_dir']= $plugin_dir;
168   if ($plugin_dir == ""){
169     gosa_log ("main.php called with invalid plug parameter \"$plug\"", 3);
170     header ("Location: logout.php");
171     exit;
172   }
173 } else {
174   /* set to welcome page as default plugin */
175   $_SESSION['plugin_dir']= "welcome";
176   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
179 /* Check if we need to delete a lock */
180 if ($old_plugin_dir != $plugin_dir){
181   if (is_file("$old_plugin_dir/main.inc")){
182     $remove_lock= true;
183     require_once ("$old_plugin_dir/main.inc");
184   }
186 $remove_lock= false;
188 /* Check for sizelimits */
189 eval_sizelimit();
191 /* Check for memory */
192 if (function_exists("memory_get_usage")){
193   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
194     print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
195   }
198 /* Redirect on back event */
199 if ($_SERVER["REQUEST_METHOD"] == "POST"){
201   /* Look for button events that match /^back[0-9]+$/,
202      extract the number and step the correct plugin. */
203   foreach ($_POST as $key => $value){
204     if (preg_match("/^back[0-9]+$/", $key)){
205       $back= substr($key, 4);
206       header ("Location: main.php?plug=$back");
207       exit;
208     }
209   }
212 /* Redirect on password back event */
213 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
214   header ("Location: main.php");
215   exit;
218 /* Check for multiple windows logout */
219 if ($_SERVER["REQUEST_METHOD"] == "POST"){
220   if (isset($_POST['reset_session'])){
221     header ("Location: logout.php");
222     exit;
223   }
225   if (isset($_POST['cancel_lock'])){
226     unset ($_SESSION['dn']);
227   }
231 /* Load department list when plugin has changed. That is some kind of
232    compromise between speed and beeing up to date */
233 if (isset($_GET['reset'])){
234   if (!isset($_SESSION['cached_departments'])){
235     $_SESSION['cached_departments']= get_departments();
236   }
237   $config->departments= $_SESSION['cached_departments'];
238   $config->make_idepartments ();
239   if (isset($_SESSION['objectinfo'])){
240     unset ($_SESSION['objectinfo']);
241   }
244 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
245 if(isset($_GET['explorer'])){
246   $_SESSION{'eGosa'}=1;
248 if(isset($_SESSION['POST'])){
249   $_SERVER["REQUEST_METHOD"] = "POST";
250   foreach ($_SESSION['POST'] as $key => $dummy){
251     $_POST[$key]=$_SESSION['POST'][$key];
252   }
253   unset($_SESSION['POST']);
256 /* show web frontend */
257 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
258 $smarty->assign ("must", "<font class=\"must\">*</font>");
259 if (isset($plug)){
260   $plug= "?plug=$plug";
261 } else {
262   $plug= "";
264 if ($_SESSION['js']==FALSE){
265   $smarty->assign("javascript", "false");
266   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
267 } else {
268   $smarty->assign("javascript", "true");
269   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
272 $smarty->assign ("username", $ui->username);
273 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
274 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
275 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
276 $smarty->assign ("go_out", get_template_path('images/stop.png'));
277 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
278 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
279 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
280 $smarty->assign ("go_help", get_template_path('images/help.png'));
282 /* reload navigation if language changed*/  
283 if($reload_navigation){
284   $plist->menu="";;
286 $plist->gen_headlines();
287 $plist->gen_menu();
288 $smarty->assign ("menu", $plist->menu);
289 $smarty->assign ("plug", "$plug");
291 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
293 /* React on clicks */
294 if ($_SERVER["REQUEST_METHOD"] == "POST"){
296   /* 'delete_lock' is set by the lock removal dialog. We should remove the
297      lock at this point globally. Plugins do not need to remove it. */
298   if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
299     del_lock ($_SESSION['dn']);
301     /* Set old Post data */
302     if(isset($_SESSION['LOCK_VARS_USED'])){
303       foreach($_SESSION['LOCK_VARS_USED'] as $name => $value){
304         $_GET[$name]  = $value;
305         $_POST[$name] = $value;
306       } 
307     }
308     sess_del ('dn');
309   }
312   /* I don't want multiple browser windows open. One way to check it is
313      to count a hidden field and warn the user if SESSION and INPUT count
314      differ. */
315   if (isset($_POST['session_cnt'])){
316     if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
317       $smarty->display(get_template_path('conflict.tpl'));
318       exit ();
319     }
320     $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
321     $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
322   }
325 /* Only generate hidden click counter, if post_cnt is defined */
326 if (isset ($_SESSION['post_cnt'])){
327   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
330 /* Load plugin */
331 if (is_file("$plugin_dir/main.inc")){
332   require_once ("$plugin_dir/main.inc");
333 } else {
334   print_red(sprintf(_("Can't find any plugin definitions for plugin '%s'!"), $plug));
335   echo $_SESSION['errors'];
336   exit();
339 /* Close div/tables */
341 /* Print_out last ErrorMessage repeated string.
342  */
343 print_red(NULL);
345 $smarty->assign("contents", $display);
347 if (isset($_SESSION['errors'])){
348   $smarty->assign("errors", $_SESSION['errors']);
350 if ($error_collector != ""){
351   $smarty->assign("php_errors", $error_collector."</div>");
352 } else {
353   $smarty->assign("php_errors", "");
355 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
357 if ((isset($config->data['MAIN']['W3CTEST']) && preg_match('/true/i', $config->data['MAIN']['W3CTEST']))&&(!empty($display))&&(is_callable("tidy_parse_string"))) {
358   tidy_parse_string(utf8_decode($display));
359   $err = nl2br(htmlentities(tidy_get_error_buffer()));
360   
361   if($err){
362     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'>&nbsp;<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;'>";
363     echo $err."</div>";
364   }
366   tidy_clean_repair($display);
369 /* Show page... */
370 echo $display;
372 /* Save plist */
373 $_SESSION['plist']= $plist;
375 /* Echo compilation time * /
376 $r = split(" ",$start);
377 $ms = $r[0];
378 $s= $r[1];
380 $re = split(" ",microtime());
381 $mse = $re[0];
382 $se= $re[1];
384 $add = 0;
385 if(($mse -$ms)<0){
386   $se --;
387   $add = 1;
389 echo ($se -$s).",";
390 echo (int)(($add+($mse -$ms))*1000)." s";
391 */
392 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
393 ?>