fda4f5b6f174a06d3ddfa3daba9a7246afe2c4b9
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 /* Save start time */
22 $start = microtime();
24 /* Basic setup, remove eventually registered sessions */
25 require_once ("../include/php_setup.inc");
26 require_once ("functions.inc");
28 /* Set header */
29 header("Content-type: text/html; charset=UTF-8");
31 /* Set the text domain as 'messages' */
32 $domain = 'messages';
33 bindtextdomain($domain, "$BASE_DIR/locale");
34 textdomain($domain);
36 /* Remember everything we did after the last click */
37 session::start();
38 session::set('limit_exceeded',FALSE);
40 if ($_SERVER["REQUEST_METHOD"] == "POST"){
41 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
42 }
43 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, session::get_all(), "_SESSION");
45 /* Logged in? Simple security check */
46 if (!session::is_set('config')){
47 new log("security","login","",array(),"main.php called without session - logging out") ;
48 header ("Location: logout.php");
49 exit;
50 }
52 /* Check for uniqe ip address */
53 $ui= session::get('ui');
54 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
55 new log("security","login","",array(),"main.php called with session which has a changed IP address.") ;
56 header ("Location: logout.php");
57 exit;
58 }
59 $config= session::get('config');
60 $config->check_and_reload();
62 /* Enable compressed output */
63 if (isset($config->data['MAIN']['COMPRESSED']) && preg_match('/^(true|on)$/i', $config->data['MAIN']['COMPRESSED'])){
64 ob_start("ob_gzhandler");
65 }
67 /* Check for invalid sessions */
68 if(session::get('_LAST_PAGE_REQUEST') == ""){
69 session::set('_LAST_PAGE_REQUEST',time());
70 }else{
72 /* check GOsa.conf for defined session lifetime */
73 if(isset($config->data['MAIN']['SESSION_LIFETIME'])){
74 $max_life = $config->data['MAIN']['SESSION_LIFETIME'];
75 }else{
76 $max_life = 60*60*2;
77 }
79 /* get time difference between last page reload */
80 $request_time = (time()- session::get('_LAST_PAGE_REQUEST'));
82 /* If page wasn't reloaded for more than max_life seconds
83 * kill session
84 */
85 if($request_time > $max_life){
86 session::destroy();
87 new log("security","login","",array(),"main.php called without session - logging out") ;
88 header ("Location: logout.php");
89 exit;
90 }
91 session::set('_LAST_PAGE_REQUEST',time());
92 }
95 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
97 /* Set template compile directory */
98 if (isset ($config->data['MAIN']['COMPILE'])){
99 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
100 } else {
101 $smarty->compile_dir= '/var/spool/gosa/';
102 }
104 /* Set default */
105 $reload_navigation = false;
107 /* Set last initialised language to current, browser settings */
108 if(!session::is_set('Last_init_lang')){
109 $reload_navigation = true;
110 session::set('Last_init_lang',get_browser_language());
111 }
113 /* If last language != current force navi reload */
114 $lang= get_browser_language();
115 if(session::get('Last_init_lang',$lang)){
116 $reload_navigation = true;
117 }
119 /* Language setup */
120 session::set('Last_init_lang',$lang);
122 /* Preset current main base */
123 if(!session::is_set('CurrentMainBase')){
124 session::set('CurrentMainBase',get_base_from_people($ui->dn));
125 }
127 putenv("LANGUAGE=");
128 putenv("LANG=$lang");
129 setlocale(LC_ALL, $lang);
130 $GLOBALS['t_language']= $lang;
131 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
133 /* Set the text domain as 'messages' */
134 $domain = 'messages';
135 bindtextdomain($domain, "$BASE_DIR/locale");
136 textdomain($domain);
137 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
139 /* Prepare plugin list */
140 if (!session::is_set('plist')){
141 /* Initially load all classes */
142 $class_list= get_declared_classes();
143 foreach ($class_mapping as $class => $path){
144 if (!in_array($class, $class_list)){
145 require_once("$BASE_DIR/$path");
146 }
147 }
149 session::set('plist', new pluglist($config, $ui));
151 /* Load ocMapping into userinfo */
152 $tmp= new acl($config, NULL, $ui->dn);
153 $ui->ocMapping= $tmp->ocMapping;
154 session::set('ui',$ui);
155 }
156 $plist= session::get('plist');
158 /* Check for register globals */
159 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
160 echo _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator.");
161 new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
162 session::destroy ();
163 exit ();
164 }
166 /* Check Plugin variable */
167 if (session::is_set('plugin_dir')){
168 $old_plugin_dir= session::get('plugin_dir');
169 } else {
170 $old_plugin_dir= "";
171 }
172 if (isset($_GET['plug'])){
173 $plug= validate($_GET['plug']);
174 $plugin_dir= $plist->get_path($plug);
175 session::set('plugin_dir',$plugin_dir);
176 if ($plugin_dir == ""){
177 new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
178 header ("Location: logout.php");
179 exit;
180 }
181 } else {
183 /* set to welcome page as default plugin */
184 session::set('plugin_dir',"welcome");
185 $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
186 }
188 /* Check if we need to delete a lock */
189 if ($old_plugin_dir != $plugin_dir){
190 if (is_file("$old_plugin_dir/main.inc")){
191 $remove_lock= true;
192 require_once ("$old_plugin_dir/main.inc");
193 }
194 }
195 $remove_lock= false;
197 /* Check for sizelimits */
198 eval_sizelimit();
200 /* Check for memory */
201 if (function_exists("memory_get_usage")){
202 if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
203 msg_dialog::display(_("Configuration warning"), _("Running out of memory!"), WARNING_DIALOG);
204 }
205 }
207 /* Redirect on back event */
208 if ($_SERVER["REQUEST_METHOD"] == "POST"){
210 /* Look for button events that match /^back[0-9]+$/,
211 extract the number and step the correct plugin. */
212 foreach ($_POST as $key => $value){
213 if (preg_match("/^back[0-9]+$/", $key)){
214 $back= substr($key, 4);
215 header ("Location: main.php?plug=$back");
216 exit;
217 }
218 }
219 }
221 /* Redirect on password back event */
222 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
223 header ("Location: main.php");
224 exit;
225 }
227 /* Check for multiple windows logout */
228 if ($_SERVER["REQUEST_METHOD"] == "POST"){
229 if (isset($_POST['reset_session'])){
230 header ("Location: logout.php");
231 exit;
232 }
234 if (isset($_POST['cancel_lock'])){
235 session::un_set('dn');
236 }
237 }
240 /* Load department list when plugin has changed. That is some kind of
241 compromise between speed and beeing up to date */
242 if (isset($_GET['reset'])){
243 if (session::is_set('objectinfo')){
244 session::un_set('objectinfo');
245 }
246 }
248 /* Install eGOsa hooks, convert _POST to session */
249 if(isset($_GET['explorer'])){
250 session::set('eGosa',TRUE);
251 }
252 if(session::is_set('POST')){
253 $_SERVER["REQUEST_METHOD"] = "POST";
254 foreach (session::get('POST') as $key => $dummy){
255 $_POST[$key]= $dummy;
256 }
257 session::un_set('POST');
258 }
260 /* show web frontend */
261 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
262 $smarty->assign ("must", "<font class=\"must\">*</font>");
263 if (isset($plug)){
264 $plug= "?plug=$plug";
265 } else {
266 $plug= "";
267 }
268 if (session::get('js')==FALSE){
269 $smarty->assign("javascript", "false");
270 $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
271 } else {
272 $smarty->assign("javascript", "true");
273 $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
274 }
276 $smarty->assign ("username", $ui->username);
277 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
278 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
279 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
280 $smarty->assign ("go_out", get_template_path('images/stop.png'));
281 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
282 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
283 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
284 $smarty->assign ("go_help", get_template_path('images/help.png'));
286 /* reload navigation if language changed*/
287 if($reload_navigation){
288 $plist->menu="";;
289 }
290 $plist->gen_headlines();
291 $plist->gen_menu();
292 $smarty->assign ("menu", $plist->menu);
293 $smarty->assign ("plug", "$plug");
295 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
297 /* React on clicks */
298 if ($_SERVER["REQUEST_METHOD"] == "POST"){
300 /* 'delete_lock' is set by the lock removal dialog. We should remove the
301 lock at this point globally. Plugins do not need to remove it. */
302 if (isset($_POST['delete_lock']) && session::is_set('dn')){
303 del_lock (session::get('dn'));
305 /* Set old Post data */
306 if(session::is_set('LOCK_VARS_USED')){
307 foreach(session::get('LOCK_VARS_USED') as $name => $value){
308 $_GET[$name] = $value;
309 $_POST[$name] = $value;
310 }
311 }
312 session::un_set ('dn');
313 }
316 /* I don't want multiple browser windows open. One way to check it is
317 to count a hidden field and warn the user if SESSION and INPUT count
318 differ. */
319 if (isset($_POST['session_cnt'])){
320 if ($_POST['session_cnt'] != session::get('session_cnt')){
321 $smarty->display(get_template_path('conflict.tpl'));
322 exit ();
323 }
324 session::set('session_cnt', (session::get('session_cnt') + 1));
325 session::set('post_cnt' , validate($_POST['session_cnt']) + 1);
326 }
327 }
329 /* Only generate hidden click counter, if post_cnt is defined */
330 if (session::is_set('post_cnt')){
331 echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".session::get('post_cnt')."\">\n";
332 }
334 /* check if we are using account expiration */
335 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
336 preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
338 $expired= ldap_expired_account($config, $ui->dn, $ui->username);
340 if ($expired == 2){
341 new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
342 msg_dialog::display(_("Password reminder"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
343 }
344 }
346 /* Load plugin */
347 if (is_file("$plugin_dir/main.inc")){
348 require_once ("$plugin_dir/main.inc");
349 } else {
350 echo sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug);
351 exit();
352 }
355 /* Print_out last ErrorMessage repeated string. */
356 if(isset($_GET['add'])){
357 msg_dialog::display("Error" ,"Kann datei nicht schreiben, bla",ERROR_DIALOG);
358 msg_dialog::display("Warning" ,"Kann datei nicht schreiben, bla",WARNING_DIALOG);
359 msg_dialog::display("Info" ,"Kann datei nicht schreiben, bla",INFO_DIALOG);
360 msg_dialog::display("Confirm" ,"Kann datei nicht schreiben, bla",CONFIRM_DIALOG);
361 }
363 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
364 $smarty->assign("contents", $display);
366 /* Assign erros to smarty */
367 if (session::is_set('errors')){
368 $smarty->assign("errors", session::get('errors'));
369 }
370 if ($error_collector != ""){
371 $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
372 } else {
373 $smarty->assign("php_errors", "");
374 }
376 /* Set focus to the error button if we've an error message */
377 $focus= "";
378 if (session::is_set('errors') && session::get('errors') != ""){
379 $focus= '<script language="JavaScript" type="text/javascript">';
380 $focus.= 'document.forms[0].error_accept.focus();';
381 $focus.= '</script>';
382 }
384 $focus= '<script language="JavaScript" type="text/javascript">';
385 $focus.= 'next_msg_dialog();';
386 $focus.= '</script>';
387 $smarty->assign("focus", $focus);
389 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
391 /* Save dialog filters and selected base in a cookie.
392 So we may be able to restore the filter an base settings on reload.
393 */
394 $cookie = array();
396 if(isset($_COOKIE['GOsa_Filter_Settings'])){
397 $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
398 }elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
399 $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
400 }
401 if(isset($config->data['MAIN']['SAVE_FILTER']) && preg_match("/true/",$config->data['MAIN']['SAVE_FILTER'])){
402 $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
403 foreach($cookie_vars as $var){
404 if(session::is_set($var)){
405 $cookie[$ui->dn][$var] = session::get($var);
406 }
407 }
408 if(isset($_GET['plug'])){
409 $cookie[$ui->dn]['plug'] = $_GET['plug'];
410 }
411 @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
412 }
414 /* Show page... */
415 echo $display;
417 /* Save plist and config */
418 session::set('plist',$plist);
419 session::set('config',$config);
420 session::set('errorsAlreadyPosted',array());
422 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
423 ?>