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