]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | use PHPMailer\PHPMailer\PHPMailer; | |
4 | use PHPMailer\PHPMailer\SMTP; | |
5 | ||
6 | class php_mailer | |
7 | { | |
8 | public $name = "PHPMailer()"; | |
9 | public $author = "Valware"; | |
10 | public $version = "1.0"; | |
11 | public $description = "Send mail using PHPMailer()"; | |
12 | public $email = "v.a.pond@outlook.com"; | |
13 | ||
14 | function __construct() | |
15 | { | |
16 | Hook::func(HOOKTYPE_USER_LOGIN, 'php_mailer::user_login_notif'); | |
17 | Hook::func(HOOKTYPE_USER_LOGIN_FAIL, 'php_mailer::user_login_fail_notif'); | |
18 | } | |
19 | ||
20 | public static function send_mail($to, $subject, $body) | |
21 | { | |
22 | $mail = new PHPMailer(true); | |
23 | try { | |
24 | //Server settings | |
25 | //$mail->SMTPDebug = 2; | |
26 | $mail->isSMTP(); //Send using SMTP | |
27 | $mail->Host = EMAIL_SETTINGS['host']; //Set the SMTP server to send through | |
28 | $mail->SMTPAuth = true; //Enable SMTP authentication | |
29 | $mail->Username = EMAIL_SETTINGS['username']; //SMTP username | |
30 | $mail->Password = EMAIL_SETTINGS['password']; //SMTP password | |
31 | $mail->SMTPSecure = EMAIL_SETTINGS['encryption']; //Enable implicit TLS encryption | |
32 | $mail->Port = EMAIL_SETTINGS['port']; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` | |
33 | ||
34 | //Recipients | |
35 | $mail->setFrom(EMAIL_SETTINGS['username'], EMAIL_SETTINGS['from_name']); | |
36 | $mail->addAddress($to['email'], $to['name']); //Add a recipient | |
37 | ||
38 | //Content | |
39 | $mail->isHTML(true); //Set email format to HTML | |
40 | $mail->Subject = $subject; | |
41 | $mail->Body = $body . "<br><br>Thank you for using UnrealIRCd!"; | |
42 | $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; | |
43 | ||
44 | $mail->send(); | |
45 | } catch (Exception $e) { | |
46 | die("Could not send mail:". $e); | |
47 | } | |
48 | } | |
49 | ||
50 | /** | |
51 | * Send a login notification to the admin (note-to-self) | |
52 | * @param mixed $user | |
53 | * @return void | |
54 | */ | |
55 | public static function user_login_notif($user) | |
56 | { | |
57 | self::send_mail( | |
58 | ["email" => EMAIL_SETTINGS['username'], "name" => EMAIL_SETTINGS['from_name']], | |
59 | "New login to Unreal Admin Panel", | |
60 | "There was a new login to the admin panel.<br>User: \"$user->username\"<br>IP: \"".$_SERVER['REMOTE_ADDR']."\" (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>". | |
61 | "User Agent: ".$_SERVER['HTTP_USER_AGENT'] | |
62 | ); | |
63 | ||
64 | if ($user->email) | |
65 | self::send_mail( | |
66 | ["email" => $user->email, "name" => $user->first_name . " " . $user->last_name], | |
67 | "New login to your account", | |
68 | "Dear $user->first_name, <br><br>". | |
69 | "There was a new login to account: \"$user->username\"<br><br>". | |
70 | "Details:<br>". | |
71 | "IP: ".$_SERVER['REMOTE_ADDR']." (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>". | |
72 | "User Agent: ".$_SERVER['HTTP_USER_AGENT']."<br><br>". | |
73 | "If this was not you, please contact your Panel Administrator." | |
74 | ); | |
75 | } | |
76 | public static function user_login_fail_notif($fail) | |
77 | { | |
78 | self::send_mail( | |
79 | ["email" => EMAIL_SETTINGS['username'], "name" => EMAIL_SETTINGS['from_name']], | |
80 | "Failed login attempt - Unreal Admin Panel", | |
81 | "There was a failed login attempt to the admin panel.<br>User: \"".$fail['login']."\"<br>IP: \"".$fail['IP']."\"" | |
82 | ); | |
83 | $user = new PanelUser($fail['login']); | |
84 | if ($user->email) | |
85 | self::send_mail( | |
86 | ["email" => $user->email, "name" => $user->first_name . " " . $user->last_name], | |
87 | "Failed login attempt to your account", | |
88 | "Dear $user->first_name, <br><br>". | |
89 | "There was failed login attempt to your account: \"$user->username\"<br><br>". | |
90 | "Details:<br>". | |
91 | "IP: ".$_SERVER['REMOTE_ADDR']." (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>". | |
92 | "User Agent: ".$_SERVER['HTTP_USER_AGENT']."<br><br>". | |
93 | "If this was not you, please contact your Panel Administrator." | |
94 | ); | |
95 | } | |
96 | } |