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