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