-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindows_compat.inc
58 lines (52 loc) · 1.59 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
<?php
/**
* @file
* Definitions for missing Windows functions
*
* @see http://drupal.org/node/508004
*/
// http://www.php.net/manual/fr/function.getmxrr.php#88033
// getmxrr() support for Windows by HM2K <php [spat] hm2k.org>
function win_getmxrr($hostname, &$mxhosts, &$mxweight=false) {
if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') return;
if (!is_array ($mxhosts) ) $mxhosts = array();
if (empty($hostname)) return;
$exec='nslookup -type=MX '.escapeshellarg($hostname);
@exec($exec, $output);
if (empty($output)) return;
$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);
}
// Define
if (!function_exists('getmxrr')) {
function getmxrr($hostname, &$mxhosts, &$mxweight=false) {
return win_getmxrr($hostname, $mxhosts, $mxweight);
}
}
// http://www.php.net/manual/fr/function.checkdnsrr.php#82701
if (!function_exists('checkdnsrr')) {
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;
}
}