clear old config values

This commit is contained in:
Sebastian Mendel
2005-12-07 08:32:21 +00:00
parent 8fb1f3ce4c
commit 50c4439d30

View File

@@ -2,8 +2,8 @@
/* $Id$ */ /* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4: // vim: expandtab sw=4 ts=4 sts=4:
class PMA_Config { class PMA_Config
{
/** /**
* @var string default config source * @var string default config source
*/ */
@@ -56,11 +56,13 @@ class PMA_Config {
* *
* @param string source to read config from * @param string source to read config from
*/ */
function __construct( $source = NULL ) { function __construct($source = NULL)
{
$this->settings = array();
// functions need to refresh in case of config file changed goes in // functions need to refresh in case of config file changed goes in
// PMA_Config::load() // PMA_Config::load()
$this->load( $source ); $this->load($source);
// other settings, independant from config file, comes in // other settings, independant from config file, comes in
$this->checkSystem(); $this->checkSystem();
@@ -69,16 +71,17 @@ class PMA_Config {
/** /**
* sets system and application settings * sets system and application settings
*/ */
function checkSystem() { function checkSystem()
$this->set( 'PMA_VERSION', '2.7.1-dev' ); {
$this->set('PMA_VERSION', '2.7.1-dev');
/** /**
* @deprecated * @deprecated
*/ */
$this->set( 'PMA_THEME_VERSION', 2 ); $this->set('PMA_THEME_VERSION', 2);
/** /**
* @deprecated * @deprecated
*/ */
$this->set( 'PMA_THEME_GENERATION', 2 ); $this->set('PMA_THEME_GENERATION', 2);
$this->checkPhpVersion(); $this->checkPhpVersion();
$this->checkWebServerOs(); $this->checkWebServerOs();
@@ -93,21 +96,22 @@ class PMA_Config {
/** /**
* wether to use gzip output compression or not * wether to use gzip output compression or not
*/ */
function checkOutputCompression() { function checkOutputCompression()
{
// If zlib output compression is set in the php configuration file, no // If zlib output compression is set in the php configuration file, no
// output buffering should be run // output buffering should be run
if ( @ini_get('zlib.output_compression') ) { if ( @ini_get('zlib.output_compression') ) {
$this->set( 'OBGzip', false ); $this->set('OBGzip', false);
} }
// disable output-buffering (if set to 'auto') for IE6, else enable it. // disable output-buffering (if set to 'auto') for IE6, else enable it.
if ( strtolower( $this->get( 'OBGzip' ) ) == 'auto' ) { if ( strtolower($this->get('OBGzip')) == 'auto' ) {
if ( $this->get( 'PMA_USR_BROWSER_AGENT' ) == 'IE' if ( $this->get('PMA_USR_BROWSER_AGENT') == 'IE'
&& $this->get( 'PMA_USR_BROWSER_VER' ) >= 6 && $this->get('PMA_USR_BROWSER_VER') >= 6
&& $this->get( 'PMA_USR_BROWSER_VER' ) < 7 ) { && $this->get('PMA_USR_BROWSER_VER') < 7 ) {
$this->set( 'OBGzip', false ); $this->set('OBGzip', false);
} else { } else {
$this->set( 'OBGzip', true ); $this->set('OBGzip', true);
} }
} }
} }
@@ -117,7 +121,8 @@ class PMA_Config {
* Based on a phpBuilder article: * Based on a phpBuilder article:
* @see http://www.phpbuilder.net/columns/tim20000821.php * @see http://www.phpbuilder.net/columns/tim20000821.php
*/ */
function checkClient() { function checkClient()
{
if (!empty($_SERVER['HTTP_USER_AGENT'])) { if (!empty($_SERVER['HTTP_USER_AGENT'])) {
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT']; $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
} elseif (!isset($HTTP_USER_AGENT)) { } elseif (!isset($HTTP_USER_AGENT)) {
@@ -173,10 +178,11 @@ class PMA_Config {
/** /**
* Whether GD2 is present * Whether GD2 is present
*/ */
function checkGd2() { function checkGd2()
if ( $this->get( 'GD2Available' ) == 'yes' ) { {
if ( $this->get('GD2Available') == 'yes' ) {
$this->set('PMA_IS_GD2', 1); $this->set('PMA_IS_GD2', 1);
} elseif ( $this->get( 'GD2Available' ) == 'no' ) { } elseif ( $this->get('GD2Available') == 'no' ) {
$this->set('PMA_IS_GD2', 0); $this->set('PMA_IS_GD2', 0);
} else { } else {
if (!@extension_loaded('gd')) { if (!@extension_loaded('gd')) {
@@ -216,35 +222,38 @@ class PMA_Config {
/** /**
* Whether the Web server php is running on is IIS * Whether the Web server php is running on is IIS
*/ */
function checkWebServer() { function checkWebServer()
{
if ( isset( $_SERVER['SERVER_SOFTWARE'] ) if ( isset( $_SERVER['SERVER_SOFTWARE'] )
&& stristr( $_SERVER['SERVER_SOFTWARE'], 'Microsoft/IIS' ) ) { && stristr($_SERVER['SERVER_SOFTWARE'], 'Microsoft/IIS') ) {
$this->set( 'PMA_IS_IIS', 1 ); $this->set('PMA_IS_IIS', 1);
} else { } else {
$this->set( 'PMA_IS_IIS', 0 ); $this->set('PMA_IS_IIS', 0);
} }
} }
/** /**
* Whether the os php is running on is windows or not * Whether the os php is running on is windows or not
*/ */
function checkWebServerOs() { function checkWebServerOs()
if ( defined('PHP_OS') && stristr( PHP_OS, 'win' ) ) { {
$this->set( 'PMA_IS_WINDOWS', 1 ); if ( defined('PHP_OS') && stristr(PHP_OS, 'win') ) {
$this->set('PMA_IS_WINDOWS', 1);
} else { } else {
$this->set( 'PMA_IS_WINDOWS', 0 ); $this->set('PMA_IS_WINDOWS', 0);
} }
} }
/** /**
* detects PHP version * detects PHP version
*/ */
function checkPhpVersion() { function checkPhpVersion()
{
$match = array(); $match = array();
if ( ! preg_match( '@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@', if ( ! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
phpversion(), $match ) ) { phpversion(), $match) ) {
$result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@', $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
phpversion(), $match ); phpversion(), $match);
} }
if ( isset( $match ) && ! empty( $match[1] ) ) { if ( isset( $match ) && ! empty( $match[1] ) ) {
if ( ! isset( $match[2] ) ) { if ( ! isset( $match[2] ) ) {
@@ -253,22 +262,24 @@ class PMA_Config {
if ( ! isset( $match[3] ) ) { if ( ! isset( $match[3] ) ) {
$match[3] = 0; $match[3] = 0;
} }
$this->set( 'PMA_PHP_INT_VERSION', $this->set('PMA_PHP_INT_VERSION',
(int) sprintf( '%d%02d%02d', $match[1], $match[2], $match[3] ) ); (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
} else { } else {
$this->set( 'PMA_PHP_INT_VERSION', 0 ); $this->set('PMA_PHP_INT_VERSION', 0);
} }
$this->set( 'PMA_PHP_STR_VERSION', phpversion() ); $this->set('PMA_PHP_STR_VERSION', phpversion());
} }
/** /**
* re-init object after loadiong from session file * re-init object after loadiong from session file
* checks config file for changes and relaods if neccessary * checks config file for changes and relaods if neccessary
*/ */
function __wakeup() { function __wakeup()
if ( $this->source_mtime !== filemtime( $this->getSource() ) {
if ( $this->source_mtime !== filemtime($this->getSource())
|| $this->error_config_file || $this->error_config_default_file ) { || $this->error_config_file || $this->error_config_default_file ) {
$this->load( $this->getSource() ); $this->settings = array();
$this->load($this->getSource());
$this->checkSystem(); $this->checkSystem();
} }
@@ -284,9 +295,10 @@ class PMA_Config {
* @uses $this->settings * @uses $this->settings
* @return boolean success * @return boolean success
*/ */
function loadDefaults() { function loadDefaults()
{
$cfg = array(); $cfg = array();
if ( ! file_exists( $this->default_source ) ) { if ( ! file_exists($this->default_source) ) {
$this->error_config_default_file = true; $this->error_config_default_file = true;
return false; return false;
} }
@@ -295,7 +307,7 @@ class PMA_Config {
$this->default_server = $cfg['Servers'][1]; $this->default_server = $cfg['Servers'][1];
unset( $cfg['Servers'] ); unset( $cfg['Servers'] );
$this->settings = PMA_array_merge_recursive( $this->settings, $cfg ); $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
return true; return true;
} }
@@ -306,11 +318,11 @@ class PMA_Config {
* *
* @param string $source config file * @param string $source config file
*/ */
function load( $source = NULL ) { function load($source = NULL)
{
$this->loadDefaults(); $this->loadDefaults();
if ( ! $source || ! $this->setSource( $source ) ) { if ( ! $source || ! $this->setSource($source) ) {
return false; return false;
} }
@@ -319,37 +331,37 @@ class PMA_Config {
/** /**
* Parses the configuration file * Parses the configuration file
*/ */
$old_error_reporting = error_reporting( 0 ); $old_error_reporting = error_reporting(0);
if ( function_exists( 'file_get_contents' ) ) { if ( function_exists('file_get_contents') ) {
$eval_result = $eval_result =
eval( '?>' . file_get_contents( $this->getSource() ) ); eval( '?>' . file_get_contents($this->getSource()) );
} else { } else {
$eval_result = $eval_result =
eval( '?>' . implode( '\n', file( $this->getSource() ) ) ); eval( '?>' . implode('\n', file($this->getSource())) );
} }
error_reporting( $old_error_reporting ); error_reporting($old_error_reporting);
if ( $eval_result === false ) { if ( $eval_result === false ) {
$this->error_config_file = true; $this->error_config_file = true;
} else { } else {
$this->error_config_file = false; $this->error_config_file = false;
$this->source_mtime = filemtime( $this->getSource() ); $this->source_mtime = filemtime($this->getSource());
} }
/** /**
* @TODO check validity of $_COOKIE['pma_collation_connection'] * @TODO check validity of $_COOKIE['pma_collation_connection']
*/ */
if ( ! empty( $_COOKIE['pma_collation_connection'] ) ) { if ( ! empty( $_COOKIE['pma_collation_connection'] ) ) {
$this->set( 'collation_connection', $this->set('collation_connection',
strip_tags( $_COOKIE['pma_collation_connection'] ) ); strip_tags($_COOKIE['pma_collation_connection']) );
} else { } else {
$this->set( 'collation_connection', $this->set('collation_connection',
$this->get( 'DefaultConnectionCollation' ) ); $this->get('DefaultConnectionCollation') );
} }
$this->checkCollationConnection(); $this->checkCollationConnection();
//$this->checkPmaAbsoluteUri(); //$this->checkPmaAbsoluteUri();
$this->settings = PMA_array_merge_recursive( $this->settings, $cfg ); $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
return true; return true;
} }
@@ -357,18 +369,19 @@ class PMA_Config {
* set source * set source
* @param string $source * @param string $source
*/ */
function setSource( $source ) { function setSource($source)
if ( ! file_exists( $source ) ) { {
if ( ! file_exists($source) ) {
// do not trigger error here // do not trigger error here
// https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
/* /*
trigger_error( trigger_error(
'phpMyAdmin-ERROR: unkown configuration source: ' . $source, 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
E_USER_WARNING ); E_USER_WARNING);
*/ */
return false; return false;
} }
$this->source = trim( $source ); $this->source = trim($source);
return true; return true;
} }
@@ -377,7 +390,8 @@ class PMA_Config {
* @param string $setting * @param string $setting
* @return mixed value * @return mixed value
*/ */
function get( $setting ) { function get($setting)
{
if ( isset( $this->settings[$setting] ) ) { if ( isset( $this->settings[$setting] ) ) {
return $this->settings[$setting]; return $this->settings[$setting];
} }
@@ -391,7 +405,8 @@ class PMA_Config {
* @param string $setting configuration option * @param string $setting configuration option
* @param string $value new value for configuration option * @param string $value new value for configuration option
*/ */
function set( $setting, $value ) { function set($setting, $value)
{
$this->settings[$setting] = $value; $this->settings[$setting] = $value;
} }
@@ -399,7 +414,8 @@ class PMA_Config {
* returns source for current config * returns source for current config
* @return string config source * @return string config source
*/ */
function getSource() { function getSource()
{
return $this->source; return $this->source;
} }
@@ -408,8 +424,9 @@ class PMA_Config {
* *
* @deprecated * @deprecated
*/ */
function PMA_Config( $source ) { function PMA_Config($source)
$this->__construct( $source ); {
$this->__construct($source);
} }
/** /**
@@ -417,17 +434,17 @@ class PMA_Config {
* set properly and, depending on browsers, inserting or updating a * set properly and, depending on browsers, inserting or updating a
* record might fail * record might fail
*/ */
function checkPmaAbsoluteUri() { function checkPmaAbsoluteUri()
{
// Setup a default value to let the people and lazy syadmins work anyway, // Setup a default value to let the people and lazy syadmins work anyway,
// they'll get an error if the autodetect code doesn't work // they'll get an error if the autodetect code doesn't work
$pma_absolute_uri = $this->get('PmaAbsoluteUri'); $pma_absolute_uri = $this->get('PmaAbsoluteUri');
if ( strlen( $pma_absolute_uri ) < 1 ) { if ( strlen($pma_absolute_uri) < 1 ) {
$url = array(); $url = array();
// At first we try to parse REQUEST_URI, it might contain full URI // At first we try to parse REQUEST_URI, it might contain full URI
if ( ! empty($_SERVER['REQUEST_URI'] ) ) { if ( ! empty($_SERVER['REQUEST_URI'] ) ) {
$url = parse_url( $_SERVER['REQUEST_URI'] ); $url = parse_url($_SERVER['REQUEST_URI']);
} }
// If we don't have scheme, we didn't have full URL so we need to // If we don't have scheme, we didn't have full URL so we need to
@@ -445,9 +462,9 @@ class PMA_Config {
// Host and port // Host and port
if ( ! empty( $_SERVER['HTTP_HOST'] ) ) { if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
if ( strpos( $_SERVER['HTTP_HOST'], ':' ) !== false ) { if ( strpos($_SERVER['HTTP_HOST'], ':') !== false ) {
list( $url['host'], $url['port'] ) = list( $url['host'], $url['port'] ) =
explode( ':', $_SERVER['HTTP_HOST'] ); explode(':', $_SERVER['HTTP_HOST']);
} else { } else {
$url['host'] = $_SERVER['HTTP_HOST']; $url['host'] = $_SERVER['HTTP_HOST'];
} }
@@ -532,19 +549,20 @@ class PMA_Config {
} }
} }
$this->set( 'PmaAbsoluteUri', $pma_absolute_uri ); $this->set('PmaAbsoluteUri', $pma_absolute_uri);
} }
/** /**
* check selected collation_connection * check selected collation_connection
* @TODO check validity of $_REQUEST['collation_connection'] * @TODO check validity of $_REQUEST['collation_connection']
*/ */
function checkCollationConnection() { function checkCollationConnection()
{
// (could be improved by executing it after the MySQL connection only if // (could be improved by executing it after the MySQL connection only if
// PMA_MYSQL_INT_VERSION >= 40100 ) // PMA_MYSQL_INT_VERSION >= 40100 )
if ( ! empty( $_REQUEST['collation_connection'] ) ) { if ( ! empty( $_REQUEST['collation_connection'] ) ) {
$this->set( 'collation_connection', $this->set('collation_connection',
strip_tags( $_REQUEST['collation_connection'] ) ); strip_tags($_REQUEST['collation_connection']) );
} }
} }
@@ -552,11 +570,12 @@ class PMA_Config {
* checks if upload is enabled * checks if upload is enabled
* *
*/ */
function checkUpload() { function checkUpload()
$this->set( 'enbale_upload', true ); {
if ( strtolower( @ini_get( 'file_uploads' ) ) == 'off' $this->set('enbale_upload', true);
|| @ini_get( 'file_uploads' ) == 0 ) { if ( strtolower(@ini_get('file_uploads')) == 'off'
$this->set( 'enbale_upload', false ); || @ini_get('file_uploads') == 0 ) {
$this->set('enbale_upload', false);
} }
} }
@@ -566,30 +585,33 @@ class PMA_Config {
* *
* this section generates $max_upload_size in bytes * this section generates $max_upload_size in bytes
*/ */
function checkUploadSize() { function checkUploadSize()
if ( ! $filesize = ini_get( 'upload_max_filesize' ) ) { {
if ( ! $filesize = ini_get('upload_max_filesize') ) {
$filesize = "5M"; $filesize = "5M";
} }
if ( $postsize = ini_get( 'post_max_size' ) ) { if ( $postsize = ini_get('post_max_size') ) {
$this->set( 'max_upload_size', $this->set('max_upload_size',
min( get_real_size( $filesize ), get_real_size( $postsize ) ) ); min(get_real_size($filesize), get_real_size($postsize)) );
} else { } else {
$this->set( 'max_upload_size', get_real_size( $filesize ) ); $this->set('max_upload_size', get_real_size($filesize));
} }
} }
/** /**
* check for https * check for https
*/ */
function checkIsHttps() { function checkIsHttps()
$this->set( 'is_https', PMA_Config::isHttps() ); {
$this->set('is_https', PMA_Config::isHttps());
} }
/** /**
* @static * @static
*/ */
function isHttps() { function isHttps()
{
static $is_https = NULL; static $is_https = NULL;
if ( NULL !== $is_https ) { if ( NULL !== $is_https ) {
@@ -600,7 +622,7 @@ class PMA_Config {
// At first we try to parse REQUEST_URI, it might contain full URI // At first we try to parse REQUEST_URI, it might contain full URI
if ( ! empty($_SERVER['REQUEST_URI'] ) ) { if ( ! empty($_SERVER['REQUEST_URI'] ) ) {
$url = parse_url( $_SERVER['REQUEST_URI'] ); $url = parse_url($_SERVER['REQUEST_URI']);
} }
// If we don't have scheme, we didn't have full URL so we need to // If we don't have scheme, we didn't have full URL so we need to
@@ -630,14 +652,16 @@ class PMA_Config {
/** /**
* detect correct cookie path * detect correct cookie path
*/ */
function checkCookiePath() { function checkCookiePath()
$this->set( 'cookie_path', PMA_Config::getCookiePath() ); {
$this->set('cookie_path', PMA_Config::getCookiePath());
} }
/** /**
* @static * @static
*/ */
function getCookiePath() { function getCookiePath()
{
static $cookie_path = NULL; static $cookie_path = NULL;
if ( NULL !== $cookie_path ) { if ( NULL !== $cookie_path ) {
@@ -645,7 +669,7 @@ class PMA_Config {
} }
if ( ! empty($_SERVER['REQUEST_URI'] ) ) { if ( ! empty($_SERVER['REQUEST_URI'] ) ) {
$url = parse_url( $_SERVER['REQUEST_URI'] ); $url = parse_url($_SERVER['REQUEST_URI']);
} }
// If we don't have path // If we don't have path
@@ -659,8 +683,8 @@ class PMA_Config {
} }
} }
$cookie_path = substr( $url['path'], 0, $cookie_path = substr($url['path'], 0,
strrpos( $url['path'], '/' ) ) . '/'; strrpos($url['path'], '/')) . '/';
return $cookie_path; return $cookie_path;
} }
@@ -668,15 +692,15 @@ class PMA_Config {
/** /**
* enables backward compatibility * enables backward compatibility
*/ */
function enableBc() { function enableBc()
{
$GLOBALS['cfg'] =& $this->settings; $GLOBALS['cfg'] =& $this->settings;
$GLOBALS['default_server'] =& $this->default_server; $GLOBALS['default_server'] =& $this->default_server;
$GLOBALS['collation_connection'] = $this->get( 'collation_connection' ); $GLOBALS['collation_connection'] = $this->get('collation_connection');
$GLOBALS['is_upload'] = $this->get( 'enable_upload' ); $GLOBALS['is_upload'] = $this->get('enable_upload');
$GLOBALS['max_upload_size'] = $this->get( 'max_upload_size' ); $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
$GLOBALS['cookie_path'] = $this->get( 'cookie_path' ); $GLOBALS['cookie_path'] = $this->get('cookie_path');
$GLOBALS['is_https'] = $this->get( 'is_https' ); $GLOBALS['is_https'] = $this->get('is_https');
$defines = array( $defines = array(
'PMA_VERSION', 'PMA_VERSION',
@@ -693,8 +717,8 @@ class PMA_Config {
); );
foreach ( $defines as $define ) { foreach ( $defines as $define ) {
if ( ! defined( $define ) ) { if ( ! defined($define) ) {
define( $define, $this->get( $define ) ); define($define, $this->get($define));
} }
} }
} }