app.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  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. db_data_get(set_data['db_type'])
  60. if set_data['db_type'] == 'mysql':
  61. if not os.path.exists(os.path.join('data', 'mysql.json')):
  62. db_set_list = ['user', 'password', 'host', 'port']
  63. set_data = json.loads(open(os.path.join('data', 'mysql.json'), encoding = 'utf8').read())
  64. for i in db_set_list:
  65. if not i in set_data:
  66. print('Please delete mysql.json')
  67. print('----')
  68. raise
  69. print('DB user ID : ', end = '')
  70. set_data_mysql['user'] = str(input())
  71. print('DB password : ', end = '')
  72. set_data_mysql['password'] = str(input())
  73. print('DB host (localhost) : ', end = '')
  74. set_data_mysql['host'] = str(input())
  75. if set_data_mysql['host'] == '':
  76. set_data_mysql['host'] = 'localhost'
  77. print('DB port (3306) : ', end = '')
  78. set_data_mysql['port'] = str(input())
  79. if set_data_mysql['port'] == '':
  80. set_data_mysql['port'] = '3306'
  81. with open(os.path.join('data', 'mysql.json'), 'w', encoding = 'utf8') as f:
  82. f.write(json.dumps(set_data_mysql))
  83. conn = pymysql.connect(
  84. host = set_data_mysql['host'] if 'host' in set_data_mysql else 'localhost',
  85. user = set_data_mysql['user'],
  86. password = set_data_mysql['password'],
  87. charset = 'utf8mb4',
  88. port = int(set_data_mysql['port']) if 'port' in set_data_mysql else 3306
  89. )
  90. curs = conn.cursor()
  91. try:
  92. curs.execute(db_change('create database ' + set_data['db'] + ' default character set utf8mb4;'))
  93. except:
  94. pass
  95. conn.select_db(set_data['db'])
  96. else:
  97. conn = sqlite3.connect(set_data['db'] + '.db')
  98. curs = conn.cursor()
  99. load_conn(conn)
  100. # Init-Create_DB
  101. create_data = {}
  102. # 폐지 예정 (data_set으로 통합)
  103. create_data['data'] = ['title', 'data', 'type']
  104. create_data['history'] = ['id', 'title', 'data', 'date', 'ip', 'send', 'leng', 'hide', 'type']
  105. create_data['rc'] = ['id', 'title', 'date', 'type']
  106. create_data['acl'] = ['title', 'data', 'type']
  107. # 개편 예정 (data_link로 변경)
  108. create_data['back'] = ['title', 'link', 'type']
  109. # 폐지 예정 (topic_set으로 통합) [가장 시급]
  110. create_data['rd'] = ['title', 'sub', 'code', 'date', 'band', 'stop', 'agree', 'acl']
  111. create_data['topic'] = ['id', 'data', 'date', 'ip', 'block', 'top', 'code']
  112. # 폐지 예정 (user_set으로 통합)
  113. create_data['rb'] = ['block', 'end', 'today', 'blocker', 'why', 'band', 'login', 'ongoing']
  114. create_data['scan'] = ['user', 'title', 'type']
  115. # 개편 예정 (wiki_set과 wiki_filter과 wiki_vote으로 변경)
  116. create_data['other'] = ['name', 'data', 'coverage']
  117. create_data['html_filter'] = ['html', 'kind', 'plus', 'plus_t']
  118. create_data['vote'] = ['name', 'id', 'subject', 'data', 'user', 'type', 'acl']
  119. # 개편 예정 (auth_list와 auth_log로 변경)
  120. create_data['alist'] = ['name', 'acl']
  121. create_data['re_admin'] = ['who', 'what', 'time']
  122. # 개편 예정 (user_notice와 user_agent로 변경)
  123. create_data['alarm'] = ['name', 'data', 'date']
  124. create_data['ua_d'] = ['name', 'ip', 'ua', 'today', 'sub']
  125. create_data['user_set'] = ['name', 'id', 'data']
  126. for create_table in create_data:
  127. try:
  128. curs.execute(db_change('select test from ' + create_table + ' limit 1'))
  129. except:
  130. try:
  131. curs.execute(db_change('create table ' + create_table + '(test longtext)'))
  132. except:
  133. curs.execute(db_change("alter table " + create_table + " add test longtext"))
  134. for create in create_data[create_table]:
  135. try:
  136. curs.execute(db_change(
  137. 'select ' + create + ' from ' + create_table + ' limit 1'
  138. ))
  139. except:
  140. try:
  141. curs.execute(db_change(
  142. "alter table " + create_table + " add " + create + " longtext default ''"
  143. ))
  144. except:
  145. curs.execute(db_change(
  146. "alter table " + create_table + " add " + create + " longtext"
  147. ))
  148. curs.execute(db_change('select data from other where name = "ver"'))
  149. ver_set_data = curs.fetchall()
  150. if ver_set_data:
  151. if int(version_list['beta']['c_ver']) > int(ver_set_data[0][0]):
  152. setup_tool = 'update'
  153. else:
  154. setup_tool = 'normal'
  155. else:
  156. setup_tool = 'init'
  157. if setup_tool != 'normal':
  158. if setup_tool == 'update':
  159. update(int(ver_set_data[0][0]), set_data)
  160. else:
  161. set_init()
  162. set_init_always(version_list['beta']['c_ver'])
  163. # Init-Route
  164. class EverythingConverter(werkzeug.routing.PathConverter):
  165. regex = '.*?'
  166. class RegexConverter(werkzeug.routing.BaseConverter):
  167. def __init__(self, url_map, *items):
  168. super(RegexConverter, self).__init__(url_map)
  169. self.regex = items[0]
  170. app = flask.Flask(__name__, template_folder = './')
  171. app.config['JSON_AS_ASCII'] = False
  172. app.logger.setLevel(logging.ERROR)
  173. app.jinja_env.filters['md5_replace'] = md5_replace
  174. app.jinja_env.filters['load_lang'] = load_lang
  175. app.jinja_env.filters['cut_100'] = cut_100
  176. app.url_map.converters['everything'] = EverythingConverter
  177. app.url_map.converters['regex'] = RegexConverter
  178. curs.execute(db_change('select data from other where name = "key"'))
  179. sql_data = curs.fetchall()
  180. app.secret_key = sql_data[0][0]
  181. print('----')
  182. # Init-DB_Data
  183. dislay_set_key = ['Host', 'Port', 'Language', 'Markup', 'Encryption method']
  184. server_set_key = ['host', 'port', 'language', 'markup', 'encode']
  185. server_set = {}
  186. server_init = server_init()
  187. for i in range(len(server_set_key)):
  188. curs.execute(db_change('select data from other where name = ?'), [server_set_key[i]])
  189. server_set_val = curs.fetchall()
  190. if not server_set_val:
  191. server_set_val = server_init.init(server_set_key[i])
  192. curs.execute(db_change('insert into other (name, data) values (?, ?)'), [server_set_key[i], server_set_val])
  193. else:
  194. server_set_val = server_set_val[0][0]
  195. print(dislay_set_key[i] + ' : ' + server_set_val)
  196. server_set[server_set_key[i]] = server_set_val
  197. print('----')
  198. # Init-DB_care
  199. if set_data['db_type'] == 'sqlite':
  200. def back_up(back_time, back_up_where):
  201. print('----')
  202. try:
  203. shutil.copyfile(
  204. set_data['db'] + '.db',
  205. back_up_where
  206. )
  207. print('Back up : OK')
  208. except:
  209. print('Back up : Error')
  210. threading.Timer(
  211. 60 * 60 * back_time,
  212. back_up,
  213. [back_time, back_up_where]
  214. ).start()
  215. curs.execute(db_change('select data from other where name = "back_up"'))
  216. back_time = curs.fetchall()
  217. back_time = int(number_check(back_time[0][0])) if back_time else 0
  218. if back_time != 0:
  219. curs.execute(db_change('select data from other where name = "backup_where"'))
  220. back_up_where = curs.fetchall()
  221. if back_up_where and back_up_where[0][0] != '':
  222. back_up_where = back_up_where[0][0]
  223. else:
  224. back_up_where = 'back_' + set_data['db'] + '.db'
  225. print('Back up state : ' + str(back_time) + ' hours')
  226. back_up(back_time, back_up_where)
  227. else:
  228. print('Back up state : Turn off')
  229. else:
  230. def mysql_dont_off(port):
  231. try:
  232. urllib.request.urlopen('http://localhost:' + port + '/')
  233. except:
  234. pass
  235. threading.Timer(
  236. 60 * 60 * 3,
  237. mysql_dont_off,
  238. [port]
  239. ).start()
  240. mysql_dont_off(server_set['port'])
  241. print('Now running... http://localhost:' + server_set['port'])
  242. if os.path.exists('custom.py'):
  243. from custom import custom_run
  244. custom_run(conn, app)
  245. # alarm과 watch_list의 user 편입
  246. # Func
  247. # Func-inter_wiki
  248. # 개편 필요
  249. @app.route('/<regex("inter_wiki"):tools>')
  250. @app.route('/<regex("edit_top"):tools>')
  251. @app.route('/<regex("image_license"):tools>')
  252. @app.route('/<regex("(?:edit|email|file|name|extension)_filter"):tools>')
  253. def inter_wiki(tools = None):
  254. return inter_wiki_2(conn, tools)
  255. @app.route('/<regex("del_(?:inter_wiki|edit_top|image_license|(?:edit|email|file|name|extension)_filter)"):tools>/<name>')
  256. def inter_wiki_del(tools = None, name = None):
  257. return inter_wiki_del_2(conn, tools, name)
  258. @app.route('/<regex("plus_(?:inter_wiki|edit_top|image_license|(?:edit|email|file|name|extension)_filter)"):tools>', methods = ['POST', 'GET'])
  259. @app.route('/<regex("plus_(?:inter_wiki|edit_top|image_license|(?:edit|email|file|name|extension)_filter)"):tools>/<name>', methods = ['POST', 'GET'])
  260. def inter_wiki_plus(tools = None, name = None):
  261. return inter_wiki_plus_2(conn, tools, name)
  262. # Func-list
  263. @app.route('/not_close_topic')
  264. def list_not_close_topic():
  265. return list_not_close_topic_2(conn)
  266. @app.route('/old_page')
  267. def list_old_page():
  268. return list_old_page_2(conn)
  269. @app.route('/acl_list')
  270. def list_acl():
  271. return list_acl_2(conn)
  272. @app.route('/image_file_list')
  273. def list_image_file():
  274. return list_image_file_2(conn)
  275. @app.route('/admin_list')
  276. def list_admin():
  277. return list_admin_2(conn)
  278. @app.route('/user_log')
  279. def list_user():
  280. return list_user_2(conn)
  281. @app.route('/admin_log', methods = ['POST', 'GET'])
  282. def list_admin_use():
  283. return list_admin_use_2(conn)
  284. @app.route('/admin_group')
  285. def list_admin_group():
  286. return list_admin_group_2(conn)
  287. @app.route('/please')
  288. def list_please():
  289. return list_please_2(conn)
  290. @app.route('/title_index')
  291. def list_title_index():
  292. return list_title_index_2(conn)
  293. @app.route('/topic_record/<name>')
  294. def list_user_topic(name = 'test'):
  295. return list_user_topic_2(conn, name)
  296. @app.route('/<regex("long_page"):tool>')
  297. @app.route('/<regex("short_page"):tool>')
  298. def list_long_page(tool = 'long_page'):
  299. return list_long_page_2(conn, tool)
  300. # Func-give
  301. @app.route('/admin_plus/<name>', methods = ['POST', 'GET'])
  302. def give_admin_groups(name = None):
  303. return give_admin_groups_2(conn, name)
  304. # 다듬어야할 듯
  305. @app.route('/delete_admin_group/<name>', methods = ['POST', 'GET'])
  306. def give_delete_admin_group(name = None):
  307. return give_delete_admin_group_2(conn, name)
  308. @app.route('/check/<name>')
  309. def give_user_check(name = None):
  310. return give_user_check_2(conn, name)
  311. @app.route('/check_delete', methods = ['POST', 'GET'])
  312. def give_user_check_delete():
  313. return give_user_check_delete_2(conn)
  314. @app.route('/ban', methods = ['POST', 'GET'])
  315. @app.route('/ban/<name>', methods = ['POST', 'GET'])
  316. def give_user_ban(name = None):
  317. return give_user_ban_2(conn, name)
  318. @app.route('/acl/<everything:name>', methods = ['POST', 'GET'])
  319. def give_acl(name = None):
  320. return give_acl_2(conn, name)
  321. @app.route('/admin/<name>', methods = ['POST', 'GET'])
  322. def give_admin(name = None):
  323. return give_admin_2(conn, name)
  324. # Func-view
  325. @app.route('/xref/<everything:name>')
  326. def view_xref(name = None):
  327. return view_xref_2(conn, name)
  328. @app.route('/raw/<everything:name>')
  329. @app.route('/thread/<int:topic_num>/raw/<int:num>')
  330. def view_raw(name = None, topic_num = None, num = None):
  331. return view_raw_2(conn, name, topic_num, num)
  332. @app.route('/diff/<everything:name>')
  333. def view_diff_data(name = None):
  334. return view_diff_data_2(conn, name)
  335. @app.route('/down/<everything:name>')
  336. def view_down(name = None):
  337. return view_down_2(conn, name)
  338. @app.route('/w/<everything:name>')
  339. def view_read(name = None):
  340. return view_read_2(conn, name)
  341. # Func-recent
  342. @app.route('/recent_discuss')
  343. def recent_discuss():
  344. return recent_discuss_2(conn)
  345. # ongoing 반영 필요
  346. @app.route('/block_log')
  347. @app.route('/block_log/<regex("user"):tool>/<name>')
  348. @app.route('/block_log/<regex("admin"):tool>/<name>')
  349. def recent_block(name = 'Test', tool = 'all'):
  350. return recent_block_2(conn, name, tool)
  351. # 이 쪽 분리 필요
  352. @app.route('/recent_change')
  353. @app.route('/recent_changes')
  354. def recent_change(name = None):
  355. return recent_change_2(conn, name, '')
  356. @app.route('/record/<name>')
  357. def recent_record(name = None):
  358. return recent_change_2(conn, name, 'record')
  359. @app.route('/history/<everything:name>', methods = ['POST', 'GET'])
  360. def recent_history(name = None):
  361. return recent_change_2(conn, name, 'history')
  362. @app.route('/history/tool/<int(signed=True):rev>/<everything:name>')
  363. def recent_history_tool(name = 'Test', rev = 1):
  364. return recent_history_tool_2(conn, name, rev)
  365. @app.route('/history/delete/<int(signed=True):rev>/<everything:name>', methods = ['POST', 'GET'])
  366. def recent_history_delete(name = 'Test', rev = 1):
  367. return recent_history_delete_2(conn, name, rev)
  368. @app.route('/history/hidden/<int(signed=True):rev>/<everything:name>')
  369. def recent_history_hidden(name = 'Test', rev = 1):
  370. return recent_history_hidden_2(conn, name, rev)
  371. @app.route('/history/send/<int(signed=True):rev>/<everything:name>', methods = ['POST', 'GET'])
  372. def recent_history_send(name = 'Test', rev = 1):
  373. return recent_history_send_2(conn, name, rev)
  374. @app.route('/history/reset/<everything:name>', methods = ['POST', 'GET'])
  375. def recent_history_reset(name = 'Test'):
  376. return recent_history_reset_2(conn, name)
  377. @app.route('/history/add/<everything:name>', methods = ['POST', 'GET'])
  378. def recent_history_add(name = 'Test'):
  379. return recent_history_add_2(conn, name)
  380. @app.route('/record/reset/<name>', methods = ['POST', 'GET'])
  381. def recent_record_reset(name = 'Test'):
  382. return recent_record_reset_2(conn, name)
  383. # Func-search
  384. @app.route('/search', methods=['POST'])
  385. def search():
  386. return search_2(conn)
  387. @app.route('/goto', methods=['POST'])
  388. @app.route('/goto/<everything:name>', methods=['POST'])
  389. def search_goto(name = 'test'):
  390. return search_goto_2(conn, name)
  391. @app.route('/search/<everything:name>')
  392. def search_deep(name = 'test'):
  393. return search_deep_2(conn, name)
  394. # Func-edit
  395. @app.route('/revert/<everything:name>', methods = ['POST', 'GET'])
  396. def edit_revert(name = None):
  397. return edit_revert_2(conn, name)
  398. @app.route('/edit/<everything:name>', methods = ['POST', 'GET'])
  399. def edit(name = 'Test'):
  400. return edit_2(conn, name)
  401. @app.route('/backlink_reset/<everything:name>')
  402. def edit_backlink_reset(name = 'Test'):
  403. return edit_backlink_reset_2(conn, name)
  404. @app.route('/delete/<everything:name>', methods = ['POST', 'GET'])
  405. def edit_delete(name = None):
  406. return edit_delete_2(conn, name)
  407. # 개편 예정
  408. @app.route('/many_delete', methods = ['POST', 'GET'])
  409. def edit_delete_many():
  410. return edit_delete_many_2(conn)
  411. @app.route('/move/<everything:name>', methods = ['POST', 'GET'])
  412. def edit_move(name = None):
  413. return edit_move_2(conn, name)
  414. # Func-topic
  415. @app.route('/thread/<int:topic_num>/b/<int:num>')
  416. def topic_block(topic_num = 1, num = 1):
  417. return topic_block_2(conn, topic_num, num)
  418. @app.route('/thread/<int:topic_num>/notice/<int:num>')
  419. def topic_top(topic_num = 1, num = 1):
  420. return topic_top_2(conn, topic_num, num)
  421. @app.route('/thread/<int:topic_num>/setting', methods = ['POST', 'GET'])
  422. def topic_stop(topic_num = 1):
  423. return topic_stop_2(conn, topic_num)
  424. @app.route('/thread/<int:topic_num>/acl', methods = ['POST', 'GET'])
  425. def topic_acl(topic_num = 1):
  426. return topic_acl_2(conn, topic_num)
  427. @app.route('/thread/<int:topic_num>/delete', methods = ['POST', 'GET'])
  428. def topic_delete(topic_num = 1):
  429. return topic_delete_2(conn, topic_num)
  430. @app.route('/thread/<int:topic_num>/tool')
  431. def topic_tool(topic_num = 1):
  432. return topic_tool_2(conn, topic_num)
  433. @app.route('/thread/<int:topic_num>/change', methods = ['POST', 'GET'])
  434. def topic_change(topic_num = 1):
  435. return topic_change_2(conn, topic_num)
  436. @app.route('/thread/<int:topic_num>/admin/<int:num>')
  437. def topic_admin(topic_num = 1, num = 1):
  438. return topic_admin_2(conn, topic_num, num)
  439. @app.route('/thread/<int:topic_num>', methods = ['POST', 'GET'])
  440. def topic(topic_num = 1):
  441. return topic_2(conn, topic_num)
  442. @app.route('/topic/<everything:name>', methods = ['POST', 'GET'])
  443. def topic_close_list(name = 'test'):
  444. return topic_close_list_2(conn, name)
  445. # Func-user
  446. @app.route('/tool/<name>')
  447. def user_tool(name = None):
  448. return user_tool_2(conn, name)
  449. @app.route('/change', methods = ['POST', 'GET'])
  450. def user_setting():
  451. return user_setting_2(conn, server_init)
  452. @app.route('/change/email', methods = ['POST', 'GET'])
  453. def user_setting_email():
  454. return user_setting_email_2(conn)
  455. @app.route('/change/email/check', methods = ['POST', 'GET'])
  456. def user_setting_email_check():
  457. return user_setting_email_check_2(conn)
  458. @app.route('/change/pw', methods = ['POST', 'GET'])
  459. def user_setting_pw_change():
  460. return user_setting_pw_change_2(conn)
  461. @app.route('/user')
  462. def user_info():
  463. return user_info_2(conn)
  464. @app.route('/custom_head', methods=['GET', 'POST'])
  465. def user_custom_head_view():
  466. return user_custom_head_view_2(conn)
  467. @app.route('/count')
  468. @app.route('/count/<name>')
  469. def user_count_edit(name = None):
  470. return user_count_edit_2(conn, name)
  471. @app.route('/alarm')
  472. def alarm():
  473. return alarm_2(conn)
  474. @app.route('/alarm/delete')
  475. def alarm_del():
  476. return alarm_del_2(conn)
  477. @app.route('/<regex("watch_list|star_doc"):tool>')
  478. def watch_list(tool = 'star_doc'):
  479. return watch_list_2(conn, tool)
  480. @app.route('/<regex("watch_list|star_doc"):tool>/<everything:name>')
  481. def watch_list_name(tool = 'star_doc', name = 'Test'):
  482. return watch_list_name_2(conn, tool, name)
  483. # Func-login
  484. # 개편 예정
  485. # login -> login/2fa -> login/2fa/email with login_id
  486. # register -> register/email -> regiter/email/check with reg_id
  487. # pass_find -> passfind/email with find_id
  488. @app.route('/login', methods = ['POST', 'GET'])
  489. def login_login():
  490. return login_login_2(conn)
  491. @app.route('/login/2fa', methods = ['POST', 'GET'])
  492. def login_2fa():
  493. return login_login_2fa_2(conn)
  494. '''
  495. @app.route('/login/2fa/email', methods = ['POST', 'GET'])
  496. def login_2fa_email():
  497. return login_login_2fa_email_2(conn)
  498. @app.route('/register', methods = ['POST', 'GET'])
  499. def login_register():
  500. return login_register_2(conn)
  501. @app.route('/register/email', methods = ['POST', 'GET'])
  502. def login_register_email():
  503. return login_register_email_2(conn)
  504. @app.route('/register/email/check', methods = ['POST', 'GET'])
  505. def login_register_email_check():
  506. return login_register_email_check_2(conn)
  507. '''
  508. @app.route('/<regex("need_email"):tool>', methods = ['POST', 'GET'])
  509. @app.route('/<regex("pass_find"):tool>', methods = ['POST', 'GET'])
  510. def login_need_email(tool = 'pass_find'):
  511. return login_need_email_2(conn, tool)
  512. @app.route('/<regex("check_key"):tool>', methods = ['POST', 'GET'])
  513. @app.route('/<regex("check_pass_key"):tool>', methods = ['POST', 'GET'])
  514. def login_check_key(tool = 'check_pass_key'):
  515. return login_check_key_2(conn, tool)
  516. @app.route('/logout')
  517. def login_logout():
  518. return login_logout_2(conn)
  519. # Func-application
  520. @app.route('/application_submitted')
  521. def application_submitted():
  522. return application_submitted_2(conn)
  523. @app.route('/applications', methods = ['POST', 'GET'])
  524. def applications():
  525. return applications_2(conn)
  526. # Func-vote
  527. @app.route('/vote/<num>', methods = ['POST', 'GET'])
  528. def vote_select(num = '1'):
  529. return vote_select_2(conn, num)
  530. @app.route('/end_vote/<num>')
  531. def vote_end(num = '1'):
  532. return vote_end_2(conn, num)
  533. @app.route('/close_vote/<num>')
  534. def vote_close(num = '1'):
  535. return vote_close_2(conn, num)
  536. @app.route('/vote')
  537. def vote():
  538. return vote_2(conn)
  539. @app.route('/add_vote', methods = ['POST', 'GET'])
  540. def vote_add():
  541. return vote_add_2(conn)
  542. # Func-api
  543. @app.route('/api/w/<everything:name>', methods = ['POST', 'GET'])
  544. def api_w(name = ''):
  545. return api_w_2(conn, name)
  546. @app.route('/api/raw/<everything:name>')
  547. def api_raw(name = ''):
  548. return api_raw_2(conn, name)
  549. @app.route('/api/version')
  550. def api_version():
  551. return api_version_2(conn, version_list['beta']['r_ver'], version_list['beta']['c_ver'])
  552. @app.route('/api/skin_info')
  553. @app.route('/api/skin_info/<name>')
  554. def api_skin_info(name = ''):
  555. return api_skin_info_2(conn, name)
  556. @app.route('/api/markup')
  557. def api_markup():
  558. return api_markup_2(conn)
  559. @app.route('/api/user_info/<name>')
  560. def api_user_info(name = ''):
  561. return api_user_info_2(conn, name)
  562. @app.route('/api/thread/<topic_num>')
  563. def api_topic_sub(name = '', topic_num = 1):
  564. return api_topic_sub_2(conn, topic_num)
  565. @app.route('/api/search/<name>')
  566. def api_search(name = ''):
  567. return api_search_2(conn, name)
  568. @app.route('/api/recent_changes')
  569. def api_recent_change():
  570. return api_recent_change_2(conn)
  571. @app.route('/api/sha224/<everything:name>', methods = ['POST', 'GET'])
  572. def api_sha224(name = 'test'):
  573. return api_sha224_2(conn, name)
  574. @app.route('/api/title_index')
  575. def api_title_index():
  576. return api_title_index_2(conn)
  577. @app.route('/api/image/<everything:name>', methods = ['POST', 'GET'])
  578. def api_image_view(name = ''):
  579. return api_image_view_2(conn, name)
  580. @app.route('/api/sitemap.xml')
  581. def api_sitemap():
  582. return api_sitemap_2(conn)
  583. # Func-main
  584. @app.route('/restart', methods = ['POST', 'GET'])
  585. def main_restart():
  586. return main_restart_2(conn)
  587. @app.route('/update', methods=['GET', 'POST'])
  588. def main_update():
  589. return main_update_2(conn, version_list['beta']['r_ver'])
  590. @app.route('/random')
  591. def main_title_random():
  592. return main_title_random_2(conn)
  593. @app.route('/upload', methods=['GET', 'POST'])
  594. def main_upload():
  595. return main_upload_2(conn)
  596. @app.route('/setting')
  597. @app.route('/setting/<int:num>', methods = ['POST', 'GET'])
  598. def setting(num = 0):
  599. return main_setting_2(conn, num, set_data['db_type'])
  600. @app.route('/other')
  601. def main_other():
  602. return main_other_2(conn)
  603. @app.route('/manager', methods = ['POST', 'GET'])
  604. @app.route('/manager/<int:num>', methods = ['POST', 'GET'])
  605. def main_manager(num = 1):
  606. return main_manager_2(conn, num, version_list['beta']['r_ver'])
  607. @app.route('/image/<everything:name>')
  608. def main_image_view(name = None):
  609. return main_image_view_2(conn, name)
  610. @app.route('/skin_set')
  611. @app.route('/main_skin_set')
  612. def main_skin_set():
  613. return main_skin_set_2(conn)
  614. @app.route('/views/<everything:name>')
  615. def main_views(name = None):
  616. return main_views_2(conn, name)
  617. @app.route('/test_func')
  618. def main_test_func():
  619. return main_test_func_2(conn)
  620. @app.route('/shutdown', methods = ['POST', 'GET'])
  621. def main_shutdown():
  622. return main_shutdown_2(conn)
  623. @app.route('/<regex("easter_egg\.html|\.(?:txt|xml)$"):data>')
  624. def main_file(data = ''):
  625. return main_file_2(conn, data)
  626. @app.errorhandler(404)
  627. def main_error_404(e):
  628. return main_error_404_2(conn)
  629. # End
  630. conn.commit()
  631. if __name__ == "__main__":
  632. WSGIServer((
  633. server_set['host'],
  634. int(server_set['port'])
  635. ), app, log = app.logger).serve_forever()