server_variables.php 7.7 KB

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