forked from openNAMU/openNAMU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
3376 lines (2650 loc) · 142 KB
/
app.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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# 모듈 불러오기
from flask import Flask, request, send_from_directory
from flask_compress import Compress
from flask_reggie import Reggie
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
import platform
import bcrypt
import difflib
import shutil
import threading
import logging
import random
import sys
# 버전 표기
r_ver = 'v3.0.3-Beta-03'
print('Version : ' + r_ver)
# 나머지 불러오기
from func import *
from set_mark.tool import savemark
# set.json 설정 확인
try:
json_data = open('set.json').read()
set_data = json.loads(json_data)
except:
while 1:
print('DB Name : ', end = '')
new_json = str(input())
if new_json != '':
with open("set.json", "w") as f:
f.write('{ "db" : "' + new_json + '" }')
json_data = open('set.json').read()
set_data = json.loads(json_data)
break
else:
print('Insert Values')
pass
# 디비 연결
conn = sqlite3.connect(set_data['db'] + '.db', check_same_thread = False)
curs = conn.cursor()
# 기타 설정 변경
logging.basicConfig(level = logging.ERROR)
app = Flask(__name__, template_folder = './')
Reggie(app)
compress = Compress()
compress.init_app(app)
# 템플릿 설정
def md5_replace(data):
return hashlib.md5(data.encode()).hexdigest()
app.jinja_env.filters['md5_replace'] = md5_replace
# 셋업 부분
curs.execute("create table if not exists data(title text, data text)")
curs.execute("create table if not exists history(id text, title text, data text, date text, ip text, send text, leng text, hide text)")
curs.execute("create table if not exists rd(title text, sub text, date text)")
curs.execute("create table if not exists user(id text, pw text, acl text, date text, email text, skin text)")
curs.execute("create table if not exists ban(block text, end text, why text, band text, login text)")
curs.execute("create table if not exists topic(id text, title text, sub text, data text, date text, ip text, block text, top text)")
curs.execute("create table if not exists stop(title text, sub text, close text)")
curs.execute("create table if not exists rb(block text, end text, today text, blocker text, why text, band text)")
curs.execute("create table if not exists back(title text, link text, type text)")
curs.execute("create table if not exists agreedis(title text, sub text)")
curs.execute("create table if not exists custom(user text, css text)")
curs.execute("create table if not exists other(name text, data text)")
curs.execute("create table if not exists alist(name text, acl text)")
curs.execute("create table if not exists re_admin(who text, what text, time text)")
curs.execute("create table if not exists alarm(name text, data text, date text)")
curs.execute("create table if not exists ua_d(name text, ip text, ua text, today text, sub text)")
curs.execute("create table if not exists filter(name text, regex text, sub text)")
curs.execute("create table if not exists scan(user text, title text)")
curs.execute("create table if not exists acl(title text, dec text, dis text, why text)")
curs.execute("create table if not exists inter(title text, link text)")
# owner 존재 확인
curs.execute("select name from alist where acl = 'owner'")
if not curs.fetchall():
curs.execute("delete from alist where name = 'owner'")
curs.execute("insert into alist (name, acl) values ('owner', 'owner')")
# 포트 점검
curs.execute("select data from other where name = 'port'")
rep_data = curs.fetchall()
if not rep_data:
while 1:
print('Port : ', end = '')
rep_port = int(input())
if rep_port:
curs.execute("insert into other (name, data) values ('port', ?)", [rep_port])
break
else:
pass
else:
rep_port = rep_data[0][0]
print('Port : ' + str(rep_port))
# robots.txt 점검
try:
if not os.path.exists('robots.txt'):
curs.execute("select data from other where name = 'robot'")
robot_test = curs.fetchall()
if robot_test:
fw_test = open('./robots.txt', 'w')
fw_test.write(re.sub('\r\n', '\n', robot_test[0][0]))
fw_test.close()
else:
fw_test = open('./robots.txt', 'w')
fw_test.write('User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/')
fw_test.close()
curs.execute("insert into other (name, data) values ('robot', 'User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/')")
print('robots.txt create')
except:
pass
# 비밀 키 점검
curs.execute("select data from other where name = 'key'")
rep_data = curs.fetchall()
if not rep_data:
while 1:
print('Secret Key : ', end = '')
rep_key = str(input())
if rep_key:
curs.execute("insert into other (name, data) values ('key', ?)", [rep_key])
break
else:
pass
else:
rep_key = rep_data[0][0]
print('Secret Key : ' + rep_key)
# 언어 점검
curs.execute("select data from other where name = 'language'")
rep_data = curs.fetchall()
if not rep_data:
while 1:
print('Language [ko-KR] : ', end = '')
support_language = ['ko-KR']
rep_language = str(input())
if rep_language in support_language:
curs.execute("insert into other (name, data) values ('language', ?)", [rep_language])
break
else:
pass
else:
rep_language = rep_data[0][0]
print('Language : ' + str(rep_language))
json_data = open(os.path.join('language', 'ko-KR.json'), 'rt', encoding='utf-8').read()
lang_data = json.loads(json_data)
# 한번 개행
print('')
# 호환성 설정
try:
curs.execute("alter table history add hide text default ''")
curs.execute('select title, re from hidhi')
for rep in curs.fetchall():
curs.execute("update history set hide = 'O' where title = ? and id = ?", [rep[0], rep[1]])
curs.execute("drop table if exists hidhi")
print('move table hidhi')
except:
pass
try:
curs.execute("alter table user add date text default ''")
print('user table add column date')
except:
pass
try:
curs.execute("alter table rb add band text default ''")
print('rb table add column band')
except:
pass
try:
curs.execute("alter table ban add login text default ''")
print('ban table add column login')
except:
pass
try:
curs.execute("select title, acl from data where acl != ''")
for rep in curs.fetchall():
curs.execute("insert into acl (title, dec, dis, why) values (?, ?, '', '')", [rep[0], rep[1]])
curs.execute("alter table data drop acl")
print('data table delete column acl')
except:
pass
try:
curs.execute("alter table user add email text default ''")
print('user table add column email')
except:
pass
try:
curs.execute('select name, sub from filter where sub != "X" and sub != ""')
filter_name = curs.fetchall()
if filter_name:
for filter_delete in filter_name:
if filter_delete[1] != '' or filter_delete[1] != 'X':
curs.execute("update filter set sub = '' where name = ?", [filter_delete[0]])
print('filter data fix')
except:
pass
try:
curs.execute("alter table user add skin text default ''")
print('user table add column skin')
except:
pass
conn.commit()
# 이미지 폴더 생성
if not os.path.exists('image'):
os.makedirs('image')
# 스킨 폴더 생성
if not os.path.exists('views'):
os.makedirs('views')
# 백업 설정
def back_up():
try:
shutil.copyfile(set_data['db'] + '.db', 'back_' + set_data['db'] + '.db')
print('Back Up Ok')
except:
print('Back Up Error')
threading.Timer(60 * 60 * back_time, back_up).start()
try:
curs.execute('select data from other where name = "back_up"')
back_up_time = curs.fetchall()
back_time = int(back_up_time[0][0])
except:
back_time = 0
# 백업 여부 확인
if back_time != 0:
print(str(back_time) + ' Hours Back Up')
if __name__ == '__main__':
back_up()
else:
print('No Back Up')
@app.route('/del_alarm')
def del_alarm():
curs.execute("delete from alarm where name = ?", [ip_check()])
conn.commit()
return redirect('/alarm')
@app.route('/alarm')
def alarm():
if custom(conn)[2] == 0:
return redirect('/login')
data = '<ul>'
curs.execute("select data, date from alarm where name = ? order by date desc", [ip_check()])
data_list = curs.fetchall()
if data_list:
data = '<a href="/del_alarm">(삭제)</a><hr>' + data
for data_one in data_list:
data += '<li>' + data_one[0] + ' (' + data_one[1] + ')</li>'
else:
data += '<li>알림이 없습니다.</li>'
data += '</ul>'
return html_minify(render_template(skin_check(conn),
imp = ['알림', wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = data,
menu = [['user', '사용자']]
))
@app.route('/inter_wiki')
def inter_wiki():
div = ''
admin = admin_check(conn, None, None)
curs.execute('select title, link from inter')
db_data = curs.fetchall()
if db_data:
div = '<ul>'
for data in db_data:
div += '<li>' + data[0] + ' : ' + data[1]
if admin == 1:
div += ' <a href="/del_inter/' + url_pas(data[0]) + '">(삭제)</a>'
div += '</li>'
div += '</ul>'
if admin == 1:
div += '<hr><a href="/plus_inter">(추가)</a>'
else:
if admin == 1:
div += '<a href="/plus_inter">(추가)</a>'
return html_minify(render_template(skin_check(conn),
imp = ['인터위키 ' + lang_data['list'], wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = div,
menu = [['other', '기타']]
))
@app.route('/del_inter/<name>')
def del_inter(name = None):
if admin_check(conn, None, None) == 1:
curs.execute("delete from inter where title = ?", [name])
conn.commit()
return redirect('/inter_wiki')
else:
return re_error(conn, '/error/3')
@app.route('/plus_inter', methods=['POST', 'GET'])
def plus_inter():
if request.method == 'POST':
curs.execute('insert into inter (title, link) values (?, ?)', [request.form['title'], request.form['link']])
conn.commit()
admin_check(conn, None, 'inter_wiki_plus')
return redirect('/inter_wiki')
else:
return html_minify(render_template(skin_check(conn),
imp = ['인터위키 추가', wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = '<form method="post"><input placeholder="이름" type="text" name="title"><hr><input placeholder="링크" type="text" name="link"><hr><button type="submit">추가</button></form>',
menu = [['other', '기타']]
))
@app.route('/edit_set')
@app.route('/edit_set/<int:num>', methods=['POST', 'GET'])
def edit_set(num = 0):
if num != 0 and admin_check(conn, None, None) != 1:
return re_error(conn, '/ban')
if num == 0:
li_list = ['기본 설정', '문구 관련', '전역 HEAD', 'robots.txt', '구글 관련']
x = 0
li_data = ''
for li in li_list:
x += 1
li_data += '<li><a href="/edit_set/' + str(x) + '">' + li + '</a></li>'
return html_minify(render_template(skin_check(conn),
imp = ['설정 편집', wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = '<h2>메뉴</h2><ul>' + li_data + '</ul>',
menu = [['manager', lang_data['admin']]]
))
elif num == 1:
i_list = ['name', 'logo', 'frontpage', 'license', 'upload', 'skin', 'edit', 'reg', 'ip_view', 'back_up']
n_list = ['Wiki', '', 'FrontPage', 'CC 0', '2', '', 'normal', '', '', '0']
if request.method == 'POST':
i = 0
for data in i_list:
curs.execute("update other set data = ? where name = ?", [request.form.get(data, n_list[i]), data])
i += 1
conn.commit()
admin_check(conn, None, 'edit_set')
return redirect('/edit_set/1')
else:
d_list = []
x = 0
for i in i_list:
curs.execute('select data from other where name = ?', [i])
sql_d = curs.fetchall()
if sql_d:
d_list += [sql_d[0][0]]
else:
curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
d_list += [n_list[x]]
x += 1
conn.commit()
div = ''
if d_list[6] == 'login':
div += '<option value="login">가입자</option>'
div += '<option value="normal">일반</option>'
div += '<option value="admin">' + lang_data['admin'] + '</option>'
elif d_list[6] == 'admin':
div += '<option value="admin">' + lang_data['admin'] + '</option>'
div += '<option value="login">가입자</option>'
div += '<option value="normal">일반</option>'
else:
div += '<option value="normal">일반</option>'
div += '<option value="admin">' + lang_data['admin'] + '</option>'
div += '<option value="login">가입자</option>'
ch_1 = ''
if d_list[7]:
ch_1 = 'checked="checked"'
ch_2 = ''
if d_list[8]:
ch_2 = 'checked="checked"'
div2 = ''
for skin_data in os.listdir(os.path.abspath('views')):
if d_list[5] == skin_data:
div2 = '<option value="' + skin_data + '">' + skin_data + '</option>' + div2
else:
div2 += '<option value="' + skin_data + '">' + skin_data + '</option>'
return html_minify(render_template(skin_check(conn),
imp = ['기본 설정', wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = '<form method="post"><span>이름</span><br><br><input placeholder="이름" type="text" name="name" value="' + html.escape(d_list[0]) + '"><hr><span>로고 (HTML)</span><br><br><input placeholder="로고" type="text" name="logo" value="' + html.escape(d_list[1]) + '"><hr><span>대문</span><br><br><input placeholder="대문" type="text" name="frontpage" value="' + html.escape(d_list[2]) + '"><hr><span>라이선스 (HTML)</span><br><br><input placeholder="라이선스" type="text" name="license" value="' + html.escape(d_list[3]) + '"><hr><span>파일 크기 [메가]</span><br><br><input placeholder="파일 크기" type="text" name="upload" value="' + html.escape(d_list[4]) + '"><hr><span>백업 간격 [시간] (끄기 : 0) {재시작 필요}</span><br><br><input placeholder="백업 간격" type="text" name="back_up" value="' + html.escape(d_list[9]) + '"><hr><span>스킨</span><br><br><select name="skin">' + div2 + '</select><hr><span>전역 ACL</span><br><br><select name="edit">' + div + '</select><hr><input type="checkbox" name="reg" ' + ch_1 + '> 가입불가<hr><input type="checkbox" name="ip_view" ' + ch_2 + '> 아이피 비공개<hr><button id="save" type="submit">저장</button></form>',
menu = [['edit_set', '설정']]
))
elif num == 2:
if request.method == 'POST':
curs.execute("update other set data = ? where name = ?", [request.form['contract'], 'contract'])
curs.execute("update other set data = ? where name = ?", [request.form['no_login_warring'], 'no_login_warring'])
conn.commit()
admin_check(conn, None, 'edit_set')
return redirect('/edit_set/2')
else:
i_list = ['contract', 'no_login_warring']
n_list = ['', '']
d_list = []
x = 0
for i in i_list:
curs.execute('select data from other where name = ?', [i])
sql_d = curs.fetchall()
if sql_d:
d_list += [sql_d[0][0]]
else:
curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
d_list += [n_list[x]]
x += 1
conn.commit()
return html_minify(render_template(skin_check(conn),
imp = ['문구 관련', wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = '<form method="post"><span>가입 약관</span><br><br><input placeholder="가입 약관" type="text" name="contract" value="' + html.escape(d_list[0]) + '"><hr><span>비 로그인 경고</span><br><br><input placeholder="비 로그인 경고" type="text" name="no_login_warring" value="' + html.escape(d_list[1]) + '"><hr><button id="save" type="submit">저장</button></form>',
menu = [['edit_set', '설정']]
))
elif num == 3:
if request.method == 'POST':
curs.execute("select name from other where name = 'head'")
if curs.fetchall():
curs.execute("update other set data = ? where name = 'head'", [request.form['content']])
else:
curs.execute("insert into other (name, data) values ('head', ?)", [request.form['content']])
conn.commit()
admin_check(conn, None, 'edit_set')
return redirect('/edit_set/3')
else:
curs.execute("select data from other where name = 'head'")
head = curs.fetchall()
if head:
data = head[0][0]
else:
data = ''
return html_minify(render_template(skin_check(conn),
imp = ['전역 HEAD', wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = '<span><style>CSS</style><br><script>JS</script></span><hr><form method="post"><textarea rows="25" name="content">' + html.escape(data) + '</textarea><hr><button id="save" type="submit">저장</button></form>',
menu = [['edit_set', '설정']]
))
elif num == 4:
if request.method == 'POST':
curs.execute("select name from other where name = 'robot'")
if curs.fetchall():
curs.execute("update other set data = ? where name = 'robot'", [request.form['content']])
else:
curs.execute("insert into other (name, data) values ('robot', ?)", [request.form['content']])
conn.commit()
fw = open('./robots.txt', 'w')
fw.write(re.sub('\r\n', '\n', request.form['content']))
fw.close()
admin_check(conn, None, 'edit_set')
return redirect('/edit_set/4')
else:
curs.execute("select data from other where name = 'robot'")
robot = curs.fetchall()
if robot:
data = robot[0][0]
else:
data = ''
f = open('./robots.txt', 'r')
lines = f.readlines()
f.close()
if not data or data == '':
data = ''.join(lines)
return html_minify(render_template(skin_check(conn),
imp = ['robots.txt', wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = '<a href="/robots.txt">(보기)</a><hr><form method="post"><textarea rows="25" name="content">' + html.escape(data) + '</textarea><hr><button id="save" type="submit">저장</button></form>',
menu = [['edit_set', '설정']]
))
elif num == 5:
if request.method == 'POST':
curs.execute("update other set data = ? where name = 'recaptcha'", [request.form['recaptcha']])
curs.execute("update other set data = ? where name = 'sec_re'", [request.form['sec_re']])
conn.commit()
admin_check(conn, None, 'edit_set')
return redirect('/edit_set/5')
else:
i_list = ['recaptcha', 'sec_re']
n_list = ['', '']
d_list = []
x = 0
for i in i_list:
curs.execute('select data from other where name = ?', [i])
sql_d = curs.fetchall()
if sql_d:
d_list += [sql_d[0][0]]
else:
curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
d_list += [n_list[x]]
x += 1
conn.commit()
return html_minify(render_template(skin_check(conn),
imp = ['구글 관련', wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = '<form method="post"><span>리캡차 (HTML)</span><br><br><input placeholder="리캡차 (HTML)" type="text" name="recaptcha" value="' + html.escape(d_list[0]) + '"><hr><span>리캡차 (비밀키)</span><br><br><input placeholder="리캡차 (비밀키)" type="text" name="sec_re" value="' + html.escape(d_list[1]) + '"><hr><button id="save" type="submit">저장</button></form>',
menu = [['edit_set', '설정']]
))
else:
return redirect('/')
@app.route('/not_close_topic')
def not_close_topic():
div = '<ul>'
curs.execute('select title, sub from rd order by date desc')
n_list = curs.fetchall()
for data in n_list:
curs.execute('select * from stop where title = ? and sub = ? and close = "O"', [data[0], data[1]])
is_close = curs.fetchall()
if not is_close:
div += '<li><a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[1]) + '">' + data[0] + ' (' + data[1] + ')</a></li>'
div += '</ul>'
return html_minify(render_template(skin_check(conn),
imp = ['열린 토론 ' + lang_data['list'], wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = div,
menu = [['manager', lang_data['admin']]]
))
@app.route('/image/<name>')
def image_view(name = None):
if os.path.exists(os.path.join('image', name)):
return send_from_directory('./image', name)
else:
return redirect('/')
@app.route('/acl_list')
def acl_list():
div = '<ul>'
curs.execute("select title, dec from acl where dec = 'admin' or dec = 'user' order by title desc")
list_data = curs.fetchall()
for data in list_data:
if not re.search('^사용자:', data[0]) and not re.search('^파일:', data[0]):
if data[1] == 'admin':
acl = lang_data['admin']
else:
acl = '가입자'
div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (' + acl + ')</li>'
div += '</ul>'
return html_minify(render_template(skin_check(conn),
imp = ['ACL ' + lang_data['document'] + ' ' + lang_data['list'], wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = div,
menu = [['other', '기타']]
))
@app.route('/admin_plus/<name>', methods=['POST', 'GET'])
def admin_plus(name = None):
if request.method == 'POST':
if admin_check(conn, None, 'admin_plus (' + name + ')') != 1:
return re_error(conn, '/error/3')
curs.execute("delete from alist where name = ?", [name])
if request.form.get('ban', 0) != 0:
curs.execute("insert into alist (name, acl) values (?, 'ban')", [name])
if request.form.get('mdel', 0) != 0:
curs.execute("insert into alist (name, acl) values (?, 'mdel')", [name])
if request.form.get('toron', 0) != 0:
curs.execute("insert into alist (name, acl) values (?, 'toron')", [name])
if request.form.get('check', 0) != 0:
curs.execute("insert into alist (name, acl) values (?, 'check')", [name])
if request.form.get('acl', 0) != 0:
curs.execute("insert into alist (name, acl) values (?, 'acl')", [name])
if request.form.get('hidel', 0) != 0:
curs.execute("insert into alist (name, acl) values (?, 'hidel')", [name])
if request.form.get('give', 0) != 0:
curs.execute("insert into alist (name, acl) values (?, 'give')", [name])
if request.form.get('owner', 0) != 0:
curs.execute("insert into alist (name, acl) values (?, 'owner')", [name])
conn.commit()
return redirect('/admin_plus/' + url_pas(name))
else:
data = '<ul>'
exist_list = ['', '', '', '', '', '', '', '']
curs.execute('select acl from alist where name = ?', [name])
acl_list = curs.fetchall()
for go in acl_list:
if go[0] == 'ban':
exist_list[0] = 'checked="checked"'
elif go[0] == 'mdel':
exist_list[1] = 'checked="checked"'
elif go[0] == 'toron':
exist_list[2] = 'checked="checked"'
elif go[0] == 'check':
exist_list[3] = 'checked="checked"'
elif go[0] == 'acl':
exist_list[4] = 'checked="checked"'
elif go[0] == 'hidel':
exist_list[5] = 'checked="checked"'
elif go[0] == 'give':
exist_list[6] = 'checked="checked"'
elif go[0] == 'owner':
exist_list[7] = 'checked="checked"'
if admin_check(conn, None, None) != 1:
state = 'disabled'
else:
state = ''
data += '<li><input type="checkbox" ' + state + ' name="ban" ' + exist_list[0] + '> ' + lang_data['ban'] + '</li>'
data += '<li><input type="checkbox" ' + state + ' name="mdel" ' + exist_list[1] + '> 많은 문서 삭제</li>'
data += '<li><input type="checkbox" ' + state + ' name="toron" ' + exist_list[2] + '> 토론 관리</li>'
data += '<li><input type="checkbox" ' + state + ' name="check" ' + exist_list[3] + '> 사용자 검사</li>'
data += '<li><input type="checkbox" ' + state + ' name="acl" ' + exist_list[4] + '> ' + lang_data['document'] + ' ACL</li>'
data += '<li><input type="checkbox" ' + state + ' name="hidel" ' + exist_list[5] + '> ' + lang_data['history'] + ' ' + lang_data['hide'] + '</li>'
data += '<li><input type="checkbox" ' + state + ' name="give" ' + exist_list[6] + '> 권한 관리</li>'
data += '<li><input type="checkbox" ' + state + ' name="owner" ' + exist_list[7] + '> 소유자</li></ul>'
return html_minify(render_template(skin_check(conn),
imp = ['관리 그룹 추가', wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = '<form method="post">' + data + '<hr><button id="save" ' + state + ' type="submit">저장</button></form>',
menu = [['manager', lang_data['admin']]]
))
@app.route('/admin_list')
def admin_list():
div = '<ul>'
curs.execute("select id, acl, date from user where not acl = 'user' order by date desc")
for data in curs.fetchall():
name = ip_pas(conn, data[0]) + ' <a href="/admin_plus/' + url_pas(data[1]) + '">(' + data[1] + ')</a>'
if data[2] != '':
name += '(가입 : ' + data[2] + ')'
div += '<li>' + name + '</li>'
div += '</ul>'
return html_minify(render_template(skin_check(conn),
imp = [lang_data['admin'] + ' ' + lang_data['list'], wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = div,
menu = [['other', '기타']]
))
@app.route('/hidden/<path:name>')
def history_hidden(name = None):
num = int(request.args.get('num', 0))
if admin_check(conn, 6, 'history_hidden (' + name + '#' + str(num) + ')') == 1:
curs.execute("select title from history where title = ? and id = ? and hide = 'O'", [name, str(num)])
if curs.fetchall():
curs.execute("update history set hide = '' where title = ? and id = ?", [name, str(num)])
else:
curs.execute("update history set hide = 'O' where title = ? and id = ?", [name, str(num)])
conn.commit()
return redirect('/history/' + url_pas(name))
@app.route('/user_log')
def user_log():
num = int(request.args.get('num', 1))
if num * 50 > 0:
sql_num = num * 50 - 50
else:
sql_num = 0
list_data = '<ul>'
admin_one = admin_check(conn, 1, None)
curs.execute("select id, date from user order by date desc limit ?, '50'", [str(sql_num)])
user_list = curs.fetchall()
for data in user_list:
if admin_one == 1:
curs.execute("select block from ban where block = ?", [data[0]])
if curs.fetchall():
ban_button = ' <a href="/ban/' + url_pas(data[0]) + '">(' + lang_data['release'] + ')</a>'
else:
ban_button = ' <a href="/ban/' + url_pas(data[0]) + '">(' + lang_data['ban'] + ')</a>'
else:
ban_button = ''
list_data += '<li>' + ip_pas(conn, data[0]) + ban_button
if data[1] != '':
list_data += ' (가입 : ' + data[1] + ')'
list_data += '</li>'
if num == 1:
curs.execute("select count(id) from user")
user_count = curs.fetchall()
if user_count:
count = user_count[0][0]
else:
count = 0
list_data += '</ul><hr><ul><li>이 위키에는 ' + str(count) + '명의 사람이 있습니다.</li></ul>'
list_data += next_fix('/user_log?num=', num, user_list)
return html_minify(render_template(skin_check(conn),
imp = ['최근 가입', wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = list_data,
menu = 0
))
@app.route('/admin_log')
def admin_log():
num = int(request.args.get('num', 1))
if num * 50 > 0:
sql_num = num * 50 - 50
else:
sql_num = 0
list_data = '<ul>'
curs.execute("select who, what, time from re_admin order by time desc limit ?, '50'", [str(sql_num)])
get_list = curs.fetchall()
for data in get_list:
list_data += '<li>' + ip_pas(conn, data[0]) + ' / ' + data[1] + ' / ' + data[2] + '</li>'
list_data += '</ul><hr><ul><li>주의 : 권한 사용 안하고 열람만 해도 기록되는 경우도 있습니다.</li></ul>'
list_data += next_fix('/admin_log?num=', num, get_list)
return html_minify(render_template(skin_check(conn),
imp = ['최근 권한', wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = list_data,
menu = 0
))
@app.route('/give_log')
def give_log():
list_data = '<ul>'
back = ''
curs.execute("select distinct name from alist order by name asc")
for data in curs.fetchall():
if back != data[0]:
back = data[0]
list_data += '<li><a href="/admin_plus/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
list_data += '</ul><hr><a href="/manager/8">(생성)</a>'
return html_minify(render_template(skin_check(conn),
imp = ['관리 그룹 ' + lang_data['list'], wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = list_data,
menu = [['other', '기타']]
))
@app.route('/indexing')
def indexing():
if admin_check(conn, None, 'indexing') != 1:
return re_error(conn, '/error/3')
print('')
curs.execute("select name from sqlite_master where type = 'index'")
data = curs.fetchall()
if data:
for delete_index in data:
print('Delete : ' + delete_index[0])
sql = 'drop index if exists ' + delete_index[0]
try:
curs.execute(sql)
except:
pass
else:
curs.execute("select name from sqlite_master where type in ('table', 'view') and name not like 'sqlite_%' union all select name from sqlite_temp_master where type in ('table', 'view') order by 1;")
for table in curs.fetchall():
curs.execute('select sql from sqlite_master where name = ?', [table[0]])
cul = curs.fetchall()
r_cul = re.findall('(?:([^ (]*) text)', str(cul[0]))
for n_cul in r_cul:
print('Create : index_' + table[0] + '_' + n_cul)
sql = 'create index index_' + table[0] + '_' + n_cul + ' on ' + table[0] + '(' + n_cul + ')'
try:
curs.execute(sql)
except:
pass
conn.commit()
print('')
return redirect('/')
@app.route('/re_start')
def re_start():
if admin_check(conn, None, 're_start') != 1:
return re_error(conn, '/error/3')
print('')
print('Re Start')
print('')
os.execl(sys.executable, sys.executable, *sys.argv)
@app.route('/update')
def update():
if admin_check(conn, None, 'update') != 1:
return re_error(conn, '/error/3')
if platform.system() == 'Linux':
print('')
print('Update')
ok = os.system('git pull')
if ok == 0:
print('Re Start')
print('')
os.execl(sys.executable, sys.executable, *sys.argv)
return html_minify(render_template(skin_check(conn),
imp = ['업데이트', wiki_set(conn, 1), custom(conn), other2([0, 0])],
data = '수동 업데이트를 권장 합니다. <a href="https://github.com/2DU/openNAMU">(깃허브)</a>',
menu = [['manager/1', lang_data['admin']]]
))
@app.route('/xref/<path:name>')
def xref(name = None):
num = int(request.args.get('num', 1))
if num * 50 > 0:
sql_num = num * 50 - 50
else:
sql_num = 0
div = '<ul>'
curs.execute("select link, type from back where title = ? and not type = 'cat' and not type = 'no' order by link asc limit ?, '50'", [name, str(sql_num)])
data_list = curs.fetchall()
for data in data_list:
div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a>'
if data[1]:
if data[1] == 'include':
side = '포함'
elif data[1] == 'file':
side = '파일'
else:
side = '넘겨주기'
div += ' (' + side + ')'
div += '</li>'
if re.search('^틀:', data[0]):
div += '<li><a id="inside" href="/xref/' + url_pas(data[0]) + '">' + data[0] + '</a> (역링크)</li>'
div += '</ul>' + next_fix('/xref/' + url_pas(name) + '?num=', num, data_list)
return html_minify(render_template(skin_check(conn),
imp = [name, wiki_set(conn, 1), custom(conn), other2([' (역링크)', 0])],
data = div,
menu = [['w/' + url_pas(name), lang_data['document']]]
))
@app.route('/please')
def please():
num = int(request.args.get('num', 1))
if num * 50 > 0:
sql_num = num * 50 - 50
else:
sql_num = 0
div = '<ul>'
var = ''
curs.execute("select distinct title from back where type = 'no' order by title asc limit ?, '50'", [str(sql_num)])
data_list = curs.fetchall()
for data in data_list:
if var != data[0]:
div += '<li><a id="not_thing" href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
var = data[0]
div += '</ul>' + next_fix('/please?num=', num, data_list)
return html_minify(render_template(skin_check(conn),
imp = ['필요한 ' + lang_data['document'], wiki_set(conn, 1), custom(conn), other2([0, 0])],