-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathe_event.php
110 lines (85 loc) · 2.84 KB
/
e_event.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/*
* TwoFactorAuth
*
* Copyright (C) 2021-2022 e107 Inc. (https://www.e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*/
if (!defined('e107_INIT')) { exit; }
require_once(e_PLUGIN."twofactorauth/twofactorauth_class.php");
class twofactorauth_event
{
function __construct()
{
$this->tfa_class = new tfa_class();
}
function config()
{
$event = array();
// User login
$event[] = array(
'name' => "user_validlogin",
'function' => "init_tfa",
);
// User has submitted Forgotten Password form
$event[] = array(
'name' => "user_fpw_request",
'function' => "init_tfa",
);
// User has submitted an recovery code (either valid or invalid)
$event[] = array(
'name' => "twofactorauth_recovery_code_used",
'function' => "recovery_code_used",
);
return $event;
}
function init_tfa($data, $eventname)
{
$this->tfa_class->tfaDebug(__LINE__." ".__FILE__.": Eventname: ".$eventname);
// Check to see if Two Factor Authentication is active for all users
if(e107::getPlugPref('twofactorauth', 'tfa_active'))
{
$this->tfa_class->tfaDebug(__LINE__." ".__FILE__.": Start Initialising TFA code.");
$this->tfa_class->init($data, $eventname);
}
}
function recovery_code_used($data, $eventname)
{
$tfa = new tfa_class();
$this->tfa_class->tfaDebug(__LINE__." ".__FILE__.": Start recovery code notification");
$userdata = e107::user($data['user_id']);
//$message = print_a($data, true);
//$message .= print_a($userdata, true);
$timestamp = e107::getDate()->convert_date(time(), 'long');
$message = '';
// Recovery was valid
if($data["valid"])
{
$this->tfa_class->tfaDebug(__LINE__." ".__FILE__.": Recovery code was valid");
$subject = LAN_2FA_RECOVERY_CODE_USED_VALID_TITLE;
$message .= e107::getParser()->lanVars(LAN_2FA_RECOVERY_CODE_USED_VALID_1, array('x' => $timestamp, 'y'=> $data["user_ip"]), true);
$message .= "<br><br>";
$message .= e107::getParser()->lanVars(LAN_2FA_RECOVERY_CODE_USED_VALID_2, array('x'=> $data["remaining"]), true);
}
// Recovery code was invalid
else
{
$this->tfa_class->tfaDebug(__LINE__." ".__FILE__.": Recovery code was invalid");
$subject = LAN_2FA_RECOVERY_CODE_USED_INVALID_TITLE;
$message .= e107::getParser()->lanVars(LAN_2FA_RECOVERY_CODE_USED_INVALID_1, array('x' => $timestamp, 'y'=> $data["user_ip"]), true);
$message .= "<br><br>";
$message .= LAN_2FA_RECOVERY_CODE_USED_INVALID_2;
}
$eml = array(
'subject' => $subject,
'sender_name' => SITENAME,
'html' => true,
'template' => 'default',
'body' => $message
);
e107::getEmail()->sendEmail($userdata["user_email"], $userdata["user_name"], $eml);
$this->tfa_class->tfaDebug(__LINE__." ".__FILE__.": Recovery code notification email sent");
}
}