Skip to content

Commit 4843fe2

Browse files
author
KirillMysnik
committed
Finished "Review Ban" MoTD interface
1 parent e97deef commit 4843fe2

File tree

6 files changed

+551
-22
lines changed

6 files changed

+551
-22
lines changed

flask-motd/motdplayer_applications/admin/included/admin_kick_ban/__init__.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
# >> CONSTANTS
1212
# =============================================================================
1313
MAX_BAN_ID_ABS_VALUE = 3000000000
14+
MAX_REASON_LENGTH = 255
15+
MAX_BAN_DURATION = 315360000 # 10 years. For a permanent ban use -1
16+
MIN_BAN_DURATION = -1
1417

1518

1619
# =============================================================================
@@ -25,6 +28,10 @@
2528
'included', 'admin_kick_ban', 'lift_steamid')
2629
lift_ip_address_page = WebRequestProcessor(
2730
'included', 'admin_kick_ban', 'lift_ip_address')
31+
review_steamid_page = WebRequestProcessor(
32+
'included', 'admin_kick_ban', 'review_steamid')
33+
review_ip_address_page = WebRequestProcessor(
34+
'included', 'admin_kick_ban', 'review_ip_address')
2835

2936

3037
# =============================================================================
@@ -153,3 +160,116 @@ def callback(data):
153160
return {
154161
'action': "get-bans",
155162
}
163+
164+
165+
# review_steamid_page
166+
@review_steamid_page.register_regular_callback
167+
def callback(ex_data_func):
168+
return "admin/included/admin_kick_ban/review_steamid.html", dict()
169+
170+
171+
# review_ip_address_page
172+
@review_ip_address_page.register_regular_callback
173+
def callback(ex_data_func):
174+
return "admin/included/admin_kick_ban/review_ip_address.html", dict()
175+
176+
177+
# review_steamid_page/review_ip_address_page
178+
@review_steamid_page.register_ajax_callback
179+
@review_ip_address_page.register_ajax_callback
180+
def callback(ex_data_func, data):
181+
if 'action' not in data:
182+
return
183+
184+
if data['action'] == "execute":
185+
try:
186+
ban_id = data['banId']
187+
duration = data['duration']
188+
reason = data['reason']
189+
except KeyError:
190+
return
191+
192+
# Ban ID checks
193+
if not isinstance(ban_id, int):
194+
return
195+
196+
if not (-MAX_BAN_ID_ABS_VALUE <= ban_id <= MAX_BAN_ID_ABS_VALUE):
197+
return
198+
199+
# Duration checks
200+
if not isinstance(duration, int):
201+
return
202+
203+
if not (MIN_BAN_DURATION <= duration <= MAX_BAN_DURATION):
204+
return
205+
206+
# Reason checks
207+
if not isinstance(reason, str):
208+
return
209+
210+
reason = reason.strip()
211+
212+
if not (0 < len(reason.encode('utf-8')) <= MAX_REASON_LENGTH):
213+
return
214+
215+
return ex_data_func({
216+
'action': "execute",
217+
'banId': ban_id,
218+
'duration': duration,
219+
'reason': reason,
220+
})
221+
222+
if data['action'] == "get-ban-data":
223+
return ex_data_func({
224+
'action': "get-ban-data",
225+
})
226+
227+
228+
@review_steamid_page.register_ws_callback
229+
@review_ip_address_page.register_ws_callback
230+
def callback(data):
231+
if 'action' not in data:
232+
return
233+
234+
if data['action'] == "execute":
235+
try:
236+
ban_id = data['banId']
237+
duration = data['duration']
238+
reason = data['reason']
239+
except KeyError:
240+
return
241+
242+
# Ban ID checks
243+
if not isinstance(ban_id, int):
244+
return
245+
246+
if not (-MAX_BAN_ID_ABS_VALUE <= ban_id <= MAX_BAN_ID_ABS_VALUE):
247+
return
248+
249+
# Duration checks
250+
if not isinstance(duration, int):
251+
return
252+
253+
if not (MIN_BAN_DURATION <= duration <= MAX_BAN_DURATION):
254+
return
255+
256+
# Reason checks
257+
if not isinstance(reason, str):
258+
return
259+
260+
reason = reason.strip()
261+
262+
if not (0 < len(reason.encode('utf-8')) <= MAX_REASON_LENGTH):
263+
return
264+
265+
return {
266+
'action': "execute",
267+
'banId': ban_id,
268+
'duration': duration,
269+
'reason': reason,
270+
}
271+
272+
if data['action'] == "get-ban-data":
273+
return {
274+
'action': "get-ban-data",
275+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
@keyframes ban-table-row-remove {
2+
0% {
3+
height: 30px;
4+
color: #ffffff;
5+
}
6+
100% {
7+
height: 0;
8+
color: #252525;
9+
}
10+
}
11+
12+
@keyframes ban-table-row-add {
13+
0% {
14+
height: 0;
15+
background-color: #ffffff;
16+
}
17+
100% {
18+
height: 30px;
19+
background-color: transparent;
20+
}
21+
}
22+
23+
.ban-table {
24+
width: 80%;
25+
margin: 20px auto 80px auto;
26+
border: 2px solid rgba(255, 255, 255, .1);
27+
}
28+
29+
.ban-table-line {
30+
height: 30px;
31+
line-height: 30px;
32+
overflow: hidden;
33+
cursor: pointer;
34+
animation-duration: 1s;
35+
}
36+
37+
.ban-table-uniqueid {
38+
float: left;
39+
width: 200px;
40+
text-align: center;
41+
font-family: monospace;
42+
font-size: 9pt;
43+
background-color: rgba(255, 255, 255, .1);
44+
}
45+
46+
.ban-table-line:hover .ban-table-uniqueid {
47+
background-color: rgba(255, 255, 255, .33);
48+
}
49+
50+
.ban-table-name {
51+
overflow: hidden;
52+
text-align: center;
53+
}
54+
55+
.ban-table-line:hover .ban-table-name {
56+
color: #fa000d;
57+
}
58+
59+
.review-ban-wrap {
60+
display: none;
61+
z-index: 11;
62+
position: fixed;
63+
top: 0;
64+
left: 0;
65+
width: 100%;
66+
height: 100%;
67+
background: rgba(255, 255, 255, .75);
68+
}
69+
70+
.review-ban-wrap.visible {
71+
display: block;
72+
}
73+
74+
.review-ban {
75+
position: absolute;
76+
top: 50%;
77+
left: 50%;
78+
width: 600px;
79+
height: 400px;
80+
margin: -200px 0 0 -300px;
81+
box-sizing: border-box;
82+
padding: 5px;
83+
background-color: #333333;
84+
border: 5px solid #252525;
85+
}
86+
87+
.review-ban h2 {
88+
text-align: center;
89+
font-weight: normal;
90+
}
91+
92+
.review-ban h3:before {
93+
content: "• ";
94+
}
95+
96+
.review-inner {
97+
font-size: 10pt;
98+
padding: 5px 30px;
99+
}
100+
101+
.review-player-name, .review-player-uniqueid, .review-ban-id {
102+
padding: 0 15px;
103+
font-family: monospace;
104+
}
105+
106+
.reason-table td {
107+
vertical-align: top;
108+
}
109+
110+
.review-button {
111+
position: absolute;
112+
left: 50%;
113+
bottom: 5px;
114+
width: 150px;
115+
margin-left: -75px;
116+
font-size: 14pt;
117+
}

0 commit comments

Comments
 (0)