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