Initial commit

This commit is contained in:
2022-11-21 09:47:28 +01:00
commit 76cec83d26
11652 changed files with 1980467 additions and 0 deletions

View File

@ -0,0 +1,182 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Config file generator
*
* @package PhpMyAdmin-Setup
*/
namespace PMA\setup\lib;
use PMA\libraries\config\ConfigFile;
/**
* Config file generation class
*
* @package PhpMyAdmin
*/
class ConfigGenerator
{
/**
* Creates config file
*
* @param ConfigFile $cf Config file instance
*
* @return string
*/
public static function getConfigFile(ConfigFile $cf)
{
$crlf = (isset($_SESSION['eol']) && $_SESSION['eol'] == 'win')
? "\r\n"
: "\n";
$conf = $cf->getConfig();
// header
$ret = '<?php' . $crlf
. '/*' . $crlf
. ' * Generated configuration file' . $crlf
. ' * Generated by: phpMyAdmin '
. $GLOBALS['PMA_Config']->get('PMA_VERSION')
. ' setup script' . $crlf
. ' * Date: ' . gmdate(DATE_RFC1123) . $crlf
. ' */' . $crlf . $crlf;
//servers
if (! empty($conf['Servers'])) {
$ret .= self::getServerPart($cf, $crlf, $conf['Servers']);
unset($conf['Servers']);
}
// other settings
$persistKeys = $cf->getPersistKeysMap();
foreach ($conf as $k => $v) {
$k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
$ret .= self::_getVarExport($k, $v, $crlf);
if (isset($persistKeys[$k])) {
unset($persistKeys[$k]);
}
}
// keep 1d array keys which are present in $persist_keys (config.values.php)
foreach (array_keys($persistKeys) as $k) {
if (mb_strpos($k, '/') === false) {
$k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
$ret .= self::_getVarExport($k, $cf->getDefault($k), $crlf);
}
}
$ret .= '?' . '>';
return $ret;
}
/**
* Returns exported configuration variable
*
* @param string $var_name configuration name
* @param mixed $var_value configuration value(s)
* @param string $crlf line ending
*
* @return string
*/
private static function _getVarExport($var_name, $var_value, $crlf)
{
if (!is_array($var_value) || empty($var_value)) {
return "\$cfg['$var_name'] = "
. var_export($var_value, true) . ';' . $crlf;
}
$ret = '';
if (self::_isZeroBasedArray($var_value)) {
$ret = "\$cfg['$var_name'] = "
. self::_exportZeroBasedArray($var_value, $crlf)
. ';' . $crlf;
} else {
// string keys: $cfg[key][subkey] = value
foreach ($var_value as $k => $v) {
$k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
$ret .= "\$cfg['$var_name']['$k'] = "
. var_export($v, true) . ';' . $crlf;
}
}
return $ret;
}
/**
* Check whether $array is a continuous 0-based array
*
* @param array $array Array to check
*
* @return boolean
*/
private static function _isZeroBasedArray(array $array)
{
for ($i = 0, $nb = count($array); $i < $nb; $i++) {
if (! isset($array[$i])) {
return false;
}
}
return true;
}
/**
* Exports continuous 0-based array
*
* @param array $array Array to export
* @param string $crlf Newline string
*
* @return string
*/
private static function _exportZeroBasedArray(array $array, $crlf)
{
$retv = array();
foreach ($array as $v) {
$retv[] = var_export($v, true);
}
$ret = "array(";
if (count($retv) <= 4) {
// up to 4 values - one line
$ret .= implode(', ', $retv);
} else {
// more than 4 values - value per line
$imax = count($retv);
for ($i = 0; $i < $imax; $i++) {
$ret .= ($i > 0 ? ',' : '') . $crlf . ' ' . $retv[$i];
}
}
$ret .= ')';
return $ret;
}
/**
* Generate server part of config file
*
* @param ConfigFile $cf Config file
* @param string $crlf Carriage return char
* @param array $servers Servers list
*
* @return string
*/
protected static function getServerPart(ConfigFile $cf, $crlf, $servers)
{
if ($cf->getServerCount() === 0) {
return null;
}
$ret = "/* Servers configuration */$crlf\$i = 0;" . $crlf . $crlf;
foreach ($servers as $id => $server) {
$ret .= '/* Server: '
. strtr($cf->getServerName($id) . " [$id] ", '*/', '-')
. "*/" . $crlf
. '$i++;' . $crlf;
foreach ($server as $k => $v) {
$k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
$ret .= "\$cfg['Servers'][\$i]['$k'] = "
. (is_array($v) && self::_isZeroBasedArray($v)
? self::_exportZeroBasedArray($v, $crlf)
: var_export($v, true))
. ';' . $crlf;
}
$ret .= $crlf;
}
$ret .= '/* End of servers configuration */' . $crlf . $crlf;
return $ret;
}
}

View File

@ -0,0 +1,54 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Loads libraries/common.inc.php and preforms some additional actions
*
* @package PhpMyAdmin-Setup
*/
use PMA\libraries\config\ConfigFile;
/**
* Do not include full common.
* @ignore
*/
define('PMA_MINIMUM_COMMON', true);
define('PMA_SETUP', true);
chdir('..');
if (!file_exists('./libraries/common.inc.php')) {
die('Bad invocation!');
}
require_once './libraries/common.inc.php';
require_once './libraries/config/config_functions.lib.php';
require_once './libraries/config/messages.inc.php';
require_once './libraries/url_generating.lib.php';
require_once './libraries/user_preferences.lib.php';
// use default error handler
restore_error_handler();
// Save current language in a cookie, required since we use PMA_MINIMUM_COMMON
$GLOBALS['PMA_Config']->setCookie('pma_lang', $GLOBALS['lang']);
$GLOBALS['ConfigFile'] = new ConfigFile();
$GLOBALS['ConfigFile']->setPersistKeys(
array(
'DefaultLang',
'ServerDefault',
'UploadDir',
'SaveDir',
'Servers/1/verbose',
'Servers/1/host',
'Servers/1/port',
'Servers/1/socket',
'Servers/1/connect_type',
'Servers/1/auth_type',
'Servers/1/user',
'Servers/1/password'
)
);
// allows for redirection even after sending some data
ob_start();

View File

@ -0,0 +1,81 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Formset processing library
*
* @package PhpMyAdmin-Setup
*/
use PMA\libraries\config\FormDisplay;
/**
* Processes forms registered in $form_display, handles error correction
*
* @param FormDisplay $form_display Form to display
*
* @return void
*/
function PMA_Process_formset(FormDisplay $form_display)
{
if (isset($_GET['mode']) && $_GET['mode'] == 'revert') {
// revert erroneous fields to their default values
$form_display->fixErrors();
PMA_generateHeader303();
}
if (!$form_display->process(false)) {
// handle form view and failed POST
echo $form_display->getDisplay(true, true);
return;
}
// check for form errors
if (!$form_display->hasErrors()) {
PMA_generateHeader303();
return;
}
// form has errors, show warning
$separator = PMA_URL_getArgSeparator('html');
$page = isset($_GET['page']) ? htmlspecialchars($_GET['page']) : null;
$formset = isset($_GET['formset']) ? htmlspecialchars($_GET['formset']) : null;
$formset = $formset ? "{$separator}formset=$formset" : '';
$formId = PMA_isValid($_GET['id'], 'numeric') ? $_GET['id'] : null;
if ($formId === null && $page == 'servers') {
// we've just added a new server, get its id
$formId = $form_display->getConfigFile()->getServerCount();
}
$formId = $formId ? "{$separator}id=$formId" : '';
?>
<div class="error">
<h4><?php echo __('Warning') ?></h4>
<?php echo __('Submitted form contains errors') ?><br />
<a href="<?php echo PMA_URL_getCommon() , $separator ?>page=<?php echo $page , $formset , $formId , $separator ?>mode=revert">
<?php echo __('Try to revert erroneous fields to their default values') ?>
</a>
</div>
<?php echo $form_display->displayErrors() ?>
<a class="btn" href="index.php<?php echo PMA_URL_getCommon() ?>">
<?php echo __('Ignore errors') ?>
</a>
&nbsp;
<a class="btn" href="<?php echo PMA_URL_getCommon() , $separator ?>page=<?php echo $page , $formset , $formId , $separator ?>mode=edit">
<?php echo __('Show form') ?>
</a>
<?php
}
/**
* Generate header for 303
*
* @return void
*/
function PMA_generateHeader303()
{
// drop post data
header('HTTP/1.1 303 See Other');
header('Location: index.php' . PMA_URL_getCommon());
if (!defined('TESTSUITE')) {
exit;
}
}

View File

@ -0,0 +1,213 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Various checks and message functions used on index page.
*
* @package PhpMyAdmin-Setup
*/
use PMA\libraries\VersionInformation;
if (!defined('PHPMYADMIN')) {
exit;
}
/**
* Initializes message list
*
* @return void
*/
function PMA_messagesBegin()
{
if (! isset($_SESSION['messages']) || !is_array($_SESSION['messages'])) {
$_SESSION['messages'] = array('error' => array(), 'notice' => array());
} else {
// reset message states
foreach ($_SESSION['messages'] as &$messages) {
foreach ($messages as &$msg) {
$msg['fresh'] = false;
$msg['active'] = false;
}
}
}
}
/**
* Adds a new message to message list
*
* @param string $type one of: notice, error
* @param string $msgId unique message identifier
* @param string $title language string id (in $str array)
* @param string $message message text
*
* @return void
*/
function PMA_messagesSet($type, $msgId, $title, $message)
{
$fresh = ! isset($_SESSION['messages'][$type][$msgId]);
$_SESSION['messages'][$type][$msgId] = array(
'fresh' => $fresh,
'active' => true,
'title' => $title,
'message' => $message);
}
/**
* Cleans up message list
*
* @return void
*/
function PMA_messagesEnd()
{
foreach ($_SESSION['messages'] as &$messages) {
$remove_ids = array();
foreach ($messages as $id => &$msg) {
if ($msg['active'] == false) {
$remove_ids[] = $id;
}
}
foreach ($remove_ids as $id) {
unset($messages[$id]);
}
}
}
/**
* Prints message list, must be called after PMA_messagesEnd()
*
* @return void
*/
function PMA_messagesShowHtml()
{
$old_ids = array();
foreach ($_SESSION['messages'] as $type => $messages) {
foreach ($messages as $id => $msg) {
echo '<div class="' , $type , '" id="' , $id , '">'
, '<h4>' , $msg['title'] , '</h4>'
, $msg['message'] , '</div>';
if (!$msg['fresh'] && $type != 'error') {
$old_ids[] = $id;
}
}
}
echo "\n" , '<script type="text/javascript">';
foreach ($old_ids as $id) {
echo "\nhiddenMessages.push('$id');";
}
echo "\n</script>\n";
}
/**
* Checks for newest phpMyAdmin version and sets result as a new notice
*
* @return void
*/
function PMA_versionCheck()
{
// version check messages should always be visible so let's make
// a unique message id each time we run it
$message_id = uniqid('version_check');
// Fetch data
$versionInformation = new VersionInformation();
$version_data = $versionInformation->getLatestVersion();
if (empty($version_data)) {
PMA_messagesSet(
'error',
$message_id,
__('Version check'),
__(
'Reading of version failed. '
. 'Maybe you\'re offline or the upgrade server does not respond.'
)
);
return;
}
$releases = $version_data->releases;
$latestCompatible = $versionInformation->getLatestCompatibleVersion($releases);
if ($latestCompatible != null) {
$version = $latestCompatible['version'];
$date = $latestCompatible['date'];
} else {
return;
}
$version_upstream = $versionInformation->versionToInt($version);
if ($version_upstream === false) {
PMA_messagesSet(
'error',
$message_id,
__('Version check'),
__('Got invalid version string from server')
);
return;
}
$version_local = $versionInformation->versionToInt(
$GLOBALS['PMA_Config']->get('PMA_VERSION')
);
if ($version_local === false) {
PMA_messagesSet(
'error',
$message_id,
__('Version check'),
__('Unparsable version string')
);
return;
}
if ($version_upstream > $version_local) {
$version = htmlspecialchars($version);
$date = htmlspecialchars($date);
PMA_messagesSet(
'notice',
$message_id,
__('Version check'),
sprintf(__('A newer version of phpMyAdmin is available and you should consider upgrading. The newest version is %s, released on %s.'), $version, $date)
);
} else {
if ($version_local % 100 == 0) {
PMA_messagesSet(
'notice',
$message_id,
__('Version check'),
PMA_sanitize(sprintf(__('You are using Git version, run [kbd]git pull[/kbd] :-)[br]The latest stable version is %s, released on %s.'), $version, $date))
);
} else {
PMA_messagesSet(
'notice',
$message_id,
__('Version check'),
__('No newer stable version is available')
);
}
}
}
/**
* Checks whether config file is readable/writable
*
* @param bool &$is_readable whether the file is readable
* @param bool &$is_writable whether the file is writable
* @param bool &$file_exists whether the file exists
*
* @return void
*/
function PMA_checkConfigRw(&$is_readable, &$is_writable, &$file_exists)
{
$file_path = $GLOBALS['ConfigFile']->getFilePath();
$file_dir = dirname($file_path);
$is_readable = true;
$is_writable = @is_dir($file_dir);
if (SETUP_DIR_WRITABLE) {
$is_writable = $is_writable && @is_writable($file_dir);
}
$file_exists = file_exists($file_path);
if ($file_exists) {
$is_readable = is_readable($file_path);
$is_writable = $is_writable && @is_writable($file_path);
}
}