*/
//"example_plugin", /* An example plugin */
//"sql_auth", /* Provides a login page which uses SQL */
+ //"php_mailer", /* Provides ability to send emails on behalf of the admin panel */
]
);
"dnsbl.dronebl.org",
"rbl.efnetrbl.org"
]);
+
+/** Your email settings
+ * Requires plugin "php_mailer"
+*/
+define('EMAIL_SETTINGS', [
+ "host" => 'smtp.host.example.com',
+ "port" => 587,
+ "encryption" => 'tls', /* Use 'tls' for STARTTLS or 'ssl' for TLS/SSL
+ "username" => "v.a.pond@outlook.com", /* The email to login with and send emails from */
+ "password" => "supersecretpassword", /* The password for the above email */
+ "from_name" => "UnrealIRCd Admin Panel",
+
+]);
\ No newline at end of file
$user = new PanelUser($_POST['username']);
/* not being too informative with the login error in case of attackers */
- if (!$user->id)
- {
- $failmsg = "Incorrect login";
- }
- else if ($user->password_verify($_POST['password']))
+ if (isset($user->id) && $user->password_verify($_POST['password']))
{
$_SESSION['id'] = $user->id;
header('Location: ' . $redirect);
$user->add_meta("last_login", date("Y-m-d m:i:s"));
+ Hook::run(HOOKTYPE_USER_LOGIN, $user);
+ die();
}
else
{
+ $fail = [
+ "login" => htmlspecialchars($_POST['username']),
+ "IP" => $_SERVER['REMOTE_ADDR']
+ ];
+ Hook::run(HOOKTYPE_USER_LOGIN_FAIL, $fail);
$failmsg = "Incorrect login";
}
--- /dev/null
+<?php
+
+use PHPMailer\PHPMailer\PHPMailer;
+use PHPMailer\PHPMailer\SMTP;
+
+class php_mailer
+{
+ public $name = "PHPMailer()";
+ public $author = "Valware";
+ public $version = "1.0";
+ public $description = "Send mail using PHPMailer()";
+
+ function __construct()
+ {
+ Hook::func(HOOKTYPE_USER_LOGIN, 'php_mailer::user_login_notif');
+ Hook::func(HOOKTYPE_USER_LOGIN_FAIL, 'php_mailer::user_login_fail_notif');
+ }
+
+ public static function send_mail($to, $subject, $body)
+ {
+ $mail = new PHPMailer(true);
+ try {
+ //Server settings
+ //$mail->SMTPDebug = 2;
+ $mail->isSMTP(); //Send using SMTP
+ $mail->Host = EMAIL_SETTINGS['host']; //Set the SMTP server to send through
+ $mail->SMTPAuth = true; //Enable SMTP authentication
+ $mail->Username = EMAIL_SETTINGS['username']; //SMTP username
+ $mail->Password = EMAIL_SETTINGS['password']; //SMTP password
+ $mail->SMTPSecure = EMAIL_SETTINGS['encryption']; //Enable implicit TLS encryption
+ $mail->Port = EMAIL_SETTINGS['port']; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
+
+ //Recipients
+ $mail->setFrom(EMAIL_SETTINGS['username'], EMAIL_SETTINGS['from_name']);
+ $mail->addAddress($to['email'], $to['name']); //Add a recipient
+
+ //Content
+ $mail->isHTML(true); //Set email format to HTML
+ $mail->Subject = $subject;
+ $mail->Body = $body . "<br><br>Thank you for using UnrealIRCd!";
+ $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
+
+ $mail->send();
+ echo 'Message has been sent';
+ } catch (Exception $e) {
+ echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
+ }
+ }
+
+ /**
+ * Send a login notification to the admin (note-to-self)
+ * @param mixed $user
+ * @return void
+ */
+ public static function user_login_notif($user)
+ {
+ self::send_mail(
+ ["email" => EMAIL_SETTINGS['username'], "name" => EMAIL_SETTINGS['from_name']],
+ "New login to Unreal Admin Panel",
+ "There was a new login to the admin panel.<br>User: \"$user->username\"<br>IP: \"".$_SERVER['REMOTE_ADDR']."\""
+ );
+ }
+ public static function user_login_fail_notif($fail)
+ {
+ self::send_mail(
+ ["email" => EMAIL_SETTINGS['username'], "name" => EMAIL_SETTINGS['from_name']],
+ "Failed login attempt - Unreal Admin Panel",
+ "There was a failed login attempt to the admin panel.<br>User: \"".$fail['login']."\"<br>IP: \"".$fail['IP']."\""
+ );
+ }
+}
\ No newline at end of file