AuthenticationConfig.class.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. /* Get the authentication interface */
  13. require_once 'libraries/plugins/AuthenticationPlugin.class.php';
  14. /**
  15. * Handles the config authentication method
  16. *
  17. * @package PhpMyAdmin-Authentication
  18. */
  19. class AuthenticationConfig extends AuthenticationPlugin
  20. {
  21. /**
  22. * Displays authentication form
  23. *
  24. * @return boolean always true
  25. */
  26. public function auth()
  27. {
  28. return true;
  29. }
  30. /**
  31. * Gets advanced authentication settings
  32. *
  33. * @return boolean always true
  34. */
  35. public function authCheck()
  36. {
  37. return true;
  38. }
  39. /**
  40. * Set the user and password after last checkings if required
  41. *
  42. * @return boolean always true
  43. */
  44. public function authSetUser()
  45. {
  46. return true;
  47. }
  48. /**
  49. * User is not allowed to login to MySQL -> authentication failed
  50. *
  51. * @global string the MySQL error message PHP returns
  52. * @global string the connection type (persistent or not)
  53. * @global string the MySQL server port to use
  54. * @global string the MySQL socket port to use
  55. * @global array the current server settings
  56. * @global string the font face to use in case of failure
  57. * @global string the default font size to use in case of failure
  58. * @global string the big font size to use in case of failure
  59. * @global boolean tell the "PMA_mysqlDie()" function headers have been
  60. * sent
  61. *
  62. * @return boolean always true (no return indeed)
  63. */
  64. public function authFails()
  65. {
  66. $conn_error = PMA_DBI_getError();
  67. if (! $conn_error) {
  68. $conn_error = __('Cannot connect: invalid settings.');
  69. }
  70. /* HTML header */
  71. $response = PMA_Response::getInstance();
  72. $response->getFooter()->setMinimal();
  73. $header = $response->getHeader();
  74. $header->setBodyId('loginform');
  75. $header->setTitle(__('Access denied'));
  76. $header->disableMenu();
  77. echo '<br /><br />
  78. <center>
  79. <h1>';
  80. echo sprintf(__('Welcome to %s'), ' phpMyAdmin ');
  81. echo '</h1>
  82. </center>
  83. <br />
  84. <table cellpadding="0" cellspacing="3" style="margin: 0 auto" width="80%">
  85. <tr>
  86. <td>';
  87. if (isset($GLOBALS['allowDeny_forbidden'])
  88. && $GLOBALS['allowDeny_forbidden']
  89. ) {
  90. trigger_error(__('Access denied'), E_USER_NOTICE);
  91. } else {
  92. // Check whether user has configured something
  93. if ($GLOBALS['PMA_Config']->source_mtime == 0) {
  94. echo '<p>' . sprintf(
  95. __(
  96. 'You probably did not create a configuration file.'
  97. . ' You might want to use the %1$ssetup script%2$s to'
  98. . ' create one.'
  99. ),
  100. '<a href="setup/">',
  101. '</a>'
  102. ) . '</p>' . "\n";
  103. } elseif (! isset($GLOBALS['errno'])
  104. || (isset($GLOBALS['errno']) && $GLOBALS['errno'] != 2002)
  105. && $GLOBALS['errno'] != 2003
  106. ) {
  107. // if we display the "Server not responding" error, do not confuse
  108. // users by telling them they have a settings problem
  109. // (note: it's true that they could have a badly typed host name,
  110. // but anyway the current message tells that the server
  111. // rejected the connection, which is not really what happened)
  112. // 2002 is the error given by mysqli
  113. // 2003 is the error given by mysql
  114. trigger_error(
  115. __(
  116. 'phpMyAdmin tried to connect to the MySQL server, and the'
  117. . ' server rejected the connection. You should check the'
  118. . ' host, username and password in your configuration and'
  119. . ' make sure that they correspond to the information given'
  120. . ' by the administrator of the MySQL server.'
  121. ), E_USER_WARNING
  122. );
  123. }
  124. echo PMA_Util::mysqlDie(
  125. $conn_error, '', true, '', false
  126. );
  127. }
  128. $GLOBALS['error_handler']->dispUserErrors();
  129. echo '</td>
  130. </tr>
  131. <tr>
  132. <td>' . "\n";
  133. echo '<a href="'
  134. . $GLOBALS['cfg']['DefaultTabServer']
  135. . PMA_generate_common_url(array()) . '" class="button disableAjax">'
  136. . __('Retry to connect')
  137. . '</a>' . "\n";
  138. echo '</td>
  139. </tr>' . "\n";
  140. if (count($GLOBALS['cfg']['Servers']) > 1) {
  141. // offer a chance to login to other servers if the current one failed
  142. include_once './libraries/select_server.lib.php';
  143. echo '<tr>' . "\n";
  144. echo ' <td>' . "\n";
  145. echo PMA_selectServer(true, true);
  146. echo ' </td>' . "\n";
  147. echo '</tr>' . "\n";
  148. }
  149. echo '</table>' . "\n";
  150. exit;
  151. return true;
  152. }
  153. /**
  154. * This method is called when any PluginManager to which the observer
  155. * is attached calls PluginManager::notify()
  156. *
  157. * @param SplSubject $subject The PluginManager notifying the observer
  158. * of an update.
  159. *
  160. * @return void
  161. */
  162. public function update (SplSubject $subject)
  163. {
  164. }
  165. }