setting.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. from .tool.func import *
  2. def setting_2(conn, num):
  3. curs = conn.cursor()
  4. if num != 0 and admin_check() != 1:
  5. return re_error('/ban')
  6. if num == 0:
  7. li_list = [
  8. load_lang('main_setting'),
  9. load_lang('text_setting'),
  10. load_lang('main_head'),
  11. load_lang('main_body'),
  12. 'robots.txt',
  13. 'Google'
  14. ]
  15. x = 0
  16. li_data = ''
  17. for li in li_list:
  18. x += 1
  19. li_data += '<li><a href="/setting/' + str(x) + '">' + li + '</a></li>'
  20. return easy_minify(flask.render_template(skin_check(),
  21. imp = [load_lang('setting'), wiki_set(), custom(), other2([0, 0])],
  22. data = '<h2>' + load_lang('list') + '</h2><ul>' + li_data + '</ul>',
  23. menu = [['manager', load_lang('return')]]
  24. ))
  25. elif num == 1:
  26. i_list = ['name', 'logo', 'frontpage', 'license', 'upload', 'skin', 'edit', 'reg', 'ip_view', 'back_up', 'port', 'key', 'update', 'email_have', 'discussion', 'encode', 'host']
  27. n_list = ['Wiki', '', 'FrontPage', 'CC 0', '2', '', 'normal', '', '', '0', '3000', 'test', 'stable', '', 'normal', 'sha256', '0.0.0.0']
  28. if flask.request.method == 'POST':
  29. i = 0
  30. for data in i_list:
  31. curs.execute("update other set data = ? where name = ?", [flask.request.form.get(data, n_list[i]), data])
  32. i += 1
  33. conn.commit()
  34. admin_check(None, 'edit_set')
  35. return redirect('/setting/1')
  36. else:
  37. d_list = []
  38. x = 0
  39. for i in i_list:
  40. curs.execute('select data from other where name = ?', [i])
  41. sql_d = curs.fetchall()
  42. if sql_d:
  43. d_list += [sql_d[0][0]]
  44. else:
  45. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  46. d_list += [n_list[x]]
  47. x += 1
  48. conn.commit()
  49. div = ''
  50. acl_list = [[load_lang('member'), 'login'], [load_lang('ip'), 'normal'], [load_lang('admin'), 'admin']]
  51. for i in acl_list:
  52. if i[1] == d_list[6]:
  53. div = '<option value="' + i[1] + '">' + i[0] + '</option>' + div
  54. else:
  55. div += '<option value="' + i[1] + '">' + i[0] + '</option>'
  56. div4 = ''
  57. for i in acl_list:
  58. if i[1] == d_list[14]:
  59. div4 = '<option value="' + i[1] + '">' + i[0] + '</option>' + div4
  60. else:
  61. div4 += '<option value="' + i[1] + '">' + i[0] + '</option>'
  62. ch_1 = ''
  63. if d_list[7]:
  64. ch_1 = 'checked="checked"'
  65. ch_2 = ''
  66. if d_list[8]:
  67. ch_2 = 'checked="checked"'
  68. ch_3 = ''
  69. if d_list[13]:
  70. ch_3 = 'checked="checked"'
  71. div2 = load_skin(d_list[5])
  72. div3 =''
  73. if d_list[12] == 'stable':
  74. div3 += '<option value="stable">stable</option>'
  75. div3 += '<option value="master">master</option>'
  76. else:
  77. div3 += '<option value="master">master</option>'
  78. div3 += '<option value="stable">stable</option>'
  79. div5 =''
  80. encode_data = ['sha256', 'sha3']
  81. for i in encode_data:
  82. if d_list[15] == i:
  83. div5 = '<option value="' + i + '">' + i + '</option>' + div5
  84. else:
  85. div5 += '<option value="' + i + '">' + i + '</option>'
  86. return easy_minify(flask.render_template(skin_check(),
  87. imp = [load_lang('main_setting'), wiki_set(), custom(), other2([0, 0])],
  88. data = '''
  89. <form method="post">
  90. <span>''' + load_lang('wiki_name') + '''</span>
  91. <hr class=\"main_hr\">
  92. <input type="text" name="name" value="''' + html.escape(d_list[0]) + '''">
  93. <hr class=\"main_hr\">
  94. <span>''' + load_lang('wiki_logo') + ''' (HTML)</span>
  95. <hr class=\"main_hr\">
  96. <input type="text" name="logo" value="''' + html.escape(d_list[1]) + '''">
  97. <hr class=\"main_hr\">
  98. <span>''' + load_lang('main_page') + '''</span>
  99. <hr class=\"main_hr\">
  100. <input type="text" name="frontpage" value="''' + html.escape(d_list[2]) + '''">
  101. <hr class=\"main_hr\">
  102. <span>''' + load_lang('bottom_text') + ''' (HTML)</span>
  103. <hr class=\"main_hr\">
  104. <input type="text" name="license" value="''' + html.escape(d_list[3]) + '''">
  105. <hr class=\"main_hr\">
  106. <span>''' + load_lang('max_file_size') + ''' [MB]</span>
  107. <hr class=\"main_hr\">
  108. <input type="text" name="upload" value="''' + html.escape(d_list[4]) + '''">
  109. <hr class=\"main_hr\">
  110. <span>''' + load_lang('backup_interval') + ' [' + load_lang('hour') + '''] (off : 0) {restart}</span>
  111. <hr class=\"main_hr\">
  112. <input type="text" name="back_up" value="''' + html.escape(d_list[9]) + '''">
  113. <hr class=\"main_hr\">
  114. <span>''' + load_lang('wiki_skin') + '''</span>
  115. <hr class=\"main_hr\">
  116. <select name="skin">''' + div2 + '''</select>
  117. <hr class=\"main_hr\">
  118. <span>''' + load_lang('default_acl') + '''</span>
  119. <hr class=\"main_hr\">
  120. <select name="edit">''' + div + '''</select>
  121. <hr class=\"main_hr\">
  122. <span>''' + load_lang('default_discussion_acl') + '''</span>
  123. <hr class=\"main_hr\">
  124. <select name="discussion">''' + div4 + '''</select>
  125. <hr class=\"main_hr\">
  126. <input type="checkbox" name="reg" ''' + ch_1 + '''> ''' + load_lang('no_register') + '''
  127. <hr class=\"main_hr\">
  128. <input type="checkbox" name="ip_view" ''' + ch_2 + '''> ''' + load_lang('hide_ip') + '''
  129. <hr class=\"main_hr\">
  130. <input type="checkbox" name="email_have" ''' + ch_3 + '''> ''' + load_lang('email_required') + ''' {<a href="/setting/5">''' + load_lang('google_imap_required') + '''</a>}
  131. <hr class=\"main_hr\">
  132. <span>''' + load_lang('wiki_host') + '''</span>
  133. <hr class=\"main_hr\">
  134. <input type="text" name="host" value="''' + html.escape(d_list[16]) + '''">
  135. <hr class=\"main_hr\">
  136. <span>''' + load_lang('wiki_port') + '''</span>
  137. <hr class=\"main_hr\">
  138. <input type="text" name="port" value="''' + html.escape(d_list[10]) + '''">
  139. <hr class=\"main_hr\">
  140. <span>''' + load_lang('wiki_secret_key') + '''</span>
  141. <hr class=\"main_hr\">
  142. <input type="password" name="key" value="''' + html.escape(d_list[11]) + '''">
  143. <hr class=\"main_hr\">
  144. <span>''' + load_lang('update_branch') + '''</span>
  145. <hr class=\"main_hr\">
  146. <select name="update">''' + div3 + '''</select>
  147. <hr class=\"main_hr\">
  148. <span>''' + load_lang('encryption_method') + '''</span>
  149. <hr class=\"main_hr\">
  150. <select name="encode">''' + div5 + '''</select>
  151. <hr class=\"main_hr\">
  152. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  153. </form>
  154. ''',
  155. menu = [['setting', load_lang('return')]]
  156. ))
  157. elif num == 2:
  158. i_list = ['contract', 'no_login_warring', 'edit_bottom_text']
  159. if flask.request.method == 'POST':
  160. for i in i_list:
  161. curs.execute("update other set data = ? where name = ?", [flask.request.form.get(i, ''), i])
  162. conn.commit()
  163. admin_check(None, 'edit_set')
  164. return redirect('/setting/2')
  165. else:
  166. n_list = ['', '', '']
  167. d_list = []
  168. x = 0
  169. for i in i_list:
  170. curs.execute('select data from other where name = ?', [i])
  171. sql_d = curs.fetchall()
  172. if sql_d:
  173. d_list += [sql_d[0][0]]
  174. else:
  175. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  176. d_list += [n_list[x]]
  177. x += 1
  178. conn.commit()
  179. return easy_minify(flask.render_template(skin_check(),
  180. imp = [load_lang('text_setting'), wiki_set(), custom(), other2([0, 0])],
  181. data = '''
  182. <form method="post">
  183. <span>''' + load_lang('register_text') + ''' (HTML)</span>
  184. <hr class=\"main_hr\">
  185. <input type="text" name="contract" value="''' + html.escape(d_list[0]) + '''">
  186. <hr class=\"main_hr\">
  187. <span>''' + load_lang('non_login_alert') + ''' (HTML)</span>
  188. <hr class=\"main_hr\">
  189. <input type="text" name="no_login_warring" value="''' + html.escape(d_list[1]) + '''">
  190. <hr class=\"main_hr\">
  191. <span>''' + load_lang('edit_bottom_text') + ''' (HTML)</span>
  192. <hr class=\"main_hr\">
  193. <input type="text" name="edit_bottom_text" value="''' + html.escape(d_list[2]) + '''">
  194. <hr class=\"main_hr\">
  195. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  196. </form>
  197. ''',
  198. menu = [['setting', load_lang('return')]]
  199. ))
  200. elif num == 3 or num == 4:
  201. if flask.request.method == 'POST':
  202. if num == 4:
  203. info_d = 'body'
  204. end_r = '4'
  205. coverage = ''
  206. else:
  207. info_d = 'head'
  208. end_r = '3'
  209. if flask.request.args.get('skin', '') == '':
  210. coverage = ''
  211. else:
  212. coverage = flask.request.args.get('skin', '')
  213. curs.execute("select name from other where name = ? and coverage = ?", [info_d, coverage])
  214. if curs.fetchall():
  215. curs.execute("update other set data = ? where name = ? and coverage = ?", [
  216. flask.request.form.get('content', ''),
  217. info_d,
  218. coverage
  219. ])
  220. else:
  221. curs.execute("insert into other (name, data, coverage) values (?, ?, ?)", [info_d, flask.request.form.get('content', ''), coverage])
  222. conn.commit()
  223. admin_check(None, 'edit_set')
  224. return redirect('/setting/' + end_r + '?skin=' + flask.request.args.get('skin', ''))
  225. else:
  226. if num == 4:
  227. curs.execute("select data from other where name = 'body'")
  228. title = '_body'
  229. start = ''
  230. else:
  231. curs.execute("select data from other where name = 'head' and coverage = ?", [flask.request.args.get('skin', '')])
  232. title = '_head'
  233. start = '<a href="?">(' + load_lang('all') + ')</a> ' + \
  234. ' '.join(['<a href="?skin=' + i + '">(' + i + ')</a>' for i in load_skin('', 1)]) + \
  235. '''
  236. <hr class=\"main_hr\">
  237. <span>&lt;style&gt;CSS&lt;/style&gt;<br>&lt;script&gt;JS&lt;/script&gt;</span><hr class=\"main_hr\">
  238. '''
  239. head = curs.fetchall()
  240. if head:
  241. data = head[0][0]
  242. else:
  243. data = ''
  244. return easy_minify(flask.render_template(skin_check(),
  245. imp = [load_lang(data = 'main' + title, safe = 1), wiki_set(), custom(), other2([0, 0])],
  246. data = '''
  247. <form method="post">
  248. ''' + start + '''
  249. <textarea rows="25" name="content">''' + html.escape(data) + '''</textarea>
  250. <hr class=\"main_hr\">
  251. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  252. </form>
  253. ''',
  254. menu = [['setting', load_lang('return')]]
  255. ))
  256. elif num == 5:
  257. if flask.request.method == 'POST':
  258. curs.execute("select name from other where name = 'robot'")
  259. if curs.fetchall():
  260. curs.execute("update other set data = ? where name = 'robot'", [flask.request.form.get('content', '')])
  261. else:
  262. curs.execute("insert into other (name, data) values ('robot', ?)", [flask.request.form.get('content', '')])
  263. conn.commit()
  264. fw = open('./robots.txt', 'w')
  265. fw.write(re.sub('\r\n', '\n', flask.request.form.get('content', '')))
  266. fw.close()
  267. admin_check(None, 'edit_set')
  268. return redirect('/setting/4')
  269. else:
  270. curs.execute("select data from other where name = 'robot'")
  271. robot = curs.fetchall()
  272. if robot:
  273. data = robot[0][0]
  274. else:
  275. data = ''
  276. f = open('./robots.txt', 'r')
  277. lines = f.readlines()
  278. f.close()
  279. if not data or data == '':
  280. data = ''.join(lines)
  281. return easy_minify(flask.render_template(skin_check(),
  282. imp = ['robots.txt', wiki_set(), custom(), other2([0, 0])],
  283. data = '''
  284. <a href="/robots.txt">(view)</a>
  285. <hr class=\"main_hr\">
  286. <form method="post">
  287. <textarea rows="25" name="content">''' + html.escape(data) + '''</textarea>
  288. <hr class=\"main_hr\">
  289. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  290. </form>
  291. ''',
  292. menu = [['setting', load_lang('return')]]
  293. ))
  294. elif num == 6:
  295. i_list = ['recaptcha', 'sec_re', 'g_email', 'g_pass']
  296. if flask.request.method == 'POST':
  297. for data in i_list:
  298. if data == 'g_email':
  299. into_data = re.sub('@.*$', '', flask.request.form.get(data, ''))
  300. else:
  301. into_data = flask.request.form.get(data, '')
  302. curs.execute("update other set data = ? where name = ?", [into_data, data])
  303. conn.commit()
  304. admin_check(None, 'edit_set')
  305. return redirect('/setting/6')
  306. else:
  307. n_list = ['', '', '', '']
  308. d_list = []
  309. x = 0
  310. for i in i_list:
  311. curs.execute('select data from other where name = ?', [i])
  312. sql_d = curs.fetchall()
  313. if sql_d:
  314. d_list += [sql_d[0][0]]
  315. else:
  316. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  317. d_list += [n_list[x]]
  318. x += 1
  319. conn.commit()
  320. return easy_minify(flask.render_template(skin_check(),
  321. imp = ['Google', wiki_set(), custom(), other2([0, 0])],
  322. data = '''
  323. <form method="post">
  324. <h2><a href="https://www.google.com/recaptcha/admin">recaptcha</a></h2>
  325. <span>''' + load_lang('recaptcha') + ''' (HTML)</span>
  326. <hr class=\"main_hr\">
  327. <input placeholder="''' + load_lang('recaptcha') + ''' (HTML)" type="text" name="recaptcha" value="''' + html.escape(d_list[0]) + '''">
  328. <hr class=\"main_hr\">
  329. <span>''' + load_lang('recaptcha') + ' (' + load_lang('secret_key') + ''')</span>
  330. <hr class=\"main_hr\">
  331. <input placeholder="''' + load_lang('recaptcha') + ' (' + load_lang('secret_key') + ''')" type="text" name="sec_re" value="''' + html.escape(d_list[1]) + '''">
  332. <hr class=\"main_hr\">
  333. <h2><a href="https://support.google.com/mail/answer/7126229">''' + load_lang('google_imap') + '</a> {' + load_lang('restart_required') + '''}</h1>
  334. <span>''' + load_lang('google_email') + '''</span>
  335. <hr class=\"main_hr\">
  336. <input placeholder="''' + load_lang('google_email') + '''" type="text" name="g_email" value="''' + html.escape(d_list[2]) + '''">
  337. <hr class=\"main_hr\">
  338. <span><a href="https://security.google.com/settings/security/apppasswords">''' + load_lang('google_app_password') + '''</a></span>
  339. <hr class=\"main_hr\">
  340. <input placeholder="''' + load_lang('google_app_password') + '''" type="password" name="g_pass" value="''' + html.escape(d_list[3]) + '''">
  341. <hr class=\"main_hr\">
  342. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  343. </form>
  344. ''',
  345. menu = [['setting', load_lang('return')]]
  346. ))
  347. else:
  348. return redirect()