forked from wille/relayawards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
114 lines (93 loc) · 3.87 KB
/
index.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
<?php
$title = "RelayAwards - competition for Tor-relay operators!";
require_once "header.php";
require_once "awards/award.php";
require_once "inc/utils.php";
if(empty($_GET['s'])) {
echo '<head><meta charset="UTF-8"><meta name="keywords" content="relayawards,tor,competition,relayawards.com,index,start,relay,node,compete,operators,win"><meta name="description" content="RelayAwards - A competition for Tor relay operators! - Welcome! | Index"></head>
<link href="css/search.css" rel="stylesheet">
<center><h1>Welcome to RelayAwards <i class="fa fa-trophy" aria-hidden="true"></i></h1><p>
RelayAwards is a competition for Tor-relay operators! Compete against your friends, your family or why not yourself?</br>
There are many awards to win. Some are easy, others are hard and some are <b>very</b> hard.</br>
Make sure to read about the different <a href="awards.php">awards</a> that you can win and how everything <a href="about.php">works</a>. Good luck!
<div class="box"> <center><form action="?" method="get">
<div class="container-4">
<input type="search" id="search" name="s" placeholder="Search..." autofocus />
<button class="icon"><i class="fa fa-search"></i></button>
</center></form>
</div>
</div>';
} else {
echo '<div class="row">
<div class="container">
<table class="table">
<thead>
<tr>
<th>Rank</th>
<th>Nickname</th>
<th>Uptime</th>
<th>Bandwidth</th>
<th>Country</th>
<th>Awards</th>
</tr>
</thead>
<tbody>';
}
?>
<?php
require_once "relays.php";
function match($relay, $search) {
$to_search = [
$relay["nick"],
$relay["fingerprint"],
$relay["country"],
$relay["country_name"],
];
$search_array = explode("+", $search);
foreach ($search_array as $s) {
foreach ($to_search as $term) {
if (strpos(strtolower($term), strtolower($s)) !== false) {
return true;
}
}
}
return false;
}
const MIN_SEARCH = 2;
const MAX_SEARCH = 25;
$search = $_GET["s"];
$can_search = isset($search) && strlen($search) >= MIN_SEARCH && strlen($search) <= MAX_SEARCH;
if (strpos($search, "+") !== false) {
$search_array = explode("+", $search);
foreach ($search_array as $s) {
$s = trim($s);
if (strlen($s) < MIN_SEARCH || strlen($s) > MAX_SEARCH) {
$can_search = false;
break;
}
}
}
if ($can_search) {
$search = htmlspecialchars($search);
$relays = json_decode(file_get_contents("cache/cache.txt"), true);
$sorted = [];
for ($i = 0; $i < count($relays); $i++) {
if (match($relays[$i], $search)) {
$sorted[] = $relays[$i];
}
}
table_relays($sorted, 0, 0, false, true);
} else {
echo "Minimum search is " . MIN_SEARCH . ", maximum is " . MAX_SEARCH;
}
if(!empty($_GET['s'])) {
echo '</tbody>
</table>
Last updated ' . getTimeSince(file_get_contents("cache/time.txt")) . " ago";
}
?>
</div>
</div>
</div>
</body>
</html>