forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_variables.php
230 lines (202 loc) · 6.83 KB
/
server_variables.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Server variables
*
* @package PhpMyAdmin
*/
require_once 'libraries/common.inc.php';
$response = PMA_Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('server_variables.js');
$common_functions = PMA_CommonFunctions::getInstance();
PMA_addJSVar('pma_token', $_SESSION[' PMA_token ']);
PMA_addJSVar('url_query', str_replace('&', '&', PMA_generate_common_url($db)));
PMA_addJSVar('is_superuser', PMA_isSuperuser() ? true : false);
/**
* Does the common work
*/
require 'libraries/server_common.inc.php';
/**
* Required to display documentation links
*/
require 'libraries/server_variables_doc.php';
/**
* Ajax request
*/
if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
// Send with correct charset
if (isset($_REQUEST['type'])) {
switch($_REQUEST['type']) {
case 'getval':
header('Content-Type: text/html; charset=UTF-8');
$varValue = PMA_DBI_fetch_single_row(
'SHOW GLOBAL VARIABLES WHERE Variable_name="'
. $common_functions->sqlAddSlashes($_REQUEST['varName']) . '";',
'NUM'
);
if (isset($VARIABLE_DOC_LINKS[$_REQUEST['varName']][3])
&& $VARIABLE_DOC_LINKS[$_REQUEST['varName']][3] == 'byte'
) {
exit(
implode(
' ', $common_functions->formatByteDown($varValue[1], 3, 3)
)
);
}
exit($varValue[1]);
break;
case 'setval':
$value = $_REQUEST['varValue'];
if (isset($VARIABLE_DOC_LINKS[$_REQUEST['varName']][3])
&& $VARIABLE_DOC_LINKS[$_REQUEST['varName']][3] == 'byte'
&& preg_match(
'/^\s*(\d+(\.\d+)?)\s*(mb|kb|mib|kib|gb|gib)\s*$/i',
$value,
$matches
)
) {
$exp = array(
'kb' => 1,
'kib' => 1,
'mb' => 2,
'mib' => 2,
'gb' => 3,
'gib' => 3
);
$value = floatval($matches[1]) * $common_functions->pow(
1024,
$exp[strtolower($matches[3])]
);
} else {
$value = $common_functions->sqlAddSlashes($value);
}
if (! is_numeric($value)) {
$value="'" . $value . "'";
}
$response = PMA_Response::getInstance();
if (! preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName'])
&& PMA_DBI_query(
'SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value
)
) {
// Some values are rounded down etc.
$varValue = PMA_DBI_fetch_single_row(
'SHOW GLOBAL VARIABLES WHERE Variable_name="'
. $common_functions->sqlAddSlashes($_REQUEST['varName'])
. '";', 'NUM'
);
$response->addJSON(
'variable',
formatVariable($_REQUEST['varName'], $varValue[1])
);
} else {
$response->isSuccess(false);
$response->addJSON(
'error',
__('Setting variable failed')
);
}
exit;
break;
}
}
}
/**
* Displays the sub-page heading
*/
$output = '<h2>' . $common_functions->getImage('s_vars.png')
. '' . __('Server variables and settings') . "\n"
. $common_functions->showMySQLDocu(
'server_system_variables', 'server_system_variables'
)
. '</h2>' . "\n";
/**
* Sends the queries and buffers the results
*/
$serverVarsSession = PMA_DBI_fetch_result('SHOW SESSION VARIABLES;', 0, 1);
$serverVars = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES;', 0, 1);
/**
* Displays the page
*/
$output .= '<fieldset id="tableFilter" style="display:none;">'
. '<legend>' . __('Filters') . '</legend>'
. '<div class="formelement">'
. '<label for="filterText">' . __('Containing the word:') . '</label>'
. '<input name="filterText" type="text" id="filterText"'
. ' style="vertical-align: baseline;" />'
. '</div>'
. '</fieldset>';
$output .= '<table id="serverVariables" class="data filteredData noclick">'
. '<thead>'
. '<tr><th>' . __('Variable') . '</th>'
. '<th class="valueHeader">'
. __('Session value') . ' / ' . __('Global value')
. '</th>'
. '<th>' . __('Documentation') . '</th>'
. '</tr>'
. '</thead>'
. '<tbody>';
$odd_row = true;
foreach ($serverVars as $name => $value) {
$has_session_value = isset($serverVarsSession[$name])
&& $serverVarsSession[$name] != $value;
$row_class = ($odd_row ? 'odd' : 'even') . ' '
. ($has_session_value ? 'diffSession' : '');
$output .= '<tr class="' . $row_class . '">'
. '<th class="nowrap">' . htmlspecialchars(str_replace('_', ' ', $name))
. '</th>'
. '<td class="value">' . formatVariable($name, $value) . '</td>'
. '<td class="value">';
// To display variable documentation link
if (isset($VARIABLE_DOC_LINKS[$name])) {
$output .= $common_functions->showMySQLDocu(
$VARIABLE_DOC_LINKS[$name][1],
$VARIABLE_DOC_LINKS[$name][1],
false,
$VARIABLE_DOC_LINKS[$name][2] . '_' . $VARIABLE_DOC_LINKS[$name][0]
);
}
$output .= '</td>';
if ($has_session_value) {
$output .= '</tr>'
. '<tr class="' . ($odd_row ? 'odd' : 'even') . '">'
. '<td>(' . __('Session value') . ')</td>'
. '<td class="value">' . formatVariable($name, $serverVarsSession[$name])
. '</td>'
. '<td class="value"></td>';
}
$output .= '</tr>';
$odd_row = ! $odd_row;
}
$output .= '</tbody>'
. '</table>';
$response->addHtml($output);
/**
* Format Variable
*
* @param string $name variable name
* @param numeric $value variable value
*
* @return formatted string
*/
function formatVariable($name, $value)
{
global $VARIABLE_DOC_LINKS;
$common_functions = PMA_CommonFunctions::getInstance();
if (is_numeric($value)) {
if (isset($VARIABLE_DOC_LINKS[$name][3])
&& $VARIABLE_DOC_LINKS[$name][3]=='byte'
) {
return '<abbr title="'
. $common_functions->formatNumber($value, 0) . '">'
. implode(' ', $common_functions->formatByteDown($value, 3, 3))
. '</abbr>';
} else {
return $common_functions->formatNumber($value, 0);
}
}
return htmlspecialchars($value);
}
?>