app.py 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  1. # Init
  2. import os
  3. import signal
  4. import atexit
  5. import logging
  6. from route.tool.func import *
  7. from route import *
  8. from hypercorn.asyncio import serve
  9. from hypercorn.config import Config
  10. from werkzeug.middleware.proxy_fix import ProxyFix
  11. args = sys.argv
  12. run_mode = ''
  13. if len(args) > 1:
  14. run_mode = args[1]
  15. if not run_mode in ('dev'):
  16. run_mode = ''
  17. # Init-Version
  18. with open('version.json', encoding = 'utf8') as file_data:
  19. version_list = json_loads(file_data.read())
  20. # Init-DB
  21. data_db_set = class_check_json()
  22. do_db_set(data_db_set)
  23. with get_db_connect(init_mode = True) as conn:
  24. curs = conn.cursor()
  25. setup_tool = ''
  26. try:
  27. curs.execute(db_change('select data from other where name = "ver"'))
  28. except:
  29. setup_tool = 'init'
  30. if setup_tool != 'init':
  31. ver_set_data = curs.fetchall()
  32. if ver_set_data:
  33. if int(version_list['c_ver']) > int(ver_set_data[0][0]):
  34. setup_tool = 'update'
  35. else:
  36. setup_tool = 'normal'
  37. else:
  38. setup_tool = 'init'
  39. if run_mode != 'dev':
  40. file_name = linux_exe_chmod()
  41. local_file_path = os.path.join("route_go", "bin", file_name)
  42. if not (setup_tool == "normal" and os.path.exists(local_file_path)):
  43. if os.path.exists(local_file_path):
  44. print('Remove Old Binary')
  45. os.remove(local_file_path)
  46. download_url = version_list["bin_link"] + file_name
  47. print('Download New Binary File')
  48. response = requests.get(download_url, stream = True)
  49. if response.status_code == 200:
  50. with open(local_file_path, 'wb') as file:
  51. for chunk in response.iter_content(chunk_size = 8192):
  52. file.write(chunk)
  53. print('Complete Download')
  54. if data_db_set['type'] == 'mysql':
  55. try:
  56. curs.execute(db_change('create database ' + data_db_set['name'] + ' default character set utf8mb4'))
  57. except:
  58. try:
  59. curs.execute(db_change('alter database ' + data_db_set['name'] + ' character set utf8mb4'))
  60. except:
  61. pass
  62. conn.select_db(data_db_set['name'])
  63. else:
  64. conn.execute('pragma journal_mode = WAL')
  65. if setup_tool != 'normal':
  66. create_data = get_db_table_list()
  67. for create_table in create_data:
  68. for create in ['test'] + create_data[create_table]:
  69. db_pass = 0
  70. try:
  71. curs.execute(db_change('select ' + create + ' from ' + create_table + ' limit 1'))
  72. db_pass = 1
  73. except:
  74. pass
  75. field_text = 'longtext' if data_db_set['type'] == 'mysql' else 'text'
  76. if db_pass == 0:
  77. try:
  78. curs.execute(db_change('create table ' + create_table + '(test ' + field_text + ' default (""))'))
  79. db_pass = 1
  80. except Exception as e:
  81. # print(e)
  82. pass
  83. if db_pass == 0:
  84. try:
  85. curs.execute(db_change('create table ' + create_table + '(test ' + field_text + ' default "")'))
  86. db_pass = 1
  87. except Exception as e:
  88. # print(e)
  89. pass
  90. if db_pass == 0:
  91. try:
  92. curs.execute(db_change('create table ' + create_table + '(test ' + field_text + ')'))
  93. db_pass = 1
  94. except Exception as e:
  95. # print(e)
  96. pass
  97. if db_pass == 0:
  98. try:
  99. curs.execute(db_change("alter table " + create_table + " add column " + create + " " + field_text + " default ('')"))
  100. db_pass = 1
  101. except Exception as e:
  102. # print(e)
  103. pass
  104. if db_pass == 0:
  105. try:
  106. curs.execute(db_change("alter table " + create_table + " add column " + create + " " + field_text + " default ''"))
  107. db_pass = 1
  108. except Exception as e:
  109. # print(e)
  110. pass
  111. if db_pass == 0:
  112. try:
  113. curs.execute(db_change("alter table " + create_table + " add column " + create + " " + field_text))
  114. db_pass = 1
  115. except Exception as e:
  116. # print(e)
  117. pass
  118. if db_pass == 0:
  119. raise
  120. try:
  121. curs.execute(db_change("create index history_index on history (title, ip)"))
  122. except:
  123. pass
  124. if setup_tool == 'update':
  125. try:
  126. loop = asyncio.get_running_loop()
  127. loop.create_task(update(conn, int(ver_set_data[0][0]), data_db_set))
  128. except RuntimeError:
  129. loop = asyncio.new_event_loop()
  130. asyncio.set_event_loop(loop)
  131. loop.run_until_complete(update(conn, int(ver_set_data[0][0]), data_db_set))
  132. else:
  133. set_init(conn)
  134. set_init_always(conn, version_list['c_ver'], run_mode)
  135. # Init-Route
  136. class EverythingConverter(werkzeug.routing.PathConverter):
  137. def __init__(self, map):
  138. super(EverythingConverter, self).__init__(map)
  139. self.regex = r'.*?'
  140. def to_python(self, value):
  141. return re.sub(r'^\\\.', '.', value)
  142. class RegexConverter(werkzeug.routing.BaseConverter):
  143. def __init__(self, url_map, *items):
  144. super(RegexConverter, self).__init__(url_map)
  145. self.regex = items[0]
  146. app = flask.Flask(__name__, template_folder = './')
  147. app.config['JSON_AS_ASCII'] = False
  148. app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
  149. app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600
  150. if run_mode == 'dev':
  151. app.config['TEMPLATES_AUTO_RELOAD'] = True
  152. app.config['DEBUG'] = True
  153. app.config['ENV'] = 'development'
  154. log = logging.getLogger('hypercorn')
  155. log.setLevel(logging.ERROR)
  156. app.jinja_env.filters['md5_replace'] = md5_replace
  157. app.jinja_env.filters['load_lang'] = load_lang
  158. app.jinja_env.filters['cut_100'] = cut_100
  159. app.url_map.converters['everything'] = EverythingConverter
  160. app.url_map.converters['regex'] = RegexConverter
  161. curs.execute(db_change('select data from other where name = "key"'))
  162. sql_data = curs.fetchall()
  163. app.secret_key = sql_data[0][0]
  164. # Init-DB_Data
  165. server_set = {}
  166. server_set_var = get_init_set_list()
  167. server_set_env = {
  168. 'host' : os.getenv('NAMU_HOST'),
  169. 'golang_port' : os.getenv('NAMU_GOLANGPORT'),
  170. 'port' : os.getenv('NAMU_PORT'),
  171. 'language' : os.getenv('NAMU_LANG'),
  172. 'markup' : os.getenv('NAMU_MARKUP'),
  173. 'encode' : os.getenv('NAMU_ENCRYPT')
  174. }
  175. for i in server_set_var:
  176. curs.execute(db_change('select data from other where name = ?'), [i])
  177. server_set_val = curs.fetchall()
  178. if server_set_val:
  179. server_set_val = server_set_val[0][0]
  180. elif server_set_env[i] != None:
  181. server_set_val = server_set_env[i]
  182. curs.execute(db_change('insert into other (name, data, coverage) values (?, ?, "")'), [i, server_set_env[i]])
  183. else:
  184. if 'list' in server_set_var[i]:
  185. print(server_set_var[i]['display'] + ' (' + server_set_var[i]['default'] + ') [' + ', '.join(server_set_var[i]['list']) + ']' + ' : ', end = '')
  186. else:
  187. print(server_set_var[i]['display'] + ' (' + server_set_var[i]['default'] + ') : ', end = '')
  188. server_set_val = input()
  189. if server_set_val == '':
  190. server_set_val = server_set_var[i]['default']
  191. elif server_set_var[i]['require'] == 'select':
  192. if not server_set_val in server_set_var[i]['list']:
  193. server_set_val = server_set_var[i]['default']
  194. curs.execute(db_change('insert into other (name, data, coverage) values (?, ?, "")'), [i, server_set_val])
  195. print(server_set_var[i]['display'] + ' : ' + server_set_val)
  196. server_set[i] = server_set_val
  197. for for_a in server_set:
  198. global_some_set_do('setup_' + for_a, server_set[for_a])
  199. ###
  200. if platform.system() == 'Linux':
  201. if platform.machine() in ["AMD64", "x86_64"]:
  202. cmd = [os.path.join(".", "route_go", "bin", "main.amd64.bin")]
  203. else:
  204. cmd = [os.path.join(".", "route_go", "bin", "main.arm64.bin")]
  205. elif platform.system() == 'Darwin':
  206. cmd = [os.path.join(".", "route_go", "bin", "main.mac.arm64.bin")]
  207. else:
  208. if platform.machine() in ["AMD64", "x86_64"]:
  209. cmd = [os.path.join(".", "route_go", "bin", "main.amd64.exe")]
  210. else:
  211. cmd = [os.path.join(".", "route_go", "bin", "main.arm64.exe")]
  212. cmd += [server_set["golang_port"]]
  213. if run_mode != '':
  214. cmd += [run_mode]
  215. async def golang_process_check():
  216. while True:
  217. try:
  218. other_set_temp = {}
  219. for k in data_db_set:
  220. other_set_temp["db_" + k] = data_db_set[k]
  221. other_set = {
  222. "url" : "test",
  223. "data" : json_dumps(other_set_temp),
  224. "session" : "{}",
  225. "cookie" : "",
  226. "ip" : "127.0.0.1"
  227. }
  228. response = requests.post('http://localhost:' + server_set["golang_port"] + '/', data = json_dumps(other_set))
  229. if response.status_code == 200:
  230. print('Golang turn on')
  231. break
  232. except requests.ConnectionError:
  233. print('Wait golang...')
  234. time.sleep(1)
  235. golang_process = subprocess.Popen(cmd)
  236. try:
  237. loop = asyncio.get_running_loop()
  238. loop.create_task(golang_process_check())
  239. except RuntimeError:
  240. loop = asyncio.new_event_loop()
  241. asyncio.set_event_loop(loop)
  242. loop.run_until_complete(golang_process_check())
  243. ###
  244. def back_up(data_db_set):
  245. with get_db_connect() as conn:
  246. curs = conn.cursor()
  247. try:
  248. curs.execute(db_change('select data from other where name = "back_up"'))
  249. back_time = curs.fetchall()
  250. back_time = float(number_check(back_time[0][0], True)) if back_time and back_time[0][0] != '' else 0
  251. curs.execute(db_change('select data from other where name = "backup_count"'))
  252. back_up_count = curs.fetchall()
  253. back_up_count = int(number_check(back_up_count[0][0])) if back_up_count and back_up_count[0][0] != '' else 3
  254. if back_time != 0:
  255. curs.execute(db_change('select data from other where name = "backup_where"'))
  256. back_up_where = curs.fetchall()
  257. back_up_where = back_up_where[0][0] if back_up_where and back_up_where[0][0] != '' else data_db_set['name'] + '.db'
  258. print('Back up state : ' + str(back_time) + ' hours')
  259. print('Back up directory : ' + back_up_where)
  260. if back_up_count != 0:
  261. print('Back up max number : ' + str(back_up_count))
  262. file_dir = os.path.split(back_up_where)[0]
  263. file_dir = '.' if file_dir == '' else file_dir
  264. file_name = os.path.split(back_up_where)[1]
  265. file_name = re.sub(r'\.db$', '_[0-9]{14}.db', file_name)
  266. backup_file = [for_a for for_a in os.listdir(file_dir) if re.search('^' + file_name + '$', for_a)]
  267. backup_file = sorted(backup_file)
  268. if len(backup_file) >= back_up_count:
  269. remove_dir = os.path.join(file_dir, backup_file[0])
  270. os.remove(remove_dir)
  271. print('Back up : Remove (' + remove_dir + ')')
  272. now_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
  273. new_file_name = re.sub(r'\.db$', '_' + now_time + '.db', back_up_where)
  274. shutil.copyfile(
  275. data_db_set['name'] + '.db',
  276. new_file_name
  277. )
  278. print('Back up : OK (' + new_file_name + ')')
  279. else:
  280. print('Back up state : Turn off')
  281. back_time = 1
  282. except Exception as e:
  283. print('Back up : Error')
  284. print(e)
  285. back_time = 1
  286. threading.Timer(60 * 60 * back_time, back_up, [data_db_set]).start()
  287. async def do_every_day():
  288. with get_db_connect() as conn:
  289. curs = conn.cursor()
  290. # 오늘의 날짜 불러오기
  291. time_today = get_time().split()[0]
  292. # vote 관리
  293. curs.execute(db_change('select id, type from vote where type = "open" or type = "n_open"'))
  294. for for_a in curs.fetchall():
  295. curs.execute(db_change('select data from vote where id = ? and name = "end_date" and type = "option"'), [for_a[0]])
  296. db_data = curs.fetchall()
  297. if db_data:
  298. time_db = db_data[0][0].split()[0]
  299. if time_today > time_db:
  300. curs.execute(db_change("update vote set type = ? where user = '' and id = ? and type = ?"), ['close' if for_a[1] == 'open' else 'n_close', for_a[0], for_a[1]])
  301. # ban 관리
  302. curs.execute(db_change("update rb set ongoing = '' where end < ? and end != '' and ongoing = '1'"), [get_time()])
  303. # auth 관리
  304. curs.execute(db_change('select id, data from user_set where name = "auth_date"'))
  305. db_data = curs.fetchall()
  306. for for_a in db_data:
  307. time_db = for_a[1].split()[0]
  308. if time_today > time_db:
  309. curs.execute(db_change("update user_set set data = 'user' where id = ? and name = 'acl'"), [for_a[0]])
  310. curs.execute(db_change('delete from user_set where name = "auth_date" and id = ?'), [for_a[0]])
  311. # acl 관리
  312. curs.execute(db_change("select doc_name, doc_rev, set_data from data_set where set_name = 'acl_date'"))
  313. db_data = curs.fetchall()
  314. for for_a in db_data:
  315. time_db = for_a[2].split()[0]
  316. if time_today > time_db:
  317. curs.execute(db_change("delete from acl where title = ? and type = ?"), [for_a[0], for_a[1]])
  318. curs.execute(db_change("delete from data_set where doc_name = ? and doc_rev = ? and set_name = 'acl_date'"), [for_a[0], for_a[1]])
  319. # ua 관리
  320. curs.execute(db_change('select data from other where name = "ua_expiration_date"'))
  321. db_data = curs.fetchall()
  322. if db_data and db_data[0][0] != '':
  323. time_db = int(number_check(db_data[0][0]))
  324. time_calc = datetime.date.today() - datetime.timedelta(days = time_db)
  325. time_calc = time_calc.strftime('%Y-%m-%d %H:%M:%S')
  326. curs.execute(db_change("delete from ua_d where today < ?"), [time_calc])
  327. # auth history 관리
  328. curs.execute(db_change('select data from other where name = "auth_history_expiration_date"'))
  329. db_data = curs.fetchall()
  330. if db_data and db_data[0][0] != '':
  331. time_db = int(number_check(db_data[0][0]))
  332. time_calc = datetime.date.today() - datetime.timedelta(days = time_db)
  333. time_calc = time_calc.strftime('%Y-%m-%d %H:%M:%S')
  334. curs.execute(db_change("delete from re_admin where time < ?"), [time_calc])
  335. # 사이트맵 생성 관리
  336. curs.execute(db_change('select data from other where name = "sitemap_auto_make"'))
  337. db_data = curs.fetchall()
  338. if db_data and db_data[0][0] != '':
  339. await main_setting_sitemap(1)
  340. print('Make sitemap')
  341. # 칭호 관리
  342. curs.execute(db_change("select id from user_set where name = 'user_title' and data = '✅'"))
  343. for for_a in curs.fetchall():
  344. if await acl_check('', 'all_admin_auth', '', for_a[0]) == 1:
  345. curs.execute(db_change("update user_set set data = '☑️' where name = 'user_title' and data = '✅' and id = ?"), [for_a[0]])
  346. threading.Timer(60 * 60 * 24, do_every_day).start()
  347. def auto_do_something(data_db_set):
  348. if data_db_set['type'] == 'sqlite':
  349. back_up(data_db_set)
  350. try:
  351. loop = asyncio.get_running_loop()
  352. loop.create_task(do_every_day())
  353. except RuntimeError:
  354. loop = asyncio.new_event_loop()
  355. asyncio.set_event_loop(loop)
  356. loop.run_until_complete(do_every_day())
  357. auto_do_something(data_db_set)
  358. print('Now running... http://localhost:' + server_set['port'])
  359. @app.before_request
  360. def before_request_func():
  361. db_data = global_some_set_do('wiki_access_password')
  362. if db_data and db_data != '':
  363. access_password = db_data
  364. input_password = flask.request.cookies.get('opennamu_wiki_access', ' ')
  365. if url_pas(access_password) != input_password:
  366. with get_db_connect() as conn:
  367. return '''
  368. <script>
  369. "use strict";
  370. function opennamu_do_wiki_access() {
  371. let password = document.getElementById('wiki_access').value;
  372. document.cookie = 'opennamu_wiki_access=' + encodeURIComponent(password) + '; path=/;';
  373. history.go(0);
  374. }
  375. </script>
  376. <h2>''' + get_lang(conn, 'error_password_require_for_wiki_access') + '''</h2>
  377. <input type="password" id="wiki_access">
  378. <input type="submit" onclick="opennamu_do_wiki_access();">
  379. '''
  380. # Init-custom
  381. if os.path.exists('custom.py'):
  382. from custom import custom_run
  383. custom_run('error', app)
  384. # Func
  385. # Func-inter_wiki
  386. app.route('/filter/inter_wiki', defaults = { 'tool' : 'inter_wiki' })(filter_all)
  387. app.route('/filter/inter_wiki/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'inter_wiki' })(filter_all_add)
  388. app.route('/filter/inter_wiki/add/<everything:name>', methods = ['POST', 'GET'], defaults = { 'tool' : 'inter_wiki' })(filter_all_add)
  389. app.route('/filter/inter_wiki/del/<everything:name>', defaults = { 'tool' : 'inter_wiki' })(filter_all_delete)
  390. app.route('/filter/outer_link', defaults = { 'tool' : 'outer_link' })(filter_all)
  391. app.route('/filter/outer_link/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'outer_link' })(filter_all_add)
  392. app.route('/filter/outer_link/add/<everything:name>', methods = ['POST', 'GET'], defaults = { 'tool' : 'outer_link' })(filter_all_add)
  393. app.route('/filter/outer_link/del/<everything:name>', defaults = { 'tool' : 'outer_link' })(filter_all_delete)
  394. app.route('/filter/document', defaults = { 'tool' : 'document' })(filter_all)
  395. app.route('/filter/document/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'document' })(filter_all_add)
  396. app.route('/filter/document/add/<everything:name>', methods = ['POST', 'GET'], defaults = { 'tool' : 'document' })(filter_all_add)
  397. app.route('/filter/document/del/<everything:name>', defaults = { 'tool' : 'document' })(filter_all_delete)
  398. app.route('/filter/edit_top', defaults = { 'tool' : 'edit_top' })(filter_all)
  399. app.route('/filter/edit_top/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'edit_top' })(filter_all_add)
  400. app.route('/filter/edit_top/add/<everything:name>', methods = ['POST', 'GET'], defaults = { 'tool' : 'edit_top' })(filter_all_add)
  401. app.route('/filter/edit_top/del/<everything:name>', defaults = { 'tool' : 'edit_top' })(filter_all_delete)
  402. app.route('/filter/image_license', defaults = { 'tool' : 'image_license' })(filter_all)
  403. app.route('/filter/image_license/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'image_license' })(filter_all_add)
  404. app.route('/filter/image_license/del/<everything:name>', defaults = { 'tool' : 'image_license' })(filter_all_delete)
  405. app.route('/filter/template', defaults = { 'tool' : 'template' })(filter_all)
  406. app.route('/filter/template/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'template' })(filter_all_add)
  407. app.route('/filter/template/add/<everything:name>', methods = ['POST', 'GET'], defaults = { 'tool' : 'template' })(filter_all_add)
  408. app.route('/filter/template/del/<everything:name>', defaults = { 'tool' : 'template' })(filter_all_delete)
  409. app.route('/filter/edit_filter', defaults = { 'tool' : 'edit_filter' })(filter_all)
  410. app.route('/filter/edit_filter/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'edit_filter' })(filter_all_add)
  411. app.route('/filter/edit_filter/add/<everything:name>', methods = ['POST', 'GET'], defaults = { 'tool' : 'edit_filter' })(filter_all_add)
  412. app.route('/filter/edit_filter/del/<everything:name>', defaults = { 'tool' : 'edit_filter' })(filter_all_delete)
  413. app.route('/filter/email_filter', defaults = { 'tool' : 'email_filter' })(filter_all)
  414. app.route('/filter/email_filter/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'email_filter' })(filter_all_add)
  415. app.route('/filter/email_filter/del/<everything:name>', defaults = { 'tool' : 'email_filter' })(filter_all_delete)
  416. app.route('/filter/file_filter', defaults = { 'tool' : 'file_filter' })(filter_all)
  417. app.route('/filter/file_filter/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'file_filter' })(filter_all_add)
  418. app.route('/filter/file_filter/del/<everything:name>', defaults = { 'tool' : 'file_filter' })(filter_all_delete)
  419. app.route('/filter/name_filter', defaults = { 'tool' : 'name_filter' })(filter_all)
  420. app.route('/filter/name_filter/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'name_filter' })(filter_all_add)
  421. app.route('/filter/name_filter/del/<everything:name>', defaults = { 'tool' : 'name_filter' })(filter_all_delete)
  422. app.route('/filter/extension_filter', defaults = { 'tool' : 'extension_filter' })(filter_all)
  423. app.route('/filter/extension_filter/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'extension_filter' })(filter_all_add)
  424. app.route('/filter/extension_filter/del/<everything:name>', defaults = { 'tool' : 'extension_filter' })(filter_all_delete)
  425. # Func-list
  426. app.route('/list/document/old', defaults = { 'set_type' : 'old' })(list_old_page)
  427. app.route('/list/document/old/<int:num>', defaults = { 'set_type' : 'old' })(list_old_page)
  428. app.route('/list/document/new', defaults = { 'set_type' : 'new' })(list_old_page)
  429. app.route('/list/document/new/<int:num>', defaults = { 'set_type' : 'new' })(list_old_page)
  430. app.route('/list/document/no_link')(list_no_link)
  431. app.route('/list/document/no_link/<int:num>')(list_no_link)
  432. app.route('/list/document/acl')(list_acl)
  433. app.route('/list/document/acl/<int:arg_num>')(list_acl)
  434. app.route('/list/document/need')(list_please)
  435. app.route('/list/document/need/<int:arg_num>')(list_please)
  436. app.route('/list/document/all')(list_title_index)
  437. app.route('/list/document/all/<int:num>')(list_title_index)
  438. app.route('/list/document/long')(list_long_page)
  439. app.route('/list/document/long/<int:arg_num>')(list_long_page)
  440. app.route('/list/document/short', defaults = { 'tool' : 'short_page' })(list_long_page)
  441. app.route('/list/document/short/<int:arg_num>', defaults = { 'tool' : 'short_page' })(list_long_page)
  442. app.route('/list/file')(list_image_file)
  443. app.route('/list/file/<int:arg_num>')(list_image_file)
  444. app.route('/list/image', defaults = { 'do_type' : 1 })(list_image_file)
  445. app.route('/list/image/<int:arg_num>', defaults = { 'do_type' : 1 })(list_image_file)
  446. app.route('/list/admin')(list_admin)
  447. app.route('/list/admin/auth_use', methods = ['POST', 'GET'])(list_admin_auth_use)
  448. app.route('/list/admin/auth_use_page/<int:arg_num>/<everything:arg_search>', methods = ['POST', 'GET'])(list_admin_auth_use)
  449. app.route('/list/user')(list_user)
  450. app.route('/list/user/<int:arg_num>')(list_user)
  451. app.route('/list/user/check_submit/<name>')(list_user_check_submit)
  452. app.route('/list/user/check/<name>')(list_user_check)
  453. app.route('/list/user/check/<name>/<do_type>')(list_user_check)
  454. app.route('/list/user/check/<name>/<do_type>/<int:arg_num>')(list_user_check)
  455. app.route('/list/user/check/<name>/<do_type>/<int:arg_num>/<plus_name>')(list_user_check)
  456. app.route('/list/user/check/delete/<name>/<ip>/<time>/<do_type>', methods = ['POST', 'GET'])(list_user_check_delete)
  457. # Func-auth
  458. app.route('/auth/give', methods = ['POST', 'GET'])(give_auth)
  459. app.route('/auth/give_total', methods = ['POST', 'GET'])(give_auth)
  460. app.route('/auth/give/<user_name>', methods = ['POST', 'GET'])(give_auth)
  461. app.route('/auth/ban', methods = ['POST', 'GET'])(give_user_ban)
  462. app.route('/auth/ban/multiple', methods = ['POST', 'GET'], defaults = { 'ban_type' : 'multiple' })(give_user_ban)
  463. app.route('/auth/ban/<everything:name>', methods = ['POST', 'GET'])(give_user_ban)
  464. app.route('/auth/ban_cidr/<everything:name>', methods = ['POST', 'GET'], defaults = { 'ban_type' : 'cidr' })(give_user_ban)
  465. app.route('/auth/ban_regex/<everything:name>', methods = ['POST', 'GET'], defaults = { 'ban_type' : 'regex' })(give_user_ban)
  466. # /auth/list
  467. # /auth/list/add/<name>
  468. # /auth/list/delete/<name>
  469. app.route('/auth/list')(list_admin_group)
  470. app.route('/auth/list/add/<name>', methods = ['POST', 'GET'])(give_admin_groups)
  471. app.route('/auth/list/delete/<name>', methods = ['POST', 'GET'])(give_delete_admin_group)
  472. app.route('/auth/give/fix/<user_name>', methods = ['POST', 'GET'])(give_user_fix)
  473. app.route('/app_submit', methods = ['POST', 'GET'])(recent_app_submit)
  474. # /auth/history
  475. app.route('/recent_block')(list_recent_block)
  476. app.route('/recent_block/all')(list_recent_block)
  477. app.route('/recent_block/all/<int:num>')(list_recent_block)
  478. app.route('/recent_block/all/<int:num>/<everything:why>')(list_recent_block)
  479. app.route('/recent_block/user/<user_name>', defaults = { 'tool' : 'user' })(list_recent_block)
  480. app.route('/recent_block/user/<user_name>/<int:num>', defaults = { 'tool' : 'user' })(list_recent_block)
  481. app.route('/recent_block/admin/<user_name>', defaults = { 'tool' : 'admin' })(list_recent_block)
  482. app.route('/recent_block/admin/<user_name>/<int:num>', defaults = { 'tool' : 'admin' })(list_recent_block)
  483. app.route('/recent_block/regex', defaults = { 'tool' : 'regex' })(list_recent_block)
  484. app.route('/recent_block/regex/<int:num>', defaults = { 'tool' : 'regex' })(list_recent_block)
  485. app.route('/recent_block/cidr', defaults = { 'tool' : 'cidr' })(list_recent_block)
  486. app.route('/recent_block/cidr/<int:num>', defaults = { 'tool' : 'cidr' })(list_recent_block)
  487. app.route('/recent_block/private', defaults = { 'tool' : 'private' })(list_recent_block)
  488. app.route('/recent_block/private/<int:num>', defaults = { 'tool' : 'private' })(list_recent_block)
  489. app.route('/recent_block/ongoing', defaults = { 'tool' : 'ongoing' })(list_recent_block)
  490. app.route('/recent_block/ongoing/<int:num>', defaults = { 'tool' : 'ongoing' })(list_recent_block)
  491. app.route('/recent_change', defaults = { 'tool' : 'recent_change' })(list_history)
  492. app.route('/recent_changes', defaults = { 'tool' : 'recent_change' })(list_history)
  493. app.route('/recent_change/<int:num>/<set_type>', defaults = { 'tool' : 'recent_change' })(list_history)
  494. app.route('/recent_discuss', defaults = { 'tool' : 'normal' })(list_recent_discuss)
  495. app.route('/recent_discuss/<int:num>/<tool>')(list_recent_discuss)
  496. # Func-history
  497. app.route('/recent_edit_request')(recent_edit_request)
  498. app.route('/record/<name>', defaults = { 'tool' : 'record' })(recent_change)
  499. app.route('/record/<int:num>/<set_type>/<name>', defaults = { 'tool' : 'record' })(recent_change)
  500. app.route('/record/reset/<name>', methods = ['POST', 'GET'])(recent_record_reset)
  501. app.route('/record/topic/<name>')(recent_record_topic)
  502. app.route('/record/bbs/<name>', defaults = { 'tool' : 'record' })(bbs_w)
  503. app.route('/record/bbs_comment/<name>', defaults = { 'tool' : 'comment_record' })(bbs_w)
  504. app.route('/history/<everything:doc_name>', methods = ['POST', 'GET'])(list_history)
  505. app.route('/history_page/<int:num>/<set_type>/<everything:doc_name>', methods = ['POST', 'GET'])(list_history)
  506. app.route('/history_tool/<int(signed = True):rev>/<everything:name>')(recent_history_tool)
  507. app.route('/history_delete/<int(signed = True):rev>/<everything:name>', methods = ['POST', 'GET'])(recent_history_delete)
  508. app.route('/history_hidden/<int(signed = True):rev>/<everything:name>')(recent_history_hidden)
  509. app.route('/history_send/<int(signed = True):rev>/<everything:name>', methods = ['POST', 'GET'])(recent_history_send)
  510. app.route('/history_reset/<everything:name>', methods = ['POST', 'GET'])(recent_history_reset)
  511. app.route('/history_add/<everything:name>', methods = ['POST', 'GET'])(recent_history_add)
  512. # Func-view
  513. app.route('/xref/<everything:name>')(view_xref)
  514. app.route('/xref_page/<int:num>/<everything:name>')(view_xref)
  515. app.route('/xref_this/<everything:name>', defaults = { 'xref_type' : 2 })(view_xref)
  516. app.route('/xref_this_page/<int:num>/<everything:name>', defaults = { 'xref_type' : 2 })(view_xref)
  517. app.route('/doc_watch_list/<int:num>/<everything:name>')(w_watch_list)
  518. app.route('/doc_star_doc/<int:num>/<everything:name>', defaults = { 'do_type' : 'star_doc' })(w_watch_list)
  519. app.route('/raw/<everything:name>')(view_w_raw)
  520. app.route('/raw_acl/<everything:name>', defaults = { 'doc_acl' : 'on' })(view_w_raw)
  521. app.route('/raw_rev/<int(signed = True):rev>/<everything:name>')(view_w_raw)
  522. app.route('/diff/<int(signed = True):num_a>/<int(signed = True):num_b>/<everything:name>')(view_diff)
  523. app.route('/down/<everything:name>')(view_down)
  524. app.route('/acl_multiple', defaults = { 'multiple' : True }, methods = ['POST', 'GET'])(view_set)
  525. app.route('/acl/<everything:name>', methods = ['POST', 'GET'])(view_set)
  526. app.route('/w_from/<everything:name>', defaults = { 'do_type' : 'from' })(view_w)
  527. app.route('/w/<everything:name>')(view_w)
  528. app.route('/random')(view_random)
  529. # Func-edit
  530. app.route('/edit/<everything:name>', methods = ['POST', 'GET'])(edit)
  531. app.route('/edit_from/<everything:name>', methods = ['POST', 'GET'], defaults = { 'do_type' : 'load' })(edit)
  532. app.route('/edit_section/<int:section>/<everything:name>', methods = ['POST', 'GET'])(edit)
  533. app.route('/edit_request/<everything:name>', methods = ['POST', 'GET'])(edit_request)
  534. app.route('/edit_request_from/<everything:name>', defaults = { 'do_type' : 'from' }, methods = ['POST', 'GET'])(edit_request)
  535. # app.route('/edit_request_rev/<int:rev>/<everything:name>', methods = ['POST', 'GET'])(edit_request)
  536. app.route('/upload', methods = ['POST', 'GET'])(edit_upload)
  537. # 개편 예정
  538. app.route('/xref_reset/<everything:name>')(edit_backlink_reset)
  539. app.route('/delete/<everything:name>', methods = ['POST', 'GET'])(edit_delete)
  540. app.route('/delete_file/<everything:name>', methods = ['POST', 'GET'])(edit_delete_file)
  541. app.route('/delete_multiple', methods = ['POST', 'GET'])(edit_delete_multiple)
  542. app.route('/revert/<int:num>/<everything:name>', methods = ['POST', 'GET'])(edit_revert)
  543. app.route('/move/<everything:name>', methods = ['POST', 'GET'])(edit_move)
  544. app.route('/move_all')(edit_move_all)
  545. # Func-topic
  546. app.route('/topic/<everything:name>', methods = ['POST', 'GET'])(topic_list)
  547. app.route('/topic_page/<int:page>/<everything:name>', methods = ['POST', 'GET'])(topic_list)
  548. app.route('/thread/<int:topic_num>', methods = ['POST', 'GET'])(topic)
  549. app.route('/thread/0/<everything:doc_name>', defaults = { 'topic_num' : '0' }, methods = ['POST', 'GET'])(topic)
  550. app.route('/thread/<int:topic_num>/tool')(topic_tool)
  551. app.route('/thread/<int:topic_num>/setting', methods = ['POST', 'GET'])(topic_tool_setting)
  552. app.route('/thread/<int:topic_num>/acl', methods = ['POST', 'GET'])(topic_tool_acl)
  553. app.route('/thread/<int:topic_num>/delete', methods = ['POST', 'GET'])(topic_tool_delete)
  554. app.route('/thread/<int:topic_num>/change', methods = ['POST', 'GET'])(topic_tool_change)
  555. app.route('/thread/<int:topic_num>/comment/<int:num>/tool')(topic_comment_tool)
  556. app.route('/thread/<int:topic_num>/comment/<int:num>/notice')(topic_comment_notice)
  557. app.route('/thread/<int:topic_num>/comment/<int:num>/blind')(topic_comment_blind)
  558. app.route('/thread/<int:topic_num>/comment/<int:num>/raw')(view_raw)
  559. app.route('/thread/<int:topic_num>/comment/<int:num>/delete', methods = ['POST', 'GET'])(topic_comment_delete)
  560. # Func-user
  561. app.route('/change', methods = ['POST', 'GET'])(user_setting)
  562. app.route('/change/key')(user_setting_key)
  563. app.route('/change/key/delete')(user_setting_key_delete)
  564. app.route('/change/pw', methods = ['POST', 'GET'])(user_setting_pw)
  565. app.route('/change/head', methods = ['GET', 'POST'], defaults = { 'skin_name' : '' })(user_setting_head)
  566. app.route('/change/head/<skin_name>', methods = ['GET', 'POST'])(user_setting_head)
  567. app.route('/change/head_reset', methods = ['GET', 'POST'])(user_setting_head_reset)
  568. app.route('/change/skin_set')(user_setting_skin_set)
  569. app.route('/change/top_menu', methods = ['GET', 'POST'])(user_setting_top_menu)
  570. app.route('/change/user_name', methods = ['GET', 'POST'])(user_setting_user_name)
  571. app.route('/change/user_name/<user_name>', methods = ['GET', 'POST'])(user_setting_user_name)
  572. # 하위 호환용 S
  573. app.route('/skin_set')(user_setting_skin_set)
  574. # 하위 호환용 E
  575. app.route('/change/skin_set/main', methods = ['POST', 'GET'])(user_setting_skin_set_main)
  576. app.route('/user')(user_info)
  577. app.route('/user/<name>')(user_info)
  578. app.route('/challenge', methods = ['GET', 'POST'])(user_challenge)
  579. app.route('/edit_filter/<name>', methods = ['GET', 'POST'])(user_edit_filter)
  580. app.route('/count')(user_count)
  581. app.route('/count/<name>')(user_count)
  582. app.route('/alarm')(user_alarm)
  583. app.route('/alarm/delete')(user_alarm_delete)
  584. app.route('/alarm/delete/<int:id>')(user_alarm_delete)
  585. app.route('/watch_list', defaults = { 'tool' : 'watch_list' })(user_watch_list)
  586. app.route('/watch_list/<everything:name>', defaults = { 'tool' : 'watch_list' })(user_watch_list_name)
  587. app.route('/watch_list_from/<everything:name>', defaults = { 'tool' : 'watch_list_from' })(user_watch_list_name)
  588. app.route('/star_doc', defaults = { 'tool' : 'star_doc' })(user_watch_list)
  589. app.route('/star_doc/<everything:name>', defaults = { 'tool' : 'star_doc' })(user_watch_list_name)
  590. app.route('/star_doc_from/<everything:name>', defaults = { 'tool' : 'star_doc_from' })(user_watch_list_name)
  591. # 개편 보류중 S
  592. app.route('/change/email', methods = ['POST', 'GET'])(user_setting_email)
  593. app.route('/change/email/delete')(user_setting_email_delete)
  594. app.route('/change/email/check', methods = ['POST', 'GET'])(user_setting_email_check)
  595. # 개편 보류중 E
  596. # Func-login
  597. # 개편 예정
  598. # login -> login/2fa -> login/2fa/email with login_id
  599. # register -> register/email -> regiter/email/check with reg_id
  600. # pass_find -> pass_find/email with find_id
  601. app.route('/login', methods = ['POST', 'GET'])(login_login)
  602. app.route('/login/2fa', methods = ['POST', 'GET'])(login_login_2fa)
  603. app.route('/register', methods = ['POST', 'GET'])(login_register)
  604. app.route('/register/email', methods = ['POST', 'GET'])(login_register_email)
  605. app.route('/register/email/check', methods = ['POST', 'GET'])(login_register_email_check)
  606. app.route('/register/submit', methods = ['POST', 'GET'])(login_register_submit)
  607. app.route('/login/find')(login_find)
  608. app.route('/login/find/key', methods = ['POST', 'GET'])(login_find_key)
  609. app.route('/login/find/email', methods = ['POST', 'GET'], defaults = { 'tool' : 'pass_find' })(login_find_email)
  610. app.route('/login/find/email/check', methods = ['POST', 'GET'], defaults = { 'tool' : 'check_key' })(login_find_email_check)
  611. app.route('/logout')(login_logout)
  612. # Func-vote
  613. app.route('/vote/<int:num>', methods = ['POST', 'GET'])(vote_select)
  614. app.route('/vote/end/<int:num>')(vote_end)
  615. app.route('/vote/close/<int:num>')(vote_close)
  616. app.route('/vote', defaults = { 'list_type' : 'normal' })(vote_list)
  617. app.route('/vote/list', defaults = { 'list_type' : 'normal' })(vote_list)
  618. app.route('/vote/list/<int:num>', defaults = { 'list_type' : 'normal' })(vote_list)
  619. app.route('/vote/list/close', defaults = { 'list_type' : 'close' })(vote_list)
  620. app.route('/vote/list/close/<int:num>', defaults = { 'list_type' : 'close' })(vote_list)
  621. app.route('/vote/add', methods = ['POST', 'GET'])(vote_add)
  622. # Func-bbs
  623. app.route('/bbs/main')(bbs_main)
  624. app.route('/bbs/make', methods = ['POST', 'GET'])(bbs_make)
  625. app.route('/bbs/in/<int:bbs_num>')(bbs_in)
  626. app.route('/bbs/in/<int:bbs_num>/<int:page>')(bbs_in)
  627. # app.route('/bbs/blind/<int:bbs_num>', methods = ['POST', 'GET'])(bbs_hide)
  628. app.route('/bbs/delete/<int:bbs_num>', methods = ['POST', 'GET'])(bbs_delete)
  629. app.route('/bbs/set/<int:bbs_num>', methods = ['POST', 'GET'])(bbs_w_set)
  630. app.route('/bbs/edit/<int:bbs_num>', methods = ['POST', 'GET'])(bbs_w_edit)
  631. app.route('/bbs/w/<int:bbs_num>/<int:post_num>', methods = ['POST', 'GET'])(bbs_w_post)
  632. # app.route('/bbs/blind/<int:bbs_num>/<int:post_num>', methods = ['POST', 'GET'])(bbs_w_hide)
  633. app.route('/bbs/pinned/<int:bbs_num>/<int:post_num>', methods = ['POST', 'GET'])(bbs_w_pinned)
  634. app.route('/bbs/delete/<int:bbs_num>/<int:post_num>', methods = ['POST', 'GET'])(bbs_w_delete)
  635. app.route('/bbs/raw/<int:bbs_num>/<int:post_num>')(view_raw)
  636. app.route('/bbs/tool/<int:bbs_num>/<int:post_num>')(bbs_w_tool)
  637. app.route('/bbs/edit/<int:bbs_num>/<int:post_num>', methods = ['POST', 'GET'])(bbs_w_edit)
  638. app.route('/bbs/tool/<int:bbs_num>/<int:post_num>/<comment_num>')(bbs_w_comment_tool)
  639. app.route('/bbs/raw/<int:bbs_num>/<int:post_num>/<comment_num>')(view_raw)
  640. app.route('/bbs/edit/<int:bbs_num>/<int:post_num>/<comment_num>', methods = ['POST', 'GET'])(bbs_w_edit)
  641. app.route('/bbs/delete/<int:bbs_num>/<int:post_num>/<comment_num>', methods = ['POST', 'GET'])(bbs_w_delete)
  642. # Func-api
  643. ## v1 API
  644. app.route('/api/render', methods = ['POST'])(api_w_render_exter)
  645. app.route('/api/render/<tool>', methods = ['POST'])(api_w_render_exter)
  646. app.route('/api/raw_exist/<everything:name>', defaults = { 'exist_check' : 'on' })(api_w_raw)
  647. app.route('/api/raw_rev/<int(signed = True):rev>/<everything:name>')(api_w_raw)
  648. app.route('/api/raw/<everything:name>')(api_w_raw)
  649. app.route('/api/xref/<int:page>/<everything:name>')(api_w_xref)
  650. app.route('/api/xref_this/<int:page>/<everything:name>', defaults = { 'xref_type' : '2' })(api_w_xref)
  651. app.route('/api/random')(api_w_random)
  652. app.route('/api/bbs/w/<sub_code>')(api_bbs_w)
  653. app.route('/api/bbs/w/comment/<sub_code>')(api_bbs_w_comment_exter)
  654. app.route('/api/bbs/w/comment_one/<sub_code>')(api_bbs_w_comment_one_exter)
  655. app.route('/api/version', defaults = { 'version_list' : version_list })(api_version)
  656. app.route('/api/skin_info')(api_skin_info)
  657. app.route('/api/skin_info/<name>')(api_skin_info)
  658. app.route('/api/user_info/<user_name>')(api_user_info)
  659. app.route('/api/thread/<int:topic_num>/<int:s_num>/<int:e_num>')(api_topic)
  660. app.route('/api/thread/<int:topic_num>/<tool>')(api_topic)
  661. app.route('/api/thread/<int:topic_num>')(api_topic)
  662. app.route('/api/search/<everything:name>')(api_func_search_exter)
  663. app.route('/api/search_page/<int:num>/<everything:name>')(api_func_search_exter)
  664. app.route('/api/search_data/<everything:name>', defaults = { 'search_type' : 'data' })(api_func_search_exter)
  665. app.route('/api/search_data_page/<int:num>/<everything:name>', defaults = { 'search_type' : 'data' })(api_func_search_exter)
  666. app.route('/api/recent_change')(api_list_recent_change_exter)
  667. app.route('/api/recent_changes')(api_list_recent_change_exter)
  668. app.route('/api/recent_change/<int:limit>')(api_list_recent_change_exter)
  669. app.route('/api/recent_change/<int:limit>/<set_type>/<int:num>')(api_list_recent_change_exter)
  670. app.route('/api/recent_edit_request')(api_list_recent_edit_request_exter)
  671. app.route('/api/recent_edit_request/<int:limit>/<set_type>/<int:num>')(api_list_recent_edit_request_exter)
  672. app.route('/api/recent_discuss/<set_type>/<int:limit>')(api_list_recent_discuss)
  673. app.route('/api/recent_discuss/<int:limit>')(api_list_recent_discuss)
  674. app.route('/api/recent_discuss')(api_list_recent_discuss)
  675. app.route('/api/lang', methods = ['POST'])(api_func_language)
  676. app.route('/api/lang/<data>')(api_func_language)
  677. app.route('/api/sha224/<everything:data>')(api_func_sha224)
  678. app.route('/api/ip/<everything:data>')(api_func_ip)
  679. app.route('/api/image/<everything:name>')(api_image_view)
  680. ## v2 API
  681. app.route('/api/v2/recent_edit_request/<set_type>/<int:num>', defaults = { 'limit' : 50 })(api_list_recent_edit_request)
  682. app.route('/api/v2/recent_change/<set_type>/<int:num>', defaults = { 'legacy' : '', 'limit' : 50 })(api_list_recent_change_exter)
  683. app.route('/api/v2/recent_discuss/<set_type>/<int:num>', defaults = { 'legacy' : '', 'limit' : 50 })(api_list_recent_discuss)
  684. app.route('/api/v2/recent_block/<set_type>/<int:num>')(api_list_recent_block)
  685. app.route('/api/v2/recent_block/<set_type>/<int:num>/<everything:why>')(api_list_recent_block)
  686. app.route('/api/v2/recent_block_user/<set_type>/<int:num>/<user_name>')(api_list_recent_block)
  687. app.route('/api/v2/recent_block_user/<set_type>/<int:num>/<user_name>/<everything:why>')(api_list_recent_block)
  688. app.route('/api/v2/list/document/old/<int:num>', defaults = { 'set_type' : 'old' })(api_list_old_page_exter)
  689. app.route('/api/v2/list/document/new/<int:num>', defaults = { 'set_type' : 'new' })(api_list_old_page_exter)
  690. app.route('/api/v2/list/document/<int:num>')(api_list_title_index)
  691. app.route('/api/v2/list/auth')(api_list_auth)
  692. app.route('/api/v2/list/markup')(api_list_markup)
  693. app.route('/api/v2/list/acl/<data_type>')(api_list_acl)
  694. app.route('/api/v2/history/<int:num>/<set_type>/<everything:doc_name>')(api_list_history_exter)
  695. app.route('/api/v2/topic/<int:num>/<set_type>/<everything:name>')(api_topic_list)
  696. app.route('/api/v2/bbs')(api_bbs_list)
  697. app.route('/api/v2/bbs/main')(api_bbs)
  698. app.route('/api/v2/bbs/set/<int:bbs_num>/<name>', methods = ['GET', 'PUT'])(api_bbs_w_set)
  699. app.route('/api/v2/bbs/in/<int:bbs_num>/<int:page>')(api_bbs)
  700. app.route('/api/v2/bbs/w/<sub_code>', defaults = { 'legacy' : '' })(api_bbs_w)
  701. app.route('/api/v2/bbs/w/tabom/<sub_code>', methods = ['GET', 'POST'])(api_bbs_w_tabom)
  702. app.route('/api/v2/bbs/w/comment/<sub_code>/<tool>', defaults = { 'legacy' : '' })(api_bbs_w_comment_exter)
  703. app.route('/api/v2/bbs/w/comment_one/<sub_code>/<tool>', defaults = { 'legacy' : '' })(api_bbs_w_comment_one_exter)
  704. app.route('/api/v2/doc_star_doc/<int:num>/<everything:name>', defaults = { 'do_type' : 'star_doc' })(api_w_watch_list)
  705. app.route('/api/v2/doc_watch_list/<int:num>/<everything:name>')(api_w_watch_list)
  706. app.route('/api/v2/set_reset/<everything:name>')(api_w_set_reset)
  707. app.route('/api/v2/page_view/<everything:name>')(api_w_page_view)
  708. app.route('/api/v2/setting/<name>', methods = ['GET', 'PUT'])(api_setting)
  709. app.route('/api/v2/auth')(api_func_auth)
  710. app.route('/api/v2/auth/<user_name>')(api_func_auth)
  711. app.route('/api/v2/auth/give', methods = ['PATCH'])(api_give_auth)
  712. app.route('/api/v2/user/rankup', methods = ['GET', 'PATCH'])(api_user_rankup)
  713. app.route('/api/v2/user/setting/editor', methods = ['GET', 'POST', 'DELETE'])(api_user_setting_editor)
  714. app.route('/api/v2/ip/<everything:data>', methods = ['GET', 'POST'])(api_func_ip)
  715. app.route('/api/v2/ip_menu/<everything:ip>', defaults = { 'option' : 'user' }, methods = ['GET', 'POST'])(api_func_ip_menu)
  716. app.route('/api/v2/user_menu/<everything:ip>')(api_func_ip_menu)
  717. app.route('/api/v2/lang', defaults = { 'legacy' : '' }, methods = ['POST'])(api_func_language)
  718. # Func-main
  719. # 여기도 전반적인 조정 시행 예정
  720. app.route('/other')(main_tool_other)
  721. app.route('/manager', methods = ['POST', 'GET'])(main_tool_admin)
  722. app.route('/manager/<int:num>', methods = ['POST', 'GET'])(main_tool_redirect)
  723. app.route('/manager/<int:num>/<everything:add_2>', methods = ['POST', 'GET'])(main_tool_redirect)
  724. app.route('/search', methods=['POST'])(main_search)
  725. app.route('/search/<everything:name>', methods = ['POST', 'GET'])(main_search_deep)
  726. app.route('/search_page/<int:num>/<everything:name>', methods = ['POST', 'GET'])(main_search_deep)
  727. app.route('/search_data/<everything:name>', defaults = { 'search_type' : 'data' }, methods = ['POST', 'GET'])(main_search_deep)
  728. app.route('/search_data_page/<int:num>/<everything:name>', defaults = { 'search_type' : 'data' }, methods = ['POST', 'GET'])(main_search_deep)
  729. app.route('/goto', methods=['POST'])(main_search_goto)
  730. app.route('/goto/<everything:name>', methods=['GET', 'POST'])(main_search_goto)
  731. app.route('/setting')(main_setting)
  732. app.route('/setting/main', methods = ['POST', 'GET'])(main_setting_main)
  733. app.route('/setting/main/logo', methods = ['POST', 'GET'])(main_setting_main_logo)
  734. app.route('/setting/top_menu', methods = ['POST', 'GET'])(main_setting_top_menu)
  735. app.route('/setting/phrase', methods = ['POST', 'GET'])(main_setting_phrase)
  736. app.route('/setting/head', defaults = { 'num' : 3 }, methods = ['POST', 'GET'])(main_setting_head)
  737. app.route('/setting/head/<skin_name>', defaults = { 'num' : 3 }, methods = ['POST', 'GET'])(main_setting_head)
  738. app.route('/setting/body/top', defaults = { 'num' : 4 }, methods = ['POST', 'GET'])(main_setting_head)
  739. app.route('/setting_preview/body/top', defaults = { 'num' : 4, 'set_preview' : 1 }, methods = ['POST'])(main_setting_head)
  740. app.route('/setting/body/bottom', defaults = { 'num' : 7 }, methods = ['POST', 'GET'])(main_setting_head)
  741. app.route('/setting_preview/body/bottom', defaults = { 'num' : 7, 'set_preview' : 1 }, methods = ['POST'])(main_setting_head)
  742. app.route('/setting/robot', methods = ['POST', 'GET'])(main_setting_robot)
  743. app.route('/setting/external', methods = ['POST', 'GET'])(main_setting_external)
  744. app.route('/setting/sitemap', methods = ['POST', 'GET'])(main_setting_sitemap)
  745. app.route('/setting/sitemap_set', methods = ['POST', 'GET'])(main_setting_sitemap_set)
  746. app.route('/setting/skin_set', methods = ['POST', 'GET'])(main_setting_skin_set)
  747. app.route('/setting/404_page', methods = ['POST', 'GET'])(setting_404_page)
  748. app.route('/setting/email_test', methods = ['POST', 'GET'])(main_setting_email_test)
  749. app.route('/easter_egg')(main_func_easter_egg)
  750. # views -> view
  751. app.route('/view/<path:name>')(main_view)
  752. app.route('/views/<path:name>')(main_view)
  753. app.route('/image/<path:name>')(main_view_image)
  754. # 조정 계획 중
  755. app.route('/<regex("[^.]+\\.(?:txt|xml|ico)"):data>')(main_view_file)
  756. app.route('/shutdown', methods = ['POST', 'GET'])(main_sys_shutdown)
  757. app.route('/restart', defaults = { 'golang_process' : golang_process }, methods = ['POST', 'GET'])(main_sys_restart)
  758. app.route('/update', defaults = { 'golang_process' : golang_process }, methods = ['POST', 'GET'])(main_sys_update)
  759. app.errorhandler(404)(main_func_error_404)
  760. def terminate_golang():
  761. if golang_process.poll() is None:
  762. golang_process.terminate()
  763. try:
  764. golang_process.wait(timeout = 5)
  765. except subprocess.TimeoutExpired:
  766. golang_process.kill()
  767. try:
  768. golang_process.wait(timeout = 5)
  769. except subprocess.TimeoutExpired:
  770. print('Golang process not terminated properly.')
  771. def signal_handler(signal, frame):
  772. terminate_golang()
  773. os._exit(0)
  774. signal.signal(signal.SIGTERM, signal_handler)
  775. signal.signal(signal.SIGINT, signal_handler)
  776. atexit.register(terminate_golang)
  777. app.wsgi_app = ProxyFix(app.wsgi_app, x_for = 1, x_proto = 1)
  778. if __name__ == "__main__":
  779. if run_mode in ('dev'):
  780. app.run(host = server_set['host'], port = int(server_set['port']), use_reloader = False)
  781. else:
  782. config = Config()
  783. config.bind = [server_set['host'] + ":" + server_set['port']]
  784. asyncio.run(serve(app, config))