Files
librenms-librenms/html/includes/authenticate.inc.php
T

91 lines
2.8 KiB
PHP
Raw Normal View History

<?php
2007-04-03 14:10:23 +00:00
@ini_set("session.gc_maxlifetime","0");
2009-05-11 14:59:40 +00:00
2009-03-17 20:26:29 +00:00
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'])
{
2011-05-12 20:01:24 +00:00
dbInsert(array('user' => $_SESSION['username'], 'address' => $_SERVER["REMOTE_ADDR"], 'result' => 'Logged Out'), 'authlog');
2009-06-19 10:43:02 +00:00
unset($_SESSION);
2007-04-03 14:10:23 +00:00
session_destroy();
header('Location: /');
2009-06-19 10:43:02 +00:00
setcookie ("username", "", time() - 60*60*24*100, "/");
setcookie ("password", "", time() - 60*60*24*100, "/");
2008-11-26 12:55:55 +00:00
$auth_message = "Logged Out";
2007-04-03 14:10:23 +00:00
}
if (isset($_GET['username']) && isset($_GET['password']))
{
2010-08-03 12:09:38 +00:00
$_SESSION['username'] = mres($_GET['username']);
2011-05-26 21:50:27 +00:00
$_SESSION['password'] = $_GET['password'];
} elseif (isset($_POST['username']) && isset($_POST['password'])) {
2009-06-19 10:43:02 +00:00
$_SESSION['username'] = mres($_POST['username']);
2011-05-26 21:50:27 +00:00
$_SESSION['password'] = $_POST['password'];
} elseif (isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
2009-06-19 10:43:02 +00:00
$_SESSION['username'] = mres($_COOKIE['username']);
2011-05-26 21:50:27 +00:00
$_SESSION['password'] = $_COOKIE['password'];
2009-06-19 10:43:02 +00:00
}
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();
}
2009-12-31 19:06:05 +00:00
$auth_success = 0;
2009-06-19 10:43:02 +00:00
2011-05-03 14:10:21 +00:00
if (isset($_SESSION['username']))
2009-12-31 19:06:05 +00:00
{
2011-05-03 14:10:21 +00:00
if (authenticate($_SESSION['username'],$_SESSION['password']))
{
2010-03-06 01:19:06 +00:00
$_SESSION['userlevel'] = get_userlevel($_SESSION['username']);
2010-03-07 22:22:29 +00:00
$_SESSION['user_id'] = get_userid($_SESSION['username']);
if (!$_SESSION['authenticated'])
2009-12-31 19:06:05 +00:00
{
$_SESSION['authenticated'] = true;
2011-05-12 20:01:24 +00:00
dbInsert(array('user' => $_SESSION['username'], 'address' => $_SERVER["REMOTE_ADDR"], 'result' => 'Logged In'), 'authlog');
header("Location: ".$_SERVER['REQUEST_URI']);
2009-12-31 19:06:05 +00:00
}
if (isset($_POST['remember']))
{
setcookie("username", $_SESSION['username'], time()+60*60*24*100, "/");
setcookie("password", $_SESSION['password'], time()+60*60*24*100, "/");
}
2010-07-31 21:08:35 +00:00
$permissions = permissions_cache($_SESSION['user_id']);
}
elseif (isset($_SESSION['username']))
{
$auth_message = "Authentication Failed";
unset ($_SESSION['authenticated']);
2011-05-12 20:01:24 +00:00
dbInsert(array('user' => $_SESSION['username'], 'address' => $_SERVER["REMOTE_ADDR"], 'result' => 'Authentication Failure'), 'authlog');
2009-12-31 19:06:05 +00:00
}
}
2007-04-03 14:10:23 +00:00
?>