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