app.py 36 KB

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