phpldapadmin/common.php

181 lines
6.5 KiB
PHP
Raw Normal View History

2009-06-30 08:07:14 +00:00
<?php
2009-06-30 09:24:29 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/common.php,v 1.59 2005/03/16 11:20:23 wurley Exp $
2009-06-30 08:07:14 +00:00
2009-06-30 09:24:29 +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:24:29 +00:00
*
* @package phpLDAPadmin
2009-06-30 08:07:14 +00:00
*/
2009-06-30 09:22:30 +00:00
// Work-around to get PLA to work in PHP5
if( phpversion() >= "5" )
ini_set( "zend.ze1_compatibility_mode", 1 );
2009-06-30 08:09:20 +00:00
// Turn on all notices and warnings. This helps us write cleaner code (we hope at least)
2009-06-30 09:22:30 +00:00
if( phpversion() >= "5" )
// E_DEBUG is PHP5 specific and prevents warnings about using 'var' to declar class members
error_reporting( 'E_DEBUG' );
else
// For PHP4
error_reporting( E_ALL );
2009-06-30 08:09:20 +00:00
2009-06-30 09:24:29 +00:00
/**
* For PHP5 backward/forward compatibility
*/
2009-06-30 09:22:30 +00:00
if( ! defined( 'E_STRICT' ) ) {
define( 'E_STRICT', 2048 );
2009-06-30 08:07:14 +00:00
}
2009-06-30 08:09:20 +00:00
2009-06-30 09:22:30 +00:00
/** The minimum version of PHP required to run phpLDAPadmin. */
@define( 'REQUIRED_PHP_VERSION', '4.1.0' );
/** The default setting for $search_deref if unspecified or misconfigured by user. */
@define( 'DEFAULT_SEARCH_DEREF_SETTING', LDAP_DEREF_ALWAYS );
/** The default setting for $tree_deref if unspecified or misconfigured by user. */
@define( 'DEFAULT_TREE_DEREF_SETTING', LDAP_DEREF_NEVER );
/** The default setting for $export_deref if unspecified or misconfigured by user. */
@define( 'DEFAULT_EXPORT_DEREF_SETTING', LDAP_DEREF_NEVER );
/** The default setting for $view_deref if unspecified or misconfigured by user. */
@define( 'DEFAULT_VIEW_DEREF_SETTING', LDAP_DEREF_NEVER );
// General functions needed to proceed (pla_ldap_search(), pla_error(), get_object_attrs(), etc.)
2009-06-30 08:10:17 +00:00
ob_start();
2009-06-30 09:22:30 +00:00
if( ! file_exists( realpath( './functions.php' ) ) ) {
ob_end_clean();
die( "Fatal error: Required file 'functions.php' does not exist." );
2009-06-30 09:24:29 +00:00
}
2009-06-30 09:22:30 +00:00
if( ! is_readable( realpath( './functions.php' ) ) ) {
ob_end_clean();
die( "Cannot read the file 'functions.php' its permissions are too strict." );
}
require_once realpath( './functions.php' );
2009-06-30 08:10:17 +00:00
ob_end_clean();
2009-06-30 08:09:20 +00:00
// Our custom error handler receives all error notices that pass the error_reporting()
// level set above.
set_error_handler( 'pla_error_handler' );
// Creates the language array which will be populated with localized strings
// based on the user-configured language.
$lang = array();
2009-06-30 09:22:30 +00:00
// config.php might not exist (if the user hasn't configured PLA yet)
// Only include it if it does exist.
if( file_exists( realpath( './config.php' ) ) ) {
ob_start();
is_readable( realpath( './config.php' ) ) or pla_error( "Could not read config.php, its permissions are too strict." );
include realpath( './config.php' );
ob_end_clean();
}
2009-06-30 09:24:29 +00:00
$required_files = array(
2009-06-30 09:22:30 +00:00
// The base English language strings
'./lang/recoded/en.php',
2009-06-30 09:24:29 +00:00
// Functions for talking to LDAP servers.
'./server_functions.php',
2009-06-30 09:22:30 +00:00
// Functions for managing the session (pla_session_start(), etc.)
2009-06-30 09:24:29 +00:00
'./session_functions.php',
2009-06-30 09:22:30 +00:00
// Functions for reading the server schema (get_schema_object_classes(), etc.)
2009-06-30 09:24:29 +00:00
'./schema_functions.php',
2009-06-30 09:22:30 +00:00
// Functions that can be defined by the user (preEntryDelete(), postEntryDelete(), etc.)
'./custom_functions.php',
// Functions for hashing passwords with OpenSSL binary (only if mhash not present)
2009-06-30 09:24:29 +00:00
'./emuhash_functions.php',
// Functions for sending syslog messages
'./syslog.php',
// Functions for running various hooks
'./hooks.php',
// Functions for timeout and automatic logout feature
'./timeout_functions.php' );
2009-06-30 09:22:30 +00:00
// Include each required file and check for sanity.
foreach( $required_files as $file_name ) {
file_exists( realpath( $file_name ) )
or pla_error( "Fatal error: Required file '$file_name' does not exist." );
2009-06-30 09:24:29 +00:00
is_readable( realpath( $file_name ) )
2009-06-30 09:22:30 +00:00
or pla_error( "Fatal error: Cannot read the file '$file_name', its permissions are too strict." );
ob_start();
require_once realpath( $file_name );
ob_end_clean();
2009-06-30 08:09:20 +00:00
}
2009-06-30 09:22:30 +00:00
if( pla_session_start() )
2009-06-30 09:24:29 +00:00
run_hook ( 'post_session_init', array () );
2009-06-30 08:07:14 +00:00
2009-06-30 08:09:20 +00:00
// Language configuration. Auto or specified?
// Shall we attempt to auto-determine the language?
if( isset( $language ) ) {
if( 0 == strcasecmp( $language, "auto" ) ) {
2009-06-30 08:10:17 +00:00
// Make sure their browser correctly reports language. If not, skip this.
if( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) {
// get the languages which are spetcified in the HTTP header
$HTTP_LANGS1 = preg_split ("/[;,]+/", $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
$HTTP_LANGS2 = preg_split ("/[;,]+/", $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
foreach( $HTTP_LANGS2 as $key => $value ) {
$value=preg_split ("/[-]+/", $value );
$HTTP_LANGS2[$key]=$value[0];
}
2009-06-30 09:24:29 +00:00
2009-06-30 08:10:17 +00:00
$HTTP_LANGS = array_merge ($HTTP_LANGS1, $HTTP_LANGS2);
foreach( $HTTP_LANGS as $HTTP_LANG) {
// try to grab one after the other the language file
if( file_exists( realpath( "lang/recoded/$HTTP_LANG.php" ) ) &&
is_readable( realpath( "lang/recoded/$HTTP_LANG.php" ) ) ) {
2009-06-30 09:22:30 +00:00
ob_start();
2009-06-30 08:10:17 +00:00
include realpath( "lang/recoded/$HTTP_LANG.php" );
2009-06-30 09:22:30 +00:00
ob_end_clean();
2009-06-30 08:10:17 +00:00
break;
}
2009-06-30 08:09:20 +00:00
}
}
2009-06-30 09:24:29 +00:00
2009-06-30 08:09:20 +00:00
} else {
// grab the language file configured in config.php
if( $language != null ) {
if( 0 == strcmp( $language, 'english' ) )
$language = 'en';
if( file_exists( realpath( "lang/recoded/$language.php" ) ) &&
is_readable( realpath( "lang/recoded/$language.php" ) ) ) {
2009-06-30 09:22:30 +00:00
ob_start();
2009-06-30 08:09:20 +00:00
include realpath( "lang/recoded/$language.php" );
2009-06-30 09:22:30 +00:00
ob_end_clean();
2009-06-30 09:24:29 +00:00
} else {
pla_error( "Could not read language file 'lang/recoded/$language.php'. Either the file
2009-06-30 09:22:30 +00:00
does not exist, or its permissions do not allow phpLDAPadmin to read it." );
2009-06-30 08:09:20 +00:00
}
}
}
}
2009-06-30 08:07:14 +00:00
2009-06-30 08:09:20 +00:00
// If config.php doesn't create the templates array, create it here.
2009-06-30 08:07:14 +00:00
if( ! isset( $templates ) || ! is_array( $templates ) )
2009-06-30 08:09:20 +00:00
$templates = array();
2009-06-30 08:07:14 +00:00
// Always including the 'custom' template (the most generic and flexible)
2009-06-30 09:24:29 +00:00
$templates['custom'] =
2009-06-30 08:07:14 +00:00
array( 'desc' => 'Custom',
'icon' => 'images/object.png',
'handler' => 'custom.php' );
// 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 ) ) {
2009-06-30 09:24:29 +00:00
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 09:22:30 +00:00
array_stripslashes($_FILES);
2009-06-30 08:07:14 +00:00
$slashes_stripped = true;
}
2009-06-30 09:24:29 +00:00
// Update $_SESSION[ 'activity' ]
// for timeout and automatic logout feature
if ( isset($_REQUEST['server_id']) ) {
$ldapserver = new LDAPServer($_REQUEST['server_id']);
if ( $ldapserver->haveAuthInfo() )
set_lastactivity( $ldapserver );
}
2009-06-30 08:07:14 +00:00
?>