init web ems all

This commit is contained in:
agtuser
2024-09-27 17:13:36 +08:00
parent 81c97acbe9
commit 5cc56f8078
4263 changed files with 798779 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,125 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Code for displaying server selection
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Server;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
/**
* PhpMyAdmin\Server\Select class
*
* @package PhpMyAdmin
*/
class Select
{
/**
* Renders the server selection in list or selectbox form, or option tags only
*
* @param boolean $not_only_options whether to include form tags or not
* @param boolean $omit_fieldset whether to omit fieldset tag or not
*
* @return string
*/
public static function render($not_only_options, $omit_fieldset)
{
$retval = '';
// Show as list?
if ($not_only_options) {
$list = $GLOBALS['cfg']['DisplayServersList'];
$not_only_options =! $list;
} else {
$list = false;
}
if ($not_only_options) {
$retval .= '<form method="post" action="'
. Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabServer'], 'server'
)
. '" class="disableAjax">';
if (! $omit_fieldset) {
$retval .= '<fieldset>';
}
$retval .= Url::getHiddenFields(array());
$retval .= '<label for="select_server">'
. __('Current server:') . '</label> ';
$retval .= '<select name="server" id="select_server" class="autosubmit">';
$retval .= '<option value="">(' . __('Servers') . ') ...</option>' . "\n";
} elseif ($list) {
$retval .= __('Current server:') . '<br />';
$retval .= '<ul id="list_server">';
}
foreach ($GLOBALS['cfg']['Servers'] as $key => $server) {
if (empty($server['host'])) {
continue;
}
if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) {
$selected = 1;
} else {
$selected = 0;
}
if (!empty($server['verbose'])) {
$label = $server['verbose'];
} else {
$label = $server['host'];
if (!empty($server['port'])) {
$label .= ':' . $server['port'];
}
}
if (! empty($server['only_db'])) {
if (! is_array($server['only_db'])) {
$label .= ' - ' . $server['only_db'];
// try to avoid displaying a too wide selector
} elseif (count($server['only_db']) < 4) {
$label .= ' - ' . implode(', ', $server['only_db']);
}
}
if (!empty($server['user']) && $server['auth_type'] == 'config') {
$label .= ' (' . $server['user'] . ')';
}
if ($list) {
$retval .= '<li>';
if ($selected) {
$retval .= '<strong>' . htmlspecialchars($label) . '</strong>';
} else {
$retval .= '<a class="disableAjax item" href="'
. Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabServer'], 'server'
)
. Url::getCommon(array('server' => $key))
. '" >' . htmlspecialchars($label) . '</a>';
}
$retval .= '</li>';
} else {
$retval .= '<option value="' . $key . '" '
. ($selected ? ' selected="selected"' : '') . '>'
. htmlspecialchars($label) . '</option>' . "\n";
}
} // end while
if ($not_only_options) {
$retval .= '</select>';
if (! $omit_fieldset) {
$retval .= '</fieldset>';
}
$retval .= '</form>';
} elseif ($list) {
$retval .= '</ul>';
}
return $retval;
}
}

View File

@@ -0,0 +1,335 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* functions for displaying server status
*
* @usedby server_status.php
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Server;
use PhpMyAdmin\ReplicationGui;
use PhpMyAdmin\Server\Status\Data;
use PhpMyAdmin\Util;
/**
* PhpMyAdmin\Server\Status
*
* @package PhpMyAdmin
*/
class Status
{
/**
* Prints server status information: processes, connections and traffic
*
* @param Data $serverStatusData Server status data
*
* @return string
*/
public static function getHtml(Data $serverStatusData)
{
//display the server state General Information
$retval = self::getHtmlForServerStateGeneralInfo($serverStatusData);
//display the server state traffic information
$retval .= self::getHtmlForServerStateTraffic($serverStatusData);
//display the server state connection information
$retval .= self::getHtmlForServerStateConnections($serverStatusData);
// display replication information
if ($GLOBALS['replication_info']['master']['status']
|| $GLOBALS['replication_info']['slave']['status']
) {
$retval .= self::getHtmlForReplicationInfo();
}
return $retval;
}
/**
* Prints server state General information
*
* @param Data $serverStatusData Server status data
*
* @return string
*/
public static function getHtmlForServerStateGeneralInfo(Data $serverStatusData)
{
$start_time = $GLOBALS['dbi']->fetchValue(
'SELECT UNIX_TIMESTAMP() - ' . $serverStatusData->status['Uptime']
);
$retval = '<h3>';
$bytes_received = $serverStatusData->status['Bytes_received'];
$bytes_sent = $serverStatusData->status['Bytes_sent'];
$retval .= sprintf(
__('Network traffic since startup: %s'),
implode(
' ',
Util::formatByteDown(
$bytes_received + $bytes_sent,
3,
1
)
)
);
$retval .= '</h3>';
$retval .= '<p>';
$retval .= sprintf(
__('This MySQL server has been running for %1$s. It started up on %2$s.'),
Util::timespanFormat($serverStatusData->status['Uptime']),
Util::localisedDate($start_time)
) . "\n";
$retval .= '</p>';
return $retval;
}
/**
* Returns HTML to display replication information
*
* @return string HTML on replication
*/
public static function getHtmlForReplicationInfo()
{
$retval = '<p class="notice clearfloat">';
if ($GLOBALS['replication_info']['master']['status']
&& $GLOBALS['replication_info']['slave']['status']
) {
$retval .= __(
'This MySQL server works as <b>master</b> and '
. '<b>slave</b> in <b>replication</b> process.'
);
} elseif ($GLOBALS['replication_info']['master']['status']) {
$retval .= __(
'This MySQL server works as <b>master</b> '
. 'in <b>replication</b> process.'
);
} elseif ($GLOBALS['replication_info']['slave']['status']) {
$retval .= __(
'This MySQL server works as <b>slave</b> '
. 'in <b>replication</b> process.'
);
}
$retval .= '</p>';
/*
* if the server works as master or slave in replication process,
* display useful information
*/
$retval .= '<hr class="clearfloat" />';
$retval .= '<h3><a name="replication">';
$retval .= __('Replication status');
$retval .= '</a></h3>';
foreach ($GLOBALS['replication_types'] as $type) {
if (isset($GLOBALS['replication_info'][$type]['status'])
&& $GLOBALS['replication_info'][$type]['status']
) {
$retval .= ReplicationGui::getHtmlForReplicationStatusTable($type);
}
}
return $retval;
}
/**
* Prints server state traffic information
*
* @param Data $serverStatusData Server status data
*
* @return string
*/
public static function getHtmlForServerStateTraffic(Data $serverStatusData)
{
$hour_factor = 3600 / $serverStatusData->status['Uptime'];
$retval = '<table id="serverstatustraffic" class="width100 data noclick">';
$retval .= '<thead>';
$retval .= '<tr>';
$retval .= '<th>';
$retval .= __('Traffic') . '&nbsp;';
$retval .= Util::showHint(
__(
'On a busy server, the byte counters may overrun, so those statistics '
. 'as reported by the MySQL server may be incorrect.'
)
);
$retval .= '</th>';
$retval .= '<th>#</th>';
$retval .= '<th>&oslash; ' . __('per hour') . '</th>';
$retval .= '</tr>';
$retval .= '</thead>';
$retval .= '<tbody>';
$retval .= '<tr>';
$retval .= '<th class="name">' . __('Received') . '</th>';
$retval .= '<td class="value">';
$retval .= implode(
' ',
Util::formatByteDown(
$serverStatusData->status['Bytes_received'], 3, 1
)
);
$retval .= '</td>';
$retval .= '<td class="value">';
$retval .= implode(
' ',
Util::formatByteDown(
$serverStatusData->status['Bytes_received'] * $hour_factor, 3, 1
)
);
$retval .= '</td>';
$retval .= '</tr>';
$retval .= '<tr>';
$retval .= '<th class="name">' . __('Sent') . '</th>';
$retval .= '<td class="value">';
$retval .= implode(
' ',
Util::formatByteDown(
$serverStatusData->status['Bytes_sent'], 3, 1
)
);
$retval .= '</td>';
$retval .= '<td class="value">';
$retval .= implode(
' ',
Util::formatByteDown(
$serverStatusData->status['Bytes_sent'] * $hour_factor, 3, 1
)
);
$retval .= '</td>';
$retval .= '</tr>';
$retval .= '<tr>';
$retval .= '<th class="name">' . __('Total') . '</th>';
$retval .= '<td class="value">';
$bytes_received = $serverStatusData->status['Bytes_received'];
$bytes_sent = $serverStatusData->status['Bytes_sent'];
$retval .= implode(
' ',
Util::formatByteDown(
$bytes_received + $bytes_sent, 3, 1
)
);
$retval .= '</td>';
$retval .= '<td class="value">';
$bytes_received = $serverStatusData->status['Bytes_received'];
$bytes_sent = $serverStatusData->status['Bytes_sent'];
$retval .= implode(
' ',
Util::formatByteDown(
($bytes_received + $bytes_sent) * $hour_factor, 3, 1
)
);
$retval .= '</td>';
$retval .= '</tr>';
$retval .= '</tbody>';
$retval .= '</table>';
return $retval;
}
/**
* Prints server state connections information
*
* @param Data $serverStatusData Server status data
*
* @return string
*/
public static function getHtmlForServerStateConnections(Data $serverStatusData)
{
$hour_factor = 3600 / $serverStatusData->status['Uptime'];
$retval = '<table id="serverstatusconnections" class="width100 data noclick">';
$retval .= '<thead>';
$retval .= '<tr>';
$retval .= '<th>' . __('Connections') . '</th>';
$retval .= '<th>#</th>';
$retval .= '<th>&oslash; ' . __('per hour') . '</th>';
$retval .= '<th>%</th>';
$retval .= '</tr>';
$retval .= '</thead>';
$retval .= '<tbody>';
$retval .= '<tr>';
$retval .= '<th class="name">' . __('Max. concurrent connections') . '</th>';
$retval .= '<td class="value">';
$retval .= Util::formatNumber(
$serverStatusData->status['Max_used_connections'], 0
);
$retval .= '</td>';
$retval .= '<td class="value">--- </td>';
$retval .= '<td class="value">--- </td>';
$retval .= '</tr>';
$retval .= '<tr>';
$retval .= '<th class="name">' . __('Failed attempts') . '</th>';
$retval .= '<td class="value">';
$retval .= Util::formatNumber(
$serverStatusData->status['Aborted_connects'], 4, 1, true
);
$retval .= '</td>';
$retval .= '<td class="value">';
$retval .= Util::formatNumber(
$serverStatusData->status['Aborted_connects'] * $hour_factor, 4, 2, true
);
$retval .= '</td>';
$retval .= '<td class="value">';
if ($serverStatusData->status['Connections'] > 0) {
$abortNum = $serverStatusData->status['Aborted_connects'];
$connectNum = $serverStatusData->status['Connections'];
$retval .= Util::formatNumber(
$abortNum * 100 / $connectNum,
0, 2, true
);
$retval .= '%';
} else {
$retval .= '--- ';
}
$retval .= '</td>';
$retval .= '</tr>';
$retval .= '<tr>';
$retval .= '<th class="name">' . __('Aborted') . '</th>';
$retval .= '<td class="value">';
$retval .= Util::formatNumber(
$serverStatusData->status['Aborted_clients'], 4, 1, true
);
$retval .= '</td>';
$retval .= '<td class="value">';
$retval .= Util::formatNumber(
$serverStatusData->status['Aborted_clients'] * $hour_factor, 4, 2, true
);
$retval .= '</td>';
$retval .= '<td class="value">';
if ($serverStatusData->status['Connections'] > 0) {
$abortNum = $serverStatusData->status['Aborted_clients'];
$connectNum = $serverStatusData->status['Connections'];
$retval .= Util::formatNumber(
$abortNum * 100 / $connectNum,
0, 2, true
);
$retval .= '%';
} else {
$retval .= '--- ';
}
$retval .= '</td>';
$retval .= '</tr>';
$retval .= '<tr>';
$retval .= '<th class="name">' . __('Total') . '</th>';
$retval .= '<td class="value">';
$retval .= Util::formatNumber(
$serverStatusData->status['Connections'], 4, 0
);
$retval .= '</td>';
$retval .= '<td class="value">';
$retval .= Util::formatNumber(
$serverStatusData->status['Connections'] * $hour_factor, 4, 2
);
$retval .= '</td>';
$retval .= '<td class="value">';
$retval .= Util::formatNumber(100, 0, 2);
$retval .= '%</td>';
$retval .= '</tr>';
$retval .= '</tbody>';
$retval .= '</table>';
return $retval;
}
}

View File

@@ -0,0 +1,73 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* functions for displaying server status sub item: advisor
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Server\Status;
use PhpMyAdmin\Advisor as PmaAdvisor;
use PhpMyAdmin\Util;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
/**
* PhpMyAdmin\Server\Status\Advisor class
*
* @package PhpMyAdmin
*/
class Advisor
{
/**
* Returns html with PhpMyAdmin\Advisor
*
* @return string
*/
public static function getHtml()
{
$output = '<a href="#openAdvisorInstructions">';
$output .= Util::getIcon('b_help', __('Instructions'));
$output .= '</a>';
$output .= '<div id="statustabs_advisor"></div>';
$output .= '<div id="advisorInstructionsDialog" class="hide">';
$output .= '<p>';
$output .= __(
'The Advisor system can provide recommendations '
. 'on server variables by analyzing the server status variables.'
);
$output .= '</p>';
$output .= '<p>';
$output .= __(
'Do note however that this system provides recommendations '
. 'based on simple calculations and by rule of thumb which may '
. 'not necessarily apply to your system.'
);
$output .= '</p>';
$output .= '<p>';
$output .= __(
'Prior to changing any of the configuration, be sure to know '
. 'what you are changing (by reading the documentation) and how '
. 'to undo the change. Wrong tuning can have a very negative '
. 'effect on performance.'
);
$output .= '</p>';
$output .= '<p>';
$output .= __(
'The best way to tune your system would be to change only one '
. 'setting at a time, observe or benchmark your database, and undo '
. 'the change if there was no clearly measurable improvement.'
);
$output .= '</p>';
$output .= '</div>';
$output .= '<div id="advisorData" class="hide">';
$advisor = new PmaAdvisor($GLOBALS['dbi'], new ExpressionLanguage());
$output .= htmlspecialchars(
json_encode(
$advisor->run()
)
);
$output .= '</div>';
return $output;
}
}

View File

@@ -0,0 +1,504 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* PhpMyAdmin\Server\Status\Data class
* Used by server_status_*.php pages
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Server\Status;
use PhpMyAdmin\Url;
/**
* This class provides data about the server status
*
* All properties of the class are read-only
*
* TODO: Use lazy initialisation for some of the properties
* since not all of the server_status_*.php pages need
* all the data that this class provides.
*
* @package PhpMyAdmin
*/
class Data
{
public $status;
public $sections;
public $variables;
public $used_queries;
public $allocationMap;
public $links;
public $db_isLocal;
public $section;
public $sectionUsed;
public $selfUrl;
public $dataLoaded;
/**
* An empty setter makes the above properties read-only
*
* @param string $a key
* @param mixed $b value
*
* @return void
*/
public function __set($a, $b)
{
// Discard everything
}
/**
* Gets the allocations for constructor
*
* @return array
*/
private function _getAllocations()
{
return array(
// variable name => section
// variable names match when they begin with the given string
'Com_' => 'com',
'Innodb_' => 'innodb',
'Ndb_' => 'ndb',
'Handler_' => 'handler',
'Qcache_' => 'qcache',
'Threads_' => 'threads',
'Slow_launch_threads' => 'threads',
'Binlog_cache_' => 'binlog_cache',
'Created_tmp_' => 'created_tmp',
'Key_' => 'key',
'Delayed_' => 'delayed',
'Not_flushed_delayed_rows' => 'delayed',
'Flush_commands' => 'query',
'Last_query_cost' => 'query',
'Slow_queries' => 'query',
'Queries' => 'query',
'Prepared_stmt_count' => 'query',
'Select_' => 'select',
'Sort_' => 'sort',
'Open_tables' => 'table',
'Opened_tables' => 'table',
'Open_table_definitions' => 'table',
'Opened_table_definitions' => 'table',
'Table_locks_' => 'table',
'Rpl_status' => 'repl',
'Slave_' => 'repl',
'Tc_' => 'tc',
'Ssl_' => 'ssl',
'Open_files' => 'files',
'Open_streams' => 'files',
'Opened_files' => 'files',
);
}
/**
* Gets the sections for constructor
*
* @return array
*/
private function _getSections()
{
return array(
// section => section name (description)
'com' => 'Com',
'query' => __('SQL query'),
'innodb' => 'InnoDB',
'ndb' => 'NDB',
'handler' => __('Handler'),
'qcache' => __('Query cache'),
'threads' => __('Threads'),
'binlog_cache' => __('Binary log'),
'created_tmp' => __('Temporary data'),
'delayed' => __('Delayed inserts'),
'key' => __('Key cache'),
'select' => __('Joins'),
'repl' => __('Replication'),
'sort' => __('Sorting'),
'table' => __('Tables'),
'tc' => __('Transaction coordinator'),
'files' => __('Files'),
'ssl' => 'SSL',
'other' => __('Other')
);
}
/**
* Gets the links for constructor
*
* @return array
*/
private function _getLinks()
{
$links = array();
// variable or section name => (name => url)
$links['table'][__('Flush (close) all tables')] = [
'url' => $this->selfUrl,
'params' => Url::getCommon(['flush' => 'TABLES'], ''),
];
$links['table'][__('Show open tables')] = [
'url' => 'sql.php',
'params' => Url::getCommon([
'sql_query' => 'SHOW OPEN TABLES',
'goto' => $this->selfUrl,
], ''),
];
if ($GLOBALS['replication_info']['master']['status']) {
$links['repl'][__('Show slave hosts')] = [
'url' => 'sql.php',
'params' => Url::getCommon([
'sql_query' => 'SHOW SLAVE HOSTS',
'goto' => $this->selfUrl,
], ''),
];
$links['repl'][__('Show master status')] = [
'url' => '#replication_master',
'params' => '',
];
}
if ($GLOBALS['replication_info']['slave']['status']) {
$links['repl'][__('Show slave status')] = [
'url' => '#replication_slave',
'params' => '',
];
}
$links['repl']['doc'] = 'replication';
$links['qcache'][__('Flush query cache')] = [
'url' => $this->selfUrl,
'params' => Url::getCommon(['flush' => 'QUERY CACHE'], ''),
];
$links['qcache']['doc'] = 'query_cache';
$links['threads']['doc'] = 'mysql_threads';
$links['key']['doc'] = 'myisam_key_cache';
$links['binlog_cache']['doc'] = 'binary_log';
$links['Slow_queries']['doc'] = 'slow_query_log';
$links['innodb'][__('Variables')] = [
'url' => 'server_engines.php',
'params' => Url::getCommon(['engine' => 'InnoDB'], ''),
];
$links['innodb'][__('InnoDB Status')] = [
'url' => 'server_engines.php',
'params' => Url::getCommon([
'engine' => 'InnoDB',
'page' => 'Status',
], ''),
];
$links['innodb']['doc'] = 'innodb';
return($links);
}
/**
* Calculate some values
*
* @param array $server_status contains results of SHOW GLOBAL STATUS
* @param array $server_variables contains results of SHOW GLOBAL VARIABLES
*
* @return array $server_status
*/
private function _calculateValues(array $server_status, array $server_variables)
{
// Key_buffer_fraction
if (isset($server_status['Key_blocks_unused'])
&& isset($server_variables['key_cache_block_size'])
&& isset($server_variables['key_buffer_size'])
&& $server_variables['key_buffer_size'] != 0
) {
$server_status['Key_buffer_fraction_%']
= 100
- $server_status['Key_blocks_unused']
* $server_variables['key_cache_block_size']
/ $server_variables['key_buffer_size']
* 100;
} elseif (isset($server_status['Key_blocks_used'])
&& isset($server_variables['key_buffer_size'])
&& $server_variables['key_buffer_size'] != 0
) {
$server_status['Key_buffer_fraction_%']
= $server_status['Key_blocks_used']
* 1024
/ $server_variables['key_buffer_size'];
}
// Ratio for key read/write
if (isset($server_status['Key_writes'])
&& isset($server_status['Key_write_requests'])
&& $server_status['Key_write_requests'] > 0
) {
$key_writes = $server_status['Key_writes'];
$key_write_requests = $server_status['Key_write_requests'];
$server_status['Key_write_ratio_%']
= 100 * $key_writes / $key_write_requests;
}
if (isset($server_status['Key_reads'])
&& isset($server_status['Key_read_requests'])
&& $server_status['Key_read_requests'] > 0
) {
$key_reads = $server_status['Key_reads'];
$key_read_requests = $server_status['Key_read_requests'];
$server_status['Key_read_ratio_%']
= 100 * $key_reads / $key_read_requests;
}
// Threads_cache_hitrate
if (isset($server_status['Threads_created'])
&& isset($server_status['Connections'])
&& $server_status['Connections'] > 0
) {
$server_status['Threads_cache_hitrate_%']
= 100 - $server_status['Threads_created']
/ $server_status['Connections'] * 100;
}
return $server_status;
}
/**
* Sort variables into arrays
*
* @param array $server_status contains results of SHOW GLOBAL STATUS
* @param array $allocations allocations for sections
* @param array $allocationMap map variables to their section
* @param array $sectionUsed is a section used?
* @param array $used_queries used queries
*
* @return array ($allocationMap, $sectionUsed, $used_queries)
*/
private function _sortVariables(
array $server_status, array $allocations, array $allocationMap, array $sectionUsed,
array $used_queries
) {
foreach ($server_status as $name => $value) {
$section_found = false;
foreach ($allocations as $filter => $section) {
if (mb_strpos($name, $filter) !== false) {
$allocationMap[$name] = $section;
$sectionUsed[$section] = true;
$section_found = true;
if ($section == 'com' && $value > 0) {
$used_queries[$name] = $value;
}
break; // Only exits inner loop
}
}
if (! $section_found) {
$allocationMap[$name] = 'other';
$sectionUsed['other'] = true;
}
}
return array($allocationMap, $sectionUsed, $used_queries);
}
/**
* Constructor
*/
public function __construct()
{
$this->selfUrl = basename($GLOBALS['PMA_PHP_SELF']);
// get status from server
$server_status_result = $GLOBALS['dbi']->tryQuery('SHOW GLOBAL STATUS');
$server_status = array();
if ($server_status_result === false) {
$this->dataLoaded = false;
} else {
$this->dataLoaded = true;
while ($arr = $GLOBALS['dbi']->fetchRow($server_status_result)) {
$server_status[$arr[0]] = $arr[1];
}
$GLOBALS['dbi']->freeResult($server_status_result);
}
// for some calculations we require also some server settings
$server_variables = $GLOBALS['dbi']->fetchResult(
'SHOW GLOBAL VARIABLES', 0, 1
);
// cleanup of some deprecated values
$server_status = self::cleanDeprecated($server_status);
// calculate some values
$server_status = $this->_calculateValues(
$server_status, $server_variables
);
// split variables in sections
$allocations = $this->_getAllocations();
$sections = $this->_getSections();
// define some needful links/commands
$links = $this->_getLinks();
// Variable to contain all com_ variables (query statistics)
$used_queries = array();
// Variable to map variable names to their respective section name
// (used for js category filtering)
$allocationMap = array();
// Variable to mark used sections
$sectionUsed = array();
// sort vars into arrays
list(
$allocationMap, $sectionUsed, $used_queries
) = $this->_sortVariables(
$server_status, $allocations, $allocationMap, $sectionUsed,
$used_queries
);
// admin commands are not queries (e.g. they include COM_PING,
// which is excluded from $server_status['Questions'])
unset($used_queries['Com_admin_commands']);
// Set all class properties
$this->db_isLocal = false;
$serverHostToLower = mb_strtolower(
$GLOBALS['cfg']['Server']['host']
);
if ($serverHostToLower === 'localhost'
|| $GLOBALS['cfg']['Server']['host'] === '127.0.0.1'
|| $GLOBALS['cfg']['Server']['host'] === '::1'
) {
$this->db_isLocal = true;
}
$this->status = $server_status;
$this->sections = $sections;
$this->variables = $server_variables;
$this->used_queries = $used_queries;
$this->allocationMap = $allocationMap;
$this->links = $links;
$this->sectionUsed = $sectionUsed;
}
/**
* cleanup of some deprecated values
*
* @param array $server_status status array to process
*
* @return array
*/
public static function cleanDeprecated(array $server_status)
{
$deprecated = array(
'Com_prepare_sql' => 'Com_stmt_prepare',
'Com_execute_sql' => 'Com_stmt_execute',
'Com_dealloc_sql' => 'Com_stmt_close',
);
foreach ($deprecated as $old => $new) {
if (isset($server_status[$old]) && isset($server_status[$new])) {
unset($server_status[$old]);
}
}
return $server_status;
}
/**
* Generates menu HTML
*
* @return string
*/
public function getMenuHtml()
{
$url_params = Url::getCommon();
$items = array(
array(
'name' => __('Server'),
'url' => 'server_status.php'
),
array(
'name' => __('Processes'),
'url' => 'server_status_processes.php'
),
array(
'name' => __('Query statistics'),
'url' => 'server_status_queries.php'
),
array(
'name' => __('All status variables'),
'url' => 'server_status_variables.php'
),
array(
'name' => __('Monitor'),
'url' => 'server_status_monitor.php'
),
array(
'name' => __('Advisor'),
'url' => 'server_status_advisor.php'
)
);
$retval = '<ul id="topmenu2">';
foreach ($items as $item) {
$class = '';
if ($item['url'] === $this->selfUrl) {
$class = ' class="tabactive"';
}
$retval .= '<li>';
$retval .= '<a' . $class;
$retval .= ' href="' . $item['url'] . $url_params . '">';
$retval .= $item['name'];
$retval .= '</a>';
$retval .= '</li>';
}
$retval .= '</ul>';
$retval .= '<div class="clearfloat"></div>';
return $retval;
}
/**
* Builds a <select> list for refresh rates
*
* @param string $name Name of select
* @param int $defaultRate Currently chosen rate
* @param array $refreshRates List of refresh rates
*
* @return string
*/
public static function getHtmlForRefreshList($name,
$defaultRate = 5,
array $refreshRates = array(1, 2, 5, 10, 20, 40, 60, 120, 300, 600)
) {
$return = '<select name="' . $name . '" id="id_' . $name
. '" class="refreshRate">';
foreach ($refreshRates as $rate) {
$selected = ($rate == $defaultRate)?' selected="selected"':'';
$return .= '<option value="' . $rate . '"' . $selected . '>';
if ($rate < 60) {
$return .= sprintf(
_ngettext('%d second', '%d seconds', $rate), $rate
);
} else {
$rate = $rate / 60;
$return .= sprintf(
_ngettext('%d minute', '%d minutes', $rate), $rate
);
}
$return .= '</option>';
}
$return .= '</select>';
return $return;
}
}

View File

@@ -0,0 +1,829 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* functions for displaying server status sub item: monitor
*
* @usedby server_status_monitor.php
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Server\Status;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\Server\Status\Data;
use PhpMyAdmin\SysInfo;
use PhpMyAdmin\Util;
/**
* functions for displaying server status sub item: monitor
*
* @package PhpMyAdmin
*/
class Monitor
{
/**
* Prints html with monitor
*
* @param Data $serverStatusData Server status data
*
* @return string
*/
public static function getHtmlForMonitor(Data $serverStatusData)
{
$retval = self::getHtmlForTabLinks();
$retval .= self::getHtmlForSettingsDialog();
$retval .= self::getHtmlForInstructionsDialog();
$retval .= self::getHtmlForAddChartDialog();
$retval .= self::getHtmlForAnalyseDialog();
$retval .= '<table class="clearfloat tdblock" id="chartGrid"></table>';
$retval .= '<div id="logTable">';
$retval .= '<br/>';
$retval .= '</div>';
$retval .= '<script type="text/javascript">';
$retval .= 'variableNames = [ ';
$i = 0;
foreach ($serverStatusData->status as $name=>$value) {
if (is_numeric($value)) {
if ($i++ > 0) {
$retval .= ", ";
}
$retval .= Sanitize::formatJsVal($name);
}
}
$retval .= '];';
$retval .= '</script>';
return $retval;
}
/**
* Returns html for Analyse Dialog
*
* @return string
*/
public static function getHtmlForAnalyseDialog()
{
$retval = '<div id="logAnalyseDialog" title="';
$retval .= __('Log statistics') . '" class="hide">';
$retval .= '<p>' . __('Selected time range:');
$retval .= '<input type="text" name="dateStart"'
. ' class="datetimefield" value="" /> - ';
$retval .= '<input type="text" name="dateEnd" class="datetimefield" value="" />';
$retval .= '</p>';
$retval .= '<input type="checkbox" id="limitTypes"'
. ' value="1" checked="checked" />';
$retval .= '<label for="limitTypes">';
$retval .= __('Only retrieve SELECT,INSERT,UPDATE and DELETE Statements');
$retval .= '</label>';
$retval .= '<br/>';
$retval .= '<input type="checkbox" id="removeVariables"'
. ' value="1" checked="checked" />';
$retval .= '<label for="removeVariables">';
$retval .= __('Remove variable data in INSERT statements for better grouping');
$retval .= '</label>';
$retval .= '<p>';
$retval .= __(
'Choose from which log you want the statistics to be generated from.'
);
$retval .= '</p>';
$retval .= '<p>';
$retval .= __('Results are grouped by query text.');
$retval .= '</p>';
$retval .= '</div>';
$retval .= '<div id="queryAnalyzerDialog" title="';
$retval .= __('Query analyzer') . '" class="hide">';
$retval .= '<textarea id="sqlquery"> </textarea>';
$retval .= '<p></p>';
$retval .= '<div class="placeHolder"></div>';
$retval .= '</div>';
return $retval;
}
/**
* Returns html for Instructions Dialog
*
* @return string
*/
public static function getHtmlForInstructionsDialog()
{
$retval = '<div id="monitorInstructionsDialog" title="';
$retval .= __('Monitor Instructions') . '" class="hide">';
$retval .= __(
'The phpMyAdmin Monitor can assist you in optimizing the server'
. ' configuration and track down time intensive queries. For the latter you'
. ' will need to set log_output to \'TABLE\' and have either the'
. ' slow_query_log or general_log enabled. Note however, that the'
. ' general_log produces a lot of data and increases server load'
. ' by up to 15%.'
);
$retval .= '<p></p>';
$retval .= '<img class="ajaxIcon" src="';
$retval .= $GLOBALS['pmaThemeImage'] . 'ajax_clock_small.gif"';
$retval .= ' alt="' . __('Loading…') . '" />';
$retval .= '<div class="ajaxContent"></div>';
$retval .= '<div class="monitorUse hide">';
$retval .= '<p></p>';
$retval .= '<strong>';
$retval .= __('Using the monitor:');
$retval .= '</strong><p>';
$retval .= __(
'Your browser will refresh all displayed charts in a regular interval.'
. ' You may add charts and change the refresh rate under \'Settings\','
. ' or remove any chart using the cog icon on each respective chart.'
);
$retval .= '</p><p>';
$retval .= __(
'To display queries from the logs, select the relevant time span on any'
. ' chart by holding down the left mouse button and panning over the'
. ' chart. Once confirmed, this will load a table of grouped queries,'
. ' there you may click on any occurring SELECT statements to further'
. ' analyze them.'
);
$retval .= '</p>';
$retval .= '<p>';
$retval .= Util::getImage('s_attention');
$retval .= '<strong>';
$retval .= __('Please note:');
$retval .= '</strong><br />';
$retval .= __(
'Enabling the general_log may increase the server load by'
. ' 5-15%. Also be aware that generating statistics from the logs is a'
. ' load intensive task, so it is advisable to select only a small time'
. ' span and to disable the general_log and empty its table once'
. ' monitoring is not required any more.'
);
$retval .= '</p>';
$retval .= '</div>';
$retval .= '</div>';
return $retval;
}
/**
* Returns html for addChartDialog
*
* @return string
*/
public static function getHtmlForAddChartDialog()
{
$retval = '<div id="addChartDialog" title="'
. __('Add chart') . '" class="hide">';
$retval .= '<div id="tabGridVariables">';
$retval .= '<p><input type="text" name="chartTitle" value="'
. __('Chart Title') . '" /></p>';
$retval .= '<input type="radio" name="chartType"'
. ' value="preset" id="chartPreset" />';
$retval .= '<label for="chartPreset">' . __('Preset chart') . '</label>';
$retval .= '<select name="presetCharts"></select><br/>';
$retval .= '<input type="radio" name="chartType" value="variable" '
. 'id="chartStatusVar" checked="checked" />';
$retval .= '<label for="chartStatusVar">';
$retval .= __('Status variable(s)');
$retval .= '</label><br/>';
$retval .= '<div id="chartVariableSettings">';
$retval .= '<label for="chartSeries">' . __('Select series:') . '</label><br />';
$retval .= '<select id="chartSeries" name="varChartList" size="1">';
$retval .= '<option>' . __('Commonly monitored') . '</option>';
$retval .= '<option>Processes</option>';
$retval .= '<option>Questions</option>';
$retval .= '<option>Connections</option>';
$retval .= '<option>Bytes_sent</option>';
$retval .= '<option>Bytes_received</option>';
$retval .= '<option>Threads_connected</option>';
$retval .= '<option>Created_tmp_disk_tables</option>';
$retval .= '<option>Handler_read_first</option>';
$retval .= '<option>Innodb_buffer_pool_wait_free</option>';
$retval .= '<option>Key_reads</option>';
$retval .= '<option>Open_tables</option>';
$retval .= '<option>Select_full_join</option>';
$retval .= '<option>Slow_queries</option>';
$retval .= '</select><br />';
$retval .= '<label for="variableInput">';
$retval .= __('or type variable name:');
$retval .= ' </label>';
$retval .= '<input type="text" name="variableInput" id="variableInput" />';
$retval .= '<p></p>';
$retval .= '<input type="checkbox" name="differentialValue"'
. ' id="differentialValue" value="differential" checked="checked" />';
$retval .= '<label for="differentialValue">';
$retval .= __('Display as differential value');
$retval .= '</label><br />';
$retval .= '<input type="checkbox" id="useDivisor"'
. ' name="useDivisor" value="1" />';
$retval .= '<label for="useDivisor">' . __('Apply a divisor') . '</label>';
$retval .= '<span class="divisorInput hide">';
$retval .= '<input type="text" name="valueDivisor" size="4" value="1" />';
$retval .= '(<a href="#kibDivisor">' . __('KiB') . '</a>, ';
$retval .= '<a href="#mibDivisor">' . __('MiB') . '</a>)';
$retval .= '</span><br />';
$retval .= '<input type="checkbox" id="useUnit" name="useUnit" value="1" />';
$retval .= '<label for="useUnit">';
$retval .= __('Append unit to data values');
$retval .= '</label>';
$retval .= '<span class="unitInput hide">';
$retval .= '<input type="text" name="valueUnit" size="4" value="" />';
$retval .= '</span>';
$retval .= '<p>';
$retval .= '<a href="#submitAddSeries"><b>' . __('Add this series') . '</b></a>';
$retval .= '<span id="clearSeriesLink" class="hide">';
$retval .= ' | <a href="#submitClearSeries">' . __('Clear series') . '</a>';
$retval .= '</span>';
$retval .= '</p>';
$retval .= __('Series in chart:');
$retval .= '<br/>';
$retval .= '<span id="seriesPreview">';
$retval .= '<i>' . __('None') . '</i>';
$retval .= '</span>';
$retval .= '</div>';
$retval .= '</div>';
$retval .= '</div>';
return $retval;
}
/**
* Returns html with Tab Links
*
* @return string
*/
public static function getHtmlForTabLinks()
{
$retval = '<div class="tabLinks">';
$retval .= '<a href="#pauseCharts">';
$retval .= Util::getImage('play') . __('Start Monitor');
$retval .= '</a>';
$retval .= '<a href="#settingsPopup" class="popupLink">';
$retval .= Util::getImage('s_cog') . __('Settings');
$retval .= '</a>';
$retval .= '<a href="#monitorInstructionsDialog">';
$retval .= Util::getImage('b_help') . __('Instructions/Setup');
$retval .= '<a href="#endChartEditMode" class="hide">';
$retval .= Util::getImage('s_okay');
$retval .= __('Done dragging (rearranging) charts');
$retval .= '</a>';
$retval .= '</div>';
return $retval;
}
/**
* Returns html with Settings dialog
*
* @return string
*/
public static function getHtmlForSettingsDialog()
{
$retval = '<div class="popupContent settingsPopup">';
$retval .= '<a href="#addNewChart">';
$retval .= Util::getImage('b_chart') . __('Add chart');
$retval .= '</a>';
$retval .= '<a href="#rearrangeCharts">';
$retval .= Util::getImage('b_tblops')
. __('Enable charts dragging');
$retval .= '</a>';
$retval .= '<div class="clearfloat paddingtop"></div>';
$retval .= '<div class="floatleft">';
$retval .= __('Refresh rate') . '<br />';
$retval .= Data::getHtmlForRefreshList(
'gridChartRefresh',
5,
Array(2, 3, 4, 5, 10, 20, 40, 60, 120, 300, 600, 1200)
);
$retval .= '<br />';
$retval .= '</div>';
$retval .= '<div class="floatleft">';
$retval .= __('Chart columns');
$retval .= '<br />';
$retval .= '<select name="chartColumns">';
$retval .= '<option>1</option>';
$retval .= '<option>2</option>';
$retval .= '<option>3</option>';
$retval .= '<option>4</option>';
$retval .= '<option>5</option>';
$retval .= '<option>6</option>';
$retval .= '</select>';
$retval .= '</div>';
$retval .= '<div class="clearfloat paddingtop">';
$retval .= '<b>' . __('Chart arrangement') . '</b> ';
$retval .= Util::showHint(
__(
'The arrangement of the charts is stored to the browsers local storage. '
. 'You may want to export it if you have a complicated set up.'
)
);
$retval .= '<br/>';
$retval .= '<a class="ajax" href="#importMonitorConfig">';
$retval .= __('Import');
$retval .= '</a>';
$retval .= '&nbsp;&nbsp;';
$retval .= '<a class="disableAjax" href="#exportMonitorConfig">';
$retval .= __('Export');
$retval .= '</a>';
$retval .= '&nbsp;&nbsp;';
$retval .= '<a href="#clearMonitorConfig">';
$retval .= __('Reset to default');
$retval .= '</a>';
$retval .= '</div>';
$retval .= '</div>';
return $retval;
}
/**
* Define some data and links needed on the client side
*
* @param Data $serverStatusData Server status data
*
* @return string
*/
public static function getHtmlForClientSideDataAndLinks(Data $serverStatusData)
{
/**
* Define some data needed on the client side
*/
$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', SysInfo::getOs());
$form .= sprintf($input, 'is_superuser', $GLOBALS['dbi']->isSuperuser());
$form .= sprintf($input, 'server_db_isLocal', $serverStatusData->db_isLocal);
$form .= '</form>';
/**
* Define some links used on client side
*/
$links = '<div id="profiling_docu" class="hide">';
$links .= Util::showMySQLDocu('general-thread-states');
$links .= '</div>';
$links .= '<div id="explain_docu" class="hide">';
$links .= Util::showMySQLDocu('explain-output');
$links .= '</div>';
return $form . $links;
}
/***************************Ajax request function***********************************/
/**
* Returns JSon for real-time charting data
*
* @return array
*/
public static function getJsonForChartingData()
{
$ret = json_decode($_POST['requiredData'], true);
$statusVars = array();
$serverVars = array();
$sysinfo = $cpuload = $memory = 0;
/* Accumulate all required variables and data */
list($serverVars, $statusVars, $ret) = self::getJsonForChartingDataGet(
$ret, $serverVars, $statusVars, $sysinfo, $cpuload, $memory
);
// Retrieve all required status variables
if (count($statusVars)) {
$statusVarValues = $GLOBALS['dbi']->fetchResult(
"SHOW GLOBAL STATUS WHERE Variable_name='"
. implode("' OR Variable_name='", $statusVars) . "'",
0,
1
);
} else {
$statusVarValues = array();
}
// Retrieve all required server variables
if (count($serverVars)) {
$serverVarValues = $GLOBALS['dbi']->fetchResult(
"SHOW GLOBAL VARIABLES WHERE Variable_name='"
. implode("' OR Variable_name='", $serverVars) . "'",
0,
1
);
} else {
$serverVarValues = array();
}
// ...and now assign them
$ret = self::getJsonForChartingDataSet($ret, $statusVarValues, $serverVarValues);
$ret['x'] = microtime(true) * 1000;
return $ret;
}
/**
* Assign the variables for real-time charting data
*
* @param array $ret Real-time charting data
* @param array $statusVarValues Status variable values
* @param array $serverVarValues Server variable values
*
* @return array
*/
public static function getJsonForChartingDataSet(array $ret, array $statusVarValues, array $serverVarValues)
{
foreach ($ret as $chart_id => $chartNodes) {
foreach ($chartNodes as $node_id => $nodeDataPoints) {
foreach ($nodeDataPoints as $point_id => $dataPoint) {
switch ($dataPoint['type']) {
case 'statusvar':
$ret[$chart_id][$node_id][$point_id]['value']
= $statusVarValues[$dataPoint['name']];
break;
case 'servervar':
$ret[$chart_id][$node_id][$point_id]['value']
= $serverVarValues[$dataPoint['name']];
break;
}
}
}
}
return $ret;
}
/**
* Get called to get JSON for charting data
*
* @param array $ret Real-time charting data
* @param array $serverVars Server variable values
* @param array $statusVars Status variable values
* @param mixed $sysinfo System info
* @param mixed $cpuload CPU load
* @param mixed $memory Memory
*
* @return array
*/
public static function getJsonForChartingDataGet(
array $ret, array $serverVars, array $statusVars, $sysinfo, $cpuload, $memory
) {
// For each chart
foreach ($ret as $chart_id => $chartNodes) {
// For each data series
foreach ($chartNodes as $node_id => $nodeDataPoints) {
// For each data point in the series (usually just 1)
foreach ($nodeDataPoints as $point_id => $dataPoint) {
list($serverVars, $statusVars, $ret[$chart_id][$node_id][$point_id])
= self::getJsonForChartingDataSwitch(
$dataPoint['type'], $dataPoint['name'], $serverVars,
$statusVars, $ret[$chart_id][$node_id][$point_id],
$sysinfo, $cpuload, $memory
);
} /* foreach */
} /* foreach */
}
return array($serverVars, $statusVars, $ret);
}
/**
* Switch called to get JSON for charting data
*
* @param string $type Type
* @param string $pName Name
* @param array $serverVars Server variable values
* @param array $statusVars Status variable values
* @param array $ret Real-time charting data
* @param mixed $sysinfo System info
* @param mixed $cpuload CPU load
* @param mixed $memory Memory
*
* @return array
*/
public static function getJsonForChartingDataSwitch(
$type, $pName, array $serverVars, array $statusVars, array $ret,
$sysinfo, $cpuload, $memory
) {
switch ($type) {
/* We only collect the status and server variables here to
* read them all in one query,
* and only afterwards assign them.
* Also do some white list filtering on the names
*/
case 'servervar':
if (!preg_match('/[^a-zA-Z_]+/', $pName)) {
$serverVars[] = $pName;
}
break;
case 'statusvar':
if (!preg_match('/[^a-zA-Z_]+/', $pName)) {
$statusVars[] = $pName;
}
break;
case 'proc':
$result = $GLOBALS['dbi']->query('SHOW PROCESSLIST');
$ret['value'] = $GLOBALS['dbi']->numRows($result);
break;
case 'cpu':
if (!$sysinfo) {
$sysinfo = SysInfo::get();
}
if (!$cpuload) {
$cpuload = $sysinfo->loadavg();
}
if (SysInfo::getOs() == 'Linux') {
$ret['idle'] = $cpuload['idle'];
$ret['busy'] = $cpuload['busy'];
} else {
$ret['value'] = $cpuload['loadavg'];
}
break;
case 'memory':
if (!$sysinfo) {
$sysinfo = SysInfo::get();
}
if (!$memory) {
$memory = $sysinfo->memory();
}
$ret['value'] = isset($memory[$pName]) ? $memory[$pName] : 0;
break;
}
return array($serverVars, $statusVars, $ret);
}
/**
* Returns JSon for log data with type: slow
*
* @param int $start Unix Time: Start time for query
* @param int $end Unix Time: End time for query
*
* @return array
*/
public static function getJsonForLogDataTypeSlow($start, $end)
{
$query = 'SELECT start_time, user_host, ';
$query .= 'Sec_to_Time(Sum(Time_to_Sec(query_time))) as query_time, ';
$query .= 'Sec_to_Time(Sum(Time_to_Sec(lock_time))) as lock_time, ';
$query .= 'SUM(rows_sent) AS rows_sent, ';
$query .= 'SUM(rows_examined) AS rows_examined, db, sql_text, ';
$query .= 'COUNT(sql_text) AS \'#\' ';
$query .= 'FROM `mysql`.`slow_log` ';
$query .= 'WHERE start_time > FROM_UNIXTIME(' . $start . ') ';
$query .= 'AND start_time < FROM_UNIXTIME(' . $end . ') GROUP BY sql_text';
$result = $GLOBALS['dbi']->tryQuery($query);
$return = array('rows' => array(), 'sum' => array());
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
$type = mb_strtolower(
mb_substr(
$row['sql_text'],
0,
mb_strpos($row['sql_text'], ' ')
)
);
switch($type) {
case 'insert':
case 'update':
//Cut off big inserts and updates, but append byte count instead
if (mb_strlen($row['sql_text']) > 220) {
$implode_sql_text = implode(
' ',
Util::formatByteDown(
mb_strlen($row['sql_text']), 2, 2
)
);
$row['sql_text'] = mb_substr($row['sql_text'], 0, 200)
. '... [' . $implode_sql_text . ']';
}
break;
default:
break;
}
if (! isset($return['sum'][$type])) {
$return['sum'][$type] = 0;
}
$return['sum'][$type] += $row['#'];
$return['rows'][] = $row;
}
$return['sum']['TOTAL'] = array_sum($return['sum']);
$return['numRows'] = count($return['rows']);
$GLOBALS['dbi']->freeResult($result);
return $return;
}
/**
* Returns JSon for log data with type: general
*
* @param int $start Unix Time: Start time for query
* @param int $end Unix Time: End time for query
*
* @return array
*/
public static function getJsonForLogDataTypeGeneral($start, $end)
{
$limitTypes = '';
if (isset($_POST['limitTypes']) && $_POST['limitTypes']) {
$limitTypes
= 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' ';
}
$query = 'SELECT TIME(event_time) as event_time, user_host, thread_id, ';
$query .= 'server_id, argument, count(argument) as \'#\' ';
$query .= 'FROM `mysql`.`general_log` ';
$query .= 'WHERE command_type=\'Query\' ';
$query .= 'AND event_time > FROM_UNIXTIME(' . $start . ') ';
$query .= 'AND event_time < FROM_UNIXTIME(' . $end . ') ';
$query .= $limitTypes . 'GROUP by argument'; // HAVING count > 1';
$result = $GLOBALS['dbi']->tryQuery($query);
$return = array('rows' => array(), 'sum' => array());
$insertTables = array();
$insertTablesFirst = -1;
$i = 0;
$removeVars = isset($_POST['removeVariables'])
&& $_POST['removeVariables'];
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
preg_match('/^(\w+)\s/', $row['argument'], $match);
$type = mb_strtolower($match[1]);
if (! isset($return['sum'][$type])) {
$return['sum'][$type] = 0;
}
$return['sum'][$type] += $row['#'];
switch($type) {
/** @noinspection PhpMissingBreakStatementInspection */
case 'insert':
// Group inserts if selected
if ($removeVars
&& preg_match(
'/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i',
$row['argument'], $matches
)
) {
$insertTables[$matches[2]]++;
if ($insertTables[$matches[2]] > 1) {
$return['rows'][$insertTablesFirst]['#']
= $insertTables[$matches[2]];
// Add a ... to the end of this query to indicate that
// there's been other queries
$temp = $return['rows'][$insertTablesFirst]['argument'];
$return['rows'][$insertTablesFirst]['argument']
.= self::getSuspensionPoints(
$temp[strlen($temp) - 1]
);
// Group this value, thus do not add to the result list
continue 2;
} else {
$insertTablesFirst = $i;
$insertTables[$matches[2]] += $row['#'] - 1;
}
}
// No break here
case 'update':
// Cut off big inserts and updates,
// but append byte count therefor
if (mb_strlen($row['argument']) > 220) {
$row['argument'] = mb_substr($row['argument'], 0, 200)
. '... ['
. implode(
' ',
Util::formatByteDown(
mb_strlen($row['argument']),
2,
2
)
)
. ']';
}
break;
default:
break;
}
$return['rows'][] = $row;
$i++;
}
$return['sum']['TOTAL'] = array_sum($return['sum']);
$return['numRows'] = count($return['rows']);
$GLOBALS['dbi']->freeResult($result);
return $return;
}
/**
* Return suspension points if needed
*
* @param string $lastChar Last char
*
* @return null|string Return suspension points if needed
*/
public static function getSuspensionPoints($lastChar)
{
if ($lastChar != '.') {
return '<br/>...';
}
return null;
}
/**
* Returns JSon for logging vars
*
* @return array
*/
public static function getJsonForLoggingVars()
{
if (isset($_POST['varName']) && isset($_POST['varValue'])) {
$value = $GLOBALS['dbi']->escapeString($_POST['varValue']);
if (! is_numeric($value)) {
$value="'" . $value . "'";
}
if (! preg_match("/[^a-zA-Z0-9_]+/", $_POST['varName'])) {
$GLOBALS['dbi']->query(
'SET GLOBAL ' . $_POST['varName'] . ' = ' . $value
);
}
}
$loggingVars = $GLOBALS['dbi']->fetchResult(
'SHOW GLOBAL VARIABLES WHERE Variable_name IN'
. ' ("general_log","slow_query_log","long_query_time","log_output")',
0,
1
);
return $loggingVars;
}
/**
* Returns JSon for query_analyzer
*
* @return array
*/
public static function getJsonForQueryAnalyzer()
{
$return = array();
if (strlen($_POST['database']) > 0) {
$GLOBALS['dbi']->selectDb($_POST['database']);
}
if ($profiling = Util::profilingSupported()) {
$GLOBALS['dbi']->query('SET PROFILING=1;');
}
// Do not cache query
$query = preg_replace(
'/^(\s*SELECT)/i',
'\\1 SQL_NO_CACHE',
$_POST['query']
);
$GLOBALS['dbi']->tryQuery($query);
$return['affectedRows'] = $GLOBALS['cached_affected_rows'];
$result = $GLOBALS['dbi']->tryQuery('EXPLAIN ' . $query);
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
$return['explain'][] = $row;
}
// In case an error happened
$return['error'] = $GLOBALS['dbi']->getError();
$GLOBALS['dbi']->freeResult($result);
if ($profiling) {
$return['profiling'] = array();
$result = $GLOBALS['dbi']->tryQuery(
'SELECT seq,state,duration FROM INFORMATION_SCHEMA.PROFILING'
. ' WHERE QUERY_ID=1 ORDER BY seq'
);
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
$return['profiling'][]= $row;
}
$GLOBALS['dbi']->freeResult($result);
}
return $return;
}
}

View File

@@ -0,0 +1,305 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* functions for displaying processes list
*
* @usedby server_status_processes.php
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Server\Status;
use PhpMyAdmin\Message;
use PhpMyAdmin\Server\Status\Data;
use PhpMyAdmin\Util;
use PhpMyAdmin\Url;
/**
* PhpMyAdmin\Server\Status\Processes class
*
* @package PhpMyAdmin
*/
class Processes
{
/**
* Prints html for auto refreshing processes list
*
* @return string
*/
public static function getHtmlForProcessListAutoRefresh()
{
$notice = Message::notice(
__(
'Note: Enabling the auto refresh here might cause '
. 'heavy traffic between the web server and the MySQL server.'
)
)->getDisplay();
$retval = $notice . '<div class="tabLinks">';
$retval .= '<label>' . __('Refresh rate') . ': ';
$retval .= Data::getHtmlForRefreshList(
'refreshRate',
5,
Array(2, 3, 4, 5, 10, 20, 40, 60, 120, 300, 600, 1200)
);
$retval .= '</label>';
$retval .= '<a id="toggleRefresh" href="#">';
$retval .= Util::getImage('play') . __('Start auto refresh');
$retval .= '</a>';
$retval .= '</div>';
return $retval;
}
/**
* Prints Server Process list
*
* @return string
*/
public static function getHtmlForServerProcesslist()
{
$show_full_sql = ! empty($_POST['full']);
// This array contains display name and real column name of each
// sortable column in the table
$sortable_columns = array(
array(
'column_name' => __('ID'),
'order_by_field' => 'Id'
),
array(
'column_name' => __('User'),
'order_by_field' => 'User'
),
array(
'column_name' => __('Host'),
'order_by_field' => 'Host'
),
array(
'column_name' => __('Database'),
'order_by_field' => 'db'
),
array(
'column_name' => __('Command'),
'order_by_field' => 'Command'
),
array(
'column_name' => __('Time'),
'order_by_field' => 'Time'
),
array(
'column_name' => __('Status'),
'order_by_field' => 'State'
),
array(
'column_name' => __('Progress'),
'order_by_field' => 'Progress'
),
array(
'column_name' => __('SQL query'),
'order_by_field' => 'Info'
)
);
$sortableColCount = count($sortable_columns);
$sql_query = $show_full_sql
? 'SHOW FULL PROCESSLIST'
: 'SHOW PROCESSLIST';
if ((! empty($_POST['order_by_field'])
&& ! empty($_POST['sort_order']))
|| (! empty($_POST['showExecuting']))
) {
$sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ';
}
if (! empty($_POST['showExecuting'])) {
$sql_query .= ' WHERE state != "" ';
}
if (!empty($_POST['order_by_field']) && !empty($_POST['sort_order'])) {
$sql_query .= ' ORDER BY '
. Util::backquote($_POST['order_by_field'])
. ' ' . $_POST['sort_order'];
}
$result = $GLOBALS['dbi']->query($sql_query);
$retval = '<div class="responsivetable">';
$retval .= '<table id="tableprocesslist" '
. 'class="data clearfloat noclick sortable">';
$retval .= '<thead>';
$retval .= '<tr>';
$retval .= '<th>' . __('Processes') . '</th>';
foreach ($sortable_columns as $column) {
$is_sorted = ! empty($_POST['order_by_field'])
&& ! empty($_POST['sort_order'])
&& ($_POST['order_by_field'] == $column['order_by_field']);
$column['sort_order'] = 'ASC';
if ($is_sorted && $_POST['sort_order'] === 'ASC') {
$column['sort_order'] = 'DESC';
}
if (isset($_POST['showExecuting'])) {
$column['showExecuting'] = 'on';
}
$retval .= '<th>';
$columnUrl = Url::getCommon($column, '', false);
$retval .= '<a href="server_status_processes.php" data-post="' . $columnUrl . '" class="sortlink">';
$retval .= $column['column_name'];
if ($is_sorted) {
$asc_display_style = 'inline';
$desc_display_style = 'none';
if ($_POST['sort_order'] === 'DESC') {
$desc_display_style = 'inline';
$asc_display_style = 'none';
}
$retval .= '<img class="icon ic_s_desc soimg" alt="'
. __('Descending') . '" title="" src="themes/dot.gif" '
. 'style="display: ' . $desc_display_style . '" />';
$retval .= '<img class="icon ic_s_asc soimg hide" alt="'
. __('Ascending') . '" title="" src="themes/dot.gif" '
. 'style="display: ' . $asc_display_style . '" />';
}
$retval .= '</a>';
if (0 === --$sortableColCount) {
$url_params = array();
if ($show_full_sql) {
$url_params['full'] = '';
} else {
$url_params['full'] = 1;
}
if (isset($_POST['showExecuting'])) {
$url_params['showExecuting'] = 'on';
}
if (isset($_POST['order_by_field'])) {
$url_params['order_by_field'] = $_POST['order_by_field'];
}
if (isset($_POST['sort_order'])) {
$url_params['sort_order'] = $_POST['sort_order'];
}
$retval .= '<a href="server_status_processes.php" data-post="' . Url::getCommon($url_params, '', false) . '" >';
if ($show_full_sql) {
$retval .= Util::getImage('s_partialtext',
__('Truncate Shown Queries'), ['class' => 'icon_fulltext']);
} else {
$retval .= Util::getImage('s_fulltext',
__('Show Full Queries'), ['class' => 'icon_fulltext']);
}
$retval .= '</a>';
}
$retval .= '</th>';
}
$retval .= '</tr>';
$retval .= '</thead>';
$retval .= '<tbody>';
while ($process = $GLOBALS['dbi']->fetchAssoc($result)) {
$retval .= self::getHtmlForServerProcessItem(
$process,
$show_full_sql
);
}
$retval .= '</tbody>';
$retval .= '</table>';
$retval .= '</div>';
return $retval;
}
/**
* Returns the html for the list filter
*
* @return string
*/
public static function getHtmlForProcessListFilter()
{
$showExecuting = '';
if (! empty($_POST['showExecuting'])) {
$showExecuting = ' checked="checked"';
}
$url_params = array(
'ajax_request' => true,
'full' => (isset($_POST['full']) ? $_POST['full'] : ''),
'column_name' => (isset($_POST['column_name']) ? $_POST['column_name'] : ''),
'order_by_field'
=> (isset($_POST['order_by_field']) ? $_POST['order_by_field'] : ''),
'sort_order' => (isset($_POST['sort_order']) ? $_POST['sort_order'] : ''),
);
$retval = '';
$retval .= '<fieldset id="tableFilter">';
$retval .= '<legend>' . __('Filters') . '</legend>';
$retval .= '<form action="server_status_processes.php" method="post">';
$retval .= Url::getHiddenInputs($url_params);
$retval .= '<input type="submit" value="' . __('Refresh') . '" />';
$retval .= '<div class="formelement">';
$retval .= '<input' . $showExecuting . ' type="checkbox" name="showExecuting"'
. ' id="showExecuting" class="autosubmit"/>';
$retval .= '<label for="showExecuting">';
$retval .= __('Show only active');
$retval .= '</label>';
$retval .= '</div>';
$retval .= '</form>';
$retval .= '</fieldset>';
return $retval;
}
/**
* Prints Every Item of Server Process
*
* @param array $process data of Every Item of Server Process
* @param bool $show_full_sql show full sql or not
*
* @return string
*/
public static function getHtmlForServerProcessItem(array $process, $show_full_sql)
{
// Array keys need to modify due to the way it has used
// to display column values
if ((! empty($_POST['order_by_field']) && ! empty($_POST['sort_order']))
|| (! empty($_POST['showExecuting']))
) {
foreach (array_keys($process) as $key) {
$new_key = ucfirst(mb_strtolower($key));
if ($new_key !== $key) {
$process[$new_key] = $process[$key];
unset($process[$key]);
}
}
}
$retval = '<tr>';
$retval .= '<td><a class="ajax kill_process" href="server_status_processes.php"'
. ' data-post="' . Url::getCommon(['kill' => $process['Id']], '', false) . '">'
. __('Kill') . '</a></td>';
$retval .= '<td class="value">' . $process['Id'] . '</td>';
$retval .= '<td>' . htmlspecialchars($process['User']) . '</td>';
$retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
$retval .= '<td>' . ((! isset($process['db'])
|| strlen($process['db']) === 0)
? '<i>' . __('None') . '</i>'
: htmlspecialchars($process['db'])) . '</td>';
$retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
$retval .= '<td class="value">' . $process['Time'] . '</td>';
$processStatusStr = empty($process['State']) ? '---' : $process['State'];
$retval .= '<td>' . $processStatusStr . '</td>';
$processProgress = empty($process['Progress']) ? '---' : $process['Progress'];
$retval .= '<td>' . $processProgress . '</td>';
$retval .= '<td>';
if (empty($process['Info'])) {
$retval .= '---';
} else {
$retval .= Util::formatSql($process['Info'], ! $show_full_sql);
}
$retval .= '</td>';
$retval .= '</tr>';
return $retval;
}
}

View File

@@ -0,0 +1,156 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* functions for displaying query statistics for the server
*
* @usedby server_status_queries.php
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Server\Status;
use PhpMyAdmin\Server\Status\Data;
use PhpMyAdmin\Util;
/**
* PhpMyAdmin\Server\Status\Queries class
*
* @package PhpMyAdmin
*/
class Queries
{
/**
* Returns the html content for the query statistics
*
* @param Data $serverStatusData Server status data
*
* @return string
*/
public static function getHtmlForQueryStatistics(Data $serverStatusData)
{
$retval = '';
$hour_factor = 3600 / $serverStatusData->status['Uptime'];
$used_queries = $serverStatusData->used_queries;
$total_queries = array_sum($used_queries);
$retval .= '<h3 id="serverstatusqueries">';
/* l10n: Questions is the name of a MySQL Status variable */
$retval .= sprintf(
__('Questions since startup: %s'),
Util::formatNumber($total_queries, 0)
);
$retval .= ' ';
$retval .= Util::showMySQLDocu(
'server-status-variables',
false,
'statvar_Questions'
);
$retval .= '<br />';
$retval .= '<span>';
$retval .= '&oslash; ' . __('per hour:') . ' ';
$retval .= Util::formatNumber($total_queries * $hour_factor, 0);
$retval .= '<br />';
$retval .= '&oslash; ' . __('per minute:') . ' ';
$retval .= Util::formatNumber(
$total_queries * 60 / $serverStatusData->status['Uptime'],
0
);
$retval .= '<br />';
if ($total_queries / $serverStatusData->status['Uptime'] >= 1) {
$retval .= '&oslash; ' . __('per second:') . ' ';
$retval .= Util::formatNumber(
$total_queries / $serverStatusData->status['Uptime'],
0
);
}
$retval .= '</span>';
$retval .= '</h3>';
$retval .= self::getHtmlForDetails($serverStatusData);
return $retval;
}
/**
* Returns the html content for the query details
*
* @param Data $serverStatusData Server status data
*
* @return string
*/
public static function getHtmlForDetails(Data $serverStatusData)
{
$hour_factor = 3600 / $serverStatusData->status['Uptime'];
$used_queries = $serverStatusData->used_queries;
$total_queries = array_sum($used_queries);
// reverse sort by value to show most used statements first
arsort($used_queries);
//(- $serverStatusData->status['Connections']);
$perc_factor = 100 / $total_queries;
$retval = '<table id="serverstatusqueriesdetails" '
. 'class="width100 data sortable noclick">';
$retval .= '<col class="namecol" />';
$retval .= '<col class="valuecol" span="3" />';
$retval .= '<thead>';
$retval .= '<tr><th>' . __('Statements') . '</th>';
$retval .= '<th>';
/* l10n: # = Amount of queries */
$retval .= __('#');
$retval .= '</th>';
$retval .= '<th>&oslash; ' . __('per hour')
. '</th>';
$retval .= '<th>%</div></th>';
$retval .= '</tr>';
$retval .= '</thead>';
$retval .= '<tbody>';
$chart_json = array();
$query_sum = array_sum($used_queries);
$other_sum = 0;
foreach ($used_queries as $name => $value) {
// For the percentage column, use Questions - Connections, because
// the number of connections is not an item of the Query types
// but is included in Questions. Then the total of the percentages is 100.
$name = str_replace(array('Com_', '_'), array('', ' '), $name);
// Group together values that make out less than 2% into "Other", but only
// if we have more than 6 fractions already
if ($value < $query_sum * 0.02 && count($chart_json)>6) {
$other_sum += $value;
} else {
$chart_json[$name] = $value;
}
$retval .= '<tr>';
$retval .= '<th class="name">' . htmlspecialchars($name) . '</th>';
$retval .= '<td class="value">';
$retval .= htmlspecialchars(
Util::formatNumber($value, 5, 0, true)
);
$retval .= '</td>';
$retval .= '<td class="value">';
$retval .= htmlspecialchars(
Util::formatNumber($value * $hour_factor, 4, 1, true)
);
$retval .= '</td>';
$retval .= '<td class="value">';
$retval .= htmlspecialchars(
Util::formatNumber($value * $perc_factor, 0, 2)
);
$retval .= '</td>';
$retval .= '</tr>';
}
$retval .= '</tbody>';
$retval .= '</table>';
$retval .= '<div id="serverstatusquerieschart" class="width100" data-chart="';
if ($other_sum > 0) {
$chart_json[__('Other')] = $other_sum;
}
$retval .= htmlspecialchars(json_encode($chart_json), ENT_QUOTES);
$retval .= '"></div>';
return $retval;
}
}

View File

@@ -0,0 +1,776 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* functions for displaying server status variables
*
* @usedby server_status_variables.php
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Server\Status;
use PhpMyAdmin\Server\Status\Data;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
/**
* PhpMyAdmin\Server\Status\Variables class
*
* @package PhpMyAdmin
*/
class Variables
{
/**
* Returns the html for the list filter
*
* @param Data $serverStatusData Server status data
*
* @return string
*/
public static function getHtmlForFilter(Data $serverStatusData)
{
$filterAlert = '';
if (! empty($_POST['filterAlert'])) {
$filterAlert = ' checked="checked"';
}
$filterText = '';
if (! empty($_POST['filterText'])) {
$filterText = htmlspecialchars($_POST['filterText']);
}
$dontFormat = '';
if (! empty($_POST['dontFormat'])) {
$dontFormat = ' checked="checked"';
}
$retval = '';
$retval .= '<fieldset id="tableFilter">';
$retval .= '<legend>' . __('Filters') . '</legend>';
$retval .= '<form action="server_status_variables.php" method="post">';
$retval .= Url::getHiddenInputs();
$retval .= '<input type="submit" value="' . __('Refresh') . '" />';
$retval .= '<div class="formelement">';
$retval .= '<label for="filterText">' . __('Containing the word:') . '</label>';
$retval .= '<input name="filterText" type="text" id="filterText" '
. 'value="' . $filterText . '" />';
$retval .= '</div>';
$retval .= '<div class="formelement">';
$retval .= '<input' . $filterAlert . ' type="checkbox" '
. 'name="filterAlert" id="filterAlert" />';
$retval .= '<label for="filterAlert">';
$retval .= __('Show only alert values');
$retval .= '</label>';
$retval .= '</div>';
$retval .= '<div class="formelement">';
$retval .= '<select id="filterCategory" name="filterCategory">';
$retval .= '<option value="">' . __('Filter by category…') . '</option>';
foreach ($serverStatusData->sections as $section_id => $section_name) {
if (isset($serverStatusData->sectionUsed[$section_id])) {
if (! empty($_POST['filterCategory'])
&& $_POST['filterCategory'] == $section_id
) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
$retval .= '<option' . $selected . ' value="' . $section_id . '">';
$retval .= htmlspecialchars($section_name) . '</option>';
}
}
$retval .= '</select>';
$retval .= '</div>';
$retval .= '<div class="formelement">';
$retval .= '<input' . $dontFormat . ' type="checkbox" '
. 'name="dontFormat" id="dontFormat" />';
$retval .= '<label for="dontFormat">';
$retval .= __('Show unformatted values');
$retval .= '</label>';
$retval .= '</div>';
$retval .= '</form>';
$retval .= '</fieldset>';
return $retval;
}
/**
* Prints the suggestion links
*
* @param Data $serverStatusData Server status data
*
* @return string
*/
public static function getHtmlForLinkSuggestions(Data $serverStatusData)
{
$retval = '<div id="linkSuggestions" class="defaultLinks hide">';
$retval .= '<p class="notice">' . __('Related links:');
foreach ($serverStatusData->links as $section_name => $section_links) {
$retval .= '<span class="status_' . $section_name . '"> ';
$i = 0;
foreach ($section_links as $link_name => $link_url) {
if ($i > 0) {
$retval .= ', ';
}
if ('doc' == $link_name) {
$retval .= Util::showMySQLDocu($link_url);
} else {
$retval .= '<a href="' . $link_url['url'] . '" data-post="' . $link_url['params'] . '">'
. $link_name . '</a>';
}
$i++;
}
$retval .= '</span>';
}
unset($link_url, $link_name, $i);
$retval .= '</p>';
$retval .= '</div>';
return $retval;
}
/**
* Returns a table with variables information
*
* @param Data $serverStatusData Server status data
*
* @return string
*/
public static function getHtmlForVariablesList(Data $serverStatusData)
{
$retval = '';
$strShowStatus = self::getDescriptions();
/**
* define some alerts
*/
// name => max value before alert
$alerts = array(
// lower is better
// variable => max value
'Aborted_clients' => 0,
'Aborted_connects' => 0,
'Binlog_cache_disk_use' => 0,
'Created_tmp_disk_tables' => 0,
'Handler_read_rnd' => 0,
'Handler_read_rnd_next' => 0,
'Innodb_buffer_pool_pages_dirty' => 0,
'Innodb_buffer_pool_reads' => 0,
'Innodb_buffer_pool_wait_free' => 0,
'Innodb_log_waits' => 0,
'Innodb_row_lock_time_avg' => 10, // ms
'Innodb_row_lock_time_max' => 50, // ms
'Innodb_row_lock_waits' => 0,
'Slow_queries' => 0,
'Delayed_errors' => 0,
'Select_full_join' => 0,
'Select_range_check' => 0,
'Sort_merge_passes' => 0,
'Opened_tables' => 0,
'Table_locks_waited' => 0,
'Qcache_lowmem_prunes' => 0,
'Qcache_free_blocks' =>
isset($serverStatusData->status['Qcache_total_blocks'])
? $serverStatusData->status['Qcache_total_blocks'] / 5
: 0,
'Slow_launch_threads' => 0,
// depends on Key_read_requests
// normally lower then 1:0.01
'Key_reads' => isset($serverStatusData->status['Key_read_requests'])
? (0.01 * $serverStatusData->status['Key_read_requests']) : 0,
// depends on Key_write_requests
// normally nearly 1:1
'Key_writes' => isset($serverStatusData->status['Key_write_requests'])
? (0.9 * $serverStatusData->status['Key_write_requests']) : 0,
'Key_buffer_fraction' => 0.5,
// alert if more than 95% of thread cache is in use
'Threads_cached' => isset($serverStatusData->variables['thread_cache_size'])
? 0.95 * $serverStatusData->variables['thread_cache_size'] : 0
// higher is better
// variable => min value
//'Handler read key' => '> ',
);
$retval .= self::getHtmlForRenderVariables(
$serverStatusData,
$alerts,
$strShowStatus
);
return $retval;
}
/**
* Returns HTML for render variables list
*
* @param Data $serverStatusData Server status data
* @param array $alerts Alert Array
* @param array $strShowStatus Status Array
*
* @return string
*/
public static function getHtmlForRenderVariables(Data $serverStatusData, array $alerts, array $strShowStatus)
{
$retval = '<div class="responsivetable">';
$retval .= '<table class="data noclick" id="serverstatusvariables">';
$retval .= '<col class="namecol" />';
$retval .= '<col class="valuecol" />';
$retval .= '<col class="descrcol" />';
$retval .= '<thead>';
$retval .= '<tr>';
$retval .= '<th>' . __('Variable') . '</th>';
$retval .= '<th>' . __('Value') . '</th>';
$retval .= '<th>' . __('Description') . '</th>';
$retval .= '</tr>';
$retval .= '</thead>';
$retval .= '<tbody>';
foreach ($serverStatusData->status as $name => $value) {
$retval .= '<tr class="' . (isset($serverStatusData->allocationMap[$name])
?' s_' . $serverStatusData->allocationMap[$name]
: '')
. '">';
$retval .= '<th class="name">';
$retval .= htmlspecialchars(str_replace('_', ' ', $name));
// Fields containing % are calculated,
// they can not be described in MySQL documentation
if (mb_strpos($name, '%') === false) {
$retval .= Util::showMySQLDocu(
'server-status-variables',
false,
'statvar_' . $name
);
}
$retval .= '</th>';
$retval .= '<td class="value"><span class="formatted">';
if (isset($alerts[$name])) {
if ($value > $alerts[$name]) {
$retval .= '<span class="attention">';
} else {
$retval .= '<span class="allfine">';
}
}
if (substr($name, -1) === '%') {
$retval .= htmlspecialchars(
Util::formatNumber($value, 0, 2)
) . ' %';
} elseif (strpos($name, 'Uptime') !== false) {
$retval .= htmlspecialchars(
Util::timespanFormat($value)
);
} elseif (is_numeric($value) && $value > 1000) {
$retval .= '<abbr title="'
// makes available the raw value as a title
. htmlspecialchars(Util::formatNumber($value, 0))
. '">'
. htmlspecialchars(Util::formatNumber($value, 3, 1))
. '</abbr>';
} elseif (is_numeric($value)) {
$retval .= htmlspecialchars(
Util::formatNumber($value, 3, 1)
);
} else {
$retval .= htmlspecialchars($value);
}
if (isset($alerts[$name])) {
$retval .= '</span>';
}
$retval .= '</span>';
$retval .= '<span class="original hide">';
if (isset($alerts[$name])) {
if ($value > $alerts[$name]) {
$retval .= '<span class="attention">';
} else {
$retval .= '<span class="allfine">';
}
}
$retval .= htmlspecialchars($value);
if (isset($alerts[$name])) {
$retval .= '</span>';
}
$retval .= '</span>';
$retval .= '</td>';
$retval .= '<td class="descr">';
if (isset($strShowStatus[$name])) {
$retval .= $strShowStatus[$name];
}
if (isset($serverStatusData->links[$name])) {
foreach ($serverStatusData->links[$name] as $link_name => $link_url) {
if ('doc' == $link_name) {
$retval .= Util::showMySQLDocu($link_url);
} else {
$retval .= ' <a href="' . $link_url['url'] . '" data-post="' . $link_url['params'] . '">'
. $link_name . '</a>';
}
}
unset($link_url, $link_name);
}
$retval .= '</td>';
$retval .= '</tr>';
}
$retval .= '</tbody>';
$retval .= '</table>';
$retval .= '</div>';
return $retval;
}
/**
* Returns a list of variable descriptions
*
* @return array
*/
public static function getDescriptions()
{
/**
* Messages are built using the message name
*/
return array(
'Aborted_clients' => __(
'The number of connections that were aborted because the client died'
. ' without closing the connection properly.'
),
'Aborted_connects' => __(
'The number of failed attempts to connect to the MySQL server.'
),
'Binlog_cache_disk_use' => __(
'The number of transactions that used the temporary binary log cache'
. ' but that exceeded the value of binlog_cache_size and used a'
. ' temporary file to store statements from the transaction.'
),
'Binlog_cache_use' => __(
'The number of transactions that used the temporary binary log cache.'
),
'Connections' => __(
'The number of connection attempts (successful or not)'
. ' to the MySQL server.'
),
'Created_tmp_disk_tables' => __(
'The number of temporary tables on disk created automatically by'
. ' the server while executing statements. If'
. ' Created_tmp_disk_tables is big, you may want to increase the'
. ' tmp_table_size value to cause temporary tables to be'
. ' memory-based instead of disk-based.'
),
'Created_tmp_files' => __(
'How many temporary files mysqld has created.'
),
'Created_tmp_tables' => __(
'The number of in-memory temporary tables created automatically'
. ' by the server while executing statements.'
),
'Delayed_errors' => __(
'The number of rows written with INSERT DELAYED for which some'
. ' error occurred (probably duplicate key).'
),
'Delayed_insert_threads' => __(
'The number of INSERT DELAYED handler threads in use. Every'
. ' different table on which one uses INSERT DELAYED gets'
. ' its own thread.'
),
'Delayed_writes' => __(
'The number of INSERT DELAYED rows written.'
),
'Flush_commands' => __(
'The number of executed FLUSH statements.'
),
'Handler_commit' => __(
'The number of internal COMMIT statements.'
),
'Handler_delete' => __(
'The number of times a row was deleted from a table.'
),
'Handler_discover' => __(
'The MySQL server can ask the NDB Cluster storage engine if it'
. ' knows about a table with a given name. This is called discovery.'
. ' Handler_discover indicates the number of time tables have been'
. ' discovered.'
),
'Handler_read_first' => __(
'The number of times the first entry was read from an index. If this'
. ' is high, it suggests that the server is doing a lot of full'
. ' index scans; for example, SELECT col1 FROM foo, assuming that'
. ' col1 is indexed.'
),
'Handler_read_key' => __(
'The number of requests to read a row based on a key. If this is'
. ' high, it is a good indication that your queries and tables'
. ' are properly indexed.'
),
'Handler_read_next' => __(
'The number of requests to read the next row in key order. This is'
. ' incremented if you are querying an index column with a range'
. ' constraint or if you are doing an index scan.'
),
'Handler_read_prev' => __(
'The number of requests to read the previous row in key order.'
. ' This read method is mainly used to optimize ORDER BY … DESC.'
),
'Handler_read_rnd' => __(
'The number of requests to read a row based on a fixed position.'
. ' This is high if you are doing a lot of queries that require'
. ' sorting of the result. You probably have a lot of queries that'
. ' require MySQL to scan whole tables or you have joins that'
. ' don\'t use keys properly.'
),
'Handler_read_rnd_next' => __(
'The number of requests to read the next row in the data file.'
. ' This is high if you are doing a lot of table scans. Generally'
. ' this suggests that your tables are not properly indexed or that'
. ' your queries are not written to take advantage of the indexes'
. ' you have.'
),
'Handler_rollback' => __(
'The number of internal ROLLBACK statements.'
),
'Handler_update' => __(
'The number of requests to update a row in a table.'
),
'Handler_write' => __(
'The number of requests to insert a row in a table.'
),
'Innodb_buffer_pool_pages_data' => __(
'The number of pages containing data (dirty or clean).'
),
'Innodb_buffer_pool_pages_dirty' => __(
'The number of pages currently dirty.'
),
'Innodb_buffer_pool_pages_flushed' => __(
'The number of buffer pool pages that have been requested'
. ' to be flushed.'
),
'Innodb_buffer_pool_pages_free' => __(
'The number of free pages.'
),
'Innodb_buffer_pool_pages_latched' => __(
'The number of latched pages in InnoDB buffer pool. These are pages'
. ' currently being read or written or that can\'t be flushed or'
. ' removed for some other reason.'
),
'Innodb_buffer_pool_pages_misc' => __(
'The number of pages busy because they have been allocated for'
. ' administrative overhead such as row locks or the adaptive'
. ' hash index. This value can also be calculated as'
. ' Innodb_buffer_pool_pages_total - Innodb_buffer_pool_pages_free'
. ' - Innodb_buffer_pool_pages_data.'
),
'Innodb_buffer_pool_pages_total' => __(
'Total size of buffer pool, in pages.'
),
'Innodb_buffer_pool_read_ahead_rnd' => __(
'The number of "random" read-aheads InnoDB initiated. This happens'
. ' when a query is to scan a large portion of a table but in'
. ' random order.'
),
'Innodb_buffer_pool_read_ahead_seq' => __(
'The number of sequential read-aheads InnoDB initiated. This'
. ' happens when InnoDB does a sequential full table scan.'
),
'Innodb_buffer_pool_read_requests' => __(
'The number of logical read requests InnoDB has done.'
),
'Innodb_buffer_pool_reads' => __(
'The number of logical reads that InnoDB could not satisfy'
. ' from buffer pool and had to do a single-page read.'
),
'Innodb_buffer_pool_wait_free' => __(
'Normally, writes to the InnoDB buffer pool happen in the'
. ' background. However, if it\'s necessary to read or create a page'
. ' and no clean pages are available, it\'s necessary to wait for'
. ' pages to be flushed first. This counter counts instances of'
. ' these waits. If the buffer pool size was set properly, this'
. ' value should be small.'
),
'Innodb_buffer_pool_write_requests' => __(
'The number writes done to the InnoDB buffer pool.'
),
'Innodb_data_fsyncs' => __(
'The number of fsync() operations so far.'
),
'Innodb_data_pending_fsyncs' => __(
'The current number of pending fsync() operations.'
),
'Innodb_data_pending_reads' => __(
'The current number of pending reads.'
),
'Innodb_data_pending_writes' => __(
'The current number of pending writes.'
),
'Innodb_data_read' => __(
'The amount of data read so far, in bytes.'
),
'Innodb_data_reads' => __(
'The total number of data reads.'
),
'Innodb_data_writes' => __(
'The total number of data writes.'
),
'Innodb_data_written' => __(
'The amount of data written so far, in bytes.'
),
'Innodb_dblwr_pages_written' => __(
'The number of pages that have been written for'
. ' doublewrite operations.'
),
'Innodb_dblwr_writes' => __(
'The number of doublewrite operations that have been performed.'
),
'Innodb_log_waits' => __(
'The number of waits we had because log buffer was too small and'
. ' we had to wait for it to be flushed before continuing.'
),
'Innodb_log_write_requests' => __(
'The number of log write requests.'
),
'Innodb_log_writes' => __(
'The number of physical writes to the log file.'
),
'Innodb_os_log_fsyncs' => __(
'The number of fsync() writes done to the log file.'
),
'Innodb_os_log_pending_fsyncs' => __(
'The number of pending log file fsyncs.'
),
'Innodb_os_log_pending_writes' => __(
'Pending log file writes.'
),
'Innodb_os_log_written' => __(
'The number of bytes written to the log file.'
),
'Innodb_pages_created' => __(
'The number of pages created.'
),
'Innodb_page_size' => __(
'The compiled-in InnoDB page size (default 16KB). Many values are'
. ' counted in pages; the page size allows them to be easily'
. ' converted to bytes.'
),
'Innodb_pages_read' => __(
'The number of pages read.'
),
'Innodb_pages_written' => __(
'The number of pages written.'
),
'Innodb_row_lock_current_waits' => __(
'The number of row locks currently being waited for.'
),
'Innodb_row_lock_time_avg' => __(
'The average time to acquire a row lock, in milliseconds.'
),
'Innodb_row_lock_time' => __(
'The total time spent in acquiring row locks, in milliseconds.'
),
'Innodb_row_lock_time_max' => __(
'The maximum time to acquire a row lock, in milliseconds.'
),
'Innodb_row_lock_waits' => __(
'The number of times a row lock had to be waited for.'
),
'Innodb_rows_deleted' => __(
'The number of rows deleted from InnoDB tables.'
),
'Innodb_rows_inserted' => __(
'The number of rows inserted in InnoDB tables.'
),
'Innodb_rows_read' => __(
'The number of rows read from InnoDB tables.'
),
'Innodb_rows_updated' => __(
'The number of rows updated in InnoDB tables.'
),
'Key_blocks_not_flushed' => __(
'The number of key blocks in the key cache that have changed but'
. ' haven\'t yet been flushed to disk. It used to be known as'
. ' Not_flushed_key_blocks.'
),
'Key_blocks_unused' => __(
'The number of unused blocks in the key cache. You can use this'
. ' value to determine how much of the key cache is in use.'
),
'Key_blocks_used' => __(
'The number of used blocks in the key cache. This value is a'
. ' high-water mark that indicates the maximum number of blocks'
. ' that have ever been in use at one time.'
),
'Key_buffer_fraction_%' => __(
'Percentage of used key cache (calculated value)'
),
'Key_read_requests' => __(
'The number of requests to read a key block from the cache.'
),
'Key_reads' => __(
'The number of physical reads of a key block from disk. If Key_reads'
. ' is big, then your key_buffer_size value is probably too small.'
. ' The cache miss rate can be calculated as'
. ' Key_reads/Key_read_requests.'
),
'Key_read_ratio_%' => __(
'Key cache miss calculated as rate of physical reads compared'
. ' to read requests (calculated value)'
),
'Key_write_requests' => __(
'The number of requests to write a key block to the cache.'
),
'Key_writes' => __(
'The number of physical writes of a key block to disk.'
),
'Key_write_ratio_%' => __(
'Percentage of physical writes compared'
. ' to write requests (calculated value)'
),
'Last_query_cost' => __(
'The total cost of the last compiled query as computed by the query'
. ' optimizer. Useful for comparing the cost of different query'
. ' plans for the same query. The default value of 0 means that'
. ' no query has been compiled yet.'
),
'Max_used_connections' => __(
'The maximum number of connections that have been in use'
. ' simultaneously since the server started.'
),
'Not_flushed_delayed_rows' => __(
'The number of rows waiting to be written in INSERT DELAYED queues.'
),
'Opened_tables' => __(
'The number of tables that have been opened. If opened tables is'
. ' big, your table cache value is probably too small.'
),
'Open_files' => __(
'The number of files that are open.'
),
'Open_streams' => __(
'The number of streams that are open (used mainly for logging).'
),
'Open_tables' => __(
'The number of tables that are open.'
),
'Qcache_free_blocks' => __(
'The number of free memory blocks in query cache. High numbers can'
. ' indicate fragmentation issues, which may be solved by issuing'
. ' a FLUSH QUERY CACHE statement.'
),
'Qcache_free_memory' => __(
'The amount of free memory for query cache.'
),
'Qcache_hits' => __(
'The number of cache hits.'
),
'Qcache_inserts' => __(
'The number of queries added to the cache.'
),
'Qcache_lowmem_prunes' => __(
'The number of queries that have been removed from the cache to'
. ' free up memory for caching new queries. This information can'
. ' help you tune the query cache size. The query cache uses a'
. ' least recently used (LRU) strategy to decide which queries'
. ' to remove from the cache.'
),
'Qcache_not_cached' => __(
'The number of non-cached queries (not cachable, or not cached'
. ' due to the query_cache_type setting).'
),
'Qcache_queries_in_cache' => __(
'The number of queries registered in the cache.'
),
'Qcache_total_blocks' => __(
'The total number of blocks in the query cache.'
),
'Rpl_status' => __(
'The status of failsafe replication (not yet implemented).'
),
'Select_full_join' => __(
'The number of joins that do not use indexes. If this value is'
. ' not 0, you should carefully check the indexes of your tables.'
),
'Select_full_range_join' => __(
'The number of joins that used a range search on a reference table.'
),
'Select_range_check' => __(
'The number of joins without keys that check for key usage after'
. ' each row. (If this is not 0, you should carefully check the'
. ' indexes of your tables.)'
),
'Select_range' => __(
'The number of joins that used ranges on the first table. (It\'s'
. ' normally not critical even if this is big.)'
),
'Select_scan' => __(
'The number of joins that did a full scan of the first table.'
),
'Slave_open_temp_tables' => __(
'The number of temporary tables currently'
. ' open by the slave SQL thread.'
),
'Slave_retried_transactions' => __(
'Total (since startup) number of times the replication slave SQL'
. ' thread has retried transactions.'
),
'Slave_running' => __(
'This is ON if this server is a slave that is connected to a master.'
),
'Slow_launch_threads' => __(
'The number of threads that have taken more than slow_launch_time'
. ' seconds to create.'
),
'Slow_queries' => __(
'The number of queries that have taken more than long_query_time'
. ' seconds.'
),
'Sort_merge_passes' => __(
'The number of merge passes the sort algorithm has had to do.'
. ' If this value is large, you should consider increasing the'
. ' value of the sort_buffer_size system variable.'
),
'Sort_range' => __(
'The number of sorts that were done with ranges.'
),
'Sort_rows' => __(
'The number of sorted rows.'
),
'Sort_scan' => __(
'The number of sorts that were done by scanning the table.'
),
'Table_locks_immediate' => __(
'The number of times that a table lock was acquired immediately.'
),
'Table_locks_waited' => __(
'The number of times that a table lock could not be acquired'
. ' immediately and a wait was needed. If this is high, and you have'
. ' performance problems, you should first optimize your queries,'
. ' and then either split your table or tables or use replication.'
),
'Threads_cached' => __(
'The number of threads in the thread cache. The cache hit rate can'
. ' be calculated as Threads_created/Connections. If this value is'
. ' red you should raise your thread_cache_size.'
),
'Threads_connected' => __(
'The number of currently open connections.'
),
'Threads_created' => __(
'The number of threads created to handle connections. If'
. ' Threads_created is big, you may want to increase the'
. ' thread_cache_size value. (Normally this doesn\'t give a notable'
. ' performance improvement if you have a good thread'
. ' implementation.)'
),
'Threads_cache_hitrate_%' => __(
'Thread cache hit rate (calculated value)'
),
'Threads_running' => __(
'The number of threads that are not sleeping.'
)
);
}
}

View File

@@ -0,0 +1,379 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* set of functions for user group handling
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Server;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
/**
* PhpMyAdmin\Server\UserGroups class
*
* @package PhpMyAdmin
*/
class UserGroups
{
/**
* Return HTML to list the users belonging to a given user group
*
* @param string $userGroup user group name
*
* @return string HTML to list the users belonging to a given user group
*/
public static function getHtmlForListingUsersofAGroup($userGroup)
{
$relation = new Relation();
$html_output = '<h2>'
. sprintf(__('Users of \'%s\' user group'), htmlspecialchars($userGroup))
. '</h2>';
$cfgRelation = $relation->getRelationsParam();
$usersTable = Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['users']);
$sql_query = "SELECT `username` FROM " . $usersTable
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "'";
$result = $relation->queryAsControlUser($sql_query, false);
if ($result) {
if ($GLOBALS['dbi']->numRows($result) == 0) {
$html_output .= '<p>'
. __('No users were found belonging to this user group.')
. '</p>';
} else {
$html_output .= '<table>'
. '<thead><tr><th>#</th><th>' . __('User') . '</th></tr></thead>'
. '<tbody>';
$i = 0;
while ($row = $GLOBALS['dbi']->fetchRow($result)) {
$i++;
$html_output .= '<tr>'
. '<td>' . $i . ' </td>'
. '<td>' . htmlspecialchars($row[0]) . '</td>'
. '</tr>';
}
$html_output .= '</tbody>'
. '</table>';
}
}
$GLOBALS['dbi']->freeResult($result);
return $html_output;
}
/**
* Returns HTML for the 'user groups' table
*
* @return string HTML for the 'user groups' table
*/
public static function getHtmlForUserGroupsTable()
{
$relation = new Relation();
$html_output = '<h2>' . __('User groups') . '</h2>';
$cfgRelation = $relation->getRelationsParam();
$groupTable = Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['usergroups']);
$sql_query = "SELECT * FROM " . $groupTable . " ORDER BY `usergroup` ASC";
$result = $relation->queryAsControlUser($sql_query, false);
if ($result && $GLOBALS['dbi']->numRows($result)) {
$html_output .= '<form name="userGroupsForm" id="userGroupsForm"'
. ' action="server_privileges.php" method="post">';
$html_output .= Url::getHiddenInputs();
$html_output .= '<table id="userGroupsTable">';
$html_output .= '<thead><tr>';
$html_output .= '<th style="white-space: nowrap">'
. __('User group') . '</th>';
$html_output .= '<th>' . __('Server level tabs') . '</th>';
$html_output .= '<th>' . __('Database level tabs') . '</th>';
$html_output .= '<th>' . __('Table level tabs') . '</th>';
$html_output .= '<th>' . __('Action') . '</th>';
$html_output .= '</tr></thead>';
$html_output .= '<tbody>';
$userGroups = array();
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
$groupName = $row['usergroup'];
if (! isset($userGroups[$groupName])) {
$userGroups[$groupName] = array();
}
$userGroups[$groupName][$row['tab']] = $row['allowed'];
}
foreach ($userGroups as $groupName => $tabs) {
$html_output .= '<tr>';
$html_output .= '<td>' . htmlspecialchars($groupName) . '</td>';
$html_output .= '<td>' . self::getAllowedTabNames($tabs, 'server') . '</td>';
$html_output .= '<td>' . self::getAllowedTabNames($tabs, 'db') . '</td>';
$html_output .= '<td>' . self::getAllowedTabNames($tabs, 'table') . '</td>';
$html_output .= '<td>';
$html_output .= '<a class="" href="server_user_groups.php" data-post="'
. Url::getCommon(
array(
'viewUsers' => 1, 'userGroup' => $groupName
),
'', false
)
. '">'
. Util::getIcon('b_usrlist', __('View users'))
. '</a>';
$html_output .= '&nbsp;&nbsp;';
$html_output .= '<a class="" href="server_user_groups.php" data-post="'
. Url::getCommon(
array(
'editUserGroup' => 1, 'userGroup' => $groupName
),
'', false
)
. '">'
. Util::getIcon('b_edit', __('Edit')) . '</a>';
$html_output .= '&nbsp;&nbsp;';
$html_output .= '<a class="deleteUserGroup ajax"'
. ' href="server_user_groups.php" data-post="'
. Url::getCommon(
array(
'deleteUserGroup' => 1, 'userGroup' => $groupName
),
'', false
)
. '">'
. Util::getIcon('b_drop', __('Delete')) . '</a>';
$html_output .= '</td>';
$html_output .= '</tr>';
}
$html_output .= '</tbody>';
$html_output .= '</table>';
$html_output .= '</form>';
}
$GLOBALS['dbi']->freeResult($result);
$html_output .= '<fieldset id="fieldset_add_user_group">';
$html_output .= '<a href="server_user_groups.php'
. Url::getCommon(array('addUserGroup' => 1)) . '">'
. Util::getIcon('b_usradd')
. __('Add user group') . '</a>';
$html_output .= '</fieldset>';
return $html_output;
}
/**
* Returns the list of allowed menu tab names
* based on a data row from usergroup table.
*
* @param array $row row of usergroup table
* @param string $level 'server', 'db' or 'table'
*
* @return string comma separated list of allowed menu tab names
*/
public static function getAllowedTabNames(array $row, $level)
{
$tabNames = array();
$tabs = Util::getMenuTabList($level);
foreach ($tabs as $tab => $tabName) {
if (! isset($row[$level . '_' . $tab])
|| $row[$level . '_' . $tab] == 'Y'
) {
$tabNames[] = $tabName;
}
}
return implode(', ', $tabNames);
}
/**
* Deletes a user group
*
* @param string $userGroup user group name
*
* @return void
*/
public static function delete($userGroup)
{
$relation = new Relation();
$cfgRelation = $relation->getRelationsParam();
$userTable = Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['users']);
$groupTable = Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['usergroups']);
$sql_query = "DELETE FROM " . $userTable
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "'";
$relation->queryAsControlUser($sql_query, true);
$sql_query = "DELETE FROM " . $groupTable
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "'";
$relation->queryAsControlUser($sql_query, true);
}
/**
* Returns HTML for add/edit user group dialog
*
* @param string $userGroup name of the user group in case of editing
*
* @return string HTML for add/edit user group dialog
*/
public static function getHtmlToEditUserGroup($userGroup = null)
{
$relation = new Relation();
$html_output = '';
if ($userGroup == null) {
$html_output .= '<h2>' . __('Add user group') . '</h2>';
} else {
$html_output .= '<h2>'
. sprintf(__('Edit user group: \'%s\''), htmlspecialchars($userGroup))
. '</h2>';
}
$html_output .= '<form name="userGroupForm" id="userGroupForm"'
. ' action="server_user_groups.php" method="post">';
$urlParams = array();
if ($userGroup != null) {
$urlParams['userGroup'] = $userGroup;
$urlParams['editUserGroupSubmit'] = '1';
} else {
$urlParams['addUserGroupSubmit'] = '1';
}
$html_output .= Url::getHiddenInputs($urlParams);
$html_output .= '<fieldset id="fieldset_user_group_rights">';
$html_output .= '<legend>' . __('User group menu assignments')
. '&nbsp;&nbsp;&nbsp;'
. '<input type="checkbox" id="addUsersForm_checkall" '
. 'class="checkall_box" title="Check all">'
. '<label for="addUsersForm_checkall">' . __('Check all') . '</label>'
. '</legend>';
if ($userGroup == null) {
$html_output .= '<label for="userGroup">' . __('Group name:') . '</label>';
$html_output .= '<input type="text" name="userGroup" maxlength="64" autocomplete="off" required="required" />';
$html_output .= '<div class="clearfloat"></div>';
}
$allowedTabs = array(
'server' => array(),
'db' => array(),
'table' => array()
);
if ($userGroup != null) {
$cfgRelation = $relation->getRelationsParam();
$groupTable = Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['usergroups']);
$sql_query = "SELECT * FROM " . $groupTable
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "'";
$result = $relation->queryAsControlUser($sql_query, false);
if ($result) {
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
$key = $row['tab'];
$value = $row['allowed'];
if (substr($key, 0, 7) == 'server_' && $value == 'Y') {
$allowedTabs['server'][] = mb_substr($key, 7);
} elseif (substr($key, 0, 3) == 'db_' && $value == 'Y') {
$allowedTabs['db'][] = mb_substr($key, 3);
} elseif (substr($key, 0, 6) == 'table_'
&& $value == 'Y'
) {
$allowedTabs['table'][] = mb_substr($key, 6);
}
}
}
$GLOBALS['dbi']->freeResult($result);
}
$html_output .= self::getTabList(
__('Server-level tabs'), 'server', $allowedTabs['server']
);
$html_output .= self::getTabList(
__('Database-level tabs'), 'db', $allowedTabs['db']
);
$html_output .= self::getTabList(
__('Table-level tabs'), 'table', $allowedTabs['table']
);
$html_output .= '</fieldset>';
$html_output .= '<fieldset id="fieldset_user_group_rights_footer"'
. ' class="tblFooters">';
$html_output .= '<input type="submit" value="' . __('Go') . '">';
$html_output .= '</fieldset>';
return $html_output;
}
/**
* Returns HTML for checkbox groups to choose
* tabs of 'server', 'db' or 'table' levels.
*
* @param string $title title of the checkbox group
* @param string $level 'server', 'db' or 'table'
* @param array $selected array of selected allowed tabs
*
* @return string HTML for checkbox groups
*/
public static function getTabList($title, $level, array $selected)
{
$tabs = Util::getMenuTabList($level);
$html_output = '<fieldset>';
$html_output .= '<legend>' . $title . '</legend>';
foreach ($tabs as $tab => $tabName) {
$html_output .= '<div class="item">';
$html_output .= '<input type="checkbox" class="checkall"'
. (in_array($tab, $selected) ? ' checked="checked"' : '')
. ' name="' . $level . '_' . $tab . '" value="Y" />';
$html_output .= '<label for="' . $level . '_' . $tab . '">'
. '<code>' . $tabName . '</code>'
. '</label>';
$html_output .= '</div>';
}
$html_output .= '</fieldset>';
return $html_output;
}
/**
* Add/update a user group with allowed menu tabs.
*
* @param string $userGroup user group name
* @param boolean $new whether this is a new user group
*
* @return void
*/
public static function edit($userGroup, $new = false)
{
$relation = new Relation();
$tabs = Util::getMenuTabList();
$cfgRelation = $relation->getRelationsParam();
$groupTable = Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['usergroups']);
if (! $new) {
$sql_query = "DELETE FROM " . $groupTable
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "';";
$relation->queryAsControlUser($sql_query, true);
}
$sql_query = "INSERT INTO " . $groupTable
. "(`usergroup`, `tab`, `allowed`)"
. " VALUES ";
$first = true;
foreach ($tabs as $tabGroupName => $tabGroup) {
foreach ($tabGroup as $tab => $tabName) {
if (! $first) {
$sql_query .= ", ";
}
$tabName = $tabGroupName . '_' . $tab;
$allowed = isset($_POST[$tabName]) && $_POST[$tabName] == 'Y';
$sql_query .= "('" . $GLOBALS['dbi']->escapeString($userGroup) . "', '" . $tabName . "', '"
. ($allowed ? "Y" : "N") . "')";
$first = false;
}
}
$sql_query .= ";";
$relation->queryAsControlUser($sql_query, true);
}
}

View File

@@ -0,0 +1,62 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* set of common functions for sub tabs in server level `Users` page
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Server;
use PhpMyAdmin\Url;
/**
* PhpMyAdmin\Server\Users class
*
* @package PhpMyAdmin
*/
class Users
{
/**
* Get HTML for secondary level menu tabs on 'Users' page
*
* @param string $selfUrl Url of the file
*
* @return string HTML for secondary level menu tabs on 'Users' page
*/
public static function getHtmlForSubMenusOnUsersPage($selfUrl)
{
$items = array(
array(
'name' => __('User accounts overview'),
'url' => 'server_privileges.php',
'params' => Url::getCommon(array('viewing_mode' => 'server')),
)
);
if ($GLOBALS['dbi']->isSuperuser()) {
$items[] = array(
'name' => __('User groups'),
'url' => 'server_user_groups.php',
'params' => Url::getCommon(),
);
}
$retval = '<ul id="topmenu2">';
foreach ($items as $item) {
$class = '';
if ($item['url'] === $selfUrl) {
$class = ' class="tabactive"';
}
$retval .= '<li>';
$retval .= '<a' . $class;
$retval .= ' href="' . $item['url'] . $item['params'] . '">';
$retval .= $item['name'];
$retval .= '</a>';
$retval .= '</li>';
}
$retval .= '</ul>';
$retval .= '<div class="clearfloat"></div>';
return $retval;
}
}