<?php
/* $Id: common.lib.php,v 2.128.2.3 2005/05/03 22:52:51 lem9 Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Misc stuff and functions used by almost all the scripts.
* Among other things, it contains the advanced authentification work.
*/
/**
* Order of sections for common.lib.php:
*
* some functions need the constants of libraries/defines.lib.php
* and defines_mysql.lib.php
*
* the PMA_setFontSizes() function must be before the call to the
* libraries/auth/cookie.auth.lib.php library
*
* the include of libraries/defines_mysql.lib.php must be after the connection
* to db to get the MySql version
*
* the PMA_sqlAddslashes() function must be before the connection to db
*
* the authentication libraries must be before the connection to db but
* after the PMA_isInto() function
*
* the PMA_mysqlDie() function must be before the connection to db but
* after mysql extension has been loaded
*
* the PMA_mysqlDie() function needs the PMA_format_sql() Function
*
* ... so the required order is:
*
* - parsing of the configuration file
* - load of the libraries/defines.lib.php library
* - load of mysql extension (if necessary)
* - definition of PMA_sqlAddslashes()
* - definition of PMA_format_sql()
* - definition of PMA_mysqlDie()
* - definition of PMA_isInto()
* - definition of PMA_setFontSizes()
* - loading of an authentication library
* - db connection
* - authentication work
* - load of the libraries/defines_mysql.lib.php library to get the MySQL
* release number
* - other functions, respecting dependencies
*/
/**
* Minimum inclusion? (i.e. for the stylesheet builder)
*/
if (!isset($is_minimum_common)) {
$is_minimum_common = FALSE;
}
/**
* Avoids undefined variables
*/
if (!isset($use_backquotes)) {
$use_backquotes = 0;
}
if (!isset($pos)) {
$pos = 0;
}
/**
* 2004-06-30 rabus: Ensure, that $cfg variables are not set somwhere else
* before including the config file.
*/
unset($cfg);
/**
* Detects the config file we want to load
*/
if (file_exists('./config.inc.developer.php')) {
$cfgfile_to_load = './config.inc.developer.php';
} else {
$cfgfile_to_load = './config.inc.php';
}
/**
* Parses the configuration file and gets some constants used to define
* versions of phpMyAdmin/php/mysql...
*/
//$old_error_reporting = error_reporting(0);
include_once($cfgfile_to_load);
// Include failed
if (!isset($cfgServers) && !isset($cfg['Servers'])) {
// Creates fake settings
$cfg = array('DefaultLang' => 'en-iso-8859-1',
'AllowAnywhereRecoding' => FALSE);
// Loads the language file
require_once('./libraries/select_lang.lib.php');
// Sends the Content-Type header
header('Content-Type: text/html; charset=' . $charset);
// Displays the error message
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $available_languages[$lang][2];?>" lang="<?php echo $available_languages[$lang][2];?>" dir="<?php echo $text_dir;?>">
<head>
<title>phpMyAdmin</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset;?>" />
<style type="text/css">
<!--
body {font-family: sans-serif; font-size: small; color: #000000; background-color: #F5F5F5}
h1 {font-family: sans-serif; font-size: large; font-weight: bold}
//-->
</style>
</head>
<body bgcolor="#ffffff">
<h1>phpMyAdmin - <?php echo $strError;?></h1>
<p>
<?php echo $strConfigFileError;?><br /><br />
<a href="config.inc.php" target="_blank">config.inc.php</a>
</p>
</body>
</html>
<?php
exit();
}
//error_reporting($old_error_reporting);
//unset($old_error_reporting;)
unset($cfgfile_to_load);
/**
* Includes compatibility code for older config.inc.php revisions
* if necessary
*/
if (isset($cfg['FileRevision'])) {
// converting revision string into an array
// e.g. "Revision: 2.0" becomes array(2, 0).
$cfg['FileRevision'] = str_replace('$' . 'Revision: ', '', $cfg['FileRevision']);
$cfg['FileRevision'] = str_replace(' $', '', $cfg['FileRevision']);
$cfg['FileRevision'] = explode('.', $cfg['FileRevision']);
} else {
$cfg['FileRevision'] = array(1, 1);
}
if ($cfg['FileRevision'][0] < 2 || ($cfg['FileRevision'][0] == 2 && $cfg['FileRevision'][1] < 52)) {
require_once('./libraries/config_import.lib.php');
}
/**
* Includes the language file if it hasn't been included yet
*/
require_once('./libraries/select_lang.lib.php');
/**
* Gets constants that defines the PHP version number.
* This include must be located physically before any code that needs to
* reference the constants, else PHP 3.0.16 won't be happy.
*/
require_once('./libraries/defines.lib.php');
/**
* Sanitizes $message, taking into account our special codes
* for formatting
*
* @param string the message
*
* @return string the sanitized message
*
* @access public
*/
function PMA_sanitize($message)
{
$replace_pairs = array(
'<' => '<',
'>' => '>',
'[i]' => '<i>',
'[/i]' => '</i>',
'[b]' => '<b>',
'[br]' => '<br />',
'[/b]' => '</b>',
);
return strtr($message, $replace_pairs);
}
// XSS
if (isset($convcharset)) {
$convcharset = PMA_sanitize($convcharset);
}
if ($is_minimum_common == FALSE) {
/**
* Define $is_upload
*/
$is_upload = TRUE;
if (strtolower(@ini_get('file_uploads')) == 'off'
|| @ini_get('file_uploads') == 0) {
$is_upload = FALSE;
}
/**
* Maximum upload size as limited by PHP
* Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
*
* this section generates $max_upload_size in bytes
*/
function get_real_size($size=0) {
/// Converts numbers like 10M into bytes
if (!$size) {
return 0;
}
$scan['MB'] = 1048576;
$scan['Mb'] = 1048576;
$scan['M'] = 1048576;
$scan['m'] = 1048576;
$scan['KB'] = 1024;
$scan['Kb'] = 1024;
$scan['K'] = 1024;
$scan['k'] = 1024;
while (list($key) = each($scan)) {
if ((strlen($size)>strlen($key))&&(substr($size, strlen($size) - strlen($key))==$key)) {
$size = substr($size, 0, strlen($size) - strlen($key)) * $scan[$key];
break;
}
}
return $size;
} // end function
if (!$filesize = ini_get('upload_max_filesize')) {
$filesize = "5M";
}
$max_upload_size = get_real_size($filesize);
if ($postsize = ini_get('post_max_size')) {
$postsize = get_real_size($postsize);
if ($postsize < $max_upload_size) {
$max_upload_size = $postsize;
}
}
unset($filesize);
unset($postsize);
/**
* other functions for maximum upload work
*/
/**
* Displays the maximum size for an upload
*
* @param integer the size
*
* @return string the message
*
* @access public
*/
function PMA_displayMaximumUploadSize($max_upload_size) {
list($max_size, $max_unit) = PMA_formatByteDown($max_upload_size);
return '(' . sprintf($GLOBALS['strMaximumSize'], $max_size, $max_unit) . ')';
}
/**
* Generates a hidden field which should indicate to the browser
* the maximum size for upload
*
* @param integer the size
*
* @return string the INPUT field
*
* @access public
*/
function PMA_generateHiddenMaxFileSize($max_size){
return '<input type="h