from .tool.func import *
def setting_2(conn, num, db_set):
curs = conn.cursor()
if not (num == 0 or num == 8) and admin_check() != 1:
return re_error('/ban')
if num == 0:
li_list = [
load_lang('main_setting'),
load_lang('text_setting'),
load_lang('main_head'),
load_lang('main_body'),
'robots.txt',
'Google',
load_lang('main_bottom_body'),
load_lang('main_acl_setting'),
load_lang('wiki_logo')
]
x = 0
li_data = ''
for li in li_list:
x += 1
li_data += '
' + li + ' '
return easy_minify(flask.render_template(skin_check(),
imp = [load_lang('setting'), wiki_set(), custom(), other2([0, 0])],
data = '' + load_lang('list') + ' ',
menu = [['manager', load_lang('return')]]
))
elif num == 1:
i_list = {
0 : 'name',
2 : 'frontpage',
3 : 'license',
4 : 'upload',
5 : 'skin',
7 : 'reg',
8 : 'ip_view',
9 : 'back_up',
10 : 'port',
11 : 'key',
12 : 'update',
13 : 'email_have',
15 : 'encode',
16 : 'host',
19 : 'slow_edit',
20 : 'requires_approval',
21 : 'backup_where',
22 : 'domain',
23 : 'ua_get'
}
n_list = {
0 : 'Wiki',
2 : 'FrontPage',
3 : 'ARR',
4 : '2',
5 : '',
7 : '',
8 : '',
9 : '0',
10 : '3000',
11 : 'test',
12 : 'stable',
13 : '',
15 : 'sha3',
16 : '0.0.0.0',
19 : '0',
20 : '',
21 : '',
22 : flask.request.host_url,
23 : ''
}
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_list[i], n_list[i]),
i_list[i]
])
conn.commit()
admin_check(None, 'edit_set (' + str(num) + ')')
return redirect('/setting/1')
else:
d_list = {}
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], n_list[i]])
d_list[i] = n_list[i]
conn.commit()
acl_div = ['']
encode_data = ['sha256', 'sha3']
for acl_data in encode_data:
if acl_data == d_list[15]:
acl_div[0] = '' + acl_data + ' ' + acl_div[0]
else:
acl_div[0] += '' + acl_data + ' '
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 == 2:
acl_num = 13
elif i == 3:
acl_num = 20
else:
acl_num = 23
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 = '' + i + ' ' + branch_div
else:
branch_div += '' + i + ' '
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(), custom(), other2([0, 0])],
data = '''
''',
menu = [['setting', load_lang('return')]]
))
elif num == 2:
i_list = [
'contract',
'no_login_warring',
'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'
]
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(), custom(), other2([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 = '''
''' + load_lang('preview') + '''
'''
elif num == 7:
curs.execute(db_change("select data from other where name = 'bottom_body'"))
title = '_bottom_body'
start = ''
plus = '''
''' + load_lang('preview') + '''
'''
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(), custom(), other2(['(HTML)' + sub_plus, 0])],
data = '''
''' + start + '''
''' + html.escape(data) + '''
''' + load_lang('save') + '''
''' + plus + '''
''',
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(), custom(), other2([0, 0])],
data = '''
(''' + load_lang('view') + ''')
''' + html.escape(data) + '''
''' + load_lang('save') + '''
''',
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'
]
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']:
security_radios += ' ' + i + ' '
re_ver = ''
if d_list[7] == '':
re_ver += 'v2 v3 '
else:
re_ver += 'v3 v2 '
return easy_minify(flask.render_template(skin_check(),
imp = ['Google', wiki_set(), custom(), other2([0, 0])],
data = '''
''' + load_lang('public_key') + '''
''' + load_lang('secret_key') + '''
''' + re_ver + '''
''' + load_lang('smtp_setting') + ' (' + load_lang('restart_required') + ''')
''' + load_lang('smtp_server') + '''
''' + load_lang('smtp_port') + '''
''' + load_lang('smtp_security') + '''
'''
+ security_radios +
'''
''' + load_lang('smtp_username') + '''
''' + load_lang('smtp_password') + '''
''' + load_lang('save') + '''
''',
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] += '' + (data_list if data_list != '' else 'normal') + ' '
return easy_minify(flask.render_template(skin_check(),
imp = [load_lang('main_acl_setting'), wiki_set(), custom(), other2([0, 0])],
data = '''
(''' + load_lang('reference') + ''')
''' + load_lang('document_acl') + '''
''' + acl_div[0] + '''
''' + load_lang('discussion_acl') + '''
''' + acl_div[1] + '''
''' + load_lang('upload_acl') + '''
''' + acl_div[2] + '''
''' + load_lang('view_acl') + '''
''' + acl_div[3] + '''
''' + load_lang('many_upload_acl') + '''
''' + acl_div[4] + '''
''' + load_lang('vote_acl') + '''
''' + acl_div[5] + '''
''' + load_lang('save') + '''
''',
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/10')
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 += ['']
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(), custom(), other2([0, 0])],
data = '''
''' + end_data + '''
''' + load_lang('save') + '''
''',
menu = [['setting', load_lang('return')]]
))
else:
return redirect()