server_binlog.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * display the binary logs and the content of the selected
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. /**
  9. *
  10. */
  11. require_once 'libraries/common.inc.php';
  12. /**
  13. * Does the common work, provides $binary_logs
  14. */
  15. require_once 'libraries/server_common.inc.php';
  16. $url_params = array();
  17. /**
  18. * Need to find the real end of rows?
  19. */
  20. if (! isset($_REQUEST['pos'])) {
  21. $pos = 0;
  22. } else {
  23. /* We need this to be a integer */
  24. $pos = (int) $_REQUEST['pos'];
  25. }
  26. if (! isset($_REQUEST['log'])
  27. || ! array_key_exists($_REQUEST['log'], $binary_logs)
  28. ) {
  29. $_REQUEST['log'] = '';
  30. } else {
  31. $url_params['log'] = $_REQUEST['log'];
  32. }
  33. $sql_query = 'SHOW BINLOG EVENTS';
  34. if (! empty($_REQUEST['log'])) {
  35. $sql_query .= ' IN \'' . $_REQUEST['log'] . '\'';
  36. }
  37. if ($GLOBALS['cfg']['MaxRows'] !== 'all') {
  38. $sql_query .= ' LIMIT ' . $pos . ', ' . (int) $GLOBALS['cfg']['MaxRows'];
  39. }
  40. /**
  41. * Sends the query
  42. */
  43. $result = PMA_DBI_query($sql_query);
  44. /**
  45. * prepare some vars for displaying the result table
  46. */
  47. // Gets the list of fields properties
  48. if (isset($result) && $result) {
  49. $num_rows = PMA_DBI_num_rows($result);
  50. } else {
  51. $num_rows = 0;
  52. }
  53. if (empty($_REQUEST['dontlimitchars'])) {
  54. $dontlimitchars = false;
  55. } else {
  56. $dontlimitchars = true;
  57. $url_params['dontlimitchars'] = 1;
  58. }
  59. /**
  60. * Displays the sub-page heading
  61. */
  62. echo '<h2>' . "\n"
  63. . PMA_Util::getImage('s_tbl.png')
  64. . ' ' . __('Binary log') . "\n"
  65. . '</h2>' . "\n";
  66. /**
  67. * Display log selector.
  68. */
  69. if (count($binary_logs) > 1) {
  70. echo '<form action="server_binlog.php" method="get">';
  71. echo PMA_generate_common_hidden_inputs($url_params);
  72. echo '<fieldset><legend>';
  73. echo __('Select binary log to view');
  74. echo '</legend><select name="log">';
  75. $full_size = 0;
  76. foreach ($binary_logs as $each_log) {
  77. echo '<option value="' . htmlspecialchars($each_log['Log_name']) . '"';
  78. if ($each_log['Log_name'] == $_REQUEST['log']) {
  79. echo ' selected="selected"';
  80. }
  81. echo '>' . htmlspecialchars($each_log['Log_name']);
  82. if (isset($each_log['File_size'])) {
  83. $full_size += $each_log['File_size'];
  84. echo ' ('
  85. . implode(
  86. ' ',
  87. PMA_Util::formatByteDown(
  88. $each_log['File_size'], 3, 2
  89. )
  90. )
  91. . ')';
  92. }
  93. echo '</option>';
  94. }
  95. echo '</select> ';
  96. echo count($binary_logs) . ' ' . __('Files') . ', ';
  97. if ($full_size > 0) {
  98. echo implode(
  99. ' ', PMA_Util::formatByteDown($full_size)
  100. );
  101. }
  102. echo '</fieldset>';
  103. echo '<fieldset class="tblFooters">';
  104. echo '<input type="submit" value="' . __('Go') . '" />';
  105. echo '</fieldset>';
  106. echo '</form>';
  107. }
  108. echo PMA_Util::getMessage(PMA_Message::success());
  109. /**
  110. * Displays the page
  111. */
  112. echo '<table cellpadding="2" cellspacing="1">'
  113. . '<thead>'
  114. . '<tr>'
  115. . '<td colspan="6" class="center">';
  116. // we do not now how much rows are in the binlog
  117. // so we can just force 'NEXT' button
  118. if ($pos > 0) {
  119. $this_url_params = $url_params;
  120. if ($pos > $GLOBALS['cfg']['MaxRows']) {
  121. $this_url_params['pos'] = $pos - $GLOBALS['cfg']['MaxRows'];
  122. }
  123. echo '<a href="server_binlog.php'
  124. . PMA_generate_common_url($this_url_params) . '"';
  125. if (in_array(
  126. $GLOBALS['cfg']['TableNavigationLinksMode'],
  127. array('icons', 'both')
  128. )
  129. ) {
  130. echo ' title="' . _pgettext('Previous page', 'Previous') . '">';
  131. } else {
  132. echo '>' . _pgettext('Previous page', 'Previous');
  133. } // end if... else...
  134. echo ' &lt; </a> - ';
  135. }
  136. $this_url_params = $url_params;
  137. if ($pos > 0) {
  138. $this_url_params['pos'] = $pos;
  139. }
  140. if ($dontlimitchars) {
  141. unset($this_url_params['dontlimitchars']);
  142. $tempTitle = __('Truncate Shown Queries');
  143. $tempImgMode = 'partial';
  144. } else {
  145. $this_url_params['dontlimitchars'] = 1;
  146. $tempTitle = __('Show Full Queries');
  147. $tempImgMode = 'full';
  148. }
  149. echo '<a href="server_binlog.php' . PMA_generate_common_url($this_url_params)
  150. . '" title="' . $tempTitle . '">'
  151. . '<img src="' .$pmaThemeImage . 's_' . $tempImgMode . 'text.png"'
  152. . 'alt="' . $tempTitle . '" /></a>';
  153. // we do not now how much rows are in the binlog
  154. // so we can just force 'NEXT' button
  155. if ($num_rows >= $GLOBALS['cfg']['MaxRows']) {
  156. $this_url_params = $url_params;
  157. $this_url_params['pos'] = $pos + $GLOBALS['cfg']['MaxRows'];
  158. echo ' - <a href="server_binlog.php' . PMA_generate_common_url($this_url_params)
  159. . '"';
  160. if (in_array(
  161. $GLOBALS['cfg']['TableNavigationLinksMode'],
  162. array('icons', 'both')
  163. )
  164. ) {
  165. echo ' title="' . _pgettext('Next page', 'Next') . '">';
  166. } else {
  167. echo '>' . _pgettext('Next page', 'Next');
  168. } // end if... else...
  169. echo ' &gt; </a>';
  170. }
  171. echo '</td>'
  172. . '</tr>'
  173. . '<tr>'
  174. . '<th>' . __('Log name') . '</th>'
  175. . '<th>' . __('Position') . '</th>'
  176. . '<th>' . __('Event type') . '</th>'
  177. . '<th>' . __('Server ID') . '</th>'
  178. . '<th>' . __('Original position') . '</th>'
  179. . '<th>' . __('Information') . '</th>'
  180. . '</tr>'
  181. . '</thead>'
  182. . '<tbody>';
  183. $odd_row = true;
  184. while ($value = PMA_DBI_fetch_assoc($result)) {
  185. if (! $dontlimitchars
  186. && PMA_strlen($value['Info']) > $GLOBALS['cfg']['LimitChars']
  187. ) {
  188. $value['Info'] = PMA_substr(
  189. $value['Info'], 0, $GLOBALS['cfg']['LimitChars']
  190. ) . '...';
  191. }
  192. echo '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">'
  193. . '<td>&nbsp;' . $value['Log_name'] . '&nbsp;</td>'
  194. . '<td class="right">&nbsp;' . $value['Pos'] . '&nbsp;</td>'
  195. . '<td>&nbsp;' . $value['Event_type'] . '&nbsp;</td>'
  196. . '<td class="right">&nbsp;' . $value['Server_id'] . '&nbsp;</td>'
  197. . '<td class="right">&nbsp;'
  198. . (isset($value['Orig_log_pos'])
  199. ? $value['Orig_log_pos'] : $value['End_log_pos'])
  200. . '&nbsp;</td>'
  201. . '<td>&nbsp;' . htmlspecialchars($value['Info']) . '&nbsp;</td>'
  202. . '</tr>';
  203. $odd_row = !$odd_row;
  204. }
  205. echo '</tbody>'
  206. . '</table>';