Index: /freepbx/branches/2.3/amp_conf/htdocs/admin/views/freepbx.php =================================================================== --- /freepbx/branches/2.3/amp_conf/htdocs/admin/views/freepbx.php (revision 4677) +++ /freepbx/branches/2.3/amp_conf/htdocs/admin/views/freepbx.php (revision 4690) @@ -169,15 +169,5 @@ if ( isset($_SESSION['AMP_user']) && isset($amp_conf['AUTHTYPE']) && ($amp_conf['AUTHTYPE'] != 'none')) { echo _('Logged in: ').$_SESSION['AMP_user']->username; - echo ' (Logout) ::'; + echo ' ('._('Logout').') '; } //echo ':: '._($message); Index: /freepbx/branches/2.3/amp_conf/htdocs/admin/header_auth.php =================================================================== --- /freepbx/branches/2.3/amp_conf/htdocs/admin/header_auth.php (revision 4358) +++ /freepbx/branches/2.3/amp_conf/htdocs/admin/header_auth.php (revision 4690) @@ -7,110 +7,46 @@ -function check_login() { - global $amp_conf; +switch (strtolower($amp_conf['AUTHTYPE'])) { + case 'database': + if (isset($_REQUEST['logout'])) { + // logging out.. + // remove the user + unset($_SESSION['AMP_user']); + header('WWW-Authenticate: Basic realm="FreePBX '._('Administration').'"'); + header('HTTP/1.0 401 Unauthorized'); + + // remove the ?logout in the url + header('Refresh: 0;'.$_SERVER['PHP_SELF']); // note, cannot do Location: because it changes the HTTP response code to 302 - if ($amp_conf['AUTHTYPE'] == 'database') { - $baselink = (isset($_SERVER['HTTPS'])?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; + exit; + } else if (!isset($_SESSION['AMP_user']) && isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { + // not logged in, and have provided a user/pass + $_SESSION['AMP_user'] = new ampuser($_SERVER['PHP_AUTH_USER']); - // start a session and don't let it stop automatically - session_set_cookie_params(0); - if (!session_id()) session_start(); - setcookie('PHPSESSID', session_id()); + if (!$_SESSION['AMP_user']->checkPassword($_SERVER['PHP_AUTH_PW'])) { + // failed, one last chance -- fallback to amportal.conf db admin user + if ( (count(getAmpAdminUsers()) == 0) && ($_SERVER['PHP_AUTH_USER'] == $amp_conf['AMPDBUSER']) + && ($_SERVER['PHP_AUTH_PW'] == $amp_conf['AMPDBPASS'])) { - // check if the current loading of the page is the first loading after a logout - if (isset($_SESSION['logout'])) { - unset($_SESSION['logout']); - // - // initialize a relogin on Firefox - // (request login with username 'relogin'): - // - // CAUTION: After that, relative hyperlinks like - // Link - // may be translated into an absolute hyperlink like - // http://relogin:relogin@... - // which will lead to an error-message in Firefox. - // - // So you always have to use absolute hyperlinks like $baselink. - // - if (! preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { - $link = preg_replace('/^(https{0,1}\/\/)(.*)$/', '$1relogin:relogin@$2', $baselink); - header("Location: $link"); - exit; - } + // password succesfully matched amportal.conf db admin user + + // set admin access + $_SESSION['AMP_user']->setAdmin(); + } else { + // password failed and admin user fall-back failed + unset($_SESSION['AMP_user']); + } + } // else, succesfully logged in + } + + if (!isset($_SESSION['AMP_user'])) { + // not logged in, send headers + header('WWW-Authenticate: Basic realm="FreePBX '._('Administration').'"'); + header('HTTP/1.0 401 Unauthorized'); + showview("noaccess"); + exit; } - - // check if a new realm needs to be generated because - // it's the first loading of the page (or the first loading - // after a logout): - // - // Remark: The realm is generated with a random ID number - // because Internet Explorer will forget the username if the - // realm changes. Unfortunately Firefox doesn't do so. - if (! isset($_SESSION['realm'])) { - srand(); - $_SESSION['realm'] = 'FreePBX (SEQ'.mt_rand( 1, 1000000000 ).')'; - $_SESSION['login'] = true; - header("WWW-Authenticate: Basic realm=\"{$_SESSION['realm']}\""); - header('HTTP/1.0 401 Unauthorized'); - return false; - } - - // check if a user has already logged in before - if (isset($_SESSION['AMP_user'])) { - unset($_SESSION['login']); - return true; - } - - // check if a user just entered a username and password - // - // is_authorized() has to return 'true' if and only if - // the username and the passwort given are correct. - if (isset($_SESSION['login'])) { - if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { - $_SESSION['AMP_user'] = new ampuser($_SERVER['PHP_AUTH_USER']); - - if (!$_SESSION['AMP_user']->checkPassword($_SERVER['PHP_AUTH_PW'])) { - // one last chance -- check admin user - if ( (count(getAmpAdminUsers()) == 0) && ($_SERVER['PHP_AUTH_USER'] == $amp_conf['AMPDBUSER']) - && ($_SERVER['PHP_AUTH_PW'] == $amp_conf['AMPDBPASS'])) { - - // set admin access - $_SESSION['AMP_user']->setAdmin(); - unset($_SESSION['login']); - return true; - } - } else { - unset($_SESSION['login']); - return true; - } - } - } - - // let the browser ask for a username and a password - $_SESSION['login'] = true; - header("WWW-Authenticate: Basic realm=\"{$_SESSION['realm']}\""); - header('HTTP/1.0 401 Unauthorized'); - - return false; - } else { - if (!isset($_SESSION['AMP_user'])) { - $_SESSION['AMP_user'] = new ampuser($amp_conf['AMPDBUSER']); - } - $_SESSION['AMP_user']->setAdmin(); - - return true; - } + break; } -$result = check_login(); -if ( !(isset($result) ? $result : false) ) { - unset($_SESSION['AMP_user']); -} - -//todo .. delete // include 'header.php'; - -if ( !(isset($result) ? $result : false) ) { - showview("noaccess"); - exit; -} ?> Index: /eepbx/branches/2.3/amp_conf/htdocs/admin/logout.php =================================================================== --- /freepbx/branches/2.3/amp_conf/htdocs/admin/logout.php (revision 4170) +++ (revision ) @@ -1,62 +1,0 @@ - true); - -require_once('common/db_connect.php'); -include 'header.php'; - -if (!$quietmode) { - // Empty navigation div - echo "
\n\n"; - - echo "";
- echo "
";
- echo "