librenms/html/includes/authenticate.inc.php
Adam Amstrong cbbd3bfa04 kludge from lenwe
git-svn-id: http://www.observium.org/svn/observer/trunk@2188 61d68cd4-352d-0410-923a-c4978735b2b8
2011-04-27 19:35:15 +00:00

96 lines
3.0 KiB
PHP

<?php
@ini_set("session.gc_maxlifetime","0");
session_start();
// Preflight checks
if (!is_dir($config['rrd_dir']))
{
echo("<div class='errorbox'>RRD Log Directory is missing ({$config['rrd_dir']}). Graphing may fail.</div>");
}
if (!is_dir($config['temp_dir']))
{
echo("<div class='errorbox'>Temp Directory is missing ({$config['tmp_dir']}). Graphing may fail.</div>");
}
if (!is_writable($config['temp_dir']))
{
echo("<div class='errorbox'>Temp Directory is not writable ({$config['tmp_dir']}). Graphing may fail.</div>");
}
if (isset($_GET['logout']) && $_SESSION['authenticated'])
{
mysql_query("INSERT INTO authlog (`user`,`address`,`result`) VALUES ('" . $_SESSION['username'] . "', '".$_SERVER["REMOTE_ADDR"]."', 'logged out')");
unset($_SESSION);
session_destroy();
header('Location: /');
setcookie ("username", "", time() - 60*60*24*100, "/");
setcookie ("password", "", time() - 60*60*24*100, "/");
$auth_message = "Logged Out";
}
if(isset($config['auth_mechanism']) and $config['auth_mechanism'] == 'http-auth' and !isset($_GET['logout'])){
$_GET['username'] = '';
$_GET['password'] = '';
}
if (isset($_GET['username']) && isset($_GET['password']))
{
$_SESSION['username'] = mres($_GET['username']);
$_SESSION['password'] = mres($_GET['password']);
} elseif (isset($_POST['username']) && isset($_POST['password'])) {
$_SESSION['username'] = mres($_POST['username']);
$_SESSION['password'] = mres($_POST['password']);
} elseif (isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
$_SESSION['username'] = mres($_COOKIE['username']);
$_SESSION['password'] = mres($_COOKIE['password']);
}
if (!isset($config['auth_mechanism']))
{
$config['auth_mechanism'] = "mysql";
}
if (file_exists('includes/authentication/' . $config['auth_mechanism'] . '.inc.php'))
{
include('includes/authentication/' . $config['auth_mechanism'] . '.inc.php');
}
else
{
print_error('ERROR: no valid auth_mechanism defined!');
exit();
}
$auth_success = 0;
if (isset($_SESSION['username']))
{
if (authenticate($_SESSION['username'],$_SESSION['password']))
{
$_SESSION['userlevel'] = get_userlevel($_SESSION['username']);
$_SESSION['user_id'] = get_userid($_SESSION['username']);
if (!$_SESSION['authenticated'])
{
$_SESSION['authenticated'] = true;
mysql_query("INSERT INTO authlog (`user`,`address`,`result`) VALUES ('".$_SESSION['username']."', '".$_SERVER["REMOTE_ADDR"]."', 'logged in')");
header("Location: ".$_SERVER['REQUEST_URI']);
}
if (isset($_POST['remember']))
{
setcookie("username", $_SESSION['username'], time()+60*60*24*100, "/");
setcookie("password", $_SESSION['password'], time()+60*60*24*100, "/");
}
$permissions = permissions_cache($_SESSION['user_id']);
}
elseif (isset($_SESSION['username']))
{
$auth_message = "Authentication Failed";
unset ($_SESSION['authenticated']);
mysql_query("INSERT INTO authlog (`user`,`address`,`result`) VALUES ('".$_SESSION['username']."', '".$_SERVER["REMOTE_ADDR"]."', 'authentication failure')");
}
}
?>