Code

Improved error handling. This will be enhanced later on
[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 $timing= array();
23 require_once ("../include/php_setup.inc");
24 require_once ("functions.inc");
25 header("Content-type: text/html; charset=UTF-8");
27 /* Reset error handler */
28 $error_collector= "";
29 set_error_handler('gosaRaiseError');
31 /* Find all class files and include them */
32 get_dir_list("$BASE_DIR/plugins");
34 /* Set the text domain as 'messages' */
35 $domain = 'messages';
36 bindtextdomain($domain, "$BASE_DIR/locale");
37 textdomain($domain);
39 /* Remember everything we did after the last click */
40 session_start ();
41 if ($_SERVER["REQUEST_METHOD"] == "POST"){
42   @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
43 }
44 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_SESSION, "_SESSION");
46 /* Logged in? Simple security check */
47 if (!isset($_SESSION['config'])){
48   gosa_log ("main.php called without session");
49   header ("Location: index.php");
50   exit;
51
53 /* Reset errors */
54 $_SESSION['errors']= "";
56 /* Check for uniqe ip address */
57 $ui= $_SESSION["ui"];
58 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
59   gosa_log ("main.php called with session which has a changed IP address.", 3);
60   header ("Location: logout.php");
61   exit;
62 }
63 $config= $_SESSION['config'];
64 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
66 /* Set template compile directory */
67 if (isset ($config->data['MAIN']['COMPILE'])){
68   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
69 } else {
70   $smarty->compile_dir= '/var/spool/gosa/';
71 }
73 /* Language setup */
74 if ($config->data['MAIN']['LANG'] == ""){
75   $lang= get_browser_language();
76 } else {
77   $lang= $config->data['MAIN']['LANG'];
78 }
79 $lang.=".UTF-8";
80 putenv("LANGUAGE=");
81 putenv("LANG=$lang");
82 setlocale(LC_ALL, $lang);
83 $GLOBALS['t_language']= $lang;
84 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
86 /* Dummy */
87 trigger_error("I'm a fake error. Please ignore me.", E_USER_NOTICE);
89 /* Set the text domain as 'messages' */
90 $domain = 'messages';
91 bindtextdomain($domain, "$BASE_DIR/locale");
92 textdomain($domain);
93 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
95 /* Prepare plugin list */
96 if (!isset($_SESSION['plist'])){
97   $_SESSION['plist']= new pluglist($config, $ui);
98 }
99 $plist= $_SESSION['plist'];
101 /* Check for register globals */
102 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
103   print_red (_("Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."));
104   echo $_SESSION['errors'];
105   gosa_log ("Register globals is on. For security reasons, this should be turned off.");
106   session_destroy ();
107   exit ();
110 /* Check Plugin variable */
111 if (isset($_SESSION['plugin_dir'])){
112   $old_plugin_dir= $_SESSION['plugin_dir'];
113 } else {
114   $old_plugin_dir= "";
116 if (isset($_GET['plug'])){
117   $plug= validate($_GET['plug']);
118   $plugin_dir= $plist->get_path($plug);
119   $_SESSION['plugin_dir']= $plugin_dir;
120   if ($plugin_dir == ""){
121     gosa_log ("main.php called with invalid plug parameter \"$plug\"", 3);
122     header ("Location: logout.php");
123     exit;
124   }
125 } else {
126   /* set to welcome page as default plugin */
127   $_SESSION['plugin_dir']= "welcome";
128   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
131 /* Check if we need to delete a lock */
132 if ($old_plugin_dir != $plugin_dir){
133   if (is_file("$old_plugin_dir/main.inc")){
134     $remove_lock= true;
135     require_once ("$old_plugin_dir/main.inc");
136   }
138 $remove_lock= false;
140 /* Check for sizelimits */
141 eval_sizelimit();
143 /* Check for memory */
144 if (function_exists("memory_get_usage")){
145   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 1024000 )){
146     print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
147   }
150 /* Redirect on back event */
151 if ($_SERVER["REQUEST_METHOD"] == "POST"){
153   /* Look for button events that match /^back[0-9]+$/,
154      extract the number and step the correct plugin. */
155   foreach ($_POST as $key => $value){
156     if (preg_match("/^back[0-9]+$/", $key)){
157       $back= substr($key, 4);
158       header ("Location: main.php?plug=$back");
159       exit;
160     }
161   }
164 /* Redirect on password back event */
165 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
166   header ("Location: main.php");
167   exit;
170 /* Check for multiple windows logout */
171 if ($_SERVER["REQUEST_METHOD"] == "POST"){
172   if (isset($_POST['reset_session'])){
173     header ("Location: logout.php");
174     exit;
175   }
177   if (isset($_POST['cancel_lock'])){
178     unset ($_SESSION['dn']);
179   }
183 /* Load department list when plugin has changed. That is some kind of
184    compromise between speed and beeing up to date */
185 if (isset($_GET['reset'])){
186   $config->departments= get_departments();
187   $config->make_idepartments ();
188   if (isset($_SESSION['objectinfo'])){
189     unset ($_SESSION['objectinfo']);
190   }
193 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
194 if(isset($_GET['explorer'])){
195   $_SESSION{'eGosa'}=1;
197 if(isset($_SESSION['POST'])){
198   $_SERVER["REQUEST_METHOD"] = "POST";
199   foreach ($_SESSION['POST'] as $key => $dummy){
200     $_POST[$key]=$_SESSION['POST'][$key];
201   }
202   unset($_SESSION['POST']);
205 /* show web frontend */
206 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
207 $smarty->assign ("must", "<font class=\"must\">*</font>");
208 if ($_SESSION['js']==FALSE){
209   $smarty->assign("javascript", "false");
210 } else {
211   $smarty->assign("javascript", "true");
213 $smarty->assign ("username", $ui->username);
214 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
215 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
216 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
217 $smarty->assign ("go_out", get_template_path('images/stop.png'));
218 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
219 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
220 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
221 $smarty->assign ("go_help", get_template_path('images/help.png'));
222 $plist->gen_menu();
223 $smarty->assign ("menu", $plist->menu);
224 if (isset($plug)){
225   $smarty->assign ("plug", "?plug=$plug");
226 } else {
227   $smarty->assign ("plug", "");
229 $smarty->display(get_template_path('headers.tpl'));
231 /* React on clicks */
232 if ($_SERVER["REQUEST_METHOD"] == "POST"){
234   /* 'delete_lock' is set by the lock removal dialog. We should remove the
235      lock at this point globally. Plugins do not need to remove it. */
236   if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
237     del_lock ($_SESSION['dn']);
238     sess_del ('dn');
239   }
242   /* I don't want multiple browser windows open. One way to check it is
243      to count a hidden field and warn the user if SESSION and INPUT count
244      differ. */
245   if (isset($_POST['session_cnt'])){
246     if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
247       $smarty->display(get_template_path('conflict.tpl'));
248       exit ();
249     }
250     $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
251     $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
252   }
255 /* Only generate hidden click counter, if post_cnt is defined */
256 if (isset ($_SESSION['post_cnt'])){
257   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
260 /* Load plugin */
261 if (is_file("$plugin_dir/main.inc")){
262   require_once ("$plugin_dir/main.inc");
263 } else {
264   print_red(sprintf(_("Can't find any plugin definitions for plugin '%s'!"), $plug));
265   echo $_SESSION['errors'];
266   exit();
269 /* Close div/tables */
270 $smarty->assign("contents", $display);
271 if (isset($_SESSION['errors'])){
272   $smarty->assign("errors", $_SESSION['errors']);
274 $smarty->assign("php_errors", $error_collector);
275 $smarty->display(get_template_path('framework.tpl'));
276 $_SESSION['plist']= $plist;
278 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
279 ?>