from .tool.func import *
def main_func_setting(db_set, num = 0):
with get_db_connect() as conn:
curs = conn.cursor()
if not (num == 0 or num == 8) and admin_check() != 1:
return re_error('/ban')
if num == 0:
li_list = [
[1, load_lang('main_setting')],
[2, load_lang('text_setting')],
[5, 'robots.txt'],
[6, load_lang('ext_api_req_set')],
[3, load_lang('main_head')],
[4, load_lang('main_body')],
[7, load_lang('main_bottom_body')]
]
li_data = ''.join(['
' for li in li_list])
return easy_minify(flask.render_template(skin_check(),
imp = [load_lang('setting'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
data = '
' + load_lang('list') + '
' + li_data + '
',
menu = [['manager', load_lang('return')]]
))
elif num == 1:
setting_list = {
0 : ['name', 'Wiki'],
2 : ['frontpage', 'FrontPage'],
4 : ['upload', '2'],
5 : ['skin', ''],
7 : ['reg', ''],
8 : ['ip_view', ''],
9 : ['back_up', '0'],
10 : ['port', '3000'],
11 : ['key', load_random_key()],
12 : ['update', 'stable'],
15 : ['encode', 'sha3'],
16 : ['host', '0.0.0.0'],
19 : ['slow_edit', '0'],
20 : ['requires_approval', ''],
21 : ['backup_where', ''],
22 : ['domain', flask.request.host_url],
23 : ['ua_get', ''],
24 : ['enable_comment', ''],
25 : ['enable_challenge', '']
}
if flask.request.method == 'POST':
for i in setting_list:
curs.execute(db_change("update other set data = ? where name = ?"), [
flask.request.form.get(setting_list[i][0], setting_list[i][1]),
setting_list[i][0]
])
conn.commit()
admin_check(None, 'edit_set (' + str(num) + ')')
return redirect('/setting/1')
else:
d_list = {}
for i in setting_list:
curs.execute(db_change('select data from other where name = ?'), [setting_list[i][0]])
db_data = curs.fetchall()
if not db_data:
curs.execute(db_change('insert into other (name, data) values (?, ?)'), [setting_list[i][0], setting_list[i][1]])
d_list[i] = db_data[0][0] if db_data else setting_list[i][1]
else:
conn.commit()
acl_div = ['']
encode_data = ['sha256', 'sha3']
for acl_data in encode_data:
if acl_data == d_list[15]:
acl_div[0] = '' + acl_div[0]
else:
acl_div[0] += ''
check_box_div = ['', '', '', '', '', '', '']
for i in range(0, len(check_box_div)):
if i == 0:
acl_num = 7
elif i == 1:
acl_num = 8
elif i == 3:
acl_num = 20
elif i == 4:
acl_num = 23
elif i == 5:
acl_num = 24
elif i == 6:
acl_num = 25
if d_list[acl_num]:
check_box_div[i] = 'checked="checked"'
branch_div = ''
branch_list = ['stable', 'dev', 'beta']
for i in branch_list:
if d_list[12] == i:
branch_div = '' + branch_div
else:
branch_div += ''
sqlite_only = 'style="display:none;"' if db_set != 'sqlite' else ''
return easy_minify(flask.render_template(skin_check(),
imp = [load_lang('main_setting'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
data = '''
''',
menu = [['setting', load_lang('return')]]
))
elif num == 2:
i_list = [
'contract',
'no_login_warning',
'edit_bottom_text',
'copyright_checkbox_text',
'check_key_text',
'email_title',
'email_text',
'email_insert_text',
'password_search_text',
'reset_user_text',
'error_401',
'error_404',
'approval_question',
'edit_help',
'upload_help',
'upload_default',
'license',
'topic_text'
]
if flask.request.method == 'POST':
for i in i_list:
curs.execute(db_change("update other set data = ? where name = ?"), [
flask.request.form.get(i, ''),
i
])
conn.commit()
admin_check(None, 'edit_set (' + str(num) + ')')
return redirect('/setting/2')
else:
d_list = []
for i in i_list:
curs.execute(db_change('select data from other where name = ?'), [i])
sql_d = curs.fetchall()
if sql_d:
d_list += [sql_d[0][0]]
else:
curs.execute(db_change('insert into other (name, data) values (?, ?)'), [i, ''])
d_list += ['']
conn.commit()
return easy_minify(flask.render_template(skin_check(),
imp = [load_lang('text_setting'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
data = '''
''',
menu = [['setting', load_lang('return')]]
))
elif num == 3 or num == 4 or num == 7:
if flask.request.method == 'POST':
if num == 4:
info_d = 'body'
end_r = '4'
coverage = ''
elif num == 7:
info_d = 'bottom_body'
end_r = '7'
coverage = ''
else:
info_d = 'head'
end_r = '3'
if flask.request.args.get('skin', '') == '':
coverage = ''
else:
coverage = flask.request.args.get('skin', '')
curs.execute(db_change("select name from other where name = ? and coverage = ?"), [info_d, coverage])
if curs.fetchall():
curs.execute(db_change("update other set data = ? where name = ? and coverage = ?"), [
flask.request.form.get('content', ''),
info_d,
coverage
])
else:
curs.execute(db_change("insert into other (name, data, coverage) values (?, ?, ?)"), [info_d, flask.request.form.get('content', ''), coverage])
conn.commit()
admin_check(None, 'edit_set (' + str(num) + ')')
return redirect('/setting/' + end_r + '?skin=' + flask.request.args.get('skin', ''))
else:
if num == 4:
curs.execute(db_change("select data from other where name = 'body'"))
title = '_body'
start = ''
plus = '''
'''
elif num == 7:
curs.execute(db_change("select data from other where name = 'bottom_body'"))
title = '_bottom_body'
start = ''
plus = '''
'''
else:
curs.execute(db_change("select data from other where name = 'head' and coverage = ?"), [flask.request.args.get('skin', '')])
title = '_head'
start = '' + \
'(' + load_lang('all') + ') ' + \
' '.join(['(' + i + ')' for i in load_skin('', 1)]) + '''
<style>CSS</style> <script>JS</script>
'''
plus = ''
head = curs.fetchall()
if head:
data = head[0][0]
else:
data = ''
if flask.request.args.get('skin', '') != '':
sub_plus = ' (' + flask.request.args.get('skin', '') + ')'
else:
sub_plus = ''
return easy_minify(flask.render_template(skin_check(),
imp = [load_lang(data = 'main' + title, safe = 1), wiki_set(), wiki_custom(), wiki_css(['(HTML)' + sub_plus, 0])],
data = '''
''',
menu = [['setting', load_lang('return')]]
))
elif num == 5:
if flask.request.method == 'POST':
curs.execute(db_change("select name from other where name = 'robot'"))
if curs.fetchall():
curs.execute(db_change("update other set data = ? where name = 'robot'"), [flask.request.form.get('content', '')])
else:
curs.execute(db_change("insert into other (name, data) values ('robot', ?)"), [flask.request.form.get('content', '')])
conn.commit()
fw = open('./robots.txt', 'w', encoding='utf8')
fw.write(re.sub('\r\n', '\n', flask.request.form.get('content', '')))
fw.close()
admin_check(None, 'edit_set (' + str(num) + ')')
return redirect('/setting/5')
else:
if not os.path.exists('robots.txt'):
curs.execute(db_change('select data from other where name = "robot"'))
robot_test = curs.fetchall()
if robot_test:
fw_test = open('./robots.txt', 'w', encoding='utf8')
fw_test.write(re.sub('\r\n', '\n', robot_test[0][0]))
fw_test.close()
else:
fw_test = open('./robots.txt', 'w', encoding='utf8')
fw_test.write('User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/')
fw_test.close()
curs.execute(db_change('insert into other (name, data) values ("robot", "User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/")'))
curs.execute(db_change("select data from other where name = 'robot'"))
robot = curs.fetchall()
if robot:
data = robot[0][0]
else:
data = ''
f = open('./robots.txt', encoding='utf8')
lines = f.readlines()
f.close()
if not data or data == '':
data = ''.join(lines)
return easy_minify(flask.render_template(skin_check(),
imp = ['robots.txt', wiki_set(), wiki_custom(), wiki_css([0, 0])],
data = '''
(''' + load_lang('view') + ''')
''',
menu = [['setting', load_lang('return')]]
))
elif num == 6:
i_list = [
'recaptcha',
'sec_re',
'smtp_server',
'smtp_port',
'smtp_security',
'smtp_email',
'smtp_pass',
'recaptcha_ver',
'oauth_client_id',
'email_have'
]
if flask.request.method == 'POST':
for data in i_list:
into_data = flask.request.form.get(data, '')
curs.execute(db_change("update other set data = ? where name = ?"), [into_data, data])
conn.commit()
admin_check(None, 'edit_set (' + str(num) + ')')
return redirect('/setting/6')
else:
d_list = []
x = 0
for i in i_list:
curs.execute(db_change('select data from other where name = ?'), [i])
sql_d = curs.fetchall()
if sql_d:
d_list += [sql_d[0][0]]
else:
curs.execute(db_change('insert into other (name, data) values (?, ?)'), [i, ''])
d_list += ['']
x += 1
conn.commit()
security_radios = ''
for i in ['tls', 'starttls', 'plain']:
if d_list[4] == i:
security_radios = '' + security_radios
else:
security_radios += ''
re_ver_list = {
'' : 'reCAPTCHA v2',
'v3' : 'reCAPTCHA v3',
'h' : 'hCAPTCHA'
}
re_ver = ''
for i in re_ver_list:
if d_list[7] == i:
re_ver = '' + re_ver
else:
re_ver += ''
return easy_minify(flask.render_template(skin_check(),
imp = [load_lang('ext_api_req_set'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
data = '''
''',
menu = [['setting', load_lang('return')]]
))
elif num == 8:
i_list = {
1 : 'edit',
2 : 'discussion',
3 : 'upload_acl',
4 : 'all_view_acl',
5 : 'many_upload_acl',
6 : 'vote_acl'
}
if flask.request.method == 'POST':
if admin_check(None, 'edit_set (' + str(num) + ')') != 1:
return re_error('/ban')
else:
for i in i_list:
curs.execute(db_change("update other set data = ? where name = ?"), [
flask.request.form.get(i_list[i], 'normal'),
i_list[i]
])
conn.commit()
return redirect('/setting/8')
else:
d_list = {}
if admin_check() != 1:
disable = 'disabled'
else:
disable = ''
for i in i_list:
curs.execute(db_change('select data from other where name = ?'), [i_list[i]])
sql_d = curs.fetchall()
if sql_d:
d_list[i] = sql_d[0][0]
else:
curs.execute(db_change('insert into other (name, data) values (?, ?)'), [i_list[i], 'normal'])
d_list[i] = 'normal'
conn.commit()
acl_div = []
for i in range(0, len(i_list)):
acl_div += ['']
acl_list = get_acl_list()
for i in range(0, len(i_list)):
for data_list in acl_list:
if data_list == d_list[i + 1]:
check = 'selected="selected"'
else:
check = ''
acl_div[i] += ''
return easy_minify(flask.render_template(skin_check(),
imp = [load_lang('main_acl_setting'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
data = '''
''',
menu = [['setting', load_lang('return')]]
))
elif num == 9:
skin_list = [0] + load_skin('', 1)
i_list = []
for i in skin_list:
i_list += [['logo', '' if i == 0 else i]]
if flask.request.method == 'POST':
for i in i_list:
curs.execute(db_change("update other set data = ? where name = ? and coverage = ?"), [
flask.request.form.get(('main_css' if i[1] == '' else i[1]), ''),
i[0],
i[1]
])
conn.commit()
admin_check(None, 'edit_set (' + str(num) + ')')
return redirect('/setting/9')
else:
d_list = []
for i in i_list:
curs.execute(db_change('select data from other where name = ? and coverage = ?'), [i[0], i[1]])
sql_d = curs.fetchall()
if sql_d:
d_list += [sql_d[0][0]]
else:
curs.execute(db_change('insert into other (name, data, coverage) values (?, ?, ?)'), [i[0], '', i[1]])
d_list += ['']
conn.commit()
end_data = ''
for i in range(0, len(skin_list)):
end_data += '' + \
'' + load_lang('wiki_logo') + ' ' + ('(' + skin_list[i] + ')' if skin_list[i] != 0 else '') + ' (HTML)' + \
'' + \
'' + \
'' + \
''
return easy_minify(flask.render_template(skin_check(),
imp = [load_lang('wiki_logo'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
data = '''
''',
menu = [['setting', load_lang('return')]]
))
else:
return redirect()