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