diff --git a/login.php b/login.php index d37af9c..d34266c 100644 --- a/login.php +++ b/login.php @@ -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");