Update website
This commit is contained in:
parent
0a686aeb9a
commit
c4ffa0f6ee
4360 changed files with 1727 additions and 718385 deletions
|
@ -1,228 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Config file generator
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Setup;
|
||||
|
||||
use PhpMyAdmin\Config\ConfigFile;
|
||||
use PhpMyAdmin\Version;
|
||||
|
||||
use function array_keys;
|
||||
use function count;
|
||||
use function gmdate;
|
||||
use function implode;
|
||||
use function is_array;
|
||||
use function is_string;
|
||||
use function mb_strlen;
|
||||
use function preg_replace;
|
||||
use function sodium_bin2hex;
|
||||
use function sodium_crypto_secretbox_keygen;
|
||||
use function sprintf;
|
||||
use function str_contains;
|
||||
use function strtr;
|
||||
use function var_export;
|
||||
|
||||
use const DATE_RFC1123;
|
||||
use const SODIUM_CRYPTO_SECRETBOX_KEYBYTES;
|
||||
|
||||
/**
|
||||
* Config file generation class
|
||||
*/
|
||||
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 '
|
||||
. Version::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_]/', '_', (string) $k);
|
||||
$ret .= self::getVarExport($k, $v, $crlf);
|
||||
if (! isset($persistKeys[$k])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($persistKeys[$k]);
|
||||
}
|
||||
|
||||
// keep 1d array keys which are present in $persist_keys (config.values.php)
|
||||
foreach (array_keys($persistKeys) as $k) {
|
||||
if (str_contains($k, '/')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
|
||||
$ret .= self::getVarExport($k, $cf->getDefault($k), $crlf);
|
||||
}
|
||||
|
||||
return $ret . $crlf;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ($var_name === 'blowfish_secret') {
|
||||
$secret = self::getBlowfishSecretKey($var_value);
|
||||
|
||||
return sprintf('$cfg[\'blowfish_secret\'] = \sodium_hex2bin(\'%s\');%s', sodium_bin2hex($secret), $crlf);
|
||||
}
|
||||
|
||||
if (! is_array($var_value) || empty($var_value)) {
|
||||
return "\$cfg['" . $var_name . "'] = "
|
||||
. var_export($var_value, true) . ';' . $crlf;
|
||||
}
|
||||
|
||||
if (self::isZeroBasedArray($var_value)) {
|
||||
return "\$cfg['" . $var_name . "'] = "
|
||||
. self::exportZeroBasedArray($var_value, $crlf)
|
||||
. ';' . $crlf;
|
||||
}
|
||||
|
||||
$ret = '';
|
||||
// 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
|
||||
*/
|
||||
private static function isZeroBasedArray(array $array): bool
|
||||
{
|
||||
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 = [];
|
||||
foreach ($array as $v) {
|
||||
$retv[] = var_export($v, true);
|
||||
}
|
||||
|
||||
$ret = '[';
|
||||
if (count($retv) <= 4) {
|
||||
// up to 4 values - one line
|
||||
return $ret . implode(', ', $retv) . ']';
|
||||
}
|
||||
|
||||
// more than 4 values - value per line
|
||||
$imax = count($retv);
|
||||
for ($i = 0; $i < $imax; $i++) {
|
||||
$ret .= ($i > 0 ? ',' : '') . $crlf . ' ' . $retv[$i];
|
||||
}
|
||||
|
||||
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|null
|
||||
*/
|
||||
protected static function getServerPart(ConfigFile $cf, $crlf, array $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_]/', '_', (string) $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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $key
|
||||
*
|
||||
* @psalm-return non-empty-string
|
||||
*/
|
||||
private static function getBlowfishSecretKey($key): string
|
||||
{
|
||||
if (is_string($key) && mb_strlen($key, '8bit') === SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
|
||||
return $key;
|
||||
}
|
||||
|
||||
return sodium_crypto_secretbox_keygen();
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Formset processing library
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Setup;
|
||||
|
||||
use PhpMyAdmin\Config\FormDisplay;
|
||||
use PhpMyAdmin\ResponseRenderer;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
|
||||
use function in_array;
|
||||
use function is_numeric;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\Setup\FormProcessing class
|
||||
*/
|
||||
class FormProcessing
|
||||
{
|
||||
/**
|
||||
* Processes forms registered in $form_display, handles error correction
|
||||
*
|
||||
* @param FormDisplay $form_display Form to display
|
||||
*/
|
||||
public static function process(FormDisplay $form_display): void
|
||||
{
|
||||
if (isset($_GET['mode']) && $_GET['mode'] === 'revert') {
|
||||
// revert erroneous fields to their default values
|
||||
$form_display->fixErrors();
|
||||
$response = ResponseRenderer::getInstance();
|
||||
$response->disable();
|
||||
$response->generateHeader303('index.php' . Url::getCommonRaw());
|
||||
}
|
||||
|
||||
if (! $form_display->process(false)) {
|
||||
// handle form view and failed POST
|
||||
echo $form_display->getDisplay();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// check for form errors
|
||||
if (! $form_display->hasErrors()) {
|
||||
$response = ResponseRenderer::getInstance();
|
||||
$response->disable();
|
||||
$response->generateHeader303('index.php' . Url::getCommonRaw());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// form has errors, show warning
|
||||
$page = 'index';
|
||||
if (isset($_GET['page']) && in_array($_GET['page'], ['form', 'config', 'servers'], true)) {
|
||||
$page = $_GET['page'];
|
||||
}
|
||||
|
||||
$formset = isset($_GET['formset']) && is_string($_GET['formset']) ? $_GET['formset'] : '';
|
||||
$formId = isset($_GET['id']) && is_numeric($_GET['id']) && (int) $_GET['id'] >= 1 ? (int) $_GET['id'] : 0;
|
||||
if ($formId === 0 && $page === 'servers') {
|
||||
// we've just added a new server, get its id
|
||||
$formId = $form_display->getConfigFile()->getServerCount();
|
||||
}
|
||||
|
||||
$urlParams = [
|
||||
'page' => $page,
|
||||
'formset' => $formset,
|
||||
'id' => $formId,
|
||||
];
|
||||
|
||||
$template = new Template();
|
||||
echo $template->render('setup/error', [
|
||||
'url_params' => $urlParams,
|
||||
'errors' => $form_display->displayErrors(),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -1,199 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Various checks and message functions used on index page.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Setup;
|
||||
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\Version;
|
||||
use PhpMyAdmin\VersionInformation;
|
||||
|
||||
use function __;
|
||||
use function htmlspecialchars;
|
||||
use function is_array;
|
||||
use function sprintf;
|
||||
use function uniqid;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\Setup\Index class
|
||||
*
|
||||
* Various checks and message functions used on index page.
|
||||
*/
|
||||
class Index
|
||||
{
|
||||
/**
|
||||
* Initializes message list
|
||||
*/
|
||||
public static function messagesBegin(): void
|
||||
{
|
||||
if (! isset($_SESSION['messages']) || ! is_array($_SESSION['messages'])) {
|
||||
$_SESSION['messages'] = [
|
||||
'error' => [],
|
||||
'notice' => [],
|
||||
];
|
||||
} 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
|
||||
*/
|
||||
public static function messagesSet($type, $msgId, $title, $message): void
|
||||
{
|
||||
$fresh = ! isset($_SESSION['messages'][$type][$msgId]);
|
||||
$_SESSION['messages'][$type][$msgId] = [
|
||||
'fresh' => $fresh,
|
||||
'active' => true,
|
||||
'title' => $title,
|
||||
'message' => $message,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up message list
|
||||
*/
|
||||
public static function messagesEnd(): void
|
||||
{
|
||||
foreach ($_SESSION['messages'] as &$messages) {
|
||||
$remove_ids = [];
|
||||
foreach ($messages as $id => $msg) {
|
||||
if ($msg['active'] != false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$remove_ids[] = $id;
|
||||
}
|
||||
|
||||
foreach ($remove_ids as $id) {
|
||||
unset($messages[$id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints message list, must be called after self::messagesEnd()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function messagesShowHtml()
|
||||
{
|
||||
$return = [];
|
||||
foreach ($_SESSION['messages'] as $type => $messages) {
|
||||
foreach ($messages as $id => $msg) {
|
||||
$return[] = [
|
||||
'id' => $id,
|
||||
'title' => $msg['title'],
|
||||
'type' => $type,
|
||||
'message' => $msg['message'],
|
||||
'is_hidden' => ! $msg['fresh'] && $type !== 'error',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for newest phpMyAdmin version and sets result as a new notice
|
||||
*/
|
||||
public static function versionCheck(): void
|
||||
{
|
||||
// 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)) {
|
||||
self::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) {
|
||||
return;
|
||||
}
|
||||
|
||||
$version = $latestCompatible['version'];
|
||||
$date = $latestCompatible['date'];
|
||||
|
||||
$version_upstream = $versionInformation->versionToInt($version);
|
||||
if ($version_upstream === false) {
|
||||
self::messagesSet(
|
||||
'error',
|
||||
$message_id,
|
||||
__('Version check'),
|
||||
__('Got invalid version string from server')
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$version_local = $versionInformation->versionToInt(Version::VERSION);
|
||||
if ($version_local === false) {
|
||||
self::messagesSet(
|
||||
'error',
|
||||
$message_id,
|
||||
__('Version check'),
|
||||
__('Unparsable version string')
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($version_upstream > $version_local) {
|
||||
$version = htmlspecialchars($version);
|
||||
$date = htmlspecialchars($date);
|
||||
self::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) {
|
||||
self::messagesSet(
|
||||
'notice',
|
||||
$message_id,
|
||||
__('Version check'),
|
||||
Sanitize::sanitizeMessage(sprintf(__('You are using Git version, run [kbd]git pull[/kbd]'
|
||||
. ' :-)[br]The latest stable version is %s, released on %s.'), $version, $date))
|
||||
);
|
||||
} else {
|
||||
self::messagesSet(
|
||||
'notice',
|
||||
$message_id,
|
||||
__('Version check'),
|
||||
__('No newer stable version is available')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue