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