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             echo "Connecting : {$server}:{$settings['port']} \n";
49             
50             $res = $smtp->connect(10);
51
52             if (is_a($res, 'PEAR_Error')) {
53                 $error[] = "{$server} - Cound not connect";
54                 continue;
55             }
56
57             echo "Login As : {$settings['username']}:{$settings['password']} \n";
58             
59             $res = $smtp->auth($settings['username'], $settings['password']);
60
61             if (is_a($res, 'PEAR_Error')) {
62                 $error[] = "{$server} - Cound not login";
63                 continue;
64             }
65         }
66         
67         if(!empty($error)){
68             print_r($error);
69             exit;
70         }
71         
72         return;
73     }
74     
75     function getHelo()
76     {
77         $ifconfig = file_get_contents("https://ifconfig.co/");
78         $dom = new DomDocument('1.0', 'utf-8');
79         $dom->loadHTML($ifconfig);
80         
81         $xpath = new DOMXPath($dom);
82         
83         $element = $xpath->query("//code[@class='ip']");
84         
85         if(!$element->length){
86             return;
87         }
88         
89         $ip = $element->item(0)->nodeValue;
90         
91         $cmd = "host {$ip}";
92         
93         $e = `$cmd`;
94         
95         $helo = substr(array_pop(explode(' ', $e)), 0, -2);
96         
97         return $helo;
98     }
99     
100 }