]>
Commit | Line | Data |
---|---|---|
69a53172 VP |
1 | <?php |
2 | /** | |
3 | @title PHP Mailer | |
4 | @author Valware | |
5 | @contact valerie@valware.co.uk | |
6 | @description Provides support for PHPMailer() to send emails you care about | |
7376f06c | 7 | @version 1.2 |
9bb36542 | 8 | @tested 0.9 |
ed85b299 | 9 | @minver 0.9 |
439184a4 | 10 | @icon https://w7.pngwing.com/pngs/78/575/png-transparent-phpmailer-hd-logo.png |
69a53172 VP |
11 | @maxver * |
12 | @license GPLv3 | |
13 | */ | |
14 | use PHPMailer\PHPMailer\PHPMailer; | |
15 | use PHPMailer\PHPMailer\SMTP; | |
16 | ||
17 | class php_mailer | |
18 | { | |
4a3e2429 | 19 | public $name = "php_mailer"; |
69a53172 | 20 | public $author = "Valware"; |
7376f06c | 21 | public $version = "1.2"; |
69a53172 VP |
22 | public $description = "Send mail using PHPMailer()"; |
23 | public $email = "v.a.pond@outlook.com"; | |
24 | ||
25 | function __construct() | |
26 | { | |
27 | Hook::func(HOOKTYPE_USER_LOGIN, 'php_mailer::user_login_notif'); | |
28 | Hook::func(HOOKTYPE_USER_LOGIN_FAIL, 'php_mailer::user_login_fail_notif'); | |
0a3d4801 | 29 | Hook::func(HOOKTYPE_NAVBAR, 'php_mailer::navbar_hook'); |
69a53172 VP |
30 | } |
31 | ||
32 | public static function send_mail($to, $subject, $body) | |
33 | { | |
34 | $mail = new PHPMailer(true); | |
35 | try { | |
36 | //Server settings | |
37 | //$mail->SMTPDebug = 2; | |
38 | $mail->isSMTP(); // Send using SMTP | |
39 | $mail->Host = get_config("smtp::host"); // Set the SMTP server to send through | |
40 | $mail->SMTPAuth = true; // Enable SMTP authentication | |
41 | $mail->Username = get_config("smtp::username"); // SMTP username | |
42 | $mail->Password = get_config("smtp::password"); // SMTP password | |
43 | $mail->SMTPSecure = get_config("smtp::encryption"); // Enable implicit TLS encryption | |
44 | $mail->Port = get_config("smtp::port"); // TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` | |
45 | ||
46 | //Recipients | |
47 | $mail->setFrom(get_config("smtp::username"), get_config("smtp::from_name")); | |
48 | $mail->addAddress($to['email'], $to['name']); // Add a recipient | |
49 | ||
50 | //Content | |
51 | $mail->isHTML(true); // Set email format to HTML | |
52 | $mail->Subject = $subject; | |
53 | $mail->Body = $body . "<br><br>Thank you for using UnrealIRCd!"; | |
54 | $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; | |
55 | ||
56 | $mail->send(); | |
57 | } catch (Exception $e) { | |
58 | die("Could not send mail:". $e); | |
59 | } | |
60 | } | |
61 | ||
62 | /** | |
63 | * Send a login notification to the admin (note-to-self) | |
64 | * @param mixed $user | |
65 | * @return void | |
66 | */ | |
67 | public static function user_login_notif($user) | |
68 | { | |
69 | self::send_mail( | |
70 | ["email" => get_config("smtp::username"), "name" => get_config("smtp::from_name")], | |
71 | "New login to Unreal Admin Panel", | |
72 | "There was a new login to the admin panel.<br>User: \"$user->username\"<br>IP: \"".$_SERVER['REMOTE_ADDR']."\" (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>". | |
73 | "User Agent: ".$_SERVER['HTTP_USER_AGENT'] | |
74 | ); | |
75 | ||
76 | if ($user->email) | |
77 | self::send_mail( | |
78 | ["email" => $user->email, "name" => $user->first_name . " " . $user->last_name], | |
79 | "New login to your account", | |
80 | "Dear $user->first_name, <br><br>". | |
81 | "There was a new login to account: \"$user->username\"<br><br>". | |
82 | "Details:<br>". | |
83 | "IP: ".$_SERVER['REMOTE_ADDR']." (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>". | |
84 | "User Agent: ".$_SERVER['HTTP_USER_AGENT']."<br><br>". | |
85 | "If this was not you, please contact your Panel Administrator." | |
86 | ); | |
87 | } | |
0a3d4801 VP |
88 | |
89 | /** | |
90 | * Send a notification about the failed attempt | |
91 | */ | |
3361ca22 | 92 | public static function user_login_fail_notif($user) |
69a53172 VP |
93 | { |
94 | self::send_mail( | |
95 | ["email" => get_config("smtp::username"), "name" => get_config("smtp::from_name")], | |
96 | "Failed login attempt - Unreal Admin Panel", | |
0a3d4801 VP |
97 | "-- ADMIN NOTIFICATION --, <br><br>". |
98 | "There was failed login attempt to account: \"$user->username\"<br><br>". | |
99 | "Details:<br>". | |
100 | "IP: ".$_SERVER['REMOTE_ADDR']." (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>". | |
101 | "User Agent: ".$_SERVER['HTTP_USER_AGENT']."<br><br>" | |
69a53172 | 102 | ); |
3361ca22 | 103 | $user = new PanelUser($user['login']); |
69a53172 VP |
104 | if ($user->email) |
105 | self::send_mail( | |
106 | ["email" => $user->email, "name" => $user->first_name . " " . $user->last_name], | |
107 | "Failed login attempt to your account", | |
108 | "Dear $user->first_name, <br><br>". | |
109 | "There was failed login attempt to your account: \"$user->username\"<br><br>". | |
110 | "Details:<br>". | |
111 | "IP: ".$_SERVER['REMOTE_ADDR']." (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>". | |
112 | "User Agent: ".$_SERVER['HTTP_USER_AGENT']."<br><br>". | |
113 | "If this was not you, please contact your Panel Administrator." | |
114 | ); | |
115 | } | |
0a3d4801 VP |
116 | |
117 | public static function navbar_hook(&$pages) | |
118 | { | |
119 | $page_name = "Mail"; | |
120 | $page_link = "plugins/php_mailer/mail-settings.php"; | |
121 | $pages["Settings"][$page_name] = ["script" => $page_link]; | |
122 | } | |
439184a4 | 123 | } |