NotifySmtpCheck.php
[Pman.Core] / NotifySmtpCheck.php
1 <?php
2
3 require_once 'Pman.php';
4 require_once "Mail.php";
5 require_once 'Mail/smtpmx.php';
6         
7 class Pman_Core_NotifySmtpCheck extends Pman
8 {
9     function check()
10     {
11         $ff = HTML_FlexyFramework::get();
12         
13         if(
14                 empty($ff->Core_Notify) ||
15                 empty($ff->Core_Notify['routes'])
16         ){
17             return;
18         }
19         
20         $helo = $this->getHelo();
21         
22         $error = array();
23         
24         foreach ($ff->Core_Notify['routes'] as $server => $settings){
25             if(empty($settings['domains']) || empty($settings['username']) || empty($settings['password'])){
26                 $error[] = "{$server} - Missing domains / username / password";
27                 continue;
28             }
29             
30             $socket_options = array (
31                 'ssl' => array(
32                     'verify_peer'  => false,
33                     'verify_peer_name'  => false
34                 )
35             );
36
37             $smtp = new Net_SMTP($server, $settings['port'], $helo, false, 0, $socket_options);
38
39             $smtp->setDebug(true);
40
41             $res = $smtp->connect(10);
42
43             if (is_a($res, 'PEAR_Error')) {
44                 $error[] = "{$server} - Cound not connect";
45                 continue;
46             }
47
48             $res = $smtp->auth($settings['username'], $settings['password']);
49
50             if (is_a($res, 'PEAR_Error')) {
51                 $error[] = "{$server} - Cound not login";
52                 continue;
53             }
54         }
55         
56         return $error;
57     }
58     
59     function getHelo()
60     {
61         $ifconfig = file_get_contents("https://ifconfig.co/");
62         $dom = new DomDocument('1.0', 'utf-8');
63         $dom->loadHTML($ifconfig);
64         
65         $xpath = new DOMXPath($dom);
66         
67         $element = $xpath->query("//code[@class='ip']");
68         
69         if(!$element->length){
70             return;
71         }
72         
73         $ip = $element->item(0)->nodeValue;
74         
75         $cmd = "host {$ip}";
76         
77         $e = `$cmd`;
78         
79         $helo = substr(array_pop(explode(' ', $e)), 0, -2);
80         
81         return $helo;
82     }
83     
84 }