setting.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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. load_lang('main_bottom_body'),
  15. load_lang('main_acl_setting'),
  16. load_lang('oauth_setting')
  17. ]
  18. x = 0
  19. li_data = ''
  20. for li in li_list:
  21. x += 1
  22. li_data += '<li><a href="/setting/' + str(x) + '">' + li + '</a></li>'
  23. return easy_minify(flask.render_template(skin_check(),
  24. imp = [load_lang('setting'), wiki_set(), custom(), other2([0, 0])],
  25. data = '<h2>' + load_lang('list') + '</h2><ul>' + li_data + '</ul>',
  26. menu = [['manager', load_lang('return')]]
  27. ))
  28. elif num == 1:
  29. i_list = {
  30. 0 : 'name',
  31. 1 : 'logo',
  32. 2 : 'frontpage',
  33. 3 : 'license',
  34. 4 : 'upload',
  35. 5 : 'skin',
  36. 7 : 'reg',
  37. 8 : 'ip_view',
  38. 9 : 'back_up',
  39. 10 : 'port',
  40. 11 : 'key',
  41. 12 : 'update',
  42. 13 : 'email_have',
  43. 15 : 'encode',
  44. 16 : 'host',
  45. 19 : 'slow_edit',
  46. 20 : 'requires_approval',
  47. }
  48. n_list = {
  49. 0 : 'Wiki',
  50. 1 : '',
  51. 2 : 'FrontPage',
  52. 3 : 'CC 0',
  53. 4 : '2',
  54. 5 : '',
  55. 7 : '',
  56. 8 : '',
  57. 9 : '0',
  58. 10 : '3000',
  59. 11 : 'test',
  60. 12 : 'stable',
  61. 13 : '',
  62. 15 : 'sha3',
  63. 16 : '0.0.0.0',
  64. 19 : '0',
  65. 20 : ''
  66. }
  67. if flask.request.method == 'POST':
  68. for i in i_list:
  69. curs.execute(db_change("update other set data = ? where name = ?"), [
  70. flask.request.form.get(i_list[i], n_list[i]),
  71. i_list[i]
  72. ])
  73. conn.commit()
  74. admin_check(None, 'edit_set')
  75. return redirect('/setting/1')
  76. else:
  77. d_list = {}
  78. for i in i_list:
  79. curs.execute(db_change('select data from other where name = ?'), [i_list[i]])
  80. sql_d = curs.fetchall()
  81. if sql_d:
  82. d_list[i] = sql_d[0][0]
  83. else:
  84. curs.execute(db_change('insert into other (name, data) values (?, ?)'), [i_list[i], n_list[i]])
  85. d_list[i] = n_list[i]
  86. conn.commit()
  87. acl_div = ['']
  88. encode_data = ['sha256', 'sha3']
  89. for acl_data in encode_data:
  90. if acl_data == d_list[15]:
  91. acl_div[0] = '<option value="' + acl_data + '">' + acl_data + '</option>' + acl_div[0]
  92. else:
  93. acl_div[0] += '<option value="' + acl_data + '">' + acl_data + '</option>'
  94. check_box_div = ['', '', '', '']
  95. for i in range(0, 4):
  96. if i == 0:
  97. acl_num = 7
  98. elif i == 1:
  99. acl_num = 8
  100. elif i == 2:
  101. acl_num = 13
  102. else:
  103. acl_num = 20
  104. if d_list[acl_num]:
  105. check_box_div[i] = 'checked="checked"'
  106. branch_div =''
  107. if d_list[12] == 'stable':
  108. branch_div += '<option value="stable">stable</option>'
  109. branch_div += '<option value="master">master</option>'
  110. else:
  111. branch_div += '<option value="master">master</option>'
  112. branch_div += '<option value="stable">stable</option>'
  113. return easy_minify(flask.render_template(skin_check(),
  114. imp = [load_lang('main_setting'), wiki_set(), custom(), other2([0, 0])],
  115. data = '''
  116. <form method="post">
  117. <span>''' + load_lang('wiki_name') + '''</span>
  118. <hr class=\"main_hr\">
  119. <input type="text" name="name" value="''' + html.escape(d_list[0]) + '''">
  120. <hr>
  121. <span>''' + load_lang('wiki_logo') + ''' (HTML)</span>
  122. <hr class=\"main_hr\">
  123. <input type="text" name="logo" value="''' + html.escape(d_list[1]) + '''">
  124. <hr>
  125. <span>''' + load_lang('main_page') + '''</span>
  126. <hr class=\"main_hr\">
  127. <input type="text" name="frontpage" value="''' + html.escape(d_list[2]) + '''">
  128. <hr>
  129. <span>''' + load_lang('bottom_text') + ''' (HTML)</span>
  130. <hr class=\"main_hr\">
  131. <input type="text" name="license" value="''' + html.escape(d_list[3]) + '''">
  132. <hr>
  133. <span>''' + load_lang('max_file_size') + ''' (MB)</span>
  134. <hr class=\"main_hr\">
  135. <input type="text" name="upload" value="''' + html.escape(d_list[4]) + '''">
  136. <hr>
  137. <span>''' + load_lang('backup_interval') + ' (' + load_lang('hour') + ') (' + load_lang('off') + ' : 0) (' + load_lang('sqlite_only') + ') (' + load_lang('restart_required') + ''')</span>
  138. <hr class=\"main_hr\">
  139. <input type="text" name="back_up" value="''' + html.escape(d_list[9]) + '''">
  140. <hr>
  141. <span>''' + load_lang('wiki_skin') + '''</span>
  142. <hr class=\"main_hr\">
  143. <select name="skin">''' + load_skin(d_list[5]) + '''</select>
  144. <hr>
  145. <input type="checkbox" name="reg" ''' + check_box_div[0] + '''> ''' + load_lang('no_register') + '''
  146. <hr>
  147. <input type="checkbox" name="ip_view" ''' + check_box_div[1] + '''> ''' + load_lang('hide_ip') + '''
  148. <hr>
  149. <input type="checkbox" name="email_have" ''' + check_box_div[2] + '''> ''' + load_lang('email_required') + ' <a href="/setting/6">(' + load_lang('google_imap_required') + ''')</a>
  150. <hr>
  151. <input type="checkbox" name="requires_approval" ''' + check_box_div[3] + '''> ''' + load_lang('requires_approval') + '''
  152. <hr>
  153. <span>''' + load_lang('wiki_host') + '''</span>
  154. <hr class=\"main_hr\">
  155. <input type="text" name="host" value="''' + html.escape(d_list[16]) + '''">
  156. <hr>
  157. <span>''' + load_lang('wiki_port') + '''</span>
  158. <hr class=\"main_hr\">
  159. <input type="text" name="port" value="''' + html.escape(d_list[10]) + '''">
  160. <hr>
  161. <span>''' + load_lang('wiki_secret_key') + '''</span>
  162. <hr class=\"main_hr\">
  163. <input type="password" name="key" value="''' + html.escape(d_list[11]) + '''">
  164. <hr>
  165. <span>''' + load_lang('update_branch') + '''</span>
  166. <hr class=\"main_hr\">
  167. <select name="update">''' + branch_div + '''</select>
  168. <hr>
  169. <span>''' + load_lang('encryption_method') + '''</span>
  170. <hr class=\"main_hr\">
  171. <select name="encode">''' + acl_div[0] + '''</select>
  172. <hr>
  173. <span>''' + load_lang('slow_edit') + ' (' + load_lang('second') + ') (' + load_lang('off') + ''' : 0)</span>
  174. <hr class=\"main_hr\">
  175. <input name="''' + i_list[19] + '''" value="''' + html.escape(d_list[19]) + '''">
  176. <hr class=\"main_hr\">
  177. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  178. </form>
  179. ''',
  180. menu = [['setting', load_lang('return')]]
  181. ))
  182. elif num == 2:
  183. i_list = [
  184. 'contract',
  185. 'no_login_warring',
  186. 'edit_bottom_text',
  187. 'check_key_text',
  188. 'email_title',
  189. 'email_text',
  190. 'email_insert_text',
  191. 'password_search_text',
  192. 'reset_user_text',
  193. 'error_401',
  194. 'error_404',
  195. 'edit_help',
  196. 'approval_question'
  197. ]
  198. if flask.request.method == 'POST':
  199. for i in i_list:
  200. curs.execute(db_change("update other set data = ? where name = ?"), [
  201. flask.request.form.get(i, ''),
  202. i
  203. ])
  204. conn.commit()
  205. admin_check(None, 'edit_set')
  206. return redirect('/setting/2')
  207. else:
  208. d_list = []
  209. for i in i_list:
  210. curs.execute(db_change('select data from other where name = ?'), [i])
  211. sql_d = curs.fetchall()
  212. if sql_d:
  213. d_list += [sql_d[0][0]]
  214. else:
  215. curs.execute(db_change('insert into other (name, data) values (?, ?)'), [i, ''])
  216. d_list += ['']
  217. conn.commit()
  218. return easy_minify(flask.render_template(skin_check(),
  219. imp = [load_lang('text_setting'), wiki_set(), custom(), other2([0, 0])],
  220. data = '''
  221. <form method="post">
  222. <span>''' + load_lang('register_text') + ''' (HTML)</span>
  223. <hr class=\"main_hr\">
  224. <input name="''' + i_list[0] + '''" value="''' + html.escape(d_list[0]) + '''">
  225. <hr>
  226. <span>''' + load_lang('non_login_alert') + ''' (HTML)</span>
  227. <hr class=\"main_hr\">
  228. <input name="''' + i_list[1] + '''" value="''' + html.escape(d_list[1]) + '''">
  229. <hr>
  230. <span>''' + load_lang('edit_bottom_text') + ''' (HTML)</span>
  231. <hr class=\"main_hr\">
  232. <input name="''' + i_list[2] + '''" value="''' + html.escape(d_list[2]) + '''">
  233. <hr>
  234. <span>''' + load_lang('check_key_text') + ''' (HTML)</span>
  235. <hr class=\"main_hr\">
  236. <input name="''' + i_list[3] + '''" value="''' + html.escape(d_list[3]) + '''">
  237. <hr>
  238. <span>''' + load_lang('email_title') + '''</span>
  239. <hr class=\"main_hr\">
  240. <input name="''' + i_list[4] + '''" value="''' + html.escape(d_list[4]) + '''">
  241. <hr>
  242. <span>''' + load_lang('email_text') + '''</span>
  243. <hr class=\"main_hr\">
  244. <input name="''' + i_list[5] + '''" value="''' + html.escape(d_list[5]) + '''">
  245. <hr>
  246. <span>''' + load_lang('email_insert_text') + '''</span>
  247. <hr class=\"main_hr\">
  248. <input name="''' + i_list[6] + '''" value="''' + html.escape(d_list[6]) + '''">
  249. <hr>
  250. <span>''' + load_lang('password_search_text') + '''</span>
  251. <hr class=\"main_hr\">
  252. <input name="''' + i_list[7] + '''" value="''' + html.escape(d_list[7]) + '''">
  253. <hr>
  254. <span>''' + load_lang('reset_user_text') + '''</span>
  255. <hr class=\"main_hr\">
  256. <input name="''' + i_list[8] + '''" value="''' + html.escape(d_list[8]) + '''">
  257. <hr>
  258. <span>''' + load_lang('error_401') + '''</span>
  259. <hr class=\"main_hr\">
  260. <input name="''' + i_list[9] + '''" value="''' + html.escape(d_list[9]) + '''">
  261. <hr>
  262. <span>''' + load_lang('error_404') + '''</span>
  263. <hr class=\"main_hr\">
  264. <input name="''' + i_list[10] + '''" value="''' + html.escape(d_list[10]) + '''">
  265. <hr>
  266. <span>''' + load_lang('edit_help') + '''</span>
  267. <hr class=\"main_hr\">
  268. <input name="''' + i_list[11] + '''" value="''' + html.escape(d_list[11]) + '''">
  269. <hr>
  270. <span>''' + load_lang('approval_question') + '''</span> <a href="#rfn-1" id="fn-1">(1)</a>
  271. <hr class=\"main_hr\">
  272. <input name="''' + i_list[12] + '''" value="''' + html.escape(d_list[12]) + '''">
  273. <hr class=\"main_hr\">
  274. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  275. <hr>
  276. <ul>
  277. <li><a href="#fn-1" id="rfn-1">(1)</a> <span>''' + load_lang('approval_question_visible_only_when_approval_on') + '''</span></li>
  278. </ul>
  279. </form>
  280. ''',
  281. menu = [['setting', load_lang('return')]]
  282. ))
  283. elif num == 3 or num == 4 or num == 7:
  284. if flask.request.method == 'POST':
  285. if num == 4:
  286. info_d = 'body'
  287. end_r = '4'
  288. coverage = ''
  289. elif num == 7:
  290. info_d = 'bottom_body'
  291. end_r = '7'
  292. coverage = ''
  293. else:
  294. info_d = 'head'
  295. end_r = '3'
  296. if flask.request.args.get('skin', '') == '':
  297. coverage = ''
  298. else:
  299. coverage = flask.request.args.get('skin', '')
  300. curs.execute(db_change("select name from other where name = ? and coverage = ?"), [info_d, coverage])
  301. if curs.fetchall():
  302. curs.execute(db_change("update other set data = ? where name = ? and coverage = ?"), [
  303. flask.request.form.get('content', ''),
  304. info_d,
  305. coverage
  306. ])
  307. else:
  308. curs.execute(db_change("insert into other (name, data, coverage) values (?, ?, ?)"), [info_d, flask.request.form.get('content', ''), coverage])
  309. conn.commit()
  310. admin_check(None, 'edit_set')
  311. return redirect('/setting/' + end_r + '?skin=' + flask.request.args.get('skin', ''))
  312. else:
  313. if num == 4:
  314. curs.execute(db_change("select data from other where name = 'body'"))
  315. title = '_body'
  316. start = ''
  317. plus = '''
  318. <button id="preview" type="button" onclick="load_raw_preview(\'content\', \'see_preview\')">''' + load_lang('preview') + '''</button>
  319. <hr class=\"main_hr\">
  320. <div id="see_preview"></div>
  321. '''
  322. elif num == 7:
  323. curs.execute(db_change("select data from other where name = 'bottom_body'"))
  324. title = '_bottom_body'
  325. start = ''
  326. plus = '''
  327. <button id="preview" type="button" onclick="load_raw_preview(\'content\', \'see_preview\')">''' + load_lang('preview') + '''</button>
  328. <hr class=\"main_hr\">
  329. <div id="see_preview"></div>
  330. '''
  331. else:
  332. curs.execute(db_change("select data from other where name = 'head' and coverage = ?"), [flask.request.args.get('skin', '')])
  333. title = '_head'
  334. start = '' + \
  335. '<a href="?">(' + load_lang('all') + ')</a> ' + \
  336. ' '.join(['<a href="?skin=' + i + '">(' + i + ')</a>' for i in load_skin('', 1)]) + '''
  337. <hr class=\"main_hr\">
  338. <span>&lt;style&gt;CSS&lt;/style&gt;<br>&lt;script&gt;JS&lt;/script&gt;</span>
  339. <hr class=\"main_hr\">
  340. '''
  341. plus = ''
  342. head = curs.fetchall()
  343. if head:
  344. data = head[0][0]
  345. else:
  346. data = ''
  347. if flask.request.args.get('skin', '') != '':
  348. sub_plus = ' (' + flask.request.args.get('skin', '') + ')'
  349. else:
  350. sub_plus = ''
  351. return easy_minify(flask.render_template(skin_check(),
  352. imp = [load_lang(data = 'main' + title, safe = 1), wiki_set(), custom(), other2([' (HTML)' + sub_plus, 0])],
  353. data = '''
  354. <form method="post">
  355. ''' + start + '''
  356. <textarea rows="25" name="content" id="content">''' + html.escape(data) + '''</textarea>
  357. <hr class=\"main_hr\">
  358. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  359. ''' + plus + '''
  360. </form>
  361. ''',
  362. menu = [['setting', load_lang('return')]]
  363. ))
  364. elif num == 5:
  365. if flask.request.method == 'POST':
  366. curs.execute(db_change("select name from other where name = 'robot'"))
  367. if curs.fetchall():
  368. curs.execute(db_change("update other set data = ? where name = 'robot'"), [flask.request.form.get('content', '')])
  369. else:
  370. curs.execute(db_change("insert into other (name, data) values ('robot', ?)"), [flask.request.form.get('content', '')])
  371. conn.commit()
  372. fw = open('./robots.txt', 'w')
  373. fw.write(re.sub('\r\n', '\n', flask.request.form.get('content', '')))
  374. fw.close()
  375. admin_check(None, 'edit_set')
  376. return redirect('/setting/5')
  377. else:
  378. if not os.path.exists('robots.txt'):
  379. curs.execute(db_change('select data from other where name = "robot"'))
  380. robot_test = curs.fetchall()
  381. if robot_test:
  382. fw_test = open('./robots.txt', 'w')
  383. fw_test.write(re.sub('\r\n', '\n', robot_test[0][0]))
  384. fw_test.close()
  385. else:
  386. fw_test = open('./robots.txt', 'w')
  387. fw_test.write('User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/')
  388. fw_test.close()
  389. curs.execute(db_change('insert into other (name, data) values ("robot", "User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/")'))
  390. curs.execute(db_change("select data from other where name = 'robot'"))
  391. robot = curs.fetchall()
  392. if robot:
  393. data = robot[0][0]
  394. else:
  395. data = ''
  396. f = open('./robots.txt', 'r')
  397. lines = f.readlines()
  398. f.close()
  399. if not data or data == '':
  400. data = ''.join(lines)
  401. return easy_minify(flask.render_template(skin_check(),
  402. imp = ['robots.txt', wiki_set(), custom(), other2([0, 0])],
  403. data = '''
  404. <a href="/robots.txt">(''' + load_lang('view') + ''')</a>
  405. <hr class=\"main_hr\">
  406. <form method="post">
  407. <textarea rows="25" name="content">''' + html.escape(data) + '''</textarea>
  408. <hr class=\"main_hr\">
  409. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  410. </form>
  411. ''',
  412. menu = [['setting', load_lang('return')]]
  413. ))
  414. elif num == 6:
  415. i_list = [
  416. 'recaptcha',
  417. 'sec_re',
  418. 'g_email',
  419. 'g_pass'
  420. ]
  421. if flask.request.method == 'POST':
  422. for data in i_list:
  423. if data == 'g_email':
  424. into_data = re.sub('@.*$', '', flask.request.form.get(data, ''))
  425. else:
  426. into_data = flask.request.form.get(data, '')
  427. curs.execute(db_change("update other set data = ? where name = ?"), [into_data, data])
  428. conn.commit()
  429. admin_check(None, 'edit_set')
  430. return redirect('/setting/6')
  431. else:
  432. d_list = []
  433. x = 0
  434. for i in i_list:
  435. curs.execute(db_change('select data from other where name = ?'), [i])
  436. sql_d = curs.fetchall()
  437. if sql_d:
  438. d_list += [sql_d[0][0]]
  439. else:
  440. curs.execute(db_change('insert into other (name, data) values (?, ?)'), [i, ''])
  441. d_list += ['']
  442. x += 1
  443. conn.commit()
  444. return easy_minify(flask.render_template(skin_check(),
  445. imp = ['Google', wiki_set(), custom(), other2([0, 0])],
  446. data = '''
  447. <form method="post">
  448. <h2><a href="https://www.google.com/recaptcha/admin">''' + load_lang('recaptcha') + '''</a></h2>
  449. <span>HTML</span>
  450. <hr class=\"main_hr\">
  451. <input name="recaptcha" placeholder='&lt;div class="g-recaptcha" data-sitekey="''' + load_lang('public_key') + '''"&gt;&lt;/div&gt;' value="''' + html.escape(d_list[0]) + '''">
  452. <hr>
  453. <span>''' + load_lang('secret_key') + '''</span>
  454. <hr class=\"main_hr\">
  455. <input name="sec_re" value="''' + html.escape(d_list[1]) + '''">
  456. <hr class=\"main_hr\">
  457. <h2><a href="https://support.google.com/mail/answer/7126229">''' + load_lang('google_imap') + '</a> (' + load_lang('restart_required') + ''')</h1>
  458. <span>''' + load_lang('google_email') + '''</span>
  459. <hr class=\"main_hr\">
  460. <input name="g_email" value="''' + html.escape(d_list[2]) + '''">
  461. <hr>
  462. <span><a href="https://security.google.com/settings/security/apppasswords">''' + load_lang('google_app_password') + '''</a></span>
  463. <hr class=\"main_hr\">
  464. <input type="password" name="g_pass" value="''' + html.escape(d_list[3]) + '''">
  465. <hr class=\"main_hr\">
  466. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  467. </form>
  468. ''',
  469. menu = [['setting', load_lang('return')]]
  470. ))
  471. elif num == 8:
  472. i_list = {
  473. 1 : 'edit',
  474. 2 : 'discussion',
  475. 3 : 'upload_acl',
  476. 4 : 'all_view_acl',
  477. 5 : 'edit_req_acl'
  478. }
  479. n_list = {
  480. 1 : 'normal',
  481. 2 : 'normal',
  482. 3 : 'normal',
  483. 4 : 'normal',
  484. 5 : 'normal'
  485. }
  486. if flask.request.method == 'POST':
  487. for i in i_list:
  488. curs.execute(db_change("update other set data = ? where name = ?"), [
  489. flask.request.form.get(i_list[i], n_list[i]),
  490. i_list[i]
  491. ])
  492. conn.commit()
  493. admin_check(None, 'edit_set')
  494. return redirect('/setting/8')
  495. else:
  496. d_list = {}
  497. for i in i_list:
  498. curs.execute(db_change('select data from other where name = ?'), [i_list[i]])
  499. sql_d = curs.fetchall()
  500. if sql_d:
  501. d_list[i] = sql_d[0][0]
  502. else:
  503. curs.execute(db_change('insert into other (name, data) values (?, ?)'), [i_list[i], n_list[i]])
  504. d_list[i] = n_list[i]
  505. conn.commit()
  506. acl_div = ['', '', '', '', '']
  507. acl_list = ['normal', 'user', 'admin', 'owner', '50_edit', 'email']
  508. for i in range(0, 5):
  509. for acl_data in acl_list:
  510. if acl_data == d_list[i + 1]:
  511. acl_div[i] = '<option value="' + acl_data + '">' + acl_data + '</option>' + acl_div[i]
  512. else:
  513. acl_div[i] += '<option value="' + acl_data + '">' + acl_data + '</option>'
  514. return easy_minify(flask.render_template(skin_check(),
  515. imp = [load_lang('main_acl_setting'), wiki_set(), custom(), other2([0, 0])],
  516. data = '''
  517. <form method="post">
  518. <span>''' + load_lang('document_acl') + '</span> <a href="/acl/TEST">(' + load_lang('reference') + ''')</a>
  519. <hr class=\"main_hr\">
  520. <select name="edit">''' + acl_div[0] + '''</select>
  521. <hr>
  522. <span>''' + load_lang('discussion_acl') + '''</span>
  523. <hr class=\"main_hr\">
  524. <select name="discussion">''' + acl_div[1] + '''</select>
  525. <hr>
  526. <span>''' + load_lang('upload_acl') + '''</span>
  527. <hr class=\"main_hr\">
  528. <select name="upload_acl">''' + acl_div[2] + '''</select>
  529. <hr>
  530. <span>''' + load_lang('view_acl') + '''</span>
  531. <hr class=\"main_hr\">
  532. <select name="all_view_acl">''' + acl_div[3] + '''</select>
  533. <hr>
  534. <span>''' + load_lang('edit_req_acl') + '''</span>
  535. <hr class=\"main_hr\">
  536. <select name="edit_req_acl">''' + acl_div[4] + '''</select>
  537. <hr class=\"main_hr\">
  538. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  539. </form>
  540. ''',
  541. menu = [['setting', load_lang('return')]]
  542. ))
  543. elif num == 9:
  544. oauth_supported = load_oauth('_README')['support']
  545. if admin_check() != 1:
  546. return re_error('/error/3')
  547. if flask.request.method == 'POST':
  548. admin_check(None, 'oauth setting')
  549. return_json_data = '{ "publish_url" : "' + flask.request.form.get('publish_url_box', '') + ', '
  550. for i in range(len(oauth_supported)):
  551. return_json_data += '"discord" : { '
  552. for j in range(2):
  553. if j == 0:
  554. load_target = 'id'
  555. elif j == 1:
  556. load_target = 'secret'
  557. target_data = flask.request.form.get(oauth_supported[i] + '_client_' + load_target, '')
  558. return_json_data += '"client_' + load_target + '" : "' + target_data + '"' + (',' if j == 0 else '')
  559. return_json_data += ' }'
  560. try:
  561. _ = oauth_supported[i + 1]
  562. return_json_data += ', '
  563. except:
  564. pas
  565. with open(app_var['path_oauth_setting'], 'w', encoding='utf-8') as f:
  566. f.write(return_json_data)
  567. return redirect('/oauth_setting')
  568. else:
  569. body_content = load_lang('oauth_explain') + '<hr>'
  570. body_content += '''
  571. <input placeholder="publish_url" id="publish_url_box" name="publish_url_box">
  572. <hr>
  573. <script>
  574. function check_value (target) {
  575. target_box = document.getElementById(target.id + "_box");
  576. if (target.value !== "") {
  577. target_box.checked = true;
  578. } else {
  579. target_box.checked = false;
  580. }
  581. }
  582. </script>
  583. '''
  584. init_js = ''
  585. body_content += '<form method="post">'
  586. for i in range(len(oauth_supported)):
  587. oauth_data = load_oauth(oauth_supported[i])
  588. for j in range(2):
  589. if j == 0:
  590. load_target = 'id'
  591. elif j == 1:
  592. load_target = 'secret'
  593. init_js += 'check_value(document.getElementById("' + oauth_supported[i] + '_client_' + load_target + '"));'
  594. body_content += '''
  595. <input id="''' + oauth_supported[i] + '''_client_''' + load_target + '''_box" type="checkbox" disabled>
  596. <input placeholder="''' + oauth_supported[i] + '''_client_''' + load_target + '''"
  597. id="''' + oauth_supported[i] + '''_client_''' + load_target + '''"
  598. name="''' + oauth_supported[i] + '''_client_''' + load_target + '''"
  599. value="''' + oauth_data['client_' + load_target] + '''"
  600. type="text"
  601. onChange="check_value(this)"
  602. style="width: 80%;">
  603. ''' + ('<hr>' if j == 1 else '<hr class=\"main_hr\">') + '''
  604. '''
  605. body_content += '<button id="save" type="submit">' + load_lang('save') + '</button></form>'
  606. body_content += '<script>' + init_js + '</script>'
  607. return easy_minify(flask.render_template(skin_check(),
  608. imp = [load_lang('oauth_setting'), wiki_set(), custom(), other2([0, 0])],
  609. data = body_content,
  610. menu = [['other', load_lang('return')]]
  611. ))
  612. else:
  613. return redirect()