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