Merge pull request #13685 from mauriciofauth/functions
Refactor function calls to static method calls
This commit is contained in:
commit
d7309f50bc
@ -17,7 +17,7 @@ phpMyAdmin - ChangeLog
|
||||
- issue #13269 Small refactoring in preparation to CSP
|
||||
- issue #13384 Database link broken in Databases Page
|
||||
- issue #13391 Configurable authentication logging using $cfg['AuthLog']
|
||||
- issue #13086 Add support for Goole Invisible Captcha
|
||||
- issue #13086 Add support for Google Invisible Captcha
|
||||
- issue #13058 Improved error reporting for reCAPTCHA
|
||||
- issue #12899 Improved rendering of server variables table
|
||||
- issue #12948 Fixed javascript editor for TIME values
|
||||
@ -34,6 +34,7 @@ phpMyAdmin - ChangeLog
|
||||
- issue #5827 Allow Designer to show tables from other databases
|
||||
- issue #13268 Replace Query-By-Example with multi-table query generator interface
|
||||
- issue #13576 Add privileges export to per database listing
|
||||
- issue Consolidate functions into class files
|
||||
|
||||
4.7.5 (not yet released)
|
||||
- issue #13615 Avoid problems with browsing unknown query types
|
||||
|
||||
@ -379,7 +379,7 @@ function getFieldValidators(field_id, onKeyUpOnly)
|
||||
* Displays errors for given form fields
|
||||
*
|
||||
* WARNING: created DOM elements must be identical with the ones made by
|
||||
* display_input() in FormDisplay.tpl.php!
|
||||
* PhpMyAdmin\Config\FormDisplayTemplate::displayInput()!
|
||||
*
|
||||
* @param {Object} error_list list of errors in the form {field id: error array}
|
||||
*/
|
||||
|
||||
@ -10,6 +10,7 @@ namespace PhpMyAdmin;
|
||||
|
||||
use Exception;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\SysInfo;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||
@ -209,8 +210,7 @@ class Advisor
|
||||
);
|
||||
|
||||
// Add total memory to variables as well
|
||||
include_once 'libraries/sysinfo.lib.php';
|
||||
$sysinfo = PMA_getSysInfo();
|
||||
$sysinfo = SysInfo::get();
|
||||
$memory = $sysinfo->memory();
|
||||
$this->variables['system_memory']
|
||||
= isset($memory['MemTotal']) ? $memory['MemTotal'] : 0;
|
||||
|
||||
@ -17,13 +17,12 @@ namespace PhpMyAdmin\Config;
|
||||
use PhpMyAdmin\Config\ConfigFile;
|
||||
use PhpMyAdmin\Config\Descriptions;
|
||||
use PhpMyAdmin\Config\Form;
|
||||
use PhpMyAdmin\Config\FormDisplayTemplate;
|
||||
use PhpMyAdmin\Config\Forms\User\UserFormList;
|
||||
use PhpMyAdmin\Config\Validator;
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
require_once './libraries/config/FormDisplay.tpl.php';
|
||||
|
||||
/**
|
||||
* Form management class, displays and processes forms
|
||||
*
|
||||
@ -230,7 +229,7 @@ class FormDisplay
|
||||
/* @var $form Form */
|
||||
$form_errors = isset($this->_errors[$form->name])
|
||||
? $this->_errors[$form->name] : null;
|
||||
$htmlOutput .= PMA_displayFieldsetTop(
|
||||
$htmlOutput .= FormDisplayTemplate::displayFieldsetTop(
|
||||
Descriptions::get("Form_{$form->name}"),
|
||||
Descriptions::get("Form_{$form->name}", 'desc'),
|
||||
$form_errors,
|
||||
@ -258,10 +257,10 @@ class FormDisplay
|
||||
);
|
||||
// register JS validators for this field
|
||||
if (isset($validators[$path])) {
|
||||
PMA_addJsValidate($translated_path, $validators[$path], $js);
|
||||
FormDisplayTemplate::addJsValidate($translated_path, $validators[$path], $js);
|
||||
}
|
||||
}
|
||||
$htmlOutput .= PMA_displayFieldsetBottom($show_buttons);
|
||||
$htmlOutput .= FormDisplayTemplate::displayFieldsetBottom($show_buttons);
|
||||
}
|
||||
return $htmlOutput;
|
||||
}
|
||||
@ -293,14 +292,14 @@ class FormDisplay
|
||||
$js = array();
|
||||
$js_default = array();
|
||||
|
||||
$htmlOutput .= PMA_displayFormTop($form_action, 'post', $hidden_fields);
|
||||
$htmlOutput .= FormDisplayTemplate::displayFormTop($form_action, 'post', $hidden_fields);
|
||||
|
||||
if ($tabbed_form) {
|
||||
$tabs = array();
|
||||
foreach ($this->_forms as $form) {
|
||||
$tabs[$form->name] = Descriptions::get("Form_$form->name");
|
||||
}
|
||||
$htmlOutput .= PMA_displayTabsTop($tabs);
|
||||
$htmlOutput .= FormDisplayTemplate::displayTabsTop($tabs);
|
||||
}
|
||||
|
||||
// validate only when we aren't displaying a "new server" form
|
||||
@ -325,9 +324,9 @@ class FormDisplay
|
||||
);
|
||||
|
||||
if ($tabbed_form) {
|
||||
$htmlOutput .= PMA_displayTabsBottom();
|
||||
$htmlOutput .= FormDisplayTemplate::displayTabsBottom();
|
||||
}
|
||||
$htmlOutput .= PMA_displayFormBottom();
|
||||
$htmlOutput .= FormDisplayTemplate::displayFormBottom();
|
||||
|
||||
// if not already done, send strings used for validation to JavaScript
|
||||
if (! $js_lang_sent) {
|
||||
@ -342,7 +341,7 @@ class FormDisplay
|
||||
|
||||
$js[] = "$.extend(defaultValues, {\n\t"
|
||||
. implode(",\n\t", $js_default) . '})';
|
||||
$htmlOutput .= PMA_displayJavascript($js);
|
||||
$htmlOutput .= FormDisplayTemplate::displayJavascript($js);
|
||||
|
||||
return $htmlOutput;
|
||||
}
|
||||
@ -423,11 +422,11 @@ class FormDisplay
|
||||
// :group:end is changed to :group:end:{unique id} in Form class
|
||||
$htmlOutput = '';
|
||||
if (mb_substr($field, 7, 4) != 'end:') {
|
||||
$htmlOutput .= PMA_displayGroupHeader(
|
||||
$htmlOutput .= FormDisplayTemplate::displayGroupHeader(
|
||||
mb_substr($field, 7)
|
||||
);
|
||||
} else {
|
||||
PMA_displayGroupFooter();
|
||||
FormDisplayTemplate::displayGroupFooter();
|
||||
}
|
||||
return $htmlOutput;
|
||||
case 'NULL':
|
||||
@ -479,7 +478,7 @@ class FormDisplay
|
||||
}
|
||||
$js_default[] = $js_line;
|
||||
|
||||
return PMA_displayInput(
|
||||
return FormDisplayTemplate::displayInput(
|
||||
$translated_path, $name, $type, $value,
|
||||
$description, $value_is_default, $opts
|
||||
);
|
||||
@ -505,7 +504,7 @@ class FormDisplay
|
||||
} else {
|
||||
$name = Descriptions::get('Form_' . $system_path);
|
||||
}
|
||||
$htmlOutput .= PMA_displayErrors($name, $error_list);
|
||||
$htmlOutput .= FormDisplayTemplate::displayErrors($name, $error_list);
|
||||
}
|
||||
|
||||
return $htmlOutput;
|
||||
|
||||
536
libraries/classes/Config/FormDisplayTemplate.php
Normal file
536
libraries/classes/Config/FormDisplayTemplate.php
Normal file
@ -0,0 +1,536 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Form templates
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PhpMyAdmin\Config;
|
||||
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\Config\FormDisplayTemplate class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class FormDisplayTemplate
|
||||
{
|
||||
/**
|
||||
* Displays top part of the form
|
||||
*
|
||||
* @param string $action default: $_SERVER['REQUEST_URI']
|
||||
* @param string $method 'post' or 'get'
|
||||
* @param array $hidden_fields array of form hidden fields (key: field name)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function displayFormTop($action = null, $method = 'post', $hidden_fields = null)
|
||||
{
|
||||
static $has_check_page_refresh = false;
|
||||
|
||||
if ($action === null) {
|
||||
$action = $_SERVER['REQUEST_URI'];
|
||||
}
|
||||
if ($method != 'post') {
|
||||
$method = 'get';
|
||||
}
|
||||
$htmlOutput = '<form method="' . $method . '" action="'
|
||||
. htmlspecialchars($action) . '" class="config-form disableAjax">';
|
||||
$htmlOutput .= '<input type="hidden" name="tab_hash" value="" />';
|
||||
// we do validation on page refresh when browser remembers field values,
|
||||
// add a field with known value which will be used for checks
|
||||
if (! $has_check_page_refresh) {
|
||||
$has_check_page_refresh = true;
|
||||
$htmlOutput .= '<input type="hidden" name="check_page_refresh" '
|
||||
. ' id="check_page_refresh" value="" />' . "\n";
|
||||
}
|
||||
$htmlOutput .= Url::getHiddenInputs('', '', 0, 'server') . "\n";
|
||||
$htmlOutput .= Url::getHiddenFields((array)$hidden_fields);
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays form tabs which are given by an array indexed by fieldset id
|
||||
* ({@link self::displayFieldsetTop}), with values being tab titles.
|
||||
*
|
||||
* @param array $tabs tab names
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function displayTabsTop($tabs)
|
||||
{
|
||||
$items = array();
|
||||
foreach ($tabs as $tab_id => $tab_name) {
|
||||
$items[] = array(
|
||||
'content' => htmlspecialchars($tab_name),
|
||||
'url' => array(
|
||||
'href' => '#' . $tab_id,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$htmlOutput = Template::get('list/unordered')->render(
|
||||
array(
|
||||
'class' => 'tabs responsivetable',
|
||||
'items' => $items,
|
||||
)
|
||||
);
|
||||
$htmlOutput .= '<br />';
|
||||
$htmlOutput .= '<div class="tabs_contents">';
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays top part of a fieldset
|
||||
*
|
||||
* @param string $title title of fieldset
|
||||
* @param string $description description shown on top of fieldset
|
||||
* @param array $errors error messages to display
|
||||
* @param array $attributes optional extra attributes of fieldset
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function displayFieldsetTop($title = '', $description = '', $errors = null,
|
||||
$attributes = array()
|
||||
) {
|
||||
global $_FormDisplayGroup;
|
||||
|
||||
$_FormDisplayGroup = 0;
|
||||
|
||||
$attributes = array_merge(array('class' => 'optbox'), $attributes);
|
||||
foreach ($attributes as $k => &$attr) {
|
||||
$attr = $k . '="' . htmlspecialchars($attr) . '"';
|
||||
}
|
||||
|
||||
$htmlOutput = '<fieldset ' . implode(' ', $attributes) . '>';
|
||||
$htmlOutput .= '<legend>' . $title . '</legend>';
|
||||
if (!empty($description)) {
|
||||
$htmlOutput .= '<p>' . $description . '</p>';
|
||||
}
|
||||
// this must match with displayErrors() in scripts.js
|
||||
if (is_array($errors) && count($errors) > 0) {
|
||||
$htmlOutput .= '<dl class="errors">';
|
||||
foreach ($errors as $error) {
|
||||
$htmlOutput .= '<dd>' . $error . '</dd>';
|
||||
}
|
||||
$htmlOutput .= '</dl>';
|
||||
}
|
||||
$htmlOutput .= '<table width="100%" cellspacing="0">';
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays input field
|
||||
*
|
||||
* $opts keys:
|
||||
* o doc - (string) documentation link
|
||||
* o errors - error array
|
||||
* o setvalue - (string) shows button allowing to set predefined value
|
||||
* o show_restore_default - (boolean) whether show "restore default" button
|
||||
* o userprefs_allow - whether user preferences are enabled for this field
|
||||
* (null - no support, true/false - enabled/disabled)
|
||||
* o userprefs_comment - (string) field comment
|
||||
* o values - key - value pairs for <select> fields
|
||||
* o values_escaped - (boolean) tells whether values array is already escaped
|
||||
* (defaults to false)
|
||||
* o values_disabled - (array)list of disabled values (keys from values)
|
||||
* o comment - (string) tooltip comment
|
||||
* o comment_warning - (bool) whether this comments warns about something
|
||||
*
|
||||
* @param string $path config option path
|
||||
* @param string $name config option name
|
||||
* @param string $type type of config option
|
||||
* @param mixed $value current value
|
||||
* @param string $description verbose description
|
||||
* @param bool $value_is_default whether value is default
|
||||
* @param array $opts see above description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function displayInput($path, $name, $type, $value, $description = '',
|
||||
$value_is_default = true, $opts = null
|
||||
) {
|
||||
global $_FormDisplayGroup;
|
||||
static $icons; // An array of IMG tags used further below in the function
|
||||
|
||||
if (defined('TESTSUITE')) {
|
||||
$icons = null;
|
||||
}
|
||||
|
||||
$is_setup_script = $GLOBALS['PMA_Config']->get('is_setup');
|
||||
if ($icons === null) { // if the static variables have not been initialised
|
||||
$icons = array();
|
||||
// Icon definitions:
|
||||
// The same indexes will be used in the $icons array.
|
||||
// The first element contains the filename and the second
|
||||
// element is used for the "alt" and "title" attributes.
|
||||
$icon_init = array(
|
||||
'edit' => array('b_edit.png', ''),
|
||||
'help' => array('b_help.png', __('Documentation')),
|
||||
'reload' => array('s_reload.png', ''),
|
||||
'tblops' => array('b_tblops.png', '')
|
||||
);
|
||||
if ($is_setup_script) {
|
||||
// When called from the setup script, we don't have access to the
|
||||
// sprite-aware getImage() function because the PMA_theme class
|
||||
// has not been loaded, so we generate the img tags manually.
|
||||
foreach ($icon_init as $k => $v) {
|
||||
$title = '';
|
||||
if (! empty($v[1])) {
|
||||
$title = ' title="' . $v[1] . '"';
|
||||
}
|
||||
$icons[$k] = sprintf(
|
||||
'<img alt="%s" src="%s"%s />',
|
||||
$v[1],
|
||||
"../themes/original/img/{$v[0]}",
|
||||
$title
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// In this case we just use getImage() because it's available
|
||||
foreach ($icon_init as $k => $v) {
|
||||
$icons[$k] = Util::getImage(
|
||||
$v[0], $v[1]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$has_errors = isset($opts['errors']) && !empty($opts['errors']);
|
||||
$option_is_disabled = ! $is_setup_script && isset($opts['userprefs_allow'])
|
||||
&& ! $opts['userprefs_allow'];
|
||||
$name_id = 'name="' . htmlspecialchars($path) . '" id="'
|
||||
. htmlspecialchars($path) . '"';
|
||||
$field_class = $type == 'checkbox' ? 'checkbox' : '';
|
||||
if (! $value_is_default) {
|
||||
$field_class .= ($field_class == '' ? '' : ' ')
|
||||
. ($has_errors ? 'custom field-error' : 'custom');
|
||||
}
|
||||
$field_class = $field_class ? ' class="' . $field_class . '"' : '';
|
||||
$tr_class = $_FormDisplayGroup > 0
|
||||
? 'group-field group-field-' . $_FormDisplayGroup
|
||||
: '';
|
||||
if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') {
|
||||
unset($opts['setvalue']);
|
||||
$_FormDisplayGroup++;
|
||||
$tr_class = 'group-header-field group-header-' . $_FormDisplayGroup;
|
||||
}
|
||||
if ($option_is_disabled) {
|
||||
$tr_class .= ($tr_class ? ' ' : '') . 'disabled-field';
|
||||
}
|
||||
$tr_class = $tr_class ? ' class="' . $tr_class . '"' : '';
|
||||
|
||||
$htmlOutput = '<tr' . $tr_class . '>';
|
||||
$htmlOutput .= '<th>';
|
||||
$htmlOutput .= '<label for="' . htmlspecialchars($path) . '">' . $name
|
||||
. '</label>';
|
||||
|
||||
if (! empty($opts['doc'])) {
|
||||
$htmlOutput .= '<span class="doc">';
|
||||
$htmlOutput .= '<a href="' . $opts['doc']
|
||||
. '" target="documentation">' . $icons['help'] . '</a>';
|
||||
$htmlOutput .= "\n";
|
||||
$htmlOutput .= '</span>';
|
||||
}
|
||||
|
||||
if ($option_is_disabled) {
|
||||
$htmlOutput .= '<span class="disabled-notice" title="';
|
||||
$htmlOutput .= __(
|
||||
'This setting is disabled, it will not be applied to your configuration.'
|
||||
);
|
||||
$htmlOutput .= '">' . __('Disabled') . "</span>";
|
||||
}
|
||||
|
||||
if (!empty($description)) {
|
||||
$htmlOutput .= '<small>' . $description . '</small>';
|
||||
}
|
||||
|
||||
$htmlOutput .= '</th>';
|
||||
$htmlOutput .= '<td>';
|
||||
|
||||
switch ($type) {
|
||||
case 'text':
|
||||
$htmlOutput .= '<input type="text" class="all85" ' . $name_id . $field_class
|
||||
. ' value="' . htmlspecialchars($value) . '" />';
|
||||
break;
|
||||
case 'password':
|
||||
$htmlOutput .= '<input type="password" class="all85" ' . $name_id . $field_class
|
||||
. ' value="' . htmlspecialchars($value) . '" />';
|
||||
break;
|
||||
case 'short_text':
|
||||
// As seen in the reporting server (#15042) we sometimes receive
|
||||
// an array here. No clue about its origin nor content, so let's avoid
|
||||
// a notice on htmlspecialchars().
|
||||
if (! is_array($value)) {
|
||||
$htmlOutput .= '<input type="text" size="25" ' . $name_id
|
||||
. $field_class . ' value="' . htmlspecialchars($value)
|
||||
. '" />';
|
||||
}
|
||||
break;
|
||||
case 'number_text':
|
||||
$htmlOutput .= '<input type="number" ' . $name_id . $field_class
|
||||
. ' value="' . htmlspecialchars($value) . '" />';
|
||||
break;
|
||||
case 'checkbox':
|
||||
$htmlOutput .= '<span' . $field_class . '><input type="checkbox" ' . $name_id
|
||||
. ($value ? ' checked="checked"' : '') . ' /></span>';
|
||||
break;
|
||||
case 'select':
|
||||
$htmlOutput .= '<select class="all85" ' . $name_id . $field_class . '>';
|
||||
$escape = !(isset($opts['values_escaped']) && $opts['values_escaped']);
|
||||
$values_disabled = isset($opts['values_disabled'])
|
||||
? array_flip($opts['values_disabled']) : array();
|
||||
foreach ($opts['values'] as $opt_value_key => $opt_value) {
|
||||
// set names for boolean values
|
||||
if (is_bool($opt_value)) {
|
||||
$opt_value = mb_strtolower(
|
||||
$opt_value ? __('Yes') : __('No')
|
||||
);
|
||||
}
|
||||
// escape if necessary
|
||||
if ($escape) {
|
||||
$display = htmlspecialchars($opt_value);
|
||||
$display_value = htmlspecialchars($opt_value_key);
|
||||
} else {
|
||||
$display = $opt_value;
|
||||
$display_value = $opt_value_key;
|
||||
}
|
||||
// compare with selected value
|
||||
// boolean values are cast to integers when used as array keys
|
||||
$selected = is_bool($value)
|
||||
? (int) $value === $opt_value_key
|
||||
: $opt_value_key === $value;
|
||||
$htmlOutput .= '<option value="' . $display_value . '"';
|
||||
if ($selected) {
|
||||
$htmlOutput .= ' selected="selected"';
|
||||
}
|
||||
if (isset($values_disabled[$opt_value_key])) {
|
||||
$htmlOutput .= ' disabled="disabled"';
|
||||
}
|
||||
$htmlOutput .= '>' . $display . '</option>';
|
||||
}
|
||||
$htmlOutput .= '</select>';
|
||||
break;
|
||||
case 'list':
|
||||
$htmlOutput .= '<textarea cols="35" rows="5" ' . $name_id . $field_class
|
||||
. '>' . htmlspecialchars(implode("\n", $value)) . '</textarea>';
|
||||
break;
|
||||
}
|
||||
if (isset($opts['comment']) && $opts['comment']) {
|
||||
$class = 'field-comment-mark';
|
||||
if (isset($opts['comment_warning']) && $opts['comment_warning']) {
|
||||
$class .= ' field-comment-warning';
|
||||
}
|
||||
$htmlOutput .= '<span class="' . $class . '" title="'
|
||||
. htmlspecialchars($opts['comment']) . '">i</span>';
|
||||
}
|
||||
if ($is_setup_script
|
||||
&& isset($opts['userprefs_comment'])
|
||||
&& $opts['userprefs_comment']
|
||||
) {
|
||||
$htmlOutput .= '<a class="userprefs-comment" title="'
|
||||
. htmlspecialchars($opts['userprefs_comment']) . '">'
|
||||
. $icons['tblops'] . '</a>';
|
||||
}
|
||||
if (isset($opts['setvalue']) && $opts['setvalue']) {
|
||||
$htmlOutput .= '<a class="set-value hide" href="#'
|
||||
. htmlspecialchars("$path={$opts['setvalue']}") . '" title="'
|
||||
. sprintf(__('Set value: %s'), htmlspecialchars($opts['setvalue']))
|
||||
. '">' . $icons['edit'] . '</a>';
|
||||
}
|
||||
if (isset($opts['show_restore_default']) && $opts['show_restore_default']) {
|
||||
$htmlOutput .= '<a class="restore-default hide" href="#' . $path . '" title="'
|
||||
. __('Restore default value') . '">' . $icons['reload'] . '</a>';
|
||||
}
|
||||
// this must match with displayErrors() in scripts/config.js
|
||||
if ($has_errors) {
|
||||
$htmlOutput .= "\n <dl class=\"inline_errors\">";
|
||||
foreach ($opts['errors'] as $error) {
|
||||
$htmlOutput .= '<dd>' . htmlspecialchars($error) . '</dd>';
|
||||
}
|
||||
$htmlOutput .= '</dl>';
|
||||
}
|
||||
$htmlOutput .= '</td>';
|
||||
if ($is_setup_script && isset($opts['userprefs_allow'])) {
|
||||
$htmlOutput .= '<td class="userprefs-allow" title="' .
|
||||
__('Allow users to customize this value') . '">';
|
||||
$htmlOutput .= '<input type="checkbox" name="' . $path
|
||||
. '-userprefs-allow" ';
|
||||
if ($opts['userprefs_allow']) {
|
||||
$htmlOutput .= 'checked="checked"';
|
||||
};
|
||||
$htmlOutput .= '/>';
|
||||
$htmlOutput .= '</td>';
|
||||
} else if ($is_setup_script) {
|
||||
$htmlOutput .= '<td> </td>';
|
||||
}
|
||||
$htmlOutput .= '</tr>';
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display group header
|
||||
*
|
||||
* @param string $header_text Text of header
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public static function displayGroupHeader($header_text)
|
||||
{
|
||||
global $_FormDisplayGroup;
|
||||
|
||||
$_FormDisplayGroup++;
|
||||
if (! $header_text) {
|
||||
return null;
|
||||
}
|
||||
$colspan = $GLOBALS['PMA_Config']->get('is_setup')
|
||||
? 3
|
||||
: 2;
|
||||
$htmlOutput = '<tr class="group-header group-header-' . $_FormDisplayGroup
|
||||
. '">';
|
||||
$htmlOutput .= '<th colspan="' . $colspan . '">';
|
||||
$htmlOutput .= $header_text;
|
||||
$htmlOutput .= '</th>';
|
||||
$htmlOutput .= '</tr>';
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display group footer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function displayGroupFooter()
|
||||
{
|
||||
global $_FormDisplayGroup;
|
||||
|
||||
$_FormDisplayGroup--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays bottom part of a fieldset
|
||||
*
|
||||
* @param bool $show_buttons whether show submit and reset button
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function displayFieldsetBottom($show_buttons = true)
|
||||
{
|
||||
$colspan = 2;
|
||||
if ($GLOBALS['PMA_Config']->get('is_setup')) {
|
||||
$colspan++;
|
||||
}
|
||||
$htmlOutput = '';
|
||||
if ($show_buttons) {
|
||||
$htmlOutput .= '<tr>';
|
||||
$htmlOutput .= '<td colspan="' . $colspan . '" class="lastrow">';
|
||||
$htmlOutput .= '<input type="submit" name="submit_save" value="'
|
||||
. __('Apply') . '" class="green" />';
|
||||
$htmlOutput .= '<input type="button" name="submit_reset" value="'
|
||||
. __('Reset') . '" />';
|
||||
$htmlOutput .= '</td>';
|
||||
$htmlOutput .= '</tr>';
|
||||
}
|
||||
$htmlOutput .= '</table>';
|
||||
$htmlOutput .= '</fieldset>';
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays simple bottom part of a fieldset (without submit buttons)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function displayFieldsetBottomSimple()
|
||||
{
|
||||
$htmlOutput = '</table>';
|
||||
$htmlOutput .= '</fieldset>';
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes form tabs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function displayTabsBottom()
|
||||
{
|
||||
$htmlOutput = "</div>\n";
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays bottom part of the form
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function displayFormBottom()
|
||||
{
|
||||
$htmlOutput = "</form>\n";
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends JS validation code to $js_array
|
||||
*
|
||||
* @param string $field_id ID of field to validate
|
||||
* @param string|array $validators validators callback
|
||||
* @param array &$js_array will be updated with javascript code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function addJsValidate($field_id, $validators, &$js_array)
|
||||
{
|
||||
foreach ((array)$validators as $validator) {
|
||||
$validator = (array)$validator;
|
||||
$v_name = array_shift($validator);
|
||||
$v_name = "PMA_" . $v_name;
|
||||
$v_args = array();
|
||||
foreach ($validator as $arg) {
|
||||
$v_args[] = Sanitize::escapeJsString($arg);
|
||||
}
|
||||
$v_args = $v_args ? ", ['" . implode("', '", $v_args) . "']" : '';
|
||||
$js_array[] = "validateField('$field_id', '$v_name', true$v_args)";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays JavaScript code
|
||||
*
|
||||
* @param array $js_array lines of javascript code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function displayJavascript($js_array)
|
||||
{
|
||||
if (empty($js_array)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Template::get('javascript/display')->render(
|
||||
array('js_array' => $js_array,)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays error list
|
||||
*
|
||||
* @param string $name name of item with errors
|
||||
* @param array $error_list list of errors to show
|
||||
*
|
||||
* @return string HTML for errors
|
||||
*/
|
||||
public static function displayErrors($name, $error_list)
|
||||
{
|
||||
$htmlOutput = '<dl>';
|
||||
$htmlOutput .= '<dt>' . htmlspecialchars($name) . '</dt>';
|
||||
foreach ($error_list as $error) {
|
||||
$htmlOutput .= '<dd>' . htmlspecialchars($error) . '</dd>';
|
||||
}
|
||||
$htmlOutput .= '</dl>';
|
||||
return $htmlOutput;
|
||||
}
|
||||
}
|
||||
@ -11,14 +11,15 @@ use PhpMyAdmin\Config\ConfigFile;
|
||||
use PhpMyAdmin\Config\Descriptions;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\Setup\Index as SetupIndex;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* Performs various compatibility, security and consistency checks on current config
|
||||
*
|
||||
* Outputs results to message list, must be called between PMA_messagesBegin()
|
||||
* and PMA_messagesEnd()
|
||||
* Outputs results to message list, must be called between SetupIndex::messagesBegin()
|
||||
* and SetupIndex::messagesEnd()
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
@ -81,7 +82,7 @@ class ServerConfigChecks
|
||||
'[a@' . Url::getCommon(array('page' => 'form', 'formset' => 'Features')) . '#tab_Security]',
|
||||
'[/a]'
|
||||
);
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'notice',
|
||||
'AllowArbitraryServer',
|
||||
Descriptions::get('AllowArbitraryServer'),
|
||||
@ -102,7 +103,7 @@ class ServerConfigChecks
|
||||
// should not be world-accessible
|
||||
//
|
||||
if ($this->cfg->getValue('SaveDir') != '') {
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'notice',
|
||||
'SaveDir',
|
||||
Descriptions::get('SaveDir'),
|
||||
@ -115,7 +116,7 @@ class ServerConfigChecks
|
||||
// should not be world-accessible
|
||||
//
|
||||
if ($this->cfg->getValue('TempDir') != '') {
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'notice',
|
||||
'TempDir',
|
||||
Descriptions::get('TempDir'),
|
||||
@ -160,7 +161,7 @@ class ServerConfigChecks
|
||||
//
|
||||
if (!$this->cfg->getValue("Servers/$i/ssl")) {
|
||||
$title = Descriptions::get('Servers/1/ssl') . " ($serverName)";
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'notice',
|
||||
"Servers/$i/ssl",
|
||||
$title,
|
||||
@ -193,7 +194,7 @@ class ServerConfigChecks
|
||||
) {
|
||||
$title = Descriptions::get('Servers/1/auth_type')
|
||||
. " ($serverName)";
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'notice',
|
||||
"Servers/$i/auth_type",
|
||||
$title,
|
||||
@ -222,7 +223,7 @@ class ServerConfigChecks
|
||||
) {
|
||||
$title = Descriptions::get('Servers/1/AllowNoPassword')
|
||||
. " ($serverName)";
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'notice',
|
||||
"Servers/$i/AllowNoPassword",
|
||||
$title,
|
||||
@ -293,7 +294,7 @@ class ServerConfigChecks
|
||||
// requires zip_open in import
|
||||
//
|
||||
if ($this->cfg->getValue('ZipDump') && !$this->functionExists('zip_open')) {
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'error',
|
||||
'ZipDump_import',
|
||||
Descriptions::get('ZipDump'),
|
||||
@ -314,7 +315,7 @@ class ServerConfigChecks
|
||||
// requires gzcompress in export
|
||||
//
|
||||
if ($this->cfg->getValue('ZipDump') && !$this->functionExists('gzcompress')) {
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'error',
|
||||
'ZipDump_export',
|
||||
Descriptions::get('ZipDump'),
|
||||
@ -351,7 +352,7 @@ class ServerConfigChecks
|
||||
if ($cookieAuthUsed) {
|
||||
if ($blowfishSecretSet) {
|
||||
// 'cookie' auth used, blowfish_secret was generated
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'notice',
|
||||
'blowfish_secret_created',
|
||||
Descriptions::get('blowfish_secret'),
|
||||
@ -384,7 +385,7 @@ class ServerConfigChecks
|
||||
);
|
||||
}
|
||||
if (!empty($blowfishWarnings)) {
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'error',
|
||||
'blowfish_warnings' . count($blowfishWarnings),
|
||||
Descriptions::get('blowfish_secret'),
|
||||
@ -408,7 +409,7 @@ class ServerConfigChecks
|
||||
$loginCookieValidity = $this->cfg->getValue('LoginCookieValidity');
|
||||
if ($loginCookieValidity > ini_get('session.gc_maxlifetime')
|
||||
) {
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'error',
|
||||
'LoginCookieValidity',
|
||||
Descriptions::get('LoginCookieValidity'),
|
||||
@ -432,7 +433,7 @@ class ServerConfigChecks
|
||||
// should be at most 1800 (30 min)
|
||||
//
|
||||
if ($loginCookieValidity > 1800) {
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'notice',
|
||||
'LoginCookieValidity',
|
||||
Descriptions::get('LoginCookieValidity'),
|
||||
@ -456,7 +457,7 @@ class ServerConfigChecks
|
||||
if (($this->cfg->getValue('LoginCookieStore') != 0)
|
||||
&& ($loginCookieValidity > $this->cfg->getValue('LoginCookieStore'))
|
||||
) {
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'error',
|
||||
'LoginCookieValidity',
|
||||
Descriptions::get('LoginCookieValidity'),
|
||||
@ -495,7 +496,7 @@ class ServerConfigChecks
|
||||
$functions .= $this->functionExists('bzcompress')
|
||||
? ''
|
||||
: ($functions ? ', ' : '') . 'bzcompress';
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'error',
|
||||
'BZipDump',
|
||||
Descriptions::get('BZipDump'),
|
||||
@ -528,7 +529,7 @@ class ServerConfigChecks
|
||||
if ($this->cfg->getValue('GZipDump')
|
||||
&& (!$this->functionExists('gzopen') || !$this->functionExists('gzencode'))
|
||||
) {
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'error',
|
||||
'GZipDump',
|
||||
Descriptions::get('GZipDump'),
|
||||
|
||||
@ -3113,7 +3113,7 @@ class Results
|
||||
}
|
||||
|
||||
// Check for the predefined fields need to show as link in schemas
|
||||
include_once 'libraries/special_schema_links.lib.php';
|
||||
include_once 'libraries/special_schema_links.inc.php';
|
||||
|
||||
if (isset($GLOBALS['special_schema_links'])
|
||||
&& (! empty($GLOBALS['special_schema_links'][$dbLower][$tblLower][$nameLower]))
|
||||
|
||||
@ -7,8 +7,10 @@
|
||||
*/
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Encoding;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Plugins;
|
||||
use PhpMyAdmin\Plugins\ExportPlugin;
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\Table;
|
||||
@ -1046,4 +1048,41 @@ class Export
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get all the export options and verify
|
||||
* call and include the appropriate Schema Class depending on $export_type
|
||||
*
|
||||
* @param string $export_type format of the export
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function processExportSchema($export_type)
|
||||
{
|
||||
/**
|
||||
* default is PDF, otherwise validate it's only letters a-z
|
||||
*/
|
||||
if (! isset($export_type) || ! preg_match('/^[a-zA-Z]+$/', $export_type)) {
|
||||
$export_type = 'pdf';
|
||||
}
|
||||
|
||||
// sanitize this parameter which will be used below in a file inclusion
|
||||
$export_type = Core::securePath($export_type);
|
||||
|
||||
// get the specific plugin
|
||||
/* @var $export_plugin SchemaPlugin */
|
||||
$export_plugin = Plugins::getPlugin(
|
||||
"schema",
|
||||
$export_type,
|
||||
'libraries/classes/Plugins/Schema/'
|
||||
);
|
||||
|
||||
// Check schema export type
|
||||
if (! isset($export_plugin)) {
|
||||
Core::fatalError(__('Bad type!'));
|
||||
}
|
||||
|
||||
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
|
||||
$export_plugin->exportSchema($GLOBALS['db']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ class Sanitize
|
||||
'./tbl_select.php?',
|
||||
'./tbl_change.php?',
|
||||
'./sql.php?',
|
||||
# Hardcoded options in libraries/special_schema_links.lib.php
|
||||
# Hardcoded options in libraries/special_schema_links.inc.php
|
||||
'./db_events.php?',
|
||||
'./db_routines.php?',
|
||||
'./server_privileges.php?',
|
||||
|
||||
@ -11,10 +11,9 @@ namespace PhpMyAdmin\Server\Status;
|
||||
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\Server\Status\Data;
|
||||
use PhpMyAdmin\SysInfo;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
require_once 'libraries/sysinfo.lib.php';
|
||||
|
||||
class Monitor
|
||||
{
|
||||
/**
|
||||
@ -349,7 +348,7 @@ class Monitor
|
||||
$input = '<input type="hidden" name="%s" value="%s" />';
|
||||
$form = '<form id="js_data" class="hide">';
|
||||
$form .= sprintf($input, 'server_time', microtime(true) * 1000);
|
||||
$form .= sprintf($input, 'server_os', PMA_getSysInfoOs());
|
||||
$form .= sprintf($input, 'server_os', SysInfo::getOs());
|
||||
$form .= sprintf($input, 'is_superuser', $GLOBALS['dbi']->isSuperuser());
|
||||
$form .= sprintf($input, 'server_db_isLocal', $serverStatusData->db_isLocal);
|
||||
$form .= '</form>';
|
||||
@ -522,14 +521,13 @@ class Monitor
|
||||
|
||||
case 'cpu':
|
||||
if (!$sysinfo) {
|
||||
include_once 'libraries/sysinfo.lib.php';
|
||||
$sysinfo = PMA_getSysInfo();
|
||||
$sysinfo = SysInfo::get();
|
||||
}
|
||||
if (!$cpuload) {
|
||||
$cpuload = $sysinfo->loadavg();
|
||||
}
|
||||
|
||||
if (PMA_getSysInfoOs() == 'Linux') {
|
||||
if (SysInfo::getOs() == 'Linux') {
|
||||
$ret['idle'] = $cpuload['idle'];
|
||||
$ret['busy'] = $cpuload['busy'];
|
||||
} else {
|
||||
@ -540,8 +538,7 @@ class Monitor
|
||||
|
||||
case 'memory':
|
||||
if (!$sysinfo) {
|
||||
include_once 'libraries/sysinfo.lib.php';
|
||||
$sysinfo = PMA_getSysInfo();
|
||||
$sysinfo = SysInfo::get();
|
||||
}
|
||||
if (!$memory) {
|
||||
$memory = $sysinfo->memory();
|
||||
|
||||
@ -1,48 +1,64 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Hold PhpMyAdmin\SysInfo class
|
||||
* Library for extracting information about system memory and cpu.
|
||||
* Currently supports all Windows and Linux platforms
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
* This code is based on the OS Classes from the phpsysinfo project
|
||||
* (https://phpsysinfo.github.io/phpsysinfo/)
|
||||
*
|
||||
* @package PhpMyAdmin-sysinfo
|
||||
*/
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\SysInfoBase;
|
||||
|
||||
/**
|
||||
* Basic sysinfo class not providing any real data.
|
||||
* PhpMyAdmin\SysInfo class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class SysInfo
|
||||
{
|
||||
public $os = PHP_OS;
|
||||
const MEMORY_REGEXP = '/^(MemTotal|MemFree|Cached|Buffers|SwapCached|SwapTotal|SwapFree):\s+(.*)\s*kB/im';
|
||||
|
||||
/**
|
||||
* Gets load information
|
||||
* Returns OS type used for sysinfo class
|
||||
*
|
||||
* @return array with load data
|
||||
* @param string $php_os PHP_OS constant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function loadavg()
|
||||
public static function getOs($php_os = PHP_OS)
|
||||
{
|
||||
return array('loadavg' => 0);
|
||||
// look for common UNIX-like systems
|
||||
$unix_like = array('FreeBSD', 'DragonFly');
|
||||
if (in_array($php_os, $unix_like)) {
|
||||
$php_os = 'Linux';
|
||||
}
|
||||
|
||||
return ucfirst($php_os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about memory usage
|
||||
* Gets sysinfo class mathing current OS
|
||||
*
|
||||
* @return array with memory usage data
|
||||
* @return PhpMyAdmin\SysInfoBase|mixed sysinfo class
|
||||
*/
|
||||
public function memory()
|
||||
public static function get()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
$php_os = self::getOs();
|
||||
$supported = array('Linux', 'WINNT', 'SunOS');
|
||||
|
||||
/**
|
||||
* Checks whether class is supported in this environment
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
public function supported()
|
||||
{
|
||||
return true;
|
||||
if (in_array($php_os, $supported)) {
|
||||
$class_name = 'PhpMyAdmin\SysInfo' . $php_os;
|
||||
/** @var PhpMyAdmin\SysInfoBase $ret */
|
||||
$ret = new $class_name();
|
||||
if ($ret->supported()) {
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
return new SysInfoBase();
|
||||
}
|
||||
}
|
||||
|
||||
48
libraries/classes/SysInfoBase.php
Normal file
48
libraries/classes/SysInfoBase.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Hold PhpMyAdmin\SysInfoBase class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
/**
|
||||
* Basic sysinfo class not providing any real data.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class SysInfoBase
|
||||
{
|
||||
public $os = PHP_OS;
|
||||
|
||||
/**
|
||||
* Gets load information
|
||||
*
|
||||
* @return array with load data
|
||||
*/
|
||||
public function loadavg()
|
||||
{
|
||||
return array('loadavg' => 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about memory usage
|
||||
*
|
||||
* @return array with memory usage data
|
||||
*/
|
||||
public function memory()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether class is supported in this environment
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
public function supported()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -8,13 +8,14 @@
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\SysInfo;
|
||||
use PhpMyAdmin\SysInfoBase;
|
||||
|
||||
/**
|
||||
* Linux based SysInfo class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class SysInfoLinux extends SysInfo
|
||||
class SysInfoLinux extends SysInfoBase
|
||||
{
|
||||
public $os = 'Linux';
|
||||
|
||||
@ -59,7 +60,7 @@ class SysInfoLinux extends SysInfo
|
||||
function memory()
|
||||
{
|
||||
preg_match_all(
|
||||
MEMORY_REGEXP,
|
||||
SysInfo::MEMORY_REGEXP,
|
||||
file_get_contents('/proc/meminfo'),
|
||||
$matches
|
||||
);
|
||||
|
||||
@ -7,14 +7,14 @@
|
||||
*/
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\SysInfo;
|
||||
use PhpMyAdmin\SysInfoBase;
|
||||
|
||||
/**
|
||||
* SunOS based SysInfo class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class SysInfoSunOS extends SysInfo
|
||||
class SysInfoSunOS extends SysInfoBase
|
||||
{
|
||||
public $os = 'SunOS';
|
||||
|
||||
|
||||
@ -8,14 +8,14 @@
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use COM;
|
||||
use PhpMyAdmin\SysInfo;
|
||||
use PhpMyAdmin\SysInfoBase;
|
||||
|
||||
/**
|
||||
* Windows NT based SysInfo class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class SysInfoWINNT extends SysInfo
|
||||
class SysInfoWINNT extends SysInfoBase
|
||||
{
|
||||
private $_wmi;
|
||||
public $os = 'WINNT';
|
||||
|
||||
251
libraries/classes/UserPassword.php
Normal file
251
libraries/classes/UserPassword.php
Normal file
@ -0,0 +1,251 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Functions for user_password.php
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Server\Privileges;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\UserPassword class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class UserPassword
|
||||
{
|
||||
/**
|
||||
* Send the message as an ajax request
|
||||
*
|
||||
* @param array $change_password_message Message to display
|
||||
* @param string $sql_query SQL query executed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function getChangePassMessage($change_password_message, $sql_query = '')
|
||||
{
|
||||
$response = Response::getInstance();
|
||||
if ($response->isAjax()) {
|
||||
/**
|
||||
* If in an Ajax request, we don't need to show the rest of the page
|
||||
*/
|
||||
if ($change_password_message['error']) {
|
||||
$response->addJSON('message', $change_password_message['msg']);
|
||||
$response->setRequestStatus(false);
|
||||
} else {
|
||||
$sql_query = Util::getMessage(
|
||||
$change_password_message['msg'],
|
||||
$sql_query,
|
||||
'success'
|
||||
);
|
||||
$response->addJSON('message', $sql_query);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the message
|
||||
*
|
||||
* @return array error value and message
|
||||
*/
|
||||
public static function setChangePasswordMsg()
|
||||
{
|
||||
$error = false;
|
||||
$message = Message::success(__('The profile has been updated.'));
|
||||
|
||||
if (($_REQUEST['nopass'] != '1')) {
|
||||
if (strlen($_REQUEST['pma_pw']) === 0 || strlen($_REQUEST['pma_pw2']) === 0) {
|
||||
$message = Message::error(__('The password is empty!'));
|
||||
$error = true;
|
||||
} elseif ($_REQUEST['pma_pw'] !== $_REQUEST['pma_pw2']) {
|
||||
$message = Message::error(
|
||||
__('The passwords aren\'t the same!')
|
||||
);
|
||||
$error = true;
|
||||
} elseif (strlen($_REQUEST['pma_pw']) > 256) {
|
||||
$message = Message::error(__('Password is too long!'));
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
return array('error' => $error, 'msg' => $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the password
|
||||
*
|
||||
* @param string $password New password
|
||||
* @param string $message Message
|
||||
* @param array $change_password_message Message to show
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function changePassword($password, $message, $change_password_message)
|
||||
{
|
||||
global $auth_plugin;
|
||||
|
||||
$hashing_function = self::changePassHashingFunction();
|
||||
|
||||
list($username, $hostname) = $GLOBALS['dbi']->getCurrentUserAndHost();
|
||||
|
||||
$serverType = Util::getServerType();
|
||||
$serverVersion = $GLOBALS['dbi']->getVersion();
|
||||
|
||||
if (isset($_REQUEST['authentication_plugin'])
|
||||
&& ! empty($_REQUEST['authentication_plugin'])
|
||||
) {
|
||||
$orig_auth_plugin = $_REQUEST['authentication_plugin'];
|
||||
} else {
|
||||
$orig_auth_plugin = Privileges::getCurrentAuthenticationPlugin(
|
||||
'change', $username, $hostname
|
||||
);
|
||||
}
|
||||
|
||||
$sql_query = 'SET password = '
|
||||
. (($password == '') ? '\'\'' : $hashing_function . '(\'***\')');
|
||||
|
||||
if ($serverType == 'MySQL'
|
||||
&& $serverVersion >= 50706
|
||||
) {
|
||||
$sql_query = 'ALTER USER \'' . $username . '\'@\'' . $hostname
|
||||
. '\' IDENTIFIED WITH ' . $orig_auth_plugin . ' BY '
|
||||
. (($password == '') ? '\'\'' : '\'***\'');
|
||||
} else if (($serverType == 'MySQL'
|
||||
&& $serverVersion >= 50507)
|
||||
|| ($serverType == 'MariaDB'
|
||||
&& $serverVersion >= 50200)
|
||||
) {
|
||||
// For MySQL versions 5.5.7+ and MariaDB versions 5.2+,
|
||||
// explicitly set value of `old_passwords` so that
|
||||
// it does not give an error while using
|
||||
// the PASSWORD() function
|
||||
if ($orig_auth_plugin == 'sha256_password') {
|
||||
$value = 2;
|
||||
} else {
|
||||
$value = 0;
|
||||
}
|
||||
$GLOBALS['dbi']->tryQuery('SET `old_passwords` = ' . $value . ';');
|
||||
}
|
||||
|
||||
self::changePassUrlParamsAndSubmitQuery(
|
||||
$username, $hostname, $password,
|
||||
$sql_query, $hashing_function, $orig_auth_plugin
|
||||
);
|
||||
|
||||
$auth_plugin->handlePasswordChange($password);
|
||||
self::getChangePassMessage($change_password_message, $sql_query);
|
||||
self::changePassDisplayPage($message, $sql_query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the hashing function
|
||||
*
|
||||
* @return string $hashing_function
|
||||
*/
|
||||
public static function changePassHashingFunction()
|
||||
{
|
||||
if (Core::isValid(
|
||||
$_REQUEST['authentication_plugin'], 'identical', 'mysql_old_password'
|
||||
)) {
|
||||
$hashing_function = 'OLD_PASSWORD';
|
||||
} else {
|
||||
$hashing_function = 'PASSWORD';
|
||||
}
|
||||
return $hashing_function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes password for a user
|
||||
*
|
||||
* @param string $username Username
|
||||
* @param string $hostname Hostname
|
||||
* @param string $password Password
|
||||
* @param string $sql_query SQL query
|
||||
* @param string $hashing_function Hashing function
|
||||
* @param string $orig_auth_plugin Original Authentication Plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function changePassUrlParamsAndSubmitQuery(
|
||||
$username, $hostname, $password, $sql_query, $hashing_function, $orig_auth_plugin
|
||||
) {
|
||||
$err_url = 'user_password.php' . Url::getCommon();
|
||||
|
||||
$serverType = Util::getServerType();
|
||||
$serverVersion = $GLOBALS['dbi']->getVersion();
|
||||
|
||||
if ($serverType == 'MySQL' && $serverVersion >= 50706) {
|
||||
$local_query = 'ALTER USER \'' . $username . '\'@\'' . $hostname . '\''
|
||||
. ' IDENTIFIED with ' . $orig_auth_plugin . ' BY '
|
||||
. (($password == '')
|
||||
? '\'\''
|
||||
: '\'' . $GLOBALS['dbi']->escapeString($password) . '\'');
|
||||
} else if ($serverType == 'MariaDB'
|
||||
&& $serverVersion >= 50200
|
||||
&& $serverVersion < 100100
|
||||
&& $orig_auth_plugin !== ''
|
||||
) {
|
||||
if ($orig_auth_plugin == 'mysql_native_password') {
|
||||
// Set the hashing method used by PASSWORD()
|
||||
// to be 'mysql_native_password' type
|
||||
$GLOBALS['dbi']->tryQuery('SET old_passwords = 0;');
|
||||
} else if ($orig_auth_plugin == 'sha256_password') {
|
||||
// Set the hashing method used by PASSWORD()
|
||||
// to be 'sha256_password' type
|
||||
$GLOBALS['dbi']->tryQuery('SET `old_passwords` = 2;');
|
||||
}
|
||||
|
||||
$hashedPassword = Privileges::getHashedPassword($_POST['pma_pw']);
|
||||
|
||||
$local_query = "UPDATE `mysql`.`user` SET"
|
||||
. " `authentication_string` = '" . $hashedPassword
|
||||
. "', `Password` = '', "
|
||||
. " `plugin` = '" . $orig_auth_plugin . "'"
|
||||
. " WHERE `User` = '" . $username . "' AND Host = '"
|
||||
. $hostname . "';";
|
||||
} else {
|
||||
$local_query = 'SET password = ' . (($password == '')
|
||||
? '\'\''
|
||||
: $hashing_function . '(\''
|
||||
. $GLOBALS['dbi']->escapeString($password) . '\')');
|
||||
}
|
||||
if (! @$GLOBALS['dbi']->tryQuery($local_query)) {
|
||||
Util::mysqlDie(
|
||||
$GLOBALS['dbi']->getError(),
|
||||
$sql_query,
|
||||
false,
|
||||
$err_url
|
||||
);
|
||||
}
|
||||
|
||||
// Flush privileges after successful password change
|
||||
$GLOBALS['dbi']->tryQuery("FLUSH PRIVILEGES;");
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the page
|
||||
*
|
||||
* @param string $message Message
|
||||
* @param string $sql_query SQL query
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function changePassDisplayPage($message, $sql_query)
|
||||
{
|
||||
echo '<h1>' , __('Change password') , '</h1>' , "\n\n";
|
||||
echo Util::getMessage(
|
||||
$message, $sql_query, 'success'
|
||||
);
|
||||
echo '<a href="index.php' , Url::getCommon()
|
||||
, ' target="_parent">' , "\n"
|
||||
, '<strong>' , __('Back') , '</strong></a>';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@ -1,527 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Form templates
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Util;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Sanitize;
|
||||
|
||||
/**
|
||||
* Displays top part of the form
|
||||
*
|
||||
* @param string $action default: $_SERVER['REQUEST_URI']
|
||||
* @param string $method 'post' or 'get'
|
||||
* @param array $hidden_fields array of form hidden fields (key: field name)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_displayFormTop($action = null, $method = 'post', $hidden_fields = null)
|
||||
{
|
||||
static $has_check_page_refresh = false;
|
||||
|
||||
if ($action === null) {
|
||||
$action = $_SERVER['REQUEST_URI'];
|
||||
}
|
||||
if ($method != 'post') {
|
||||
$method = 'get';
|
||||
}
|
||||
$htmlOutput = '<form method="' . $method . '" action="'
|
||||
. htmlspecialchars($action) . '" class="config-form disableAjax">';
|
||||
$htmlOutput .= '<input type="hidden" name="tab_hash" value="" />';
|
||||
// we do validation on page refresh when browser remembers field values,
|
||||
// add a field with known value which will be used for checks
|
||||
if (! $has_check_page_refresh) {
|
||||
$has_check_page_refresh = true;
|
||||
$htmlOutput .= '<input type="hidden" name="check_page_refresh" '
|
||||
. ' id="check_page_refresh" value="" />' . "\n";
|
||||
}
|
||||
$htmlOutput .= Url::getHiddenInputs('', '', 0, 'server') . "\n";
|
||||
$htmlOutput .= Url::getHiddenFields((array)$hidden_fields);
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays form tabs which are given by an array indexed by fieldset id
|
||||
* ({@link PMA_displayFieldsetTop}), with values being tab titles.
|
||||
*
|
||||
* @param array $tabs tab names
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_displayTabsTop($tabs)
|
||||
{
|
||||
$items = array();
|
||||
foreach ($tabs as $tab_id => $tab_name) {
|
||||
$items[] = array(
|
||||
'content' => htmlspecialchars($tab_name),
|
||||
'url' => array(
|
||||
'href' => '#' . $tab_id,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$htmlOutput = Template::get('list/unordered')->render(
|
||||
array(
|
||||
'class' => 'tabs responsivetable',
|
||||
'items' => $items,
|
||||
)
|
||||
);
|
||||
$htmlOutput .= '<br />';
|
||||
$htmlOutput .= '<div class="tabs_contents">';
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Displays top part of a fieldset
|
||||
*
|
||||
* @param string $title title of fieldset
|
||||
* @param string $description description shown on top of fieldset
|
||||
* @param array $errors error messages to display
|
||||
* @param array $attributes optional extra attributes of fieldset
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_displayFieldsetTop($title = '', $description = '', $errors = null,
|
||||
$attributes = array()
|
||||
) {
|
||||
global $_FormDisplayGroup;
|
||||
|
||||
$_FormDisplayGroup = 0;
|
||||
|
||||
$attributes = array_merge(array('class' => 'optbox'), $attributes);
|
||||
foreach ($attributes as $k => &$attr) {
|
||||
$attr = $k . '="' . htmlspecialchars($attr) . '"';
|
||||
}
|
||||
|
||||
$htmlOutput = '<fieldset ' . implode(' ', $attributes) . '>';
|
||||
$htmlOutput .= '<legend>' . $title . '</legend>';
|
||||
if (!empty($description)) {
|
||||
$htmlOutput .= '<p>' . $description . '</p>';
|
||||
}
|
||||
// this must match with displayErrors() in scripts.js
|
||||
if (is_array($errors) && count($errors) > 0) {
|
||||
$htmlOutput .= '<dl class="errors">';
|
||||
foreach ($errors as $error) {
|
||||
$htmlOutput .= '<dd>' . $error . '</dd>';
|
||||
}
|
||||
$htmlOutput .= '</dl>';
|
||||
}
|
||||
$htmlOutput .= '<table width="100%" cellspacing="0">';
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays input field
|
||||
*
|
||||
* $opts keys:
|
||||
* o doc - (string) documentation link
|
||||
* o errors - error array
|
||||
* o setvalue - (string) shows button allowing to set predefined value
|
||||
* o show_restore_default - (boolean) whether show "restore default" button
|
||||
* o userprefs_allow - whether user preferences are enabled for this field
|
||||
* (null - no support, true/false - enabled/disabled)
|
||||
* o userprefs_comment - (string) field comment
|
||||
* o values - key - value pairs for <select> fields
|
||||
* o values_escaped - (boolean) tells whether values array is already escaped
|
||||
* (defaults to false)
|
||||
* o values_disabled - (array)list of disabled values (keys from values)
|
||||
* o comment - (string) tooltip comment
|
||||
* o comment_warning - (bool) whether this comments warns about something
|
||||
*
|
||||
* @param string $path config option path
|
||||
* @param string $name config option name
|
||||
* @param string $type type of config option
|
||||
* @param mixed $value current value
|
||||
* @param string $description verbose description
|
||||
* @param bool $value_is_default whether value is default
|
||||
* @param array $opts see above description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_displayInput($path, $name, $type, $value, $description = '',
|
||||
$value_is_default = true, $opts = null
|
||||
) {
|
||||
global $_FormDisplayGroup;
|
||||
static $icons; // An array of IMG tags used further below in the function
|
||||
|
||||
if (defined('TESTSUITE')) {
|
||||
$icons = null;
|
||||
}
|
||||
|
||||
$is_setup_script = $GLOBALS['PMA_Config']->get('is_setup');
|
||||
if ($icons === null) { // if the static variables have not been initialised
|
||||
$icons = array();
|
||||
// Icon definitions:
|
||||
// The same indexes will be used in the $icons array.
|
||||
// The first element contains the filename and the second
|
||||
// element is used for the "alt" and "title" attributes.
|
||||
$icon_init = array(
|
||||
'edit' => array('b_edit.png', ''),
|
||||
'help' => array('b_help.png', __('Documentation')),
|
||||
'reload' => array('s_reload.png', ''),
|
||||
'tblops' => array('b_tblops.png', '')
|
||||
);
|
||||
if ($is_setup_script) {
|
||||
// When called from the setup script, we don't have access to the
|
||||
// sprite-aware getImage() function because the PMA_theme class
|
||||
// has not been loaded, so we generate the img tags manually.
|
||||
foreach ($icon_init as $k => $v) {
|
||||
$title = '';
|
||||
if (! empty($v[1])) {
|
||||
$title = ' title="' . $v[1] . '"';
|
||||
}
|
||||
$icons[$k] = sprintf(
|
||||
'<img alt="%s" src="%s"%s />',
|
||||
$v[1],
|
||||
"../themes/original/img/{$v[0]}",
|
||||
$title
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// In this case we just use getImage() because it's available
|
||||
foreach ($icon_init as $k => $v) {
|
||||
$icons[$k] = Util::getImage(
|
||||
$v[0], $v[1]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$has_errors = isset($opts['errors']) && !empty($opts['errors']);
|
||||
$option_is_disabled = ! $is_setup_script && isset($opts['userprefs_allow'])
|
||||
&& ! $opts['userprefs_allow'];
|
||||
$name_id = 'name="' . htmlspecialchars($path) . '" id="'
|
||||
. htmlspecialchars($path) . '"';
|
||||
$field_class = $type == 'checkbox' ? 'checkbox' : '';
|
||||
if (! $value_is_default) {
|
||||
$field_class .= ($field_class == '' ? '' : ' ')
|
||||
. ($has_errors ? 'custom field-error' : 'custom');
|
||||
}
|
||||
$field_class = $field_class ? ' class="' . $field_class . '"' : '';
|
||||
$tr_class = $_FormDisplayGroup > 0
|
||||
? 'group-field group-field-' . $_FormDisplayGroup
|
||||
: '';
|
||||
if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') {
|
||||
unset($opts['setvalue']);
|
||||
$_FormDisplayGroup++;
|
||||
$tr_class = 'group-header-field group-header-' . $_FormDisplayGroup;
|
||||
}
|
||||
if ($option_is_disabled) {
|
||||
$tr_class .= ($tr_class ? ' ' : '') . 'disabled-field';
|
||||
}
|
||||
$tr_class = $tr_class ? ' class="' . $tr_class . '"' : '';
|
||||
|
||||
$htmlOutput = '<tr' . $tr_class . '>';
|
||||
$htmlOutput .= '<th>';
|
||||
$htmlOutput .= '<label for="' . htmlspecialchars($path) . '">' . $name
|
||||
. '</label>';
|
||||
|
||||
if (! empty($opts['doc'])) {
|
||||
$htmlOutput .= '<span class="doc">';
|
||||
$htmlOutput .= '<a href="' . $opts['doc']
|
||||
. '" target="documentation">' . $icons['help'] . '</a>';
|
||||
$htmlOutput .= "\n";
|
||||
$htmlOutput .= '</span>';
|
||||
}
|
||||
|
||||
if ($option_is_disabled) {
|
||||
$htmlOutput .= '<span class="disabled-notice" title="';
|
||||
$htmlOutput .= __(
|
||||
'This setting is disabled, it will not be applied to your configuration.'
|
||||
);
|
||||
$htmlOutput .= '">' . __('Disabled') . "</span>";
|
||||
}
|
||||
|
||||
if (!empty($description)) {
|
||||
$htmlOutput .= '<small>' . $description . '</small>';
|
||||
}
|
||||
|
||||
$htmlOutput .= '</th>';
|
||||
$htmlOutput .= '<td>';
|
||||
|
||||
switch ($type) {
|
||||
case 'text':
|
||||
$htmlOutput .= '<input type="text" class="all85" ' . $name_id . $field_class
|
||||
. ' value="' . htmlspecialchars($value) . '" />';
|
||||
break;
|
||||
case 'password':
|
||||
$htmlOutput .= '<input type="password" class="all85" ' . $name_id . $field_class
|
||||
. ' value="' . htmlspecialchars($value) . '" />';
|
||||
break;
|
||||
case 'short_text':
|
||||
// As seen in the reporting server (#15042) we sometimes receive
|
||||
// an array here. No clue about its origin nor content, so let's avoid
|
||||
// a notice on htmlspecialchars().
|
||||
if (! is_array($value)) {
|
||||
$htmlOutput .= '<input type="text" size="25" ' . $name_id
|
||||
. $field_class . ' value="' . htmlspecialchars($value)
|
||||
. '" />';
|
||||
}
|
||||
break;
|
||||
case 'number_text':
|
||||
$htmlOutput .= '<input type="number" ' . $name_id . $field_class
|
||||
. ' value="' . htmlspecialchars($value) . '" />';
|
||||
break;
|
||||
case 'checkbox':
|
||||
$htmlOutput .= '<span' . $field_class . '><input type="checkbox" ' . $name_id
|
||||
. ($value ? ' checked="checked"' : '') . ' /></span>';
|
||||
break;
|
||||
case 'select':
|
||||
$htmlOutput .= '<select class="all85" ' . $name_id . $field_class . '>';
|
||||
$escape = !(isset($opts['values_escaped']) && $opts['values_escaped']);
|
||||
$values_disabled = isset($opts['values_disabled'])
|
||||
? array_flip($opts['values_disabled']) : array();
|
||||
foreach ($opts['values'] as $opt_value_key => $opt_value) {
|
||||
// set names for boolean values
|
||||
if (is_bool($opt_value)) {
|
||||
$opt_value = mb_strtolower(
|
||||
$opt_value ? __('Yes') : __('No')
|
||||
);
|
||||
}
|
||||
// escape if necessary
|
||||
if ($escape) {
|
||||
$display = htmlspecialchars($opt_value);
|
||||
$display_value = htmlspecialchars($opt_value_key);
|
||||
} else {
|
||||
$display = $opt_value;
|
||||
$display_value = $opt_value_key;
|
||||
}
|
||||
// compare with selected value
|
||||
// boolean values are cast to integers when used as array keys
|
||||
$selected = is_bool($value)
|
||||
? (int) $value === $opt_value_key
|
||||
: $opt_value_key === $value;
|
||||
$htmlOutput .= '<option value="' . $display_value . '"';
|
||||
if ($selected) {
|
||||
$htmlOutput .= ' selected="selected"';
|
||||
}
|
||||
if (isset($values_disabled[$opt_value_key])) {
|
||||
$htmlOutput .= ' disabled="disabled"';
|
||||
}
|
||||
$htmlOutput .= '>' . $display . '</option>';
|
||||
}
|
||||
$htmlOutput .= '</select>';
|
||||
break;
|
||||
case 'list':
|
||||
$htmlOutput .= '<textarea cols="35" rows="5" ' . $name_id . $field_class
|
||||
. '>' . htmlspecialchars(implode("\n", $value)) . '</textarea>';
|
||||
break;
|
||||
}
|
||||
if (isset($opts['comment']) && $opts['comment']) {
|
||||
$class = 'field-comment-mark';
|
||||
if (isset($opts['comment_warning']) && $opts['comment_warning']) {
|
||||
$class .= ' field-comment-warning';
|
||||
}
|
||||
$htmlOutput .= '<span class="' . $class . '" title="'
|
||||
. htmlspecialchars($opts['comment']) . '">i</span>';
|
||||
}
|
||||
if ($is_setup_script
|
||||
&& isset($opts['userprefs_comment'])
|
||||
&& $opts['userprefs_comment']
|
||||
) {
|
||||
$htmlOutput .= '<a class="userprefs-comment" title="'
|
||||
. htmlspecialchars($opts['userprefs_comment']) . '">'
|
||||
. $icons['tblops'] . '</a>';
|
||||
}
|
||||
if (isset($opts['setvalue']) && $opts['setvalue']) {
|
||||
$htmlOutput .= '<a class="set-value hide" href="#'
|
||||
. htmlspecialchars("$path={$opts['setvalue']}") . '" title="'
|
||||
. sprintf(__('Set value: %s'), htmlspecialchars($opts['setvalue']))
|
||||
. '">' . $icons['edit'] . '</a>';
|
||||
}
|
||||
if (isset($opts['show_restore_default']) && $opts['show_restore_default']) {
|
||||
$htmlOutput .= '<a class="restore-default hide" href="#' . $path . '" title="'
|
||||
. __('Restore default value') . '">' . $icons['reload'] . '</a>';
|
||||
}
|
||||
// this must match with displayErrors() in scripts/config.js
|
||||
if ($has_errors) {
|
||||
$htmlOutput .= "\n <dl class=\"inline_errors\">";
|
||||
foreach ($opts['errors'] as $error) {
|
||||
$htmlOutput .= '<dd>' . htmlspecialchars($error) . '</dd>';
|
||||
}
|
||||
$htmlOutput .= '</dl>';
|
||||
}
|
||||
$htmlOutput .= '</td>';
|
||||
if ($is_setup_script && isset($opts['userprefs_allow'])) {
|
||||
$htmlOutput .= '<td class="userprefs-allow" title="' .
|
||||
__('Allow users to customize this value') . '">';
|
||||
$htmlOutput .= '<input type="checkbox" name="' . $path
|
||||
. '-userprefs-allow" ';
|
||||
if ($opts['userprefs_allow']) {
|
||||
$htmlOutput .= 'checked="checked"';
|
||||
};
|
||||
$htmlOutput .= '/>';
|
||||
$htmlOutput .= '</td>';
|
||||
} else if ($is_setup_script) {
|
||||
$htmlOutput .= '<td> </td>';
|
||||
}
|
||||
$htmlOutput .= '</tr>';
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display group header
|
||||
*
|
||||
* @param string $header_text Text of header
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
function PMA_displayGroupHeader($header_text)
|
||||
{
|
||||
global $_FormDisplayGroup;
|
||||
|
||||
$_FormDisplayGroup++;
|
||||
if (! $header_text) {
|
||||
return null;
|
||||
}
|
||||
$colspan = $GLOBALS['PMA_Config']->get('is_setup')
|
||||
? 3
|
||||
: 2;
|
||||
$htmlOutput = '<tr class="group-header group-header-' . $_FormDisplayGroup
|
||||
. '">';
|
||||
$htmlOutput .= '<th colspan="' . $colspan . '">';
|
||||
$htmlOutput .= $header_text;
|
||||
$htmlOutput .= '</th>';
|
||||
$htmlOutput .= '</tr>';
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display group footer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_displayGroupFooter()
|
||||
{
|
||||
global $_FormDisplayGroup;
|
||||
|
||||
$_FormDisplayGroup--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays bottom part of a fieldset
|
||||
*
|
||||
* @param bool $show_buttons whether show submit and reset button
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_displayFieldsetBottom($show_buttons = true)
|
||||
{
|
||||
$colspan = 2;
|
||||
if ($GLOBALS['PMA_Config']->get('is_setup')) {
|
||||
$colspan++;
|
||||
}
|
||||
$htmlOutput = '';
|
||||
if ($show_buttons) {
|
||||
$htmlOutput .= '<tr>';
|
||||
$htmlOutput .= '<td colspan="' . $colspan . '" class="lastrow">';
|
||||
$htmlOutput .= '<input type="submit" name="submit_save" value="'
|
||||
. __('Apply') . '" class="green" />';
|
||||
$htmlOutput .= '<input type="button" name="submit_reset" value="'
|
||||
. __('Reset') . '" />';
|
||||
$htmlOutput .= '</td>';
|
||||
$htmlOutput .= '</tr>';
|
||||
}
|
||||
$htmlOutput .= '</table>';
|
||||
$htmlOutput .= '</fieldset>';
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays simple bottom part of a fieldset (without submit buttons)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_displayFieldsetBottomSimple()
|
||||
{
|
||||
$htmlOutput = '</table>';
|
||||
$htmlOutput .= '</fieldset>';
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes form tabs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_displayTabsBottom()
|
||||
{
|
||||
$htmlOutput = "</div>\n";
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays bottom part of the form
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_displayFormBottom()
|
||||
{
|
||||
$htmlOutput = "</form>\n";
|
||||
return $htmlOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends JS validation code to $js_array
|
||||
*
|
||||
* @param string $field_id ID of field to validate
|
||||
* @param string|array $validators validators callback
|
||||
* @param array &$js_array will be updated with javascript code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_addJsValidate($field_id, $validators, &$js_array)
|
||||
{
|
||||
foreach ((array)$validators as $validator) {
|
||||
$validator = (array)$validator;
|
||||
$v_name = array_shift($validator);
|
||||
$v_name = "PMA_" . $v_name;
|
||||
$v_args = array();
|
||||
foreach ($validator as $arg) {
|
||||
$v_args[] = Sanitize::escapeJsString($arg);
|
||||
}
|
||||
$v_args = $v_args ? ", ['" . implode("', '", $v_args) . "']" : '';
|
||||
$js_array[] = "validateField('$field_id', '$v_name', true$v_args)";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays JavaScript code
|
||||
*
|
||||
* @param array $js_array lines of javascript code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_displayJavascript($js_array)
|
||||
{
|
||||
if (empty($js_array)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Template::get('javascript/display')->render(
|
||||
array('js_array' => $js_array,)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays error list
|
||||
*
|
||||
* @param string $name name of item with errors
|
||||
* @param array $error_list list of errors to show
|
||||
*
|
||||
* @return string HTML for errors
|
||||
*/
|
||||
function PMA_displayErrors($name, $error_list)
|
||||
{
|
||||
$htmlOutput = '<dl>';
|
||||
$htmlOutput .= '<dt>' . htmlspecialchars($name) . '</dt>';
|
||||
foreach ($error_list as $error) {
|
||||
$htmlOutput .= '<dd>' . htmlspecialchars($error) . '</dd>';
|
||||
}
|
||||
$htmlOutput .= '</dl>';
|
||||
return $htmlOutput;
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Library for extracting information about system memory and cpu.
|
||||
* Currently supports all Windows and Linux platforms
|
||||
*
|
||||
* This code is based on the OS Classes from the phpsysinfo project
|
||||
* (https://phpsysinfo.github.io/phpsysinfo/)
|
||||
*
|
||||
* @package PhpMyAdmin-sysinfo
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
use PhpMyAdmin\SysInfo;
|
||||
|
||||
define(
|
||||
'MEMORY_REGEXP',
|
||||
'/^(MemTotal|MemFree|Cached|Buffers|SwapCached|SwapTotal|SwapFree):'
|
||||
. '\s+(.*)\s*kB/im'
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns OS type used for sysinfo class
|
||||
*
|
||||
* @param string $php_os PHP_OS constant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_getSysInfoOs($php_os = PHP_OS)
|
||||
{
|
||||
|
||||
// look for common UNIX-like systems
|
||||
$unix_like = array('FreeBSD', 'DragonFly');
|
||||
if (in_array($php_os, $unix_like)) {
|
||||
$php_os = 'Linux';
|
||||
}
|
||||
|
||||
return ucfirst($php_os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets sysinfo class mathing current OS
|
||||
*
|
||||
* @return \PhpMyAdmin\SysInfo|mixed sysinfo class
|
||||
*/
|
||||
function PMA_getSysInfo()
|
||||
{
|
||||
$php_os = PMA_getSysInfoOs();
|
||||
$supported = array('Linux', 'WINNT', 'SunOS');
|
||||
|
||||
if (in_array($php_os, $supported)) {
|
||||
$class_name = 'PhpMyAdmin\SysInfo' . $php_os;
|
||||
/** @var PhpMyAdmin\SysInfo $ret */
|
||||
$ret = new $class_name();
|
||||
if ($ret->supported()) {
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
return new SysInfo();
|
||||
}
|
||||
@ -6,10 +6,9 @@
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Plugins;
|
||||
use PhpMyAdmin\Plugins\SchemaPlugin;
|
||||
use PhpMyAdmin\Export;
|
||||
use PhpMyAdmin\Relation;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* Gets some core libraries
|
||||
@ -23,48 +22,11 @@ require_once 'libraries/common.inc.php';
|
||||
$cfgRelation = Relation::getRelationsParam();
|
||||
|
||||
if (! isset($_REQUEST['export_type'])) {
|
||||
PhpMyAdmin\Util::checkParameters(array('export_type'));
|
||||
Util::checkParameters(array('export_type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the appropriate Schema Class depending on $export_type
|
||||
* default is PDF
|
||||
*/
|
||||
PMA_processExportSchema($_REQUEST['export_type']);
|
||||
|
||||
/**
|
||||
* get all the export options and verify
|
||||
* call and include the appropriate Schema Class depending on $export_type
|
||||
*
|
||||
* @param string $export_type format of the export
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_processExportSchema($export_type)
|
||||
{
|
||||
/**
|
||||
* default is PDF, otherwise validate it's only letters a-z
|
||||
*/
|
||||
if (! isset($export_type) || ! preg_match('/^[a-zA-Z]+$/', $export_type)) {
|
||||
$export_type = 'pdf';
|
||||
}
|
||||
|
||||
// sanitize this parameter which will be used below in a file inclusion
|
||||
$export_type = Core::securePath($export_type);
|
||||
|
||||
// get the specific plugin
|
||||
/* @var $export_plugin SchemaPlugin */
|
||||
$export_plugin = Plugins::getPlugin(
|
||||
"schema",
|
||||
$export_type,
|
||||
'libraries/classes/Plugins/Schema/'
|
||||
);
|
||||
|
||||
// Check schema export type
|
||||
if (! isset($export_plugin)) {
|
||||
Core::fatalError(__('Bad type!'));
|
||||
}
|
||||
|
||||
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
|
||||
$export_plugin->exportSchema($GLOBALS['db']);
|
||||
}
|
||||
Export::processExportSchema($_REQUEST['export_type']);
|
||||
|
||||
@ -6,25 +6,20 @@
|
||||
* @package PhpMyAdmin-Setup
|
||||
*/
|
||||
|
||||
use PhpMyAdmin\Setup\ConfigGenerator;
|
||||
use PhpMyAdmin\Config\FormDisplayTemplate;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Setup\ConfigGenerator;
|
||||
|
||||
if (!defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Core libraries.
|
||||
*/
|
||||
require_once './libraries/config/FormDisplay.tpl.php';
|
||||
require_once './setup/lib/index.lib.php';
|
||||
|
||||
echo '<h2>' , __('Configuration file') , '</h2>';
|
||||
|
||||
echo PMA_displayFormTop('config.php');
|
||||
echo FormDisplayTemplate::displayFormTop('config.php');
|
||||
echo '<input type="hidden" name="eol" value="'
|
||||
, htmlspecialchars(Core::ifSetOr($_GET['eol'], 'unix')) , '" />';
|
||||
echo PMA_displayFieldsetTop('config.inc.php', '', null, array('class' => 'simple'));
|
||||
echo FormDisplayTemplate::displayFieldsetTop('config.inc.php', '', null, array('class' => 'simple'));
|
||||
echo '<tr>';
|
||||
echo '<td>';
|
||||
echo '<textarea cols="50" rows="20" name="textconfig" '
|
||||
@ -40,5 +35,5 @@ echo '<input type="submit" name="submit_download" value="'
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
|
||||
echo PMA_displayFieldsetBottomSimple();
|
||||
echo PMA_displayFormBottom();
|
||||
echo FormDisplayTemplate::displayFieldsetBottomSimple();
|
||||
echo FormDisplayTemplate::displayFormBottom();
|
||||
|
||||
@ -8,16 +8,12 @@
|
||||
|
||||
use PhpMyAdmin\Config\Forms\Setup\SetupFormList;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Setup\FormProcessing;
|
||||
|
||||
if (!defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Core libraries.
|
||||
*/
|
||||
require_once './setup/lib/form_processing.lib.php';
|
||||
|
||||
$formset_id = Core::isValid($_GET['formset'], 'scalar') ? $_GET['formset'] : null;
|
||||
$mode = isset($_GET['mode']) ? $_GET['mode'] : null;
|
||||
$form_class = SetupFormList::get($formset_id);
|
||||
@ -26,4 +22,4 @@ if (is_null($form_class)) {
|
||||
}
|
||||
echo '<h2>' , $form_class::getName() , '</h2>';
|
||||
$form_display = new $form_class($GLOBALS['ConfigFile']);
|
||||
PMA_Process_formset($form_display);
|
||||
FormProcessing::process($form_display);
|
||||
|
||||
@ -8,22 +8,18 @@
|
||||
|
||||
use PhpMyAdmin\Config\ConfigFile;
|
||||
use PhpMyAdmin\Config\FormDisplay;
|
||||
use PhpMyAdmin\Config\FormDisplayTemplate;
|
||||
use PhpMyAdmin\Config\ServerConfigChecks;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\LanguageManager;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\Setup\Index as SetupIndex;
|
||||
use PhpMyAdmin\Url;
|
||||
|
||||
if (!defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Core libraries.
|
||||
*/
|
||||
require_once './setup/lib/index.lib.php';
|
||||
require_once './libraries/config/FormDisplay.tpl.php';
|
||||
|
||||
// prepare unfiltered language list
|
||||
$all_languages = LanguageManager::getInstance()->sortedLanguages();
|
||||
|
||||
@ -31,13 +27,13 @@ $all_languages = LanguageManager::getInstance()->sortedLanguages();
|
||||
$cf = $GLOBALS['ConfigFile'];
|
||||
|
||||
// message handling
|
||||
PMA_messagesBegin();
|
||||
SetupIndex::messagesBegin();
|
||||
|
||||
//
|
||||
// Check phpMyAdmin version
|
||||
//
|
||||
if (isset($_GET['version_check'])) {
|
||||
PMA_versionCheck();
|
||||
SetupIndex::versionCheck();
|
||||
}
|
||||
|
||||
//
|
||||
@ -59,7 +55,7 @@ $text .= __(
|
||||
. 'follow this link to use a secure connection.'
|
||||
);
|
||||
$text .= '</a>';
|
||||
PMA_messagesSet('notice', 'no_https', __('Insecure connection'), $text);
|
||||
SetupIndex::messagesSet('notice', 'no_https', __('Insecure connection'), $text);
|
||||
|
||||
echo '<form id="select_lang" method="post">';
|
||||
echo Url::getHiddenInputs();
|
||||
@ -84,7 +80,7 @@ echo '</form>';
|
||||
switch ($action_done) {
|
||||
case 'config_saved':
|
||||
/* Use uniqid to display this message every time configuration is saved */
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'notice', uniqid('config_saved'), __('Configuration saved.'),
|
||||
Sanitize::sanitize(
|
||||
__(
|
||||
@ -97,7 +93,7 @@ case 'config_saved':
|
||||
break;
|
||||
case 'config_not_saved':
|
||||
/* Use uniqid to display this message every time configuration is saved */
|
||||
PMA_messagesSet(
|
||||
SetupIndex::messagesSet(
|
||||
'notice', uniqid('config_not_saved'), __('Configuration not saved!'),
|
||||
Sanitize::sanitize(
|
||||
__(
|
||||
@ -116,8 +112,8 @@ default:
|
||||
echo '<h2>' , __('Overview') , '</h2>';
|
||||
|
||||
// message handling
|
||||
PMA_messagesEnd();
|
||||
PMA_messagesShowHtml();
|
||||
SetupIndex::messagesEnd();
|
||||
SetupIndex::messagesShowHtml();
|
||||
|
||||
echo '<a href="#" id="show_hidden_messages" class="hide">';
|
||||
echo __('Show hidden messages (#MSG_COUNT)');
|
||||
@ -130,7 +126,7 @@ echo '</legend>';
|
||||
//
|
||||
// Display server list
|
||||
//
|
||||
echo PMA_displayFormTop(
|
||||
echo FormDisplayTemplate::displayFormTop(
|
||||
'index.php', 'get',
|
||||
array(
|
||||
'page' => 'servers',
|
||||
@ -186,7 +182,7 @@ echo '</tr>';
|
||||
echo '</table>';
|
||||
echo '</div>';
|
||||
|
||||
echo PMA_displayFormBottom();
|
||||
echo FormDisplayTemplate::displayFormBottom();
|
||||
|
||||
echo '</fieldset>';
|
||||
|
||||
@ -197,7 +193,7 @@ echo '<fieldset class="simple"><legend>' , __('Configuration file') , '</legend>
|
||||
//
|
||||
$form_display = new FormDisplay($cf);
|
||||
|
||||
echo PMA_displayFormTop('config.php');
|
||||
echo FormDisplayTemplate::displayFormTop('config.php');
|
||||
echo '<table width="100%" cellspacing="0">';
|
||||
|
||||
// Display language list
|
||||
@ -208,7 +204,7 @@ $opts = array(
|
||||
foreach ($all_languages as $each_lang) {
|
||||
$opts['values'][$each_lang->getCode()] = $each_lang->getName();
|
||||
}
|
||||
echo PMA_displayInput(
|
||||
echo FormDisplayTemplate::displayInput(
|
||||
'DefaultLang', __('Default language'), 'select',
|
||||
$cf->getValue('DefaultLang'), '', true, $opts
|
||||
);
|
||||
@ -233,7 +229,7 @@ if ($cf->getServerCount() > 0) {
|
||||
$opts['values']['1'] = __('- none -');
|
||||
$opts['values_escaped'] = true;
|
||||
}
|
||||
echo PMA_displayInput(
|
||||
echo FormDisplayTemplate::displayInput(
|
||||
'ServerDefault', __('Default server'), 'select',
|
||||
$cf->getValue('ServerDefault'), '', true, $opts
|
||||
);
|
||||
@ -245,7 +241,7 @@ $opts = array(
|
||||
'win' => 'Windows (\r\n)'),
|
||||
'values_escaped' => true);
|
||||
$eol = Core::ifSetOr($_SESSION['eol'], (PMA_IS_WINDOWS ? 'win' : 'unix'));
|
||||
echo PMA_displayInput(
|
||||
echo FormDisplayTemplate::displayInput(
|
||||
'eol', __('End of line'), 'select',
|
||||
$eol, '', true, $opts
|
||||
);
|
||||
@ -261,7 +257,7 @@ echo '</td>';
|
||||
echo '</tr>';
|
||||
echo '</table>';
|
||||
|
||||
echo PMA_displayFormBottom();
|
||||
echo FormDisplayTemplate::displayFormBottom();
|
||||
|
||||
echo '</fieldset>';
|
||||
echo '<div id="footer">';
|
||||
|
||||
@ -9,17 +9,13 @@
|
||||
use PhpMyAdmin\Config\ConfigFile;
|
||||
use PhpMyAdmin\Config\Forms\Setup\ServersForm;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Setup\FormProcessing;
|
||||
use PhpMyAdmin\Url;
|
||||
|
||||
if (!defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Core libraries.
|
||||
*/
|
||||
require_once './setup/lib/form_processing.lib.php';
|
||||
|
||||
$mode = isset($_GET['mode']) ? $_GET['mode'] : null;
|
||||
$id = Core::isValid($_GET['id'], 'numeric') ? intval($_GET['id']) : null;
|
||||
|
||||
@ -45,4 +41,4 @@ if (isset($page_title)) {
|
||||
echo '<h2>' , $page_title . '</h2>';
|
||||
}
|
||||
$form_display = new ServersForm($cf, $id);
|
||||
PMA_Process_formset($form_display);
|
||||
FormProcessing::process($form_display);
|
||||
|
||||
77
setup/lib/FormProcessing.php
Normal file
77
setup/lib/FormProcessing.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Formset processing library
|
||||
*
|
||||
* @package PhpMyAdmin-Setup
|
||||
*/
|
||||
namespace PhpMyAdmin\Setup;
|
||||
|
||||
use PhpMyAdmin\Config\FormDisplay;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Response;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\Setup\FormProcessing class
|
||||
*
|
||||
* @package PhpMyAdmin-Setup
|
||||
*/
|
||||
class FormProcessing
|
||||
{
|
||||
/**
|
||||
* Processes forms registered in $form_display, handles error correction
|
||||
*
|
||||
* @param FormDisplay $form_display Form to display
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function process(FormDisplay $form_display)
|
||||
{
|
||||
if (isset($_GET['mode']) && $_GET['mode'] == 'revert') {
|
||||
// revert erroneous fields to their default values
|
||||
$form_display->fixErrors();
|
||||
$response = Response::getInstance();
|
||||
$response->generateHeader303('index.php' . Url::getCommonRaw());
|
||||
}
|
||||
|
||||
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()) {
|
||||
$response = Response::getInstance();
|
||||
$response->generateHeader303('index.php' . Url::getCommonRaw());
|
||||
return;
|
||||
}
|
||||
|
||||
// form has errors, show warning
|
||||
$page = isset($_GET['page']) ? $_GET['page'] : '';
|
||||
$formset = isset($_GET['formset']) ? $_GET['formset'] : '';
|
||||
$formId = Core::isValid($_GET['id'], 'numeric') ? $_GET['id'] : '';
|
||||
if ($formId === null && $page == 'servers') {
|
||||
// we've just added a new server, get its id
|
||||
$formId = $form_display->getConfigFile()->getServerCount();
|
||||
}
|
||||
?>
|
||||
<div class="error">
|
||||
<h4><?php echo __('Warning') ?></h4>
|
||||
<?php echo __('Submitted form contains errors') ?><br />
|
||||
<a href="<?php echo Url::getCommon(array('page' => $page, 'formset' => $formset, 'id' => $formId, '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 Url::getCommon() ?>">
|
||||
<?php echo __('Ignore errors') ?>
|
||||
</a>
|
||||
|
||||
<a class="btn" href="<?php echo Url::getCommon(array('page' => $page, 'formset' => $formset, 'id' => $formId, 'mode' => 'edit')) ?>">
|
||||
<?php echo __('Show form') ?>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
191
setup/lib/Index.php
Normal file
191
setup/lib/Index.php
Normal file
@ -0,0 +1,191 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Various checks and message functions used on index page.
|
||||
*
|
||||
* @package PhpMyAdmin-Setup
|
||||
*/
|
||||
namespace PhpMyAdmin\Setup;
|
||||
|
||||
use PhpMyAdmin\VersionInformation;
|
||||
use PhpMyAdmin\Sanitize;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\Setup\Index class
|
||||
*
|
||||
* Various checks and message functions used on index page.
|
||||
*
|
||||
* @package PhpMyAdmin-Setup
|
||||
*/
|
||||
class Index
|
||||
{
|
||||
/**
|
||||
* Initializes message list
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function 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
|
||||
*/
|
||||
public static function 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
|
||||
*/
|
||||
public static function 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 self::messagesEnd()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function messagesShowHtml()
|
||||
{
|
||||
foreach ($_SESSION['messages'] as $type => $messages) {
|
||||
foreach ($messages as $id => $msg) {
|
||||
if (! $msg['fresh'] && $type != 'error') {
|
||||
$extra = ' hiddenmessage';
|
||||
} else {
|
||||
$extra = '';
|
||||
}
|
||||
echo '<div class="' , $type, $extra , '" id="' , $id , '">'
|
||||
, '<h4>' , $msg['title'] , '</h4>'
|
||||
, $msg['message'] , '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for newest phpMyAdmin version and sets result as a new notice
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function 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)) {
|
||||
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) {
|
||||
$version = $latestCompatible['version'];
|
||||
$date = $latestCompatible['date'];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
$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(
|
||||
$GLOBALS['PMA_Config']->get('PMA_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::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 {
|
||||
self::messagesSet(
|
||||
'notice',
|
||||
$message_id,
|
||||
__('Version check'),
|
||||
__('No newer stable version is available')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Formset processing library
|
||||
*
|
||||
* @package PhpMyAdmin-Setup
|
||||
*/
|
||||
use PhpMyAdmin\Config\FormDisplay;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Response;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
$response = Response::getInstance();
|
||||
$response->generateHeader303('index.php' . Url::getCommonRaw());
|
||||
}
|
||||
|
||||
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()) {
|
||||
$response = Response::getInstance();
|
||||
$response->generateHeader303('index.php' . Url::getCommonRaw());
|
||||
return;
|
||||
}
|
||||
|
||||
// form has errors, show warning
|
||||
$page = isset($_GET['page']) ? $_GET['page'] : '';
|
||||
$formset = isset($_GET['formset']) ? $_GET['formset'] : '';
|
||||
$formId = Core::isValid($_GET['id'], 'numeric') ? $_GET['id'] : '';
|
||||
if ($formId === null && $page == 'servers') {
|
||||
// we've just added a new server, get its id
|
||||
$formId = $form_display->getConfigFile()->getServerCount();
|
||||
}
|
||||
?>
|
||||
<div class="error">
|
||||
<h4><?php echo __('Warning') ?></h4>
|
||||
<?php echo __('Submitted form contains errors') ?><br />
|
||||
<a href="<?php echo Url::getCommon(array('page' => $page, 'formset' => $formset, 'id' => $formId, '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 Url::getCommon() ?>">
|
||||
<?php echo __('Ignore errors') ?>
|
||||
</a>
|
||||
|
||||
<a class="btn" href="<?php echo Url::getCommon(array('page' => $page, 'formset' => $formset, 'id' => $formId, 'mode' => 'edit')) ?>">
|
||||
<?php echo __('Show form') ?>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
@ -1,184 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Various checks and message functions used on index page.
|
||||
*
|
||||
* @package PhpMyAdmin-Setup
|
||||
*/
|
||||
|
||||
use PhpMyAdmin\VersionInformation;
|
||||
use PhpMyAdmin\Sanitize;
|
||||
|
||||
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()
|
||||
{
|
||||
foreach ($_SESSION['messages'] as $type => $messages) {
|
||||
foreach ($messages as $id => $msg) {
|
||||
if (! $msg['fresh'] && $type != 'error') {
|
||||
$extra = ' hiddenmessage';
|
||||
} else {
|
||||
$extra = '';
|
||||
}
|
||||
echo '<div class="' , $type, $extra , '" id="' , $id , '">'
|
||||
, '<h4>' , $msg['title'] , '</h4>'
|
||||
, $msg['message'] , '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'),
|
||||
Sanitize::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')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,19 +5,16 @@
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
namespace PhpMyAdmin\Tests\Setup;
|
||||
|
||||
/*
|
||||
* Include to test
|
||||
*/
|
||||
require_once 'setup/lib/form_processing.lib.php';
|
||||
|
||||
use PhpMyAdmin\Setup\FormProcessing;
|
||||
|
||||
/**
|
||||
* tests for methods under Formset processing library
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PMA_Form_Processing_Test extends PMATestCase
|
||||
class FormProcessingTest extends \PMATestCase
|
||||
{
|
||||
/**
|
||||
* Prepares environment for the test.
|
||||
@ -60,7 +57,7 @@ class PMA_Form_Processing_Test extends PMATestCase
|
||||
->method('getDisplay')
|
||||
->with(true, true);
|
||||
|
||||
PMA_Process_formset($formDisplay);
|
||||
FormProcessing::process($formDisplay);
|
||||
|
||||
// case 2
|
||||
$formDisplay = $this->getMockBuilder('PhpMyAdmin\Config\FormDisplay')
|
||||
@ -79,7 +76,7 @@ class PMA_Form_Processing_Test extends PMATestCase
|
||||
->will($this->returnValue(true));
|
||||
|
||||
ob_start();
|
||||
PMA_Process_formset($formDisplay);
|
||||
FormProcessing::process($formDisplay);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
@ -118,8 +115,6 @@ class PMA_Form_Processing_Test extends PMATestCase
|
||||
->with()
|
||||
->will($this->returnValue(false));
|
||||
|
||||
PMA_Process_formset($formDisplay);
|
||||
|
||||
FormProcessing::process($formDisplay);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,23 +1,21 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for methods under setup/lib/index.lib.php
|
||||
* tests for methods under PhpMyAdmin\Setup\Index
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
namespace PhpMyAdmin\Tests\Setup;
|
||||
|
||||
/*
|
||||
* Include to test
|
||||
*/
|
||||
|
||||
require_once 'setup/lib/index.lib.php';
|
||||
use PhpMyAdmin\Setup\Index as SetupIndex;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
/**
|
||||
* tests for methods under setup/lib/index.lib.php
|
||||
* tests for methods under PhpMyAdmin\Setup\Index
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PMA_SetupIndex_Test extends PHPUnit_Framework_TestCase
|
||||
class IndexTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
@ -30,7 +28,7 @@ class PMA_SetupIndex_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_messagesBegin()
|
||||
* Test for SetupIndex::messagesBegin()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -43,7 +41,7 @@ class PMA_SetupIndex_Test extends PHPUnit_Framework_TestCase
|
||||
)
|
||||
);
|
||||
|
||||
PMA_messagesBegin();
|
||||
SetupIndex::messagesBegin();
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
@ -66,7 +64,7 @@ class PMA_SetupIndex_Test extends PHPUnit_Framework_TestCase
|
||||
// case 2
|
||||
|
||||
unset($_SESSION['messages']);
|
||||
PMA_messagesBegin();
|
||||
SetupIndex::messagesBegin();
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'error' => array(),
|
||||
@ -77,13 +75,13 @@ class PMA_SetupIndex_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_messagesSet
|
||||
* Test for SetupIndex::messagesSet
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPMAmessagesSet()
|
||||
{
|
||||
PMA_messagesSet('type', '123', 'testTitle', 'msg');
|
||||
SetupIndex::messagesSet('type', '123', 'testTitle', 'msg');
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
@ -97,7 +95,7 @@ class PMA_SetupIndex_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_messagesEnd
|
||||
* Test for SetupIndex::messagesEnd
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -110,7 +108,7 @@ class PMA_SetupIndex_Test extends PHPUnit_Framework_TestCase
|
||||
)
|
||||
);
|
||||
|
||||
PMA_messagesEnd();
|
||||
SetupIndex::messagesEnd();
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
@ -126,7 +124,7 @@ class PMA_SetupIndex_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_messagesShowHtml
|
||||
* Test for SetupIndex::messagesShowHtml
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -140,7 +138,7 @@ class PMA_SetupIndex_Test extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
ob_start();
|
||||
PMA_messagesShowHtml();
|
||||
SetupIndex::messagesShowHtml();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
@ -5,15 +5,17 @@
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
namespace PhpMyAdmin\Tests;
|
||||
|
||||
require_once 'libraries/sysinfo.lib.php';
|
||||
use PhpMyAdmin\SysInfo;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
/**
|
||||
* tests for sysinfo library
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PMA_SysInfoTest extends PHPUnit_Framework_TestCase
|
||||
class SysInfoTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test for OS detection
|
||||
@ -29,7 +31,7 @@ class PMA_SysInfoTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
PMA_getSysInfoOs($os)
|
||||
SysInfo::getOs($os)
|
||||
);
|
||||
}
|
||||
|
||||
@ -55,7 +57,7 @@ class PMA_SysInfoTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testGetSysInfo()
|
||||
{
|
||||
$this->assertInstanceOf('PhpMyAdmin\SysInfo', PMA_getSysInfo());
|
||||
$this->assertInstanceOf('PhpMyAdmin\SysInfoBase', SysInfo::get());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,6 +67,6 @@ class PMA_SysInfoTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testGetSysInfoSupported()
|
||||
{
|
||||
$this->assertTrue(PMA_getSysInfo()->supported());
|
||||
$this->assertTrue(SysInfo::get()->supported());
|
||||
}
|
||||
}
|
||||
@ -6,19 +6,19 @@
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PhpMyAdmin\Config\FormDisplayTemplate;
|
||||
use PhpMyAdmin\Theme;
|
||||
|
||||
require_once 'libraries/config/FormDisplay.tpl.php';
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
/**
|
||||
* Tests for FromDisplay.tpl.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
class FormDisplayTemplateTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test for PMA_displayFormTop()
|
||||
* Test for FormDisplayTemplate::displayFormTop()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -26,7 +26,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$_SERVER['REQUEST_URI'] = 'https://www.phpmyadmin.net';
|
||||
$GLOBALS['cfg']['ServerDefault'] = '';
|
||||
$result = PMA_displayFormTop(null, 'posted', array(1));
|
||||
$result = FormDisplayTemplate::displayFormTop(null, 'posted', array(1));
|
||||
|
||||
$this->assertContains(
|
||||
'<form method="get" action="https://www.phpmyadmin.net" ' .
|
||||
@ -56,13 +56,13 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_displayTabsTop()
|
||||
* Test for FormDisplayTemplate::displayTabsTop()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisplayTabsTop()
|
||||
{
|
||||
$result = PMA_displayTabsTop(array('one', 'two'));
|
||||
$result = FormDisplayTemplate::displayTabsTop(array('one', 'two'));
|
||||
|
||||
$this->assertContains(
|
||||
'<ul class="tabs responsivetable"',
|
||||
@ -86,7 +86,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_displayFieldsetTop()
|
||||
* Test for FormDisplayTemplate::displayFieldsetTop()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -95,7 +95,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
$attributes = array('name' => 'attrname');
|
||||
$errors = array('e1', 'e2');
|
||||
|
||||
$result = PMA_displayFieldsetTop("TitleTest", "DescTest", $errors, $attributes);
|
||||
$result = FormDisplayTemplate::displayFieldsetTop("TitleTest", "DescTest", $errors, $attributes);
|
||||
|
||||
$this->assertContains(
|
||||
'<fieldset class="optbox" name="attrname">',
|
||||
@ -129,7 +129,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_displayInput()
|
||||
* Test for FormDisplayTemplate::displayInput()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -144,7 +144,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
$opts['comment'] = "testComment";
|
||||
$opts['comment_warning'] = true;
|
||||
$opts['show_restore_default'] = true;
|
||||
$result = PMA_displayInput(
|
||||
$result = FormDisplayTemplate::displayInput(
|
||||
'test/path', 'testName', 'text', 'val',
|
||||
'desc', false, $opts
|
||||
);
|
||||
@ -214,7 +214,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
$opts['userprefs_comment'] = 'userprefsComment';
|
||||
$opts['userprefs_allow'] = true;
|
||||
|
||||
$result = PMA_displayInput(
|
||||
$result = FormDisplayTemplate::displayInput(
|
||||
'test/path', 'testName', 'checkbox', 'val',
|
||||
'', false, $opts
|
||||
);
|
||||
@ -252,7 +252,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
$opts = array();
|
||||
$opts['errors'] = array();
|
||||
|
||||
$result = PMA_displayInput(
|
||||
$result = FormDisplayTemplate::displayInput(
|
||||
'test/path', 'testName', 'short_text', 'val',
|
||||
'', true, $opts
|
||||
);
|
||||
@ -264,7 +264,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
// number_text
|
||||
$result = PMA_displayInput(
|
||||
$result = FormDisplayTemplate::displayInput(
|
||||
'test/path', 'testName', 'number_text', 'val',
|
||||
'', true, $opts
|
||||
);
|
||||
@ -283,7 +283,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
'key1' => true,
|
||||
'key2' => false,
|
||||
);
|
||||
$result = PMA_displayInput(
|
||||
$result = FormDisplayTemplate::displayInput(
|
||||
'test/path', 'testName', 'select', true,
|
||||
'', true, $opts
|
||||
);
|
||||
@ -315,7 +315,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
'key1' => true,
|
||||
'key2' => false,
|
||||
);
|
||||
$result = PMA_displayInput(
|
||||
$result = FormDisplayTemplate::displayInput(
|
||||
'test/path', 'testName', 'select', false,
|
||||
'', true, $opts
|
||||
);
|
||||
@ -332,7 +332,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
// list
|
||||
$result = PMA_displayInput(
|
||||
$result = FormDisplayTemplate::displayInput(
|
||||
'test/path', 'testName', 'list', array('foo', 'bar'),
|
||||
'', true, $opts
|
||||
);
|
||||
@ -344,21 +344,21 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_displayGroupHeader()
|
||||
* Test for FormDisplayTemplate::displayGroupHeader()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisplayGroupHeader()
|
||||
{
|
||||
$this->assertNull(
|
||||
PMA_displayGroupHeader('')
|
||||
FormDisplayTemplate::displayGroupHeader('')
|
||||
);
|
||||
|
||||
$GLOBALS['_FormDisplayGroup'] = 3;
|
||||
|
||||
$GLOBALS['PMA_Config']->set('is_setup', true);
|
||||
|
||||
$result = PMA_displayGroupHeader('headerText');
|
||||
$result = FormDisplayTemplate::displayGroupHeader('headerText');
|
||||
|
||||
$this->assertContains(
|
||||
'<tr class="group-header group-header-4">',
|
||||
@ -370,7 +370,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
|
||||
$GLOBALS['_FormDisplayGroup'] = 3;
|
||||
|
||||
$result = PMA_displayGroupHeader('headerText');
|
||||
$result = FormDisplayTemplate::displayGroupHeader('headerText');
|
||||
|
||||
$this->assertContains(
|
||||
'<tr class="group-header group-header-4">',
|
||||
@ -380,14 +380,14 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_displayGroupFooter()
|
||||
* Test for FormDisplayTemplate::displayGroupFooter()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisplayGroupFooter()
|
||||
{
|
||||
$GLOBALS['_FormDisplayGroup'] = 3;
|
||||
PMA_displayGroupFooter();
|
||||
FormDisplayTemplate::displayGroupFooter();
|
||||
$this->assertEquals(
|
||||
2,
|
||||
$GLOBALS['_FormDisplayGroup']
|
||||
@ -395,7 +395,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_displayFieldsetBottom()
|
||||
* Test for FormDisplayTemplate::displayFieldsetBottom()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -404,7 +404,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
// with PMA_SETUP
|
||||
$GLOBALS['PMA_Config']->set('is_setup', true);
|
||||
|
||||
$result = PMA_displayFieldsetBottom();
|
||||
$result = FormDisplayTemplate::displayFieldsetBottom();
|
||||
|
||||
$this->assertContains(
|
||||
'<td colspan="3" class="lastrow">',
|
||||
@ -429,7 +429,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
// without PMA_SETUP
|
||||
$GLOBALS['PMA_Config']->set('is_setup', false);
|
||||
|
||||
$result = PMA_displayFieldsetBottom();
|
||||
$result = FormDisplayTemplate::displayFieldsetBottom();
|
||||
|
||||
$this->assertContains(
|
||||
'<td colspan="2" class="lastrow">',
|
||||
@ -438,13 +438,13 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_displayFieldsetBottomSimple()
|
||||
* Test for FormDisplayTemplate::displayFieldsetBottomSimple()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisplayFieldsetBottomSimple()
|
||||
{
|
||||
$result = PMA_displayFieldsetBottomSimple();
|
||||
$result = FormDisplayTemplate::displayFieldsetBottomSimple();
|
||||
$this->assertEquals(
|
||||
'</table></fieldset>',
|
||||
$result
|
||||
@ -452,13 +452,13 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_displayTabsBottom()
|
||||
* Test for FormDisplayTemplate::displayTabsBottom()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisplayTabsBottom()
|
||||
{
|
||||
$result = PMA_displayTabsBottom();
|
||||
$result = FormDisplayTemplate::displayTabsBottom();
|
||||
$this->assertEquals(
|
||||
"</div>\n",
|
||||
$result
|
||||
@ -466,13 +466,13 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_displayFormBottom()
|
||||
* Test for FormDisplayTemplate::displayFormBottom()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisplayFormBottom()
|
||||
{
|
||||
$result = PMA_displayFormBottom();
|
||||
$result = FormDisplayTemplate::displayFormBottom();
|
||||
$this->assertEquals(
|
||||
"</form>\n",
|
||||
$result
|
||||
@ -480,7 +480,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_addJsValidate()
|
||||
* Test for FormDisplayTemplate::addJsValidate()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -493,7 +493,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
|
||||
$js = array();
|
||||
|
||||
PMA_addJsValidate('testID', $validators, $js);
|
||||
FormDisplayTemplate::addJsValidate('testID', $validators, $js);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
@ -507,17 +507,17 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_displayJavascript()
|
||||
* Test for FormDisplayTemplate::displayJavascript()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisplayJavascript()
|
||||
{
|
||||
$this->assertNull(
|
||||
PMA_displayJavascript(array())
|
||||
FormDisplayTemplate::displayJavascript(array())
|
||||
);
|
||||
|
||||
$result = PMA_displayJavascript(array('var i = 1', 'i++'));
|
||||
$result = FormDisplayTemplate::displayJavascript(array('var i = 1', 'i++'));
|
||||
|
||||
$this->assertEquals(
|
||||
'<script type="text/javascript">' . "\n"
|
||||
@ -536,7 +536,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_displayErrors()
|
||||
* Test for FormDisplayTemplate::displayErrors()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -544,7 +544,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$errors = array('<err1>', '&err2');
|
||||
|
||||
$result = PMA_displayErrors('err"Name1"', $errors);
|
||||
$result = FormDisplayTemplate::displayErrors('err"Name1"', $errors);
|
||||
|
||||
$this->assertEquals(
|
||||
'<dl><dt>err"Name1"</dt>' .
|
||||
@ -7,11 +7,10 @@
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Display\ChangePassword;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Server\Privileges;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\UserPassword;
|
||||
|
||||
/**
|
||||
* Gets some core libraries
|
||||
@ -32,7 +31,7 @@ if (! $GLOBALS['cfg']['ShowChgPassword']) {
|
||||
$GLOBALS['cfg']['ShowChgPassword'] = $GLOBALS['dbi']->selectDb('mysql');
|
||||
}
|
||||
if ($cfg['Server']['auth_type'] == 'config' || ! $cfg['ShowChgPassword']) {
|
||||
PhpMyAdmin\Message::error(
|
||||
Message::error(
|
||||
__('You don\'t have sufficient privileges to be here right now!')
|
||||
)->display();
|
||||
exit;
|
||||
@ -48,12 +47,12 @@ if (isset($_REQUEST['nopass'])) {
|
||||
} else {
|
||||
$password = $_REQUEST['pma_pw'];
|
||||
}
|
||||
$change_password_message = PMA_setChangePasswordMsg();
|
||||
$change_password_message = UserPassword::setChangePasswordMsg();
|
||||
$msg = $change_password_message['msg'];
|
||||
if (! $change_password_message['error']) {
|
||||
PMA_changePassword($password, $msg, $change_password_message);
|
||||
UserPassword::changePassword($password, $msg, $change_password_message);
|
||||
} else {
|
||||
PMA_getChangePassMessage($change_password_message);
|
||||
UserPassword::getChangePassMessage($change_password_message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,231 +69,3 @@ if (isset($msg)) {
|
||||
|
||||
echo ChangePassword::getHtml('change_pw', $username, $hostname);
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Send the message as an ajax request
|
||||
*
|
||||
* @param array $change_password_message Message to display
|
||||
* @param string $sql_query SQL query executed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_getChangePassMessage($change_password_message, $sql_query = '')
|
||||
{
|
||||
$response = Response::getInstance();
|
||||
if ($response->isAjax()) {
|
||||
/**
|
||||
* If in an Ajax request, we don't need to show the rest of the page
|
||||
*/
|
||||
if ($change_password_message['error']) {
|
||||
$response->addJSON('message', $change_password_message['msg']);
|
||||
$response->setRequestStatus(false);
|
||||
} else {
|
||||
$sql_query = PhpMyAdmin\Util::getMessage(
|
||||
$change_password_message['msg'],
|
||||
$sql_query,
|
||||
'success'
|
||||
);
|
||||
$response->addJSON('message', $sql_query);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the message
|
||||
*
|
||||
* @return array error value and message
|
||||
*/
|
||||
function PMA_setChangePasswordMsg()
|
||||
{
|
||||
$error = false;
|
||||
$message = PhpMyAdmin\Message::success(__('The profile has been updated.'));
|
||||
|
||||
if (($_REQUEST['nopass'] != '1')) {
|
||||
if (strlen($_REQUEST['pma_pw']) === 0 || strlen($_REQUEST['pma_pw2']) === 0) {
|
||||
$message = PhpMyAdmin\Message::error(__('The password is empty!'));
|
||||
$error = true;
|
||||
} elseif ($_REQUEST['pma_pw'] !== $_REQUEST['pma_pw2']) {
|
||||
$message = PhpMyAdmin\Message::error(
|
||||
__('The passwords aren\'t the same!')
|
||||
);
|
||||
$error = true;
|
||||
} elseif (strlen($_REQUEST['pma_pw']) > 256) {
|
||||
$message = PMA_Message::error(__('Password is too long!'));
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
return array('error' => $error, 'msg' => $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the password
|
||||
*
|
||||
* @param string $password New password
|
||||
* @param string $message Message
|
||||
* @param array $change_password_message Message to show
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_changePassword($password, $message, $change_password_message)
|
||||
{
|
||||
global $auth_plugin;
|
||||
|
||||
$hashing_function = PMA_changePassHashingFunction();
|
||||
|
||||
list($username, $hostname) = $GLOBALS['dbi']->getCurrentUserAndHost();
|
||||
|
||||
$serverType = PhpMyAdmin\Util::getServerType();
|
||||
$serverVersion = $GLOBALS['dbi']->getVersion();
|
||||
|
||||
if (isset($_REQUEST['authentication_plugin'])
|
||||
&& ! empty($_REQUEST['authentication_plugin'])
|
||||
) {
|
||||
$orig_auth_plugin = $_REQUEST['authentication_plugin'];
|
||||
} else {
|
||||
$orig_auth_plugin = Privileges::getCurrentAuthenticationPlugin(
|
||||
'change', $username, $hostname
|
||||
);
|
||||
}
|
||||
|
||||
$sql_query = 'SET password = '
|
||||
. (($password == '') ? '\'\'' : $hashing_function . '(\'***\')');
|
||||
|
||||
if ($serverType == 'MySQL'
|
||||
&& $serverVersion >= 50706
|
||||
) {
|
||||
$sql_query = 'ALTER USER \'' . $username . '\'@\'' . $hostname
|
||||
. '\' IDENTIFIED WITH ' . $orig_auth_plugin . ' BY '
|
||||
. (($password == '') ? '\'\'' : '\'***\'');
|
||||
} else if (($serverType == 'MySQL'
|
||||
&& $serverVersion >= 50507)
|
||||
|| ($serverType == 'MariaDB'
|
||||
&& $serverVersion >= 50200)
|
||||
) {
|
||||
// For MySQL versions 5.5.7+ and MariaDB versions 5.2+,
|
||||
// explicitly set value of `old_passwords` so that
|
||||
// it does not give an error while using
|
||||
// the PASSWORD() function
|
||||
if ($orig_auth_plugin == 'sha256_password') {
|
||||
$value = 2;
|
||||
} else {
|
||||
$value = 0;
|
||||
}
|
||||
$GLOBALS['dbi']->tryQuery('SET `old_passwords` = ' . $value . ';');
|
||||
}
|
||||
|
||||
PMA_changePassUrlParamsAndSubmitQuery(
|
||||
$username, $hostname, $password,
|
||||
$sql_query, $hashing_function, $orig_auth_plugin
|
||||
);
|
||||
|
||||
$auth_plugin->handlePasswordChange($password);
|
||||
PMA_getChangePassMessage($change_password_message, $sql_query);
|
||||
PMA_changePassDisplayPage($message, $sql_query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the hashing function
|
||||
*
|
||||
* @return string $hashing_function
|
||||
*/
|
||||
function PMA_changePassHashingFunction()
|
||||
{
|
||||
if (Core::isValid(
|
||||
$_REQUEST['authentication_plugin'], 'identical', 'mysql_old_password'
|
||||
)) {
|
||||
$hashing_function = 'OLD_PASSWORD';
|
||||
} else {
|
||||
$hashing_function = 'PASSWORD';
|
||||
}
|
||||
return $hashing_function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes password for a user
|
||||
*
|
||||
* @param string $username Username
|
||||
* @param string $hostname Hostname
|
||||
* @param string $password Password
|
||||
* @param string $sql_query SQL query
|
||||
* @param string $hashing_function Hashing function
|
||||
* @param string $orig_auth_plugin Original Authentication Plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_changePassUrlParamsAndSubmitQuery(
|
||||
$username, $hostname, $password, $sql_query, $hashing_function, $orig_auth_plugin
|
||||
) {
|
||||
$err_url = 'user_password.php' . Url::getCommon();
|
||||
|
||||
$serverType = PhpMyAdmin\Util::getServerType();
|
||||
$serverVersion = $GLOBALS['dbi']->getVersion();
|
||||
|
||||
if ($serverType == 'MySQL' && $serverVersion >= 50706) {
|
||||
$local_query = 'ALTER USER \'' . $username . '\'@\'' . $hostname . '\''
|
||||
. ' IDENTIFIED with ' . $orig_auth_plugin . ' BY '
|
||||
. (($password == '')
|
||||
? '\'\''
|
||||
: '\'' . $GLOBALS['dbi']->escapeString($password) . '\'');
|
||||
} else if ($serverType == 'MariaDB'
|
||||
&& $serverVersion >= 50200
|
||||
&& $serverVersion < 100100
|
||||
&& $orig_auth_plugin !== ''
|
||||
) {
|
||||
if ($orig_auth_plugin == 'mysql_native_password') {
|
||||
// Set the hashing method used by PASSWORD()
|
||||
// to be 'mysql_native_password' type
|
||||
$GLOBALS['dbi']->tryQuery('SET old_passwords = 0;');
|
||||
} else if ($orig_auth_plugin == 'sha256_password') {
|
||||
// Set the hashing method used by PASSWORD()
|
||||
// to be 'sha256_password' type
|
||||
$GLOBALS['dbi']->tryQuery('SET `old_passwords` = 2;');
|
||||
}
|
||||
|
||||
$hashedPassword = Privileges::getHashedPassword($_POST['pma_pw']);
|
||||
|
||||
$local_query = "UPDATE `mysql`.`user` SET"
|
||||
. " `authentication_string` = '" . $hashedPassword
|
||||
. "', `Password` = '', "
|
||||
. " `plugin` = '" . $orig_auth_plugin . "'"
|
||||
. " WHERE `User` = '" . $username . "' AND Host = '"
|
||||
. $hostname . "';";
|
||||
} else {
|
||||
$local_query = 'SET password = ' . (($password == '')
|
||||
? '\'\''
|
||||
: $hashing_function . '(\''
|
||||
. $GLOBALS['dbi']->escapeString($password) . '\')');
|
||||
}
|
||||
if (! @$GLOBALS['dbi']->tryQuery($local_query)) {
|
||||
PhpMyAdmin\Util::mysqlDie(
|
||||
$GLOBALS['dbi']->getError(),
|
||||
$sql_query,
|
||||
false,
|
||||
$err_url
|
||||
);
|
||||
}
|
||||
|
||||
// Flush privileges after successful password change
|
||||
$GLOBALS['dbi']->tryQuery("FLUSH PRIVILEGES;");
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the page
|
||||
*
|
||||
* @param string $message Message
|
||||
* @param string $sql_query SQL query
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_changePassDisplayPage($message, $sql_query)
|
||||
{
|
||||
echo '<h1>' , __('Change password') , '</h1>' , "\n\n";
|
||||
echo PhpMyAdmin\Util::getMessage(
|
||||
$message, $sql_query, 'success'
|
||||
);
|
||||
echo '<a href="index.php' , Url::getCommon()
|
||||
, ' target="_parent">' , "\n"
|
||||
, '<strong>' , __('Back') , '</strong></a>';
|
||||
exit;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user