-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblocklist.php
More file actions
75 lines (72 loc) · 2.49 KB
/
blocklist.php
File metadata and controls
75 lines (72 loc) · 2.49 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
<?php
// Load configuration file
require_once 'config.php';
$count = 0;
$count2 = 0;
// Connect to database
$conn = mysqli_connect($config['host'], $config['username'], $config['password'], $config['database']);
// Check connection
if (!$conn) {
die("Verbindung fehlgeschlagen: " . mysqli_connect_error());
}
// Get the 'id' parameter from the URL and sanitize it
$ID = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_STRING);
// Check if 'id' parameter is set and not empty
if(isset($ID) && $ID != ""){
$timestamp = date('D, d M Y, H:i T');
// 'id' parameter is passed, get contents of URLs
$id = $_GET['id'];
$query = "SELECT urls FROM `".$config['tablename']."` WHERE resolved_url='".$id."'";
$result = mysqli_query($conn, $query);
// Check if only one entry is found
if (mysqli_num_rows($result) == 1) {
// Entry found, get URLs
$row = mysqli_fetch_assoc($result);
$urls = explode(',', $row['urls']);
$content = '';
$unique_lines = array();
foreach ($urls as $url) {
// Trim leading/trailing whitespace from URL
$url = trim($url);
if (!empty($url)) {
// Get content of URL
$blocklist = file_get_contents($url);
if ($blocklist !== false) {
$blocklist_lines = explode("\n", $blocklist);
foreach ($blocklist_lines as $line) {
$line = trim($line);
$count2 ++;
if (!empty($line) && !isset($unique_lines[$line])) {
// Add line to content if it's not a duplicate
$content .= $line . "\n";
$unique_lines[$line] = true;
}
else{
$count ++;
}
}
}
}
}
// Output content as plain text
header('Content-Type: text/plain');
echo "# ".$count." out of ".$count2." entries were duplicates and have been removed.
# Based on: https://github.com/HOCKULUS/BlocklistBlaster
# Title: BlocklistBlaster
# Last modified: ".$timestamp."
# Creator: HOCKULUS
#------------------
".$content;
}
else {
// Entry not found, output error message
header('Content-Type: text/plain');
echo "# ID not found!";
}
}
else {
// 'id' parameter not set, output error message
header('Content-Type: text/plain');
echo "# ID not specified!";
}
?>