|
4 | 4 | header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
|
5 | 5 | header("Access-Control-Allow-Headers: Content-Type");
|
6 | 6 | $request_headers = apache_request_headers();
|
7 |
| - $http_origin = $request_headers['Origin']; |
8 |
| - $allowed_http_origins = array( |
9 |
| - "http://192.168.178.4.1", |
10 |
| - "https://192.168.178.4.1", |
11 |
| - "http://honeypi.local", |
12 |
| - "https://honeypi.local", |
13 |
| - "http://honeypi.fritz.box", |
14 |
| - "https://honeypi.fritz.box", |
15 |
| - "http://localhost:4200", |
16 |
| - "https://localhost:4200" |
17 |
| - ); |
18 |
| - $host = parse_url($http_origin, PHP_URL_HOST); |
19 |
| - $tmp = explode('.',$host); $n = count($tmp); |
20 |
| - $tld = $tmp[($n-2)].".".$tmp[($n-1)]; //top-level domain |
21 |
| - $isHomeNetwork = strpos($host, "192.168."); |
22 |
| - |
23 |
| - if (in_array($http_origin, $allowed_http_origins) || in_array($tld, array("local", "honeypi")) || $isHomeNetwork !== false) { |
24 |
| - // This function is actually not bullet-proof |
25 |
| - @header("Access-Control-Allow-Origin: " . $http_origin); |
| 7 | + if( isset($request_headers['Origin'])) { |
| 8 | + $http_origin = $request_headers['Origin']; |
| 9 | + $allowed_http_origins = array( |
| 10 | + "http://192.168.178.4.1", |
| 11 | + "https://192.168.178.4.1", |
| 12 | + "http://honeypi.local", |
| 13 | + "https://honeypi.local", |
| 14 | + "http://honeypi.fritz.box", |
| 15 | + "https://honeypi.fritz.box", |
| 16 | + "http://localhost:4200", |
| 17 | + "https://localhost:4200" |
| 18 | + ); |
| 19 | + $host = parse_url($http_origin, PHP_URL_HOST); |
| 20 | + $tmp = explode('.',$host); $n = count($tmp); |
| 21 | + $tld = $tmp[($n-2)].".".$tmp[($n-1)]; //top-level domain |
| 22 | + $isHomeNetwork = strpos($host, "192.168."); |
| 23 | + if (in_array($http_origin, $allowed_http_origins) || in_array($tld, array("local", "honeypi")) || $isHomeNetwork !== false) { |
| 24 | + // This function is actually not bullet-proof |
| 25 | + @header("Access-Control-Allow-Origin: " . $http_origin); |
| 26 | + } |
| 27 | + header("Vary: Origin"); |
26 | 28 | }
|
27 |
| - header("Vary: Origin"); |
28 |
| - |
29 | 29 | // nocache
|
30 | 30 | header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
31 | 31 | header("Cache-Control: post-check=0, pre-check=0", false);
|
|
0 commit comments