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