app.py 47 KB

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