|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Shieldon package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Terry L. <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace Shieldon\Firewall\Panel\Sandbox; |
|
14
|
|
|
|
|
15
|
|
|
use Shieldon\Messenger as Messenger; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The sandbox for SMTP. |
|
19
|
|
|
*/ |
|
20
|
|
|
class Smtp |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Invoker. |
|
24
|
|
|
* |
|
25
|
|
|
* @param array $args |
|
26
|
|
|
* |
|
27
|
|
|
* @return bool |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __invoke(array $args): bool |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->sandbox($args[0], $args[1]); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Test SMTP. |
|
36
|
|
|
* |
|
37
|
|
|
* @param array $getParams The GET params passed from tryMessenger method. |
|
38
|
|
|
* @param array $message The message title and body. |
|
39
|
|
|
* |
|
40
|
|
|
* @return bool |
|
41
|
|
|
*/ |
|
42
|
|
|
private function sandbox($getParams, $message) |
|
43
|
|
|
{ |
|
44
|
|
|
$type = $getParams['type'] ?? ''; |
|
45
|
|
|
$host = $getParams['host'] ?? ''; |
|
46
|
|
|
$user = $getParams['user'] ?? ''; |
|
47
|
|
|
$pass = $getParams['pass'] ?? ''; |
|
48
|
|
|
$port = $getParams['port'] ?? ''; |
|
49
|
|
|
$data = []; |
|
50
|
|
|
|
|
51
|
|
|
$sender = $getParams['sender'] ?? ''; |
|
52
|
|
|
$recipients = $getParams['recipients'] ?? ''; |
|
53
|
|
|
|
|
54
|
|
|
if ( |
|
55
|
|
|
( |
|
56
|
|
|
!filter_var($host, FILTER_VALIDATE_IP) && |
|
57
|
|
|
!filter_var($host, FILTER_VALIDATE_DOMAIN) |
|
58
|
|
|
) || |
|
59
|
|
|
!is_numeric($port) || |
|
60
|
|
|
empty($user) || |
|
61
|
|
|
empty($pass) |
|
62
|
|
|
) { |
|
63
|
|
|
$data['result']['message'] = 'Invalid fields.'; |
|
64
|
|
|
$output = json_encode($data); |
|
65
|
|
|
return $this->respondJson($output); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if ('ssl' === $type || 'tls' === $type) { |
|
69
|
|
|
$host = $type . '://' . $host; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
if (!empty($sender) && $recipients) { |
|
73
|
|
|
$recipients = str_replace("\r", '|', $recipients); |
|
74
|
|
|
$recipients = str_replace("\n", '|', $recipients); |
|
75
|
|
|
$recipients = explode('|', $recipients); |
|
76
|
|
|
|
|
77
|
|
|
$messenger = new Messenger\Smtp($user, $pass, $host, (int) $port); |
|
78
|
|
|
|
|
79
|
|
|
foreach($recipients as $recipient) { |
|
80
|
|
|
if (filter_var($recipient, FILTER_VALIDATE_EMAIL)) { |
|
81
|
|
|
$messenger->addRecipient($recipient); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if (filter_var($sender, FILTER_VALIDATE_EMAIL)) { |
|
86
|
|
|
$messenger->addSender($sender); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$messenger->setSubject($message['title']); |
|
90
|
|
|
|
|
91
|
|
|
if ($messenger->send($message['body'])) { |
|
92
|
|
|
return true; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
return false; |
|
96
|
|
|
} |
|
97
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.