Remove unnecessary files
This commit is contained in:
parent
efe7e80867
commit
5b60c7c11e
@ -1,135 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to run config authentication (ie no authentication).
|
||||
*
|
||||
* @package PhpMyAdmin-Auth
|
||||
* @subpackage Config
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Displays authentication form
|
||||
*
|
||||
* @return boolean always true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth()
|
||||
{
|
||||
return true;
|
||||
} // end of the 'PMA_auth()' function
|
||||
|
||||
|
||||
/**
|
||||
* Gets advanced authentication settings
|
||||
*
|
||||
* @return boolean always true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_check()
|
||||
{
|
||||
return true;
|
||||
} // end of the 'PMA_auth_check()' function
|
||||
|
||||
|
||||
/**
|
||||
* Set the user and password after last checkings if required
|
||||
*
|
||||
* @return boolean always true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_set_user()
|
||||
{
|
||||
return true;
|
||||
} // end of the 'PMA_auth_set_user()' function
|
||||
|
||||
|
||||
/**
|
||||
* User is not allowed to login to MySQL -> authentication failed
|
||||
*
|
||||
* @global string the MySQL error message PHP returns
|
||||
* @global string the connection type (persistent or not)
|
||||
* @global string the MySQL server port to use
|
||||
* @global string the MySQL socket port to use
|
||||
* @global array the current server settings
|
||||
* @global string the font face to use in case of failure
|
||||
* @global string the default font size to use in case of failure
|
||||
* @global string the big font size to use in case of failure
|
||||
* @global boolean tell the "mysqlDie()" function headers have been
|
||||
* sent
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_fails()
|
||||
{
|
||||
$conn_error = PMA_DBI_getError();
|
||||
if (! $conn_error) {
|
||||
$conn_error = __('Cannot connect: invalid settings.');
|
||||
}
|
||||
|
||||
/* HTML header */
|
||||
$response = PMA_Response::getInstance();
|
||||
$response->getFooter()->setMinimal();
|
||||
$header = $response->getHeader();
|
||||
$header->setTitle(__('Access denied'));
|
||||
$header->disableMenu();
|
||||
|
||||
?>
|
||||
<br /><br />
|
||||
<center>
|
||||
<h1><?php echo sprintf(__('Welcome to %s'), ' phpMyAdmin '); ?></h1>
|
||||
</center>
|
||||
<br />
|
||||
<table cellpadding="0" cellspacing="3" style="margin: 0 auto" width="80%">
|
||||
<tr>
|
||||
<td>
|
||||
<?php
|
||||
|
||||
if (isset($GLOBALS['allowDeny_forbidden']) && $GLOBALS['allowDeny_forbidden']) {
|
||||
trigger_error(__('Access denied'), E_USER_NOTICE);
|
||||
} else {
|
||||
// Check whether user has configured something
|
||||
if ($GLOBALS['PMA_Config']->source_mtime == 0) {
|
||||
echo '<p>' . sprintf(__('You probably did not create a configuration file. You might want to use the %1$ssetup script%2$s to create one.'), '<a href="setup/">', '</a>') . '</p>' . "\n";
|
||||
} elseif (! isset($GLOBALS['errno'])
|
||||
|| (isset($GLOBALS['errno']) && $GLOBALS['errno'] != 2002)
|
||||
&& $GLOBALS['errno'] != 2003
|
||||
) {
|
||||
// if we display the "Server not responding" error, do not confuse users
|
||||
// by telling them they have a settings problem
|
||||
// (note: it's true that they could have a badly typed host name, but
|
||||
// anyway the current message tells that the server
|
||||
// rejected the connection, which is not really what happened)
|
||||
// 2002 is the error given by mysqli
|
||||
// 2003 is the error given by mysql
|
||||
trigger_error(__('phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.'), E_USER_WARNING);
|
||||
}
|
||||
PMA_CommonFunctions::getInstance()->mysqlDie(
|
||||
$conn_error, '', true, '', false
|
||||
);
|
||||
}
|
||||
$GLOBALS['error_handler']->dispUserErrors();
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
if (count($GLOBALS['cfg']['Servers']) > 1) {
|
||||
// offer a chance to login to other servers if the current one failed
|
||||
include_once './libraries/select_server.lib.php';
|
||||
echo '<tr>' . "\n";
|
||||
echo ' <td>' . "\n";
|
||||
PMA_selectServer(true, true);
|
||||
echo ' </td>' . "\n";
|
||||
echo '</tr>' . "\n";
|
||||
}
|
||||
echo '</table>' . "\n";
|
||||
exit;
|
||||
return true;
|
||||
} // end of the 'PMA_auth_fails()' function
|
||||
|
||||
?>
|
||||
@ -1,645 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to run cookie based authentication.
|
||||
*
|
||||
* @package PhpMyAdmin-Auth
|
||||
* @subpackage Cookie
|
||||
*/
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remember where to redirect the user
|
||||
* in case of an expired session.
|
||||
*/
|
||||
if (! empty($_REQUEST['target'])) {
|
||||
$GLOBALS['target'] = $_REQUEST['target'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Swekey authentication functions.
|
||||
*/
|
||||
require './libraries/auth/swekey/swekey.auth.lib.php';
|
||||
|
||||
if (function_exists('mcrypt_encrypt')) {
|
||||
/**
|
||||
* Uses faster mcrypt library if available
|
||||
* (as this is not called from anywhere else, put the code in-line
|
||||
* for faster execution)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initialization
|
||||
* Store the initialization vector because it will be needed for
|
||||
* further decryption. I don't think necessary to have one iv
|
||||
* per server so I don't put the server number in the cookie name.
|
||||
*/
|
||||
if (empty($_COOKIE['pma_mcrypt_iv'])
|
||||
|| false === ($iv = base64_decode($_COOKIE['pma_mcrypt_iv'], true))
|
||||
) {
|
||||
srand((double) microtime() * 1000000);
|
||||
$td = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
|
||||
if ($td === false) {
|
||||
PMA_fatalError(__('Failed to use Blowfish from mcrypt!'));
|
||||
}
|
||||
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
|
||||
$GLOBALS['PMA_Config']->setCookie('pma_mcrypt_iv', base64_encode($iv));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encryption using blowfish algorithm (mcrypt)
|
||||
*
|
||||
* @param string $data original data
|
||||
* @param string $secret the secret
|
||||
*
|
||||
* @return string the encrypted result
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
function PMA_blowfish_encrypt($data, $secret)
|
||||
{
|
||||
global $iv;
|
||||
return base64_encode(
|
||||
mcrypt_encrypt(MCRYPT_BLOWFISH, $secret, $data, MCRYPT_MODE_CBC, $iv)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decryption using blowfish algorithm (mcrypt)
|
||||
*
|
||||
* @param string $encdata encrypted data
|
||||
* @param string $secret the secret
|
||||
*
|
||||
* @return string original data
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
function PMA_blowfish_decrypt($encdata, $secret)
|
||||
{
|
||||
global $iv;
|
||||
$data = base64_decode($encdata);
|
||||
$decrypted = mcrypt_decrypt(
|
||||
MCRYPT_BLOWFISH,
|
||||
$secret,
|
||||
$data,
|
||||
MCRYPT_MODE_CBC,
|
||||
$iv
|
||||
);
|
||||
return trim($decrypted);
|
||||
}
|
||||
|
||||
} else {
|
||||
include_once './libraries/blowfish.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns blowfish secret or generates one if needed.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function PMA_get_blowfish_secret()
|
||||
{
|
||||
if (empty($GLOBALS['cfg']['blowfish_secret'])) {
|
||||
if (empty($_SESSION['auto_blowfish_secret'])) {
|
||||
// this returns 23 characters
|
||||
$_SESSION['auto_blowfish_secret'] = uniqid('', true);
|
||||
}
|
||||
return $_SESSION['auto_blowfish_secret'];
|
||||
} else {
|
||||
// apply md5() to work around too long secrets (returns 32 characters)
|
||||
return md5($GLOBALS['cfg']['blowfish_secret']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays authentication form
|
||||
*
|
||||
* this function MUST exit/quit the application
|
||||
*
|
||||
* @global string the last connection error
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth()
|
||||
{
|
||||
global $conn_error;
|
||||
|
||||
$response = PMA_Response::getInstance();
|
||||
if ($response->isAjax()) {
|
||||
$response->isSuccess(false);
|
||||
if (! empty($conn_error)) {
|
||||
$response->addJSON('message', $conn_error);
|
||||
} else {
|
||||
$response->addJSON('message', PMA_Message::error(__('Your session has expired. Please login again.')));
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Perform logout to custom URL */
|
||||
if (! empty($_REQUEST['old_usr'])
|
||||
&& ! empty($GLOBALS['cfg']['Server']['LogoutURL'])
|
||||
) {
|
||||
PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* No recall if blowfish secret is not configured as it would produce garbage */
|
||||
if ($GLOBALS['cfg']['LoginCookieRecall']
|
||||
&& ! empty($GLOBALS['cfg']['blowfish_secret'])
|
||||
) {
|
||||
$default_user = $GLOBALS['PHP_AUTH_USER'];
|
||||
$default_server = $GLOBALS['pma_auth_server'];
|
||||
$autocomplete = '';
|
||||
} else {
|
||||
$default_user = '';
|
||||
$default_server = '';
|
||||
// skip the IE autocomplete feature.
|
||||
$autocomplete = ' autocomplete="off"';
|
||||
}
|
||||
|
||||
$cell_align = ($GLOBALS['text_dir'] == 'ltr') ? 'left' : 'right';
|
||||
|
||||
$response->getFooter()->setMinimal();
|
||||
$header = $response->getHeader();
|
||||
$header->setBodyId('loginform');
|
||||
$header->setTitle('phpMyAdmin');
|
||||
$header->disableMenu();
|
||||
$header->disableWarnings();
|
||||
|
||||
if (file_exists(CUSTOM_HEADER_FILE)) {
|
||||
include CUSTOM_HEADER_FILE;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="container">
|
||||
<a href="<?php echo PMA_linkURL('http://www.phpmyadmin.net/'); ?>" target="_blank" class="logo"><?php
|
||||
$logo_image = $GLOBALS['pmaThemeImage'] . 'logo_right.png';
|
||||
if (@file_exists($logo_image)) {
|
||||
echo '<img src="' . $logo_image
|
||||
. '" id="imLogo" name="imLogo" alt="phpMyAdmin" border="0" />';
|
||||
} else {
|
||||
echo '<img name="imLogo" id="imLogo" src="'
|
||||
. $GLOBALS['pmaThemeImage'] . 'pma_logo.png' . '" '
|
||||
. 'border="0" width="88" height="31" alt="phpMyAdmin" />';
|
||||
}
|
||||
?></a>
|
||||
<h1>
|
||||
<?php
|
||||
echo sprintf(
|
||||
__('Welcome to %s'),
|
||||
'<bdo dir="ltr" lang="en">phpMyAdmin</bdo>'
|
||||
);
|
||||
?>
|
||||
</h1>
|
||||
<?php
|
||||
|
||||
// Show error message
|
||||
if (! empty($conn_error)) {
|
||||
PMA_Message::rawError($conn_error)->display();
|
||||
}
|
||||
|
||||
echo "<noscript>\n";
|
||||
PMA_message::error(__("Javascript must be enabled past this point"))->display();
|
||||
echo "</noscript>\n";
|
||||
|
||||
echo "<div class='hide js-show'>";
|
||||
// Displays the languages form
|
||||
if (empty($GLOBALS['cfg']['Lang'])) {
|
||||
include_once './libraries/display_select_lang.lib.php';
|
||||
// use fieldset, don't show doc link
|
||||
PMA_select_language(true, false);
|
||||
}
|
||||
echo "</div>";
|
||||
|
||||
?>
|
||||
<br />
|
||||
<!-- Login form -->
|
||||
<form method="post" action="index.php" name="login_form"<?php echo $autocomplete; ?> target="_top" class="login hide js-show">
|
||||
<fieldset>
|
||||
<legend>
|
||||
<?php
|
||||
echo __('Log in');
|
||||
echo PMA_CommonFunctions::getInstance()->showDocu('');
|
||||
?>
|
||||
</legend>
|
||||
|
||||
<?php if ($GLOBALS['cfg']['AllowArbitraryServer']) { ?>
|
||||
<div class="item">
|
||||
<label for="input_servername" title="<?php echo __('You can enter hostname/IP address and port separated by space.'); ?>"><?php echo __('Server:'); ?></label>
|
||||
<input type="text" name="pma_servername" id="input_servername" value="<?php echo htmlspecialchars($default_server); ?>" size="24" class="textfield" title="<?php echo __('You can enter hostname/IP address and port separated by space.'); ?>" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="item">
|
||||
<label for="input_username"><?php echo __('Username:'); ?></label>
|
||||
<input type="text" name="pma_username" id="input_username" value="<?php echo htmlspecialchars($default_user); ?>" size="24" class="textfield"/>
|
||||
</div>
|
||||
<div class="item">
|
||||
<label for="input_password"><?php echo __('Password:'); ?></label>
|
||||
<input type="password" name="pma_password" id="input_password" value="" size="24" class="textfield" />
|
||||
</div>
|
||||
<?php
|
||||
if (count($GLOBALS['cfg']['Servers']) > 1) {
|
||||
?>
|
||||
<div class="item">
|
||||
<label for="select_server"><?php echo __('Server Choice'); ?>:</label>
|
||||
<select name="server" id="select_server"
|
||||
<?php
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']) {
|
||||
echo ' onchange="document.forms[\'login_form\'].elements[\'pma_servername\'].value = \'\'" ';
|
||||
}
|
||||
echo '>';
|
||||
|
||||
include_once './libraries/select_server.lib.php';
|
||||
PMA_selectServer(false, false);
|
||||
|
||||
echo '</select></div>';
|
||||
} else {
|
||||
echo ' <input type="hidden" name="server" value="' . $GLOBALS['server'] . '" />';
|
||||
} // end if (server choice)
|
||||
?>
|
||||
</fieldset>
|
||||
<fieldset class="tblFooters">
|
||||
<input value="<?php echo __('Go'); ?>" type="submit" id="input_go" />
|
||||
<?php
|
||||
$_form_params = array();
|
||||
if (! empty($GLOBALS['target'])) {
|
||||
$_form_params['target'] = $GLOBALS['target'];
|
||||
}
|
||||
if (! empty($GLOBALS['db'])) {
|
||||
$_form_params['db'] = $GLOBALS['db'];
|
||||
}
|
||||
if (! empty($GLOBALS['table'])) {
|
||||
$_form_params['table'] = $GLOBALS['table'];
|
||||
}
|
||||
// do not generate a "server" hidden field as we want the "server"
|
||||
// drop-down to have priority
|
||||
echo PMA_generate_common_hidden_inputs($_form_params, '', 0, 'server');
|
||||
?>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
// BEGIN Swekey Integration
|
||||
Swekey_login('input_username', 'input_go');
|
||||
// END Swekey Integration
|
||||
|
||||
// show the "Cookies required" message only if cookies are disabled
|
||||
// (we previously tried to set some cookies)
|
||||
if (empty($_COOKIE)) {
|
||||
trigger_error(__('Cookies must be enabled past this point.'), E_USER_NOTICE);
|
||||
}
|
||||
if ($GLOBALS['error_handler']->hasDisplayErrors()) {
|
||||
echo '<div>';
|
||||
$GLOBALS['error_handler']->dispErrors();
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
if (file_exists(CUSTOM_FOOTER_FILE)) {
|
||||
include CUSTOM_FOOTER_FILE;
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
// show login form in top frame.
|
||||
if (top != self || ! $('body#loginform').length) {
|
||||
window.top.location.href=location;
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
<?php
|
||||
exit;
|
||||
} // end of the 'PMA_auth()' function
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets advanced authentication settings
|
||||
*
|
||||
* this function DOES NOT check authentication - it just checks/provides
|
||||
* authentication credentials required to connect to the MySQL server
|
||||
* usually with PMA_DBI_connect()
|
||||
*
|
||||
* it returns false if something is missing - which usually leads to
|
||||
* PMA_auth() which displays login form
|
||||
*
|
||||
* it returns true if all seems ok which usually leads to PMA_auth_set_user()
|
||||
*
|
||||
* it directly switches to PMA_auth_fails() if user inactivity timout is reached
|
||||
*
|
||||
* @todo AllowArbitraryServer on does not imply that the user wants an
|
||||
* arbitrary server, or? so we should also check if this is filled and
|
||||
* not only if allowed
|
||||
*
|
||||
* @return boolean whether we get authentication settings or not
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_check()
|
||||
{
|
||||
// Initialization
|
||||
/**
|
||||
* @global $GLOBALS['pma_auth_server'] the user provided server to connect to
|
||||
*/
|
||||
$GLOBALS['pma_auth_server'] = '';
|
||||
|
||||
$GLOBALS['PHP_AUTH_USER'] = $GLOBALS['PHP_AUTH_PW'] = '';
|
||||
$GLOBALS['from_cookie'] = false;
|
||||
|
||||
$common_functions = PMA_CommonFunctions::getInstance();
|
||||
|
||||
// BEGIN Swekey Integration
|
||||
if (! Swekey_auth_check()) {
|
||||
return false;
|
||||
}
|
||||
// END Swekey Integration
|
||||
|
||||
if (defined('PMA_CLEAR_COOKIES')) {
|
||||
foreach ($GLOBALS['cfg']['Servers'] as $key => $val) {
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $key);
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaServer-' . $key);
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaUser-' . $key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! empty($_REQUEST['old_usr'])) {
|
||||
// The user wants to be logged out
|
||||
// -> delete his choices that were stored in session
|
||||
|
||||
// according to the PHP manual we should do this before the destroy:
|
||||
//$_SESSION = array();
|
||||
|
||||
session_destroy();
|
||||
// -> delete password cookie(s)
|
||||
if ($GLOBALS['cfg']['LoginCookieDeleteAll']) {
|
||||
foreach ($GLOBALS['cfg']['Servers'] as $key => $val) {
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $key);
|
||||
if (isset($_COOKIE['pmaPass-' . $key])) {
|
||||
unset($_COOKIE['pmaPass-' . $key]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $GLOBALS['server']);
|
||||
if (isset($_COOKIE['pmaPass-' . $GLOBALS['server']])) {
|
||||
unset($_COOKIE['pmaPass-' . $GLOBALS['server']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($_REQUEST['pma_username'])) {
|
||||
// The user just logged in
|
||||
$GLOBALS['PHP_AUTH_USER'] = $_REQUEST['pma_username'];
|
||||
$GLOBALS['PHP_AUTH_PW'] = empty($_REQUEST['pma_password'])
|
||||
? ''
|
||||
: $_REQUEST['pma_password'];
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']
|
||||
&& isset($_REQUEST['pma_servername'])
|
||||
) {
|
||||
$GLOBALS['pma_auth_server'] = $_REQUEST['pma_servername'];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// At the end, try to set the $GLOBALS['PHP_AUTH_USER']
|
||||
// and $GLOBALS['PHP_AUTH_PW'] variables from cookies
|
||||
|
||||
// servername
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']
|
||||
&& ! empty($_COOKIE['pmaServer-' . $GLOBALS['server']])
|
||||
) {
|
||||
$GLOBALS['pma_auth_server'] = $_COOKIE['pmaServer-' . $GLOBALS['server']];
|
||||
}
|
||||
|
||||
// username
|
||||
if (empty($_COOKIE['pmaUser-' . $GLOBALS['server']])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$GLOBALS['PHP_AUTH_USER'] = PMA_blowfish_decrypt(
|
||||
$_COOKIE['pmaUser-' . $GLOBALS['server']],
|
||||
PMA_get_blowfish_secret()
|
||||
);
|
||||
|
||||
// user was never logged in since session start
|
||||
if (empty($_SESSION['last_access_time'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// User inactive too long
|
||||
if ($_SESSION['last_access_time'] < time() - $GLOBALS['cfg']['LoginCookieValidity']) {
|
||||
$common_functions->cacheUnset('is_create_db_priv', true);
|
||||
$common_functions->cacheUnset('is_process_priv', true);
|
||||
$common_functions->cacheUnset('is_reload_priv', true);
|
||||
$common_functions->cacheUnset('db_to_create', true);
|
||||
$common_functions->cacheUnset('dbs_where_create_table_allowed', true);
|
||||
$GLOBALS['no_activity'] = true;
|
||||
PMA_auth_fails();
|
||||
exit;
|
||||
}
|
||||
|
||||
// password
|
||||
if (empty($_COOKIE['pmaPass-' . $GLOBALS['server']])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$GLOBALS['PHP_AUTH_PW'] = PMA_blowfish_decrypt(
|
||||
$_COOKIE['pmaPass-' . $GLOBALS['server']],
|
||||
PMA_get_blowfish_secret()
|
||||
);
|
||||
|
||||
if ($GLOBALS['PHP_AUTH_PW'] == "\xff(blank)") {
|
||||
$GLOBALS['PHP_AUTH_PW'] = '';
|
||||
}
|
||||
|
||||
$GLOBALS['from_cookie'] = true;
|
||||
|
||||
return true;
|
||||
} // end of the 'PMA_auth_check()' function
|
||||
|
||||
|
||||
/**
|
||||
* Set the user and password after last checkings if required
|
||||
*
|
||||
* @return boolean always true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_set_user()
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
// Ensures valid authentication mode, 'only_db', bookmark database and
|
||||
// table names and relation table name are used
|
||||
if ($cfg['Server']['user'] != $GLOBALS['PHP_AUTH_USER']) {
|
||||
foreach ($cfg['Servers'] as $idx => $current) {
|
||||
if ($current['host'] == $cfg['Server']['host']
|
||||
&& $current['port'] == $cfg['Server']['port']
|
||||
&& $current['socket'] == $cfg['Server']['socket']
|
||||
&& $current['ssl'] == $cfg['Server']['ssl']
|
||||
&& $current['connect_type'] == $cfg['Server']['connect_type']
|
||||
&& $current['user'] == $GLOBALS['PHP_AUTH_USER']
|
||||
) {
|
||||
$GLOBALS['server'] = $idx;
|
||||
$cfg['Server'] = $current;
|
||||
break;
|
||||
}
|
||||
} // end foreach
|
||||
} // end if
|
||||
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']
|
||||
&& ! empty($GLOBALS['pma_auth_server'])
|
||||
) {
|
||||
/* Allow to specify 'host port' */
|
||||
$parts = explode(' ', $GLOBALS['pma_auth_server']);
|
||||
if (count($parts) == 2) {
|
||||
$tmp_host = $parts[0];
|
||||
$tmp_port = $parts[1];
|
||||
} else {
|
||||
$tmp_host = $GLOBALS['pma_auth_server'];
|
||||
$tmp_port = '';
|
||||
}
|
||||
if ($cfg['Server']['host'] != $GLOBALS['pma_auth_server']) {
|
||||
$cfg['Server']['host'] = $tmp_host;
|
||||
if (! empty($tmp_port)) {
|
||||
$cfg['Server']['port'] = $tmp_port;
|
||||
}
|
||||
}
|
||||
unset($tmp_host, $tmp_port, $parts);
|
||||
}
|
||||
$cfg['Server']['user'] = $GLOBALS['PHP_AUTH_USER'];
|
||||
$cfg['Server']['password'] = $GLOBALS['PHP_AUTH_PW'];
|
||||
|
||||
// Avoid showing the password in phpinfo()'s output
|
||||
unset($GLOBALS['PHP_AUTH_PW']);
|
||||
unset($_SERVER['PHP_AUTH_PW']);
|
||||
|
||||
$_SESSION['last_access_time'] = time();
|
||||
|
||||
// Name and password cookies need to be refreshed each time
|
||||
// Duration = one month for username
|
||||
$GLOBALS['PMA_Config']->setCookie(
|
||||
'pmaUser-' . $GLOBALS['server'],
|
||||
PMA_blowfish_encrypt(
|
||||
$cfg['Server']['user'], PMA_get_blowfish_secret()
|
||||
)
|
||||
);
|
||||
|
||||
// Duration = as configured
|
||||
$GLOBALS['PMA_Config']->setCookie(
|
||||
'pmaPass-' . $GLOBALS['server'],
|
||||
PMA_blowfish_encrypt(
|
||||
! empty($cfg['Server']['password']) ? $cfg['Server']['password'] : "\xff(blank)",
|
||||
PMA_get_blowfish_secret()
|
||||
),
|
||||
null,
|
||||
$GLOBALS['cfg']['LoginCookieStore']
|
||||
);
|
||||
|
||||
// Set server cookies if required (once per session) and, in this case, force
|
||||
// reload to ensure the client accepts cookies
|
||||
if (! $GLOBALS['from_cookie']) {
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']) {
|
||||
if (! empty($GLOBALS['pma_auth_server'])) {
|
||||
// Duration = one month for servername
|
||||
$GLOBALS['PMA_Config']->setCookie(
|
||||
'pmaServer-' . $GLOBALS['server'],
|
||||
$cfg['Server']['host']
|
||||
);
|
||||
} else {
|
||||
// Delete servername cookie
|
||||
$GLOBALS['PMA_Config']->removeCookie(
|
||||
'pmaServer-' . $GLOBALS['server']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// URL where to go:
|
||||
$redirect_url = $cfg['PmaAbsoluteUri'] . 'index.php';
|
||||
|
||||
// any parameters to pass?
|
||||
$url_params = array();
|
||||
if (strlen($GLOBALS['db'])) {
|
||||
$url_params['db'] = $GLOBALS['db'];
|
||||
}
|
||||
if (strlen($GLOBALS['table'])) {
|
||||
$url_params['table'] = $GLOBALS['table'];
|
||||
}
|
||||
// any target to pass?
|
||||
if (! empty($GLOBALS['target']) && $GLOBALS['target'] != 'index.php') {
|
||||
$url_params['target'] = $GLOBALS['target'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear user cache.
|
||||
*/
|
||||
PMA_CommonFunctions::getInstance()->clearUserCache();
|
||||
|
||||
PMA_Response::getInstance()->disable();
|
||||
|
||||
PMA_sendHeaderLocation(
|
||||
$redirect_url . PMA_generate_common_url($url_params, '&'),
|
||||
true
|
||||
);
|
||||
exit;
|
||||
} // end if
|
||||
|
||||
return true;
|
||||
} // end of the 'PMA_auth_set_user()' function
|
||||
|
||||
|
||||
/**
|
||||
* User is not allowed to login to MySQL -> authentication failed
|
||||
*
|
||||
* prepares error message and switches to PMA_auth() which display the error
|
||||
* and the login form
|
||||
*
|
||||
* this function MUST exit/quit the application,
|
||||
* currently doen by call to PMA_auth()
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_fails()
|
||||
{
|
||||
global $conn_error;
|
||||
|
||||
// Deletes password cookie and displays the login form
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $GLOBALS['server']);
|
||||
|
||||
if (! empty($GLOBALS['login_without_password_is_forbidden'])) {
|
||||
$conn_error = __('Login without a password is forbidden by configuration (see AllowNoPassword)');
|
||||
} elseif (! empty($GLOBALS['allowDeny_forbidden'])) {
|
||||
$conn_error = __('Access denied');
|
||||
} elseif (! empty($GLOBALS['no_activity'])) {
|
||||
$conn_error = sprintf(__('No activity within %s seconds; please log in again'), $GLOBALS['cfg']['LoginCookieValidity']);
|
||||
// Remember where we got timeout to return on same place
|
||||
if (PMA_getenv('SCRIPT_NAME')) {
|
||||
$GLOBALS['target'] = basename(PMA_getenv('SCRIPT_NAME'));
|
||||
// avoid "missing parameter: field" on re-entry
|
||||
if ('tbl_alter.php' == $GLOBALS['target']) {
|
||||
$GLOBALS['target'] = 'tbl_structure.php';
|
||||
}
|
||||
}
|
||||
} elseif (PMA_DBI_getError()) {
|
||||
$conn_error = '#' . $GLOBALS['errno'] . ' '
|
||||
. __('Cannot log in to the MySQL server');
|
||||
} else {
|
||||
$conn_error = __('Cannot log in to the MySQL server');
|
||||
}
|
||||
|
||||
// needed for PHP-CGI (not need for FastCGI or mod-php)
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
|
||||
PMA_auth();
|
||||
} // end of the 'PMA_auth_fails()' function
|
||||
|
||||
?>
|
||||
@ -1,259 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to run single signon authentication.
|
||||
*
|
||||
* @package PhpMyAdmin-Auth
|
||||
* @subpackage Signon
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Displays authentication form
|
||||
*
|
||||
* @global string the font face to use in case of failure
|
||||
* @global string the default font size to use in case of failure
|
||||
* @global string the big font size to use in case of failure
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth()
|
||||
{
|
||||
unset($_SESSION['LAST_SIGNON_URL']);
|
||||
if (empty($GLOBALS['cfg']['Server']['SignonURL'])) {
|
||||
PMA_fatalError('You must set SignonURL!');
|
||||
} elseif (! empty($_REQUEST['old_usr'])
|
||||
&& ! empty($GLOBALS['cfg']['Server']['LogoutURL'])
|
||||
) {
|
||||
/* Perform logout to custom URL */
|
||||
PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
|
||||
} else {
|
||||
PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['SignonURL']);
|
||||
}
|
||||
exit();
|
||||
} // end of the 'PMA_auth()' function
|
||||
|
||||
|
||||
/**
|
||||
* Gets advanced authentication settings
|
||||
*
|
||||
* @global string the username if register_globals is on
|
||||
* @global string the password if register_globals is on
|
||||
* @global array the array of server variables if register_globals is
|
||||
* off
|
||||
* @global array the array of environment variables if register_globals
|
||||
* is off
|
||||
* @global string the username for the ? server
|
||||
* @global string the password for the ? server
|
||||
* @global string the username for the WebSite Professional server
|
||||
* @global string the password for the WebSite Professional server
|
||||
* @global string the username of the user who logs out
|
||||
*
|
||||
* @return boolean whether we get authentication settings or not
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_check()
|
||||
{
|
||||
global $PHP_AUTH_USER, $PHP_AUTH_PW;
|
||||
|
||||
/* Check if we're using same sigon server */
|
||||
if (isset($_SESSION['LAST_SIGNON_URL'])
|
||||
&& $_SESSION['LAST_SIGNON_URL'] != $GLOBALS['cfg']['Server']['SignonURL']
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Script name */
|
||||
$script_name = $GLOBALS['cfg']['Server']['SignonScript'];
|
||||
|
||||
/* Session name */
|
||||
$session_name = $GLOBALS['cfg']['Server']['SignonSession'];
|
||||
|
||||
/* Login URL */
|
||||
$signon_url = $GLOBALS['cfg']['Server']['SignonURL'];
|
||||
|
||||
/* Current host */
|
||||
$single_signon_host = $GLOBALS['cfg']['Server']['host'];
|
||||
|
||||
/* Current port */
|
||||
$single_signon_port = $GLOBALS['cfg']['Server']['port'];
|
||||
|
||||
/* No configuration updates */
|
||||
$single_signon_cfgupdate = array();
|
||||
|
||||
/* Are we requested to do logout? */
|
||||
$do_logout = !empty($_REQUEST['old_usr']);
|
||||
|
||||
/* Handle script based auth */
|
||||
if (!empty($script_name)) {
|
||||
if (! file_exists($script_name)) {
|
||||
PMA_fatalError(
|
||||
__('Can not find signon authentication script:') . ' ' . $script_name
|
||||
);
|
||||
}
|
||||
include $script_name;
|
||||
|
||||
list ($PHP_AUTH_USER, $PHP_AUTH_PW)
|
||||
= get_login_credentials($cfg['Server']['user']);
|
||||
|
||||
} elseif (isset($_COOKIE[$session_name])) { /* Does session exist? */
|
||||
/* End current session */
|
||||
$old_session = session_name();
|
||||
$old_id = session_id();
|
||||
session_write_close();
|
||||
|
||||
/* Load single signon session */
|
||||
session_name($session_name);
|
||||
session_id($_COOKIE[$session_name]);
|
||||
session_start();
|
||||
|
||||
/* Clear error message */
|
||||
unset($_SESSION['PMA_single_signon_error_message']);
|
||||
|
||||
/* Grab credentials if they exist */
|
||||
if (isset($_SESSION['PMA_single_signon_user'])) {
|
||||
if ($do_logout) {
|
||||
$PHP_AUTH_USER = '';
|
||||
} else {
|
||||
$PHP_AUTH_USER = $_SESSION['PMA_single_signon_user'];
|
||||
}
|
||||
}
|
||||
if (isset($_SESSION['PMA_single_signon_password'])) {
|
||||
if ($do_logout) {
|
||||
$PHP_AUTH_PW = '';
|
||||
} else {
|
||||
$PHP_AUTH_PW = $_SESSION['PMA_single_signon_password'];
|
||||
}
|
||||
}
|
||||
if (isset($_SESSION['PMA_single_signon_host'])) {
|
||||
$single_signon_host = $_SESSION['PMA_single_signon_host'];
|
||||
}
|
||||
|
||||
if (isset($_SESSION['PMA_single_signon_port'])) {
|
||||
$single_signon_port = $_SESSION['PMA_single_signon_port'];
|
||||
}
|
||||
|
||||
if (isset($_SESSION['PMA_single_signon_cfgupdate'])) {
|
||||
$single_signon_cfgupdate = $_SESSION['PMA_single_signon_cfgupdate'];
|
||||
}
|
||||
|
||||
|
||||
/* Also get token as it is needed to access subpages */
|
||||
if (isset($_SESSION['PMA_single_signon_token'])) {
|
||||
/* No need to care about token on logout */
|
||||
$pma_token = $_SESSION['PMA_single_signon_token'];
|
||||
}
|
||||
|
||||
/* End single signon session */
|
||||
session_write_close();
|
||||
|
||||
/* Restart phpMyAdmin session */
|
||||
session_name($old_session);
|
||||
if (!empty($old_id)) {
|
||||
session_id($old_id);
|
||||
}
|
||||
session_start();
|
||||
|
||||
/* Set the single signon host */
|
||||
$GLOBALS['cfg']['Server']['host'] = $single_signon_host;
|
||||
|
||||
/* Set the single signon port */
|
||||
$GLOBALS['cfg']['Server']['port'] = $single_signon_port;
|
||||
|
||||
/* Configuration update */
|
||||
$GLOBALS['cfg']['Server'] = array_merge(
|
||||
$GLOBALS['cfg']['Server'],
|
||||
$single_signon_cfgupdate
|
||||
);
|
||||
|
||||
/* Restore our token */
|
||||
if (!empty($pma_token)) {
|
||||
$_SESSION[' PMA_token '] = $pma_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear user cache.
|
||||
*/
|
||||
PMA_CommonFunctions::getInstance()->clearUserCache();
|
||||
}
|
||||
|
||||
// Returns whether we get authentication settings or not
|
||||
if (empty($PHP_AUTH_USER)) {
|
||||
unset($_SESSION['LAST_SIGNON_URL']);
|
||||
return false;
|
||||
} else {
|
||||
$_SESSION['LAST_SIGNON_URL'] = $GLOBALS['cfg']['Server']['SignonURL'];
|
||||
return true;
|
||||
}
|
||||
} // end of the 'PMA_auth_check()' function
|
||||
|
||||
|
||||
/**
|
||||
* Set the user and password after last checkings if required
|
||||
*
|
||||
* @global array the valid servers settings
|
||||
* @global integer the id of the current server
|
||||
* @global array the current server settings
|
||||
* @global string the current username
|
||||
* @global string the current password
|
||||
*
|
||||
* @return boolean always true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_set_user()
|
||||
{
|
||||
global $cfg;
|
||||
global $PHP_AUTH_USER, $PHP_AUTH_PW;
|
||||
|
||||
$cfg['Server']['user'] = $PHP_AUTH_USER;
|
||||
$cfg['Server']['password'] = $PHP_AUTH_PW;
|
||||
|
||||
return true;
|
||||
} // end of the 'PMA_auth_set_user()' function
|
||||
|
||||
|
||||
/**
|
||||
* User is not allowed to login to MySQL -> authentication failed
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_fails()
|
||||
{
|
||||
/* Session name */
|
||||
$session_name = $GLOBALS['cfg']['Server']['SignonSession'];
|
||||
|
||||
/* Does session exist? */
|
||||
if (isset($_COOKIE[$session_name])) {
|
||||
/* End current session */
|
||||
$old_session = session_name();
|
||||
$old_id = session_id();
|
||||
session_write_close();
|
||||
|
||||
/* Load single signon session */
|
||||
session_name($session_name);
|
||||
session_id($_COOKIE[$session_name]);
|
||||
session_start();
|
||||
|
||||
/* Set error message */
|
||||
if (! empty($GLOBALS['login_without_password_is_forbidden'])) {
|
||||
$_SESSION['PMA_single_signon_error_message'] = __('Login without a password is forbidden by configuration (see AllowNoPassword)');
|
||||
} elseif (! empty($GLOBALS['allowDeny_forbidden'])) {
|
||||
$_SESSION['PMA_single_signon_error_message'] = __('Access denied');
|
||||
} elseif (! empty($GLOBALS['no_activity'])) {
|
||||
$_SESSION['PMA_single_signon_error_message'] = sprintf(__('No activity within %s seconds; please log in again'), $GLOBALS['cfg']['LoginCookieValidity']);
|
||||
} elseif (PMA_DBI_getError()) {
|
||||
$_SESSION['PMA_single_signon_error_message'] = PMA_sanitize(PMA_DBI_getError());
|
||||
} else {
|
||||
$_SESSION['PMA_single_signon_error_message'] = __('Cannot log in to the MySQL server');
|
||||
}
|
||||
}
|
||||
PMA_auth();
|
||||
} // end of the 'PMA_auth_fails()' function
|
||||
|
||||
?>
|
||||
@ -1,456 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to build NHibernate dumps of tables
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage Codegen
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets executed twice so avoid a notice
|
||||
*/
|
||||
if (! defined('CG_FORMAT_NHIBERNATE_CS')) {
|
||||
define("CG_FORMAT_NHIBERNATE_CS", "NHibernate C# DO");
|
||||
define("CG_FORMAT_NHIBERNATE_XML", "NHibernate XML");
|
||||
|
||||
define("CG_HANDLER_NHIBERNATE_CS_BODY", "handleNHibernateCSBody");
|
||||
define("CG_HANDLER_NHIBERNATE_XML_BODY", "handleNHibernateXMLBody");
|
||||
}
|
||||
|
||||
$CG_FORMATS = array(
|
||||
CG_FORMAT_NHIBERNATE_CS,
|
||||
CG_FORMAT_NHIBERNATE_XML
|
||||
);
|
||||
$CG_HANDLERS = array(
|
||||
CG_HANDLER_NHIBERNATE_CS_BODY,
|
||||
CG_HANDLER_NHIBERNATE_XML_BODY
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['codegen'] = array(
|
||||
'text' => 'CodeGen',
|
||||
'extension' => 'cs',
|
||||
'mime_type' => 'text/cs',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$plugin_list['codegen']['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data'
|
||||
),
|
||||
array('type' => 'select',
|
||||
'name' => 'format',
|
||||
'text' => __('Format:'),
|
||||
'values' => $CG_FORMATS
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Set of functions used to build exports of tables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs CREATE DATABASE statement
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in NHibernate format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
global $CG_FORMATS, $CG_HANDLERS, $what;
|
||||
$format = $GLOBALS[$what . '_format'];
|
||||
if (isset($CG_FORMATS[$format])) {
|
||||
return PMA_exportOutputHandler(
|
||||
$CG_HANDLERS[$format]($db, $table, $crlf)
|
||||
);
|
||||
}
|
||||
return PMA_exportOutputHandler(sprintf("%s is not supported.", $format));
|
||||
}
|
||||
|
||||
/**
|
||||
* TableProperty class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage Codegen
|
||||
*/
|
||||
class TableProperty
|
||||
{
|
||||
public $name;
|
||||
public $type;
|
||||
public $nullable;
|
||||
public $key;
|
||||
public $defaultValue;
|
||||
public $ext;
|
||||
function __construct($row)
|
||||
{
|
||||
$this->name = trim($row[0]);
|
||||
$this->type = trim($row[1]);
|
||||
$this->nullable = trim($row[2]);
|
||||
$this->key = trim($row[3]);
|
||||
$this->defaultValue = trim($row[4]);
|
||||
$this->ext = trim($row[5]);
|
||||
}
|
||||
function getPureType()
|
||||
{
|
||||
$pos=strpos($this->type, "(");
|
||||
if ($pos > 0) {
|
||||
return substr($this->type, 0, $pos);
|
||||
}
|
||||
return $this->type;
|
||||
}
|
||||
function isNotNull()
|
||||
{
|
||||
return $this->nullable == "NO" ? "true" : "false";
|
||||
}
|
||||
function isUnique()
|
||||
{
|
||||
return $this->key == "PRI" || $this->key == "UNI" ? "true" : "false";
|
||||
}
|
||||
function getDotNetPrimitiveType()
|
||||
{
|
||||
if (strpos($this->type, "int") === 0) {
|
||||
return "int";
|
||||
}
|
||||
if (strpos($this->type, "long") === 0) {
|
||||
return "long";
|
||||
}
|
||||
if (strpos($this->type, "char") === 0) {
|
||||
return "string";
|
||||
}
|
||||
if (strpos($this->type, "varchar") === 0) {
|
||||
return "string";
|
||||
}
|
||||
if (strpos($this->type, "text") === 0) {
|
||||
return "string";
|
||||
}
|
||||
if (strpos($this->type, "longtext") === 0) {
|
||||
return "string";
|
||||
}
|
||||
if (strpos($this->type, "tinyint") === 0) {
|
||||
return "bool";
|
||||
}
|
||||
if (strpos($this->type, "datetime") === 0) {
|
||||
return "DateTime";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
function getDotNetObjectType()
|
||||
{
|
||||
if (strpos($this->type, "int") === 0) {
|
||||
return "Int32";
|
||||
}
|
||||
if (strpos($this->type, "long") === 0) {
|
||||
return "Long";
|
||||
}
|
||||
if (strpos($this->type, "char") === 0) {
|
||||
return "String";
|
||||
}
|
||||
if (strpos($this->type, "varchar") === 0) {
|
||||
return "String";
|
||||
}
|
||||
if (strpos($this->type, "text") === 0) {
|
||||
return "String";
|
||||
}
|
||||
if (strpos($this->type, "longtext") === 0) {
|
||||
return "String";
|
||||
}
|
||||
if (strpos($this->type, "tinyint") === 0) {
|
||||
return "Boolean";
|
||||
}
|
||||
if (strpos($this->type, "datetime") === 0) {
|
||||
return "DateTime";
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
function getIndexName()
|
||||
{
|
||||
if (strlen($this->key) > 0) {
|
||||
return "index=\""
|
||||
. htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8')
|
||||
. "\"";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function isPK()
|
||||
{
|
||||
return $this->key=="PRI";
|
||||
}
|
||||
function formatCs($text)
|
||||
{
|
||||
$text = str_replace(
|
||||
"#name#",
|
||||
cgMakeIdentifier($this->name, false),
|
||||
$text
|
||||
);
|
||||
return $this->format($text);
|
||||
}
|
||||
function formatXml($text)
|
||||
{
|
||||
$text = str_replace(
|
||||
"#name#",
|
||||
htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8'),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#indexName#",
|
||||
$this->getIndexName(),
|
||||
$text
|
||||
);
|
||||
return $this->format($text);
|
||||
}
|
||||
function format($text)
|
||||
{
|
||||
$text = str_replace(
|
||||
"#ucfirstName#",
|
||||
cgMakeIdentifier($this->name),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#dotNetPrimitiveType#",
|
||||
$this->getDotNetPrimitiveType(),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#dotNetObjectType#",
|
||||
$this->getDotNetObjectType(),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#type#",
|
||||
$this->getPureType(),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#notNull#",
|
||||
$this->isNotNull(),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#unique#",
|
||||
$this->isUnique(),
|
||||
$text
|
||||
);
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
function cgMakeIdentifier($str, $ucfirst = true)
|
||||
{
|
||||
// remove unsafe characters
|
||||
$str = preg_replace('/[^\p{L}\p{Nl}_]/u', '', $str);
|
||||
// make sure first character is a letter or _
|
||||
if (! preg_match('/^\pL/u', $str)) {
|
||||
$str = '_' . $str;
|
||||
}
|
||||
if ($ucfirst) {
|
||||
$str = ucfirst($str);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
function handleNHibernateCSBody($db, $table, $crlf)
|
||||
{
|
||||
$lines = array();
|
||||
$result = PMA_DBI_query(
|
||||
sprintf('DESC %s.%s', PMA_CommonFunctions::getInstance()->backquote($db), PMA_CommonFunctions::getInstance()->backquote($table))
|
||||
);
|
||||
if ($result) {
|
||||
$tableProperties = array();
|
||||
while ($row = PMA_DBI_fetch_row($result)) {
|
||||
$tableProperties[] = new TableProperty($row);
|
||||
}
|
||||
PMA_DBI_free_result($result);
|
||||
$lines[] = 'using System;';
|
||||
$lines[] = 'using System.Collections;';
|
||||
$lines[] = 'using System.Collections.Generic;';
|
||||
$lines[] = 'using System.Text;';
|
||||
$lines[] = 'namespace ' . cgMakeIdentifier($db);
|
||||
$lines[] = '{';
|
||||
$lines[] = ' #region ' . cgMakeIdentifier($table);
|
||||
$lines[] = ' public class ' . cgMakeIdentifier($table);
|
||||
$lines[] = ' {';
|
||||
$lines[] = ' #region Member Variables';
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
$lines[] = $tableProperty->formatCs(
|
||||
' protected #dotNetPrimitiveType# _#name#;'
|
||||
);
|
||||
}
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = ' #region Constructors';
|
||||
$lines[] = ' public ' . cgMakeIdentifier($table).'() { }';
|
||||
$temp = array();
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
if (! $tableProperty->isPK()) {
|
||||
$temp[] = $tableProperty->formatCs(
|
||||
'#dotNetPrimitiveType# #name#'
|
||||
);
|
||||
}
|
||||
}
|
||||
$lines[] = ' public '
|
||||
. cgMakeIdentifier($table)
|
||||
. '('
|
||||
. implode(', ', $temp)
|
||||
. ')';
|
||||
$lines[] = ' {';
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
if (! $tableProperty->isPK()) {
|
||||
$lines[] = $tableProperty->formatCs(
|
||||
' this._#name#=#name#;'
|
||||
);
|
||||
}
|
||||
}
|
||||
$lines[] = ' }';
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = ' #region Public Properties';
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
$lines[] = $tableProperty->formatCs(
|
||||
' public virtual #dotNetPrimitiveType# #ucfirstName#'
|
||||
. "\n"
|
||||
. ' {' . "\n"
|
||||
. ' get {return _#name#;}' . "\n"
|
||||
. ' set {_#name#=value;}' . "\n"
|
||||
. ' }'
|
||||
);
|
||||
}
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = ' }';
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = '}';
|
||||
}
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
|
||||
function handleNHibernateXMLBody($db, $table, $crlf)
|
||||
{
|
||||
$lines = array();
|
||||
$lines[] = '<?xml version="1.0" encoding="utf-8" ?' . '>';
|
||||
$lines[] = '<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" '
|
||||
. 'namespace="' . cgMakeIdentifier($db) . '" '
|
||||
. 'assembly="' . cgMakeIdentifier($db) . '">';
|
||||
$lines[] = ' <class '
|
||||
. 'name="' . cgMakeIdentifier($table) . '" '
|
||||
. 'table="' . cgMakeIdentifier($table) . '">';
|
||||
$result = PMA_DBI_query(
|
||||
sprintf("DESC %s.%s", PMA_CommonFunctions::getInstance()->backquote($db), PMA_CommonFunctions::getInstance()->backquote($table))
|
||||
);
|
||||
if ($result) {
|
||||
while ($row = PMA_DBI_fetch_row($result)) {
|
||||
$tableProperty = new TableProperty($row);
|
||||
if ($tableProperty->isPK()) {
|
||||
$lines[] = $tableProperty->formatXml(
|
||||
' <id name="#ucfirstName#" type="#dotNetObjectType#"'
|
||||
. ' unsaved-value="0">' . "\n"
|
||||
. ' <column name="#name#" sql-type="#type#"'
|
||||
. ' not-null="#notNull#" unique="#unique#"'
|
||||
. ' index="PRIMARY"/>' . "\n"
|
||||
. ' <generator class="native" />' . "\n"
|
||||
. ' </id>'
|
||||
);
|
||||
} else {
|
||||
$lines[] = $tableProperty->formatXml(
|
||||
' <property name="#ucfirstName#"'
|
||||
. ' type="#dotNetObjectType#">' . "\n"
|
||||
. ' <column name="#name#" sql-type="#type#"'
|
||||
. ' not-null="#notNull#" #indexName#/>' . "\n"
|
||||
. ' </property>'
|
||||
);
|
||||
}
|
||||
}
|
||||
PMA_DBI_free_result($result);
|
||||
}
|
||||
$lines[] = ' </class>';
|
||||
$lines[] = '</hibernate-mapping>';
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,334 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to build MediaWiki dumps of tables
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage MediaWiki
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['mediawiki'] = array(
|
||||
'text' => __('MediaWiki Table'),
|
||||
'extension' => 'mediawiki',
|
||||
'mime_type' => 'text/plain',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
// general options
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
);
|
||||
|
||||
// what to dump (structure/data/both)
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'begin_subgroup',
|
||||
'subgroup_header' => array(
|
||||
'type' => 'message_only',
|
||||
'text' => __('Dump table')
|
||||
)
|
||||
);
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'radio',
|
||||
'name' => 'structure_or_data',
|
||||
'values' => array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
)
|
||||
);
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'end_subgroup'
|
||||
);
|
||||
|
||||
// export table name
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'caption',
|
||||
'text' => __('Export table names')
|
||||
);
|
||||
|
||||
// export table headers
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'headers',
|
||||
'text' => __('Export table headers')
|
||||
);
|
||||
|
||||
// end general options
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Outputs comments containing info about the exported tables
|
||||
*
|
||||
* @param string $text Text of comment
|
||||
*
|
||||
* @return string The formatted comment
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function PMA_exportComment($text = '')
|
||||
{
|
||||
// see http://www.mediawiki.org/wiki/Help:Formatting
|
||||
$comment = PMA_exportCRLF();
|
||||
$comment .= '<!--' . PMA_exportCRLF();
|
||||
$comment .= $text . PMA_exportCRLF();
|
||||
$comment .= '-->' . str_repeat(PMA_exportCRLF(), 2);
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs CRLF
|
||||
*
|
||||
* @return string CRLF
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function PMA_exportCRLF()
|
||||
{
|
||||
// The CRLF expected by the mediawiki format is "\n"
|
||||
return "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs CREATE DATABASE statement
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs table's structure
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $export_mode 'create_table','triggers','create_view',
|
||||
* 'stand_in'
|
||||
* @param string $export_type 'server', 'database', 'table'
|
||||
* @param bool $do_relation whether to include relation comments
|
||||
* @param bool $do_comments whether to include the pmadb-style column comments
|
||||
* as comments in the structure; this is deprecated
|
||||
* but the parameter is left here because export.php
|
||||
* calls PMA_exportStructure() also for other export
|
||||
* types which use this parameter
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportStructure(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
$error_url,
|
||||
$export_mode,
|
||||
$export_type,
|
||||
$do_relation = false,
|
||||
$do_comments = false,
|
||||
$do_mime = false,
|
||||
$dates = false
|
||||
) {
|
||||
switch($export_mode) {
|
||||
case 'create_table':
|
||||
$columns = PMA_DBI_get_columns($db, $table);
|
||||
$columns = array_values($columns);
|
||||
$row_cnt = count($columns);
|
||||
|
||||
// Print structure comment
|
||||
$output = PMA_exportComment(
|
||||
"Table structure for "
|
||||
. PMA_CommonFunctions::getInstance()->backquote($table)
|
||||
);
|
||||
|
||||
// Begin the table construction
|
||||
$output .= "{| class=\"wikitable\" style=\"text-align:center;\""
|
||||
. PMA_exportCRLF();
|
||||
|
||||
// Add the table name
|
||||
if ($GLOBALS['mediawiki_caption']) {
|
||||
$output .= "|+'''" . $table . "'''" . PMA_exportCRLF();
|
||||
}
|
||||
|
||||
// Add the table headers
|
||||
if ($GLOBALS['mediawiki_headers']) {
|
||||
$output .= "|- style=\"background:#ffdead;\"" . PMA_exportCRLF();
|
||||
$output .= "! style=\"background:#ffffff\" | " . PMA_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Field']. PMA_exportCRLF();
|
||||
}
|
||||
}
|
||||
|
||||
// Add the table structure
|
||||
$output .= "|-" . PMA_exportCRLF();
|
||||
$output .= "! Type" . PMA_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Type'] . PMA_exportCRLF();
|
||||
}
|
||||
|
||||
$output .= "|-" . PMA_exportCRLF();
|
||||
$output .= "! Null" . PMA_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Null'] . PMA_exportCRLF();
|
||||
}
|
||||
|
||||
$output .= "|-" . PMA_exportCRLF();
|
||||
$output .= "! Default" . PMA_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Default'] . PMA_exportCRLF();
|
||||
}
|
||||
|
||||
$output .= "|-" . PMA_exportCRLF();
|
||||
$output .= "! Extra" . PMA_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Extra'] . PMA_exportCRLF();
|
||||
}
|
||||
|
||||
$output .= "|}" . str_repeat(PMA_exportCRLF(), 2);
|
||||
break;
|
||||
} // end switch
|
||||
|
||||
return PMA_exportOutputHandler($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in MediaWiki format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
$error_url,
|
||||
$sql_query
|
||||
) {
|
||||
// Print data comment
|
||||
$output = PMA_exportComment("Table data for ". PMA_CommonFunctions::getInstance()->backquote($table));
|
||||
|
||||
// Begin the table construction
|
||||
// Use the "wikitable" class for style
|
||||
// Use the "sortable" class for allowing tables to be sorted by column
|
||||
$output .= "{| class=\"wikitable sortable\" style=\"text-align:center;\""
|
||||
. PMA_exportCRLF();
|
||||
|
||||
// Add the table name
|
||||
if ($GLOBALS['mediawiki_caption']) {
|
||||
$output .= "|+'''" . $table . "'''" . PMA_exportCRLF();
|
||||
}
|
||||
|
||||
// Add the table headers
|
||||
if ($GLOBALS['mediawiki_headers']) {
|
||||
// Get column names
|
||||
$column_names = PMA_DBI_get_column_names($db, $table);
|
||||
|
||||
// Add column names as table headers
|
||||
if ( ! is_null($column_names) ) {
|
||||
// Use '|-' for separating rows
|
||||
$output .= "|-" . PMA_exportCRLF();
|
||||
|
||||
// Use '!' for separating table headers
|
||||
foreach ($column_names as $column) {
|
||||
$output .= " ! " . $column . "" . PMA_exportCRLF();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the table data from the database
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$fields_cnt = PMA_DBI_num_fields($result);
|
||||
|
||||
while ($row = PMA_DBI_fetch_row($result)) {
|
||||
$output .= "|-" . PMA_exportCRLF();
|
||||
|
||||
// Use '|' for separating table columns
|
||||
for ($i = 0; $i < $fields_cnt; ++ $i) {
|
||||
$output .= " | " . $row[$i] . "" . PMA_exportCRLF();
|
||||
}
|
||||
}
|
||||
|
||||
// End table construction
|
||||
$output .= "|}" . str_repeat(PMA_exportCRLF(), 2);
|
||||
return PMA_exportOutputHandler($output);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,530 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* CSV import plugin for phpMyAdmin
|
||||
*
|
||||
* @todo add an option for handling NULL values
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage CSV
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$common_functions = PMA_CommonFunctions::getInstance();
|
||||
$analyze = false;
|
||||
|
||||
if ($plugin_param !== 'table') {
|
||||
$analyze = true;
|
||||
}
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['csv'] = array(
|
||||
'text' => __('CSV'),
|
||||
'extension' => 'csv',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$plugin_list['csv']['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'replace',
|
||||
'text' => __('Replace table data with file')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'ignore',
|
||||
'text' => __('Do not abort on INSERT error')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'terminated',
|
||||
'text' => __('Columns separated with:'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'enclosed',
|
||||
'text' => __('Columns enclosed with:'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'escaped',
|
||||
'text' => __('Columns escaped with:'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'new_line',
|
||||
'text' => __('Lines terminated with:'),
|
||||
'size' => 2
|
||||
)
|
||||
);
|
||||
|
||||
if ($plugin_param !== 'table') {
|
||||
$plugin_list['csv']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'col_names',
|
||||
'text' => __(
|
||||
'The first line of the file contains the table column names <i>'
|
||||
. '(if this is unchecked, the first line will become part of the'
|
||||
. ' data)</i>'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$hint = new PMA_Message(
|
||||
__(
|
||||
'If the data in each row of the file is not'
|
||||
. ' in the same order as in the database, list the corresponding'
|
||||
. ' column names here. Column names must be separated by commas'
|
||||
. ' and not enclosed in quotations.'
|
||||
)
|
||||
);
|
||||
$plugin_list['csv']['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'columns',
|
||||
'text' => __('Column names: ') . $common_functions->showHint($hint)
|
||||
);
|
||||
}
|
||||
|
||||
$plugin_list['csv']['options'][] = array('type' => 'end_group');
|
||||
|
||||
/* We do not define function when plugin is just queried for information above */
|
||||
return;
|
||||
}
|
||||
|
||||
$replacements = array(
|
||||
'\\n' => "\n",
|
||||
'\\t' => "\t",
|
||||
'\\r' => "\r",
|
||||
);
|
||||
$csv_terminated = strtr($csv_terminated, $replacements);
|
||||
$csv_enclosed = strtr($csv_enclosed, $replacements);
|
||||
$csv_escaped = strtr($csv_escaped, $replacements);
|
||||
$csv_new_line = strtr($csv_new_line, $replacements);
|
||||
|
||||
$param_error = false;
|
||||
if (strlen($csv_terminated) != 1) {
|
||||
$message = PMA_Message::error(__('Invalid parameter for CSV import: %s'));
|
||||
$message->addParam(__('Columns terminated by'), false);
|
||||
$error = true;
|
||||
$param_error = true;
|
||||
// The default dialog of MS Excel when generating a CSV produces a
|
||||
// semi-colon-separated file with no chance of specifying the
|
||||
// enclosing character. Thus, users who want to import this file
|
||||
// tend to remove the enclosing character on the Import dialog.
|
||||
// I could not find a test case where having no enclosing characters
|
||||
// confuses this script.
|
||||
// But the parser won't work correctly with strings so we allow just
|
||||
// one character.
|
||||
} elseif (strlen($csv_enclosed) > 1) {
|
||||
$message = PMA_Message::error(__('Invalid parameter for CSV import: %s'));
|
||||
$message->addParam(__('Columns enclosed by'), false);
|
||||
$error = true;
|
||||
$param_error = true;
|
||||
} elseif (strlen($csv_escaped) != 1) {
|
||||
$message = PMA_Message::error(__('Invalid parameter for CSV import: %s'));
|
||||
$message->addParam(__('Columns escaped by'), false);
|
||||
$error = true;
|
||||
$param_error = true;
|
||||
} elseif (strlen($csv_new_line) != 1 && $csv_new_line != 'auto') {
|
||||
$message = PMA_Message::error(__('Invalid parameter for CSV import: %s'));
|
||||
$message->addParam(__('Lines terminated by'), false);
|
||||
$error = true;
|
||||
$param_error = true;
|
||||
}
|
||||
|
||||
// If there is an error in the parameters entered, indicate that immediately.
|
||||
if ($param_error) {
|
||||
$common_functions->mysqlDie($message->getMessage(), '', '', $err_url);
|
||||
}
|
||||
|
||||
$buffer = '';
|
||||
$required_fields = 0;
|
||||
|
||||
if (! $analyze) {
|
||||
if (isset($csv_replace)) {
|
||||
$sql_template = 'REPLACE';
|
||||
} else {
|
||||
$sql_template = 'INSERT';
|
||||
if (isset($csv_ignore)) {
|
||||
$sql_template .= ' IGNORE';
|
||||
}
|
||||
}
|
||||
$sql_template .= ' INTO ' . $common_functions->backquote($table);
|
||||
|
||||
$tmp_fields = PMA_DBI_get_columns($db, $table);
|
||||
|
||||
if (empty($csv_columns)) {
|
||||
$fields = $tmp_fields;
|
||||
} else {
|
||||
$sql_template .= ' (';
|
||||
$fields = array();
|
||||
$tmp = preg_split('/,( ?)/', $csv_columns);
|
||||
foreach ($tmp as $key => $val) {
|
||||
if (count($fields) > 0) {
|
||||
$sql_template .= ', ';
|
||||
}
|
||||
/* Trim also `, if user already included backquoted fields */
|
||||
$val = trim($val, " \t\r\n\0\x0B`");
|
||||
$found = false;
|
||||
foreach ($tmp_fields as $id => $field) {
|
||||
if ($field['Field'] == $val) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! $found) {
|
||||
$message = PMA_Message::error(
|
||||
__(
|
||||
'Invalid column (%s) specified! Ensure that columns names'
|
||||
. ' are spelled correctly, separated by commas, and not'
|
||||
. ' enclosed in quotes.'
|
||||
)
|
||||
);
|
||||
$message->addParam($val);
|
||||
$error = true;
|
||||
break;
|
||||
}
|
||||
$fields[] = $field;
|
||||
$sql_template .= $common_functions->backquote($val);
|
||||
}
|
||||
$sql_template .= ') ';
|
||||
}
|
||||
|
||||
$required_fields = count($fields);
|
||||
|
||||
$sql_template .= ' VALUES (';
|
||||
}
|
||||
|
||||
// Defaults for parser
|
||||
$i = 0;
|
||||
$len = 0;
|
||||
$line = 1;
|
||||
$lasti = -1;
|
||||
$values = array();
|
||||
$csv_finish = false;
|
||||
|
||||
$tempRow = array();
|
||||
$rows = array();
|
||||
$col_names = array();
|
||||
$tables = array();
|
||||
|
||||
$col_count = 0;
|
||||
$max_cols = 0;
|
||||
|
||||
while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
// subtract data we didn't handle yet and stop processing
|
||||
$offset -= strlen($buffer);
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
// Handle rest of buffer
|
||||
} else {
|
||||
// Append new data to buffer
|
||||
$buffer .= $data;
|
||||
unset($data);
|
||||
// Do not parse string when we're not at the end
|
||||
// and don't have new line inside
|
||||
if (($csv_new_line == 'auto'
|
||||
&& strpos($buffer, "\r") === false
|
||||
&& strpos($buffer, "\n") === false)
|
||||
|| ($csv_new_line != 'auto'
|
||||
&& strpos($buffer, $csv_new_line) === false)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Current length of our buffer
|
||||
$len = strlen($buffer);
|
||||
// Currently parsed char
|
||||
$ch = $buffer[$i];
|
||||
while ($i < $len) {
|
||||
// Deadlock protection
|
||||
if ($lasti == $i && $lastlen == $len) {
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid format of CSV input on line %d.')
|
||||
);
|
||||
$message->addParam($line);
|
||||
$error = true;
|
||||
break;
|
||||
}
|
||||
$lasti = $i;
|
||||
$lastlen = $len;
|
||||
|
||||
// This can happen with auto EOL and \r at the end of buffer
|
||||
if (! $csv_finish) {
|
||||
// Grab empty field
|
||||
if ($ch == $csv_terminated) {
|
||||
if ($i == $len - 1) {
|
||||
break;
|
||||
}
|
||||
$values[] = '';
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
continue;
|
||||
}
|
||||
|
||||
// Grab one field
|
||||
$fallbacki = $i;
|
||||
if ($ch == $csv_enclosed) {
|
||||
if ($i == $len - 1) {
|
||||
break;
|
||||
}
|
||||
$need_end = true;
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
} else {
|
||||
$need_end = false;
|
||||
}
|
||||
$fail = false;
|
||||
$value = '';
|
||||
while (($need_end
|
||||
&& ( $ch != $csv_enclosed || $csv_enclosed == $csv_escaped ))
|
||||
|| ( ! $need_end
|
||||
&& ! ( $ch == $csv_terminated
|
||||
|| $ch == $csv_new_line
|
||||
|| ( $csv_new_line == 'auto'
|
||||
&& ( $ch == "\r" || $ch == "\n" ) ) ) )
|
||||
) {
|
||||
if ($ch == $csv_escaped) {
|
||||
if ($i == $len - 1) {
|
||||
$fail = true;
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
if ($csv_enclosed == $csv_escaped
|
||||
&& ($ch == $csv_terminated
|
||||
|| $ch == $csv_new_line
|
||||
|| ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n")))
|
||||
) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$value .= $ch;
|
||||
if ($i == $len - 1) {
|
||||
if (! $finished) {
|
||||
$fail = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
}
|
||||
|
||||
// unquoted NULL string
|
||||
if (false === $need_end && $value === 'NULL') {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
if ($fail) {
|
||||
$i = $fallbacki;
|
||||
$ch = $buffer[$i];
|
||||
break;
|
||||
}
|
||||
// Need to strip trailing enclosing char?
|
||||
if ($need_end && $ch == $csv_enclosed) {
|
||||
if ($finished && $i == $len - 1) {
|
||||
$ch = null;
|
||||
} elseif ($i == $len - 1) {
|
||||
$i = $fallbacki;
|
||||
$ch = $buffer[$i];
|
||||
break;
|
||||
} else {
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
}
|
||||
}
|
||||
// Are we at the end?
|
||||
if ($ch == $csv_new_line
|
||||
|| ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))
|
||||
|| ($finished && $i == $len - 1)
|
||||
) {
|
||||
$csv_finish = true;
|
||||
}
|
||||
// Go to next char
|
||||
if ($ch == $csv_terminated) {
|
||||
if ($i == $len - 1) {
|
||||
$i = $fallbacki;
|
||||
$ch = $buffer[$i];
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
}
|
||||
// If everything went okay, store value
|
||||
$values[] = $value;
|
||||
}
|
||||
|
||||
// End of line
|
||||
if ($csv_finish
|
||||
|| $ch == $csv_new_line
|
||||
|| ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))
|
||||
) {
|
||||
if ($csv_new_line == 'auto' && $ch == "\r") { // Handle "\r\n"
|
||||
if ($i >= ($len - 2) && ! $finished) {
|
||||
break; // We need more data to decide new line
|
||||
}
|
||||
if ($buffer[$i + 1] == "\n") {
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
// We didn't parse value till the end of line, so there was empty one
|
||||
if (! $csv_finish) {
|
||||
$values[] = '';
|
||||
}
|
||||
|
||||
if ($analyze) {
|
||||
foreach ($values as $ley => $val) {
|
||||
$tempRow[] = $val;
|
||||
++$col_count;
|
||||
}
|
||||
|
||||
if ($col_count > $max_cols) {
|
||||
$max_cols = $col_count;
|
||||
}
|
||||
$col_count = 0;
|
||||
|
||||
$rows[] = $tempRow;
|
||||
$tempRow = array();
|
||||
} else {
|
||||
// Do we have correct count of values?
|
||||
if (count($values) != $required_fields) {
|
||||
|
||||
// Hack for excel
|
||||
if ($values[count($values) - 1] == ';') {
|
||||
unset($values[count($values) - 1]);
|
||||
} else {
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid column count in CSV input on line %d.')
|
||||
);
|
||||
$message->addParam($line);
|
||||
$error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$first = true;
|
||||
$sql = $sql_template;
|
||||
foreach ($values as $key => $val) {
|
||||
if (! $first) {
|
||||
$sql .= ', ';
|
||||
}
|
||||
if ($val === null) {
|
||||
$sql .= 'NULL';
|
||||
} else {
|
||||
$sql .= '\'' . $common_functions->sqlAddSlashes($val) . '\'';
|
||||
}
|
||||
|
||||
$first = false;
|
||||
}
|
||||
$sql .= ')';
|
||||
|
||||
/**
|
||||
* @todo maybe we could add original line to verbose SQL in comment
|
||||
*/
|
||||
PMA_importRunQuery($sql, $sql);
|
||||
}
|
||||
|
||||
$line++;
|
||||
$csv_finish = false;
|
||||
$values = array();
|
||||
$buffer = substr($buffer, $i + 1);
|
||||
$len = strlen($buffer);
|
||||
$i = 0;
|
||||
$lasti = -1;
|
||||
$ch = $buffer[0];
|
||||
}
|
||||
} // End of parser loop
|
||||
} // End of import loop
|
||||
|
||||
if ($analyze) {
|
||||
/* Fill out all rows */
|
||||
$num_rows = count($rows);
|
||||
for ($i = 0; $i < $num_rows; ++$i) {
|
||||
for ($j = count($rows[$i]); $j < $max_cols; ++$j) {
|
||||
$rows[$i][] = 'NULL';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['csv_col_names'])) {
|
||||
$col_names = array_splice($rows, 0, 1);
|
||||
$col_names = $col_names[0];
|
||||
}
|
||||
|
||||
if ((isset($col_names) && count($col_names) != $max_cols)
|
||||
|| ! isset($col_names)
|
||||
) {
|
||||
// Fill out column names
|
||||
for ($i = 0; $i < $max_cols; ++$i) {
|
||||
$col_names[] = 'COL '.($i+1);
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen($db)) {
|
||||
$result = PMA_DBI_fetch_result('SHOW TABLES');
|
||||
$tbl_name = 'TABLE '.(count($result) + 1);
|
||||
} else {
|
||||
$tbl_name = 'TBL_NAME';
|
||||
}
|
||||
|
||||
$tables[] = array($tbl_name, $col_names, $rows);
|
||||
|
||||
/* Obtain the best-fit MySQL types for each column */
|
||||
$analyses = array();
|
||||
$analyses[] = PMA_analyzeTable($tables[0]);
|
||||
|
||||
/**
|
||||
* string $db_name (no backquotes)
|
||||
*
|
||||
* array $table = array(table_name, array() column_names, array()() rows)
|
||||
* array $tables = array of "$table"s
|
||||
*
|
||||
* array $analysis = array(array() column_types, array() column_sizes)
|
||||
* array $analyses = array of "$analysis"s
|
||||
*
|
||||
* array $create = array of SQL strings
|
||||
*
|
||||
* array $options = an associative array of options
|
||||
*/
|
||||
|
||||
/* Set database name to the currently selected one, if applicable */
|
||||
if (strlen($db)) {
|
||||
$db_name = $db;
|
||||
$options = array('create_db' => false);
|
||||
} else {
|
||||
$db_name = 'CSV_DB';
|
||||
$options = null;
|
||||
}
|
||||
|
||||
/* Non-applicable parameters */
|
||||
$create = null;
|
||||
|
||||
/* Created and execute necessary SQL statements from data */
|
||||
PMA_buildSQL($db_name, $tables, $analyses, $create, $options);
|
||||
|
||||
unset($tables);
|
||||
unset($analyses);
|
||||
}
|
||||
|
||||
// Commit any possible data in buffers
|
||||
PMA_importRunQuery();
|
||||
|
||||
if (count($values) != 0 && ! $error) {
|
||||
$message = PMA_Message::error(__('Invalid format of CSV input on line %d.'));
|
||||
$message->addParam($line);
|
||||
$error = true;
|
||||
}
|
||||
?>
|
||||
@ -1,99 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* DocSQL import plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage DocSQL
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load relations.
|
||||
*/
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
$common_functions = PMA_CommonFunctions::getInstance();
|
||||
|
||||
/**
|
||||
* We need relations enabled and we work only on database
|
||||
*/
|
||||
if ($plugin_param !== 'database' || $GLOBALS['num_tables'] < 1
|
||||
|| ! $cfgRelation['relwork'] || ! $cfgRelation['commwork']
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['docsql'] = array( // set name of your plugin
|
||||
'text' => __('DocSQL'), // text to be displayed as choice
|
||||
'extension' => '', // extension this plugin can handle
|
||||
'options' => array( // array of options for your plugin (optional)
|
||||
array('type' => 'begin_group', 'name' => 'general_opts'),
|
||||
array('type' => 'text', 'name' => 'table', 'text' => __('Table name')),
|
||||
array('type' => 'end_group')
|
||||
),
|
||||
'options_text' => __('Options'), // text to describe plugin options (must be set if options are used)
|
||||
);
|
||||
/* We do not define function when plugin is just queried for information above */
|
||||
return;
|
||||
}
|
||||
|
||||
$tab = $_POST['docsql_table'];
|
||||
$buffer = '';
|
||||
/* Read whole buffer, we except it is small enough */
|
||||
while (!$finished && !$error && !$timeout_passed) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
// subtract data we didn't handle yet and stop processing
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
// nothing to read
|
||||
break;
|
||||
} else {
|
||||
// Append new data to buffer
|
||||
$buffer .= $data;
|
||||
}
|
||||
} // End of import loop
|
||||
/* Process the data */
|
||||
if ($data === true && !$error && !$timeout_passed) {
|
||||
$buffer = str_replace("\r\n", "\n", $buffer);
|
||||
$buffer = str_replace("\r", "\n", $buffer);
|
||||
$lines = explode("\n", $buffer);
|
||||
foreach ($lines AS $lkey => $line) {
|
||||
//echo '<p>' . $line . '</p>';
|
||||
$inf = explode('|', $line);
|
||||
if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) {
|
||||
$qry = '
|
||||
INSERT INTO
|
||||
' . $common_functions->backquote($cfgRelation['db']) . '.' . $common_functions->backquote($cfgRelation['column_info']) . '
|
||||
(db_name, table_name, column_name, comment)
|
||||
VALUES (
|
||||
\'' . $common_functions->sqlAddSlashes($GLOBALS['db']) . '\',
|
||||
\'' . $common_functions->sqlAddSlashes(trim($tab)) . '\',
|
||||
\'' . $common_functions->sqlAddSlashes(trim($inf[0])) . '\',
|
||||
\'' . $common_functions->sqlAddSlashes(trim($inf[1])) . '\')';
|
||||
PMA_importRunQuery($qry, $qry . '-- ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]), true);
|
||||
} // end inf[1] exists
|
||||
if (!empty($inf[2]) && strlen(trim($inf[2])) > 0) {
|
||||
$for = explode('->', $inf[2]);
|
||||
$qry = '
|
||||
INSERT INTO
|
||||
' . $common_functions->backquote($cfgRelation['db']) . '.' . $common_functions->backquote($cfgRelation['relation']) . '
|
||||
(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)
|
||||
VALUES (
|
||||
\'' . $common_functions->sqlAddSlashes($GLOBALS['db']) . '\',
|
||||
\'' . $common_functions->sqlAddSlashes(trim($tab)) . '\',
|
||||
\'' . $common_functions->sqlAddSlashes(trim($inf[0])) . '\',
|
||||
\'' . $common_functions->sqlAddSlashes($GLOBALS['db']) . '\',
|
||||
\'' . $common_functions->sqlAddSlashes(trim($for[0])) . '\',
|
||||
\'' . $common_functions->sqlAddSlashes(trim($for[1])) . '\')';
|
||||
PMA_importRunQuery($qry, $qry . '-- ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '(' . htmlspecialchars($inf[2]) . ')', true);
|
||||
} // end inf[2] exists
|
||||
} // End lines loop
|
||||
} // End import
|
||||
// Commit any possible data in buffers
|
||||
PMA_importRunQuery();
|
||||
?>
|
||||
@ -1,159 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* CSV import plugin for phpMyAdmin using LOAD DATA
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage LDI
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$common_functions = PMA_CommonFunctions::getInstance();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if ($plugin_param !== 'table') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') {
|
||||
$GLOBALS['cfg']['Import']['ldi_local_option'] = false;
|
||||
|
||||
$result = PMA_DBI_try_query('SHOW VARIABLES LIKE \'local\\_infile\';');
|
||||
if ($result != false && PMA_DBI_num_rows($result) > 0) {
|
||||
$tmp = PMA_DBI_fetch_row($result);
|
||||
if ($tmp[1] == 'ON') {
|
||||
$GLOBALS['cfg']['Import']['ldi_local_option'] = true;
|
||||
}
|
||||
}
|
||||
PMA_DBI_free_result($result);
|
||||
unset($result);
|
||||
}
|
||||
$plugin_list['ldi'] = array(
|
||||
'text' => __('CSV using LOAD DATA'),
|
||||
// Following is nonsense, however we want to default to our parser for csv
|
||||
'extension' => 'ldi',
|
||||
'options' => array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'replace',
|
||||
'text' => __('Replace table data with file')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'ignore',
|
||||
'text' => __('Do not abort on INSERT error')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'terminated',
|
||||
'text' => __('Columns terminated by'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'enclosed',
|
||||
'text' => __('Columns enclosed by'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'escaped',
|
||||
'text' => __('Columns escaped by'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'new_line',
|
||||
'text' => __('Lines terminated by'),
|
||||
'size' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'columns',
|
||||
'text' => __('Column names')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'local_option',
|
||||
'text' => __('Use LOCAL keyword')
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
/* We do not define function when plugin is just queried for information above */
|
||||
return;
|
||||
}
|
||||
|
||||
if ($import_file == 'none' || $compression != 'none' || $charset_conversion) {
|
||||
// We handle only some kind of data!
|
||||
$message = PMA_Message::error(__('This plugin does not support compressed imports!'));
|
||||
$error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'LOAD DATA';
|
||||
if (isset($ldi_local_option)) {
|
||||
$sql .= ' LOCAL';
|
||||
}
|
||||
$sql .= ' INFILE \'' . $common_functions->sqlAddSlashes($import_file) . '\'';
|
||||
if (isset($ldi_replace)) {
|
||||
$sql .= ' REPLACE';
|
||||
} elseif (isset($ldi_ignore)) {
|
||||
$sql .= ' IGNORE';
|
||||
}
|
||||
$sql .= ' INTO TABLE ' . $common_functions->backquote($table);
|
||||
|
||||
if (strlen($ldi_terminated) > 0) {
|
||||
$sql .= ' FIELDS TERMINATED BY \'' . $ldi_terminated . '\'';
|
||||
}
|
||||
if (strlen($ldi_enclosed) > 0) {
|
||||
$sql .= ' ENCLOSED BY \'' . $common_functions->sqlAddSlashes($ldi_enclosed) . '\'';
|
||||
}
|
||||
if (strlen($ldi_escaped) > 0) {
|
||||
$sql .= ' ESCAPED BY \'' . $common_functions->sqlAddSlashes($ldi_escaped) . '\'';
|
||||
}
|
||||
if (strlen($ldi_new_line) > 0) {
|
||||
if ($ldi_new_line == 'auto') {
|
||||
$ldi_new_line = ($common_functions->whichCrlf() == "\n")
|
||||
? '\n'
|
||||
: '\r\n';
|
||||
}
|
||||
$sql .= ' LINES TERMINATED BY \'' . $ldi_new_line . '\'';
|
||||
}
|
||||
if ($skip_queries > 0) {
|
||||
$sql .= ' IGNORE ' . $skip_queries . ' LINES';
|
||||
$skip_queries = 0;
|
||||
}
|
||||
if (strlen($ldi_columns) > 0) {
|
||||
$sql .= ' (';
|
||||
$tmp = preg_split('/,( ?)/', $ldi_columns);
|
||||
$cnt_tmp = count($tmp);
|
||||
for ($i = 0; $i < $cnt_tmp; $i++) {
|
||||
if ($i > 0) {
|
||||
$sql .= ', ';
|
||||
}
|
||||
/* Trim also `, if user already included backquoted fields */
|
||||
$sql .= $common_functions->backquote(trim($tmp[$i], " \t\r\n\0\x0B`"));
|
||||
} // end for
|
||||
$sql .= ')';
|
||||
}
|
||||
|
||||
PMA_importRunQuery($sql, $sql);
|
||||
PMA_importRunQuery();
|
||||
$finished = true;
|
||||
?>
|
||||
@ -1,318 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* XML import plugin for phpMyAdmin
|
||||
*
|
||||
* @todo Improve efficiency
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage XML
|
||||
*/
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* We need way to disable external XML entities processing.
|
||||
*/
|
||||
if (!function_exists('libxml_disable_entity_loader')) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* The possible scopes for $plugin_param are: 'table', 'database', and 'server'
|
||||
*/
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['xml'] = array(
|
||||
'text' => __('XML'),
|
||||
'extension' => 'xml',
|
||||
'options' => array(
|
||||
),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
/* We do not define function when plugin is just queried for information above */
|
||||
return;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$len = 0;
|
||||
$buffer = "";
|
||||
|
||||
/**
|
||||
* Read in the file via PMA_importGetNextChunk so that
|
||||
* it can process compressed files
|
||||
*/
|
||||
while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
/* subtract data we didn't handle yet and stop processing */
|
||||
$offset -= strlen($buffer);
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
/* Handle rest of buffer */
|
||||
} else {
|
||||
/* Append new data to buffer */
|
||||
$buffer .= $data;
|
||||
unset($data);
|
||||
}
|
||||
}
|
||||
|
||||
unset($data);
|
||||
|
||||
/**
|
||||
* Disable loading of external XML entities.
|
||||
*/
|
||||
libxml_disable_entity_loader();
|
||||
|
||||
/**
|
||||
* Load the XML string
|
||||
*
|
||||
* The option LIBXML_COMPACT is specified because it can
|
||||
* result in increased performance without the need to
|
||||
* alter the code in any way. It's basically a freebee.
|
||||
*/
|
||||
$xml = simplexml_load_string($buffer, "SimpleXMLElement", LIBXML_COMPACT);
|
||||
|
||||
unset($buffer);
|
||||
|
||||
/**
|
||||
* The XML was malformed
|
||||
*/
|
||||
if ($xml === false) {
|
||||
PMA_Message::error(__('The XML file specified was either malformed or incomplete. Please correct the issue and try again.'))->display();
|
||||
unset($xml);
|
||||
$GLOBALS['finished'] = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Table accumulator
|
||||
*/
|
||||
$tables = array();
|
||||
/**
|
||||
* Row accumulator
|
||||
*/
|
||||
$rows = array();
|
||||
|
||||
/**
|
||||
* Temp arrays
|
||||
*/
|
||||
$tempRow = array();
|
||||
$tempCells = array();
|
||||
|
||||
/**
|
||||
* CREATE code included (by default: no)
|
||||
*/
|
||||
$struct_present = false;
|
||||
|
||||
/**
|
||||
* Analyze the data in each table
|
||||
*/
|
||||
$namespaces = $xml->getNameSpaces(true);
|
||||
|
||||
/**
|
||||
* Get the database name, collation and charset
|
||||
*/
|
||||
$db_attr = $xml->children($namespaces['pma'])->{'structure_schemas'}->{'database'};
|
||||
|
||||
if ($db_attr instanceof SimpleXMLElement) {
|
||||
$db_attr = $db_attr->attributes();
|
||||
$db_name = (string)$db_attr['name'];
|
||||
$collation = (string)$db_attr['collation'];
|
||||
$charset = (string)$db_attr['charset'];
|
||||
} else {
|
||||
/**
|
||||
* If the structure section is not present
|
||||
* get the database name from the data section
|
||||
*/
|
||||
$db_attr = $xml->children()->attributes();
|
||||
$db_name = (string)$db_attr['name'];
|
||||
$collation = null;
|
||||
$charset = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The XML was malformed
|
||||
*/
|
||||
if ($db_name === null) {
|
||||
PMA_Message::error(__('The XML file specified was either malformed or incomplete. Please correct the issue and try again.'))->display();
|
||||
unset($xml);
|
||||
$GLOBALS['finished'] = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the structure information
|
||||
*/
|
||||
if (isset($namespaces['pma'])) {
|
||||
/**
|
||||
* Get structures for all tables
|
||||
*/
|
||||
$struct = $xml->children($namespaces['pma']);
|
||||
|
||||
$create = array();
|
||||
|
||||
foreach ($struct as $tier1 => $val1) {
|
||||
foreach ($val1 as $tier2 => $val2) {
|
||||
// Need to select the correct database for the creation of tables,
|
||||
// views, triggers, etc.
|
||||
/**
|
||||
* @todo Generating a USE here blocks importing of a table
|
||||
* into another database.
|
||||
*/
|
||||
$attrs = $val2->attributes();
|
||||
$create[] = "USE " . PMA_CommonFunctions::getInstance()->backquote($attrs["name"]);
|
||||
|
||||
foreach ($val2 as $val3) {
|
||||
/**
|
||||
* Remove the extra cosmetic spacing
|
||||
*/
|
||||
$val3 = str_replace(" ", "", (string)$val3);
|
||||
$create[] = $val3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$struct_present = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move down the XML tree to the actual data
|
||||
*/
|
||||
$xml = $xml->children()->children();
|
||||
|
||||
$data_present = false;
|
||||
|
||||
/**
|
||||
* Only attempt to analyze/collect data if there is data present
|
||||
*/
|
||||
if ($xml && @$xml->count()) {
|
||||
$data_present = true;
|
||||
|
||||
/**
|
||||
* Process all database content
|
||||
*/
|
||||
foreach ($xml as $k1 => $v1) {
|
||||
$tbl_attr = $v1->attributes();
|
||||
|
||||
$isInTables = false;
|
||||
for ($i = 0; $i < count($tables); ++$i) {
|
||||
if (! strcmp($tables[$i][TBL_NAME], (string)$tbl_attr['name'])) {
|
||||
$isInTables = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isInTables == false) {
|
||||
$tables[] = array((string)$tbl_attr['name']);
|
||||
}
|
||||
|
||||
foreach ($v1 as $k2 => $v2) {
|
||||
$row_attr = $v2->attributes();
|
||||
if (! array_search((string)$row_attr['name'], $tempRow)) {
|
||||
$tempRow[] = (string)$row_attr['name'];
|
||||
}
|
||||
$tempCells[] = (string)$v2;
|
||||
}
|
||||
|
||||
$rows[] = array((string)$tbl_attr['name'], $tempRow, $tempCells);
|
||||
|
||||
$tempRow = array();
|
||||
$tempCells = array();
|
||||
}
|
||||
|
||||
unset($tempRow);
|
||||
unset($tempCells);
|
||||
unset($xml);
|
||||
|
||||
/**
|
||||
* Bring accumulated rows into the corresponding table
|
||||
*/
|
||||
$num_tbls = count($tables);
|
||||
for ($i = 0; $i < $num_tbls; ++$i) {
|
||||
for ($j = 0; $j < count($rows); ++$j) {
|
||||
if (! strcmp($tables[$i][TBL_NAME], $rows[$j][TBL_NAME])) {
|
||||
if (! isset($tables[$i][COL_NAMES])) {
|
||||
$tables[$i][] = $rows[$j][COL_NAMES];
|
||||
}
|
||||
|
||||
$tables[$i][ROWS][] = $rows[$j][ROWS];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($rows);
|
||||
|
||||
if (! $struct_present) {
|
||||
$analyses = array();
|
||||
|
||||
$len = count($tables);
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$analyses[] = PMA_analyzeTable($tables[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($xml);
|
||||
unset($tempRows);
|
||||
unset($tempCells);
|
||||
unset($rows);
|
||||
|
||||
/**
|
||||
* Only build SQL from data if there is data present
|
||||
*/
|
||||
if ($data_present) {
|
||||
/**
|
||||
* Set values to NULL if they were not present
|
||||
* to maintain PMA_buildSQL() call integrity
|
||||
*/
|
||||
if (! isset($analyses)) {
|
||||
$analyses = null;
|
||||
if (! $struct_present) {
|
||||
$create = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* string $db_name (no backquotes)
|
||||
*
|
||||
* array $table = array(table_name, array() column_names, array()() rows)
|
||||
* array $tables = array of "$table"s
|
||||
*
|
||||
* array $analysis = array(array() column_types, array() column_sizes)
|
||||
* array $analyses = array of "$analysis"s
|
||||
*
|
||||
* array $create = array of SQL strings
|
||||
*
|
||||
* array $options = an associative array of options
|
||||
*/
|
||||
|
||||
/* Set database name to the currently selected one, if applicable */
|
||||
if (strlen($db)) {
|
||||
/* Override the database name in the XML file, if one is selected */
|
||||
$db_name = $db;
|
||||
$options = array('create_db' => false);
|
||||
} else {
|
||||
if ($db_name === null) {
|
||||
$db_name = 'XML_DB';
|
||||
}
|
||||
|
||||
/* Set database collation/charset */
|
||||
$options = array(
|
||||
'db_collation' => $collation,
|
||||
'db_charset' => $charset,
|
||||
);
|
||||
}
|
||||
|
||||
/* Created and execute necessary SQL statements from data */
|
||||
PMA_buildSQL($db_name, $tables, $analyses, $create, $options);
|
||||
|
||||
unset($analyses);
|
||||
unset($tables);
|
||||
unset($create);
|
||||
|
||||
/* Commit any possible data in buffers */
|
||||
PMA_importRunQuery();
|
||||
?>
|
||||
@ -1,105 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* @package PhpMyAdmin-Transformation
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function PMA_transformation_text_plain__dateformat_info()
|
||||
{
|
||||
return array(
|
||||
'info' => __('Displays a TIME, TIMESTAMP, DATETIME or numeric unix timestamp column as formatted date. The first option is the offset (in hours) which will be added to the timestamp (Default: 0). Use second option to specify a different date/time format string. Third option determines whether you want to see local date or UTC one (use "local" or "utc" strings) for that. According to that, date format has different value - for "local" see the documentation for PHP\'s strftime() function and for "utc" it is done using gmdate() function.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function PMA_transformation_text_plain__dateformat($buffer, $options = array(), $meta = '')
|
||||
{
|
||||
// possibly use a global transform and feed it with special options
|
||||
|
||||
// further operations on $buffer using the $options[] array.
|
||||
if (empty($options[0])) {
|
||||
$options[0] = 0;
|
||||
}
|
||||
|
||||
if (empty($options[2])) {
|
||||
$options[2] = 'local';
|
||||
} else {
|
||||
$options[2] = strtolower($options[2]);
|
||||
}
|
||||
|
||||
if (empty($options[1])) {
|
||||
if ($options[2] == 'local') {
|
||||
$options[1] = __('%B %d, %Y at %I:%M %p');
|
||||
} else {
|
||||
$options[1] = 'Y-m-d H:i:s';
|
||||
}
|
||||
}
|
||||
|
||||
$timestamp = -1;
|
||||
|
||||
// INT columns will be treated as UNIX timestamps
|
||||
// and need to be detected before the verification for
|
||||
// MySQL TIMESTAMP
|
||||
if ($meta->type == 'int') {
|
||||
$timestamp = $buffer;
|
||||
|
||||
// Detect TIMESTAMP(6 | 8 | 10 | 12 | 14)
|
||||
// TIMESTAMP (2 | 4) not supported here.
|
||||
// (Note: prior to MySQL 4.1, TIMESTAMP has a display size, for example
|
||||
// TIMESTAMP(8) means YYYYMMDD)
|
||||
} else if (preg_match('/^(\d{2}){3,7}$/', $buffer)) {
|
||||
|
||||
if (strlen($buffer) == 14 || strlen($buffer) == 8) {
|
||||
$offset = 4;
|
||||
} else {
|
||||
$offset = 2;
|
||||
}
|
||||
|
||||
$d = array();
|
||||
$d['year'] = substr($buffer, 0, $offset);
|
||||
$d['month'] = substr($buffer, $offset, 2);
|
||||
$d['day'] = substr($buffer, $offset + 2, 2);
|
||||
$d['hour'] = substr($buffer, $offset + 4, 2);
|
||||
$d['minute'] = substr($buffer, $offset + 6, 2);
|
||||
$d['second'] = substr($buffer, $offset + 8, 2);
|
||||
|
||||
if (checkdate($d['month'], $d['day'], $d['year'])) {
|
||||
$timestamp = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']);
|
||||
}
|
||||
// If all fails, assume one of the dozens of valid strtime() syntaxes (http://www.gnu.org/manual/tar-1.12/html_chapter/tar_7.html)
|
||||
} else {
|
||||
if (preg_match('/^[0-9]\d{1,9}$/', $buffer)) {
|
||||
$timestamp = (int)$buffer;
|
||||
} else {
|
||||
$timestamp = strtotime($buffer);
|
||||
}
|
||||
}
|
||||
|
||||
// If all above failed, maybe it's a Unix timestamp already?
|
||||
if ($timestamp < 0 && preg_match('/^[1-9]\d{1,9}$/', $buffer)) {
|
||||
$timestamp = $buffer;
|
||||
}
|
||||
|
||||
// Reformat a valid timestamp
|
||||
if ($timestamp >= 0) {
|
||||
$timestamp -= $options[0] * 60 * 60;
|
||||
$source = $buffer;
|
||||
if ($options[2] == 'local') {
|
||||
$text = PMA_CommonFunctions::getInstance()->localisedDate($timestamp, $options[1]);
|
||||
} elseif ($options[2] == 'utc') {
|
||||
$text = gmdate($options[1], $timestamp);
|
||||
} else {
|
||||
$text = 'INVALID DATE TYPE';
|
||||
}
|
||||
$buffer = '<dfn onclick="alert(\'' . $source . '\');" title="' . $source . '">' . $text . '</dfn>';
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user