setting.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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>''' + load_lang('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', ''), 'contract'])
  174. curs.execute("update other set data = ? where name = ?", [flask.request.form.get('no_login_warring', ''), '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. coverage = ''
  218. else:
  219. info_d = 'head'
  220. end_r = '3'
  221. if flask.request.args.get('skin', '') == '':
  222. coverage = ''
  223. else:
  224. coverage = flask.request.args.get('skin', '')
  225. curs.execute("select name from other where name = ? and coverage = ?", [info_d, coverage])
  226. if curs.fetchall():
  227. curs.execute("update other set data = ? where name = ? and coverage = ?", [
  228. flask.request.form.get('content', ''),
  229. info_d,
  230. coverage
  231. ])
  232. else:
  233. curs.execute("insert into other (name, data, coverage) values (?, ?, ?)", [info_d, flask.request.form.get('content', ''), coverage])
  234. conn.commit()
  235. admin_check(None, 'edit_set')
  236. return redirect('/setting/' + end_r + '?skin=' + flask.request.args.get('skin', ''))
  237. else:
  238. if num == 4:
  239. curs.execute("select data from other where name = 'body'")
  240. title = '_body'
  241. start = ''
  242. else:
  243. curs.execute("select data from other where name = 'head' and coverage = ?", [flask.request.args.get('skin', '')])
  244. title = '_head'
  245. start = '<a href="?">(' + load_lang('all') + ')</a> ' + \
  246. ' '.join(['<a href="?skin=' + i + '">(' + i + ')</a>' for i in load_skin('', 1)]) + \
  247. '''
  248. <hr class=\"main_hr\">
  249. <span>&lt;style&gt;CSS&lt;/style&gt;<br>&lt;script&gt;JS&lt;/script&gt;</span><hr class=\"main_hr\">
  250. '''
  251. head = curs.fetchall()
  252. if head:
  253. data = head[0][0]
  254. else:
  255. data = ''
  256. return easy_minify(flask.render_template(skin_check(),
  257. imp = [load_lang(data = 'main' + title, safe = 1), wiki_set(), custom(), other2([0, 0])],
  258. data = '''
  259. <form method="post">
  260. ''' + start + '''
  261. <textarea rows="25" name="content">''' + html.escape(data) + '''</textarea>
  262. <hr class=\"main_hr\">
  263. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  264. </form>
  265. ''',
  266. menu = [['setting', load_lang('return')]]
  267. ))
  268. elif num == 5:
  269. if flask.request.method == 'POST':
  270. curs.execute("select name from other where name = 'robot'")
  271. if curs.fetchall():
  272. curs.execute("update other set data = ? where name = 'robot'", [flask.request.form.get('content', '')])
  273. else:
  274. curs.execute("insert into other (name, data) values ('robot', ?)", [flask.request.form.get('content', '')])
  275. conn.commit()
  276. fw = open('./robots.txt', 'w')
  277. fw.write(re.sub('\r\n', '\n', flask.request.form.get('content', '')))
  278. fw.close()
  279. admin_check(None, 'edit_set')
  280. return redirect('/setting/4')
  281. else:
  282. curs.execute("select data from other where name = 'robot'")
  283. robot = curs.fetchall()
  284. if robot:
  285. data = robot[0][0]
  286. else:
  287. data = ''
  288. f = open('./robots.txt', 'r')
  289. lines = f.readlines()
  290. f.close()
  291. if not data or data == '':
  292. data = ''.join(lines)
  293. return easy_minify(flask.render_template(skin_check(),
  294. imp = ['robots.txt', wiki_set(), custom(), other2([0, 0])],
  295. data = '''
  296. <a href="/robots.txt">(view)</a>
  297. <hr class=\"main_hr\">
  298. <form method="post">
  299. <textarea rows="25" name="content">''' + html.escape(data) + '''</textarea>
  300. <hr class=\"main_hr\">
  301. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  302. </form>
  303. ''',
  304. menu = [['setting', load_lang('return')]]
  305. ))
  306. elif num == 6:
  307. i_list = ['recaptcha', 'sec_re', 'g_email', 'g_pass']
  308. if flask.request.method == 'POST':
  309. for data in i_list:
  310. if data == 'g_email':
  311. into_data = re.sub('@.*$', '', flask.request.form.get(data, ''))
  312. else:
  313. into_data = flask.request.form.get(data, '')
  314. curs.execute("update other set data = ? where name = ?", [into_data, data])
  315. conn.commit()
  316. admin_check(None, 'edit_set')
  317. return redirect('/setting/6')
  318. else:
  319. n_list = ['', '', '', '']
  320. d_list = []
  321. x = 0
  322. for i in i_list:
  323. curs.execute('select data from other where name = ?', [i])
  324. sql_d = curs.fetchall()
  325. if sql_d:
  326. d_list += [sql_d[0][0]]
  327. else:
  328. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  329. d_list += [n_list[x]]
  330. x += 1
  331. conn.commit()
  332. return easy_minify(flask.render_template(skin_check(),
  333. imp = ['Google', wiki_set(), custom(), other2([0, 0])],
  334. data = '''
  335. <form method="post">
  336. <h2><a href="https://www.google.com/recaptcha/admin">recaptcha</a></h2>
  337. <span>''' + load_lang('recaptcha') + ''' (HTML)</span>
  338. <br>
  339. <br>
  340. <input placeholder="''' + load_lang('recaptcha') + ''' (HTML)" type="text" name="recaptcha" value="''' + html.escape(d_list[0]) + '''">
  341. <hr class=\"main_hr\">
  342. <span>''' + load_lang('recaptcha') + ' (' + load_lang('secret_key') + ''')</span>
  343. <br>
  344. <br>
  345. <input placeholder="''' + load_lang('recaptcha') + ' (' + load_lang('secret_key') + ''')" type="text" name="sec_re" value="''' + html.escape(d_list[1]) + '''">
  346. <hr class=\"main_hr\">
  347. <h2><a href="https://support.google.com/mail/answer/7126229">''' + load_lang('google_imap') + '</a> {' + load_lang('restart_required') + '''}</h1>
  348. <span>''' + load_lang('google_email') + '''</span>
  349. <br>
  350. <br>
  351. <input placeholder="''' + load_lang('google_email') + '''" type="text" name="g_email" value="''' + html.escape(d_list[2]) + '''">
  352. <hr class=\"main_hr\">
  353. <span><a href="https://security.google.com/settings/security/apppasswords">''' + load_lang('google_app_password') + '''</a></span>
  354. <br>
  355. <br>
  356. <input placeholder="''' + load_lang('google_app_password') + '''" type="password" name="g_pass" value="''' + html.escape(d_list[3]) + '''">
  357. <hr class=\"main_hr\">
  358. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  359. </form>
  360. ''',
  361. menu = [['setting', load_lang('return')]]
  362. ))
  363. else:
  364. return redirect()