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