-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
324 lines (286 loc) · 14.2 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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<?php
include('config.php');
if(!isset($_SESSION['email']))
{
header("Location: $baseUrl/login.php");
exit();
}
$ip = $_SERVER['REMOTE_ADDR'];
$timestamp = time() + 3600;
////////////////////////////PAGE Stuff///////////////////////////////////////
$page = 1;
if(isset($_GET['page']))
{
$page=$_GET['page'];
}
$adjacents = 2;
$limit = $perPageRecords;
$sql = "SELECT COUNT(id) as total_pages FROM {$tbl_prefex}scans";
$query = $handler->prepare($sql);
$query->execute();
if ($row=$query->fetch())
{
$total_pages=$row['total_pages'];
}
else
{
header("Location: $baseUrl/404");
exit;
}
if($page)
$start = ($page - 1) * $limit;
else
{
$page=1;
$start=0;
}
////////////////////////////PAGE Stuff///////////////////////////////////////
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title><?php echo $baseTitle; ?></title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet"/>
<link href="css/style.css?v=10" rel="stylesheet"/>
<link href="css/font-awesome.min.css" rel="stylesheet"/>
<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<![endif]-->
<link rel="icon" type="image/x-icon" sizes="16x16" href="icons/16x16.ico">
<link rel="icon" type="image/x-icon" sizes="32x32" href="icons/32x32.ico">
<link rel="apple-touch-icon" sizes="57x57" href="icons/57x57.ico">
<link rel="apple-touch-icon" sizes="60x60" href="icons/60x60.ico">
<link rel="apple-touch-icon" sizes="72x72" href="icons/72x72.ico">
<link rel="apple-touch-icon" sizes="76x76" href="icons/76x76.ico">
<link rel="icon" type="image/x-icon" sizes="96x96" href="icons/96x96.ico">
<link rel="apple-touch-icon" sizes="114x114" href="icons/114x114.ico">
<link rel="apple-touch-icon" sizes="120x120" href="icons/120x120.ico">
<link rel="apple-touch-icon" sizes="144x144" href="icons/144x144.ico">
<meta name="msapplication-TileColor" content="#ffffff">
<link name="msapplication-TileImage" content="icons/144x144.ico">
<meta name="theme-color" content="#ffffff">
<link rel="apple-touch-icon" sizes="152x152" href="icons/152x152.ico">
<link rel="apple-touch-icon" sizes="180x180" href="icons/180x180.ico">
<link rel="icon" type="image/x-icon" sizes="192x192" href="icons/192x192.ico">
<link rel="icon" type="image/x-icon" sizes="128x128" href="icons/128x128.ico">
<link rel="icon" type="image/x-icon" sizes="256x256" href="icons/256x256.ico">
<link rel="icon" type="image/x-icon" sizes="512x512" href="icons/512x512.ico">
</head>
<body>
<?php include('navigation.php'); ?>
<main role="main">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<h2>Scan Reports</h2>
<table class="table table-responsive table-hover">
<tr>
<th style="width: 50px;">#</th>
<th>File Name</th>
<th style="width: 500px;">Scan Status</th>
<th style="width: 100px;">File Size</th>
<th style="width: 150px;">Download</th>
<th style="width: 200px;" >Date Uploaded</th>
<th style="width: 200px;">Delete</th>
</tr>
<?php
$sql = "SELECT t1.filehash, t1.filename, t1.filesize, t1.datetime, t1.sha256, t1.url, t2.positives, t2.total, t2.permalink,t1.status, t2.datetime as scantime, t1.lastscantime
FROM {$tbl_prefex}scans t2, {$tbl_prefex}files t1
WHERE t1.id = t2.file_id
ORDER BY t2.id desc LIMIT $start, $limit";
$query = $handler->prepare($sql);
$query->execute();
$rows = $query->rowCount();
if($rows > 0)
{
$count = $start;
while ($row=$query->fetch())
{
$filehash = $row["filehash"];
$filename = $row["filename"];
$filesize = $row["filesize"];
$url = $row["url"];
$datetime = $row["datetime"];
$sha256 = $row["sha256"];
$scantime = $row["scantime"];
$positives = $row["positives"];
$total = $row["total"];
$permalink = $row["permalink"];
$status = $row["status"];
$h = md5($salt . $timestamp . $filehash);
$downloadLink = "$baseUrl/file.php?sig={$filehash}&h={$h}&t={$timestamp}&download=1";
$deleteLink = "$baseUrl/file.php?sig={$filehash}&h={$h}&t={$timestamp}&delete=1";
?>
<tr>
<td><?php echo $total_pages - $count; ?></td>
<?php if($url!="") {?>
<td><a target="_blank" href="<?php echo $url; ?>"><?php echo $filename; ?></a><br /><span class="hash"><b>sha256: </b><?php echo $sha256; ?></span></td>
<?php } else { ?>
<td><?php echo $filename; ?><br /><span class="hash"><b>sha256: </b><?php echo $sha256; ?></span></td>
<?php } ?>
<?php if($permalink!=''){ ?>
<?php if($positives>0){ ?>
<td><span style="color: red;"><i class="fa fa-flag"></i></span> Scanned <?php echo $helper->ago(strtotime($scantime)); ?>, <?php echo "$positives/$total detections"; ?>. <a href="<?php echo $permalink; ?>" target="_blank">Full Report</a></td>
<?php } else if($positives==0){ ?>
<td><span style="color: green;"><i class="fa fa-flag"></i></span> Scanned <?php echo $helper->ago(strtotime($scantime)); ?>, <?php echo "$positives/$total detections"; ?>. <a href="<?php echo $permalink; ?>" target="_blank">Full Report</a></td>
<?php } ?>
<?php }
else if($status == "Oversize") echo "<td><p><i class='fa fa-flag'></i> Error: File is above 32MB</p></td>";
else if($status == "Error") echo "<td><p><i class='fa fa-flag'></i> Unknown error occurred while scanning this file.</p></td>";
else if($status == "Not Scanned") echo "<td><p><i class='fa fa-flag'></i> File not scanned yet.</p></td>";
else if($status == "Queued") echo "<td><p><i class='fa fa-flag'></i> File queued for scan <?php echo $helper->ago(strtotime($scantime)); ?>.</p></td>";
else { echo "<td>-</td>"; }
?>
<td><?php echo $helper->size($filesize); ?></td>
<td><i class="fa fa-arrow-circle-down"></i> <a target="_blank" href="<?php echo $downloadLink; ?>">Download</a></td>
<td><?php echo $helper->ago(strtotime($datetime)); ?></td>
<td>
<i class="fa fa-times" aria-hidden="true"></i> <a href="#delete" onclick="deleteFile('<?php echo $deleteLink; ?>')">Delete</a>
</td>
</tr>
<?php
$count++;
}
}
else
{
echo '<div class="col-md-12 text-center"><p>No scan reports at this time.</p></div>';
}
?>
</table>
<!--Pagination-->
<?php
/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<ul class=\"pagination pull-right\">";
//previous button
if ($page > 1)
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=$prev\">←</a></li>";
else
$pagination.= "<li class='page-item disabled'><a class='page-link'>←</a></li>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<li class='page-item disabled'><a class='page-link'>$counter</a></li>";
else
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=$counter\">$counter</a></li>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<li class='page-item active'><a class='page-link'>$counter</a></li>";
else
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=$counter\">$counter</a></li>";
}
$pagination.= "<li class='page-item disabled'><a class='page-link'>...</a></li>";
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=$lpm1\">$lpm1</a></li>";
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=$lastpage\">$lastpage</a></li>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=1\">1</a></li>";
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=2\">2</a></li>";
$pagination.= "<li class='page-item disabled'><a class='page-link'>...</a></li>";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<li class='page-item disabled'><a class='page-link'>$counter</a></li>";
else
$pagination.= "<li class='page-item'><a class='page-link'href=\"$baseUrl/index.php?page=$counter\">$counter</a></li>";
}
$pagination.= "<li class='page-item disabled'><a class='page-link'>...</a></li>";
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=$lpm1\">$lpm1</a></li>";
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=$lastpage\">$lastpage</a></li>";
}
//close to end; only hide early pages
else
{
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=1\">1</a></li>";
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=2\">2</a></li>";
$pagination.= "<li class='page-item disabled'><a class='page-link'>...</a></li>";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<li class='page-item active'><a class='page-link'>$counter</a></li>";
else
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=$counter\">$counter</a></li>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<li class='page-item'><a class='page-link' href=\"$baseUrl/index.php?page=$next\">→</a></li>";
else
$pagination.= "<li class='page-item'><a class='page-link'>→</a></li>";
$pagination.= "</ul>\n";
}
echo $pagination;
?>
</div>
</div>
</div> <!-- /container-fluid -->
</main>
<footer class="container-fluid">
<p>© <?php echo $baseTitle; ?></p>
</footer>
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/tether.min.js"></script>
<!--script src="js/popper.min.js"></script-->
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
function deleteFile(_url)
{
if(confirm("Are you sure you want to delete this file?"))
{
$.ajax(
{
type: "GET",
url: _url,
dataType: "json",
success: function(json)
{
$.each(json,function()
{
if(json.error)
{
alert(json.error);
}
if(json.success)
{
alert(json.success);
}
});
}
});
}
else
{
}
}
</script>
</body>
</html>