forked from Gowee/GoogleMirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublic.php
More file actions
83 lines (74 loc) · 2.78 KB
/
public.php
File metadata and controls
83 lines (74 loc) · 2.78 KB
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
<?php
$Default = "";
//The 2 variables below just make it easier to set $hosts, they should not be used in other scripts
$oHost = "google.com";
$pHost = "g.ppx.pw";
$defaultHost = "www.google.com";
$hosts = array(
"domain=" . $oHost => "domain=" . $pHost,//google.com cookie
"domain=." . $oHost => "domain=." . $pHost,//*.google.com cookie
"www." . $oHost => "www." . $pHost,
"ipv6." . $oHost => "ipv6." . $pHost,
"ipv4." . $oHost => "ipv4." . $pHost,
"id." . $oHost => "id." . $pHost,
"scholar." . $oHost => "scholar." . $pHost,
"apis." . $oHost => "apis." . $pHost,
"(([a-z0-9\-]+)\.gstatic\.com)" => "gs-$1." . $pHost, //the re in php should have "()"" or '//''
//"(([a-z0-9\-]+)\.google\.com)" => "$1." . $pHost,
);
$hostsFlip = array(
"domain:" . $pHost => "domain:" . $oHost,
"domain:." . $pHost => "domain:." . $oHost,
"www." . $pHost => "www." . $oHost,
"ipv6." . $pHost => "ipv6." . $oHost,
"ipv4." . $pHost => "ipv4." . $oHost,
"id." . $pHost => "id." . $oHost,
"scholar." . $pHost => "scholar." . $oHost,
"apis." . $pHost => "apis." . $oHost,
"(gs\-([a-z0-9\-]+)\." . preg_quote($pHost) . ")" => "$1.gstatic.com",
//"(([a-z0-9\-]+)\." . preg_quote($pHost) . ")" => "$1.google.com",
);
//var_dump($hosts, $hostsFlip);
/*just add domain here like the added to make it support more subdomain of google
such as
"news." . $oHost => "news." . $pHost,
for Google News
and you can add more domains not restricted in Google then it will perform as
a big mirror system
*/
//$secureKey = "a nice cat"; //for hash
function hostReplace($hosts, $subject){
$retval = $subject;
foreach($hosts as $key => $value){
if(substr($key, 0, 1) === "("){ //if regex
$retval = preg_replace($key, $value, $retval);
}
else $retval = str_ireplace($key, $value, $retval);
}
return $retval;
}
function doesNeedHostReplace($rawContentType){
$contentType = strtolower($rawContentType);
function startsWith($haystack, $needle) {
// search backwards starting from haystack length characters from the end
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
}//https://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php/10473026#10473026
if(startsWith($contentType, "text/html") or startsWith($contentType, "text/javascript") or startsWith($contentType, "text/css") or startsWith($contentType, "application/javascript")) return true;
else return false;//http://www.w3.org/Protocols/rfc1341/4_Content-Type.html
}
function matchHost($currentHost, $hosts){
if(isset($hosts[$currentHost])){
//plain text
return $hosts[$currentHost];
}
else{
foreach($hosts as $key => $value){
if(substr($key, 0, 1) === "("){//if regex
$host = preg_replace($key, $value, $currentHost, 1, $count);
if($count !== 0) return $host;
}
}
return false;
}
}
?>