spam.blade.php 6.36 KB
Newer Older
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
@extends('layouts.subPages')

@section('title', $title )

@section('content')
<style>
    #head {
        display: flex;
        align-items: center;
        margin-bottom: 16px;
    }
    #head > button {
        margin-left: 16px;
    }
    #head > h1 {
        margin: 0;
    }
    #queries {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
    }

    .matches {
        background-color: #c9f4c9;
    }
    #block-requests {
        margin-bottom: 16px;
    }
    #regexp {
        margin-bottom: 8px;
    }
    #ban-time {
        margin-bottom: 8px;
    }
</style>
<div id="block-requests">
    <form method="post">
        <input class="form-control" type="text" name="regexp" id="regexp" placeholder="Type in regexp to match queries...">
        <select name="ban-time" id="ban-time" class="form-control">
            <option value="1 day">Einen Tag</option>
            <option value="1 week">Eine Woche</option>
            <option value="2 weeks">Zwei Wochen</option>
            <option value="1 month" selected>Einen Monat</option>
        </select>
        <button type="submit" class="btn btn-default btn-sm">Sperren</button>
    </form>
</div>
<div id="head">
    <h1>Letzte Suchanfragen</h1>
    <button type="button" class="btn btn-success btn-sm">Aktualisierung stoppen (60)</button>
</div>
<input class="form-control" type="text" name="" id="check-against" placeholder="Match against...">
<div id="queries">
    @foreach($queries as $query)
    <div class="query card">{{$query}}</div>
    @endforeach
</div>
<div id="bans">
    <h1>Current Bans</h1>
    <table class="table table-striped">
        <thead>
            <tr>
                <td>Regexp</td>
                <td>Banned until</td>
                <td>Actions</td>
            </tr>
        </thead>
        <tbody>
            @foreach($bans as $ban)
            <tr>
                <td>{{ $ban["regexp"] }}</td>
                <td>{{ Carbon::createFromFormat("Y-m-d H:i:s", $ban["banned-until"])->format("d.m.Y H:i:s")}} ({{ Carbon::createFromFormat("Y-m-d H:i:s", $ban["banned-until"])->diffInDays(Carbon::now()) }} Days)</td>
                <td>
                    <form action="{{ url("admin/spam/deleteRegexp") }}" method="post">
                        <input type="hidden" name="regexp" value="{{ $ban["regexp"] }}">
                        <button type="submit">&#128465;</button>
                    </form>
                </td>
            </tr>
            @endforeach
        </tbody>
    </table>
</div>
<div id="loadedbans">
    <h1>Loaded Bans</h1>
    <table class="table table-striped">
        <thead>
            <tr>
                <td>Regexp</td>
            </tr>
        </thead>
        <tbody>
            @foreach($loadedBans as $ban)
            <tr>
                <td>{{ $ban }}</td>
            </tr>
            @endforeach
        </tbody>
    </table>
</div>
<script>
    var lastUpdate = Date.now();
    var updating = true;
    var buttonText = "Aktualisierung stoppen";
    var interval = setInterval(updateQueries, 1000);
107
108
109
    document.getElementById("regexp").oninput = checkRegexp;
    document.getElementById("check-against").oninput = checkRegexp;
    window.addEventListener('load', function(){
110
111
112
113
        checkRegexp();
    });


114
    document.querySelector("#head > button").addEventListener('click', function() {
115
116
117
118
119
120
121
122
123
124
        if(!updating) {
            $("#head > button").removeClass("btn-danger");
            $("#head > button").addClass("btn-success");
            buttonText = "Aktualisierung stoppen";
            interval = setInterval(updateQueries, 1000);
        }
        var updateAt = lastUpdate + 60000;
        var updateIn = Math.round((updateAt - Date.now()) / 1000);
        $("#head > button").html(buttonText + " (" + updateIn + ")");
        updating = !updating;
125
    })
126
127
128
129
130
131

    function updateQueries() {
        var updateAt = lastUpdate + 60000;
        var updateIn = Math.round((updateAt - Date.now()) / 1000);

        if(!updating){
132
133
            document.querySelector("#head > button").classList.remove("btn-success");
            document.querySelector("#head > button").classList.add("btn-danger");
134
135
136
137
            buttonText = "Aktualisierung starten";
            clearInterval(interval);
        }

138
        document.querySelector("#head > button").innerHTML = buttonText + " (" + updateIn + ")";
139
140
141
142
143
144
        if(updateAt > Date.now()){
            return;
        }
        fetch("{{ url('admin/spam/jsonQueries') }}")
            .then(response => response.json())
            .then(data => {
145
146
147
148
149
150
                document.getElementById("queries").innerHTML = "";
                data.forEach((index, el) => {
                    newElement = document.createElement("div");
                    newElement.classList.add("query");
                    newElement.classList.add("card");
                    newElement.innerHTML = el;
Dominik Hebeler's avatar
Dominik Hebeler committed
151
                    document.getElementById("queries").appendChild(newElement);
152
153
154
155
156
157
158
159
160
                });
                lastUpdate = Date.now();
                checkRegexp();
            });

    }


    function checkRegexp() {
Dominik Hebeler's avatar
Dominik Hebeler committed
161
        var val = document.getElementById("regexp").value;
162
163
164
        var queries = [];


Dominik Hebeler's avatar
Dominik Hebeler committed
165
166
        document.querySelectorAll("#queries > .query").forEach((el, index) => {
            queries.push(el.innerHTML);
167
        });
Dominik Hebeler's avatar
Dominik Hebeler committed
168
169
170
        

        queries.push(document.getElementById("check-against").value)
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

        var url = "{{ url('admin/spam/queryregexp') }}";
        var options = {
            method: 'POST',
            body: JSON.stringify({
                "queries": queries,
                "regexp": val
            }),
            headers: {
                'Content-Type': 'application/json'
            }
        };

        fetch(url, options)
            .then(response => response.json())
            .then(data => {
Dominik Hebeler's avatar
Dominik Hebeler committed
187
                document.querySelectorAll("#queries > .query").forEach((el, index) => {
188
                    if(data[index]["matches"]){
Dominik Hebeler's avatar
Dominik Hebeler committed
189
                        el.classList.add("matches");
190
                    }else{
Dominik Hebeler's avatar
Dominik Hebeler committed
191
                        elclassList.remove("matches");
192
193
                    }
                });
Dominik Hebeler's avatar
Dominik Hebeler committed
194
                
195
                if(data[data.length-1]["matches"]){
Dominik Hebeler's avatar
Dominik Hebeler committed
196
                    document.getElementById("check-against").classList.add("matches");
197
                }else{
Dominik Hebeler's avatar
Dominik Hebeler committed
198
                    document.getElementById("check-against").classList.remove("matches");
199
200
201
202
203
204
205
                }
            });
    }


</script>
@endsection