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 /* Set default */
70 $reload_navigation = false;
72 /* Set last initialised language to current, browser settings */
73 if((!isset($_SESSION['Last_init_lang']))){
74 $reload_navigation = true;
75 $_SESSION['Last_init_lang'] = get_browser_language();
76 }
78 /* Language setup */
79 if ($config->data['MAIN']['LANG'] == ""){
81 /* If last language != current force navi reload */
82 if($_SESSION['Last_init_lang'] != get_browser_language()){
83 $reload_navigation = true;
84 }
85 $lang= get_browser_language();
86 $_SESSION['Last_init_lang'] = $lang;
87 } else {
88 $lang= $config->data['MAIN']['LANG'];
89 }
91 $lang.=".UTF-8";
92 putenv("LANGUAGE=");
93 putenv("LANG=$lang");
94 setlocale(LC_ALL, $lang);
95 $GLOBALS['t_language']= $lang;
96 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
98 /* Set the text domain as 'messages' */
99 $domain = 'messages';
100 bindtextdomain($domain, "$BASE_DIR/locale");
101 textdomain($domain);
102 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
104 /* Prepare plugin list */
105 if (!isset($_SESSION['plist'])){
106 $_SESSION['plist']= new pluglist($config, $ui);
107 }
108 $plist= $_SESSION['plist'];
110 /* Check for register globals */
111 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
112 print_red (_("Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."));
113 echo $_SESSION['errors'];
114 gosa_log ("Register globals is on. For security reasons, this should be turned off.");
115 session_destroy ();
116 exit ();
117 }
119 /* Check Plugin variable */
120 if (isset($_SESSION['plugin_dir'])){
121 $old_plugin_dir= $_SESSION['plugin_dir'];
122 } else {
123 $old_plugin_dir= "";
124 }
125 if (isset($_GET['plug'])){
126 $plug= validate($_GET['plug']);
127 $plugin_dir= $plist->get_path($plug);
128 $_SESSION['plugin_dir']= $plugin_dir;
129 if ($plugin_dir == ""){
130 gosa_log ("main.php called with invalid plug parameter \"$plug\"", 3);
131 header ("Location: logout.php");
132 exit;
133 }
134 } else {
135 /* set to welcome page as default plugin */
136 $_SESSION['plugin_dir']= "welcome";
137 $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
138 }
140 /* Check if we need to delete a lock */
141 if ($old_plugin_dir != $plugin_dir){
142 if (is_file("$old_plugin_dir/main.inc")){
143 $remove_lock= true;
144 require_once ("$old_plugin_dir/main.inc");
145 }
146 }
147 $remove_lock= false;
149 /* Check for sizelimits */
150 eval_sizelimit();
152 /* Check for memory */
153 if (function_exists("memory_get_usage")){
154 if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
155 print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
156 }
157 }
159 /* Redirect on back event */
160 if ($_SERVER["REQUEST_METHOD"] == "POST"){
162 /* Look for button events that match /^back[0-9]+$/,
163 extract the number and step the correct plugin. */
164 foreach ($_POST as $key => $value){
165 if (preg_match("/^back[0-9]+$/", $key)){
166 $back= substr($key, 4);
167 header ("Location: main.php?plug=$back");
168 exit;
169 }
170 }
171 }
173 /* Redirect on password back event */
174 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
175 header ("Location: main.php");
176 exit;
177 }
179 /* Check for multiple windows logout */
180 if ($_SERVER["REQUEST_METHOD"] == "POST"){
181 if (isset($_POST['reset_session'])){
182 header ("Location: logout.php");
183 exit;
184 }
186 if (isset($_POST['cancel_lock'])){
187 unset ($_SESSION['dn']);
188 }
189 }
192 /* Load department list when plugin has changed. That is some kind of
193 compromise between speed and beeing up to date */
194 if (isset($_GET['reset'])){
195 $config->departments= get_departments();
196 $config->make_idepartments ();
197 if (isset($_SESSION['objectinfo'])){
198 unset ($_SESSION['objectinfo']);
199 }
200 }
202 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
203 if(isset($_GET['explorer'])){
204 $_SESSION{'eGosa'}=1;
205 }
206 if(isset($_SESSION['POST'])){
207 $_SERVER["REQUEST_METHOD"] = "POST";
208 foreach ($_SESSION['POST'] as $key => $dummy){
209 $_POST[$key]=$_SESSION['POST'][$key];
210 }
211 unset($_SESSION['POST']);
212 }
214 /* show web frontend */
215 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
216 $smarty->assign ("must", "<font class=\"must\">*</font>");
217 if (isset($plug)){
218 $plug= "?plug=$plug";
219 } else {
220 $plug= "";
221 }
222 if ($_SESSION['js']==FALSE){
223 $smarty->assign("javascript", "false");
224 $smarty->assign("help_method", "href='helpviewer.php$plug' target='_new'");
225 } else {
226 $smarty->assign("javascript", "true");
227 $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
228 }
230 $smarty->assign ("username", $ui->username);
231 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
232 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
233 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
234 $smarty->assign ("go_out", get_template_path('images/stop.png'));
235 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
236 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
237 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
238 $smarty->assign ("go_help", get_template_path('images/help.png'));
240 /* reload navigation if language changed*/
241 if($reload_navigation){
242 $plist->menu="";;
243 }
244 $plist->gen_menu();
245 $smarty->assign ("menu", $plist->menu);
246 $smarty->assign ("plug", "$plug");
248 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
251 /* React on clicks */
252 if ($_SERVER["REQUEST_METHOD"] == "POST"){
254 /* 'delete_lock' is set by the lock removal dialog. We should remove the
255 lock at this point globally. Plugins do not need to remove it. */
256 if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
257 del_lock ($_SESSION['dn']);
258 sess_del ('dn');
259 }
262 /* I don't want multiple browser windows open. One way to check it is
263 to count a hidden field and warn the user if SESSION and INPUT count
264 differ. */
265 if (isset($_POST['session_cnt'])){
266 if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
267 $smarty->display(get_template_path('conflict.tpl'));
268 exit ();
269 }
270 $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
271 $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
272 }
273 }
275 /* Only generate hidden click counter, if post_cnt is defined */
276 if (isset ($_SESSION['post_cnt'])){
277 echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
278 }
280 /* Load plugin */
281 if (is_file("$plugin_dir/main.inc")){
282 require_once ("$plugin_dir/main.inc");
283 } else {
284 print_red(sprintf(_("Can't find any plugin definitions for plugin '%s'!"), $plug));
285 echo $_SESSION['errors'];
286 exit();
287 }
289 /* Close div/tables */
290 $smarty->assign("contents", $display);
291 if (isset($_SESSION['errors'])){
292 $smarty->assign("errors", $_SESSION['errors']);
293 }
294 if ($error_collector != ""){
295 $smarty->assign("php_errors", $error_collector."</div>");
296 } else {
297 $smarty->assign("php_errors", "");
298 }
299 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
301 /* For development, perform a W3C conformance check if specified in gosa.conf */
302 if (isset($config->data['MAIN']['W3CTEST']) && preg_match('/true/i', $config->data['MAIN']['W3CTEST'])) {
304 /* Use PHP tidy for debugging */
305 $tidy = new tidy();
306 $config = array('indent' => TRUE,
307 'output-xhtml' => TRUE,
308 'wrap' => 200);
309 $display = tidy_parse_string($display, $config, 'UTF8');
310 tidy_clean_repair($display);
311 $cnt = (tidy_error_count($display))+(tidy_warning_count($display));
312 if($cnt != 0){
313 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;'>";
315 echo nl2br(htmlentities($display->errorBuffer))."</div>";
316 }
317 tidy_clean_repair($display);
318 }
320 /* Show page... */
321 echo $display;
323 /* Save plist */
324 $_SESSION['plist']= $plist;
326 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
327 ?>