app.py 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. # Init
  2. import os
  3. import re
  4. import logging
  5. from route.tool.func import *
  6. from route import *
  7. from hypercorn.asyncio import serve
  8. from hypercorn.config import Config
  9. # Init-Version
  10. with open('version.json', encoding = 'utf8') as file_data:
  11. version_list = json.loads(file_data.read())
  12. # Init-DB
  13. data_db_set = class_check_json()
  14. do_db_set(data_db_set)
  15. with get_db_connect() as conn:
  16. curs = conn.cursor()
  17. setup_tool = ''
  18. try:
  19. curs.execute(db_change('select data from other where name = "ver"'))
  20. except:
  21. setup_tool = 'init'
  22. if setup_tool != 'init':
  23. ver_set_data = curs.fetchall()
  24. if ver_set_data:
  25. if int(version_list['beta']['c_ver']) > int(ver_set_data[0][0]):
  26. setup_tool = 'update'
  27. else:
  28. setup_tool = 'normal'
  29. else:
  30. setup_tool = 'init'
  31. if data_db_set['type'] == 'mysql':
  32. try:
  33. curs.execute(db_change('create database ' + data_db_set['name'] + ' default character set utf8mb4'))
  34. except:
  35. try:
  36. curs.execute(db_change('alter database ' + data_db_set['name'] + ' character set utf8mb4'))
  37. except:
  38. pass
  39. conn.select_db(data_db_set['name'])
  40. if setup_tool != 'normal':
  41. create_data = get_db_table_list()
  42. for create_table in create_data:
  43. for create in ['test'] + create_data[create_table]:
  44. db_pass = 0
  45. try:
  46. curs.execute(db_change('select ' + create + ' from ' + create_table + ' limit 1'))
  47. db_pass = 1
  48. except:
  49. pass
  50. field_text = 'longtext' if data_db_set['type'] == 'mysql' else 'text'
  51. if db_pass == 0:
  52. try:
  53. curs.execute(db_change('create table ' + create_table + '(test ' + field_text + ' default (""))'))
  54. db_pass = 1
  55. except Exception as e:
  56. # print(e)
  57. pass
  58. if db_pass == 0:
  59. try:
  60. curs.execute(db_change('create table ' + create_table + '(test ' + field_text + ' default "")'))
  61. db_pass = 1
  62. except Exception as e:
  63. # print(e)
  64. pass
  65. if db_pass == 0:
  66. try:
  67. curs.execute(db_change('create table ' + create_table + '(test ' + field_text + ')'))
  68. db_pass = 1
  69. except Exception as e:
  70. # print(e)
  71. pass
  72. if db_pass == 0:
  73. try:
  74. curs.execute(db_change("alter table " + create_table + " add column " + create + " " + field_text + " default ('')"))
  75. db_pass = 1
  76. except Exception as e:
  77. # print(e)
  78. pass
  79. if db_pass == 0:
  80. try:
  81. curs.execute(db_change("alter table " + create_table + " add column " + create + " " + field_text + " default ''"))
  82. db_pass = 1
  83. except Exception as e:
  84. # print(e)
  85. pass
  86. if db_pass == 0:
  87. try:
  88. curs.execute(db_change("alter table " + create_table + " add column " + create + " " + field_text))
  89. db_pass = 1
  90. except Exception as e:
  91. # print(e)
  92. pass
  93. if db_pass == 0:
  94. raise
  95. try:
  96. curs.execute(db_change("create index history_index on history (title, ip)"))
  97. except:
  98. pass
  99. if setup_tool == 'update':
  100. update(conn, int(ver_set_data[0][0]), data_db_set)
  101. else:
  102. set_init(conn)
  103. set_init_always(conn, version_list['beta']['c_ver'])
  104. # Init-Route
  105. class EverythingConverter(werkzeug.routing.PathConverter):
  106. def __init__(self, map):
  107. super(EverythingConverter, self).__init__(map)
  108. self.regex = r'.*?'
  109. def to_python(self, value):
  110. return re.sub(r'^\\\.', '.', value)
  111. class RegexConverter(werkzeug.routing.BaseConverter):
  112. def __init__(self, url_map, *items):
  113. super(RegexConverter, self).__init__(url_map)
  114. self.regex = items[0]
  115. app = flask.Flask(
  116. __name__,
  117. template_folder = './'
  118. )
  119. app.config['JSON_AS_ASCII'] = False
  120. app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
  121. app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600
  122. log = logging.getLogger('hypercorn')
  123. log.setLevel(logging.ERROR)
  124. app.jinja_env.filters['md5_replace'] = md5_replace
  125. app.jinja_env.filters['load_lang'] = load_lang
  126. app.jinja_env.filters['cut_100'] = cut_100
  127. app.url_map.converters['everything'] = EverythingConverter
  128. app.url_map.converters['regex'] = RegexConverter
  129. curs.execute(db_change('select data from other where name = "key"'))
  130. sql_data = curs.fetchall()
  131. app.secret_key = sql_data[0][0]
  132. # Init-DB_Data
  133. server_set = {}
  134. server_set_var = get_init_set_list()
  135. server_set_env = {
  136. 'host' : os.getenv('NAMU_HOST'),
  137. 'port' : os.getenv('NAMU_PORT'),
  138. 'language' : os.getenv('NAMU_LANG'),
  139. 'markup' : os.getenv('NAMU_MARKUP'),
  140. 'encode' : os.getenv('NAMU_ENCRYPT')
  141. }
  142. for i in server_set_var:
  143. curs.execute(db_change('select data from other where name = ?'), [i])
  144. server_set_val = curs.fetchall()
  145. if server_set_val:
  146. server_set_val = server_set_val[0][0]
  147. elif server_set_env[i] != None:
  148. server_set_val = server_set_env[i]
  149. curs.execute(db_change('insert into other (name, data, coverage) values (?, ?, "")'), [i, server_set_env[i]])
  150. else:
  151. if 'list' in server_set_var[i]:
  152. print(server_set_var[i]['display'] + ' (' + server_set_var[i]['default'] + ') [' + ', '.join(server_set_var[i]['list']) + ']' + ' : ', end = '')
  153. else:
  154. print(server_set_var[i]['display'] + ' (' + server_set_var[i]['default'] + ') : ', end = '')
  155. server_set_val = input()
  156. if server_set_val == '':
  157. server_set_val = server_set_var[i]['default']
  158. elif server_set_var[i]['require'] == 'select':
  159. if not server_set_val in server_set_var[i]['list']:
  160. server_set_val = server_set_var[i]['default']
  161. curs.execute(db_change('insert into other (name, data, coverage) values (?, ?, "")'), [i, server_set_val])
  162. print(server_set_var[i]['display'] + ' : ' + server_set_val)
  163. server_set[i] = server_set_val
  164. def back_up(data_db_set):
  165. with get_db_connect() as conn:
  166. curs = conn.cursor()
  167. try:
  168. curs.execute(db_change('select data from other where name = "back_up"'))
  169. back_time = curs.fetchall()
  170. back_time = float(number_check(back_time[0][0], True)) if back_time and back_time[0][0] != '' else 0
  171. curs.execute(db_change('select data from other where name = "backup_count"'))
  172. back_up_count = curs.fetchall()
  173. back_up_count = int(number_check(back_up_count[0][0])) if back_up_count and back_up_count[0][0] != '' else 3
  174. if back_time != 0:
  175. curs.execute(db_change('select data from other where name = "backup_where"'))
  176. back_up_where = curs.fetchall()
  177. back_up_where = back_up_where[0][0] if back_up_where and back_up_where[0][0] != '' else data_db_set['name'] + '.db'
  178. print('Back up state : ' + str(back_time) + ' hours')
  179. print('Back up directory : ' + back_up_where)
  180. if back_up_count != 0:
  181. print('Back up max number : ' + str(back_up_count))
  182. file_dir = os.path.split(back_up_where)[0]
  183. file_dir = '.' if file_dir == '' else file_dir
  184. file_name = os.path.split(back_up_where)[1]
  185. file_name = re.sub(r'\.db$', '_[0-9]{14}.db', file_name)
  186. backup_file = [for_a for for_a in os.listdir(file_dir) if re.search('^' + file_name + '$', for_a)]
  187. backup_file = sorted(backup_file)
  188. if len(backup_file) >= back_up_count:
  189. remove_dir = os.path.join(file_dir, backup_file[0])
  190. os.remove(remove_dir)
  191. print('Back up : Remove (' + remove_dir + ')')
  192. now_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
  193. new_file_name = re.sub(r'\.db$', '_' + now_time + '.db', back_up_where)
  194. shutil.copyfile(
  195. data_db_set['name'] + '.db',
  196. new_file_name
  197. )
  198. print('Back up : OK (' + new_file_name + ')')
  199. else:
  200. print('Back up state : Turn off')
  201. back_time = 1
  202. except Exception as e:
  203. print('Back up : Error')
  204. print(e)
  205. back_time = 1
  206. threading.Timer(60 * 60 * back_time, back_up, [data_db_set]).start()
  207. def do_every_day():
  208. with get_db_connect() as conn:
  209. curs = conn.cursor()
  210. # 오늘의 날짜 불러오기
  211. time_today = get_time().split()[0]
  212. # vote 관리
  213. curs.execute(db_change('select id, type from vote where type = "open" or type = "n_open"'))
  214. for for_a in curs.fetchall():
  215. curs.execute(db_change('select data from vote where id = ? and name = "end_date" and type = "option"'), [for_a[0]])
  216. db_data = curs.fetchall()
  217. if db_data:
  218. time_db = db_data[0][0].split()[0]
  219. if time_today > time_db:
  220. 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]])
  221. # ban 관리
  222. curs.execute(db_change("update rb set ongoing = '' where end < ? and end != '' and ongoing = '1'"), [get_time()])
  223. # auth 관리
  224. curs.execute(db_change('select id, data from user_set where name = "auth_date"'))
  225. db_data = curs.fetchall()
  226. for for_a in db_data:
  227. time_db = for_a[1].split()[0]
  228. if time_today > time_db:
  229. curs.execute(db_change("update user_set set data = 'user' where id = ? and name = 'acl'"), [for_a[0]])
  230. curs.execute(db_change('delete from user_set where name = "auth_date" and id = ?'), [for_a[0]])
  231. # acl 관리
  232. curs.execute(db_change("select doc_name, doc_rev, set_data from data_set where set_name = 'acl_date'"))
  233. db_data = curs.fetchall()
  234. for for_a in db_data:
  235. time_db = for_a[2].split()[0]
  236. if time_today > time_db:
  237. curs.execute(db_change("delete from acl where title = ? and type = ?"), [for_a[0], for_a[1]])
  238. 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]])
  239. # ua 관리
  240. curs.execute(db_change('select data from other where name = "ua_expiration_date"'))
  241. db_data = curs.fetchall()
  242. if db_data and db_data[0][0] != '':
  243. time_db = int(number_check(db_data[0][0]))
  244. time_calc = datetime.date.today() - datetime.timedelta(days = time_db)
  245. time_calc = time_calc.strftime('%Y-%m-%d %H:%M:%S')
  246. curs.execute(db_change("delete from ua_d where today < ?"), [time_calc])
  247. # auth history 관리
  248. curs.execute(db_change('select data from other where name = "auth_history_expiration_date"'))
  249. db_data = curs.fetchall()
  250. if db_data and db_data[0][0] != '':
  251. time_db = int(number_check(db_data[0][0]))
  252. time_calc = datetime.date.today() - datetime.timedelta(days = time_db)
  253. time_calc = time_calc.strftime('%Y-%m-%d %H:%M:%S')
  254. curs.execute(db_change("delete from re_admin where time < ?"), [time_calc])
  255. # 사이트맵 생성 관리
  256. curs.execute(db_change('select data from other where name = "sitemap_auto_make"'))
  257. db_data = curs.fetchall()
  258. if db_data and db_data[0][0] != '':
  259. main_setting_sitemap(1)
  260. print('Make sitemap')
  261. # 칭호 관리
  262. curs.execute(db_change("select id from user_set where name = 'user_title' and data = '✅'"))
  263. for for_a in curs.fetchall():
  264. if admin_check(conn, 'all', None, for_a[0]) != 1:
  265. curs.execute(db_change("update user_set set data = '☑️' where name = 'user_title' and data = '✅' and id = ?"), [for_a[0]])
  266. threading.Timer(60 * 60 * 24, do_every_day).start()
  267. def auto_do_something(data_db_set):
  268. if data_db_set['type'] == 'sqlite':
  269. back_up(data_db_set)
  270. do_every_day()
  271. auto_do_something(data_db_set)
  272. print('Now running... http://localhost:' + server_set['port'])
  273. # Init-custom
  274. if os.path.exists('custom.py'):
  275. from custom import custom_run
  276. custom_run('error', app)
  277. # Func
  278. # Func-inter_wiki
  279. app.route('/filter/inter_wiki', defaults = { 'tool' : 'inter_wiki' })(filter_all)
  280. app.route('/filter/inter_wiki/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'inter_wiki' })(filter_all_add)
  281. app.route('/filter/inter_wiki/add/<everything:name>', methods = ['POST', 'GET'], defaults = { 'tool' : 'inter_wiki' })(filter_all_add)
  282. app.route('/filter/inter_wiki/del/<everything:name>', defaults = { 'tool' : 'inter_wiki' })(filter_all_delete)
  283. app.route('/filter/outer_link', defaults = { 'tool' : 'outer_link' })(filter_all)
  284. app.route('/filter/outer_link/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'outer_link' })(filter_all_add)
  285. app.route('/filter/outer_link/add/<everything:name>', methods = ['POST', 'GET'], defaults = { 'tool' : 'outer_link' })(filter_all_add)
  286. app.route('/filter/outer_link/del/<everything:name>', defaults = { 'tool' : 'outer_link' })(filter_all_delete)
  287. app.route('/filter/document', defaults = { 'tool' : 'document' })(filter_all)
  288. app.route('/filter/document/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'document' })(filter_all_add)
  289. app.route('/filter/document/add/<everything:name>', methods = ['POST', 'GET'], defaults = { 'tool' : 'document' })(filter_all_add)
  290. app.route('/filter/document/del/<everything:name>', defaults = { 'tool' : 'document' })(filter_all_delete)
  291. app.route('/filter/edit_top', defaults = { 'tool' : 'edit_top' })(filter_all)
  292. app.route('/filter/edit_top/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'edit_top' })(filter_all_add)
  293. app.route('/filter/edit_top/add/<everything:name>', methods = ['POST', 'GET'], defaults = { 'tool' : 'edit_top' })(filter_all_add)
  294. app.route('/filter/edit_top/del/<everything:name>', defaults = { 'tool' : 'edit_top' })(filter_all_delete)
  295. app.route('/filter/image_license', defaults = { 'tool' : 'image_license' })(filter_all)
  296. app.route('/filter/image_license/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'image_license' })(filter_all_add)
  297. app.route('/filter/image_license/del/<everything:name>', defaults = { 'tool' : 'image_license' })(filter_all_delete)
  298. app.route('/filter/template', defaults = { 'tool' : 'template' })(filter_all)
  299. app.route('/filter/template/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'template' })(filter_all_add)
  300. app.route('/filter/template/add/<everything:name>', methods = ['POST', 'GET'], defaults = { 'tool' : 'template' })(filter_all_add)
  301. app.route('/filter/template/del/<everything:name>', defaults = { 'tool' : 'template' })(filter_all_delete)
  302. app.route('/filter/edit_filter', defaults = { 'tool' : 'edit_filter' })(filter_all)
  303. app.route('/filter/edit_filter/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'edit_filter' })(filter_all_add)
  304. app.route('/filter/edit_filter/add/<everything:name>', methods = ['POST', 'GET'], defaults = { 'tool' : 'edit_filter' })(filter_all_add)
  305. app.route('/filter/edit_filter/del/<everything:name>', defaults = { 'tool' : 'edit_filter' })(filter_all_delete)
  306. app.route('/filter/email_filter', defaults = { 'tool' : 'email_filter' })(filter_all)
  307. app.route('/filter/email_filter/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'email_filter' })(filter_all_add)
  308. app.route('/filter/email_filter/del/<everything:name>', defaults = { 'tool' : 'email_filter' })(filter_all_delete)
  309. app.route('/filter/file_filter', defaults = { 'tool' : 'file_filter' })(filter_all)
  310. app.route('/filter/file_filter/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'file_filter' })(filter_all_add)
  311. app.route('/filter/file_filter/del/<everything:name>', defaults = { 'tool' : 'file_filter' })(filter_all_delete)
  312. app.route('/filter/name_filter', defaults = { 'tool' : 'name_filter' })(filter_all)
  313. app.route('/filter/name_filter/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'name_filter' })(filter_all_add)
  314. app.route('/filter/name_filter/del/<everything:name>', defaults = { 'tool' : 'name_filter' })(filter_all_delete)
  315. app.route('/filter/extension_filter', defaults = { 'tool' : 'extension_filter' })(filter_all)
  316. app.route('/filter/extension_filter/add', methods = ['POST', 'GET'], defaults = { 'tool' : 'extension_filter' })(filter_all_add)
  317. app.route('/filter/extension_filter/del/<everything:name>', defaults = { 'tool' : 'extension_filter' })(filter_all_delete)
  318. # Func-list
  319. app.route('/list/document/old', defaults = { 'set_type' : 'old' })(list_old_page)
  320. app.route('/list/document/old/<int:num>', defaults = { 'set_type' : 'old' })(list_old_page)
  321. app.route('/list/document/new', defaults = { 'set_type' : 'new' })(list_old_page)
  322. app.route('/list/document/new/<int:num>', defaults = { 'set_type' : 'new' })(list_old_page)
  323. app.route('/list/document/no_link')(list_no_link)
  324. app.route('/list/document/no_link/<int:num>')(list_no_link)
  325. app.route('/list/document/acl')(list_acl)
  326. app.route('/list/document/acl/<int:arg_num>')(list_acl)
  327. app.route('/list/document/need')(list_please)
  328. app.route('/list/document/need/<int:arg_num>')(list_please)
  329. app.route('/list/document/all')(list_title_index)
  330. app.route('/list/document/all/<int:num>')(list_title_index)
  331. app.route('/list/document/long')(list_long_page)
  332. app.route('/list/document/long/<int:arg_num>')(list_long_page)
  333. app.route('/list/document/short', defaults = { 'tool' : 'short_page' })(list_long_page)
  334. app.route('/list/document/short/<int:arg_num>', defaults = { 'tool' : 'short_page' })(list_long_page)
  335. app.route('/list/file')(list_image_file)
  336. app.route('/list/file/<int:arg_num>')(list_image_file)
  337. app.route('/list/image', defaults = { 'do_type' : 1 })(list_image_file)
  338. app.route('/list/image/<int:arg_num>', defaults = { 'do_type' : 1 })(list_image_file)
  339. app.route('/list/admin')(list_admin)
  340. app.route('/list/admin/auth_use', methods = ['POST', 'GET'])(list_admin_auth_use)
  341. app.route('/list/admin/auth_use_page/<int:arg_num>/<everything:arg_search>', methods = ['POST', 'GET'])(list_admin_auth_use)
  342. app.route('/list/user')(list_user)
  343. app.route('/list/user/<int:arg_num>')(list_user)
  344. app.route('/list/user/check_submit/<name>')(list_user_check_submit)
  345. app.route('/list/user/check/<name>')(list_user_check)
  346. app.route('/list/user/check/<name>/<do_type>')(list_user_check)
  347. app.route('/list/user/check/<name>/<do_type>/<int:arg_num>')(list_user_check)
  348. app.route('/list/user/check/<name>/<do_type>/<int:arg_num>/<plus_name>')(list_user_check)
  349. app.route('/list/user/check/delete/<name>/<ip>/<time>/<do_type>', methods = ['POST', 'GET'])(list_user_check_delete)
  350. # Func-auth
  351. app.route('/auth/give', methods = ['POST', 'GET'])(give_auth)
  352. app.route('/auth/give/<name>', methods = ['POST', 'GET'])(give_auth)
  353. app.route('/auth/give/ban', methods = ['POST', 'GET'])(give_user_ban)
  354. app.route('/auth/give/ban/<everything:name>', methods = ['POST', 'GET'])(give_user_ban)
  355. app.route('/auth/give/ban_cidr/<everything:name>', methods = ['POST', 'GET'], defaults = { 'ban_type' : 'cidr' })(give_user_ban)
  356. app.route('/auth/give/ban_regex/<everything:name>', methods = ['POST', 'GET'], defaults = { 'ban_type' : 'regex' })(give_user_ban)
  357. app.route('/auth/give/ban_multiple', methods = ['POST', 'GET'], defaults = { 'ban_type' : 'multiple' })(give_user_ban)
  358. # /auth/list
  359. # /auth/list/add/<name>
  360. # /auth/list/delete/<name>
  361. app.route('/auth/list')(list_admin_group_2)
  362. app.route('/auth/list/add/<name>', methods = ['POST', 'GET'])(give_admin_groups_2)
  363. app.route('/auth/list/delete/<name>', methods = ['POST', 'GET'])(give_delete_admin_group_2)
  364. app.route('/auth/give/fix/<user_name>', methods = ['POST', 'GET'])(give_user_fix)
  365. app.route('/app_submit', methods = ['POST', 'GET'])(recent_app_submit_2)
  366. # /auth/history
  367. app.route('/recent_block')(list_recent_block)
  368. app.route('/recent_block/all')(list_recent_block)
  369. app.route('/recent_block/all/<int:num>')(list_recent_block)
  370. app.route('/recent_block/user/<user_name>', defaults = { 'tool' : 'user' })(list_recent_block)
  371. app.route('/recent_block/user/<user_name>/<int:num>', defaults = { 'tool' : 'user' })(list_recent_block)
  372. app.route('/recent_block/admin/<user_name>', defaults = { 'tool' : 'admin' })(list_recent_block)
  373. app.route('/recent_block/admin/<user_name>/<int:num>', defaults = { 'tool' : 'admin' })(list_recent_block)
  374. app.route('/recent_block/regex', defaults = { 'tool' : 'regex' })(list_recent_block)
  375. app.route('/recent_block/regex/<int:num>', defaults = { 'tool' : 'regex' })(list_recent_block)
  376. app.route('/recent_block/cidr', defaults = { 'tool' : 'cidr' })(list_recent_block)
  377. app.route('/recent_block/cidr/<int:num>', defaults = { 'tool' : 'cidr' })(list_recent_block)
  378. app.route('/recent_block/ongoing', defaults = { 'tool' : 'ongoing' })(list_recent_block)
  379. app.route('/recent_block/ongoing/<int:num>', defaults = { 'tool' : 'ongoing' })(list_recent_block)
  380. app.route('/recent_change')(list_recent_change)
  381. app.route('/recent_changes')(list_recent_change)
  382. app.route('/recent_change/<int:num>/<set_type>')(list_recent_change)
  383. app.route('/recent_discuss', defaults = { 'tool' : 'normal' })(list_recent_discuss)
  384. app.route('/recent_discuss/<int:num>/<tool>')(list_recent_discuss)
  385. # Func-history
  386. app.route('/recent_edit_request')(recent_edit_request)
  387. app.route('/record/<name>', defaults = { 'tool' : 'record' })(recent_change)
  388. app.route('/record/<int:num>/<set_type>/<name>', defaults = { 'tool' : 'record' })(recent_change)
  389. app.route('/record/reset/<name>', methods = ['POST', 'GET'])(recent_record_reset)
  390. app.route('/record/topic/<name>')(recent_record_topic)
  391. app.route('/record/bbs/<name>', defaults = { 'tool' : 'record' })(bbs_w)
  392. app.route('/record/bbs_comment/<name>', defaults = { 'tool' : 'comment_record' })(bbs_w)
  393. app.route('/history/<everything:name>', defaults = { 'tool' : 'history' }, methods = ['POST', 'GET'])(recent_change)
  394. app.route('/history_page/<int:num>/<set_type>/<everything:name>', defaults = { 'tool' : 'history' }, methods = ['POST', 'GET'])(recent_change)
  395. app.route('/history_tool/<int(signed = True):rev>/<everything:name>')(recent_history_tool)
  396. app.route('/history_delete/<int(signed = True):rev>/<everything:name>', methods = ['POST', 'GET'])(recent_history_delete)
  397. app.route('/history_hidden/<int(signed = True):rev>/<everything:name>')(recent_history_hidden)
  398. app.route('/history_send/<int(signed = True):rev>/<everything:name>', methods = ['POST', 'GET'])(recent_history_send)
  399. app.route('/history_reset/<everything:name>', methods = ['POST', 'GET'])(recent_history_reset)
  400. app.route('/history_add/<everything:name>', methods = ['POST', 'GET'])(recent_history_add)
  401. # Func-view
  402. app.route('/xref/<everything:name>')(view_xref)
  403. app.route('/xref_page/<int:num>/<everything:name>')(view_xref)
  404. app.route('/xref_this/<everything:name>', defaults = { 'xref_type' : 2 })(view_xref)
  405. app.route('/xref_this_page/<int:num>/<everything:name>', defaults = { 'xref_type' : 2 })(view_xref)
  406. app.route('/doc_watch_list/<int:num>/<everything:name>')(w_watch_list)
  407. app.route('/doc_star_doc/<int:num>/<everything:name>', defaults = { 'do_type' : 'star_doc' })(w_watch_list)
  408. app.route('/raw/<everything:name>')(view_w_raw)
  409. app.route('/raw_acl/<everything:name>', defaults = { 'doc_acl' : 'on' })(view_w_raw)
  410. app.route('/raw_rev/<int(signed = True):rev>/<everything:name>')(view_w_raw)
  411. app.route('/diff/<int(signed = True):num_a>/<int(signed = True):num_b>/<everything:name>')(view_diff)
  412. app.route('/down/<everything:name>')(view_down)
  413. app.route('/acl_multiple', defaults = { 'multiple' : True }, methods = ['POST', 'GET'])(view_set)
  414. app.route('/acl/<everything:name>', methods = ['POST', 'GET'])(view_set)
  415. app.route('/w_from/<everything:name>', defaults = { 'do_type' : 'from' })(view_w)
  416. app.route('/w/<everything:name>')(view_w)
  417. app.route('/random')(view_random)
  418. # Func-edit
  419. app.route('/edit/<everything:name>', methods = ['POST', 'GET'])(edit)
  420. app.route('/edit_from/<everything:name>', methods = ['POST', 'GET'], defaults = { 'do_type' : 'load' })(edit)
  421. app.route('/edit_section/<int:section>/<everything:name>', methods = ['POST', 'GET'])(edit)
  422. app.route('/edit_request/<everything:name>', methods = ['POST', 'GET'])(edit_request)
  423. app.route('/edit_request_from/<everything:name>', defaults = { 'do_type' : 'from' }, methods = ['POST', 'GET'])(edit_request)
  424. # app.route('/edit_request_rev/<int:rev>/<everything:name>', methods = ['POST', 'GET'])(edit_request)
  425. app.route('/upload', methods = ['POST', 'GET'])(edit_upload)
  426. # 개편 예정
  427. app.route('/xref_reset/<everything:name>')(edit_backlink_reset)
  428. app.route('/delete/<everything:name>', methods = ['POST', 'GET'])(edit_delete)
  429. app.route('/delete_file/<everything:name>', methods = ['POST', 'GET'])(edit_delete_file)
  430. app.route('/delete_multiple', methods = ['POST', 'GET'])(edit_delete_multiple)
  431. app.route('/revert/<int:num>/<everything:name>', methods = ['POST', 'GET'])(edit_revert)
  432. app.route('/move/<everything:name>', methods = ['POST', 'GET'])(edit_move)
  433. app.route('/move_all')(edit_move_all)
  434. # Func-topic
  435. app.route('/topic/<everything:name>', methods = ['POST', 'GET'])(topic_list)
  436. app.route('/topic_page/<int:page>/<everything:name>', methods = ['POST', 'GET'])(topic_list)
  437. app.route('/thread/<int:topic_num>', methods = ['POST', 'GET'])(topic)
  438. app.route('/thread/0/<everything:doc_name>', defaults = { 'topic_num' : '0' }, methods = ['POST', 'GET'])(topic)
  439. app.route('/thread/<int:topic_num>/tool')(topic_tool)
  440. app.route('/thread/<int:topic_num>/setting', methods = ['POST', 'GET'])(topic_tool_setting)
  441. app.route('/thread/<int:topic_num>/acl', methods = ['POST', 'GET'])(topic_tool_acl)
  442. app.route('/thread/<int:topic_num>/delete', methods = ['POST', 'GET'])(topic_tool_delete)
  443. app.route('/thread/<int:topic_num>/change', methods = ['POST', 'GET'])(topic_tool_change)
  444. app.route('/thread/<int:topic_num>/comment/<int:num>/tool')(topic_comment_tool)
  445. app.route('/thread/<int:topic_num>/comment/<int:num>/notice')(topic_comment_notice)
  446. app.route('/thread/<int:topic_num>/comment/<int:num>/blind')(topic_comment_blind)
  447. app.route('/thread/<int:topic_num>/comment/<int:num>/raw')(view_raw)
  448. app.route('/thread/<int:topic_num>/comment/<int:num>/delete', methods = ['POST', 'GET'])(topic_comment_delete)
  449. # Func-user
  450. app.route('/change', methods = ['POST', 'GET'])(user_setting)
  451. app.route('/change/key')(user_setting_key)
  452. app.route('/change/key/delete')(user_setting_key_delete)
  453. app.route('/change/pw', methods = ['POST', 'GET'])(user_setting_pw)
  454. app.route('/change/head', methods = ['GET', 'POST'], defaults = { 'skin_name' : '' })(user_setting_head)
  455. app.route('/change/head/<skin_name>', methods = ['GET', 'POST'])(user_setting_head)
  456. app.route('/change/head_reset', methods = ['GET', 'POST'])(user_setting_head_reset)
  457. app.route('/change/skin_set')(user_setting_skin_set)
  458. app.route('/change/top_menu', methods = ['GET', 'POST'])(user_setting_top_menu)
  459. app.route('/change/user_name', methods = ['GET', 'POST'])(user_setting_user_name)
  460. app.route('/change/user_name/<user_name>', methods = ['GET', 'POST'])(user_setting_user_name)
  461. # 하위 호환용 S
  462. app.route('/skin_set')(user_setting_skin_set)
  463. # 하위 호환용 E
  464. app.route('/change/skin_set/main', methods = ['POST', 'GET'])(user_setting_skin_set_main)
  465. app.route('/user')(user_info)
  466. app.route('/user/<name>')(user_info)
  467. app.route('/challenge', methods = ['GET', 'POST'])(user_challenge)
  468. app.route('/edit_filter/<name>', methods = ['GET', 'POST'])(user_edit_filter)
  469. app.route('/count')(user_count)
  470. app.route('/count/<name>')(user_count)
  471. app.route('/alarm')(user_alarm)
  472. app.route('/alarm/delete')(user_alarm_delete)
  473. app.route('/alarm/delete/<int:id>')(user_alarm_delete)
  474. app.route('/watch_list', defaults = { 'tool' : 'watch_list' })(user_watch_list)
  475. app.route('/watch_list/<everything:name>', defaults = { 'tool' : 'watch_list' })(user_watch_list_name)
  476. app.route('/watch_list_from/<everything:name>', defaults = { 'tool' : 'watch_list_from' })(user_watch_list_name)
  477. app.route('/star_doc', defaults = { 'tool' : 'star_doc' })(user_watch_list)
  478. app.route('/star_doc/<everything:name>', defaults = { 'tool' : 'star_doc' })(user_watch_list_name)
  479. app.route('/star_doc_from/<everything:name>', defaults = { 'tool' : 'star_doc_from' })(user_watch_list_name)
  480. # 개편 보류중 S
  481. app.route('/change/email', methods = ['POST', 'GET'])(user_setting_email_2)
  482. app.route('/change/email/delete')(user_setting_email_delete)
  483. app.route('/change/email/check', methods = ['POST', 'GET'])(user_setting_email_check_2)
  484. # 개편 보류중 E
  485. # Func-login
  486. # 개편 예정
  487. # login -> login/2fa -> login/2fa/email with login_id
  488. # register -> register/email -> regiter/email/check with reg_id
  489. # pass_find -> pass_find/email with find_id
  490. app.route('/login', methods = ['POST', 'GET'])(login_login_2)
  491. app.route('/login/2fa', methods = ['POST', 'GET'])(login_login_2fa_2)
  492. app.route('/register', methods = ['POST', 'GET'])(login_register_2)
  493. app.route('/register/email', methods = ['POST', 'GET'])(login_register_email_2)
  494. app.route('/register/email/check', methods = ['POST', 'GET'])(login_register_email_check_2)
  495. app.route('/register/submit', methods = ['POST', 'GET'])(login_register_submit_2)
  496. app.route('/login/find')(login_find)
  497. app.route('/login/find/key', methods = ['POST', 'GET'])(login_find_key)
  498. app.route('/login/find/email', methods = ['POST', 'GET'], defaults = { 'tool' : 'pass_find' })(login_find_email)
  499. app.route('/login/find/email/check', methods = ['POST', 'GET'], defaults = { 'tool' : 'check_key' })(login_find_email_check)
  500. app.route('/logout')(login_logout)
  501. # Func-vote
  502. app.route('/vote/<int:num>', methods = ['POST', 'GET'])(vote_select)
  503. app.route('/vote/end/<int:num>')(vote_end)
  504. app.route('/vote/close/<int:num>')(vote_close)
  505. app.route('/vote', defaults = { 'list_type' : 'normal' })(vote_list)
  506. app.route('/vote/list', defaults = { 'list_type' : 'normal' })(vote_list)
  507. app.route('/vote/list/<int:num>', defaults = { 'list_type' : 'normal' })(vote_list)
  508. app.route('/vote/list/close', defaults = { 'list_type' : 'close' })(vote_list)
  509. app.route('/vote/list/close/<int:num>', defaults = { 'list_type' : 'close' })(vote_list)
  510. app.route('/vote/add', methods = ['POST', 'GET'])(vote_add)
  511. # Func-bbs
  512. app.route('/bbs/main')(bbs_main)
  513. app.route('/bbs/make', methods = ['POST', 'GET'])(bbs_make)
  514. # app.route('/bbs/main/set')
  515. app.route('/bbs/in/<int:bbs_num>')(bbs_in)
  516. app.route('/bbs/in/<int:bbs_num>/<int:page>')(bbs_in)
  517. # app.route('/bbs/blind/<int:bbs_num>', methods = ['POST', 'GET'])(bbs_hide)
  518. app.route('/bbs/delete/<int:bbs_num>', methods = ['POST', 'GET'])(bbs_delete)
  519. app.route('/bbs/set/<int:bbs_num>', methods = ['POST', 'GET'])(bbs_w_set)
  520. app.route('/bbs/edit/<int:bbs_num>', methods = ['POST', 'GET'])(bbs_w_edit)
  521. app.route('/bbs/w/<int:bbs_num>/<int:post_num>', methods = ['POST', 'GET'])(bbs_w_post)
  522. # app.route('/bbs/blind/<int:bbs_num>/<int:post_num>', methods = ['POST', 'GET'])(bbs_w_hide)
  523. app.route('/bbs/pinned/<int:bbs_num>/<int:post_num>', methods = ['POST', 'GET'])(bbs_w_pinned)
  524. app.route('/bbs/delete/<int:bbs_num>/<int:post_num>', methods = ['POST', 'GET'])(bbs_w_delete)
  525. app.route('/bbs/raw/<int:bbs_num>/<int:post_num>')(view_raw)
  526. app.route('/bbs/tool/<int:bbs_num>/<int:post_num>')(bbs_w_tool)
  527. app.route('/bbs/edit/<int:bbs_num>/<int:post_num>', methods = ['POST', 'GET'])(bbs_w_edit)
  528. app.route('/bbs/tool/<int:bbs_num>/<int:post_num>/<comment_num>')(bbs_w_comment_tool)
  529. app.route('/bbs/raw/<int:bbs_num>/<int:post_num>/<comment_num>')(view_raw)
  530. app.route('/bbs/edit/<int:bbs_num>/<int:post_num>/<comment_num>', methods = ['POST', 'GET'])(bbs_w_edit)
  531. app.route('/bbs/delete/<int:bbs_num>/<int:post_num>/<comment_num>', methods = ['POST', 'GET'])(bbs_w_delete)
  532. # Func-api
  533. ## v1 API
  534. app.route('/api/render', methods = ['POST'])(api_w_render)
  535. app.route('/api/render/<tool>', methods = ['POST'])(api_w_render)
  536. app.route('/api/raw_exist/<everything:name>', defaults = { 'exist_check' : 'on' })(api_w_raw)
  537. app.route('/api/raw_rev/<int(signed = True):rev>/<everything:name>')(api_w_raw)
  538. app.route('/api/raw/<everything:name>')(api_w_raw)
  539. app.route('/api/xref/<int:num>/<everything:name>')(api_w_xref)
  540. app.route('/api/xref_this/<int:num>/<everything:name>', defaults = { 'xref_type' : '2' })(api_w_xref)
  541. app.route('/api/random')(api_w_random)
  542. app.route('/api/bbs/w/<sub_code>')(api_bbs_w_post)
  543. app.route('/api/bbs/w/comment/<sub_code>')(api_bbs_w_comment)
  544. app.route('/api/bbs/w/comment_one/<sub_code>')(api_bbs_w_comment)
  545. app.route('/api/version', defaults = { 'version_list' : version_list })(api_version)
  546. app.route('/api/skin_info')(api_skin_info)
  547. app.route('/api/skin_info/<name>')(api_skin_info)
  548. app.route('/api/user_info/<user_name>')(api_user_info)
  549. app.route('/api/setting/<name>')(api_setting)
  550. app.route('/api/auth_list')(api_func_auth_list)
  551. app.route('/api/auth_list/<user_name>')(api_func_auth_list)
  552. app.route('/api/thread/<int:topic_num>/<int:s_num>/<int:e_num>')(api_topic)
  553. app.route('/api/thread/<int:topic_num>/<tool>')(api_topic)
  554. app.route('/api/thread/<int:topic_num>')(api_topic)
  555. app.route('/api/search/<everything:name>')(api_search)
  556. app.route('/api/search_page/<int:num>/<everything:name>')(api_search)
  557. app.route('/api/search_data/<everything:name>', defaults = { 'search_type' : 'data' })(api_search)
  558. app.route('/api/search_data_page/<int:num>/<everything:name>', defaults = { 'search_type' : 'data' })(api_search)
  559. app.route('/api/recent_change')(api_list_recent_change)
  560. app.route('/api/recent_changes')(api_list_recent_change)
  561. app.route('/api/recent_change/<int:limit>')(api_list_recent_change)
  562. app.route('/api/recent_change/<int:limit>/<set_type>/<int:num>')(api_list_recent_change)
  563. app.route('/api/recent_edit_request')(api_list_recent_edit_request)
  564. app.route('/api/recent_edit_request/<int:limit>/<set_type>/<int:num>')(api_list_recent_edit_request)
  565. app.route('/api/recent_discuss/<set_type>/<int:limit>')(api_list_recent_discuss)
  566. app.route('/api/recent_discuss/<int:limit>')(api_list_recent_discuss)
  567. app.route('/api/recent_discuss')(api_list_recent_discuss)
  568. app.route('/api/lang', methods = ['POST'])(api_func_language)
  569. app.route('/api/lang/<data>')(api_func_language)
  570. app.route('/api/sha224/<everything:data>')(api_func_sha224)
  571. app.route('/api/ip/<everything:data>')(api_func_ip)
  572. app.route('/api/image/<everything:name>')(api_image_view)
  573. ## v2 API
  574. app.route('/api/v2/recent_edit_request/<set_type>/<int:num>', defaults = { 'limit' : 50 })(api_list_recent_edit_request)
  575. app.route('/api/v2/recent_change/<set_type>/<int:num>', defaults = { 'legacy' : '', 'limit' : 50 })(api_list_recent_change)
  576. app.route('/api/v2/recent_discuss/<set_type>/<int:num>', defaults = { 'legacy' : '', 'limit' : 50 })(api_list_recent_discuss)
  577. app.route('/api/v2/recent_block/<set_type>/<int:num>')(api_list_recent_block)
  578. app.route('/api/v2/recent_block/<set_type>/<int:num>/<user_name>')(api_list_recent_block)
  579. app.route('/api/v2/list/document/old/<int:num>', defaults = { 'set_type' : 'old' })(api_list_old_page)
  580. app.route('/api/v2/list/document/new/<int:num>', defaults = { 'set_type' : 'new' })(api_list_old_page)
  581. app.route('/api/v2/list/document/<int:num>')(api_list_title_index)
  582. app.route('/api/v2/topic/<int:num>/<set_type>/<everything:name>')(api_topic_list)
  583. app.route('/api/v2/bbs')(api_bbs_list)
  584. app.route('/api/v2/bbs/main')(api_bbs)
  585. app.route('/api/v2/bbs/in/<int:bbs_num>/<int:page>')(api_bbs)
  586. app.route('/api/v2/bbs/w/comment/<int:bbs_num>/<int:post_num>/<tool>')(api_bbs_w_comment_n)
  587. app.route('/api/v2/doc_star_doc/<int:num>/<everything:name>', defaults = { 'do_type' : 'star_doc' })(api_w_watch_list)
  588. app.route('/api/v2/doc_watch_list/<int:num>/<everything:name>')(api_w_watch_list)
  589. app.route('/api/v2/set_reset/<everything:name>')(api_w_set_reset)
  590. app.route('/api/v2/setting/<name>', methods = ['GET', 'PUT'])(api_setting)
  591. app.route('/api/v2/user/setting/editor', methods = ['GET', 'POST', 'DELETE'])(api_user_setting_editor)
  592. app.route('/api/v2/ip/<everything:data>')(api_func_ip)
  593. app.route('/api/v2/ip_menu/<everything:ip>', defaults = { 'option' : 'user' })(api_func_ip_menu)
  594. app.route('/api/v2/user_menu/<everything:ip>')(api_func_ip_menu)
  595. # Func-main
  596. # 여기도 전반적인 조정 시행 예정
  597. app.route('/other')(main_tool_other)
  598. app.route('/manager', methods = ['POST', 'GET'])(main_tool_admin)
  599. app.route('/manager/<int:num>', methods = ['POST', 'GET'])(main_tool_redirect)
  600. app.route('/manager/<int:num>/<everything:add_2>', methods = ['POST', 'GET'])(main_tool_redirect)
  601. app.route('/search', methods=['POST'])(main_search)
  602. app.route('/search/<everything:name>', methods = ['POST', 'GET'])(main_search_deep)
  603. app.route('/search_page/<int:num>/<everything:name>', methods = ['POST', 'GET'])(main_search_deep)
  604. app.route('/search_data/<everything:name>', defaults = { 'search_type' : 'data' }, methods = ['POST', 'GET'])(main_search_deep)
  605. app.route('/search_data_page/<int:num>/<everything:name>', defaults = { 'search_type' : 'data' }, methods = ['POST', 'GET'])(main_search_deep)
  606. app.route('/goto', methods=['POST'])(main_search_goto)
  607. app.route('/goto/<everything:name>', methods=['GET', 'POST'])(main_search_goto)
  608. app.route('/setting')(main_setting)
  609. app.route('/setting/main', methods = ['POST', 'GET'])(main_setting_main)
  610. app.route('/setting/main/logo', methods = ['POST', 'GET'])(main_setting_main_logo)
  611. app.route('/setting/top_menu', methods = ['POST', 'GET'])(main_setting_top_menu)
  612. app.route('/setting/phrase', methods = ['POST', 'GET'])(main_setting_phrase)
  613. app.route('/setting/head', defaults = { 'num' : 3 }, methods = ['POST', 'GET'])(main_setting_head)
  614. app.route('/setting/head/<skin_name>', defaults = { 'num' : 3 }, methods = ['POST', 'GET'])(main_setting_head)
  615. app.route('/setting/body/top', defaults = { 'num' : 4 }, methods = ['POST', 'GET'])(main_setting_head)
  616. app.route('/setting_preview/body/top', defaults = { 'num' : 4, 'set_preview' : 1 }, methods = ['POST'])(main_setting_head)
  617. app.route('/setting/body/bottom', defaults = { 'num' : 7 }, methods = ['POST', 'GET'])(main_setting_head)
  618. app.route('/setting_preview/body/bottom', defaults = { 'num' : 7, 'set_preview' : 1 }, methods = ['POST'])(main_setting_head)
  619. app.route('/setting/robot', methods = ['POST', 'GET'])(main_setting_robot)
  620. app.route('/setting/external', methods = ['POST', 'GET'])(main_setting_external)
  621. app.route('/setting/acl', methods = ['POST', 'GET'])(main_setting_acl)
  622. app.route('/setting/sitemap', methods = ['POST', 'GET'])(main_setting_sitemap)
  623. app.route('/setting/sitemap_set', methods = ['POST', 'GET'])(main_setting_sitemap_set)
  624. app.route('/setting/skin_set', methods = ['POST', 'GET'])(main_setting_skin_set)
  625. app.route('/setting/404_page', methods = ['POST', 'GET'])(setting_404_page)
  626. app.route('/easter_egg')(main_func_easter_egg)
  627. # views -> view
  628. app.route('/view/<path:name>')(main_view)
  629. app.route('/views/<path:name>')(main_view)
  630. app.route('/image/<path:name>')(main_view_image)
  631. # 조정 계획 중
  632. app.route('/<regex("[^.]+\\.(?:txt|xml|ico)"):data>')(main_view_file)
  633. app.route('/shutdown', methods = ['POST', 'GET'])(main_sys_shutdown)
  634. app.route('/restart', methods = ['POST', 'GET'])(main_sys_restart)
  635. app.route('/update', methods = ['POST', 'GET'])(main_sys_update)
  636. app.errorhandler(404)(main_func_error_404)
  637. if __name__ == "__main__":
  638. config = Config()
  639. config.bind = [f"{server_set['host']}:{server_set['port']}"]
  640. # hypercorn 서버 실행
  641. asyncio.run(serve(app, config))