forked from mozillakr/mozilla.or.kr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.php
133 lines (123 loc) · 2.76 KB
/
fetch.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
if ($_SERVER['HTTP_HOST'] != 'localhost:8000') {
exit();
}
// fetch
if ($_GET['action'] == 'fetch') {
$url = urldecode($_GET['url']);
unlink('output/' . urlencode($url));
unlink('output/source/' . urlencode($url));
unlink('output/remote/' . urlencode($url));
$local_url = str_replace('http://www.mozilla.org/en-US/', 'http://localhost:8000/ko/', $url);
$local_url = str_replace('http://www.mozilla.org/', 'http://localhost:8000/', $local_url);
file_get_contents($local_url);
header('Location: fetch.php');
exit();
} else if ($_GET['action'] == 'flush') {
$files = glob('output/remote/*');
foreach($files as $file){
if(is_file($file))
unlink($file);
}
header('Location: fetch.php');
exit();
}
$file_list = scandir('output/source/');
$result = array();
foreach ($file_list as $item) {
$url = urldecode($item);
if (substr($url, 0, strlen('http://www.mozilla.org/')) == 'http://www.mozilla.org/') {
$remote_file_name = 'output/remote/' . urlencode($url);
if (file_exists($remote_file_name)) {
$remote_html = file_get_contents($remote_file_name);
} else {
$remote_html = file_get_contents($url);
fwrite(fopen($remote_file_name, 'w'), $remote_html);
}
$diff = shell_exec('diff output/source/' . $item . ' ' . $remote_file_name);
$diff = htmlspecialchars($diff);
$diff = nl2br($diff);
array_push($result, array(
'url' => $url,
'diff' => $diff
));
}
}
?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>Fetch remote server</title>
<style>
body {
line-height: 1.5;
}
a:link {
color: #000;
}
a:hover {
color: #000;
}
a:active {
color: #000;
}
a:visited {
color: #000;
}
h1 {
font-size: 2em;
text-align: center;
}
h2 {
font-size: 1.2em;
color: #770;
border-top: 2px solid #990;
padding-top: 0.5em;
}
.diff {
font-family: monospace;
font-size: 0.8em;
line-height: 1;
border: 1px solid #eee;
background-color: #f9f9f9;
padding: 0.5em;
max-height: 50em;
overflow: auto;
}
.button {
border: 1px solid #ddd;
background: #eee;
padding: 0.3em 1em 0.1em;
border-radius: 0.3em;
text-decoration: none;
color: #000;
font-size: 0.8em;
}
.button:hover,
.button:focus {
background: #ddd;
}
.button:active {
background: #ccc;
border-style: inset;
}
</style>
</head>
<body>
<h1><a href="http://www.mozilla.or.kr/">mozilla.or.kr</a> dashboard</h1>
<h2>All files</h2>
<p class="action"><a href="?action=flush" class="button">Refresh all remote caches</a></p>
<?php
foreach ($result as $item) {
echo('<h2>' . $item['url'] . '</h2>');
echo('<p class="action"><a href="?action=fetch&url=' . urlencode($item['url']) . '" class="button">Fetch remote and re-generate cache</a></p>');
if (strlen($item['diff'] > 0)) {
echo('<div class="diff">' . $item['diff'] . '</div>');
} else {
echo('<p>Clean!</p>');
}
}
?>
</body>
</html>