~ubuntu-branches/ubuntu/quantal/gosa/quantal

« back to all changes in this revision

Viewing changes to .pc/smarty3.patch/gosa-core/html/main.php

  • Committer: Package Import Robot
  • Author(s): Cajus Pollmeier
  • Date: 2012-06-19 09:36:39 UTC
  • mfrom: (7.2.16 sid)
  • Revision ID: package-import@ubuntu.com-20120619093639-uxhp7dk39opb2ygk
Tags: 2.7.4-4
New smarty3 package fixes problems with template loading. This
release removes the workarounds for that issue.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * This code is part of GOsa (http://www.gosa-project.org)
 
4
 * Copyright (C) 2003-2008 GONICUS GmbH
 
5
 *
 
6
 * ID: $$Id: main.php 21044 2011-11-07 10:01:32Z hickert $$
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
 */
 
22
 
 
23
/* Save start time */
 
24
$start = microtime();
 
25
 
 
26
// Will be used in the "stats" plugin later, to be able calculate the elapsed render time.
 
27
$overallRenderTimer = microtime(TRUE);
 
28
 
 
29
/* Basic setup, remove eventually registered sessions */
 
30
require_once ("../include/php_setup.inc");
 
31
require_once ("functions.inc");
 
32
 
 
33
/* Set header */
 
34
header("Content-type: text/html; charset=UTF-8");
 
35
 
 
36
/* Set the text domain as 'messages' */
 
37
$domain = 'messages';
 
38
bindtextdomain($domain, LOCALE_DIR);
 
39
textdomain($domain);
 
40
 
 
41
 
 
42
/* Remember everything we did after the last click */
 
43
session::start();
 
44
session::set('errorsAlreadyPosted',array());
 
45
session::global_set('runtime_cache',array());
 
46
session::set('limit_exceeded',FALSE);
 
47
 
 
48
// Count number of page reloads 
 
49
if(!session::is_set('clicks')){
 
50
    session::set('clicks', 0);
 
51
}
 
52
$clicks = session::get('clicks');
 
53
$clicks ++ ;
 
54
session::set('clicks', $clicks);
 
55
 
 
56
pathNavigator::clear();
 
57
 
 
58
if ($_SERVER["REQUEST_METHOD"] == "POST"){
 
59
  @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
 
60
}
 
61
@DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, session::get_all(), "_SESSION");
 
62
 
 
63
/* Logged in? Simple security check */
 
64
if (!session::global_is_set('config')){
 
65
  new log("security","login","",array(),"main.php called without session - logging out") ;
 
66
  header ("Location: logout.php");
 
67
  exit;
 
68
 
69
 
 
70
/* Check for uniqe ip address */
 
71
$ui= session::global_get('ui');
 
72
if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
 
73
  new log("security","login","",array(),"main.php called with session which has a changed IP address.") ;
 
74
  header ("Location: logout.php");
 
75
  exit;
 
76
}
 
77
$config= session::global_get('config');
 
78
$config->check_and_reload();
 
79
$config->configRegistry->reload();
 
80
 
 
81
/* Enable compressed output */
 
82
if ($config->get_cfg_value("core","sendCompressedOutput") == "true"){
 
83
  ob_start("ob_gzhandler");
 
84
}
 
85
 
 
86
/* Check for invalid sessions */
 
87
if(session::global_get('_LAST_PAGE_REQUEST') == ""){
 
88
  session::global_set('_LAST_PAGE_REQUEST',time());
 
89
}else{
 
90
 
 
91
  /* check GOsa.conf for defined session lifetime */
 
92
  $max_life= $config->get_cfg_value("core","sessionLifetime");
 
93
 
 
94
  /* get time difference between last page reload */
 
95
  $request_time = (time()- session::global_get('_LAST_PAGE_REQUEST'));
 
96
 
 
97
  /* If page wasn't reloaded for more than max_life seconds 
 
98
   * kill session
 
99
   */
 
100
  if($request_time > $max_life){
 
101
    session::destroy();
 
102
    new log("security","login","",array(),"main.php called without session - logging out") ;
 
103
    header ("Location: logout.php");
 
104
    exit;
 
105
  }
 
106
  session::global_set('_LAST_PAGE_REQUEST',time());
 
107
}
 
108
 
 
109
 
 
110
@DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
 
111
 
 
112
/* Set template compile directory */
 
113
$smarty->compile_dir= $config->get_cfg_value("core","templateCompileDirectory");
 
114
$smarty->error_unassigned= true;
 
115
 
 
116
/* Set default */
 
117
$reload_navigation = false;
 
118
 
 
119
/* Set last initialised language to current, browser settings */
 
120
if(!session::global_is_set('Last_init_lang')){
 
121
  $reload_navigation = true;
 
122
  session::global_set('Last_init_lang',get_browser_language());
 
123
}
 
124
 
 
125
/* If last language != current force navi reload */
 
126
$lang= get_browser_language();
 
127
if(session::global_get('Last_init_lang') != $lang){
 
128
  $reload_navigation = true;
 
129
}
 
130
 
 
131
/* Language setup */
 
132
session::global_set('Last_init_lang',$lang);
 
133
 
 
134
/* Preset current main base */
 
135
if(!session::global_is_set('CurrentMainBase')){
 
136
  session::global_set('CurrentMainBase',get_base_from_people($ui->dn));
 
137
}
 
138
 
 
139
putenv("LANGUAGE=");
 
140
putenv("LANG=$lang");
 
141
setlocale(LC_ALL, $lang);
 
142
$GLOBALS['t_language']= $lang;
 
143
$GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
 
144
 
 
145
// Validate LDAP schema if not done already
 
146
if( $config->boolValueIsTrue('core','schemaCheck') && 
 
147
    !$config->configRegistry->schemaCheckFinished() && 
 
148
    !$config->configRegistry->validateSchemata($force=FALSE,$disableIncompatiblePlugins=TRUE)){
 
149
    $config->configRegistry->displayRequirementErrors();
 
150
}
 
151
 
 
152
/* Check if the config is up to date */
 
153
$config->check_config_version();
 
154
 
 
155
/* Set the text domain as 'messages' */
 
156
$domain = 'messages';
 
157
bindtextdomain($domain, LOCALE_DIR);
 
158
textdomain($domain);
 
159
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
 
160
 
 
161
/* Prepare plugin list */
 
162
if (!session::global_is_set('plist')){
 
163
  /* Initially load all classes */
 
164
  $class_list= get_declared_classes();
 
165
  foreach ($class_mapping as $class => $path){
 
166
    if (!in_array_strict($class, $class_list)){
 
167
      if (is_readable("$BASE_DIR/$path")){
 
168
        require_once("$BASE_DIR/$path");
 
169
      } else {
 
170
        msg_dialog::display(_("Fatal error"),
 
171
            sprintf(_("Cannot locate file %s - please run %s to fix this"),
 
172
              bold("$BASE_DIR/$path"), bold("update-gosa")), FATAL_ERROR_DIALOG);
 
173
        exit;
 
174
      }
 
175
    }
 
176
  }
 
177
 
 
178
  session::global_set('plist', new pluglist($config, $ui));
 
179
 
 
180
  /* Load ocMapping into userinfo */
 
181
  $tmp= new acl($config, NULL, $ui->dn);
 
182
  $ui->ocMapping= $tmp->ocMapping;
 
183
  session::global_set('ui',$ui);
 
184
}
 
185
$plist= session::global_get('plist');
 
186
 
 
187
/* Check for register globals */
 
188
if (isset($global_check) && $config->boolValueIsTrue("core","forceGlobals")){
 
189
  msg_dialog::display(
 
190
            _("PHP configuration"),
 
191
            _("Fatal error: Register globals is active. Please fix this in order to continue."),
 
192
            FATAL_ERROR_DIALOG);
 
193
 
 
194
  new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
 
195
  session::destroy ();
 
196
  exit;
 
197
}
 
198
 
 
199
/* Check Plugin variable */
 
200
if (session::global_is_set('plugin_dir')){
 
201
  $old_plugin_dir= session::global_get('plugin_dir');
 
202
} else {
 
203
  $old_plugin_dir= "";
 
204
}
 
205
 
 
206
// Generate menus 
 
207
$plist->gen_headlines();
 
208
$plist->gen_menu();
 
209
$plist->genPathMenu();
 
210
 
 
211
/* check if we are using account expiration */
 
212
$smarty->assign("hideMenus", FALSE);
 
213
if ($config->boolValueIsTrue("core","handleExpiredAccounts")){
 
214
    $expired= ldap_expired_account($config, $ui->dn, $ui->username);
 
215
 
 
216
    if ($expired == POSIX_WARN_ABOUT_EXPIRATION && !session::is_set('POSIX_WARN_ABOUT_EXPIRATION__DONE')){
 
217
 
 
218
        // The users password is about to xpire soon, display a warning message.
 
219
        new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
 
220
        msg_dialog::display(_("Password change"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
 
221
        session::set('POSIX_WARN_ABOUT_EXPIRATION__DONE', TRUE);
 
222
 
 
223
    } elseif ($expired == POSIX_FORCE_PASSWORD_CHANGE){
 
224
 
 
225
        // The password is expired, we are now going to enforce a new one from the user.
 
226
 
 
227
        // Hide the GOsa menus to avoid leaving the enforced password change dialog.
 
228
        $smarty->assign("hideMenus", TRUE);
 
229
        $plug = (isset($_GET['plug'])) ? $_GET['plug'] : null;
 
230
 
 
231
        // Detect password plugin id:
 
232
        $passId =  array_search('password', $plist->pluginList);
 
233
        if($passId !== FALSE){
 
234
            $_GET['plug'] = $passId;
 
235
        }
 
236
    }
 
237
}
 
238
 
 
239
$smarty->assign("noMenuMode", count($plist->getRegisteredMenuEntries()) == 0);
 
240
if (isset($_GET['plug']) && $plist->plugin_access_allowed($_GET['plug'])){
 
241
  $plug= validate($_GET['plug']);
 
242
  $plugin_dir= $plist->get_path($plug);
 
243
  $plugin= $plist->get_class($plug);
 
244
  session::global_set('currentPlugin',$plugin);
 
245
  session::global_set('plugin_dir',$plugin_dir);
 
246
  if ($plugin_dir == ""){
 
247
    new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
 
248
    header ("Location: logout.php");
 
249
    exit;
 
250
  }
 
251
} else {
 
252
    session::global_set('plugin_dir',"welcome");
 
253
    session::global_set('currentPlugin','welcome');
 
254
    $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
 
255
}
 
256
 
 
257
// Display the welcome page for admins (iconmenu) and an info page for those 
 
258
//  who are not allowed to adminstrate anything (user)
 
259
if(count($plist->getRegisteredMenuEntries()) == 0 && session::global_get('currentPlugin') == "welcome"){
 
260
    session::global_set('plugin_dir',"infoPage");
 
261
    session::global_set('currentPlugin','welcome');
 
262
    $plugin_dir= "$BASE_DIR/plugins/generic/infoPage";
 
263
 
264
 
 
265
/* Handle plugin locks.
 
266
    - Remove the plugin from session if we switched to another. (cleanup) 
 
267
    - Remove all created locks if "reset" was posted.
 
268
    - Remove all created locks if we switched to another plugin.
 
269
*/
 
270
$cleanup    = FALSE;
 
271
$remove_lock= FALSE;
 
272
 
 
273
/* Check if we have changed the selected plugin 
 
274
*/
 
275
if(($old_plugin_dir != $plugin_dir && $old_plugin_dir != "") || 
 
276
    (isset($_GET['reset']) && $_GET['reset'] == 1)){
 
277
  if (is_file("$old_plugin_dir/main.inc")){
 
278
    $cleanup = $remove_lock = TRUE;
 
279
    require ("$old_plugin_dir/main.inc");
 
280
    $cleanup = $remove_lock = FALSE;
 
281
  }
 
282
}else // elseif
 
283
 
 
284
/* Reset was posted, remove all created locks for the current plugin
 
285
*/
 
286
if((isset($_GET['reset']) && $_GET['reset'] == 1) || isset($_POST['delete_lock'])){
 
287
  $remove_lock = TRUE;
 
288
}
 
289
 
 
290
/* Check for sizelimits */
 
291
eval_sizelimit();
 
292
 
 
293
/* Check for memory */
 
294
if (function_exists("memory_get_usage")){
 
295
  if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
 
296
    msg_dialog::display(_("Configuration error"), _("Running out of memory!"), WARNING_DIALOG);
 
297
  }
 
298
}
 
299
 
 
300
/* Redirect on back event */
 
301
if ($_SERVER["REQUEST_METHOD"] == "POST"){
 
302
 
 
303
  /* Look for button events that match /^back[0-9]+$/,
 
304
     extract the number and step the correct plugin. */
 
305
  foreach ($_POST as $key => $value){
 
306
    if (preg_match("/^back[0-9]+$/", $key)){
 
307
      $back= substr($key, 4);
 
308
      header ("Location: main.php?plug=$back");
 
309
      exit;
 
310
    }
 
311
  }
 
312
}
 
313
 
 
314
/* Redirect on password back event */
 
315
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
 
316
  header ("Location: main.php");
 
317
  exit;
 
318
}
 
319
 
 
320
/* Check for multiple windows logout */
 
321
if ($_SERVER["REQUEST_METHOD"] == "POST"){
 
322
  if (isset($_POST['reset_session'])){
 
323
    header ("Location: logout.php");
 
324
    exit;
 
325
  }
 
326
}
 
327
 
 
328
 
 
329
/* Load department list when plugin has changed. That is some kind of
 
330
   compromise between speed and beeing up to date */
 
331
if (isset($_GET['reset'])){
 
332
  set_object_info();
 
333
}
 
334
 
 
335
/* show web frontend */
 
336
$smarty->assign ("title","GOsa");
 
337
$smarty->assign ("logo", image(get_template_path("images/logo.png")));
 
338
$smarty->assign ("logoutimage", get_template_path("images/btn-logout.png"));
 
339
$smarty->assign ("date", date("l, dS F Y H:i:s O"));
 
340
$smarty->assign ("lang", preg_replace('/_.*$/', '', $lang));
 
341
$smarty->assign ("must", "<span class='required'>*</span>");
 
342
if (isset($plug)){
 
343
  $plug= "?plug=$plug";
 
344
} else {
 
345
  $plug= "";
 
346
}
 
347
if (session::global_get('js')==FALSE){
 
348
  $smarty->assign("javascript", "false");
 
349
  $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
 
350
} else {
 
351
  $smarty->assign("javascript", "true");
 
352
  $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
 
353
}
 
354
 
 
355
 
 
356
$loggedin = sprintf(_("You're logged in as %s"), 
 
357
    "<span>".$ui->cn." [".$ui->username."] / ".$config->current['NAME']."</span> &nbsp;");
 
358
if($ui->ignore_acl_for_current_user()){
 
359
    $loggedin = "<font color='red'>"._("ACLs are disabled")."</font>&nbsp;".$loggedin;
 
360
}
 
361
 
 
362
$smarty->assign ("loggedin", $loggedin);
 
363
$smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
 
364
$smarty->assign ("go_base", get_template_path('images/dtree.png'));
 
365
$smarty->assign ("go_home", get_template_path('images/gohome.png'));
 
366
$smarty->assign ("go_out", get_template_path('images/logout.png'));
 
367
$smarty->assign ("go_top", get_template_path('images/go_top.png'));
 
368
$smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
 
369
$smarty->assign ("go_left", get_template_path('images/go_left.png'));
 
370
$smarty->assign ("go_help", get_template_path('images/help.png'));
 
371
 
 
372
/* reload navigation if language changed*/  
 
373
if($reload_navigation){
 
374
  $plist->menu="";
 
375
}
 
376
$smarty->assign ("menu", $plist->gen_menu());
 
377
$smarty->assign ("plug", "$plug");
 
378
 
 
379
 
 
380
/* React on clicks */
 
381
if ($_SERVER["REQUEST_METHOD"] == "POST"){
 
382
  if (isset($_POST['delete_lock']) || isset($_POST['open_readonly'])){
 
383
 
 
384
    /* Set old Post data */
 
385
    if(session::global_is_set('LOCK_VARS_USED_GET')){
 
386
      foreach(session::global_get('LOCK_VARS_USED_GET') as $name => $value){
 
387
        $_GET[$name]  = $value;
 
388
      } 
 
389
    } 
 
390
    if(session::global_is_set('LOCK_VARS_USED_POST')){
 
391
      foreach(session::global_get('LOCK_VARS_USED_POST') as $name => $value){
 
392
        $_POST[$name] = $value;
 
393
      } 
 
394
    }
 
395
    if(session::global_is_set('LOCK_VARS_USED_REQUEST')){
 
396
      foreach(session::global_get('LOCK_VARS_USED_REQUEST') as $name => $value){
 
397
        $_REQUEST[$name] = $value;
 
398
      } 
 
399
    }
 
400
  }
 
401
}
 
402
 
 
403
/* Load plugin */
 
404
if (is_file("$plugin_dir/main.inc")){
 
405
  $display ="";
 
406
  require ("$plugin_dir/main.inc");
 
407
} else {
 
408
  msg_dialog::display(
 
409
      _("Plug-in"),
 
410
      sprintf(_("Fatal error: Cannot find any plugin definitions for plugin %s!"), bold($plug)),
 
411
      FATAL_ERROR_DIALOG);
 
412
  exit();
 
413
}
 
414
 
 
415
 
 
416
/* Print_out last ErrorMessage repeated string. */
 
417
$smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
 
418
$smarty->assign ("pathMenu", $plist->genPathMenu());
 
419
$smarty->assign("contents", $display);
 
420
$smarty->assign("sessionLifetime", $config->get_cfg_value('core','sessionLifetime'));
 
421
 
 
422
/* If there's some post, take a look if everything is there... */
 
423
if (isset($_POST) && count($_POST)){
 
424
  if (!isset($_POST['php_c_check'])){
 
425
    msg_dialog::display(
 
426
            _("Configuration Error"),
 
427
            sprintf(_("Fatal error: not all POST variables have been transfered by PHP - please inform your administrator!")),
 
428
            FATAL_ERROR_DIALOG);
 
429
    exit();
 
430
  }
 
431
}
 
432
 
 
433
/* Assign erros to smarty */
 
434
if (session::is_set('errors')){
 
435
  $smarty->assign("errors", session::get('errors'));
 
436
}
 
437
if ($error_collector != ""){
 
438
  $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
 
439
} else {
 
440
  $smarty->assign("php_errors", "");
 
441
}
 
442
 
 
443
/* Set focus to the error button if we've an error message */
 
444
$focus= "";
 
445
if (session::is_set('errors') && session::get('errors') != ""){
 
446
  $focus= '<script language="JavaScript" type="text/javascript">';
 
447
  $focus.= 'document.forms[0].error_accept.focus();';
 
448
  $focus.= '</script>';
 
449
}
 
450
 
 
451
$focus= '<script language="JavaScript" type="text/javascript">';
 
452
$focus.= 'next_msg_dialog();';
 
453
$focus.= '</script>';
 
454
$smarty->assign("focus", $focus);
 
455
 
 
456
/* Set channel if needed */
 
457
#TODO: * move all global session calls to global_
 
458
#      * create a new channel where needed (mostly management dialogues)
 
459
#      * remove regulary created channels when not needed anymore
 
460
#      * take a look at external php calls (i.e. get fax, ldif, etc.)
 
461
#      * handle aborted sessions (by pressing anachors i.e. Main, Menu, etc.)
 
462
#      * check lock removals, is "dn" global or not in this case?
 
463
#      * last page request -> global or not?
 
464
#      * check that filters are still global
 
465
#      * maxC global?
 
466
if (isset($_POST['_channel_'])){
 
467
        echo "DEBUG - current channel: ".$_POST['_channel_'];
 
468
        $smarty->assign("channel", $_POST['_channel_']);
 
469
} else {
 
470
        $smarty->assign("channel", "");
 
471
}
 
472
 
 
473
$display= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl')).
 
474
          $smarty->fetch(get_template_path('framework.tpl'));
 
475
 
 
476
/* Save dialog filters and selected base in a cookie. 
 
477
   So we may be able to restore the filter an base settings on reload.
 
478
*/
 
479
$cookie = array();
 
480
 
 
481
if(isset($_COOKIE['GOsa_Filter_Settings'])){
 
482
  $cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
 
483
}elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
 
484
  $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
 
485
}
 
486
 
 
487
/* Save filters? */
 
488
if($config->get_cfg_value("core","storeFilterSettings") == "true"){
 
489
  $cookie_vars = array("MultiDialogFilters","CurrentMainBase");
 
490
  foreach($cookie_vars as $var){
 
491
    if(session::global_is_set($var)){
 
492
      $cookie[$ui->dn][$var] = session::global_get($var);
 
493
    }
 
494
  }
 
495
  if(isset($_GET['plug'])){
 
496
    $cookie[$ui->dn]['plug'] = $_GET['plug'];
 
497
  }
 
498
  @setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
 
499
}
 
500
 
 
501
/* Show page... */
 
502
echo $display;
 
503
 
 
504
/* Save plist and config */
 
505
session::global_set('plist',$plist);
 
506
session::global_set('config',$config);
 
507
session::set('errorsAlreadyPosted',array());
 
508
 
 
509
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 
510
?>