AuthenticationConfig.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Config Authentication plugin for phpMyAdmin
  5. *
  6. * @package PhpMyAdmin-Authentication
  7. * @subpackage Config
  8. */
  9. namespace PhpMyAdmin\Plugins\Auth;
  10. use PhpMyAdmin\Plugins\AuthenticationPlugin;
  11. use PhpMyAdmin\Response;
  12. use PhpMyAdmin\Server\Select;
  13. use PhpMyAdmin\Url;
  14. use PhpMyAdmin\Util;
  15. /**
  16. * Handles the config authentication method
  17. *
  18. * @package PhpMyAdmin-Authentication
  19. */
  20. class AuthenticationConfig extends AuthenticationPlugin
  21. {
  22. /**
  23. * Displays authentication form
  24. *
  25. * @return boolean always true
  26. */
  27. public function showLoginForm()
  28. {
  29. $response = Response::getInstance();
  30. if ($response->isAjax()) {
  31. $response->setRequestStatus(false);
  32. // reload_flag removes the token parameter from the URL and reloads
  33. $response->addJSON('reload_flag', '1');
  34. if (defined('TESTSUITE')) {
  35. return true;
  36. } else {
  37. exit;
  38. }
  39. }
  40. return true;
  41. }
  42. /**
  43. * Gets authentication credentials
  44. *
  45. * @return boolean always true
  46. */
  47. public function readCredentials()
  48. {
  49. if ($GLOBALS['token_provided'] && $GLOBALS['token_mismatch']) {
  50. return false;
  51. }
  52. $this->user = $GLOBALS['cfg']['Server']['user'];
  53. $this->password = $GLOBALS['cfg']['Server']['password'];
  54. return true;
  55. }
  56. /**
  57. * User is not allowed to login to MySQL -> authentication failed
  58. *
  59. * @param string $failure String describing why authentication has failed
  60. *
  61. * @return void
  62. */
  63. public function showFailure($failure)
  64. {
  65. parent::showFailure($failure);
  66. $conn_error = $GLOBALS['dbi']->getError();
  67. if (!$conn_error) {
  68. $conn_error = __('Cannot connect: invalid settings.');
  69. }
  70. /* HTML header */
  71. $response = Response::getInstance();
  72. $response->getFooter()
  73. ->setMinimal();
  74. $header = $response->getHeader();
  75. $header->setBodyId('loginform');
  76. $header->setTitle(__('Access denied!'));
  77. $header->disableMenuAndConsole();
  78. echo '<br /><br />
  79. <center>
  80. <h1>';
  81. echo sprintf(__('Welcome to %s'), ' phpMyAdmin ');
  82. echo '</h1>
  83. </center>
  84. <br />
  85. <table cellpadding="0" cellspacing="3" class= "auth_config_tbl" width="80%">
  86. <tr>
  87. <td>';
  88. if (isset($GLOBALS['allowDeny_forbidden'])
  89. && $GLOBALS['allowDeny_forbidden']
  90. ) {
  91. trigger_error(__('Access denied!'), E_USER_NOTICE);
  92. } else {
  93. // Check whether user has configured something
  94. if ($GLOBALS['PMA_Config']->source_mtime == 0) {
  95. echo '<p>' , sprintf(
  96. __(
  97. 'You probably did not create a configuration file.'
  98. . ' You might want to use the %1$ssetup script%2$s to'
  99. . ' create one.'
  100. ),
  101. '<a href="setup/">',
  102. '</a>'
  103. ) , '</p>' , "\n";
  104. } elseif (!isset($GLOBALS['errno'])
  105. || (isset($GLOBALS['errno']) && $GLOBALS['errno'] != 2002)
  106. && $GLOBALS['errno'] != 2003
  107. ) {
  108. // if we display the "Server not responding" error, do not confuse
  109. // users by telling them they have a settings problem
  110. // (note: it's true that they could have a badly typed host name,
  111. // but anyway the current message tells that the server
  112. // rejected the connection, which is not really what happened)
  113. // 2002 is the error given by mysqli
  114. // 2003 is the error given by mysql
  115. trigger_error(
  116. __(
  117. 'phpMyAdmin tried to connect to the MySQL server, and the'
  118. . ' server rejected the connection. You should check the'
  119. . ' host, username and password in your configuration and'
  120. . ' make sure that they correspond to the information given'
  121. . ' by the administrator of the MySQL server.'
  122. ),
  123. E_USER_WARNING
  124. );
  125. }
  126. echo Util::mysqlDie(
  127. $conn_error,
  128. '',
  129. true,
  130. '',
  131. false
  132. );
  133. }
  134. $GLOBALS['error_handler']->dispUserErrors();
  135. echo '</td>
  136. </tr>
  137. <tr>
  138. <td>' , "\n";
  139. echo '<a href="'
  140. , Util::getScriptNameForOption(
  141. $GLOBALS['cfg']['DefaultTabServer'],
  142. 'server'
  143. )
  144. , Url::getCommon() , '" class="button disableAjax">'
  145. , __('Retry to connect')
  146. , '</a>' , "\n";
  147. echo '</td>
  148. </tr>' , "\n";
  149. if (count($GLOBALS['cfg']['Servers']) > 1) {
  150. // offer a chance to login to other servers if the current one failed
  151. echo '<tr>' , "\n";
  152. echo ' <td>' , "\n";
  153. echo Select::render(true, true);
  154. echo ' </td>' , "\n";
  155. echo '</tr>' , "\n";
  156. }
  157. echo '</table>' , "\n";
  158. if (!defined('TESTSUITE')) {
  159. exit;
  160. }
  161. }
  162. }