-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowserint.php
90 lines (70 loc) · 2.15 KB
/
browserint.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
$redirect = false;
if(!isset($_GET['x'])){
$redirect = true;
}elseif($_GET['x'] != "ipxx"){
$redirect = true;
}
if($redirect){
header("Location: ./index.php");
die();
}
$b = new Browser(urldecode($_GET['url']));
echo $b->display();
class Browser {
private $wgetPath = "/usr/bin/";
private $wgetExec = "wget";
private $toReturn;
private function delTree($dir) {
$files = glob($dir . '*', GLOB_MARK);
foreach($files as $file){
if(substr($file, -1) == '/'){
$this->delTree($file);
}else{
unlink( $file );
}
}
if (is_dir($dir)) rmdir( $dir );
}
// Constructor
public function Browser($url){
$curDir = getcwd();
$cacheDir = $curDir.'/browser/';
chdir($cacheDir);
$dirName = md5($url);
$refresh = FALSE;
if (file_exists($dirName) && ((time() - filectime($dirName)) > 10)) {
$this->delTree($dirName);
$refresh = TRUE;
}elseif(!file_exists($dirName)){
$refresh = TRUE;
}
$fullPath = $cacheDir . $dirName;
$url = str_replace("[q]","?",$url);
$url = str_replace("[eq]","=",$url);
$url = str_replace("[amp]","&",$url);
if($refresh == TRUE){
mkdir($dirName);
exec($this->wgetPath . $this->wgetExec . " --directory-prefix=$dirName --convert-links \"$url\"");
}
$openDir = opendir($fullPath);
$return = "";
while (false !== ($file = readdir($openDir))){
if($file!="." && $file!=".."){
$return = $file;
}
}
$contents = file_get_contents($fullPath . "/" . $return);
if($contents=="")
$this->toReturn = "404 Page not found";
else
$this->toReturn = $contents;
// rewrite anchor tag href to redirect through browser.php
$this->toReturn = preg_replace('@\<a ([^>]*)href="([^"]*)"@i', '<a \1href="browser.php?url=\2"', $this->toReturn);
chdir($curDir);
}
public function display() {
return $this->toReturn;
}
}
?>