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             die($error);
58         }
59         
60         return;
61     }
62     
63     function getHelo()
64     {
65         $ifconfig = file_get_contents("https://ifconfig.co/");
66         $dom = new DomDocument('1.0', 'utf-8');
67         $dom->loadHTML($ifconfig);
68         
69         $xpath = new DOMXPath($dom);
70         
71         $element = $xpath->query("//code[@class='ip']");
72         
73         if(!$element->length){
74             return;
75         }
76         
77         $ip = $element->item(0)->nodeValue;
78         
79         $cmd = "host {$ip}";
80         
81         $e = `$cmd`;
82         
83         $helo = substr(array_pop(explode(' ', $e)), 0, -2);
84         
85         return $helo;
86     }
87     
88 }