-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·217 lines (181 loc) · 5.47 KB
/
index.php
File metadata and controls
executable file
·217 lines (181 loc) · 5.47 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
<?php
$search = false;
$base = "";
$alg = "";
$query = "";
if (isset($_GET["query"])) {
$search = true;
$base = $_GET["base"];
$alg = $_GET["alg"];
$query = $_GET["query"];
}
if (strpos($base, "..") !== false) {
die("puto maricón, que haces");
}
function getObjectsIter($path) {
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
return $objects;
}
function getObjectsLaura($path) {
$result = array();
$dir2 = glob($path."/*",GLOB_ONLYDIR);
$dir = glob($path."/*"); // creo que esto coge los dir tambien
while (count($dir2) != 0) {
for ($i = 0; $i < count($dir2); $i++){
$folder = glob($dir2[$i]);
}
}
$result = $dir;
return $result;
}
function getObjectsMe($path) {
if ($path[strlen($path) - 1] != '/') $path = $path.'/';
//echo $path."<br>";
$objects = array_slice(scandir($path), 2); // 35
for ($i = 0; $i < count($objects); $i++) {
$objects[$i] = $path.$objects[$i];
}
foreach ($objects as $object) {
if(strpos($object, ".") || strpos($object, "..")) continue;
if (is_dir($object)) {
$objects = array_merge($objects, getObjectsMe($object));
}
}
return $objects;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="/style.css">
<title>ARFNET</title>
<style>
.title {
font-size: 36px;
}
header *{
display: inline-block;
}
*{
vertical-align: middle;
max-width: 100%;
}
video {
width: 72%;
}
.form {
margin: auto;
text-align: center;
margin-bottom: 50px;
}
.searchbox {
width: 300px;
}
.searchbar {
height: 25px;
}
.stats {
font-size: 20px;
margin-bottom: 20px;
margin-left: 15px;
}
.result {
margin-bottom: 20px;
margin-left: 15px;
}
.name {
font-size: 20px;
}
.address {
font-size: 14px;
}
</style>
</head>
<body>
<header>
<img src="/arfnet_logo.png" width="64">
<span class="title"><strong>ARFNET</strong></span>
</header>
<hr>
<a class="home" href="/">Home</a><br>
<h2>ARFNET Search Engine</h2>
<br>
<div class="form">
<form action="/search/index.php" method="GET">
<select class="searchbar" name="base">
<option <?php if ($base == "FTPServer/") echo "selected"; ?> value="FTPServer/">FTPServer</option>
<option <?php if ($base == "source/repos/") echo "selected"; ?> value="source/">source</option>
</select>
<select class="searchbar" name="alg">
<option <?php if ($alg == "str_contains") echo "selected"; ?> value="str_contains">str_contains</option>
<option <?php if ($alg == "regex") echo "selected"; ?> value="regex">regex</option>
</select>
<input class="searchbar searchbox" type="text" name="query" <?php if ($search) echo 'value="'.$query.'"'; ?> >
<input class="searchbar" type="submit" value="Search">
</form>
</div>
<hr>
<?php
if ($search) {
if ($query == "") die("empty query");
if ($base != "FTPServer/" && $base != "source/repos/") die("No other based allowed, fuck you.");
if (strpos($query, "<") === false) { } else { die("No <> allowed, fuck you."); }
$time_start = microtime(true);
$path = "/d/".$base;
//echo $path;
$objects = getObjectsMe($path);
$results1 = array();
$results2 = array();
//echo "<pre>";
//print_r($objects);
//echo "</pre>";
$tok = strtok($query, ' ');
$tokens = array();
while ($tok !== false) {
array_push($tokens, $tok);
$tok = strtok(' ');
}
foreach($objects as $name) {
//echo $name."<br>";
$relevance1 = true;
$relevance2 = false;
foreach($tokens as $token) {
if (strpos(strtolower($name), strtolower($token))) {
$relevance1 = $relevance1 && true;
$relevance2 = $relevance2 || true;
} else {
$relevance1 = $relevance1 && false;
$relevance2 = $relevance2 || false;
}
}
if ($relevance1 && $relevance2)
array_push($results1, $name);
else if (!$relevance1 && $relevance2)
array_push($results2, $name);
}
$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
echo '<div class="stats"><span><strong>'.(count($results1) + count($results2)).' results in '.round($execution_time, 3).' seconds</strong></span></div>';
echo '<div class="stats"><span><strong>Results including all tokens [';
foreach ($tokens as $token) echo $token.', ';
echo ']</strong></span></div>';
foreach ($results1 as $result) {
echo '<div class="result">'.
'<a class="name" href="'.substr($result, 2).'">'.basename($result).'</a><br>'.
'<span class="address">'.substr($result, 2).'</span>'.
'</div>';
}
echo '<div class="stats"><span><strong>Results including single token [';
foreach ($tokens as $token) echo $token.', ';
echo ']</strong></span></div>';
foreach ($results2 as $result) {
echo '<div class="result">'.
'<a class="name" href="'.substr($result, 2).'">'.basename($result).'</a><br>'.
'<span class="address">'.substr($result, 2).'</span>'.
'</div>';
}
}
?>
</body>
</html>