snakeia-server 1.1.3-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,305 @@
1
+ <!--
2
+ * Copyright (C) 2020 Eliastik (eliastiksofts.com)
3
+ *
4
+ * This file is part of "SnakeIA Server".
5
+ *
6
+ * "SnakeIA Server" is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * "SnakeIA Server" is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with "SnakeIA Server". If not, see <http://www.gnu.org/licenses/>. -->
18
+ <!doctype HTML>
19
+ <html>
20
+ <head>
21
+ <meta charset="UTF-8"></meta>
22
+ <meta name="viewport" content="width=device-width, initial-scale=1">
23
+ <meta name="csrf-token" content="<%= csrfToken %>">
24
+ <link href="/css/bootstrap.min.css" rel="stylesheet">
25
+ <link href="/css/flat-ui.min.css" rel="stylesheet">
26
+ <link href="/css/main.css" rel="stylesheet">
27
+ <script src="/js/jquery.min.js"></script>
28
+ <script src="/js/bootstrap.bundle.min.js"></script>
29
+ <% if(enableRecaptcha && publicKey) { %><script src="https://www.google.com/recaptcha/api.js?hl=<%= locale %>" async defer></script><% } %>
30
+ <title>SnakeIA Server</title>
31
+ </head>
32
+ <body class="text-center">
33
+ <div class="container">
34
+ <div class="row">
35
+ <div class="col">
36
+ <p><img class="logo" src="/img/logo.png" alt="SnakeIA Server" /></p>
37
+ <h3><%= __("adminTitle") %></h3>
38
+ <% if(authent && games) { %>
39
+ <ul class="nav nav-tabs" role="tablist">
40
+ <li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#roomList"><%= __("roomList") %></a></li>
41
+ <li class="nav-item"><a class="nav-link" data-toggle="tab" href="#banList"><%= __("banList") %></a></li>
42
+ <li class="nav-item"><a class="nav-link" data-toggle="tab" href="#manualBan"><%= __("manualBan") %></a></li>
43
+ <li class="nav-item"><a class="nav-link" data-toggle="tab" href="#logs"><%= __("logs") %></a></li>
44
+ <% if(role === "administrator") { %><li class="nav-item"><a class="nav-link" data-toggle="tab" href="#config"><%= __("config") %></a></li><% } %>
45
+ </ul>
46
+ <div class="tab-content">
47
+ <div class="tab-pane fade show active" id="roomList" role="tabpanel">
48
+ <%
49
+ const gamesKeys = Object.keys(games);
50
+ let currentRoom = 1;
51
+
52
+ gamesKeys.forEach(key => {
53
+ if(games[key]) { %>
54
+ <div class="accordion" id="accordion">
55
+ <div class="card">
56
+ <div class="card-header" id="heading<%= currentRoom %>">
57
+ <button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapse<%= currentRoom %>" aria-expanded="true" aria-controls="collapse<%= currentRoom %>">
58
+ <%= __("roomAdmin", currentRoom, key) %>
59
+ </button>
60
+ </div>
61
+ <div id="collapse<%= currentRoom %>" class="collapse" aria-labelledby="heading<%= currentRoom %>" data-parent="#accordion">
62
+ <div class="card-body">
63
+ <%
64
+ const users = [];
65
+ games[key].players.forEach(player => users.push(player));
66
+ games[key].spectators.forEach(player => users.push(player));
67
+ %>
68
+ <ul class="list-group">
69
+ <% users.forEach(user => { %>
70
+ <li class="list-group-item">
71
+ <strong><%= __("usernameAdmin") %></strong> <%= user.username %><br />
72
+ <strong><%= __("idSocket") %></strong> <%= user.id %><br />
73
+ <strong><%= __("ip") %></strong> <%= user.id && io.of("/").sockets.get(user.id) && getIPSocketIO(io.of("/").sockets.get(user.id).handshake) %><br />
74
+ <strong><%= __("clientVersion") %></strong> <%= user.version %><br />
75
+ <a href="#" data-action="kick" data-form="socket=<%= user.id %>&token=<%= user.token %>" class="btn btn-primary"><%= __("kick") %></a>
76
+ <a href="#" data-action="banIP" data-form="socket=<%= user.id %>&token=<%= user.token %>" class="btn btn-primary"><%= __("banIP") %></a>
77
+ <a href="#" data-action="banUserName" data-form="socket=<%= user.id %>&token=<%= user.token %>" class="btn btn-primary"><%= __("banUsername") %></a>
78
+ <a href="#" data-action="banIPUserName" data-form="socket=<%= user.id %>&token=<%= user.token %>" class="btn btn-primary"><%= __("banUsernameIP") %></a>
79
+ </li>
80
+ <% }); %>
81
+ </ul>
82
+ </div>
83
+ </div>
84
+ </div>
85
+ </div>
86
+ <% currentRoom++;
87
+ } %>
88
+ <% });
89
+ if(currentRoom <= 1) { %>
90
+ <strong><%= __("noRoomFound"); %></strong>
91
+ <% } %>
92
+ </div>
93
+ <div class="tab-pane fade" id="banList" role="tabpanel">
94
+ <form method="POST" action="/admin/unbanUsername">
95
+ <div class="form-group row">
96
+ <label for="usernamesBanned" class="col-sm-4 col-form-label"><%= __("bannedUsernames") %></label>
97
+ <div class="input-group col-sm-6">
98
+ <% if(config && config.usernameBan && config.usernameBan.length > 0) { %>
99
+ <input type="hidden" name="_csrf" value="<%= csrfToken %>" />
100
+ <select class="form-control" id="usernamesBanned" name="value">
101
+ <% config.usernameBan.forEach(username => { %>
102
+ <option value="<%= username %>"><%= username %></option>
103
+ <% }); %>
104
+ </select>
105
+ <input type="submit" class="btn btn-primary mb-2" value="<%= __("unban") %>" />
106
+ <% } else { %>
107
+ <strong><%= __("noElement") %></strong>
108
+ <% } %>
109
+ </div>
110
+ </div>
111
+ </form>
112
+ <form method="POST" action="/admin/unbanIP">
113
+ <div class="form-group row">
114
+ <label for="ipsBanned" class="col-sm-4 col-form-label"><%= __("ipsBanned") %></label>
115
+ <div class="input-group col-sm-6">
116
+ <% if(config && config.ipBan && config.ipBan.length > 0) { %>
117
+ <input type="hidden" name="_csrf" value="<%= csrfToken %>" />
118
+ <select class="form-control" id="ipsBanned" name="value">
119
+ <% config.ipBan.forEach(ip => { %>
120
+ <option value="<%= ip %>"><%= ip %></option>
121
+ <% }); %>
122
+ </select>
123
+ <input type="submit" class="btn btn-primary mb-2" value="<%= __("unban") %>" />
124
+ </form>
125
+ <% } else { %>
126
+ <strong><%= __("noElement") %></strong>
127
+ <% } %>
128
+ </div>
129
+ </div>
130
+ </form>
131
+ </div>
132
+ <div class="tab-pane fade" id="manualBan" role="tabpanel">
133
+ <form method="POST" action="/admin/banUserName">
134
+ <div class="form-group row">
135
+ <label for="usernameToBan" class="col-sm-4 col-form-label"><%= __("usernameTwo") %></label>
136
+ <div class="input-group col-sm-6">
137
+ <input type="hidden" name="_csrf" value="<%= csrfToken %>" />
138
+ <input class="form-control" type="text" id="usernameToBan" name="value" />
139
+ <input type="submit" class="btn btn-primary mb-2" value="<%= __("ban") %>" />
140
+ </div>
141
+ </div>
142
+ </form>
143
+ <form method="POST" action="/admin/banIP">
144
+ <div class="form-group row">
145
+ <label for="ipToBan" class="col-sm-4 col-form-label"><%= __("ip") %></label>
146
+ <div class="input-group col-sm-6">
147
+ <input type="hidden" name="_csrf" value="<%= csrfToken %>" />
148
+ <input class="form-control" type="text" id="ipToBan" name="value" />
149
+ <input type="submit" class="btn btn-primary mb-2" value="<%= __("ban") %>" />
150
+ </div>
151
+ </div>
152
+ </form>
153
+ </div>
154
+ <div class="tab-pane fade" id="logs" role="tabpanel">
155
+ <div class="accordion" id="accordionLogs">
156
+ <div class="card">
157
+ <div class="card-header" id="headingLogFile">
158
+ <button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseLogFile" aria-expanded="true" aria-controls="collapseLogFile">
159
+ <%= __("generalLogFile") %>
160
+ </button>
161
+ </div>
162
+ <div id="collapseLogFile" class="collapse" aria-labelledby="headingLogFile" data-parent="#accordionLogs">
163
+ <div class="card-body">
164
+ <% if(serverLog && serverLog.trim() != "") { %>
165
+ <pre class="pre-scrollable text-left mb-0"><%= serverLog %></pre>
166
+ <button data-action="resetLog" data-confirm-action="true" class="btn btn-block btn-danger <% if(role !== "administrator") { %>disabled<% } %>" <% if(role !== "administrator") { %>disabled="true"<% } %>><span class="fui-trash mr-2"></span> <%= __("reset") %></button>
167
+ <% } else { %>
168
+ <%= __("fileEmpty") %>
169
+ <% } %>
170
+ </div>
171
+ </div>
172
+ </div>
173
+ <div class="card">
174
+ <div class="card-header" id="headingErrorLogFile">
175
+ <button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseErrorLogFile" aria-expanded="true" aria-controls="collapseErrorLogFile">
176
+ <%= __("errorLogFile") %>
177
+ </button>
178
+ </div>
179
+ <div id="collapseErrorLogFile" class="collapse" aria-labelledby="headingErrorLogFile" data-parent="#accordionLogs">
180
+ <div class="card-body">
181
+ <% if(errorLog && errorLog.trim() != "") { %>
182
+ <pre class="pre-scrollable text-left mb-0"><%= errorLog %></pre>
183
+ <button data-action="resetErrorLog" data-confirm-action="true" class="btn btn-block btn-danger <% if(role !== "administrator") { %>disabled<% } %>" <% if(role !== "administrator") { %>disabled="true"<% } %>><span class="fui-trash mr-2"></span> <%= __("reset") %></button>
184
+ <% } else { %>
185
+ <%= __("fileEmpty") %>
186
+ <% } %>
187
+ </div>
188
+ </div>
189
+ </div>
190
+ </div>
191
+ </div>
192
+ <% if(role === "administrator") { %>
193
+ <div class="tab-pane fade" id="config" role="tabpanel">
194
+ <form method="POST" action="/admin/updateConfig">
195
+ <% if(config) { %>
196
+ <input type="hidden" name="_csrf" value="<%= csrfToken %>" />
197
+ <textarea name="value" spellcheck="false" class="form-control" rows="20"><%= JSON.stringify(config, null, 4) %></textarea>
198
+ <div class="form-group row">
199
+ <div class="btn-group col">
200
+ <button type="reset" class="btn btn-danger"><span class="fui-cross mr-2"></span> <%= __("reset") %></button>
201
+ <button type="submit" class="btn btn-primary"><span class="fui-check mr-2"></span> <%= __("submit") %></button>
202
+ </div>
203
+ </div>
204
+ <% } %>
205
+ </form>
206
+ </div>
207
+ <% } %>
208
+ </div>
209
+ <p><%= __("loggedInAs") %> <strong><%= username %></strong> – <%= __("role") %> <strong><%= __(role) %></strong></p>
210
+ <p><a href="#" data-action="disconnect" class="btn btn-lg btn-danger"><span class="fui-power mr-2"></span> <%= __("disconnectAdmin") %></a></p>
211
+ <% } else { %>
212
+ <form action="" method="post">
213
+ <fieldset class="form-group">
214
+ <div class="form-group row">
215
+ <label for="username" class="col-12 col-form-label"><%= __("usernameAdmin") %></label>
216
+ <div class="col-12">
217
+ <input type="text" id="username" name="username" class="form-control">
218
+ </div>
219
+ </div>
220
+ <div class="form-group row">
221
+ <label for="password" class="col-12 col-form-label"><%= __("passwordAdmin") %></label>
222
+ <div class="col-12">
223
+ <input type="password" id="password" name="password" class="form-control">
224
+ </div>
225
+ </div>
226
+ <% if(enableRecaptcha && publicKey) { %>
227
+ <div class="form-group row">
228
+ <div class="col-12">
229
+ <div class="g-recaptcha" data-sitekey="<%= publicKey %>"></div>
230
+ <% if(errorRecaptcha) { %><div class="text-danger"><span class="fui-cross-circle mr-1"></span> <%= __("errorRecaptcha") %></div><% } %>
231
+ </div>
232
+ </div>
233
+ <% } %>
234
+ <% if(errorAuthent) { %>
235
+ <div class="form-group row">
236
+ <div class="col-12">
237
+ <div class="text-danger"><span class="fui-cross-circle mr-1"></span> <%= __("errorAuthentAdmin") %></div>
238
+ </div>
239
+ </div>
240
+ <% } %>
241
+ <div class="form-group row">
242
+ <div class="col-12">
243
+ <button type="submit" name="submit" class="btn btn-lg btn-primary"><span class="fui-check mr-2"></span> <%= __("submit") %></button>
244
+ </div>
245
+ </div>
246
+ </fieldset>
247
+ </form>
248
+ <% } %>
249
+ </div>
250
+ </div>
251
+ </div>
252
+ <% if(authent && games) { %>
253
+ <script type="text/javascript">
254
+ var token = document.querySelector("meta[name='csrf-token']").getAttribute("content");
255
+
256
+ function requestAction(action, data, element) {
257
+ fetch("/admin/" + action, {
258
+ credentials: "same-origin",
259
+ headers: {
260
+ "CSRF-Token": token,
261
+ "Content-Type": "application/json",
262
+ },
263
+ method: "POST",
264
+ body: JSON.stringify(data),
265
+ redirect: "follow"
266
+ }).then((response) => {
267
+ if(response.ok && response.redirected) {
268
+ location.href = response.url;
269
+ }
270
+ }).catch(() => {
271
+ element.classList.remove("disabled");
272
+ element.disabled = false;
273
+ });
274
+ }
275
+
276
+ var elements = document.querySelectorAll("[data-action]");
277
+
278
+ elements.forEach(function(element) {
279
+ var action = element.dataset.action;
280
+ var form = element.dataset.form;
281
+ var data = {};
282
+ var confirmAction = element.dataset.confirmAction;
283
+
284
+ if(form) {
285
+ form.split("&").forEach(function(element) {
286
+ if(element) {
287
+ var key = element.split("=")[0];
288
+ var value = element.split("=")[1];
289
+ data[key] = value;
290
+ }
291
+ });
292
+ }
293
+
294
+ element.addEventListener("click", function() {
295
+ if((confirmAction && confirm("<%= __("actionConfirmAdmin") %>")) || !confirmAction) {
296
+ element.classList.add("disabled");
297
+ element.disabled = true;
298
+ requestAction(action, data);
299
+ }
300
+ });
301
+ });
302
+ </script>
303
+ <% } %>
304
+ </body>
305
+ </html>
@@ -0,0 +1,78 @@
1
+ <!--
2
+ * Copyright (C) 2020 Eliastik (eliastiksofts.com)
3
+ *
4
+ * This file is part of "SnakeIA Server".
5
+ *
6
+ * "SnakeIA Server" is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * "SnakeIA Server" is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with "SnakeIA Server". If not, see <http://www.gnu.org/licenses/>. -->
18
+ <!doctype HTML>
19
+ <html>
20
+ <head>
21
+ <meta charset="UTF-8"></meta>
22
+ <meta name="viewport" content="width=device-width, initial-scale=1">
23
+ <link href="/css/bootstrap.min.css" rel="stylesheet">
24
+ <link href="/css/flat-ui.min.css" rel="stylesheet">
25
+ <link href="/css/main.css" rel="stylesheet">
26
+ <% if(enableRecaptcha && publicKey) { %><script src="https://www.google.com/recaptcha/api.js?hl=<%= locale %>" async defer></script><% } %>
27
+ <title>SnakeIA Server</title>
28
+ </head>
29
+ <body class="text-center remove-padding">
30
+ <div class="container">
31
+ <% if(authent) { %>
32
+ <h3><%= __("alreadyAuthentified") %></h3>
33
+ <% } else if(!success) { %>
34
+ <form action="" method="post">
35
+ <fieldset class="form-group">
36
+ <div class="form-group row">
37
+ <label for="username" class="col-12 col-form-label"><%= __("username", __n("characters", max), min) %></label>
38
+ <div class="col-12">
39
+ <input type="text" id="username" name="username" class="form-control<% if(errorUsername || errorUsernameBanned || errorUsernameAlreadyInUse) { %> is-invalid <% } %>" maxlength="<%= max %>">
40
+ <% if(errorUsername) { %><div class="text-danger"><span class="fui-cross-circle mr-1"></span> <%= __("errorUsername") %></div><% } %>
41
+ <% if(errorUsernameBanned) { %><div class="text-danger"><span class="fui-cross-circle mr-1"></span> <%= __("errorUsernameBanned") %></div><% } %>
42
+ <% if(errorUsernameAlreadyInUse) { %><div class="text-danger"><span class="fui-cross-circle mr-1"></span> <%= __("errorUsernameAlreadyInUse") %></div><% } %>
43
+ </div>
44
+ </div>
45
+ <% if(enableRecaptcha && publicKey) { %>
46
+ <div class="form-group row">
47
+ <div class="col-12">
48
+ <div class="g-recaptcha" data-sitekey="<%= publicKey %>"></div>
49
+ <% if(errorRecaptcha) { %><div class="text-danger"><span class="fui-cross-circle mr-1"></span> <%= __("errorRecaptcha") %></div><% } %>
50
+ </div>
51
+ </div>
52
+ <% } %>
53
+ <div class="form-group row">
54
+ <div class="col-12">
55
+ <button type="submit" name="submit" class="btn btn-lg btn-primary"><span class="fui-check mr-2"></span> <%= __("submit") %></button>
56
+ </div>
57
+ </div>
58
+ <% if(enableMaxTimeGame) { %>
59
+ <div class="form-group row">
60
+ <div class="col-12 small">
61
+ <% if((maxTimeGame / 1000 % 60) < 1) { %>
62
+ <%= __("maxTimeGame", __n("minutes", (maxTimeGame / 1000 / 60))) %>
63
+ <% } else if((maxTimeGame / 1000 / 60) < 1) { %>
64
+ <%= __("maxTimeGame", __n("seconds", (maxTimeGame / 1000 % 60))) %>
65
+ <% } else { %>
66
+ <%= __("maxTimeGameTwo", __n("minutes", (maxTimeGame / 1000 / 60)), __n("seconds", (maxTimeGame / 1000 % 60))) %>
67
+ <% } %>
68
+ </div>
69
+ </div>
70
+ <% } %>
71
+ </fieldset>
72
+ </form>
73
+ <% } else { %>
74
+ <h3><%= __("successAuthentification") %></h3>
75
+ <% } %>
76
+ </div>
77
+ </body>
78
+ </html>
@@ -0,0 +1,38 @@
1
+ <!--
2
+ * Copyright (C) 2020 Eliastik (eliastiksofts.com)
3
+ *
4
+ * This file is part of "SnakeIA Server".
5
+ *
6
+ * "SnakeIA Server" is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * "SnakeIA Server" is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with "SnakeIA Server". If not, see <http://www.gnu.org/licenses/>. -->
18
+ <!doctype HTML>
19
+ <html>
20
+ <head>
21
+ <meta charset="UTF-8"></meta>
22
+ <meta name="viewport" content="width=device-width, initial-scale=1">
23
+ <link href="/css/bootstrap.min.css" rel="stylesheet">
24
+ <link href="/css/flat-ui.min.css" rel="stylesheet">
25
+ <link href="/css/main.css" rel="stylesheet">
26
+ <title>SnakeIA Server</title>
27
+ </head>
28
+ <body class="text-center">
29
+ <div class="container">
30
+ <div class="row">
31
+ <div class="col">
32
+ <h2><%= __("banned") %></h2>
33
+ <% if(contact.trim() != "") { %><p><a href="<%= contact %>" target="_blank"><%= __("bannedContact") %></a></p><% } %>
34
+ </div>
35
+ </div>
36
+ </div>
37
+ </body>
38
+ </html>
@@ -0,0 +1,41 @@
1
+ <!--
2
+ * Copyright (C) 2020 Eliastik (eliastiksofts.com)
3
+ *
4
+ * This file is part of "SnakeIA Server".
5
+ *
6
+ * "SnakeIA Server" is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * "SnakeIA Server" is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with "SnakeIA Server". If not, see <http://www.gnu.org/licenses/>. -->
18
+ <!doctype HTML>
19
+ <html>
20
+ <head>
21
+ <meta charset="UTF-8"></meta>
22
+ <meta name="viewport" content="width=device-width, initial-scale=1">
23
+ <link href="/css/bootstrap.min.css" rel="stylesheet">
24
+ <link href="/css/flat-ui.min.css" rel="stylesheet">
25
+ <link href="/css/main.css" rel="stylesheet">
26
+ <script src="https://www.google.com/recaptcha/api.js" async defer></script>
27
+ <title>SnakeIA Server</title>
28
+ </head>
29
+ <body class="text-center">
30
+ <div class="container">
31
+ <div class="row">
32
+ <div class="col">
33
+ <p><img class="logo" src="/img/logo.png" alt="SnakeIA Server" /></p>
34
+ <h2><%= __("version") %> <%= version %></h2>
35
+ <h3><%= __("engineVersion") %> <%= engineVersion %></h3>
36
+ <p class="lead"><%= __("githubRepos") %> <a href="https://github.com/Eliastik/snakeia-server/"><%= __("server") %></a> / <a href="https://github.com/Eliastik/snakeia/"><%= __("engine") %></a></p>
37
+ </div>
38
+ </div>
39
+ </div>
40
+ </body>
41
+ </html>