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         print_R($helo);exit;
33         
34         $error = array();
35         
36         foreach ($ff->Core_Notify['routes'] as $server => $settings){
37             if(empty($settings['domains']) || empty($settings['username']) || empty($settings['password'])){
38                 $error[] = "{$server} - Missing domains / username / password";
39                 continue;
40             }
41             
42             foreach ($settings['domains'] as $dom){
43                 
44                 $socket_options = array (
45                     'ssl' => array(
46                         'verify_peer'  => false,
47                         'verify_peer_name'  => false,
48                         'allow_self_signed' => true
49                     )
50                 );
51                 
52                 $smtp = new Net_SMTP($server, $settings['port'], $helo, false, 0, $socket_options);
53                 
54                 $smtp->setDebug(true);
55                 
56                 $res = $smtp->connect(10);
57                 
58                 if (is_a($res, 'PEAR_Error')) {
59                     $error[] = "{$server} - Cound not connect";
60                     continue;
61                 }
62                 
63                 $res = $smtp->auth($settings['username'], $settings['password']);
64             
65                 if (is_a($res, 'PEAR_Error')) {
66                     $error[] = "{$server} - Cound not login";
67                     continue;
68                 }
69                 
70             }
71             
72         }
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 }