-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetViolations.php
59 lines (52 loc) · 1.85 KB
/
getViolations.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
<?php
$log_file = dirname(__FILE__) . '/csp-violations.log';
if (isset($_GET['p']) && $_GET['p'] === 'del') {
file_put_contents($log_file, '');
}
$violations = \file_get_contents($log_file);
$violations = str_replace('##', ',', $violations);
$start = '{"Last validations": "' . date('d-m-y h:m:s') . '","Violations number":"0"}';
$violationsJson = "[$violations $start]";
$violationsSlot = json_decode($violationsJson);
$violationsSlot = array_reverse($violationsSlot);
$violationsSlot[0]->{"Violations number"} = \count($violationsSlot) - 1;
?>
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
</head>
<body>
<script>
function emptyHandler() {
fetch('http://0.0.0.0:8080/getViolations.php?p=del')
reloadHandler()
}
function reloadHandler() {
self.location.reload();
}
</script>
<div class="container m-0">
<div class="row">
<div class="col">
<hr class="my-2"/>
<input class="btn btn-outline-primary" type='button' value="Reload" id="reload"
onclick="javascript:reloadHandler()"/>
<input class="btn btn-outline-primary" type='button' value="Empty log" id="empty"
onclick="javascript:emptyHandler()"/>
<hr class="my-2"/>
<?php
foreach ($violationsSlot as $v) {
echo '<div class="card text-white bg-danger mb-3""><div class="card-body">';
foreach ($v as $k => $val) {
echo "<span style='font-weight: bold'>$k: </span> $val<br> ";
}
echo "</div></div><br>";
}
?>
</div>
</div>
</div>
</body>
</html>