app.py 49 KB

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