From 4c1fb57a858e4c2d8ce1377096f90174225c2e81 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 25 Jan 2010 16:56:19 +0000 Subject: [PATCH] moved environment checks to separate file and added check for SPL extension --- lam/lib/checkEnvironment.inc | 121 +++++++++++++++++++++++++++++++++++ lam/templates/login.php | 84 +----------------------- 2 files changed, 123 insertions(+), 82 deletions(-) create mode 100644 lam/lib/checkEnvironment.inc diff --git a/lam/lib/checkEnvironment.inc b/lam/lib/checkEnvironment.inc new file mode 100644 index 00000000..2b0071ba --- /dev/null +++ b/lam/lib/checkEnvironment.inc @@ -0,0 +1,121 @@ += 5.1 +if (version_compare(phpversion(), '5.1.0') < 0) { + echo "\n\n"; + echo "\n\n"; + echo "\n"; + echo "\n \n"; + echo "\n"; + echo "\n"; + echo "LDAP Account Manager\n"; + echo "\n"; + StatusMessage("ERROR", "LAM needs a PHP 5 version which is greater or equal than 5.1.0.", "Please upgrade your PHP installation. The found version is " . phpversion()); + echo "

"; + echo ""; + exit(); +} + +// check environment +$criticalErrors = array(); +// check if PHP has session support +if (! function_exists('session_start')) { + $criticalErrors[] = array("ERROR", "Your PHP has no session support!", "Please install the session extension for PHP."); +} +// check if PHP has SPL support +if (! function_exists('class_implements')) { + $criticalErrors[] = array("ERROR", "Your PHP has no SPL support!", "Please install the SPL extension for PHP."); +} +// check if PHP has LDAP support +if (! function_exists('ldap_search')) { + $criticalErrors[] = array("ERROR", "Your PHP has no LDAP support!", "Please install the LDAP extension for PHP."); +} +// check if PHP has gettext support +if (! function_exists('gettext') || !function_exists('_')) { + $criticalErrors[] = array("ERROR", "Your PHP has no gettext support!", "Please install gettext for PHP."); +} +// check if PHP has XML support +if (! function_exists('utf8_decode')) { + $criticalErrors[] = array("ERROR", "Your PHP has no XML support!", "Please install the XML extension for PHP."); +} +// check if PHP has GD support +if (! function_exists('getimagesize')) { + $criticalErrors[] = array("ERROR", "Your PHP has no GD support!", "Please install the GD extension for PHP."); +} +// check file permissions +$writableDirs = array('sess', 'tmp'); +for ($i = 0; $i < sizeof($writableDirs); $i++) { + $path = realpath('../') . "/" . $writableDirs[$i]; + if (!is_writable($path)) { + $criticalErrors[] = array("ERROR", 'The directory %s is not writable for the web server. Please change your file permissions.', '', array($path)); + } +} +// check session auto start +if (ini_get("session.auto_start") == "1") { + $criticalErrors[] = array("ERROR", "Please deactivate session.auto_start in your php.ini. LAM will not work if it is activated."); +} +// check memory limit +$memLimit = ini_get('memory_limit'); +if (isset($memLimit) && ($memLimit != '') && (substr(strtoupper($memLimit), strlen($memLimit) - 1) == 'M')) { + if (intval(substr($memLimit, 0, strlen($memLimit) - 1)) < 64) { + $criticalErrors[] = array("ERROR", "Please increase the \"memory_limit\" parameter in your php.ini to at least \"64M\".", + "Your current memory limit is $memLimit."); + } +} +// check PCRE regex system +if (!@preg_match('/^\p{L}+$/u', "abc")) { + $criticalErrors[] = array("ERROR", "Your PCRE library has no complete Unicode support. Please upgrade libpcre or compile with \"--enable-unicode-properties\"."); +} +// stop login if critical errors occured +if (sizeof($criticalErrors) > 0) { + echo "\n\n"; + echo "\n\n"; + echo "\n"; + echo "\n \n"; + echo "\n"; + echo "\n"; + echo "LDAP Account Manager\n"; + echo "\n"; + for ($i = 0; $i < sizeof($criticalErrors); $i++) { + call_user_func_array("StatusMessage", $criticalErrors[$i]); + echo "

"; + } + echo ""; + exit(); +} + + +?> \ No newline at end of file diff --git a/lam/templates/login.php b/lam/templates/login.php index 03748b66..a39dcb9e 100644 --- a/lam/templates/login.php +++ b/lam/templates/login.php @@ -33,93 +33,13 @@ $Id$ /** status messages */ include_once("../lib/status.inc"); -// check if PHP >= 5.1 -if (version_compare(phpversion(), '5.1.0') < 0) { - echo "\n\n"; - echo "\n\n"; - echo "\n"; - echo "\n \n"; - echo "\n"; - echo "\n"; - echo "LDAP Account Manager\n"; - echo "\n"; - StatusMessage("ERROR", "LAM needs PHP 5 greater or equal as 5.1.0!", "Please upgrade your PHP installation."); - echo "

"; - echo ""; - exit(); -} - +/** check environment */ +include '../lib/checkEnvironment.inc'; /** security functions */ include_once("../lib/security.inc"); /** self service functions */ include_once("../lib/selfService.inc"); - -// check environment -$criticalErrors = array(); -// check if PHP has session support -if (! function_exists('session_start')) { - $criticalErrors[] = array("ERROR", "Your PHP has no session support!", "Please install the session extension for PHP."); -} -// check if PHP has LDAP support -if (! function_exists('ldap_search')) { - $criticalErrors[] = array("ERROR", "Your PHP has no LDAP support!", "Please install the LDAP extension for PHP."); -} -// check if PHP has gettext support -if (! function_exists('gettext') || !function_exists('_')) { - $criticalErrors[] = array("ERROR", "Your PHP has no gettext support!", "Please install gettext for PHP."); -} -// check if PHP has XML support -if (! function_exists('utf8_decode')) { - $criticalErrors[] = array("ERROR", "Your PHP has no XML support!", "Please install the XML extension for PHP."); -} -// check if PHP has GD support -if (! function_exists('getimagesize')) { - $criticalErrors[] = array("ERROR", "Your PHP has no GD support!", "Please install the GD extension for PHP."); -} -// check file permissions -$writableDirs = array('sess', 'tmp'); -for ($i = 0; $i < sizeof($writableDirs); $i++) { - $path = realpath('../') . "/" . $writableDirs[$i]; - if (!is_writable($path)) { - $criticalErrors[] = array("ERROR", 'The directory %s is not writable for the web server. Please change your file permissions.', '', array($path)); - } -} -// check session auto start -if (ini_get("session.auto_start") == "1") { - $criticalErrors[] = array("ERROR", "Please deactivate session.auto_start in your php.ini. LAM will not work if it is activated."); -} -// check memory limit -$memLimit = ini_get('memory_limit'); -if (isset($memLimit) && ($memLimit != '') && (substr(strtoupper($memLimit), strlen($memLimit) - 1) == 'M')) { - if (intval(substr($memLimit, 0, strlen($memLimit) - 1)) < 64) { - $criticalErrors[] = array("ERROR", "Please increase the \"memory_limit\" parameter in your php.ini to at least \"64M\".", - "Your current memory limit is $memLimit."); - } -} -// check PCRE regex system -if (!@preg_match('/^\p{L}+$/u', "abc")) { - $criticalErrors[] = array("ERROR", "Your PCRE library has no complete Unicode support. Please upgrade libpcre or compile with \"--enable-unicode-properties\"."); -} -// stop login if critical errors occured -if (sizeof($criticalErrors) > 0) { - echo "\n\n"; - echo "\n\n"; - echo "\n"; - echo "\n \n"; - echo "\n"; - echo "\n"; - echo "LDAP Account Manager\n"; - echo "\n"; - for ($i = 0; $i < sizeof($criticalErrors); $i++) { - call_user_func_array("StatusMessage", $criticalErrors[$i]); - echo "

"; - } - echo ""; - exit(); -} - - /** access to configuration options */ include_once("../lib/config.inc"); // Include config.inc which provides Config class