Added error handling of missing ldap server connection and audit message for failed login

This commit is contained in:
2021-08-18 18:02:56 +02:00
parent 964e39af90
commit e7d5a4b981

View File

@@ -18,7 +18,20 @@ if (!empty($login_username) && !empty($login_pass))
$ldap_server = "localhost";
$ldap_port = 30389;
$connect = ldap_connect($ldap_server, $ldap_port); #or die("Failed to connect to the LDAP server.");
$connect = ldap_connect($ldap_server, $ldap_port);
if (!$connect)
{
# If debug mode is on show error message
if ($debug)
{
echo "Failed to connect to the LDAP server.";
}
else
{
shell_exec('curl -X POST -H \'Content-Type: application/json\' --data \'{"alias":"ECG Notification Bot","emoji":":ghost:","text":"Failed to connect to the LDAP server."}\' https://chat.ecogood.org/hooks/A' . $rc_webhook);
}
exit;
}
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
@@ -26,7 +39,7 @@ if (!empty($login_username) && !empty($login_pass))
# bind user
$auth_user = "uid=" . $login_username . ",ou=users,ou=ecg";
$auth_pass = $login_pass;
$bind = ldap_bind($connect, $auth_user, $auth_pass); #or die("Failed to bind to LDAP server.");
$bind = ldap_bind($connect, $auth_user, $auth_pass);
# If the bind was successfull
if ($bind)
@@ -49,7 +62,7 @@ if (!empty($login_username) && !empty($login_pass))
# If debug mode is on show error message
if ($debug)
{
echo $return["message"];
echo $return["message"];
}
else
{
@@ -62,6 +75,9 @@ if (!empty($login_username) && !empty($login_pass))
}
else
{
# Send audit message on failed login
shell_exec('curl -X POST -H \'Content-Type: application/json\' --data \'{"alias":"ECG Notification Bot","emoji":":ghost:","text":"Login failed: ' . $login_username . ' (' . $_SERVER["REMOTE_ADDR"] . ')"}\' https://chat.ecogood.org/hooks/' . $rc_webhook);
// Incorrect password
$_SESSION["error_code"] = 3;
header("Location: error.php");