-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.php
More file actions
235 lines (226 loc) · 8.48 KB
/
main.php
File metadata and controls
235 lines (226 loc) · 8.48 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
if(!isset($config)): die(); endif;
define('UPDATE_DOMAIN', 'cachechu.googlecode.com');
define('UPDATE_PATH', '/svn/VERSION');
define('GEOIP_PATH', 'geoip/geoip.php');
define('GEOIP_DATA_PATH', 'geoip/GeoIP.dat');
$config['Path']['Update'] = isset($config['Path']['Update']) ? $config['Path']['Update'] : 'data/update.dat';
$config['Interface']['Info'] = isset($config['Interface']['Info']) ? $config['Interface']['Info'] : 1;
$config['Interface']['Update'] = isset($config['Interface']['Update']) ? $config['Interface']['Update'] : 1;
$is_only_mute = (in_array(MUTE, $config['Network']['Support']) && count($config['Network']['Support']) == 1);
function get_flag($ip) {
global $geoip;
$html = '';
if($geoip) {
$code = geoip_country_code_by_addr($geoip, $ip);
$path = 'flags/' . strtolower($code) . '.png';
if($code && file_exists($path)) {
$country = geoip_country_name_by_addr($geoip, $ip);
$html = '<img src="' . $path . '" width="16" height="11" alt="' . $code . '" title="' . $country . '">';
}
}
return $html;
}
$geoip = FALSE;
if(file_exists(GEOIP_PATH) && file_exists(GEOIP_DATA_PATH) && file_exists('flags')) {
require(GEOIP_PATH);
if(function_exists('geoip_open') && function_exists('geoip_country_code_by_addr') &&
function_exists('geoip_country_name_by_addr')) {
$geoip = geoip_open(GEOIP_DATA_PATH, GEOIP_STANDARD);
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="language" content="en">
<meta name="description" content="Cachechu is a GWebCache licensed under the GPL.">
<meta name="keywords" content="Gnutella, Gnutella2">
<title>Cachechu GWebCache</title>
<link href="main.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1>
<a href="http://code.google.com/p/cachechu/"
title="Cachechu Projects Page">Cachechu GWebCache</a>
</h1>
<?php
// Do not show update notification for test versions
if(substr(VERSION, 0, 1) != 'R' && $config['Interface']['Update']):
$config['Path']['Update'] = isset($config['Path']['Update']) ? $config['Path']['Update'] : 'data/update.dat';
if(file_exists($config['Path']['Update'])) {
$age = $now - @filemtime($config['Path']['Update']);
} else {
$dir = dirname($config['Path']['Update']);
if(!file_exists($dir)) {
@mkdir($dir, DIR_FLAGS, TRUE); // Create directory if it does not exist
}
$age = $config['URL']['Age'];
}
if($age >= $config['URL']['Age']) {
$domain = UPDATE_DOMAIN;
$contents = trim(download_data(UPDATE_DOMAIN, 80, get_input(UPDATE_PATH, UPDATE_DOMAIN), TRUE));
if($contents != '') { @file_put_contents($config['Path']['Update'], $contents); }
}
if(file_exists($config['Path']['Update'])):
$latest = substr(trim(@file_get_contents($config['Path']['Update'])), 0, 5);
if($latest != '' && $latest != VERSION): ?>
<div class="update">
<a href="http://code.google.com/p/cachechu/downloads/list">
GWebCache is out of date. Update to Cachechu <?php echo $latest; ?>.
</a>
</div>
<?php
endif;
endif;
endif;
?>
<?php if($config['Interface']['Info']): ?>
<?php date_default_timezone_set('UTC'); ?>
<ul id="navigation">
<li><?php if($data == 'hosts'): ?>Hosts<?php else: ?><a href="?data=hosts">Hosts</a><?php endif; ?></li>
<?php if(!$is_only_mute): ?>
<li><?php if($data == 'services'): ?>Services<?php else: ?><a href="?data=services">Services</a><?php endif; ?></li>
<?php endif; ?>
</ul>
<?php if($data == 'hosts'): ?>
<div id="main">
<?php foreach($config['Network']['Support'] as $network): ?>
<div class="network">
<h2><?php echo ucwords($network); ?> Hosts</h2>
<table summary="Current <?php echo ucwords($network); ?> hosts in cache">
<?php if($geoip): ?><col class="flags"><?php endif; ?>
<col class="ips">
<col class="ports">
<col class="clients">
<col class="timestamps">
<col class="ages">
<thead>
<tr>
<?php if($geoip): ?><th scope="col"></th><?php endif; ?>
<th scope="col">IP</th>
<th scope="col">Port</th>
<th scope="col">Client</th>
<th scope="col">Timestamp</th>
<th scope="col">Age (<abbr title="seconds">s</abbr>)</th>
</tr>
</thead>
<tbody>
<?php
$count = 0;
$path = str_replace(NET_REPLACE, $network, $config['Path']['Host']);
$lines = file_exists($path) ? @file($path) : array();
foreach($lines as $line) {
@list($host, $time, $client, $xnet) = explode('|', $line);
$xnet = trim($xnet) == '' ? DEFAULT_NET : $xnet;
$age = $now - $time;
@list($ip, $port) = explode(':', $host);
if($xnet == $network && $age < $config['Host']['Age'] && $age >= 0) {
echo '<tr class="';
echo $count % 2 == 0 ? 'odd' : 'even';
echo '">';
echo $geoip ? '<td>' . get_flag($ip) . '</td>' : '';
echo '<td>', htmlentities($ip), '</td>';
echo '<td>', htmlentities($port), '</td>';
echo '<td>', htmlentities($client), '</td>';
echo '<td>', date('Y-m-d H:i', $time), 'Z</td>';
echo '<td>', $age, '</td>';
echo '</tr>';
++$count;
if($count >= $config['Host']['Output']) { break; }
}
}
if(!$count) {
echo '<tr class="empty"><td colspan="', $geoip ? 6 : 5, '">There are no ', ucwords($network), ' hosts.</td></tr>';
}
?>
</tbody>
</table>
</div>
<?php endforeach; ?>
</div>
<?php elseif($data == 'services' && !$is_only_mute): ?>
<div id="main">
<?php foreach($config['Network']['Support'] as $network): ?>
<?php if($network != MUTE): ?>
<div class="network">
<h2><?php echo ucwords($network); ?> Services</h2>
<table summary="Current <?php echo ucwords($network); ?> services in cache">
<?php if($geoip): ?><col class="flags"><?php endif; ?>
<col class="urls">
<col class="ips">
<col class="clients">
<col class="timestamps">
<thead>
<tr>
<?php if($geoip): ?><th scope="col"></th><?php endif; ?>
<th scope="col">URL</th>
<th scope="col">IP</th>
<th scope="col">Client</th>
<th scope="col">Timestamp</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="<?php echo $geoip ? 5 : 4 ?>">
<form method="get" action="">
<div>
<?php if($network != GNUTELLA): ?>
<input type="hidden" name="net" value="<?php echo $network; ?>">
<input type="hidden" name="update" value="1">
<?php endif; ?>
<input type="hidden" name="client" value="CACH">
<input type="hidden" name="version" value="ECHU">
<label for="<?php echo $network; ?>url"><?php echo ucwords($network); ?> URL:</label>
<input type="text" name="url" id="<?php echo $network; ?>url" size="50">
<input type="submit" value="Add">
</div>
</form>
</td>
</tr>
</tfoot>
<tbody>
<?php
$count = 0;
$path = str_replace(NET_REPLACE, $network, $config['Path']['URL']);
$lines = file_exists($path) ? @file($path) : array();
sort($lines);
foreach($lines as $line) {
@list($url, $time, $status, $ip, $xnet, $client) = explode('|', $line);
$xnet = trim($xnet) == '' ? DEFAULT_NET : $xnet;
$url = get_url($url);
$url = preg_match(URL_REGEX, $url, $match) ? $url : '';
if($time == 0) { $time = $now; }
$age = $now - $time;
if($url && $xnet == $network && $age < $config['URL']['Age'] && $age >= 0 && $status === 'OK') {
echo '<tr class="';
echo $count % 2 == 0 ? 'odd' : 'even';
echo '">';
echo $geoip ? '<td>' . get_flag($ip) . '</td>' : '';
echo '<td><a href="', htmlentities($url), '" rel="nofollow">', htmlentities($match['domain']), '</a></td>';
echo '<td>', htmlentities(trim($ip) == '' ? 'Unknown' : $ip), '</td>';
echo '<td>', htmlentities(trim($client) == '' ? 'Unknown' : $client), '</td>';
echo '<td>', date('Y-m-d H:i', $time > 0 ? $time : $now), 'Z</td>';
echo '</tr>';
++$count;
}
}
if(!$count) {
echo '<tr class="empty"><td colspan="', $geoip ? 5 : 4,'">There are no ', ucwords($network), ' services.</td></tr>';
}
?>
</tbody>
</table>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php endif; ?>
<div id="footer">
Cachechu <?php echo VERSION; ?> under <a href="http://www.gnu.org/licenses/gpl-3.0.html">GPLv3</a>
</div>
</body>
</html>