This repository has been archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathwpad.php
68 lines (53 loc) · 1.7 KB
/
wpad.php
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
<?php
include_once 'data.php';
//check if proxy is set to autodetect
if (isset($_SESSION['connection']) && $_SESSION['connection'] == "autodetect") {
session_write_close();
//get local network hostname
$ipconfig = array ();
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
exec('ipconfig', $ipconfig);
foreach ($ipconfig as $row) {
if (preg_match('/ip address/i', $row)) {
$row_arr = explode (':', $row);
if (!empty($row_arr[1])) $ip = trim ($row_arr[1]);
}
}
}
if (empty($ip)) die();
$localhostname = gethostbyaddr($ip);
if ($localhostname == $ip) die();
$hostname_arr = explode ('.', $localhostname);
$hostname_arr2 = $hostname_arr;
//look for wpad.dat
for ($i=0; $i<count($hostname_arr)-2; $i++) {
unset($hostname_arr2[$i]);
$hostname = implode ('.', $hostname_arr2);
$wpad_url = 'http://wpad.'.$hostname.'/wpad.dat';
$wpad = @file_get_contents ($wpad_url);
if (!empty($wpad)) {
print $wpad;
die();
}
}
//look for proxy.pac
for ($i=0; $i<count($hostname_arr)-2; $i++) {
unset($hostname_arr2[$i]);
$hostname = implode ('.', $hostname_arr2);
$wpad_url = 'http://wpad.'.$hostname.'/proxy.pac';
$wpad = @file_get_contents ($wpad_url);
if (!empty($wpad)) {
print $wpad;
die();
}
}
}
//check if proxy is set to WPAD url
if (isset($_SESSION['connection']) && $_SESSION['connection'] == "url" && !empty($_SESSION['wpad_url'])) {
$wpad = @file_get_contents ($_SESSION['wpad_url']);
if (!empty($wpad)) {
print $wpad;
die();
}
}
?>