|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* 2FA callback action for handeling text messages. |
|
4
|
|
|
* |
|
5
|
|
|
* @package ThreemaGateway |
|
6
|
|
|
* @author rugk |
|
7
|
|
|
* @copyright Copyright (c) 2015-2016 rugk |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
class ThreemaGateway_Handler_Action_TfaCallback_TextMessage extends ThreemaGateway_Handler_Action_TfaCallback_Abstract |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var int replace chars in the string |
|
15
|
|
|
*/ |
|
16
|
|
|
const FILTER_REPLACE = 1; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var int regular expression match, can only succeed or fail |
|
20
|
|
|
*/ |
|
21
|
|
|
const FILTER_REGEX_MATCH = 10; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string text of Threema message |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $msgText; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Prepare the message handling. Should be called before any other actions. |
|
30
|
|
|
* |
|
31
|
|
|
* @return bool |
|
32
|
|
|
*/ |
|
33
|
|
|
public function prepareProcessing() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->msgText = trim($this->threemaMsg->getText()); |
|
36
|
|
|
|
|
37
|
|
|
return true; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Filters the passed data/message. |
|
42
|
|
|
* |
|
43
|
|
|
* Returns "false" if the process should be canceled. Otherwise "true". |
|
44
|
|
|
* |
|
45
|
|
|
* @param int $filterType please use the constants FILTER_* |
|
46
|
|
|
* @param mixed $filterData any data the filter uses |
|
47
|
|
|
* @param bool $failOnError whether the filter should fail on errors (true) |
|
48
|
|
|
* or silently ignore them (false) |
|
49
|
|
|
* |
|
50
|
|
|
* @throws XenForo_Exception |
|
51
|
|
|
* @return bool |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function applyFilter($filterType, $filterData, $failOnError = true) |
|
54
|
|
|
{ |
|
55
|
|
|
/** @var $success bool */ |
|
56
|
|
|
$success = true; |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
switch ($filterType) { |
|
59
|
|
|
case $this::FILTER_REPLACE: |
|
60
|
|
|
$success = strtr($this->msgText, $filterData); |
|
61
|
|
|
|
|
62
|
|
|
if (is_string($success)) { |
|
63
|
|
|
$this->msgText = $success; |
|
64
|
|
|
$success = true; |
|
65
|
|
|
} else { |
|
66
|
|
|
$success = false; |
|
67
|
|
|
} |
|
68
|
|
|
break; |
|
69
|
|
|
|
|
70
|
|
|
case $this::FILTER_REGEX_MATCH: |
|
71
|
|
|
$success = preg_match($filterData, $this->msgText); |
|
72
|
|
|
break; |
|
73
|
|
|
|
|
74
|
|
|
default: |
|
75
|
|
|
throw new XenForo_Exception('Unknown filter type: ' . $filterType); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if ($failOnError && !$success) { |
|
79
|
|
|
return false; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return true; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Does all steps needed to do before processing data. |
|
87
|
|
|
* |
|
88
|
|
|
* Returns "false" if the process should be canceled. Otherwise "true". |
|
89
|
|
|
* |
|
90
|
|
|
* @throws XenForo_Exception |
|
91
|
|
|
* @return bool |
|
|
|
|
|
|
92
|
|
|
*/ |
|
93
|
|
|
protected function preProcessPending() |
|
94
|
|
|
{ |
|
95
|
|
|
$this->log('Recognized ' . $this->name . ' (text message).'); |
|
96
|
|
|
$this->log('[...]', 'Message text: ' . $this->msgText); |
|
97
|
|
|
|
|
98
|
|
|
if (!parent::preProcessPending()) { |
|
99
|
|
|
return false; |
|
100
|
|
|
}; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Verifies & saves data for one confirm request. |
|
105
|
|
|
* |
|
106
|
|
|
* Returns "false" if the process should be canceled. Otherwise "true". |
|
107
|
|
|
* |
|
108
|
|
|
* @param array $processOptions please include 'saveKey' |
|
109
|
|
|
* |
|
110
|
|
|
* @return bool |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function processConfirmRequest($confirmRequest, array $processOptions = []) |
|
113
|
|
|
{ |
|
114
|
|
|
if (!parent::processConfirmRequest($confirmRequest, $processOptions)) { |
|
|
|
|
|
|
115
|
|
|
return false; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
// save data |
|
119
|
|
|
try { |
|
120
|
|
|
$this->setDataForRequest($confirmRequest, [ |
|
121
|
|
|
$processOptions['saveKey'] => $this->msgText |
|
122
|
|
|
]); |
|
123
|
|
|
} catch (Exception $e) { |
|
124
|
|
|
$this->log('Could not save data for request.', $e->getMessage()); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
// whether the code is the same as the requested one is verified in |
|
128
|
|
|
// the actual 2FA provider (verifyFromInput) later |
|
129
|
|
|
|
|
130
|
|
|
return true; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.