forked from openNAMU/openNAMU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.py
453 lines (381 loc) · 13.9 KB
/
func.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
from bottle import request, app, template
from bottle.ext import beaker
import json
import sqlite3
from css_html_js_minify import html_minify
json_data = open('set.json').read()
set_data = json.loads(json_data)
conn = sqlite3.connect(set_data['db'] + '.db')
curs = conn.cursor()
session_opts = {
'session.type': 'dbm',
'session.data_dir': './app_session/',
'session.auto': 1
}
app = beaker.middleware.SessionMiddleware(app(), session_opts)
from mark import *
def other2(d):
g = ''
session = request.environ.get('beaker.session')
if(session.get('View_List')):
m = re.findall('(?:(?:([^\n]+)\n))', session.get('View_List'))
if(m):
g = ''
for z in m[-6:-1]:
g += '<a href="/w/' + url_pas(z) + '">' + html.escape(z) + '</a> / '
g = re.sub(' / $', '', g)
r = d + [g]
return(r)
def wiki_set(num):
if(num == 1):
r = []
curs.execute('select data from other where name = ?', ['name'])
d = curs.fetchall()
if(d):
r += [d[0][0]]
else:
r += ['무명위키']
curs.execute('select data from other where name = "license"')
d = curs.fetchall()
if(d):
r += [d[0][0]]
else:
r += ['CC 0']
curs.execute("select data from other where name = 'css'")
d = curs.fetchall()
if(d):
r += [d[0][0]]
else:
r += ['']
curs.execute("select data from other where name = 'js'")
d = curs.fetchall()
if(d):
r += [d[0][0]]
else:
r += ['']
curs.execute('select data from other where name = "logo"')
d = curs.fetchall()
if(d):
r += [d[0][0]]
else:
r += [r[0]]
return(r)
if(num == 2):
d = '위키:대문'
curs.execute('select data from other where name = "frontpage"')
elif(num == 3):
d = '2'
curs.execute('select data from other where name = "upload"')
r = curs.fetchall()
if(r):
return(r[0][0])
else:
return(d)
def diff(seqm, num):
output= []
for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
if(opcode == 'equal' and num == 1):
output.append(seqm.a[a0:a1])
elif(opcode == 'insert' and num == 0):
output.append("<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>")
elif(opcode == 'delete' and num == 1):
output.append("<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>")
elif(opcode == 'replace'):
if(num == 1):
output.append("<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>")
else:
output.append("<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>")
elif(num == 0):
output.append(seqm.b[b0:b1])
return(''.join(output))
def admin_check(num, what):
ip = ip_check()
curs.execute("select acl from user where id = ?", [ip])
user = curs.fetchall()
if(user):
reset = 0
while(1):
if(num == 1 and reset == 0):
check = 'ban'
elif(num == 2 and reset == 0):
check = 'mdel'
elif(num == 3 and reset == 0):
check = 'toron'
elif(num == 4 and reset == 0):
check = 'check'
elif(num == 5 and reset == 0):
check = 'acl'
elif(num == 6 and reset == 0):
check = 'hidel'
else:
check = 'owner'
curs.execute('select name from alist where name = ? and acl = ?', [user[0][0], check])
acl_data = curs.fetchall()
if(acl_data):
if(what):
curs.execute("insert into re_admin (who, what, time) values (?, ?, ?)", [ip, what, get_time()])
conn.commit()
return(1)
else:
if(reset == 0):
reset = 1
else:
break
def ip_pas(raw_ip):
if(re.search("(\.|:)", raw_ip)):
ip = raw_ip
else:
curs.execute("select title from data where title = ?", ['사용자:' + raw_ip])
if(curs.fetchall()):
ip = '<a href="/w/' + url_pas('사용자:' + raw_ip) + '">' + raw_ip + '</a>'
else:
ip = '<a class="not_thing" href="/w/' + url_pas('사용자:' + raw_ip) + '">' + raw_ip + '</a>'
ip += ' <a href="/record/' + url_pas(raw_ip) + '">(기록)</a>'
return(ip)
def custom():
session = request.environ.get('beaker.session')
try:
d1 = format(session['Daydream'])
except:
d1 = ''
try:
d2 = format(session['AQUARIUM'])
except:
d2 = ''
if(session.get('Now') == 1):
curs.execute('select name from alarm limit 1')
if(curs.fetchall()):
d3 = 2
else:
d3 = 1
else:
d3 = 0
return([d1, d2, d3])
def acl_check(name):
ip = ip_check()
band = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
if(band):
band_it = band.groups()
else:
band_it = ['Not']
curs.execute("select block from ban where block = ? and band = 'O'", [band_it[0]])
band_d = curs.fetchall()
curs.execute("select block from ban where block = ?", [ip])
ban_d = curs.fetchall()
if(band_d or ban_d):
return(1)
acl_c = re.search("^사용자:([^/]*)", name)
if(acl_c):
acl_n = acl_c.groups()
if(admin_check(5, None) == 1):
return(0)
curs.execute("select acl from data where title = ?", ['사용자:' + acl_n[0]])
acl_d = curs.fetchall()
if(acl_d):
if(acl_d[0][0] == 'all'):
return(0)
if(acl_d[0][0] == 'user' and not re.search("(\.|:)", ip)):
return(0)
if(not ip == acl_n[0] or re.search("(\.|:)", ip)):
return(1)
if(ip == acl_n[0] and not re.search("(\.|:)", ip) and not re.search("(\.|:)", acl_n[0])):
return(0)
else:
return(1)
file_c = re.search("^파일:(.*)", name)
if(file_c and admin_check(5, 'edit (' + name + ')') != 1):
return(1)
curs.execute("select acl from data where title = ?", [name])
acl_d = curs.fetchall()
if(not acl_d):
return(0)
curs.execute("select acl from user where id = ?", [ip])
user_d = curs.fetchall()
curs.execute('select data from other where name = "edit"')
set_d = curs.fetchall()
if(acl_d[0][0] == 'user'):
if(not user_d):
return(1)
if(acl_d[0][0] == 'admin'):
if(not user_d):
return(1)
if(not admin_check(5, 'edit (' + name + ')') == 1):
return(1)
if(set_d):
if(set_d[0][0] == 'user'):
if(not user_d):
return(1)
if(set_d[0][0] == 'admin'):
if(not user_d):
return(1)
if(not admin_check(5, None) == 1):
return(1)
return(0)
def ban_check():
ip = ip_check()
band = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
if(band):
band_it = band.groups()
else:
band_it = ['Not']
curs.execute("select block from ban where block = ? and band = 'O'", [band_it[0]])
band_d = curs.fetchall()
curs.execute("select block from ban where block = ?", [ip])
ban_d = curs.fetchall()
if(band_d or ban_d):
return(1)
return(0)
def topic_check(name, sub):
ip = ip_check()
band = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
if(band):
band_it = band.groups()
else:
band_it = ['Not']
curs.execute("select block from ban where block = ? and band = 'O'", [band_it[0]])
band_d = curs.fetchall()
curs.execute("select block from ban where block = ?", [ip])
ban_d = curs.fetchall()
if(band_d or ban_d):
return(1)
curs.execute("select title from stop where title = ? and sub = ?", [name, sub])
topic_s = curs.fetchall()
if(topic_s):
return(1)
return(0)
def rd_plus(title, sub, date):
curs.execute("select title from rd where title = ? and sub = ?", [title, sub])
if(curs.fetchall()):
curs.execute("update rd set date = ? where title = ? and sub = ?", [date, title, sub])
else:
curs.execute("insert into rd (title, sub, date) values (?, ?, ?)", [title, sub, date])
def rb_plus(block, end, today, blocker, why):
curs.execute("insert into rb (block, end, today, blocker, why) values (?, ?, ?, ?, ?)", [block, end, today, blocker, why])
def history_plus(title, data, date, ip, send, leng):
curs.execute("select id from history where title = ? order by id+0 desc limit 1", [title])
d = curs.fetchall()
if(d):
curs.execute("insert into history (id, title, data, date, ip, send, leng) values (?, ?, ?, ?, ?, ?, ?)", [str(int(d[0][0]) + 1), title, data, date, ip, send, leng])
else:
curs.execute("insert into history (id, title, data, date, ip, send, leng) values ('1', ?, ?, ?, ?, ?, ?)", [title, data, date, ip, send + ' (새 문서)', leng])
def leng_check(a, b):
if(a < b):
c = b - a
c = '+' + str(c)
elif(b < a):
c = a - b
c = '-' + str(c)
else:
c = '0'
return(c)
def redirect(data):
return('<meta http-equiv="refresh" content="0;url=' + data + '" />')
def re_error(data):
if(data == '/ban'):
ip = ip_check()
end = '권한이 맞지 않는 상태 입니다.'
if(ban_check() == 1):
curs.execute("select end, why from ban where block = ?", [ip])
d = curs.fetchall()
if(not d):
m = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
if(m):
curs.execute("select end, why from ban where block = ? and band = 'O'", [m.groups()[0]])
d = curs.fetchall()
if(d):
if(d[0][0]):
end = d[0][0] + ' 까지 차단 상태 입니다. / 사유 : ' + d[0][1]
now = re.sub(':', '', get_time())
now = re.sub('\-', '', now)
now = int(re.sub(' ', '', now))
day = re.sub('\-', '', d[0][0])
if(now >= int(day + '000000')):
curs.execute("delete from ban where block = ?", [ip])
conn.commit()
end = '차단이 풀렸습니다. 다시 시도 해 보세요.'
else:
end = '영구 차단 상태 입니다. / 사유 : ' + d[0][1]
return(
html_minify(
template('index',
imp = ['권한 오류', wiki_set(1), custom(), other2([0, 0])],
data = end,
menu = 0
)
)
)
d = re.search('\/error\/([0-9]+)', data)
if(d):
num = int(d.groups()[0])
if(num == 1):
title = '권한 오류'
data = '비 로그인 상태 입니다.'
elif(num == 2):
title = '권한 오류'
data = '이 계정이 없습니다.'
elif(num == 3):
title = '권한 오류'
data = '권한이 모자랍니다.'
elif(num == 4):
title = '권한 오류'
data = '관리자는 차단, 검사 할 수 없습니다.'
elif(num == 5):
title = '사용자 오류'
data = '그런 계정이 없습니다.'
elif(num == 6):
title = '가입 오류'
data = '동일한 아이디의 사용자가 있습니다.'
elif(num == 7):
title = '가입 오류'
data = '아이디는 20글자보다 짧아야 합니다.'
elif(num == 8):
title = '가입 오류'
data = '아이디에는 한글과 알파벳과 공백만 허용 됩니다.'
elif(num == 9):
title = '파일 올리기 오류'
data = '파일이 없습니다.'
elif(num == 10):
title = '변경 오류'
data = '비밀번호가 다릅니다.'
elif(num == 11):
title = '로그인 오류'
data = '이미 로그인 되어 있습니다.'
elif(num == 12):
title = '편집 오류'
data = '누군가 먼저 편집 했습니다.'
elif(num == 14):
title = '파일 올리기 오류'
data = 'jpg, gif, jpeg, png, webp만 가능 합니다.'
elif(num == 15):
title = '편집 오류'
data = '편집 기록은 500자를 넘을 수 없습니다.'
elif(num == 16):
title = '파일 올리기 오류'
data = '동일한 이름의 파일이 있습니다.'
elif(num == 17):
title = '파일 올리기 오류'
data = '파일 용량은 ' + wiki_set(3) + 'MB를 넘길 수 없습니다.'
elif(num == 18):
title = '편집 오류'
data = '내용이 원래 문서와 동일 합니다.'
elif(num == 19):
title = '이동 오류'
data = '이동 하려는 곳에 문서가 이미 있습니다.'
elif(num == 20):
title = '비밀번호 오류'
data = '재 확인이랑 비밀번호가 다릅니다.'
if(title):
return(
html_minify(
template(
'index',
imp = [title, wiki_set(1), custom(), other2([0, 0])],
data = data,
menu = 0
)
)
)
else:
return(redirect('/'))
else:
return(redirect('/'))