AuthenticationConfig.class.php 5.8 KB

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