looking for wrong seperator
[Pman.Core] / NotifySmtpCheck.php
1 <?php
2
3 require_once 'Pman.php';
4
5         
6 class Pman_Core_NotifySmtpCheck extends Pman
7 {
8     function __construct()
9     {
10         require_once "Mail.php";
11         require_once 'Mail/smtpmx.php';
12     }
13     
14     function get($v, $opts=array())
15     {
16         $this->check();
17         exit;
18     }
19     
20     function check()
21     {
22         $ff = HTML_FlexyFramework::get();
23         
24         if(
25                 empty($ff->Core_Notify) ||
26                 empty($ff->Core_Notify['routes'])
27         ){
28             return;
29         }
30         
31         $helo = $this->getHelo();
32         
33         echo "HELO : {$helo} \n";
34         
35         $error = array();
36         
37         foreach ($ff->Core_Notify['routes'] as $server => $settings){
38             if(empty($settings['domains']) || empty($settings['username']) || empty($settings['password'])){
39                 $error[] = "{$server} - Missing domains / username / password";
40                 continue;
41             }
42             
43             $socket_options = array (
44                 'ssl' => array(
45                     'verify_peer'  => false,
46                     'verify_peer_name'  => false
47                 )
48             );
49             if (empty($settings['port'])) {
50                 $settings['port'] = 25;
51             }
52             $smtp = new Net_SMTP($server, $settings['port'], $helo, false, 0, $socket_options);
53
54 //            $smtp->setDebug(true);
55             
56             echo "Connecting : {$server}:{$settings['port']} \n";
57             
58             $res = $smtp->connect(10);
59
60             if (is_a($res, 'PEAR_Error')) {
61                 $error[] = "{$server} - Cound not connect";
62                 continue;
63             }
64
65             echo "Login As : {$settings['username']}:{$settings['password']} \n";
66             
67             $res = $smtp->auth($settings['username'], $settings['password']);
68
69             if (is_a($res, 'PEAR_Error')) {
70                 $error[] = "{$server} - Cound not login";
71                 continue;
72             }
73         }
74         
75         if(!empty($error)){
76             print_r($error);
77             exit;
78         }
79         
80         return;
81     }
82     
83     function getHelo()
84     {
85         $ifconfig = file_get_contents("https://ifconfig.co/");
86         $dom = new DomDocument('1.0', 'utf-8');
87         @$dom->loadHTML($ifconfig);
88         
89         $xpath = new DOMXPath($dom);
90         
91         $element = $xpath->query("//code[@class='ip']");
92         
93         if(!$element->length){
94             return;
95         }
96         
97         $ip = $element->item(0)->nodeValue;
98         
99         $cmd = "host {$ip}";
100         
101         $e = `$cmd`;
102         
103         $helo = substr(array_pop(explode(' ', $e)), 0, -2);
104         
105         return $helo;
106     }
107     
108 }