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