2009-06-30 08:07:14 +00:00
|
|
|
<?php
|
2009-06-30 10:41:18 +00:00
|
|
|
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/common.php,v 1.79 2006/09/17 07:22:09 wurley Exp $
|
2009-06-30 08:07:14 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
/**
|
2009-06-30 08:07:14 +00:00
|
|
|
* Contains code to be executed at the top of each phpLDAPadmin page.
|
|
|
|
* include this file at the top of every PHP file.
|
2009-06-30 09:29:51 +00:00
|
|
|
*
|
|
|
|
* This file will "pre-initialise" a PLA environment so that any PHP file will have a consistent
|
|
|
|
* environment with other PLA PHP files.
|
|
|
|
*
|
|
|
|
* This code WILL NOT check that all required functions are usable/readable, etc. This process has
|
|
|
|
* been moved to index.php (which really is only called once when a browser hits PLA for the first time).
|
|
|
|
*
|
|
|
|
* The list of ADDITIONAL function files is now defined in functions.php.
|
|
|
|
*
|
|
|
|
* @package phpLDAPadmin
|
2009-06-30 08:07:14 +00:00
|
|
|
*/
|
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
$timer = stopwatch();
|
|
|
|
|
2009-06-30 09:40:37 +00:00
|
|
|
@define('LIBDIR','../lib/');
|
2009-06-30 08:09:20 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
# For PHP5 backward/forward compatibility
|
|
|
|
if (! defined('E_STRICT'))
|
|
|
|
define('E_STRICT',2048);
|
2009-06-30 08:09:20 +00:00
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
# General functions needed to proceed.
|
2009-06-30 08:10:17 +00:00
|
|
|
ob_start();
|
2009-06-30 09:29:51 +00:00
|
|
|
require_once realpath(LIBDIR.'functions.php');
|
2009-06-30 08:10:17 +00:00
|
|
|
ob_end_clean();
|
2009-06-30 08:09:20 +00:00
|
|
|
|
2009-06-30 10:40:03 +00:00
|
|
|
# Turn on all notices and warnings. This helps us write cleaner code (we hope at least)
|
|
|
|
if (phpversion() < 5)
|
|
|
|
pla_error('Sorry, PLA is now a PHP5 application.<BR>For a PHP4 application, please use a 0.9.x version.');
|
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
/* Our custom error handler receives all error notices that pass the error_reporting()
|
|
|
|
level set above. */
|
|
|
|
set_error_handler('pla_error_handler');
|
2009-06-30 09:40:37 +00:00
|
|
|
# Disable error reporting until all our required functions are loaded.
|
|
|
|
error_reporting(0);
|
2009-06-30 08:09:20 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
/*
|
|
|
|
* functions.php should have defined our pla_function_files array, listing all our
|
|
|
|
* required functions (order IS important).
|
|
|
|
* index.php should have checked they exist and are usable - we'll assume that the user
|
|
|
|
* has been via index.php, and fixed any problems already.
|
|
|
|
*/
|
|
|
|
ob_start();
|
|
|
|
foreach ($pla_function_files as $file_name) {
|
|
|
|
require_once realpath ($file_name);
|
2009-06-30 09:22:30 +00:00
|
|
|
}
|
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
# Now read in config_default.php, which also reads in config.php
|
|
|
|
require_once realpath(LIBDIR.'config_default.php');
|
|
|
|
ob_end_clean();
|
2009-06-30 08:09:20 +00:00
|
|
|
|
2009-06-30 09:40:37 +00:00
|
|
|
# We are now ready for error reporting.
|
2009-06-30 10:40:03 +00:00
|
|
|
error_reporting(E_DEBUG);
|
2009-06-30 09:40:37 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
/**
|
|
|
|
* At this point we have read all our additional function PHP files and our configuration.
|
|
|
|
*/
|
2009-06-30 08:07:14 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
# Check our custom variables.
|
|
|
|
$config->CheckCustom();
|
2009-06-30 08:10:17 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
if (pla_session_start())
|
|
|
|
run_hook('post_session_init',array());
|
2009-06-30 08:10:17 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
/*
|
|
|
|
* Language configuration. Auto or specified?
|
|
|
|
* Shall we attempt to auto-determine the language?
|
|
|
|
*/
|
2009-06-30 09:40:37 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
$language = $config->GetValue('appearance','language');
|
2009-06-30 09:40:37 +00:00
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
if ($language == 'auto') {
|
2009-06-30 09:29:51 +00:00
|
|
|
|
|
|
|
# Make sure their browser correctly reports language. If not, skip this.
|
2009-06-30 10:26:08 +00:00
|
|
|
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
|
|
|
|
|
|
|
# Get the languages which are spetcified in the HTTP header
|
|
|
|
$HTTP_LANGS = preg_split ('/[;,]+/',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
|
|
|
foreach ($HTTP_LANGS as $key => $value) {
|
|
|
|
if (substr($value,0,2) == 'q=') {
|
|
|
|
unset($HTTP_LANGS[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$value = preg_split('/[-]+/',$value);
|
|
|
|
if (sizeof($value) == 2)
|
|
|
|
$HTTP_LANGS[$key] = strtolower($value[0]).'_'.strtoupper($value[1]);
|
|
|
|
else
|
|
|
|
$HTTP_LANGS[$key] = auto_lang(strtolower($value[0]));
|
2009-06-30 08:09:20 +00:00
|
|
|
}
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
$HTTP_LANGS = array_unique($HTTP_LANGS);
|
|
|
|
|
|
|
|
foreach ($HTTP_LANGS as $HTTP_LANG) {
|
|
|
|
# Try to grab one after the other the language file
|
|
|
|
$language_file = LANGDIR.$HTTP_LANG;
|
|
|
|
|
|
|
|
if ((substr($HTTP_LANG,0,2) == 'en') ||
|
|
|
|
(file_exists($language_file) && is_readable($language_file))) {
|
|
|
|
|
|
|
|
# Set language
|
|
|
|
putenv('LANG='.$HTTP_LANG); # e.g. LANG=de_DE
|
2009-06-30 10:41:18 +00:00
|
|
|
$HTTP_LANG .= '.UTF-8';
|
2009-06-30 10:26:08 +00:00
|
|
|
setlocale(LC_ALL,$HTTP_LANG); # set LC_ALL to de_DE
|
|
|
|
bindtextdomain('messages',LANGDIR);
|
|
|
|
bind_textdomain_codeset('messages','UTF-8');
|
|
|
|
textdomain('messages');
|
|
|
|
header('Content-type: text/html; charset=UTF-8',true);
|
2009-06-30 09:29:51 +00:00
|
|
|
break;
|
2009-06-30 08:09:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-30 09:29:51 +00:00
|
|
|
|
|
|
|
} else {
|
2009-06-30 10:26:08 +00:00
|
|
|
# Grab the language file configured in config.php
|
|
|
|
if ($language != null) {
|
|
|
|
if (strcmp($language,'english') == 0)
|
|
|
|
$language = 'en_GB';
|
|
|
|
|
|
|
|
$language_file = LANGDIR.$language;
|
|
|
|
|
|
|
|
# Set language
|
|
|
|
putenv('LANG='.$language); # e.g. LANG=de_DE
|
2009-06-30 10:41:18 +00:00
|
|
|
$language .= '.UTF-8';
|
2009-06-30 10:26:08 +00:00
|
|
|
setlocale(LC_ALL,$language); # set LC_ALL to de_DE
|
|
|
|
bindtextdomain('messages',LANGDIR);
|
|
|
|
bind_textdomain_codeset('messages','UTF-8');
|
|
|
|
textdomain('messages');
|
|
|
|
header('Content-type: text/html; charset=UTF-8', true);
|
2009-06-30 09:29:51 +00:00
|
|
|
}
|
2009-06-30 08:09:20 +00:00
|
|
|
}
|
2009-06-30 08:07:14 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
# If config.php doesn't create the templates array, create it here.
|
|
|
|
if (! isset($templates) || ! is_array($templates))
|
2009-06-30 08:09:20 +00:00
|
|
|
$templates = array();
|
2009-06-30 08:07:14 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
# Always including the 'custom' template (the most generic and flexible)
|
|
|
|
$templates['custom'] =
|
|
|
|
array('desc' => 'Custom',
|
|
|
|
'icon' => 'images/object.png',
|
2009-06-30 10:26:08 +00:00
|
|
|
'handler' => 'custom.php');
|
2009-06-30 08:07:14 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
/*
|
|
|
|
* Strip slashes from GET, POST, and COOKIE variables if this
|
|
|
|
* PHP install is configured to automatically addslashes()
|
|
|
|
*/
|
|
|
|
if (get_magic_quotes_gpc() && (! isset($slashes_stripped) || ! $slashes_stripped)) {
|
|
|
|
array_stripslashes($_REQUEST);
|
2009-06-30 08:07:14 +00:00
|
|
|
array_stripslashes($_GET);
|
2009-06-30 08:09:20 +00:00
|
|
|
array_stripslashes($_POST);
|
|
|
|
array_stripslashes($_COOKIE);
|
2009-06-30 08:07:14 +00:00
|
|
|
$slashes_stripped = true;
|
|
|
|
}
|
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
/*
|
|
|
|
* Update $_SESSION['activity']
|
|
|
|
* for timeout and automatic logout feature
|
|
|
|
*/
|
|
|
|
if (isset($_REQUEST['server_id'])) {
|
|
|
|
$ldapserver = $ldapservers->Instance($_REQUEST['server_id']);
|
|
|
|
if ($ldapserver->haveAuthInfo())
|
|
|
|
set_lastactivity($ldapserver);
|
|
|
|
}
|
2009-06-30 10:26:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Timer stopwatch, used to instrument PLA
|
|
|
|
*/
|
|
|
|
function stopwatch() {
|
|
|
|
static $mt_previous = 0;
|
|
|
|
|
|
|
|
list($usec, $sec) = explode(' ',microtime());
|
|
|
|
$mt_current = (float)$usec + (float)$sec;
|
|
|
|
|
|
|
|
if (! $mt_previous) {
|
|
|
|
$mt_previous = $mt_current;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$mt_diff = ($mt_current - $mt_previous);
|
|
|
|
$mt_previous = $mt_current;
|
|
|
|
return sprintf('%.5f',$mt_diff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will convert the browser two character language into the
|
|
|
|
* default 5 character language, where the country portion should NOT be
|
|
|
|
* assumed to be upper case characters of the first two characters.
|
|
|
|
*/
|
|
|
|
function auto_lang($lang) {
|
|
|
|
switch ($lang) {
|
|
|
|
case 'ja': return 'ja_JP';
|
|
|
|
default: return sprintf('%s_%s',$lang,strtoupper($lang));
|
|
|
|
}
|
|
|
|
}
|
2009-06-30 08:07:14 +00:00
|
|
|
?>
|