app.py 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. # Init
  2. import os
  3. import re
  4. for i_data in os.listdir("route"):
  5. f_src = re.search(r"(.+)\.py$", i_data)
  6. if f_src:
  7. exec("from route." + f_src.group(1) + " import *")
  8. # Init-Version
  9. version_list = json.loads(open('version.json', encoding = 'utf8').read())
  10. # Init-DB
  11. if os.path.exists(os.path.join('data', 'set.json')):
  12. db_set_list = ['db', 'db_type']
  13. set_data = json.loads(open(
  14. os.path.join('data', 'set.json'),
  15. encoding = 'utf8'
  16. ).read())
  17. for i in db_set_list:
  18. if not i in set_data:
  19. print('Please delete set.json')
  20. print('----')
  21. raise
  22. print('DB name : ' + set_data['db'])
  23. print('DB type : ' + set_data['db_type'])
  24. elif os.getenv('NAMU_DB') or os.getenv('NAMU_DB_TYPE'):
  25. set_data = {}
  26. if os.getenv('NAMU_DB'):
  27. set_data['db'] = os.getenv('NAMU_DB')
  28. else:
  29. set_data['db'] = 'data'
  30. if os.getenv('NAMU_DB_TYPE'):
  31. set_data['db'] = os.getenv('NAMU_DB_TYPE')
  32. else:
  33. set_data['db'] = 'sqlite'
  34. print('DB name : ' + set_data['db'])
  35. print('DB type : ' + set_data['db_type'])
  36. else:
  37. set_data = {}
  38. normal_db_type = ['sqlite', 'mysql']
  39. print('DB type (' + normal_db_type[0] + ') [' + ', '.join(normal_db_type) + '] : ', end = '')
  40. data_get = str(input())
  41. if data_get == '' or not data_get in normal_db_type:
  42. set_data['db_type'] = 'sqlite'
  43. else:
  44. set_data['db_type'] = data_get
  45. all_src = []
  46. if set_data['db_type'] == 'sqlite':
  47. for i_data in os.listdir("."):
  48. f_src = re.search(r"(.+)\.db$", i_data)
  49. if f_src:
  50. all_src += [f_src.group(1)]
  51. print('DB name (data) [' + ', '.join(all_src) + '] : ', end = '')
  52. data_get = str(input())
  53. if data_get == '':
  54. set_data['db'] = 'data'
  55. else:
  56. set_data['db'] = data_get
  57. with open(os.path.join('data', 'set.json'), 'w', encoding = 'utf8') as f:
  58. f.write(json.dumps(set_data))
  59. data_db_set = {}
  60. data_db_set['name'] = set_data['db']
  61. data_db_set['type'] = set_data['db_type']
  62. if data_db_set['type'] == 'mysql':
  63. if os.path.exists(os.path.join('data', 'mysql.json')):
  64. db_set_list = ['user', 'password', 'host', 'port']
  65. set_data = json.loads(
  66. open(
  67. os.path.join('data', 'mysql.json'),
  68. encoding = 'utf8'
  69. ).read()
  70. )
  71. for i in db_set_list:
  72. if not i in set_data:
  73. os.remove(os.path.join('data', 'mysql.json'))
  74. break
  75. set_data_mysql = set_data
  76. if not os.path.exists(os.path.join('data', 'mysql.json')):
  77. set_data_mysql = {}
  78. print('DB user ID : ', end = '')
  79. set_data_mysql['user'] = str(input())
  80. print('DB password : ', end = '')
  81. set_data_mysql['password'] = str(input())
  82. print('DB host (localhost) : ', end = '')
  83. set_data_mysql['host'] = str(input())
  84. if set_data_mysql['host'] == '':
  85. set_data_mysql['host'] = 'localhost'
  86. print('DB port (3306) : ', end = '')
  87. set_data_mysql['port'] = str(input())
  88. if set_data_mysql['port'] == '':
  89. set_data_mysql['port'] = '3306'
  90. with open(
  91. os.path.join('data', 'mysql.json'),
  92. 'w',
  93. encoding = 'utf8'
  94. ) as f:
  95. f.write(json.dumps(set_data_mysql))
  96. data_db_set['mysql_user'] = set_data_mysql['user']
  97. data_db_set['mysql_pw'] = set_data_mysql['password']
  98. if 'host' in set_data_mysql:
  99. data_db_set['mysql_host'] = set_data_mysql['host']
  100. else:
  101. data_db_set['mysql_host'] = 'localhost'
  102. if 'port' in set_data_mysql:
  103. data_db_set['mysql_port'] = set_data_mysql['port']
  104. else:
  105. data_db_set['mysql_port'] = '3306'
  106. db_data_get(data_db_set['type'])
  107. with get_db_connect(data_db_set) as conn:
  108. curs = conn.cursor()
  109. setup_tool = ''
  110. try:
  111. curs.execute(db_change('select data from other where name = "ver"'))
  112. except:
  113. setup_tool = 'init'
  114. if setup_tool != 'init':
  115. ver_set_data = curs.fetchall()
  116. if ver_set_data:
  117. if int(version_list['beta']['c_ver']) > int(ver_set_data[0][0]):
  118. setup_tool = 'update'
  119. else:
  120. setup_tool = 'normal'
  121. else:
  122. setup_tool = 'init'
  123. if setup_tool != 'normal':
  124. # Init-Create_DB
  125. create_data = {}
  126. # 폐지 예정 (data_set으로 통합)
  127. create_data['data'] = ['title', 'data', 'type']
  128. create_data['history'] = ['id', 'title', 'data', 'date', 'ip', 'send', 'leng', 'hide', 'type']
  129. create_data['rc'] = ['id', 'title', 'date', 'type']
  130. create_data['acl'] = ['title', 'data', 'type']
  131. # 개편 예정 (data_link로 변경)
  132. create_data['back'] = ['title', 'link', 'type']
  133. # 폐지 예정 (topic_set으로 통합) [가장 시급]
  134. create_data['rd'] = ['title', 'sub', 'code', 'date', 'band', 'stop', 'agree', 'acl']
  135. create_data['topic'] = ['id', 'data', 'date', 'ip', 'block', 'top', 'code']
  136. # 폐지 예정 (user_set으로 통합)
  137. create_data['rb'] = ['block', 'end', 'today', 'blocker', 'why', 'band', 'login', 'ongoing']
  138. create_data['scan'] = ['user', 'title', 'type']
  139. # 개편 예정 (wiki_set과 wiki_filter과 wiki_vote으로 변경)
  140. create_data['other'] = ['name', 'data', 'coverage']
  141. create_data['html_filter'] = ['html', 'kind', 'plus', 'plus_t']
  142. create_data['vote'] = ['name', 'id', 'subject', 'data', 'user', 'type', 'acl']
  143. # 개편 예정 (auth_list와 auth_log로 변경)
  144. create_data['alist'] = ['name', 'acl']
  145. create_data['re_admin'] = ['who', 'what', 'time']
  146. # 개편 예정 (user_notice와 user_agent로 변경)
  147. create_data['alarm'] = ['name', 'data', 'date']
  148. create_data['ua_d'] = ['name', 'ip', 'ua', 'today', 'sub']
  149. create_data['user_set'] = ['name', 'id', 'data']
  150. for create_table in create_data:
  151. for create in ['test'] + create_data[create_table]:
  152. try:
  153. curs.execute(db_change('select ' + create + ' from ' + create_table + ' limit 1'))
  154. except:
  155. try:
  156. curs.execute(db_change('create table ' + create_table + '(test longtext default "")'))
  157. except:
  158. curs.execute(db_change("alter table " + create_table + " add column " + create + " longtext default ''"))
  159. if setup_tool == 'update':
  160. update(int(ver_set_data[0][0]), set_data)
  161. else:
  162. set_init()
  163. set_init_always(version_list['beta']['c_ver'])
  164. # Init-Route
  165. class EverythingConverter(werkzeug.routing.PathConverter):
  166. regex = '.*?'
  167. class RegexConverter(werkzeug.routing.BaseConverter):
  168. def __init__(self, url_map, *items):
  169. super(RegexConverter, self).__init__(url_map)
  170. self.regex = items[0]
  171. app = flask.Flask(
  172. __name__,
  173. template_folder = './'
  174. )
  175. app.config['JSON_AS_ASCII'] = False
  176. app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
  177. log = logging.getLogger('werkzeug')
  178. log.setLevel(logging.ERROR)
  179. app.jinja_env.filters['md5_replace'] = md5_replace
  180. app.jinja_env.filters['load_lang'] = load_lang
  181. app.jinja_env.filters['cut_100'] = cut_100
  182. app.url_map.converters['everything'] = EverythingConverter
  183. app.url_map.converters['regex'] = RegexConverter
  184. curs.execute(db_change('select data from other where name = "key"'))
  185. sql_data = curs.fetchall()
  186. app.secret_key = sql_data[0][0]
  187. print('----')
  188. # Init-DB_Data
  189. server_set = {}
  190. server_set_var = {
  191. 'host' : {
  192. 'display' : 'Host',
  193. 'require' : 'conv',
  194. 'default' : '0.0.0.0'
  195. }, 'port' : {
  196. 'display' : 'Port',
  197. 'require' : 'conv',
  198. 'default' : '3000'
  199. }, 'language' : {
  200. 'display' : 'Language',
  201. 'require' : 'select',
  202. 'default' : 'ko-KR',
  203. 'list' : ['ko-KR', 'en-US']
  204. }, 'markup' : {
  205. 'display' : 'Markup',
  206. 'require' : 'select',
  207. 'default' : 'namumark',
  208. 'list' : ['namumark', 'custom', 'raw']
  209. }, 'encode' : {
  210. 'display' : 'Encryption method',
  211. 'require' : 'select',
  212. 'default' : 'sha3',
  213. 'list' : ['sha3', 'sha256']
  214. }
  215. }
  216. server_set_env = {
  217. 'host' : os.getenv('NAMU_HOST'),
  218. 'port' : os.getenv('NAMU_PORT'),
  219. 'language' : os.getenv('NAMU_LANG'),
  220. 'markup' : os.getenv('NAMU_MARKUP'),
  221. 'encode' : os.getenv('NAMU_ENCRYPT')
  222. }
  223. for i in server_set_var:
  224. curs.execute(db_change('select data from other where name = ?'), [i])
  225. server_set_val = curs.fetchall()
  226. if server_set_val:
  227. server_set_val = server_set_val[0][0]
  228. elif server_set_env[i] != None:
  229. server_set_val = server_set_env[i]
  230. else:
  231. if 'list' in server_set_var[i]:
  232. print(server_set_var[i]['display'] + ' (' + server_set_var[i]['default'] + ') [' + ', '.join(server_set_var[i]['list']) + ']' + ' : ', end = '')
  233. else:
  234. print(server_set_var[i]['display'] + ' (' + server_set_var[i]['default'] + ') : ', end = '')
  235. server_set_val = input()
  236. if server_set_val == '':
  237. server_set_val = server_set_var[i]['default']
  238. elif server_set_var[i]['require'] == 'select':
  239. if not server_set_val in server_set_var[i]['list']:
  240. server_set_val = server_set_var[i]['default']
  241. curs.execute(db_change('insert into other (name, data) values (?, ?)'), [i, server_set_val])
  242. print(server_set_var[i]['display'] + ' : ' + server_set_val)
  243. server_set[i] = server_set_val
  244. print('----')
  245. # Init-DB_care
  246. if set_data['db_type'] == 'sqlite':
  247. def back_up(back_time, back_up_where):
  248. print('----')
  249. try:
  250. shutil.copyfile(
  251. set_data['db'] + '.db',
  252. back_up_where
  253. )
  254. print('Back up : OK')
  255. except:
  256. print('Back up : Error')
  257. threading.Timer(
  258. 60 * 60 * back_time,
  259. back_up,
  260. [back_time, back_up_where]
  261. ).start()
  262. curs.execute(db_change('select data from other where name = "back_up"'))
  263. back_time = curs.fetchall()
  264. back_time = int(number_check(back_time[0][0])) if back_time else 0
  265. if back_time != 0:
  266. curs.execute(db_change('select data from other where name = "backup_where"'))
  267. back_up_where = curs.fetchall()
  268. if back_up_where and back_up_where[0][0] != '':
  269. back_up_where = back_up_where[0][0]
  270. else:
  271. back_up_where = 'back_' + set_data['db'] + '.db'
  272. print('Back up state : ' + str(back_time) + ' hours')
  273. back_up(back_time, back_up_where)
  274. else:
  275. print('Back up state : Turn off')
  276. print('Now running... http://localhost:' + server_set['port'])
  277. conn.commit()
  278. # Init-custom
  279. if os.path.exists('custom.py'):
  280. from custom import custom_run
  281. with get_db_connect(data_db_set) as conn:
  282. custom_run(conn, app)
  283. # Func
  284. # Func-inter_wiki
  285. @app.route('/inter_wiki')
  286. def inter_wiki():
  287. with get_db_connect(data_db_set) as conn:
  288. return inter_wiki_2(conn, 'inter_wiki')
  289. @app.route('/inter_wiki/del/<name>')
  290. def inter_wiki_del(name = 'Test'):
  291. with get_db_connect(data_db_set) as conn:
  292. return inter_wiki_del_2(conn, 'del_inter_wiki', name)
  293. @app.route('/edit_top')
  294. def inter_wiki_edit_top():
  295. with get_db_connect(data_db_set) as conn:
  296. return inter_wiki_2(conn, 'edit_top')
  297. @app.route('/edit_top/del/<name>')
  298. def inter_wiki_edit_top_del(name = 'Test'):
  299. with get_db_connect(data_db_set) as conn:
  300. return inter_wiki_del_2(conn, 'del_edit_top', name)
  301. @app.route('/image_license')
  302. def inter_wiki_image_license():
  303. with get_db_connect(data_db_set) as conn:
  304. return inter_wiki_2(conn, 'image_license')
  305. @app.route('/image_license/del/<name>')
  306. def inter_wiki_image_license_del(name = 'Test'):
  307. with get_db_connect(data_db_set) as conn:
  308. return inter_wiki_del_2(conn, 'del_image_license', name)
  309. @app.route('/edit_filter')
  310. def inter_wiki_edit_filter():
  311. with get_db_connect(data_db_set) as conn:
  312. return inter_wiki_2(conn, 'edit_filter')
  313. @app.route('/edit_filter/del/<name>')
  314. def inter_wiki_edit_filter_del(name = 'Test'):
  315. with get_db_connect(data_db_set) as conn:
  316. return inter_wiki_del_2(conn, 'del_edit_filter', name)
  317. @app.route('/email_filter')
  318. def inter_wiki_email_filter():
  319. with get_db_connect(data_db_set) as conn:
  320. return inter_wiki_2(conn, 'email_filter')
  321. @app.route('/email_filter/del/<name>')
  322. def inter_wiki_email_filter_del(name = 'Test'):
  323. with get_db_connect(data_db_set) as conn:
  324. return inter_wiki_del_2(conn, 'del_email_filter', name)
  325. @app.route('/file_filter')
  326. def inter_wiki_file_filter():
  327. with get_db_connect(data_db_set) as conn:
  328. return inter_wiki_2(conn, 'file_filter')
  329. @app.route('/file_filter/del/<name>')
  330. def inter_wiki_file_filter_del(name = 'Test'):
  331. with get_db_connect(data_db_set) as conn:
  332. return inter_wiki_del_2(conn, 'del_file_filter', name)
  333. @app.route('/name_filter')
  334. def inter_wiki_name_filter():
  335. with get_db_connect(data_db_set) as conn:
  336. return inter_wiki_2(conn, 'name_filter')
  337. @app.route('/name_filter/del/<name>')
  338. def inter_wiki_name_filter_del(name = 'Test'):
  339. with get_db_connect(data_db_set) as conn:
  340. return inter_wiki_del_2(conn, 'del_name_filter', name)
  341. @app.route('/extension_filter')
  342. def inter_wiki_extension_filter():
  343. with get_db_connect(data_db_set) as conn:
  344. return inter_wiki_2(conn, 'extension_filter')
  345. @app.route('/extension_filter/del/<name>')
  346. def inter_wiki_extension_filter_del(name = 'Test'):
  347. with get_db_connect(data_db_set) as conn:
  348. return inter_wiki_del_2(conn, 'del_extension_filter', name)
  349. @app.route('/<regex("(?:inter_wiki|edit_top|image_license|(?:edit|email|file|name|extension)_filter)"):tools>/add', methods = ['POST', 'GET'])
  350. @app.route('/<regex("(?:inter_wiki|edit_top|image_license|(?:edit|email|file|name|extension)_filter)"):tools>/add/<name>', methods = ['POST', 'GET'])
  351. def inter_wiki_plus(tools = None, name = None):
  352. with get_db_connect(data_db_set) as conn:
  353. return inter_wiki_plus_2(conn, 'plus_' + tools, name)
  354. # Func-list
  355. # /list/topic/open
  356. @app.route('/not_close_topic')
  357. def list_not_close_topic():
  358. with get_db_connect(data_db_set) as conn:
  359. return list_not_close_topic_2(conn)
  360. # /list/document/old
  361. @app.route('/old_page')
  362. def list_old_page():
  363. with get_db_connect(data_db_set) as conn:
  364. return list_old_page_2(conn)
  365. # /list/document/acl
  366. @app.route('/acl_list')
  367. def list_acl():
  368. with get_db_connect(data_db_set) as conn:
  369. return list_acl_2(conn)
  370. # /list/document/acl/add
  371. @app.route('/acl/<everything:name>', methods = ['POST', 'GET'])
  372. def give_acl(name = None):
  373. with get_db_connect(data_db_set) as conn:
  374. return give_acl_2(conn, name)
  375. # /list/document/need
  376. @app.route('/please')
  377. def list_please():
  378. with get_db_connect(data_db_set) as conn:
  379. return list_please_2(conn)
  380. # /list/document/all
  381. @app.route('/title_index')
  382. def list_title_index():
  383. with get_db_connect(data_db_set) as conn:
  384. return list_title_index_2(conn)
  385. # /list/document/long
  386. @app.route('/long_page')
  387. def list_long_page():
  388. with get_db_connect(data_db_set) as conn:
  389. return list_long_page_2(conn, 'long_page')
  390. # /list/document/short
  391. @app.route('/short_page')
  392. def list_short_page():
  393. with get_db_connect(data_db_set) as conn:
  394. return list_long_page_2(conn, 'short_page')
  395. # /list/file
  396. @app.route('/image_file_list')
  397. def list_image_file():
  398. with get_db_connect(data_db_set) as conn:
  399. return list_image_file_2(conn)
  400. # /list/admin
  401. # /list/admin/list
  402. @app.route('/admin_list')
  403. def list_admin():
  404. with get_db_connect(data_db_set) as conn:
  405. return list_admin_2(conn)
  406. # /list/admin/auth_use
  407. @app.route('/admin_log', methods = ['POST', 'GET'])
  408. def list_admin_use():
  409. with get_db_connect(data_db_set) as conn:
  410. return list_admin_use_2(conn)
  411. # /list/user
  412. @app.route('/user_log')
  413. def list_user():
  414. with get_db_connect(data_db_set) as conn:
  415. return list_user_2(conn)
  416. # /list/user/check
  417. @app.route('/check/<name>')
  418. def give_user_check(name = None):
  419. with get_db_connect(data_db_set) as conn:
  420. return give_user_check_2(conn, name)
  421. # /list/user/check/delete
  422. @app.route('/check_delete', methods = ['POST', 'GET'])
  423. def give_user_check_delete():
  424. with get_db_connect(data_db_set) as conn:
  425. return give_user_check_delete_2(conn)
  426. # Func-auth
  427. # /auth/give
  428. # /auth/give/<name>
  429. @app.route('/admin/<name>', methods = ['POST', 'GET'])
  430. def give_admin(name = None):
  431. with get_db_connect(data_db_set) as conn:
  432. return give_admin_2(conn, name)
  433. # /auth/give
  434. # /auth/give/<name>
  435. @app.route('/ban', methods = ['POST', 'GET'])
  436. @app.route('/ban/<name>', methods = ['POST', 'GET'])
  437. def give_user_ban(name = None):
  438. with get_db_connect(data_db_set) as conn:
  439. return give_user_ban_2(conn, name)
  440. # /auth/list
  441. @app.route('/admin_group')
  442. def list_admin_group():
  443. with get_db_connect(data_db_set) as conn:
  444. return list_admin_group_2(conn)
  445. # /auth/list/add/<name>
  446. @app.route('/admin_plus/<name>', methods = ['POST', 'GET'])
  447. def give_admin_groups(name = None):
  448. with get_db_connect(data_db_set) as conn:
  449. return give_admin_groups_2(conn, name)
  450. # /auth/list/delete/<name>
  451. @app.route('/delete_admin_group/<name>', methods = ['POST', 'GET'])
  452. def give_delete_admin_group(name = None):
  453. with get_db_connect(data_db_set) as conn:
  454. return give_delete_admin_group_2(conn, name)
  455. # /auth/history
  456. # ongoing 반영 필요
  457. @app.route('/block_log')
  458. @app.route('/block_log/<regex("user"):tool>/<name>')
  459. @app.route('/block_log/<regex("admin"):tool>/<name>')
  460. def recent_block(name = 'Test', tool = 'all'):
  461. with get_db_connect(data_db_set) as conn:
  462. return recent_block_2(conn, name, tool)
  463. # Func-history
  464. @app.route('/recent_change')
  465. @app.route('/recent_changes')
  466. def recent_change(name = None):
  467. with get_db_connect(data_db_set) as conn:
  468. return recent_change_2(conn, name, '')
  469. @app.route('/record/<name>')
  470. def recent_record(name = None):
  471. with get_db_connect(data_db_set) as conn:
  472. return recent_change_2(conn, name, 'record')
  473. @app.route('/history/<everything:name>', methods = ['POST', 'GET'])
  474. def recent_history(name = None):
  475. with get_db_connect(data_db_set) as conn:
  476. return recent_change_2(conn, name, 'history')
  477. @app.route('/history/tool/<int(signed=True):rev>/<everything:name>')
  478. def recent_history_tool(name = 'Test', rev = 1):
  479. with get_db_connect(data_db_set) as conn:
  480. return recent_history_tool_2(conn, name, rev)
  481. @app.route('/history/delete/<int(signed=True):rev>/<everything:name>', methods = ['POST', 'GET'])
  482. def recent_history_delete(name = 'Test', rev = 1):
  483. with get_db_connect(data_db_set) as conn:
  484. return recent_history_delete_2(conn, name, rev)
  485. @app.route('/history/hidden/<int(signed=True):rev>/<everything:name>')
  486. def recent_history_hidden(name = 'Test', rev = 1):
  487. with get_db_connect(data_db_set) as conn:
  488. return recent_history_hidden_2(conn, name, rev)
  489. @app.route('/history/send/<int(signed=True):rev>/<everything:name>', methods = ['POST', 'GET'])
  490. def recent_history_send(name = 'Test', rev = 1):
  491. with get_db_connect(data_db_set) as conn:
  492. return recent_history_send_2(conn, name, rev)
  493. @app.route('/history/reset/<everything:name>', methods = ['POST', 'GET'])
  494. def recent_history_reset(name = 'Test'):
  495. with get_db_connect(data_db_set) as conn:
  496. return recent_history_reset_2(conn, name)
  497. @app.route('/history/add/<everything:name>', methods = ['POST', 'GET'])
  498. def recent_history_add(name = 'Test'):
  499. with get_db_connect(data_db_set) as conn:
  500. return recent_history_add_2(conn, name)
  501. @app.route('/record/reset/<name>', methods = ['POST', 'GET'])
  502. def recent_record_reset(name = 'Test'):
  503. with get_db_connect(data_db_set) as conn:
  504. return recent_record_reset_2(conn, name)
  505. @app.route('/record/topic/<name>')
  506. def recent_record_topic(name = 'Test'):
  507. with get_db_connect(data_db_set) as conn:
  508. return recent_record_topic_2(conn, name)
  509. # 거처를 고심중
  510. @app.route('/app_submit', methods = ['POST', 'GET'])
  511. def recent_app_submit():
  512. with get_db_connect(data_db_set) as conn:
  513. return recent_app_submit_2(conn)
  514. # Func-search
  515. @app.route('/search', methods=['POST'])
  516. def search():
  517. with get_db_connect(data_db_set) as conn:
  518. return search_2(conn)
  519. @app.route('/goto', methods=['POST'])
  520. @app.route('/goto/<everything:name>', methods=['POST'])
  521. def search_goto(name = 'test'):
  522. with get_db_connect(data_db_set) as conn:
  523. return search_goto_2(conn, name)
  524. @app.route('/search/<everything:name>')
  525. def search_deep(name = 'test'):
  526. with get_db_connect(data_db_set) as conn:
  527. return search_deep_2(conn, name)
  528. # Func-view
  529. @app.route('/xref/<everything:name>')
  530. def view_xref(name = 'Test'):
  531. with get_db_connect(data_db_set) as conn:
  532. return view_xref_2(conn, name)
  533. @app.route('/xref/this/<everything:name>')
  534. def view_xref_this(name = 'Test'):
  535. with get_db_connect(data_db_set) as conn:
  536. return view_xref_2(conn, name, xref_type = '2')
  537. @app.route('/raw/<everything:name>')
  538. @app.route('/thread/<int:topic_num>/raw/<int:num>')
  539. def view_raw(name = None, topic_num = None, num = None):
  540. with get_db_connect(data_db_set) as conn:
  541. return view_raw_2(conn, name, topic_num, num)
  542. @app.route('/diff/<int:num_a>/<int:num_b>/<everything:name>')
  543. def view_diff(name = 'Test', num_a = 1, num_b = 1):
  544. with get_db_connect(data_db_set) as conn:
  545. return view_diff_2(conn, name, num_a, num_b)
  546. @app.route('/down/<everything:name>')
  547. def view_down(name = None):
  548. with get_db_connect(data_db_set) as conn:
  549. return view_down_2(conn, name)
  550. @app.route('/w/<everything:name>/doc_rev/<int:doc_rev>')
  551. @app.route('/w/<everything:name>/doc_from/<everything:doc_from>')
  552. @app.route('/w/<everything:name>')
  553. def view_read(name = 'Test', doc_rev = 0, doc_from = ''):
  554. with get_db_connect(data_db_set) as conn:
  555. return view_read_2(conn, name, doc_rev, doc_from)
  556. # Func-edit
  557. @app.route('/revert/<everything:name>', methods = ['POST', 'GET'])
  558. def edit_revert(name = None):
  559. with get_db_connect(data_db_set) as conn:
  560. return edit_revert_2(conn, name)
  561. @app.route('/edit/<everything:name>', methods = ['POST', 'GET'])
  562. @app.route('/edit/<everything:name>/doc_section/<int:section>', methods = ['POST', 'GET'])
  563. def edit(name = 'Test', section = 0):
  564. with get_db_connect(data_db_set) as conn:
  565. return edit_2(conn, name, section)
  566. @app.route('/backlink_reset/<everything:name>')
  567. def edit_backlink_reset(name = 'Test'):
  568. with get_db_connect(data_db_set) as conn:
  569. return edit_backlink_reset_2(conn, name)
  570. @app.route('/delete/<everything:name>', methods = ['POST', 'GET'])
  571. def edit_delete(name = None):
  572. with get_db_connect(data_db_set) as conn:
  573. return edit_delete_2(conn, name)
  574. @app.route('/delete/doc_file/<everything:name>', methods = ['POST', 'GET'])
  575. def edit_delete_file(name = 'test.jpg'):
  576. with get_db_connect(data_db_set) as conn:
  577. return edit_delete_file_2(conn, name)
  578. @app.route('/delete/doc_mutiple', methods = ['POST', 'GET'])
  579. def edit_delete_mutiple():
  580. with get_db_connect(data_db_set) as conn:
  581. return edit_delete_mutiple_2(conn)
  582. @app.route('/move/<everything:name>', methods = ['POST', 'GET'])
  583. def edit_move(name = None):
  584. with get_db_connect(data_db_set) as conn:
  585. return edit_move_2(conn, name)
  586. # Func-topic
  587. @app.route('/recent_discuss')
  588. def recent_discuss():
  589. with get_db_connect(data_db_set) as conn:
  590. return recent_discuss_2(conn)
  591. @app.route('/thread/<int:topic_num>/b/<int:num>')
  592. def topic_block(topic_num = 1, num = 1):
  593. with get_db_connect(data_db_set) as conn:
  594. return topic_block_2(conn, topic_num, num)
  595. @app.route('/thread/<int:topic_num>/notice/<int:num>')
  596. def topic_top(topic_num = 1, num = 1):
  597. with get_db_connect(data_db_set) as conn:
  598. return topic_top_2(conn, topic_num, num)
  599. @app.route('/thread/<int:topic_num>/setting', methods = ['POST', 'GET'])
  600. def topic_stop(topic_num = 1):
  601. with get_db_connect(data_db_set) as conn:
  602. return topic_stop_2(conn, topic_num)
  603. @app.route('/thread/<int:topic_num>/acl', methods = ['POST', 'GET'])
  604. def topic_acl(topic_num = 1):
  605. with get_db_connect(data_db_set) as conn:
  606. return topic_acl_2(conn, topic_num)
  607. @app.route('/thread/<int:topic_num>/delete', methods = ['POST', 'GET'])
  608. def topic_delete(topic_num = 1):
  609. with get_db_connect(data_db_set) as conn:
  610. return topic_delete_2(conn, topic_num)
  611. @app.route('/thread/<int:topic_num>/tool')
  612. def topic_tool(topic_num = 1):
  613. with get_db_connect(data_db_set) as conn:
  614. return topic_tool_2(conn, topic_num)
  615. @app.route('/thread/<int:topic_num>/change', methods = ['POST', 'GET'])
  616. def topic_change(topic_num = 1):
  617. with get_db_connect(data_db_set) as conn:
  618. return topic_change_2(conn, topic_num)
  619. @app.route('/thread/<int:topic_num>/admin/<int:num>')
  620. def topic_admin(topic_num = 1, num = 1):
  621. with get_db_connect(data_db_set) as conn:
  622. return topic_admin_2(conn, topic_num, num)
  623. @app.route('/thread/<int:topic_num>', methods = ['POST', 'GET'])
  624. def topic(topic_num = 1):
  625. with get_db_connect(data_db_set) as conn:
  626. return topic_2(conn, topic_num)
  627. @app.route('/topic/<everything:name>', methods = ['POST', 'GET'])
  628. def topic_close_list(name = 'test'):
  629. with get_db_connect(data_db_set) as conn:
  630. return topic_close_list_2(conn, name)
  631. # Func-user
  632. @app.route('/change', methods = ['POST', 'GET'])
  633. def user_setting():
  634. with get_db_connect(data_db_set) as conn:
  635. return user_setting_2(conn, server_set_var)
  636. @app.route('/change/email', methods = ['POST', 'GET'])
  637. def user_setting_email():
  638. with get_db_connect(data_db_set) as conn:
  639. return user_setting_email_2(conn)
  640. @app.route('/change/email/check', methods = ['POST', 'GET'])
  641. def user_setting_email_check():
  642. with get_db_connect(data_db_set) as conn:
  643. return user_setting_email_check_2(conn)
  644. @app.route('/change/pw', methods = ['POST', 'GET'])
  645. def user_setting_pw_change():
  646. with get_db_connect(data_db_set) as conn:
  647. return user_setting_pw_change_2(conn)
  648. @app.route('/change/head', methods=['GET', 'POST'])
  649. def user_setting_head():
  650. with get_db_connect(data_db_set) as conn:
  651. return user_setting_head_2(conn)
  652. @app.route('/user')
  653. @app.route('/user/<name>')
  654. def user_info(name = ''):
  655. with get_db_connect(data_db_set) as conn:
  656. return user_info_2(conn, name)
  657. @app.route('/count')
  658. @app.route('/count/<name>')
  659. def user_count_edit(name = None):
  660. with get_db_connect(data_db_set) as conn:
  661. return user_count_edit_2(conn, name)
  662. @app.route('/alarm')
  663. def user_alarm():
  664. with get_db_connect(data_db_set) as conn:
  665. return user_alarm_2(conn)
  666. @app.route('/alarm/delete')
  667. def user_alarm_del():
  668. with get_db_connect(data_db_set) as conn:
  669. return user_alarm_del_2(conn)
  670. @app.route('/watch_list')
  671. def user_watch_list():
  672. with get_db_connect(data_db_set) as conn:
  673. return user_watch_list_2(conn, 'watch_list')
  674. @app.route('/watch_list/<everything:name>')
  675. def user_watch_list_name(name = 'Test'):
  676. with get_db_connect(data_db_set) as conn:
  677. return user_watch_list_name_2(conn, 'watch_list', name)
  678. @app.route('/star_doc')
  679. def user_star_doc():
  680. with get_db_connect(data_db_set) as conn:
  681. return user_watch_list_2(conn, 'star_doc')
  682. @app.route('/star_doc/<everything:name>')
  683. def user_star_doc_name(name = 'Test'):
  684. with get_db_connect(data_db_set) as conn:
  685. return user_watch_list_name_2(conn, 'star_doc', name)
  686. # Func-login
  687. # 개편 예정
  688. # login -> login/2fa -> login/2fa/email with login_id
  689. # register -> register/email -> regiter/email/check with reg_id
  690. # pass_find -> pass_find/email with find_id
  691. @app.route('/login', methods = ['POST', 'GET'])
  692. def login_login():
  693. with get_db_connect(data_db_set) as conn:
  694. return login_login_2(conn)
  695. @app.route('/login/2fa', methods = ['POST', 'GET'])
  696. def login_login_2fa():
  697. with get_db_connect(data_db_set) as conn:
  698. return login_login_2fa_2(conn)
  699. '''
  700. @app.route('/login/2fa/email', methods = ['POST', 'GET'])
  701. def login_2fa_email():
  702. with get_db_connect(data_db_set) as conn:
  703. return login_login_2fa_email_2(conn)
  704. '''
  705. @app.route('/register', methods = ['POST', 'GET'])
  706. def login_register():
  707. with get_db_connect(data_db_set) as conn:
  708. return login_register_2(conn)
  709. @app.route('/register/email', methods = ['POST', 'GET'])
  710. def login_register_email():
  711. with get_db_connect(data_db_set) as conn:
  712. return login_register_email_2(conn)
  713. @app.route('/register/email/check', methods = ['POST', 'GET'])
  714. def login_register_email_check():
  715. with get_db_connect(data_db_set) as conn:
  716. return login_register_email_check_2(conn)
  717. @app.route('/register/submit', methods = ['POST', 'GET'])
  718. def login_register_submit():
  719. with get_db_connect(data_db_set) as conn:
  720. return login_register_submit_2(conn)
  721. # 개편 필요
  722. @app.route('/pass_find', methods = ['POST', 'GET'])
  723. def login_pass_find():
  724. with get_db_connect(data_db_set) as conn:
  725. return login_pass_find_2(conn, 'pass_find')
  726. @app.route('/pass_find/email', methods = ['POST', 'GET'])
  727. def login_pass_find_email():
  728. with get_db_connect(data_db_set) as conn:
  729. return login_pass_find_email_2(conn, 'check_key')
  730. @app.route('/logout')
  731. def login_logout():
  732. with get_db_connect(data_db_set) as conn:
  733. return login_logout_2(conn)
  734. # Func-vote
  735. @app.route('/vote/<int:num>', methods = ['POST', 'GET'])
  736. def vote_select(num = 1):
  737. with get_db_connect(data_db_set) as conn:
  738. return vote_select_2(conn, str(num))
  739. @app.route('/vote/end/<int:num>')
  740. def vote_end(num = 1):
  741. with get_db_connect(data_db_set) as conn:
  742. return vote_end_2(conn, str(num))
  743. @app.route('/vote/close/<int:num>')
  744. def vote_close(num = 1):
  745. with get_db_connect(data_db_set) as conn:
  746. return vote_close_2(conn, str(num))
  747. @app.route('/vote')
  748. @app.route('/vote/list')
  749. @app.route('/vote/list/<int:num>')
  750. def vote_list(num = 1):
  751. with get_db_connect(data_db_set) as conn:
  752. return vote_list_2(conn, 'normal', num)
  753. @app.route('/vote/list/close')
  754. @app.route('/vote/list/close/<int:num>')
  755. def vote_list_close(num = 1):
  756. with get_db_connect(data_db_set) as conn:
  757. return vote_list_2(conn, 'close', num)
  758. @app.route('/vote/add', methods = ['POST', 'GET'])
  759. def vote_add():
  760. with get_db_connect(data_db_set) as conn:
  761. return vote_add_2(conn)
  762. # Func-api
  763. @app.route('/api/w/<everything:name>', methods = ['POST', 'GET'])
  764. def api_w(name = ''):
  765. with get_db_connect(data_db_set) as conn:
  766. return api_w_2(conn, name)
  767. @app.route('/api/raw/<everything:name>')
  768. def api_raw(name = ''):
  769. with get_db_connect(data_db_set) as conn:
  770. return api_raw_2(conn, name)
  771. @app.route('/api/version')
  772. def api_version():
  773. with get_db_connect(data_db_set) as conn:
  774. return api_version_2(conn, version_list)
  775. @app.route('/api/skin_info')
  776. @app.route('/api/skin_info/<name>')
  777. def api_skin_info(name = ''):
  778. with get_db_connect(data_db_set) as conn:
  779. return api_skin_info_2(conn, name)
  780. @app.route('/api/markup')
  781. def api_markup():
  782. with get_db_connect(data_db_set) as conn:
  783. return api_markup_2(conn)
  784. @app.route('/api/user_info/<name>')
  785. def api_user_info(name = ''):
  786. with get_db_connect(data_db_set) as conn:
  787. return api_user_info_2(conn, name)
  788. @app.route('/api/thread/<topic_num>')
  789. def api_topic_sub(name = '', topic_num = 1):
  790. with get_db_connect(data_db_set) as conn:
  791. return api_topic_sub_2(conn, topic_num)
  792. @app.route('/api/search/<name>')
  793. def api_search(name = ''):
  794. with get_db_connect(data_db_set) as conn:
  795. return api_search_2(conn, name)
  796. @app.route('/api/recent_changes')
  797. def api_recent_change():
  798. with get_db_connect(data_db_set) as conn:
  799. return api_recent_change_2(conn)
  800. @app.route('/api/recent_discuss')
  801. @app.route('/api/recent_discuss/<int:num>')
  802. def api_recent_discuss(num = 10):
  803. with get_db_connect(data_db_set) as conn:
  804. return api_recent_discuss_2(conn, num, 'normal')
  805. @app.route('/api/recent_discuss/stop')
  806. @app.route('/api/recent_discuss/<int:num>/stop')
  807. def api_recent_discuss_stop(num = 10):
  808. with get_db_connect(data_db_set) as conn:
  809. return api_recent_discuss_2(conn, num, 'stop')
  810. @app.route('/api/recent_discuss/all')
  811. @app.route('/api/recent_discuss/<int:num>/all')
  812. def api_recent_discuss_all(num = 10):
  813. with get_db_connect(data_db_set) as conn:
  814. return api_recent_discuss_2(conn, num, 'all')
  815. @app.route('/api/sha224/<everything:name>', methods = ['POST', 'GET'])
  816. def api_sha224(name = 'test'):
  817. with get_db_connect(data_db_set) as conn:
  818. return api_sha224_2(conn, name)
  819. @app.route('/api/title_index')
  820. def api_title_index():
  821. with get_db_connect(data_db_set) as conn:
  822. return api_title_index_2(conn)
  823. @app.route('/api/image/<everything:name>', methods = ['POST', 'GET'])
  824. def api_image_view(name = ''):
  825. with get_db_connect(data_db_set) as conn:
  826. return api_image_view_2(conn, name)
  827. @app.route('/api/sitemap.xml')
  828. def api_sitemap():
  829. with get_db_connect(data_db_set) as conn:
  830. return api_sitemap_2(conn)
  831. # Func-main
  832. # 여기도 전반적인 조정 시행 예정
  833. @app.route('/restart', methods = ['POST', 'GET'])
  834. def main_restart():
  835. with get_db_connect(data_db_set) as conn:
  836. return main_restart_2(conn)
  837. @app.route('/update', methods=['GET', 'POST'])
  838. def main_update():
  839. with get_db_connect(data_db_set) as conn:
  840. return main_update_2(conn, version_list['beta']['r_ver'])
  841. @app.route('/random')
  842. def main_title_random():
  843. with get_db_connect(data_db_set) as conn:
  844. return main_title_random_2(conn)
  845. @app.route('/upload', methods=['GET', 'POST'])
  846. def main_upload():
  847. with get_db_connect(data_db_set) as conn:
  848. return main_upload_2(conn)
  849. @app.route('/setting')
  850. @app.route('/setting/<int:num>', methods = ['POST', 'GET'])
  851. def setting(num = 0):
  852. with get_db_connect(data_db_set) as conn:
  853. return main_setting_2(conn, num, set_data['db_type'])
  854. @app.route('/other')
  855. def main_other():
  856. with get_db_connect(data_db_set) as conn:
  857. return main_other_2(conn)
  858. @app.route('/manager', methods = ['POST', 'GET'])
  859. @app.route('/manager/<int:num>', methods = ['POST', 'GET'])
  860. def main_manager(num = 1):
  861. with get_db_connect(data_db_set) as conn:
  862. return main_manager_2(conn, num)
  863. @app.route('/image/<everything:name>')
  864. def main_image_view(name = None):
  865. with get_db_connect(data_db_set) as conn:
  866. return main_image_view_2(conn, name)
  867. @app.route('/skin_set')
  868. @app.route('/main_skin_set')
  869. def main_skin_set():
  870. with get_db_connect(data_db_set) as conn:
  871. return main_skin_set_2(conn)
  872. @app.route('/views/<everything:name>')
  873. def main_views(name = None):
  874. with get_db_connect(data_db_set) as conn:
  875. return main_views_2(conn, name)
  876. @app.route('/test_func')
  877. def main_test_func():
  878. with get_db_connect(data_db_set) as conn:
  879. return main_test_func_2(conn)
  880. @app.route('/shutdown', methods = ['POST', 'GET'])
  881. def main_shutdown():
  882. with get_db_connect(data_db_set) as conn:
  883. return main_shutdown_2(conn)
  884. @app.route('/easter_egg.xml')
  885. def main_easter_egg():
  886. with get_db_connect(data_db_set) as conn:
  887. return main_easter_egg_2(conn)
  888. @app.route('/<regex("[^.]+\.(?:txt|xml)"):data>')
  889. def main_file(data = ''):
  890. with get_db_connect(data_db_set) as conn:
  891. return main_file_2(conn, data)
  892. @app.errorhandler(404)
  893. def main_error_404(e):
  894. with get_db_connect(data_db_set) as conn:
  895. return main_error_404_2(conn)
  896. if __name__ == "__main__":
  897. waitress.serve(
  898. app,
  899. host = server_set['host'],
  900. port = int(server_set['port']),
  901. )