Documentation TYPO3 par Ameos

http.auth.lib.php

00001 <?php
00002 /* $Id: http.auth.lib.php,v 2.3 2003/11/26 22:52:24 rabus Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 // +--------------------------------------------------------------------------+
00006 // | Set of functions used to run http authentication.                        |
00007 // | NOTE: Requires PHP loaded as a Apache module.                            |
00008 // +--------------------------------------------------------------------------+
00009 
00010 
00022 function PMA_auth()
00023 {
00024     global $right_font_family, $font_size, $font_bigger;
00025 
00026     header('WWW-Authenticate: Basic realm="phpMyAdmin ' . sprintf($GLOBALS['strRunning'], (empty($GLOBALS['cfg']['Server']['verbose']) ? str_replace('\'', '\\\'',$GLOBALS['cfg']['Server']['host']) : str_replace('\'', '\\\'', $GLOBALS['cfg']['Server']['verbose']))) .  '"');
00027     header('HTTP/1.0 401 Unauthorized');
00028     header('status: 401 Unauthorized');
00029 
00030     // Defines the charset to be used
00031     header('Content-Type: text/html; charset=' . $GLOBALS['charset']);
00032     ?>
00033 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
00034     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
00035 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $GLOBALS['available_languages'][$GLOBALS['lang']][2]; ?>" lang="<?php echo $GLOBALS['available_languages'][$GLOBALS['lang']][2]; ?>" dir="<?php echo $GLOBALS['text_dir']; ?>">
00036 
00037 <head>
00038 <title><?php echo $GLOBALS['strAccessDenied']; ?></title>
00039 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $GLOBALS['charset']; ?>" />
00040 <style type="text/css">
00041 <!--
00042 body     {font-family: <?php echo $right_font_family; ?>; font-size: <?php echo $font_size; ?>; color: #000000}
00043 h1       {font-family: <?php echo $right_font_family; ?>; font-size: <?php echo $font_bigger; ?>; font-weight: bold}
00044 //-->
00045 </style>
00046 </head>
00047 
00048 <body bgcolor="<?php echo $GLOBALS['cfg']['RightBgColor']; ?>">
00049 <br /><br />
00050 <center>
00051     <h1><?php echo sprintf($GLOBALS['strWelcome'], ' phpMyAdmin ' . PMA_VERSION); ?></h1>
00052 </center>
00053 <br />
00054 <p><?php echo $GLOBALS['strWrongUser']; ?></p>
00055 </body>
00056 
00057 </html>
00058     <?php
00059     echo "\n";
00060     exit();
00061 
00062     return TRUE;
00063 } // end of the 'PMA_auth()' function
00064 
00065 
00085 function PMA_auth_check()
00086 {
00087     global $PHP_AUTH_USER, $PHP_AUTH_PW;
00088     global $REMOTE_USER, $AUTH_USER, $REMOTE_PASSWORD, $AUTH_PASSWORD;
00089     global $HTTP_AUTHORIZATION;
00090     global $old_usr;
00091 
00092     // Grabs the $PHP_AUTH_USER variable whatever are the values of the
00093     // 'register_globals' and the 'variables_order' directives
00094     // loic1 - 2001/25/11: use the new globals arrays defined with php 4.1+
00095     if (empty($PHP_AUTH_USER)) {
00096         if (!empty($_SERVER) && isset($_SERVER['PHP_AUTH_USER'])) {
00097             $PHP_AUTH_USER = $_SERVER['PHP_AUTH_USER'];
00098         }
00099         else if (isset($REMOTE_USER)) {
00100             $PHP_AUTH_USER = $REMOTE_USER;
00101         }
00102         else if (!empty($_ENV) && isset($_ENV['REMOTE_USER'])) {
00103             $PHP_AUTH_USER = $_ENV['REMOTE_USER'];
00104         }
00105         else if (@getenv('REMOTE_USER')) {
00106             $PHP_AUTH_USER = getenv('REMOTE_USER');
00107         }
00108         // Fix from Matthias Fichtner for WebSite Professional - Part 1
00109         else if (isset($AUTH_USER)) {
00110             $PHP_AUTH_USER = $AUTH_USER;
00111         }
00112         else if (!empty($_ENV) && isset($_ENV['AUTH_USER'])) {
00113             $PHP_AUTH_USER = $_ENV['AUTH_USER'];
00114         }
00115         else if (@getenv('AUTH_USER')) {
00116             $PHP_AUTH_USER = getenv('AUTH_USER');
00117         }
00118     }
00119     // Grabs the $PHP_AUTH_PW variable whatever are the values of the
00120     // 'register_globals' and the 'variables_order' directives
00121     // loic1 - 2001/25/11: use the new globals arrays defined with php 4.1+
00122     if (empty($PHP_AUTH_PW)) {
00123         if (!empty($_SERVER) && isset($_SERVER['PHP_AUTH_PW'])) {
00124             $PHP_AUTH_PW = $_SERVER['PHP_AUTH_PW'];
00125         }
00126         else if (isset($REMOTE_PASSWORD)) {
00127             $PHP_AUTH_PW = $REMOTE_PASSWORD;
00128         }
00129         else if (!empty($_ENV) && isset($_ENV['REMOTE_PASSWORD'])) {
00130             $PHP_AUTH_PW = $_ENV['REMOTE_PASSWORD'];
00131         }
00132         else if (@getenv('REMOTE_PASSWORD')) {
00133             $PHP_AUTH_PW = getenv('REMOTE_PASSWORD');
00134         }
00135         // Fix from Matthias Fichtner for WebSite Professional - Part 2
00136         else if (isset($AUTH_PASSWORD)) {
00137             $PHP_AUTH_PW = $AUTH_PASSWORD;
00138         }
00139         else if (!empty($_ENV) && isset($_ENV['AUTH_PASSWORD'])) {
00140             $PHP_AUTH_PW = $_ENV['AUTH_PASSWORD'];
00141         }
00142         else if (@getenv('AUTH_PASSWORD')) {
00143             $PHP_AUTH_PW = getenv('AUTH_PASSWORD');
00144         }
00145     }
00146     // Gets authenticated user settings with IIS
00147     if (empty($PHP_AUTH_USER) && empty($PHP_AUTH_PW)
00148         && function_exists('base64_decode')) {
00149         if (!empty($HTTP_AUTHORIZATION)
00150             && substr($HTTP_AUTHORIZATION, 0, 6) == 'Basic ') {
00151             list($PHP_AUTH_USER, $PHP_AUTH_PW) = explode(':', base64_decode(substr($HTTP_AUTHORIZATION, 6)));
00152         }
00153         else if (!empty($_ENV)
00154              && isset($_ENV['HTTP_AUTHORIZATION'])
00155              && substr($_ENV['HTTP_AUTHORIZATION'], 0, 6) == 'Basic ') {
00156             list($PHP_AUTH_USER, $PHP_AUTH_PW) = explode(':', base64_decode(substr($_ENV['HTTP_AUTHORIZATION'], 6)));
00157         }
00158         else if (@getenv('HTTP_AUTHORIZATION')
00159                  && substr(getenv('HTTP_AUTHORIZATION'), 0, 6) == 'Basic ') {
00160             list($PHP_AUTH_USER, $PHP_AUTH_PW) = explode(':', base64_decode(substr(getenv('HTTP_AUTHORIZATION'), 6)));
00161         }
00162     } // end IIS
00163 
00164     // User logged out -> ensure the new username is not the same
00165     if (!empty($old_usr)
00166         && (isset($PHP_AUTH_USER) && $old_usr == $PHP_AUTH_USER)) {
00167         $PHP_AUTH_USER = '';
00168     }
00169 
00170     // Returns whether we get authentication settings or not
00171     if (empty($PHP_AUTH_USER)) {
00172         return FALSE;
00173     } else {
00174         if (get_magic_quotes_gpc()) {
00175             $PHP_AUTH_USER = stripslashes($PHP_AUTH_USER);
00176             $PHP_AUTH_PW   = stripslashes($PHP_AUTH_PW);
00177         }
00178         return TRUE;
00179     }
00180 } // end of the 'PMA_auth_check()' function
00181 
00182 
00196 function PMA_auth_set_user()
00197 {
00198     global $cfg, $server;
00199     global $PHP_AUTH_USER, $PHP_AUTH_PW;
00200 
00201     // Ensures valid authentication mode, 'only_db', bookmark database and
00202     // table names and relation table name are used
00203     if ($cfg['Server']['user'] != $PHP_AUTH_USER) {
00204         $servers_cnt = count($cfg['Servers']);
00205         for ($i = 1; $i <= $servers_cnt; $i++) {
00206             if (isset($cfg['Servers'][$i])
00207                 && ($cfg['Servers'][$i]['host'] == $cfg['Server']['host'] && $cfg['Servers'][$i]['user'] == $PHP_AUTH_USER)) {
00208                 $server        = $i;
00209                 $cfg['Server'] = $cfg['Servers'][$i];
00210                 break;
00211             }
00212         } // end for
00213     } // end if
00214 
00215     $cfg['Server']['user']     = $PHP_AUTH_USER;
00216     $cfg['Server']['password'] = $PHP_AUTH_PW;
00217 
00218     return TRUE;
00219 } // end of the 'PMA_auth_set_user()' function
00220 
00221 
00229 function PMA_auth_fails()
00230 {
00231     PMA_auth();
00232 
00233     return TRUE;
00234 } // end of the 'PMA_auth_fails()' function
00235 
00236 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6