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