-
Notifications
You must be signed in to change notification settings - Fork 0
/
windows_compat.inc
111 lines (98 loc) · 2.78 KB
/
windows_compat.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* @file
* Definitions for functions missing from the Windows implementation of PHP.
*
* @see http://drupal.org/node/508004
*/
if (!function_exists('getmxrr')) {
/**
* Checks for getmxrr() before replacing it with win_getmxrr().
*
* @return bool
* The results of the win_getmxrr() function.
*
* @see win_getmxrr()
*/
function getmxrr($hostname, array &$mxhosts, array &$mxweight = array()) {
return win_getmxrr($hostname, $mxhosts, $mxweight);
}
}
/**
* Implements getmxrr() for Windows prior to PHP 5.3.0.
*
* Code originally by HM2K <php [at] hm2k.org>.
*
* @param string $hostname
* The Internet host name.
* @param array $mxhosts
* A list of the MX records found is placed into the array mxhosts.
* @param array $mxweight
* If the weight array is given, it will be filled with the weight information
* gathered.
*
* @return bool
* Returns TRUE if any records are found; returns FALSE if no records were
* found or if an error occurred.
*
* @see http://php.net/manual/function.getmxrr.php#88033
*/
function win_getmxrr($hostname, array &$mxhosts, array &$mxweight = array()) {
if (empty($hostname)) {
return FALSE;
}
if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
return FALSE;
}
if (!is_array($mxhosts)) {
$mxhosts = array();
}
$exec = 'nslookup -type=MX ' . escapeshellarg($hostname);
@exec($exec, $output);
if (empty($output)) {
return FALSE;
}
$i = -1;
foreach ($output as $line) {
$i++;
if (preg_match("/^$hostname\tMX preference = ([0-9]+), mail exchanger = (.+)$/i", $line, $parts)) {
$mxweight[$i] = trim($parts[1]);
$mxhosts[$i] = trim($parts[2]);
}
if (preg_match('/responsible mail addr = (.+)$/i', $line, $parts)) {
$mxweight[$i] = $i;
$mxhosts[$i] = trim($parts[1]);
}
}
return ($i != -1);
}
if (!function_exists('checkdnsrr')) {
/**
* Implements checkdnsrr() for Windows prior to PHP 5.3.0.
*
* @param string $host
* May either be the IP address in dotted-quad notation or the host name.
* @param string $type
* May be any one of: A, MX, NS, SOA, PTR, CNAME, AAAA, A6, SRV, NAPTR, TXT
* or ANY.
*
* @return bool
* Returns TRUE if any records are found; returns FALSE if no records were
* found or if an error occurred.
*
* @see http://php.net/manual/function.checkdnsrr.php
*/
function checkdnsrr($host, $type = '') {
if (!empty($host)) {
$type = (empty($type)) ? 'MX' : $type;
exec('nslookup -type=' . $type . ' ' . escapeshellcmd($host), $result);
$it = new ArrayIterator($result);
foreach (new RegexIterator($it, '~^' . $host . '~', RegexIterator::GET_MATCH) as $result) {
if ($result) {
return TRUE;
}
}
}
return FALSE;
}
}