-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-to-blacklist.php
80 lines (64 loc) · 2.04 KB
/
add-to-blacklist.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
<?php
// Include bootstrap file to initialization
require_once './src/bootstrap.php';
// Set default values
$ipAddress = '';
$ttl = -1;
$reason = '';
$readyToCreate = false;
$input = file_get_contents('php://input');
// Check if post data is JSON
if ($data = json_decode($input)) {
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json; charset=UTF-8');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Max-Age: 3600');
header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, X-Request-With');
$data = (array) $data;
// Check post variables in JSON
if (isset($data['ip_address'])) {
$ipAddress = $data['ip_address'];
}
else {
die('IP adresi gerekli.');
}
if (isset($data['ttl'])) {
$ttl = $data['ttl'];
}
if (isset($data['reason'])) {
$reason = $data['reason'];
}
$readyToCreate = true;
}
else if ($_POST) {
// Check post variables in form data
if (isset($_POST['ip_address'])) {
$ipAddress = $_POST['ip_address'];
}
else {
die('IP adresi gerekli.');
}
if (isset($_POST['ttl'])) {
$ttl = $_POST['ttl'];
}
if (isset($_POST['reason'])) {
$reason = $_POST['reason'];
}
$readyToCreate = true;
}
if ($readyToCreate) {
// Add IP address, time to live value and reason to storage
addToBlacklist($ipAddress, $ttl, $reason);
// Check if logging is active on config
if ($config['logging'] == true) {
// Prepare log string
$log = sprintf("Banned: %s for %s minutes. Sebep: %s", $ipAddress, $ttl, $reason);
// Log that
error_log($log, 0);
}
}
else {
die('Geçersiz metot');
}
// If there is a query for that then redirect
thenRedirect();