2
0

setting.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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 = [
  159. 'contract',
  160. 'no_login_warring',
  161. 'edit_bottom_text',
  162. 'check_key_text',
  163. 'email_title',
  164. 'email_text',
  165. 'email_insert_text',
  166. 'password_search_text',
  167. 'reset_user_text'
  168. ]
  169. if flask.request.method == 'POST':
  170. for i in i_list:
  171. curs.execute("update other set data = ? where name = ?", [flask.request.form.get(i, ''), i])
  172. conn.commit()
  173. admin_check(None, 'edit_set')
  174. return redirect('/setting/2')
  175. else:
  176. n_list = ['', '', '', '', '', '', '', '', '']
  177. d_list = []
  178. x = 0
  179. for i in i_list:
  180. curs.execute('select data from other where name = ?', [i])
  181. sql_d = curs.fetchall()
  182. if sql_d:
  183. d_list += [sql_d[0][0]]
  184. else:
  185. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  186. d_list += [n_list[x]]
  187. x += 1
  188. conn.commit()
  189. return easy_minify(flask.render_template(skin_check(),
  190. imp = [load_lang('text_setting'), wiki_set(), custom(), other2([0, 0])],
  191. data = '''
  192. <form method="post">
  193. <span>''' + load_lang('register_text') + ''' (HTML)</span>
  194. <hr class=\"main_hr\">
  195. <input type="text" name="contract" value="''' + html.escape(d_list[0]) + '''">
  196. <hr class=\"main_hr\">
  197. <span>''' + load_lang('non_login_alert') + ''' (HTML)</span>
  198. <hr class=\"main_hr\">
  199. <input type="text" name="no_login_warring" value="''' + html.escape(d_list[1]) + '''">
  200. <hr class=\"main_hr\">
  201. <span>''' + load_lang('edit_bottom_text') + ''' (HTML)</span>
  202. <hr class=\"main_hr\">
  203. <input type="text" name="edit_bottom_text" value="''' + html.escape(d_list[2]) + '''">
  204. <hr class=\"main_hr\">
  205. <span>''' + load_lang('check_key_text') + ''' (HTML)</span>
  206. <hr class=\"main_hr\">
  207. <input type="text" name="check_key_text" value="''' + html.escape(d_list[3]) + '''">
  208. <hr class=\"main_hr\">
  209. <span>''' + load_lang('email_title') + '''</span>
  210. <hr class=\"main_hr\">
  211. <input type="text" name="email_title" value="''' + html.escape(d_list[4]) + '''">
  212. <hr class=\"main_hr\">
  213. <span>''' + load_lang('email_text') + '''</span>
  214. <hr class=\"main_hr\">
  215. <input type="text" name="email_text" value="''' + html.escape(d_list[5]) + '''">
  216. <hr class=\"main_hr\">
  217. <span>''' + load_lang('email_insert_text') + '''</span>
  218. <hr class=\"main_hr\">
  219. <input type="text" name="email_insert_text" value="''' + html.escape(d_list[6]) + '''">
  220. <hr class=\"main_hr\">
  221. <span>''' + load_lang('password_search_text') + '''</span>
  222. <hr class=\"main_hr\">
  223. <input type="text" name="password_search_text" value="''' + html.escape(d_list[7]) + '''">
  224. <hr class=\"main_hr\">
  225. <span>''' + load_lang('reset_user_text') + '''</span>
  226. <hr class=\"main_hr\">
  227. <input type="text" name="reset_user_text" value="''' + html.escape(d_list[8]) + '''">
  228. <hr class=\"main_hr\">
  229. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  230. </form>
  231. ''',
  232. menu = [['setting', load_lang('return')]]
  233. ))
  234. elif num == 3 or num == 4:
  235. if flask.request.method == 'POST':
  236. if num == 4:
  237. info_d = 'body'
  238. end_r = '4'
  239. coverage = ''
  240. else:
  241. info_d = 'head'
  242. end_r = '3'
  243. if flask.request.args.get('skin', '') == '':
  244. coverage = ''
  245. else:
  246. coverage = flask.request.args.get('skin', '')
  247. curs.execute("select name from other where name = ? and coverage = ?", [info_d, coverage])
  248. if curs.fetchall():
  249. curs.execute("update other set data = ? where name = ? and coverage = ?", [
  250. flask.request.form.get('content', ''),
  251. info_d,
  252. coverage
  253. ])
  254. else:
  255. curs.execute("insert into other (name, data, coverage) values (?, ?, ?)", [info_d, flask.request.form.get('content', ''), coverage])
  256. conn.commit()
  257. admin_check(None, 'edit_set')
  258. return redirect('/setting/' + end_r + '?skin=' + flask.request.args.get('skin', ''))
  259. else:
  260. if num == 4:
  261. curs.execute("select data from other where name = 'body'")
  262. title = '_body'
  263. start = ''
  264. else:
  265. curs.execute("select data from other where name = 'head' and coverage = ?", [flask.request.args.get('skin', '')])
  266. title = '_head'
  267. start = '<a href="?">(' + load_lang('all') + ')</a> ' + \
  268. ' '.join(['<a href="?skin=' + i + '">(' + i + ')</a>' for i in load_skin('', 1)]) + \
  269. '''
  270. <hr class=\"main_hr\">
  271. <span>&lt;style&gt;CSS&lt;/style&gt;<br>&lt;script&gt;JS&lt;/script&gt;</span><hr class=\"main_hr\">
  272. '''
  273. head = curs.fetchall()
  274. if head:
  275. data = head[0][0]
  276. else:
  277. data = ''
  278. return easy_minify(flask.render_template(skin_check(),
  279. imp = [load_lang(data = 'main' + title, safe = 1), wiki_set(), custom(), other2([0, 0])],
  280. data = '''
  281. <form method="post">
  282. ''' + start + '''
  283. <textarea rows="25" name="content">''' + html.escape(data) + '''</textarea>
  284. <hr class=\"main_hr\">
  285. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  286. </form>
  287. ''',
  288. menu = [['setting', load_lang('return')]]
  289. ))
  290. elif num == 5:
  291. if flask.request.method == 'POST':
  292. curs.execute("select name from other where name = 'robot'")
  293. if curs.fetchall():
  294. curs.execute("update other set data = ? where name = 'robot'", [flask.request.form.get('content', '')])
  295. else:
  296. curs.execute("insert into other (name, data) values ('robot', ?)", [flask.request.form.get('content', '')])
  297. conn.commit()
  298. fw = open('./robots.txt', 'w')
  299. fw.write(re.sub('\r\n', '\n', flask.request.form.get('content', '')))
  300. fw.close()
  301. admin_check(None, 'edit_set')
  302. return redirect('/setting/4')
  303. else:
  304. curs.execute("select data from other where name = 'robot'")
  305. robot = curs.fetchall()
  306. if robot:
  307. data = robot[0][0]
  308. else:
  309. data = ''
  310. f = open('./robots.txt', 'r')
  311. lines = f.readlines()
  312. f.close()
  313. if not data or data == '':
  314. data = ''.join(lines)
  315. return easy_minify(flask.render_template(skin_check(),
  316. imp = ['robots.txt', wiki_set(), custom(), other2([0, 0])],
  317. data = '''
  318. <a href="/robots.txt">(view)</a>
  319. <hr class=\"main_hr\">
  320. <form method="post">
  321. <textarea rows="25" name="content">''' + html.escape(data) + '''</textarea>
  322. <hr class=\"main_hr\">
  323. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  324. </form>
  325. ''',
  326. menu = [['setting', load_lang('return')]]
  327. ))
  328. elif num == 6:
  329. i_list = ['recaptcha', 'sec_re', 'g_email', 'g_pass']
  330. if flask.request.method == 'POST':
  331. for data in i_list:
  332. if data == 'g_email':
  333. into_data = re.sub('@.*$', '', flask.request.form.get(data, ''))
  334. else:
  335. into_data = flask.request.form.get(data, '')
  336. curs.execute("update other set data = ? where name = ?", [into_data, data])
  337. conn.commit()
  338. admin_check(None, 'edit_set')
  339. return redirect('/setting/6')
  340. else:
  341. n_list = ['', '', '', '']
  342. d_list = []
  343. x = 0
  344. for i in i_list:
  345. curs.execute('select data from other where name = ?', [i])
  346. sql_d = curs.fetchall()
  347. if sql_d:
  348. d_list += [sql_d[0][0]]
  349. else:
  350. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  351. d_list += [n_list[x]]
  352. x += 1
  353. conn.commit()
  354. return easy_minify(flask.render_template(skin_check(),
  355. imp = ['Google', wiki_set(), custom(), other2([0, 0])],
  356. data = '''
  357. <form method="post">
  358. <h2><a href="https://www.google.com/recaptcha/admin">recaptcha</a></h2>
  359. <span>''' + load_lang('recaptcha') + ''' (HTML)</span>
  360. <hr class=\"main_hr\">
  361. <input placeholder="''' + load_lang('recaptcha') + ''' (HTML)" type="text" name="recaptcha" value="''' + html.escape(d_list[0]) + '''">
  362. <hr class=\"main_hr\">
  363. <span>''' + load_lang('recaptcha') + ' (' + load_lang('secret_key') + ''')</span>
  364. <hr class=\"main_hr\">
  365. <input placeholder="''' + load_lang('recaptcha') + ' (' + load_lang('secret_key') + ''')" type="text" name="sec_re" value="''' + html.escape(d_list[1]) + '''">
  366. <hr class=\"main_hr\">
  367. <h2><a href="https://support.google.com/mail/answer/7126229">''' + load_lang('google_imap') + '</a> {' + load_lang('restart_required') + '''}</h1>
  368. <span>''' + load_lang('google_email') + '''</span>
  369. <hr class=\"main_hr\">
  370. <input placeholder="''' + load_lang('google_email') + '''" type="text" name="g_email" value="''' + html.escape(d_list[2]) + '''">
  371. <hr class=\"main_hr\">
  372. <span><a href="https://security.google.com/settings/security/apppasswords">''' + load_lang('google_app_password') + '''</a></span>
  373. <hr class=\"main_hr\">
  374. <input placeholder="''' + load_lang('google_app_password') + '''" type="password" name="g_pass" value="''' + html.escape(d_list[3]) + '''">
  375. <hr class=\"main_hr\">
  376. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  377. </form>
  378. ''',
  379. menu = [['setting', load_lang('return')]]
  380. ))
  381. else:
  382. return redirect()