setting.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. <br>
  92. <br>
  93. <input placeholder="''' + load_lang('wiki_name') + '''" type="text" name="name" value="''' + html.escape(d_list[0]) + '''">
  94. <hr class=\"main_hr\">
  95. <span>''' + load_lang('wiki_logo') + ''' (HTML)</span>
  96. <br>
  97. <br>
  98. <input placeholder="''' + load_lang('wiki_logo') + '''" type="text" name="logo" value="''' + html.escape(d_list[1]) + '''">
  99. <hr class=\"main_hr\">
  100. <span>''' + load_lang('main_page') + '''</span>
  101. <br>
  102. <br>
  103. <input placeholder="''' + load_lang('main_page') + '''" type="text" name="frontpage" value="''' + html.escape(d_list[2]) + '''">
  104. <hr class=\"main_hr\">
  105. <span>''' + load_lang('bottom_text') + ''' (HTML)</span>
  106. <br>
  107. <br>
  108. <input placeholder="''' + load_lang('bottom_text') + '''" type="text" name="license" value="''' + html.escape(d_list[3]) + '''">
  109. <hr class=\"main_hr\">
  110. <span>''' + load_lang('max_file_size') + ''' [MB]</span>
  111. <br>
  112. <br>
  113. <input placeholder="''' + load_lang('max_file_size') + '''" type="text" name="upload" value="''' + html.escape(d_list[4]) + '''">
  114. <hr class=\"main_hr\">
  115. <span>''' + load_lang('backup_interval') + ' [' + load_lang('hour') + '''] (off : 0) {restart}</span>
  116. <br>
  117. <br>
  118. <input placeholder="''' + load_lang('backup_interval') + '''" type="text" name="back_up" value="''' + html.escape(d_list[9]) + '''">
  119. <hr class=\"main_hr\">
  120. <span>''' + load_lang('wiki_skin') + '''</span>
  121. <br>
  122. <br>
  123. <select name="skin">''' + div2 + '''</select>
  124. <hr class=\"main_hr\">
  125. <span>''' + load_lang('default_acl') + '''</span>
  126. <br>
  127. <br>
  128. <select name="edit">''' + div + '''</select>
  129. <hr class=\"main_hr\">
  130. <span>''' + load_lang('default_discussion_acl') + '''</span>
  131. <br>
  132. <br>
  133. <select name="discussion">''' + div4 + '''</select>
  134. <hr class=\"main_hr\">
  135. <input type="checkbox" name="reg" ''' + ch_1 + '''> ''' + load_lang('no_register') + '''
  136. <hr class=\"main_hr\">
  137. <input type="checkbox" name="ip_view" ''' + ch_2 + '''> ''' + load_lang('hide_ip') + '''
  138. <hr class=\"main_hr\">
  139. <input type="checkbox" name="email_have" ''' + ch_3 + '''> ''' + load_lang('email_required') + ''' {<a href="/setting/5">''' + load_lang('google_imap_required') + '''</a>}
  140. <hr class=\"main_hr\">
  141. <span>''' + load_lang('wiki_host') + '''</span>
  142. <br>
  143. <br>
  144. <input placeholder="''' + load_lang('wiki_host') + '''" type="text" name="host" value="''' + html.escape(d_list[16]) + '''">
  145. <hr class=\"main_hr\">
  146. <span>''' + load_lang('wiki_port') + '''</span>
  147. <br>
  148. <br>
  149. <input placeholder="''' + load_lang('wiki_port') + '''" type="text" name="port" value="''' + html.escape(d_list[10]) + '''">
  150. <hr class=\"main_hr\">
  151. <span>''' + load_lang('wiki_secret_key') + '''</span>
  152. <br>
  153. <br>
  154. <input placeholder="''' + load_lang('wiki_secret_key') + '''" type="password" name="key" value="''' + html.escape(d_list[11]) + '''">
  155. <hr class=\"main_hr\">
  156. <span>''' + load_lang('update_branch') + '''</span>
  157. <br>
  158. <br>
  159. <select name="update">''' + div3 + '''</select>
  160. <hr class=\"main_hr\">
  161. <span>encryption method</span>
  162. <br>
  163. <br>
  164. <select name="encode">''' + div5 + '''</select>
  165. <hr class=\"main_hr\">
  166. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  167. </form>
  168. ''',
  169. menu = [['setting', load_lang('return')]]
  170. ))
  171. elif num == 2:
  172. if flask.request.method == 'POST':
  173. curs.execute("update other set data = ? where name = ?", [flask.request.form.get('contract', None), 'contract'])
  174. curs.execute("update other set data = ? where name = ?", [flask.request.form.get('no_login_warring', None), 'no_login_warring'])
  175. conn.commit()
  176. admin_check(None, 'edit_set')
  177. return redirect('/setting/2')
  178. else:
  179. i_list = ['contract', 'no_login_warring']
  180. n_list = ['', '']
  181. d_list = []
  182. x = 0
  183. for i in i_list:
  184. curs.execute('select data from other where name = ?', [i])
  185. sql_d = curs.fetchall()
  186. if sql_d:
  187. d_list += [sql_d[0][0]]
  188. else:
  189. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  190. d_list += [n_list[x]]
  191. x += 1
  192. conn.commit()
  193. return easy_minify(flask.render_template(skin_check(),
  194. imp = [load_lang('text_setting'), wiki_set(), custom(), other2([0, 0])],
  195. data = '''
  196. <form method="post">
  197. <span>''' + load_lang('register_text') + '''</span>
  198. <br>
  199. <br>
  200. <input placeholder="''' + load_lang('register_text') + '''" type="text" name="contract" value="''' + html.escape(d_list[0]) + '''">
  201. <hr class=\"main_hr\">
  202. <span>''' + load_lang('non_login_alert') + '''</span>
  203. <br>
  204. <br>
  205. <input placeholder="''' + load_lang('non_login_alert') + '''" type="text" name="no_login_warring" value="''' + html.escape(d_list[1]) + '''">
  206. <hr class=\"main_hr\">
  207. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  208. </form>
  209. ''',
  210. menu = [['setting', load_lang('return')]]
  211. ))
  212. elif num == 3 or num == 4:
  213. if flask.request.method == 'POST':
  214. if num == 4:
  215. info_d = 'body'
  216. end_r = '4'
  217. else:
  218. info_d = 'head'
  219. end_r = '3'
  220. curs.execute("select name from other where name = ?", [info_d])
  221. if curs.fetchall():
  222. curs.execute("update other set data = ? where name = ?", [flask.request.form.get('content', ''), info_d])
  223. else:
  224. curs.execute("insert into other (name, data) values (?, ?)", [info_d, flask.request.form.get('content', '')])
  225. conn.commit()
  226. admin_check(None, 'edit_set')
  227. return redirect('/setting/' + end_r)
  228. else:
  229. if num == 4:
  230. curs.execute("select data from other where name = 'body'")
  231. title = '_body'
  232. start = ''
  233. else:
  234. curs.execute("select data from other where name = 'head'")
  235. title = '_head'
  236. start = '<span>&lt;style&gt;CSS&lt;/style&gt;<br>&lt;script&gt;JS&lt;/script&gt;</span><hr class=\"main_hr\">'
  237. head = curs.fetchall()
  238. if head:
  239. data = head[0][0]
  240. else:
  241. data = ''
  242. return easy_minify(flask.render_template(skin_check(),
  243. imp = [load_lang(data = 'main' + title, safe = 1), wiki_set(), custom(), other2([0, 0])],
  244. data = '''
  245. <form method="post">
  246. ''' + start + '''
  247. <textarea rows="25" name="content">''' + html.escape(data) + '''</textarea>
  248. <hr class=\"main_hr\">
  249. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  250. </form>
  251. ''',
  252. menu = [['setting', load_lang('return')]]
  253. ))
  254. elif num == 5:
  255. if flask.request.method == 'POST':
  256. curs.execute("select name from other where name = 'robot'")
  257. if curs.fetchall():
  258. curs.execute("update other set data = ? where name = 'robot'", [flask.request.form.get('content', None)])
  259. else:
  260. curs.execute("insert into other (name, data) values ('robot', ?)", [flask.request.form.get('content', None)])
  261. conn.commit()
  262. fw = open('./robots.txt', 'w')
  263. fw.write(re.sub('\r\n', '\n', flask.request.form.get('content', None)))
  264. fw.close()
  265. admin_check(None, 'edit_set')
  266. return redirect('/setting/4')
  267. else:
  268. curs.execute("select data from other where name = 'robot'")
  269. robot = curs.fetchall()
  270. if robot:
  271. data = robot[0][0]
  272. else:
  273. data = ''
  274. f = open('./robots.txt', 'r')
  275. lines = f.readlines()
  276. f.close()
  277. if not data or data == '':
  278. data = ''.join(lines)
  279. return easy_minify(flask.render_template(skin_check(),
  280. imp = ['robots.txt', wiki_set(), custom(), other2([0, 0])],
  281. data = '''
  282. <a href="/robots.txt">(view)</a>
  283. <hr class=\"main_hr\">
  284. <form method="post">
  285. <textarea rows="25" name="content">''' + html.escape(data) + '''</textarea>
  286. <hr class=\"main_hr\">
  287. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  288. </form>
  289. ''',
  290. menu = [['setting', load_lang('return')]]
  291. ))
  292. elif num == 6:
  293. i_list = ['recaptcha', 'sec_re', 'g_email', 'g_pass']
  294. if flask.request.method == 'POST':
  295. for data in i_list:
  296. curs.execute("update other set data = ? where name = ?", [flask.request.form.get(data, ''), data])
  297. conn.commit()
  298. admin_check(None, 'edit_set')
  299. return redirect('/setting/5')
  300. else:
  301. n_list = ['', '', '', '']
  302. d_list = []
  303. x = 0
  304. for i in i_list:
  305. curs.execute('select data from other where name = ?', [i])
  306. sql_d = curs.fetchall()
  307. if sql_d:
  308. d_list += [sql_d[0][0]]
  309. else:
  310. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  311. d_list += [n_list[x]]
  312. x += 1
  313. conn.commit()
  314. return easy_minify(flask.render_template(skin_check(),
  315. imp = ['google', wiki_set(), custom(), other2([0, 0])],
  316. data = '''
  317. <form method="post">
  318. <h2><a href="https://www.google.com/recaptcha/admin">recaptcha</a></h2>
  319. <span>''' + load_lang('recaptcha') + ''' (HTML)</span>
  320. <br>
  321. <br>
  322. <input placeholder="''' + load_lang('recaptcha') + ''' (HTML)" type="text" name="recaptcha" value="''' + html.escape(d_list[0]) + '''">
  323. <hr class=\"main_hr\">
  324. <span>''' + load_lang('recaptcha') + ' (' + load_lang('secret_key') + ''')</span>
  325. <br>
  326. <br>
  327. <input placeholder="''' + load_lang('recaptcha') + ' (' + load_lang('secret_key') + ''')" type="text" name="sec_re" value="''' + html.escape(d_list[1]) + '''">
  328. <hr class=\"main_hr\">
  329. <h2><a href="https://support.google.com/mail/answer/7126229">''' + load_lang('google_imap') + '</a> {' + load_lang('restart_required') + '''}</h1>
  330. <span>''' + load_lang('google_email') + '''</span>
  331. <br>
  332. <br>
  333. <input placeholder="''' + load_lang('google_email') + '''" type="text" name="g_email" value="''' + html.escape(d_list[2]) + '''">
  334. <hr class=\"main_hr\">
  335. <span><a href="https://security.google.com/settings/security/apppasswords">''' + load_lang('google_app_password') + '''</a></span>
  336. <br>
  337. <br>
  338. <input placeholder="''' + load_lang('google_app_password') + '''" type="password" name="g_pass" value="''' + html.escape(d_list[3]) + '''">
  339. <hr class=\"main_hr\">
  340. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  341. </form>
  342. ''',
  343. menu = [['setting', load_lang('return')]]
  344. ))
  345. else:
  346. return redirect()