func.py 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646
  1. # Init
  2. import os
  3. import sys
  4. import platform
  5. import json
  6. import smtplib
  7. import zipfile
  8. import shutil
  9. import logging
  10. import random
  11. import ipaddress
  12. import email.mime.text
  13. import email.utils
  14. import email.header
  15. import urllib.request
  16. # Init-Version
  17. version_list = json.loads(open('version.json', encoding = 'utf8').read())
  18. print('Version : ' + version_list['beta']['r_ver'])
  19. print('DB set version : ' + version_list['beta']['c_ver'])
  20. print('Skin set version : ' + version_list['beta']['s_ver'])
  21. print('----')
  22. # Init-PIP_Install
  23. data_up_date = 1
  24. if os.path.exists(os.path.join('data', 'version.json')):
  25. data_load_ver = open(os.path.join('data', 'version.json'), encoding = 'utf8').read()
  26. if data_load_ver == version_list['beta']['r_ver']:
  27. data_up_date = 0
  28. if data_up_date == 1:
  29. with open(os.path.join('data', 'version.json'), 'w', encoding = 'utf8') as f:
  30. f.write(version_list['beta']['r_ver'])
  31. if platform.system() in ('Linux', 'Windows'):
  32. if platform.python_implementation() == 'PyPy':
  33. os.system(
  34. 'pypy' + ('3' if platform.system() != 'Windows' else '') + ' ' + \
  35. '-m pip install --upgrade --user -r requirements.txt'
  36. )
  37. else:
  38. os.system(
  39. 'python' + ('3' if platform.system() != 'Windows' else '') + ' ' + \
  40. '-m pip install --upgrade --user -r requirements.txt'
  41. )
  42. print('----')
  43. try:
  44. os.execl(sys.executable, sys.executable, *sys.argv)
  45. except:
  46. pass
  47. try:
  48. os.execl(sys.executable, '"' + sys.executable + '"', *sys.argv)
  49. except:
  50. print('Error : restart failed')
  51. raise
  52. else:
  53. print('Error : automatic installation is not supported.')
  54. print('Help : try "python3 -m pip install -r requirements.txt"')
  55. else:
  56. print('PIP check pass')
  57. print('----')
  58. # Init-Load
  59. from .func_render import *
  60. from diff_match_patch import diff_match_patch
  61. import waitress
  62. import werkzeug.routing
  63. import werkzeug.debug
  64. import flask
  65. import requests
  66. import pymysql
  67. if sys.version_info < (3, 6):
  68. import sha3
  69. # Init-Global
  70. global_lang = {}
  71. global_wiki_set = {}
  72. global_db_set = ''
  73. conn = ''
  74. # Func
  75. # Func-main
  76. def load_conn(data):
  77. global conn
  78. conn = data
  79. def do_db_set(db_set):
  80. global global_db_set
  81. global_db_set = db_set
  82. # Func-init
  83. def get_init_set_list(need = 'all'):
  84. init_set_list = {
  85. 'host' : {
  86. 'display' : 'Host',
  87. 'require' : 'conv',
  88. 'default' : '0.0.0.0'
  89. }, 'port' : {
  90. 'display' : 'Port',
  91. 'require' : 'conv',
  92. 'default' : '3000'
  93. }, 'language' : {
  94. 'display' : 'Language',
  95. 'require' : 'select',
  96. 'default' : 'ko-KR',
  97. 'list' : ['ko-KR', 'en-US']
  98. }, 'markup' : {
  99. 'display' : 'Markup',
  100. 'require' : 'select',
  101. 'default' : 'namumark',
  102. 'list' : ['namumark', 'markdown', 'custom', 'raw']
  103. }, 'encode' : {
  104. 'display' : 'Encryption method',
  105. 'require' : 'select',
  106. 'default' : 'sha3',
  107. 'list' : ['sha3', 'sha3-salt', 'sha3-512', 'sha3-512-salt']
  108. }
  109. }
  110. if need == 'all':
  111. return init_set_list
  112. else:
  113. return init_set_list[need]
  114. class get_db_connect:
  115. # 임시 DB 커넥션 동작 구조
  116. # Init 파트
  117. # DB 커넥트(get_db_connect_old) -> func.py로 conn 넘겨줌
  118. # route 파트
  119. # DB 새로 커넥트 -> func.py에서 쓰던 conn은 conn_sub로 보관 ->
  120. # func.py로 conn 넘겨줌 -> 모든 라우터 과정이 끝나면 conn_sub를 다시 func.py에 conn으로 넘겨줌 ->
  121. # DB 커넥트 종료
  122. def __init__(self):
  123. global global_db_set
  124. global conn
  125. self.conn_sub = conn
  126. self.db_set = global_db_set
  127. def __enter__(self):
  128. if self.db_set['type'] == 'sqlite':
  129. self.conn = sqlite3.connect(
  130. self.db_set['name'] + '.db',
  131. check_same_thread = False,
  132. isolation_level = None
  133. )
  134. self.conn.execute('pragma journal_mode = wal')
  135. else:
  136. self.conn = pymysql.connect(
  137. host = self.db_set['mysql_host'],
  138. user = self.db_set['mysql_user'],
  139. password = self.db_set['mysql_pw'],
  140. charset = 'utf8mb4',
  141. port = int(self.db_set['mysql_port']),
  142. autocommit = True
  143. )
  144. curs = self.conn.cursor()
  145. self.conn.select_db(self.db_set['name'])
  146. load_conn(self.conn)
  147. return self.conn
  148. def __exit__(self, exc_type, exc_value, traceback):
  149. load_conn(self.conn_sub)
  150. self.conn.close()
  151. # class get_whoosh_connect:
  152. class class_check_json:
  153. def do_check_set_json():
  154. if os.getenv('NAMU_DB') or os.getenv('NAMU_DB_TYPE'):
  155. set_data = {}
  156. set_data['db'] = os.getenv('NAMU_DB') if os.getenv('NAMU_DB') else 'data'
  157. set_data['db_type'] = os.getenv('NAMU_DB_TYPE') if os.getenv('NAMU_DB_TYPE') else 'sqlite'
  158. else:
  159. if os.path.exists(os.path.join('data', 'set.json')):
  160. db_set_list = ['db', 'db_type']
  161. set_data = json.loads(open(
  162. os.path.join('data', 'set.json'),
  163. encoding = 'utf8'
  164. ).read())
  165. for i in db_set_list:
  166. if not i in set_data:
  167. os.remove(os.path.join('data', 'set.json'))
  168. break
  169. if not os.path.exists(os.path.join('data', 'set.json')):
  170. set_data = {}
  171. normal_db_type = ['sqlite', 'mysql']
  172. print('DB type (' + normal_db_type[0] + ') [' + ', '.join(normal_db_type) + '] : ', end = '')
  173. data_get = str(input())
  174. if data_get == '' or not data_get in normal_db_type:
  175. set_data['db_type'] = 'sqlite'
  176. else:
  177. set_data['db_type'] = data_get
  178. all_src = []
  179. if set_data['db_type'] == 'sqlite':
  180. for i_data in os.listdir("."):
  181. f_src = re.search(r"(.+)\.db$", i_data)
  182. if f_src:
  183. all_src += [f_src.group(1)]
  184. print('DB name (data) [' + ', '.join(all_src) + '] : ', end = '')
  185. data_get = str(input())
  186. if data_get == '':
  187. set_data['db'] = 'data'
  188. else:
  189. set_data['db'] = data_get
  190. with open(os.path.join('data', 'set.json'), 'w', encoding = 'utf8') as f:
  191. f.write(json.dumps(set_data))
  192. print('DB name : ' + set_data['db'])
  193. print('DB type : ' + set_data['db_type'])
  194. data_db_set = {}
  195. data_db_set['name'] = set_data['db']
  196. data_db_set['type'] = set_data['db_type']
  197. return data_db_set
  198. def do_check_mysql_json(data_db_set):
  199. if os.path.exists(os.path.join('data', 'mysql.json')):
  200. db_set_list = ['user', 'password', 'host', 'port']
  201. set_data = json.loads(
  202. open(
  203. os.path.join('data', 'mysql.json'),
  204. encoding = 'utf8'
  205. ).read()
  206. )
  207. for i in db_set_list:
  208. if not i in set_data:
  209. os.remove(os.path.join('data', 'mysql.json'))
  210. break
  211. set_data_mysql = set_data
  212. if not os.path.exists(os.path.join('data', 'mysql.json')):
  213. set_data_mysql = {}
  214. print('DB user ID : ', end = '')
  215. set_data_mysql['user'] = str(input())
  216. print('DB password : ', end = '')
  217. set_data_mysql['password'] = str(input())
  218. print('DB host (localhost) : ', end = '')
  219. set_data_mysql['host'] = str(input())
  220. if set_data_mysql['host'] == '':
  221. set_data_mysql['host'] = 'localhost'
  222. print('DB port (3306) : ', end = '')
  223. set_data_mysql['port'] = str(input())
  224. if set_data_mysql['port'] == '':
  225. set_data_mysql['port'] = '3306'
  226. with open(
  227. os.path.join('data', 'mysql.json'),
  228. 'w',
  229. encoding = 'utf8'
  230. ) as f:
  231. f.write(json.dumps(set_data_mysql))
  232. data_db_set['mysql_user'] = set_data_mysql['user']
  233. data_db_set['mysql_pw'] = set_data_mysql['password']
  234. if 'host' in set_data_mysql:
  235. data_db_set['mysql_host'] = set_data_mysql['host']
  236. else:
  237. data_db_set['mysql_host'] = 'localhost'
  238. if 'port' in set_data_mysql:
  239. data_db_set['mysql_port'] = set_data_mysql['port']
  240. else:
  241. data_db_set['mysql_port'] = '3306'
  242. return data_db_set
  243. def __init__(self):
  244. self.data_db_set = {}
  245. def __new__(self):
  246. self.data_db_set = self.do_check_set_json()
  247. if self.data_db_set['type'] == 'mysql':
  248. self.data_db_set = self.do_check_mysql_json(self.data_db_set)
  249. return self.data_db_set
  250. def get_db_table_list():
  251. # Init-Create_DB
  252. # DB 테이블 구조
  253. # --이거 개편한다더니 도대체 언제?--
  254. create_data = {}
  255. # 폐지 예정 (data_set으로 통합)
  256. create_data['data_set'] = ['doc_name', 'doc_rev', 'set_name', 'set_data']
  257. create_data['data'] = ['title', 'data', 'type']
  258. create_data['history'] = ['id', 'title', 'data', 'date', 'ip', 'send', 'leng', 'hide', 'type']
  259. create_data['rc'] = ['id', 'title', 'date', 'type']
  260. create_data['acl'] = ['title', 'data', 'type']
  261. # 개편 예정 (data_link로 변경)
  262. create_data['back'] = ['title', 'link', 'type']
  263. # 폐지 예정 (topic_set으로 통합) [가장 시급]
  264. create_data['topic_set'] = ['thread_code', 'set_name', 'set_id', 'set_data']
  265. create_data['rd'] = ['title', 'sub', 'code', 'date', 'band', 'stop', 'agree', 'acl']
  266. create_data['topic'] = ['id', 'data', 'date', 'ip', 'block', 'top', 'code']
  267. # 폐지 예정 (user_set으로 통합)
  268. create_data['rb'] = ['block', 'end', 'today', 'blocker', 'why', 'band', 'login', 'ongoing']
  269. create_data['scan'] = ['user', 'title', 'type']
  270. # 개편 예정 (wiki_set과 wiki_filter과 wiki_vote으로 변경)
  271. create_data['other'] = ['name', 'data', 'coverage']
  272. create_data['html_filter'] = ['html', 'kind', 'plus', 'plus_t']
  273. create_data['vote'] = ['name', 'id', 'subject', 'data', 'user', 'type', 'acl']
  274. # 개편 예정 (auth_list와 auth_log로 변경)
  275. create_data['alist'] = ['name', 'acl']
  276. create_data['re_admin'] = ['who', 'what', 'time']
  277. # 개편 예정 (user_notice와 user_agent로 변경)
  278. create_data['alarm'] = ['name', 'data', 'date']
  279. create_data['ua_d'] = ['name', 'ip', 'ua', 'today', 'sub']
  280. create_data['user_set'] = ['name', 'id', 'data']
  281. create_data['bbs_set'] = ['set_name', 'set_code', 'set_id', 'set_data']
  282. create_data['bbs_data'] = ['set_name', 'set_code', 'set_id', 'set_data']
  283. return create_data
  284. def update(ver_num, set_data):
  285. curs = conn.cursor()
  286. print('----')
  287. # 업데이트 하위 호환 유지 함수
  288. if ver_num < 3160027:
  289. print('Add init set')
  290. set_init()
  291. if ver_num < 3170002:
  292. curs.execute(db_change("select html from html_filter where kind = 'extension'"))
  293. if not curs.fetchall():
  294. for i in ['jpg', 'jpeg', 'png', 'gif', 'webp']:
  295. curs.execute(db_change(
  296. "insert into html_filter (html, kind) values (?, 'extension')"
  297. ), [i])
  298. if ver_num < 3170400:
  299. curs.execute(db_change("select title, sub, code from topic where id = '1'"))
  300. for i in curs.fetchall():
  301. curs.execute(db_change(
  302. "update topic set code = ? where title = ? and sub = ?"
  303. ), [
  304. i[2],
  305. i[0],
  306. i[1]
  307. ])
  308. curs.execute(db_change(
  309. "update rd set code = ? where title = ? and sub = ?"
  310. ), [
  311. i[2],
  312. i[0],
  313. i[1]
  314. ])
  315. if ver_num < 3171800:
  316. curs.execute(db_change("select data from other where name = 'recaptcha'"))
  317. change_rec = curs.fetchall()
  318. if change_rec and change_rec[0][0] != '':
  319. new_rec = re.search(r'data-sitekey="([^"]+)"', change_rec[0][0])
  320. if new_rec:
  321. curs.execute(db_change(
  322. "update other set data = ? where name = 'recaptcha'"
  323. ), [new_rec.group(1)])
  324. else:
  325. curs.execute(db_change("update other set data = '' where name = 'recaptcha'"))
  326. curs.execute(db_change("update other set data = '' where name = 'sec_re'"))
  327. if ver_num < 3172800 and \
  328. set_data['db_type'] == 'mysql':
  329. get_data_mysql = json.loads(open('data/mysql.json', encoding = 'utf8').read())
  330. with open('data/mysql.json', 'w') as f:
  331. f.write('{ "user" : "' + get_data_mysql['user'] + '", "password" : "' + get_data_mysql['password'] + '", "host" : "localhost" }')
  332. if ver_num < 3183603:
  333. curs.execute(db_change("select block from ban where band = 'O'"))
  334. for i in curs.fetchall():
  335. curs.execute(db_change(
  336. "update ban set block = ?, band = 'regex' where block = ? and band = 'O'"
  337. ), [
  338. '^' + i[0].replace('.', '\\.'),
  339. i[0]
  340. ])
  341. curs.execute(db_change("select block from rb where band = 'O'"))
  342. for i in curs.fetchall():
  343. curs.execute(db_change(
  344. "update rb set block = ?, band = 'regex' where block = ? and band = 'O'"
  345. ), [
  346. '^' + i[0].replace('.', '\\.'),
  347. i[0]
  348. ])
  349. if ver_num < 3190201:
  350. today_time = get_time()
  351. curs.execute(db_change("select block, end, why, band, login from ban"))
  352. for i in curs.fetchall():
  353. curs.execute(db_change(
  354. "insert into rb (block, end, today, why, band, login, ongoing) " + \
  355. "values (?, ?, ?, ?, ?, ?, ?)"
  356. ), [
  357. i[0],
  358. i[1],
  359. today_time,
  360. i[2],
  361. i[3],
  362. i[4],
  363. '1'
  364. ])
  365. if ver_num < 3191301:
  366. curs.execute(db_change('' + \
  367. 'select id, title, date from history ' + \
  368. 'where not title like "user:%" ' + \
  369. 'order by date desc ' + \
  370. 'limit 50' + \
  371. ''))
  372. data_list = curs.fetchall()
  373. for get_data in data_list:
  374. curs.execute(db_change(
  375. "insert into rc (id, title, date, type) values (?, ?, ?, 'normal')"
  376. ), [
  377. get_data[0],
  378. get_data[1],
  379. get_data[2]
  380. ])
  381. if ver_num < 3202400:
  382. curs.execute(db_change("select data from other where name = 'update'"))
  383. get_data = curs.fetchall()
  384. if get_data and get_data[0][0] == 'master':
  385. curs.execute(db_change("update other set data = 'beta' where name = 'update'"), [])
  386. if ver_num < 3202600:
  387. curs.execute(db_change("select name, regex, sub from filter"))
  388. for i in curs.fetchall():
  389. curs.execute(db_change(
  390. "insert into html_filter (html, kind, plus, plus_t) " + \
  391. "values (?, 'regex_filter', ?, ?)"
  392. ), [
  393. i[0],
  394. i[1],
  395. i[2]
  396. ])
  397. curs.execute(db_change("select title, link, icon from inter"))
  398. for i in curs.fetchall():
  399. curs.execute(db_change(
  400. "insert into html_filter (html, kind, plus, plus_t) " + \
  401. "values (?, 'inter_wiki', ?, ?)"), [
  402. i[0],
  403. i[1],
  404. i[2]
  405. ])
  406. if ver_num < 3203400:
  407. curs.execute(db_change("select user, css from custom"))
  408. for i in curs.fetchall():
  409. curs.execute(db_change(
  410. "insert into user_set (name, id, data) values ('custom_css', ?, ?)"
  411. ), [
  412. re.sub(r' \(head\)$', '', i[0]),
  413. i[1]
  414. ])
  415. if ver_num < 3205500:
  416. curs.execute(db_change("select title, decu, dis, view, why from acl"))
  417. for i in curs.fetchall():
  418. curs.execute(db_change(
  419. "insert into acl (title, data, type) values (?, ?, ?)"
  420. ), [i[0], i[1], 'decu'])
  421. curs.execute(db_change(
  422. "insert into acl (title, data, type) values (?, ?, ?)"
  423. ), [i[0], i[2], 'dis'])
  424. curs.execute(db_change(
  425. "insert into acl (title, data, type) values (?, ?, ?)"
  426. ), [i[0], i[3], 'view'])
  427. curs.execute(db_change(
  428. "insert into acl (title, data, type) values (?, ?, ?)"
  429. ), [i[0], i[4], 'why'])
  430. if ver_num < 3300101:
  431. # 캐시 초기화
  432. curs.execute(db_change('delete from cache_data'))
  433. if ver_num < 3300301:
  434. # regex_filter 오류 해결
  435. curs.execute(db_change(
  436. 'delete from html_filter where kind = "regex_filter" and html is null'
  437. ))
  438. if ver_num < 3302302:
  439. # user이랑 user_set 테이블의 통합
  440. curs.execute(db_change('select id, pw, acl, date, encode from user'))
  441. for i in curs.fetchall():
  442. curs.execute(db_change(
  443. "insert into user_set (name, id, data) values (?, ?, ?)"
  444. ), ['pw', i[0], i[1]])
  445. curs.execute(db_change(
  446. "insert into user_set (name, id, data) values (?, ?, ?)"
  447. ), ['acl', i[0], i[2]])
  448. curs.execute(db_change(
  449. "insert into user_set (name, id, data) values (?, ?, ?)"
  450. ), ['date', i[0], i[3]])
  451. curs.execute(db_change(
  452. "insert into user_set (name, id, data) values (?, ?, ?)"
  453. ), ['encode', i[0], i[4]])
  454. if ver_num < 3400101:
  455. # user_set이랑 user_application 테이블의 통합
  456. curs.execute(db_change('' + \
  457. 'select id, pw, date, encode, question, answer, ip, ua, email ' + \
  458. 'from user_application' + \
  459. ''))
  460. for i in curs.fetchall():
  461. sql_data = {}
  462. sql_data['id'] = i[0]
  463. sql_data['pw'] = i[1]
  464. sql_data['date'] = i[2]
  465. sql_data['encode'] = i[3]
  466. sql_data['question'] = i[4]
  467. sql_data['answer'] = i[5]
  468. sql_data['ip'] = i[6]
  469. sql_data['ua'] = i[7]
  470. sql_data['email'] = i[8]
  471. curs.execute(db_change(
  472. "insert into user_set (name, id, data) values (?, ?, ?)"
  473. ), ['application', i[0], json.dumps(sql_data)])
  474. if ver_num < 3500105:
  475. curs.execute(db_change(
  476. 'delete from acl where title like "file:%" and data = "admin" and type like "decu%"'
  477. ))
  478. if ver_num < 3500106:
  479. curs.execute(db_change("select data from other where name = 'domain'"))
  480. db_data = curs.fetchall()
  481. if db_data and db_data[0][0] != '':
  482. db_data = db_data[0][0]
  483. db_data = re.match(r'[^/]+\/\/([^/]+)', db_data)
  484. if db_data:
  485. db_data = db_data.group(1)
  486. curs.execute(db_change(
  487. "update other set data = ? where name = 'domain'"
  488. ), [
  489. db_data
  490. ])
  491. else:
  492. curs.execute(db_change(
  493. "update other set data = '' where name = 'domain'"
  494. ))
  495. if ver_num < 3500107:
  496. db_table_list = get_db_table_list()
  497. for for_a in db_table_list:
  498. for for_b in db_table_list[for_a]:
  499. curs.execute(db_change("update " + for_a + " set " + for_b + " = '' where " + for_b + " is null"))
  500. if ver_num < 3500113:
  501. db_table_list = get_db_table_list()
  502. for for_a in db_table_list:
  503. for for_b in db_table_list[for_a]:
  504. curs.execute(db_change("update " + for_a + " set " + for_b + " = '' where " + for_b + " is null"))
  505. if ver_num < 3500114:
  506. curs.execute(db_change('delete from alarm'))
  507. if ver_num < 3500354:
  508. curs.execute(db_change("select data from other where name = 'robot'"))
  509. db_data = curs.fetchall()
  510. if db_data:
  511. robot_default = '' + \
  512. 'User-agent: *\n' + \
  513. 'Disallow: /\n' + \
  514. 'Allow: /$\n' + \
  515. 'Allow: /image/\n' + \
  516. 'Allow: /views/\n' + \
  517. 'Allow: /w/' + \
  518. ''
  519. if db_data[0][0] == robot_default:
  520. curs.execute(db_change("insert into other (name, data, coverage) values ('robot_default', 'on', '')"))
  521. if ver_num < 3500355:
  522. # other coverage 오류 해결
  523. curs.execute(db_change(
  524. "update other set coverage = '' where coverage is null"
  525. ))
  526. if ver_num < 3500358:
  527. curs.execute(db_change("drop index history_index"))
  528. curs.execute(db_change("create index history_index on history (title, ip)"))
  529. if ver_num < 3500360:
  530. # 마지막 편집 따로 기록하도록
  531. # create_data['data_set'] = ['doc_name', 'doc_rev', 'set_name', 'set_data']
  532. print("Update 3500360...")
  533. curs.execute(db_change('delete from data_set where set_name = "last_edit"'))
  534. curs.execute(db_change("select title from data"))
  535. db_data = curs.fetchall()
  536. for for_a in db_data:
  537. curs.execute(db_change("select date from history where title = ? order by date desc limit 1"), [for_a[0]])
  538. db_data_2 = curs.fetchall()
  539. if db_data_2:
  540. curs.execute(db_change("insert into data_set (doc_name, doc_rev, set_name, set_data) values (?, '', 'last_edit', ?)"), [for_a[0], db_data_2[0][0]])
  541. curs.execute(db_change(
  542. 'delete from acl where title like "file:%" and data = "admin" and type like "decu%"'
  543. ))
  544. print("Update 3500360 complete")
  545. if ver_num < 3500361:
  546. # curs.execute(db_change('select id from user_set where name = "email" and data = ?'), [user_email])
  547. curs.execute(db_change('select id from user_set where name = "email"'))
  548. for db_data in curs.fetchall():
  549. if ip_or_user(db_data[0]) == 1:
  550. curs.execute(db_change(
  551. 'delete from user_set where id = ? and name = "email"'
  552. ), [db_data[0]])
  553. # if ver_num < 3500361:
  554. conn.commit()
  555. print('Update completed')
  556. def set_init_always(ver_num):
  557. global global_wiki_set
  558. curs = conn.cursor()
  559. curs.execute(db_change('delete from other where name = "ver"'))
  560. curs.execute(db_change('insert into other (name, data, coverage) values ("ver", ?, "")'), [ver_num])
  561. curs.execute(db_change('delete from alist where name = "owner"'))
  562. curs.execute(db_change('insert into alist (name, acl) values ("owner", "owner")'))
  563. if not os.path.exists(load_image_url()):
  564. os.makedirs(load_image_url())
  565. curs.execute(db_change('select data from other where name = "key"'))
  566. if not curs.fetchall():
  567. curs.execute(db_change('insert into other (name, data, coverage) values ("key", ?, "")'), [load_random_key()])
  568. curs.execute(db_change('select data from other where name = "salt_key"'))
  569. if not curs.fetchall():
  570. curs.execute(db_change('insert into other (name, data, coverage) values ("salt_key", ?, "")'), [load_random_key(4)])
  571. curs.execute(db_change('select data from other where name = "count_all_title"'))
  572. if not curs.fetchall():
  573. curs.execute(db_change('insert into other (name, data, coverage) values ("count_all_title", "0", "")'))
  574. curs.execute(db_change('select data from other where name = "wiki_access_password_need"'))
  575. db_data = curs.fetchall()
  576. if db_data and db_data[0][0] != '':
  577. curs.execute(db_change('select data from other where name = "wiki_access_password"'))
  578. db_data = curs.fetchall()
  579. if db_data:
  580. global_wiki_set['wiki_access_password'] = db_data[0][0]
  581. conn.commit()
  582. def set_init():
  583. curs = conn.cursor()
  584. # 초기값 설정 함수
  585. curs.execute(db_change("select html from html_filter where kind = 'email'"))
  586. if not curs.fetchall():
  587. for i in ['naver.com', 'gmail.com', 'daum.net', 'kakao.com']:
  588. curs.execute(db_change(
  589. "insert into html_filter (html, kind, plus, plus_t) values (?, 'email', '', '')"
  590. ), [i])
  591. curs.execute(db_change("select html from html_filter where kind = 'extension'"))
  592. if not curs.fetchall():
  593. for i in ['jpg', 'jpeg', 'png', 'gif', 'webp']:
  594. curs.execute(db_change(
  595. "insert into html_filter (html, kind, plus, plus_t) values (?, 'extension', '', '')"
  596. ), [i])
  597. curs.execute(db_change(
  598. 'select data from other ' + \
  599. 'where name = "smtp_server" or name = "smtp_port" or name = "smtp_security"'
  600. ))
  601. if not curs.fetchall():
  602. for i in [
  603. ['smtp_server', 'smtp.gmail.com'],
  604. ['smtp_port', '587'],
  605. ['smtp_security', 'starttls']
  606. ]:
  607. curs.execute(db_change("insert into other (name, data, coverage) values (?, ?, '')"), [i[0], i[1]])
  608. conn.commit()
  609. # Func-simple
  610. ## Func-simple-without_DB
  611. def get_default_admin_group():
  612. return ['owner', 'user', 'ban']
  613. def get_default_robots_txt():
  614. data = '' + \
  615. 'User-agent: *\n' + \
  616. 'Disallow: /\n' + \
  617. 'Allow: /$\n' + \
  618. 'Allow: /w/\n' + \
  619. 'Allow: /sitemap.xml$\n' + \
  620. 'Allow: /sitemap_*.xml$' + \
  621. ''
  622. if os.path.exists('sitemap.xml'):
  623. data += '' + \
  624. '\n' + \
  625. 'Sitemap: ' + load_domain('full') + '/sitemap.xml' + \
  626. ''
  627. return data
  628. def get_user_title_list(ip = ''):
  629. curs = conn.cursor()
  630. ip = ip_check() if ip == '' else ip
  631. # default
  632. user_title = {
  633. '' : load_lang('default'),
  634. '🌳' : '🌳 namu',
  635. }
  636. # admin
  637. if admin_check('all', None, ip) == 1:
  638. user_title['✅'] = '✅ admin'
  639. curs.execute(db_change('select name from user_set where id = ? and name = ?'), [ip, 'get_🥚'])
  640. if curs.fetchall():
  641. user_title['🥚'] = '🥚 easter_egg'
  642. return user_title
  643. def load_random_key(long = 128):
  644. return ''.join(
  645. random.choice(
  646. "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  647. ) for i in range(long)
  648. )
  649. def http_warning():
  650. return '''
  651. <div id="opennamu_http_warning_text"></div>
  652. <span style="display: none;" id="opennamu_http_warning_text_lang">''' + load_lang('http_warning') + '''</span>
  653. '''
  654. def get_next_page_bottom(link, num, page, end = 50):
  655. list_data = ''
  656. if num == 1:
  657. if len(page) == end:
  658. list_data += '' + \
  659. '<hr class="main_hr">' + \
  660. '<a href="' + link.format(str(num + 1)) + '">(' + load_lang('next') + ')</a>' + \
  661. ''
  662. elif len(page) != end:
  663. list_data += '' + \
  664. '<hr class="main_hr">' + \
  665. '<a href="' + link.format(str(num - 1)) + '">(' + load_lang('previous') + ')</a>' + \
  666. ''
  667. else:
  668. list_data += '' + \
  669. '<hr class="main_hr">' + \
  670. '<a href="' + link.format(str(num - 1)) + '">(' + load_lang('previous') + ')</a> ' + \
  671. '<a href="' + link.format(str(num + 1)) + '">(' + load_lang('next') + ')</a>' + \
  672. ''
  673. return list_data
  674. def next_fix(link, num, page, end = 50):
  675. list_data = ''
  676. if num == 1:
  677. if len(page) == end:
  678. list_data += '' + \
  679. '<hr class="main_hr">' + \
  680. '<a href="' + link + str(num + 1) + '">(' + load_lang('next') + ')</a>' + \
  681. ''
  682. elif len(page) != end:
  683. list_data += '' + \
  684. '<hr class="main_hr">' + \
  685. '<a href="' + link + str(num - 1) + '">(' + load_lang('previous') + ')</a>' + \
  686. ''
  687. else:
  688. list_data += '' + \
  689. '<hr class="main_hr">' + \
  690. '<a href="' + link + str(num - 1) + '">(' + load_lang('previous') + ')</a> <a href="' + link + str(num + 1) + '">(' + load_lang('next') + ')</a>' + \
  691. ''
  692. return list_data
  693. def leng_check(A, B):
  694. # B -> new
  695. # A -> old
  696. return '0' if A == B else (('-' + str(A - B)) if A > B else ('+' + str(B - A)))
  697. def number_check(data):
  698. try:
  699. int(data)
  700. return data
  701. except:
  702. return '1'
  703. def check_int(data):
  704. try:
  705. int(data)
  706. return data
  707. except:
  708. return ''
  709. def redirect(data = '/'):
  710. return flask.redirect(load_domain('full') + data)
  711. def get_acl_list(type_d = 'normal'):
  712. if type_d == 'user':
  713. return ['', 'user', 'all']
  714. else:
  715. return ['', 'all', 'user', 'admin', 'owner', '50_edit', 'email', 'ban', 'before', '30_day', 'ban_admin', 'not_all']
  716. ## Func-simple-with_DB
  717. def load_image_url():
  718. curs = conn.cursor()
  719. curs.execute(db_change('select data from other where name = "image_where"'))
  720. image_where = curs.fetchall()
  721. image_where = image_where[0][0] if image_where else os.path.join('data', 'images')
  722. return image_where
  723. def load_domain(data_type = 'normal'):
  724. curs = conn.cursor()
  725. domain = ''
  726. if data_type == 'full':
  727. curs.execute(db_change("select data from other where name = 'http_select'"))
  728. db_data = curs.fetchall()
  729. domain += db_data[0][0] if db_data and db_data[0][0] != '' else 'http'
  730. domain += '://'
  731. curs.execute(db_change("select data from other where name = 'domain'"))
  732. db_data = curs.fetchall()
  733. domain += db_data[0][0] if db_data and db_data[0][0] != '' else flask.request.host
  734. else:
  735. curs.execute(db_change("select data from other where name = 'domain'"))
  736. db_data = curs.fetchall()
  737. domain += db_data[0][0] if db_data and db_data[0][0] != '' else flask.request.host
  738. return domain
  739. def edit_button(ob_name = 'opennamu_edit_textarea', monaco_ob_name = 'opennamu_monaco_editor'):
  740. curs = conn.cursor()
  741. insert_list = []
  742. curs.execute(db_change("select html, plus from html_filter where kind = 'edit_top'"))
  743. db_data = curs.fetchall()
  744. for get_data in db_data:
  745. insert_list += [[get_data[1], get_data[0]]]
  746. data = ''
  747. for insert_data in insert_list:
  748. data += '<a href="javascript:do_insert_data(\'' + ob_name + '\', \'' + insert_data[0] + '\', \'' + monaco_ob_name + '\');">(' + insert_data[1] + ')</a> '
  749. data += (' ' if data != '' else '') + '<a href="/edit_top">(' + load_lang('add') + ')</a>'
  750. data += '<hr class="main_hr">'
  751. return data
  752. def ip_warning():
  753. curs = conn.cursor()
  754. if ip_or_user() != 0:
  755. curs.execute(db_change('select data from other where name = "no_login_warning"'))
  756. data = curs.fetchall()
  757. if data and data[0][0] != '':
  758. text_data = '' + \
  759. '<span>' + data[0][0] + '</span>' + \
  760. '<hr class="main_hr">' + \
  761. ''
  762. else:
  763. text_data = '' + \
  764. '<span>' + load_lang('no_login_warning') + '</span>' + \
  765. '<hr class="main_hr">' + \
  766. ''
  767. else:
  768. text_data = ''
  769. return text_data
  770. # Func-login
  771. def pw_encode(data, db_data_encode = ''):
  772. curs = conn.cursor()
  773. if db_data_encode == '':
  774. curs.execute(db_change('select data from other where name = "encode"'))
  775. db_data = curs.fetchall()
  776. db_data_encode = db_data[0][0] if db_data else 'sha3'
  777. if db_data_encode == 'sha256':
  778. return hashlib.sha256(bytes(data, 'utf-8')).hexdigest()
  779. elif db_data_encode == 'sha3':
  780. return hashlib.sha3_256(bytes(data, 'utf-8')).hexdigest()
  781. elif db_data_encode == 'sha3-512':
  782. return hashlib.sha3_512(bytes(data, 'utf-8')).hexdigest()
  783. else:
  784. curs.execute(db_change('select data from other where name = "salt_key"'))
  785. db_data = curs.fetchall()
  786. db_data_salt = db_data[0][0] if db_data else ''
  787. if db_data_encode == 'sha3-salt':
  788. return hashlib.sha3_256(bytes(data + db_data_salt, 'utf-8')).hexdigest()
  789. else:
  790. return hashlib.sha3_512(bytes(data + db_data_salt, 'utf-8')).hexdigest()
  791. def pw_check(data, data2, type_d = 'no', id_d = ''):
  792. curs = conn.cursor()
  793. curs.execute(db_change('select data from other where name = "encode"'))
  794. db_data = curs.fetchall()
  795. if type_d != 'no':
  796. if type_d == '':
  797. set_data = 'sha3'
  798. else:
  799. set_data = type_d
  800. else:
  801. set_data = db_data[0][0]
  802. re_data = 1 if pw_encode(data, set_data) == data2 else 0
  803. if db_data[0][0] != set_data and re_data == 1 and id_d != '':
  804. curs.execute(db_change("update user_set set data = ? where id = ? and name = 'pw'"), [
  805. pw_encode(data),
  806. id_d
  807. ])
  808. curs.execute(db_change("update user_set set data = ? where id = ? and name = 'encode'"), [
  809. db_data[0][0],
  810. id_d
  811. ])
  812. return re_data
  813. # Func-skin
  814. def easy_minify(data, tool = None):
  815. # without_DB
  816. if 'wiki_access_password' in global_wiki_set:
  817. access_password = global_wiki_set['wiki_access_password']
  818. input_password = flask.request.cookies.get('opennamu_wiki_access', ' ')
  819. if url_pas(access_password) == input_password:
  820. return data
  821. return '''
  822. <script src="/views/main_css/js/route/wiki_access_password.js"></script>
  823. <h2>''' + load_lang('error_password_require_for_wiki_access') + '''</h2>
  824. <input type="password" id="wiki_access">
  825. <input type="submit" onclick="opennamu_do_wiki_access();">
  826. '''
  827. else:
  828. return data
  829. def load_lang(data, safe = 0):
  830. curs = conn.cursor()
  831. global global_lang
  832. ip = ip_check()
  833. if ip_or_user(ip) == 0:
  834. curs.execute(db_change('select data from user_set where name = "lang" and id = ?'), [ip])
  835. rep_data = curs.fetchall()
  836. elif 'lang' in flask.session:
  837. rep_data = [[flask.session['lang']]]
  838. else:
  839. curs.execute(db_change("select data from other where name = 'language'"))
  840. rep_data = curs.fetchall()
  841. if not rep_data or rep_data[0][0] in ('', 'default'):
  842. curs.execute(db_change("select data from other where name = 'language'"))
  843. rep_data = curs.fetchall()
  844. if rep_data:
  845. lang_name = rep_data[0][0]
  846. else:
  847. lang_name = 'en-US'
  848. if lang_name in global_lang:
  849. lang = global_lang[lang_name]
  850. else:
  851. lang_list = os.listdir('lang')
  852. if (lang_name + '.json') in lang_list:
  853. lang = json.loads(open(
  854. os.path.join('lang', lang_name + '.json'),
  855. encoding = 'utf8'
  856. ).read())
  857. global_lang[lang_name] = lang
  858. else:
  859. lang = {}
  860. if data in lang:
  861. if safe == 1:
  862. return lang[data]
  863. else:
  864. return html.escape(lang[data])
  865. return html.escape(data + ' (' + lang_name + ')')
  866. def skin_check(set_n = 0):
  867. curs = conn.cursor()
  868. # 개편 필요?
  869. skin_list = load_skin('ringo', 1)
  870. skin = skin_list[0]
  871. ip = ip_check()
  872. user_need_skin = ''
  873. if ip_or_user(ip) == 0:
  874. curs.execute(db_change('select data from user_set where name = "skin" and id = ?'), [ip])
  875. skin_exist = curs.fetchall()
  876. if skin_exist:
  877. user_need_skin = skin_exist[0][0]
  878. else:
  879. if 'skin' in flask.session:
  880. user_need_skin = flask.session['skin']
  881. user_need_skin = '' if user_need_skin == 'default' else user_need_skin
  882. if user_need_skin == '':
  883. curs.execute(db_change('select data from other where name = "skin"'))
  884. skin_exist = curs.fetchall()
  885. if skin_exist:
  886. user_need_skin = skin_exist[0][0]
  887. if user_need_skin != '' and user_need_skin in skin_list:
  888. skin = user_need_skin
  889. if set_n == 0:
  890. return './views/' + skin + '/index.html'
  891. else:
  892. return skin
  893. def wiki_css(data):
  894. # without_DB
  895. data += ['' for _ in range(0, 3 - len(data))]
  896. data_css = ''
  897. data_css_ver = '172'
  898. # Func JS + Defer
  899. data_css += '<script src="/views/main_css/js/func/func.js?ver=' + data_css_ver + '"></script>'
  900. data_css += '<script defer src="/views/main_css/js/func/insert_version.js?ver=' + data_css_ver + '"></script>'
  901. data_css += '<script defer src="/views/main_css/js/func/insert_user_info.js?ver=' + data_css_ver + '"></script>'
  902. data_css += '<script defer src="/views/main_css/js/func/insert_version_skin.js?ver=' + data_css_ver + '"></script>'
  903. data_css += '<script defer src="/views/main_css/js/func/insert_http_warning_text.js?ver=' + data_css_ver + '"></script>'
  904. data_css += '<script defer src="/views/main_css/js/func/ie_end_of_life.js?ver=' + data_css_ver + '"></script>'
  905. data_css += '<script defer src="/views/main_css/js/func/shortcut.js?ver=' + data_css_ver + '"></script>'
  906. # Route JS + Defer
  907. data_css += '<script defer src="/views/main_css/js/route/thread.js?ver=' + data_css_ver + '"></script>'
  908. # 레거시 일반 JS
  909. data_css += '<script src="/views/main_css/js/load_editor.js?ver=' + data_css_ver + '"></script>'
  910. # Main CSS
  911. data_css += '<link rel="stylesheet" href="/views/main_css/css/main.css?ver=' + data_css_ver + '">'
  912. # External
  913. data_css += '<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.5.0/build/styles/default.min.css">'
  914. data_css += '<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.5.0/build/highlight.min.js"></script>'
  915. data_css += '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css" integrity="sha384-vKruj+a13U8yHIkAyGgK1J3ArTLzrFGBbBc0tDp4ad/EyewESeXE/Iv67Aj8gKZ0" crossorigin="anonymous">'
  916. data_css += '<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js" integrity="sha384-PwRUT/YqbnEjkZO0zZxNqcxACrXe+j766U2amXcgMg5457rve2Y7I6ZJSm2A0mS4" crossorigin="anonymous"></script>'
  917. data = data[0:2] + ['', data_css] + data[2:]
  918. return data
  919. def cut_100(data):
  920. # without_DB
  921. if re.search(r'<div class="opennamu_render_complete">', data):
  922. data = re.sub(r'(.|\r|\n)*<div class="opennamu_render_complete">', '', data, 1)
  923. data = data.replace('<br>', ' ')
  924. data = data.replace('\r', '')
  925. data = data.replace('\n', ' ')
  926. data = re.sub(r'<[^<>]+>', ' ', data)
  927. data = data.replace('\n', ' ')
  928. data = re.sub(r' {2,}', ' ', data)
  929. data = re.sub(r'(^ +| +$)', '', data)
  930. data_len = len(data)
  931. if data_len > 100:
  932. return data[0:100]
  933. else:
  934. return data[0:data_len]
  935. else:
  936. return ''
  937. def wiki_set(num = 1):
  938. curs = conn.cursor()
  939. ip = ip_check()
  940. skin_name = skin_check(1)
  941. data_list = []
  942. curs.execute(db_change('select data from other where name = ?'), ['name'])
  943. db_data = curs.fetchall()
  944. data_list += [db_data[0][0]] if db_data and db_data[0][0] != '' else ['Wiki']
  945. curs.execute(db_change('select data from other where name = "license"'))
  946. db_data = curs.fetchall()
  947. data_list += [db_data[0][0]] if db_data and db_data[0][0] != '' else ['ARR']
  948. data_list += ['', '']
  949. curs.execute(db_change('select data from other where name = "logo" and coverage = ?'), [skin_name])
  950. db_data = curs.fetchall()
  951. if db_data and db_data[0][0] != '':
  952. data_list += [db_data[0][0]]
  953. else:
  954. curs.execute(db_change('select data from other where name = "logo" and coverage = ""'))
  955. db_data = curs.fetchall()
  956. data_list += [db_data[0][0]] if db_data and db_data[0][0] != '' else [data_list[0]]
  957. head_data = ''
  958. curs.execute(db_change("select data from other where name = 'head' and coverage = ''"))
  959. db_data = curs.fetchall()
  960. head_data += db_data[0][0] if db_data and db_data[0][0] != '' else ''
  961. curs.execute(db_change("select data from other where name = 'head' and coverage = ?"), [skin_name])
  962. db_data = curs.fetchall()
  963. head_data += db_data[0][0] if db_data and db_data[0][0] != '' else ''
  964. data_list += [head_data]
  965. curs.execute(db_change("select data from other where name = 'top_menu'"))
  966. db_data = curs.fetchall()
  967. db_data = db_data[0][0] if db_data else ''
  968. db_data = db_data.replace('\r', '')
  969. curs.execute(db_change("select data from user_set where name = '' and id = ?"), [ip])
  970. db_data_2 = curs.fetchall()
  971. db_data_2 = db_data_2[0][0] if db_data_2 else ''
  972. db_data += db_data_2.replace('\r', '')
  973. if db_data != '':
  974. db_data = db_data.split('\n')
  975. if len(db_data) % 2 != 0:
  976. db_data += ['']
  977. db_data = [[db_data[for_a], db_data[for_a + 1]] for for_a in range(0, len(db_data), 2)]
  978. data_list += [db_data]
  979. return data_list
  980. def wiki_custom():
  981. curs = conn.cursor()
  982. ip = ip_check()
  983. skin_name = '_' + skin_check(1)
  984. if ip_or_user(ip) == 0:
  985. user_icon = 1
  986. user_name = ip
  987. if 'head' in flask.session:
  988. user_head = flask.session['head']
  989. else:
  990. curs.execute(db_change("select data from user_set where id = ? and name = 'custom_css'"), [ip])
  991. db_data = curs.fetchall()
  992. user_head = db_data[0][0] if db_data else ''
  993. flask.session['head'] = db_data[0][0] if db_data else ''
  994. if 'head' + skin_name in flask.session:
  995. user_head += flask.session['head' + skin_name]
  996. else:
  997. curs.execute(db_change("select data from user_set where id = ? and name = ?"), [ip, 'custom_css' + skin_name])
  998. db_data = curs.fetchall()
  999. user_head += db_data[0][0] if db_data else ''
  1000. flask.session['head' + skin_name] = db_data[0][0] if db_data else ''
  1001. curs.execute(db_change('select data from user_set where name = "email" and id = ?'), [ip])
  1002. email = curs.fetchall()
  1003. email = email[0][0] if email else ''
  1004. if admin_check('all') == 1:
  1005. user_admin = '1'
  1006. user_acl_list = []
  1007. curs.execute(db_change("select data from user_set where id = ? and name = 'acl'"), [ip])
  1008. curs.execute(db_change('select acl from alist where name = ?'), [curs.fetchall()[0][0]])
  1009. user_acl = curs.fetchall()
  1010. for i in user_acl:
  1011. user_acl_list += [i[0]]
  1012. user_acl_list = user_acl_list if user_acl != [] else '0'
  1013. else:
  1014. user_admin = '0'
  1015. user_acl_list = '0'
  1016. curs.execute(db_change("select count(*) from alarm where name = ?"), [ip])
  1017. count = curs.fetchall()
  1018. user_notice = str(count[0][0]) if count else '0'
  1019. else:
  1020. user_icon = 0
  1021. user_name = load_lang('user')
  1022. email = ''
  1023. user_admin = '0'
  1024. user_acl_list = '0'
  1025. user_notice = '0'
  1026. user_head = flask.session['head'] if 'head' in flask.session else ''
  1027. user_head += flask.session['head' + skin_name] if 'head' + skin_name in flask.session else ''
  1028. curs.execute(db_change("select title from rd where title = ? and stop = ''"), ['user:' + ip])
  1029. user_topic = '1' if curs.fetchall() else '0'
  1030. split_path = flask.request.path.split('/')
  1031. if len(split_path) > 1:
  1032. split_path = split_path[1]
  1033. else:
  1034. split_path = 0
  1035. return [
  1036. '',
  1037. '',
  1038. user_icon,
  1039. user_head,
  1040. email,
  1041. user_name,
  1042. user_admin,
  1043. str(ban_check()),
  1044. user_notice,
  1045. user_acl_list,
  1046. ip,
  1047. user_topic,
  1048. split_path
  1049. ]
  1050. def load_skin(data = '', set_n = 0, default = 0):
  1051. # without_DB
  1052. # data -> 가장 앞에 있을 스킨 이름
  1053. # set_n == 0 -> 스트링으로 반환
  1054. # set_n == 1 -> 리스트로 반환
  1055. # default == 0 -> 디폴트 미포함
  1056. # default == 1 -> 디폴트 포함
  1057. if set_n == 0:
  1058. skin_return_data = ''
  1059. else:
  1060. skin_return_data = []
  1061. skin_list_get = os.listdir('views')
  1062. if default == 1:
  1063. skin_list_get = ['default'] + skin_list_get
  1064. for skin_data in skin_list_get:
  1065. if skin_data != 'default':
  1066. see_data = skin_data
  1067. else:
  1068. see_data = load_lang('default')
  1069. if skin_data != 'main_css':
  1070. if set_n == 0:
  1071. if skin_data == data:
  1072. skin_return_data = '' + \
  1073. '<option value="' + skin_data + '">' + \
  1074. see_data + \
  1075. '</option>' + \
  1076. '' + skin_return_data
  1077. else:
  1078. skin_return_data += '' + \
  1079. '<option value="' + skin_data + '">' + \
  1080. see_data + \
  1081. '</option>' + \
  1082. ''
  1083. else:
  1084. if skin_data == data:
  1085. skin_return_data = [skin_data] + skin_return_data
  1086. else:
  1087. skin_return_data += [skin_data]
  1088. return skin_return_data
  1089. # Func-markup
  1090. def render_set(doc_name = '', doc_data = '', data_type = 'view', data_in = '', doc_acl = ''):
  1091. curs = conn.cursor()
  1092. # data_type in ['view', 'raw', 'api_view', 'backlink']
  1093. doc_acl = acl_check(doc_name, 'render') if doc_acl == '' else doc_acl
  1094. doc_data = 0 if doc_data == None else doc_data
  1095. acl_dict = {}
  1096. acl_dict[doc_name] = doc_acl
  1097. if doc_acl == 1:
  1098. return 'HTTP Request 401.3'
  1099. else:
  1100. if data_type == 'raw':
  1101. return doc_data
  1102. if doc_data != 0:
  1103. render_lang_data = {
  1104. 'toc' : load_lang('toc'),
  1105. 'category' : load_lang('category')
  1106. }
  1107. get_class_render = class_do_render(conn, render_lang_data).do_render(doc_name, doc_data, data_type, data_in)
  1108. if data_type == 'backlink':
  1109. return ''
  1110. if 'include' in get_class_render[2]:
  1111. for_a = 0
  1112. while len(get_class_render[2]['include']) > for_a:
  1113. include_data = get_class_render[2]['include'][for_a]
  1114. if include_data[1] in acl_dict:
  1115. acl_result = acl_dict[include_data[1]]
  1116. else:
  1117. acl_result = acl_check(include_data[1], 'render')
  1118. acl_dict[include_data[1]] = acl_result
  1119. if acl_result == 0:
  1120. include_regex = re.compile('<div id="' + include_data[0] + '"><\/div>')
  1121. if re.search(include_regex, get_class_render[0]):
  1122. include_data_render = class_do_render(conn, render_lang_data).do_render(include_data[1], include_data[2], data_type, include_data[0] + data_in)
  1123. if len(include_data) > 3:
  1124. include_data_render[0] = '<div id="' + include_data[0] + '" ' + include_data[3] + '>' + include_data_render[0] + '</div>'
  1125. else:
  1126. include_data_render[0] = '<div id="' + include_data[0] + '">' + include_data_render[0] + '</div>'
  1127. get_class_render[0] = re.sub(include_regex, include_data_render[0], get_class_render[0])
  1128. get_class_render[1] += include_data_render[1]
  1129. get_class_render[2]['include'] += include_data_render[2]['include']
  1130. for_a += 1
  1131. get_class_render[0] = '<div class="opennamu_render_complete">' + get_class_render[0] + '</div>'
  1132. curs.execute(db_change("select data from other where name = 'namumark_compatible'"))
  1133. db_data = curs.fetchall()
  1134. if db_data and db_data[0][0] != '':
  1135. get_class_render[0] += '''
  1136. <style>
  1137. .opennamu_render_complete {
  1138. font-size: 14.4px !important;
  1139. }
  1140. .opennamu_render_complete td {
  1141. padding: 5px 10px !important;
  1142. }
  1143. .opennamu_render_complete summary {
  1144. list-style: none !important;
  1145. font-weight: bold;
  1146. }
  1147. </style>
  1148. '''
  1149. if data_type == 'api_view':
  1150. return [
  1151. get_class_render[0],
  1152. get_class_render[1]
  1153. ]
  1154. else:
  1155. return get_class_render[0] + '<script>' + get_class_render[1] + '</script>'
  1156. else:
  1157. return 'HTTP Request 404'
  1158. def render_simple_set(data):
  1159. toc_data = ''
  1160. toc_regex = r'<h([1-6])>([^<>]+)<\/h[1-6]>'
  1161. toc_search_data = re.findall(toc_regex, data)
  1162. heading_stack = [0, 0, 0, 0, 0, 0]
  1163. if toc_search_data:
  1164. toc_data += '''
  1165. <div class="opennamu_TOC" id="toc">
  1166. <span class="opennamu_TOC_title">''' + load_lang('toc') + '''</span>
  1167. <br>
  1168. '''
  1169. for toc_search_in in toc_search_data:
  1170. heading_level = int(toc_search_in[0])
  1171. heading_level_str = str(heading_level)
  1172. heading_stack[heading_level - 1] += 1
  1173. for for_a in range(heading_level, 6):
  1174. heading_stack[for_a] = 0
  1175. heading_stack_str = ''.join([str(for_a) + '.' if for_a != 0 else '' for for_a in heading_stack])
  1176. heading_stack_str = re.sub(r'\.$', '', heading_stack_str)
  1177. toc_data += '''
  1178. <br>
  1179. <span class="opennamu_TOC_list">
  1180. ''' + ('<span style="margin-left: 10px;"></span>' * (heading_stack_str.count('.'))) + '''
  1181. <a href="#s-''' + heading_stack_str + '''">''' + heading_stack_str + '''.</a>
  1182. ''' + toc_search_in[1] + '''
  1183. </span>
  1184. '''
  1185. data = re.sub(toc_regex, '<h' + toc_search_in[0] + ' id="s-' + heading_stack_str + '"><a href="#toc">' + heading_stack_str + '.</a> ' + toc_search_in[1] + '</h' + toc_search_in[0] + '>', data, 1)
  1186. if toc_data != '':
  1187. toc_data += '</div>'
  1188. footnote_data = ''
  1189. footnote_regex = r'<sup>((?:(?!<sup>|<\/sup>).)+)<\/sup>'
  1190. footnote_search_data = re.findall(footnote_regex, data)
  1191. footnote_count = 1
  1192. if footnote_search_data:
  1193. footnote_data += '<div class="opennamu_footnote">'
  1194. for footnote_search in footnote_search_data:
  1195. footnote_count_str = str(footnote_count)
  1196. if footnote_count != 1:
  1197. footnote_data += '<br>'
  1198. footnote_data += '<a id="fn-' + footnote_count_str + '" href="#rfn-' + footnote_count_str + '">(' + footnote_count_str + ')</a> ' + footnote_search
  1199. data = re.sub(footnote_regex, '<sup id="rfn-' + footnote_count_str + '"><a href="#fn-' + footnote_count_str + '">(' + footnote_count_str + ')</a></sup>', data, 1)
  1200. footnote_count += 1
  1201. if footnote_data != '':
  1202. footnote_data += '</div>'
  1203. data = toc_data + data + footnote_data
  1204. return data
  1205. # Func-request
  1206. def send_email(who, title, data):
  1207. curs = conn.cursor()
  1208. curs.execute(db_change('' + \
  1209. 'select name, data from other ' + \
  1210. 'where name = "smtp_email" or name = "smtp_pass" or name = "smtp_server" or name = "smtp_port" or name = "smtp_security"' + \
  1211. ''))
  1212. rep_data = curs.fetchall()
  1213. smtp_email = ''
  1214. smtp_pass = ''
  1215. smtp_server = ''
  1216. smtp_security = ''
  1217. smtp_port = ''
  1218. smtp = ''
  1219. for i in rep_data:
  1220. if i[0] == 'smtp_email':
  1221. smtp_email = i[1]
  1222. elif i[0] == 'smtp_pass':
  1223. smtp_pass = i[1]
  1224. elif i[0] == 'smtp_server':
  1225. smtp_server = i[1]
  1226. elif i[0] == 'smtp_security':
  1227. smtp_security = i[1]
  1228. elif i[0] == 'smtp_port':
  1229. smtp_port = i[1]
  1230. smtp_port = int(number_check(smtp_port))
  1231. if smtp_security == 'plain':
  1232. smtp = smtplib.SMTP(smtp_server, smtp_port)
  1233. elif smtp_security == 'starttls':
  1234. smtp = smtplib.SMTP(smtp_server, smtp_port)
  1235. smtp.starttls()
  1236. else:
  1237. # if smtp_security == 'tls':
  1238. smtp = smtplib.SMTP_SSL(smtp_server, smtp_port)
  1239. domain = load_domain()
  1240. wiki_name = wiki_set()[0]
  1241. msg = email.mime.text.MIMEText(data)
  1242. msg['Subject'] = title
  1243. msg['From'] = wiki_name + ' <noreply@' + domain + '>'
  1244. msg['To'] = who
  1245. try:
  1246. smtp.login(smtp_email, smtp_pass)
  1247. smtp.sendmail('openNAMU@' + domain, who, msg.as_string())
  1248. smtp.quit()
  1249. return 1
  1250. except Exception as e:
  1251. print('----')
  1252. print('Error : email send error')
  1253. print(e)
  1254. return 0
  1255. def captcha_get():
  1256. curs = conn.cursor()
  1257. data = ''
  1258. if ip_or_user() != 0:
  1259. curs.execute(db_change('select data from other where name = "recaptcha"'))
  1260. recaptcha = curs.fetchall()
  1261. curs.execute(db_change('select data from other where name = "sec_re"'))
  1262. sec_re = curs.fetchall()
  1263. curs.execute(db_change('select data from other where name = "recaptcha_ver"'))
  1264. rec_ver = curs.fetchall()
  1265. if recaptcha and recaptcha[0][0] != '' and sec_re and sec_re[0][0] != '':
  1266. if not rec_ver or rec_ver[0][0] == '':
  1267. data += '' + \
  1268. '<script src="https://www.google.com/recaptcha/api.js" async defer></script>' + \
  1269. '<div class="g-recaptcha" data-sitekey="' + recaptcha[0][0] + '"></div>' + \
  1270. '<hr class="main_hr">' + \
  1271. ''
  1272. elif rec_ver[0][0] == 'v3':
  1273. data += '' + \
  1274. '<script src="https://www.google.com/recaptcha/api.js?render=' + recaptcha[0][0] + '"></script>' + \
  1275. '<input type="hidden" id="g-recaptcha" name="g-recaptcha">' + \
  1276. '<script type="text/javascript">' + \
  1277. 'grecaptcha.ready(function() {' + \
  1278. 'grecaptcha.execute(\'' + recaptcha[0][0] + '\', {action: \'homepage\'}).then(function(token) {' + \
  1279. 'document.getElementById(\'g-recaptcha\').value = token;' + \
  1280. '});' + \
  1281. '});' + \
  1282. '</script>' + \
  1283. ''
  1284. else:
  1285. data += '''
  1286. <script src="https://js.hcaptcha.com/1/api.js" async defer></script>
  1287. <div class="h-captcha" data-sitekey="''' + recaptcha[0][0] + '''"></div>
  1288. <hr class="main_hr">
  1289. '''
  1290. return data
  1291. def captcha_post(re_data, num = 1):
  1292. curs = conn.cursor()
  1293. if num == 1 and ip_or_user() != 0:
  1294. curs.execute(db_change('select data from other where name = "sec_re"'))
  1295. sec_re = curs.fetchall()
  1296. curs.execute(db_change('select data from other where name = "recaptcha_ver"'))
  1297. rec_ver = curs.fetchall()
  1298. if captcha_get() != '':
  1299. if not rec_ver or rec_ver[0][0] in ('', 'v3'):
  1300. data = requests.get(
  1301. 'https://www.google.com/recaptcha/api/siteverify' + \
  1302. '?secret=' + sec_re[0][0] + '&response=' + re_data
  1303. )
  1304. if data.status_code == 200:
  1305. json_data = json.loads(data.text)
  1306. if json_data['success'] != True:
  1307. return 1
  1308. else:
  1309. data = requests.get(
  1310. 'https://hcaptcha.com/siteverify' + \
  1311. '?secret=' + sec_re[0][0] + '&response=' + re_data
  1312. )
  1313. if data.status_code == 200:
  1314. json_data = json.loads(data.text)
  1315. if json_data['success'] != True:
  1316. return 1
  1317. return 0
  1318. # Func-user
  1319. def get_admin_auth_list(num = None):
  1320. check = {
  1321. 0 : 'owner',
  1322. 1 : 'ban',
  1323. 2 : 'nothing',
  1324. 3 : 'toron',
  1325. 4 : 'check',
  1326. 5 : 'acl',
  1327. 6 : 'hidel',
  1328. 7 : 'give'
  1329. }
  1330. if not num:
  1331. check = check[0]
  1332. elif num == 'all':
  1333. check = [check[i] for i in check]
  1334. else:
  1335. check = check[num]
  1336. return check
  1337. def get_admin_list(num = None):
  1338. curs = conn.cursor()
  1339. if num == 'all':
  1340. curs.execute(db_change(
  1341. "select data from user_set where data != 'user' and name = 'acl'"
  1342. ))
  1343. db_data = curs.fetchall()
  1344. db_data = [db_data_in[0] for db_data_in in db_data] if db_data else []
  1345. return db_data
  1346. else:
  1347. check = get_admin_auth_list(num)
  1348. admin_list = []
  1349. curs.execute(db_change(
  1350. 'select name from alist where acl = ?'
  1351. ), [check])
  1352. db_data = curs.fetchall()
  1353. for db_data_in in db_data:
  1354. curs.execute(db_change(
  1355. "select id from user_set where data = ? and name = 'acl'"
  1356. ), [db_data_in[0]])
  1357. db_data_2 = curs.fetchall()
  1358. admin_list += [db_data_2_in[0] for db_data_2_in in db_data_2] if db_data_2 else []
  1359. return admin_list
  1360. def admin_check(num = None, what = None, name = ''):
  1361. curs = conn.cursor()
  1362. ip = ip_check() if name == '' else name
  1363. time_data = get_time()
  1364. pass_ok = 0
  1365. if ip_or_user(ip) == 0:
  1366. curs.execute(db_change(
  1367. "select data from user_set where id = ? and name = 'acl'"
  1368. ), [ip])
  1369. user_auth = curs.fetchall()
  1370. if user_auth:
  1371. user_auth = user_auth[0][0]
  1372. check = get_admin_auth_list(num)
  1373. curs.execute(db_change(
  1374. 'select name from alist where name = ? and acl = "owner"'
  1375. ), [user_auth])
  1376. if curs.fetchall():
  1377. pass_ok = 1
  1378. else:
  1379. if num == 'all':
  1380. curs.execute(db_change(
  1381. 'select name from alist where name = ?'
  1382. ), [user_auth])
  1383. else:
  1384. curs.execute(db_change(
  1385. 'select name from alist where name = ? and acl = ?'
  1386. ), [user_auth, check])
  1387. if curs.fetchall():
  1388. pass_ok = 1
  1389. if pass_ok == 1:
  1390. if what:
  1391. curs.execute(db_change(
  1392. "insert into re_admin (who, what, time) values (?, ?, ?)"
  1393. ), [ip, what, time_data])
  1394. conn.commit()
  1395. return 1
  1396. return 0
  1397. def acl_check(name = 'test', tool = '', topic_num = '1'):
  1398. curs = conn.cursor()
  1399. ip = ip_check()
  1400. get_ban = ban_check()
  1401. if tool == '' and name:
  1402. if acl_check(name, 'render') == 1:
  1403. return 1
  1404. user_page = re.search(r"^user:((?:(?!\/).)*)", name)
  1405. if user_page:
  1406. user_page = user_page.group(1)
  1407. if admin_check(5) == 1:
  1408. return 0
  1409. if get_ban == 1:
  1410. return 1
  1411. curs.execute(db_change(
  1412. "select data from acl where title = ? and type = 'decu'"
  1413. ), [name])
  1414. acl_data = curs.fetchall()
  1415. if acl_data:
  1416. if acl_data[0][0] == 'all':
  1417. return 0
  1418. elif acl_data[0][0] == 'user' and not ip_or_user(ip) == 1:
  1419. return 0
  1420. if ip == user_page and not ip_or_user(ip) == 1:
  1421. return 0
  1422. return 1
  1423. elif tool in ['document_edit', 'document_move', 'document_delete']:
  1424. if acl_check(name, '') == 1:
  1425. return 1
  1426. elif tool == 'topic':
  1427. curs.execute(db_change("select title from rd where code = ?"), [topic_num])
  1428. name = curs.fetchall()
  1429. name = name[0][0] if name else 'test'
  1430. if tool in ['topic']:
  1431. end = 3
  1432. elif tool in ['render', 'vote', '', 'document_edit', 'document_move', 'document_delete']:
  1433. end = 2
  1434. else:
  1435. end = 1
  1436. for i in range(0, end):
  1437. if tool == '':
  1438. if i == 0:
  1439. curs.execute(db_change(
  1440. "select data from acl where title = ? and type = 'decu'"
  1441. ), [name])
  1442. '''
  1443. elif i == 1:
  1444. curs.execute(db_change(
  1445. "select plus from html_filter where kind = 'document'"
  1446. ))
  1447. '''
  1448. else:
  1449. curs.execute(db_change(
  1450. 'select data from other where name = "edit"'
  1451. ))
  1452. num = 5
  1453. elif tool == 'document_move':
  1454. if i == 0:
  1455. curs.execute(db_change(
  1456. "select data from acl where title = ? and type = 'document_move_acl'"
  1457. ), [name])
  1458. else:
  1459. curs.execute(db_change(
  1460. 'select data from other where name = "document_move_acl"'
  1461. ))
  1462. num = 5
  1463. elif tool == 'document_edit':
  1464. if i == 0:
  1465. curs.execute(db_change(
  1466. "select data from acl where title = ? and type = 'document_edit_acl'"
  1467. ), [name])
  1468. else:
  1469. curs.execute(db_change(
  1470. 'select data from other where name = "document_edit_acl"'
  1471. ))
  1472. num = 5
  1473. elif tool == 'document_delete':
  1474. if i == 0:
  1475. curs.execute(db_change(
  1476. "select data from acl where title = ? and type = 'document_delete_acl'"
  1477. ), [name])
  1478. else:
  1479. curs.execute(db_change(
  1480. 'select data from other where name = "document_delete_acl"'
  1481. ))
  1482. num = 5
  1483. elif tool == 'topic':
  1484. if i == 0:
  1485. curs.execute(db_change(
  1486. "select acl from rd where code = ?"
  1487. ), [topic_num])
  1488. elif i == 1:
  1489. curs.execute(db_change(
  1490. "select data from acl where title = ? and type = 'dis'"
  1491. ), [name])
  1492. else:
  1493. curs.execute(db_change(
  1494. 'select data from other where name = "discussion"'
  1495. ))
  1496. num = 3
  1497. elif tool == 'topic_view':
  1498. curs.execute(db_change("select set_data from topic_set where thread_code = ? and set_name = 'thread_view_acl'"), [
  1499. topic_num
  1500. ])
  1501. num = 3
  1502. elif tool == 'upload':
  1503. curs.execute(db_change(
  1504. "select data from other where name = 'upload_acl'"
  1505. ))
  1506. num = 5
  1507. elif tool == 'many_upload':
  1508. curs.execute(db_change(
  1509. "select data from other where name = 'many_upload_acl'"
  1510. ))
  1511. num = 5
  1512. elif tool == 'vote':
  1513. if i == 0:
  1514. curs.execute(db_change(
  1515. 'select acl from vote where id = ? and user = ""'
  1516. ), [topic_num])
  1517. else:
  1518. curs.execute(db_change(
  1519. 'select data from other where name = "vote_acl"'
  1520. ))
  1521. num = None
  1522. elif tool == 'slow_edit':
  1523. curs.execute(db_change(
  1524. 'select data from other where name = "slow_edit_acl"'
  1525. ))
  1526. num = 'all'
  1527. elif tool == 'edit_bottom_compulsion':
  1528. curs.execute(db_change(
  1529. 'select data from other where name = "edit_bottom_compulsion_acl"'
  1530. ))
  1531. num = 'all'
  1532. else:
  1533. # tool == 'render'
  1534. if i == 0:
  1535. curs.execute(db_change(
  1536. "select data from acl where title = ? and type = 'view'"
  1537. ), [name])
  1538. else:
  1539. curs.execute(db_change("select data from other where name = 'all_view_acl'"))
  1540. num = 5
  1541. acl_data = curs.fetchall()
  1542. if not acl_data or acl_data[0][0] == '':
  1543. if tool == 'slow_edit' or tool == 'edit_bottom_compulsion':
  1544. acl_data = [['not_all']]
  1545. else:
  1546. acl_data = [['normal']]
  1547. except_ban_tool_list = ['render', 'topic_view']
  1548. if acl_data[0][0] != 'normal':
  1549. if not acl_data[0][0] in ['ban', 'ban_admin'] and not tool in except_ban_tool_list:
  1550. if get_ban == 1:
  1551. return 1
  1552. if acl_data[0][0] in ['all', 'ban']:
  1553. return 0
  1554. elif acl_data[0][0] == 'user':
  1555. if ip_or_user(ip) != 1:
  1556. return 0
  1557. elif acl_data[0][0] == 'admin':
  1558. if ip_or_user(ip) != 1:
  1559. if admin_check(num) == 1:
  1560. return 0
  1561. elif acl_data[0][0] == '50_edit':
  1562. if ip_or_user(ip) != 1:
  1563. if admin_check(num) == 1:
  1564. return 0
  1565. else:
  1566. curs.execute(db_change(
  1567. "select count(*) from history where ip = ?"
  1568. ), [ip])
  1569. count = curs.fetchall()
  1570. count = count[0][0] if count else 0
  1571. if count >= 50:
  1572. return 0
  1573. elif acl_data[0][0] == 'before':
  1574. if ip_or_user(ip) != 1:
  1575. if admin_check(num) == 1:
  1576. return 0
  1577. curs.execute(db_change(
  1578. "select ip from history where title = ? and ip = ?"
  1579. ), [name, ip])
  1580. if curs.fetchall():
  1581. return 0
  1582. elif acl_data[0][0] == '30_day' or acl_data[0][0] == '90_day':
  1583. if ip_or_user(ip) != 1:
  1584. if admin_check(num) == 1:
  1585. return 0
  1586. else:
  1587. curs.execute(db_change(
  1588. "select data from user_set where id = ? and name = 'date'"
  1589. ), [ip])
  1590. user_date = curs.fetchall()[0][0]
  1591. if acl_data[0][0] == '30_day':
  1592. time_1 = datetime.datetime.strptime(
  1593. user_date,
  1594. '%Y-%m-%d %H:%M:%S'
  1595. ) + datetime.timedelta(days = 30)
  1596. else:
  1597. time_1 = datetime.datetime.strptime(
  1598. user_date,
  1599. '%Y-%m-%d %H:%M:%S'
  1600. ) + datetime.timedelta(days = 90)
  1601. time_2 = datetime.datetime.strptime(
  1602. get_time(),
  1603. '%Y-%m-%d %H:%M:%S'
  1604. )
  1605. if time_2 > time_1:
  1606. return 0
  1607. elif acl_data[0][0] == 'email':
  1608. if ip_or_user(ip) != 1:
  1609. if admin_check(num) == 1:
  1610. return 0
  1611. else:
  1612. curs.execute(db_change(
  1613. "select data from user_set where id = ? and name = 'email'"
  1614. ), [ip])
  1615. if curs.fetchall():
  1616. return 0
  1617. elif acl_data[0][0] == 'owner':
  1618. if admin_check() == 1:
  1619. return 0
  1620. elif acl_data[0][0] == 'ban_admin':
  1621. if admin_check(1) == 1 or get_ban == 1:
  1622. return 0
  1623. elif acl_data[0][0] == 'not_all':
  1624. return 1
  1625. return 1
  1626. elif i == (end - 1):
  1627. if not tool in except_ban_tool_list:
  1628. if get_ban == 1:
  1629. return 1
  1630. if tool == 'topic':
  1631. curs.execute(db_change(
  1632. "select title from rd where code = ? and stop != ''"
  1633. ), [topic_num])
  1634. if curs.fetchall():
  1635. if admin_check(3, 'topic (code ' + topic_num + ')') == 1:
  1636. return 0
  1637. else:
  1638. return 1
  1639. else:
  1640. return 0
  1641. else:
  1642. return 0
  1643. return 1
  1644. def ban_check(ip = None, tool = ''):
  1645. curs = conn.cursor()
  1646. ip = ip_check() if not ip else ip
  1647. tool = '' if not tool else tool
  1648. if admin_check(None, None, ip) == 1:
  1649. return 0
  1650. curs.execute(db_change(
  1651. "update rb set ongoing = '' " + \
  1652. "where end < ? and end != '' and ongoing = '1'"
  1653. ), [get_time()])
  1654. conn.commit()
  1655. curs.execute(db_change("" + \
  1656. "select login, block from rb " + \
  1657. "where band = 'regex' and ongoing = '1'" + \
  1658. ""))
  1659. regex_d = curs.fetchall()
  1660. for test_r in regex_d:
  1661. g_regex = re.compile(test_r[1])
  1662. if g_regex.search(ip):
  1663. if tool == 'login':
  1664. if test_r[0] != 'O':
  1665. return 1
  1666. else:
  1667. return 1
  1668. curs.execute(db_change("" + \
  1669. "select login from rb " + \
  1670. "where block = ? and band = '' and ongoing = '1'" + \
  1671. "" + \
  1672. ""), [ip])
  1673. ban_d = curs.fetchall()
  1674. if ban_d:
  1675. if tool == 'login':
  1676. if ban_d[0][0] != 'O':
  1677. return 1
  1678. else:
  1679. return 1
  1680. return 0
  1681. def ip_pas(raw_ip, type_data = 0):
  1682. curs = conn.cursor()
  1683. end_ip = {}
  1684. return_data = 0
  1685. if type(raw_ip) != type([]):
  1686. get_ip = [raw_ip]
  1687. return_data = 1
  1688. else:
  1689. get_ip = raw_ip
  1690. curs.execute(db_change("select data from other where name = 'ip_view'"))
  1691. ip_view = curs.fetchall()
  1692. ip_view = ip_view[0][0] if ip_view else ''
  1693. ip_view = '' if admin_check(1) == 1 else ip_view
  1694. get_ip = list(set(get_ip))
  1695. for raw_ip in get_ip:
  1696. change_ip = 0
  1697. is_this_ip = ip_or_user(raw_ip)
  1698. if is_this_ip != 0 and ip_view != '':
  1699. try:
  1700. ip = ipaddress.ip_address(raw_ip)
  1701. if type(ip) == ipaddress.IPv6Address:
  1702. ip = ip.exploded
  1703. ip = re.sub(r':([^:]*):([^:]*)$', ':*:*', ip)
  1704. else:
  1705. ip = ip.exploded
  1706. ip = re.sub(r'\.([^.]*)\.([^.]*)$', '.*.*', ip)
  1707. # ip = hashlib.sha3_224(bytes(raw_ip, 'utf-8')).hexdigest()
  1708. # ip = ip[0:4] + '-' + ip[4:8] + '-' + ip[8:12] + '-' + ip[12:16]
  1709. change_ip = 1
  1710. except:
  1711. ip = raw_ip
  1712. else:
  1713. ip = raw_ip
  1714. if type_data == 0 and change_ip == 0:
  1715. if is_this_ip == 0:
  1716. ip = '<a href="/w/' + url_pas('user:' + raw_ip) + '">' + raw_ip + '</a>'
  1717. if admin_check('all', None, raw_ip) == 1:
  1718. ip = '<b>' + ip + '</b>'
  1719. curs.execute(db_change('select data from user_set where name = "user_title" and id = ?'), [raw_ip])
  1720. db_data = curs.fetchall()
  1721. if db_data:
  1722. ip = db_data[0][0] + ip
  1723. if ban_check(raw_ip) == 1:
  1724. ip = '<s>' + ip + '</s>'
  1725. if ban_check(raw_ip, 'login') == 1:
  1726. ip = '<i>' + ip + '</i>'
  1727. ip = ip + ' <a href="/user/' + url_pas(raw_ip) + '">(' + load_lang('tool') + ')</a>'
  1728. end_ip[raw_ip] = ip
  1729. if return_data == 1:
  1730. return end_ip[raw_ip]
  1731. else:
  1732. return end_ip
  1733. # Func-edit
  1734. def get_edit_text_bottom():
  1735. curs = conn.cursor()
  1736. b_text = ''
  1737. curs.execute(db_change('select data from other where name = "edit_bottom_text"'))
  1738. db_data= curs.fetchall()
  1739. if db_data and db_data[0][0] != '':
  1740. b_text = '' + \
  1741. db_data[0][0] + \
  1742. '<hr class="main_hr">' + \
  1743. ''
  1744. return b_text
  1745. def get_edit_text_bottom_check_box():
  1746. curs = conn.cursor()
  1747. cccb_text = ''
  1748. curs.execute(db_change('select data from other where name = "copyright_checkbox_text"'))
  1749. sql_d = curs.fetchall()
  1750. if sql_d and sql_d[0][0] != '':
  1751. cccb_text = '' + \
  1752. '<input type="checkbox" name="copyright_agreement" value="yes"> ' + sql_d[0][0] + \
  1753. '<hr class="main_hr">' + \
  1754. ''
  1755. return cccb_text
  1756. def do_edit_text_bottom_check_box_check(data):
  1757. curs = conn.cursor()
  1758. curs.execute(db_change('select data from other where name = "copyright_checkbox_text"'))
  1759. db_data = curs.fetchall()
  1760. if db_data and db_data[0][0] != '':
  1761. if data != 'yes':
  1762. return 1
  1763. return 0
  1764. def do_edit_send_check(data):
  1765. curs = conn.cursor()
  1766. curs.execute(db_change('select data from other where name = "edit_bottom_compulsion"'))
  1767. db_data = curs.fetchall()
  1768. if db_data and db_data[0][0] != '':
  1769. if acl_check(None, 'edit_bottom_compulsion') == 1:
  1770. if data == '':
  1771. return 1
  1772. return 0
  1773. def do_edit_slow_check():
  1774. curs = conn.cursor()
  1775. curs.execute(db_change("select data from other where name = 'slow_edit'"))
  1776. slow_edit = curs.fetchall()
  1777. if slow_edit and slow_edit[0][0] != '':
  1778. if acl_check(None, 'slow_edit') == 1:
  1779. slow_edit = int(number_check(slow_edit[0][0]))
  1780. curs.execute(db_change(
  1781. "select date from history where ip = ? order by date desc limit 1"
  1782. ), [ip_check()])
  1783. last_edit_data = curs.fetchall()
  1784. if last_edit_data:
  1785. last_edit_data = int(re.sub(' |:|-', '', last_edit_data[0][0]))
  1786. now_edit_data = int((
  1787. datetime.datetime.now() - datetime.timedelta(seconds = slow_edit)
  1788. ).strftime("%Y%m%d%H%M%S"))
  1789. if last_edit_data > now_edit_data:
  1790. return 1
  1791. return 0
  1792. def do_edit_filter(data):
  1793. curs = conn.cursor()
  1794. if admin_check(1) != 1:
  1795. curs.execute(db_change(
  1796. "select plus, plus_t from html_filter where kind = 'regex_filter' and plus != ''"
  1797. ))
  1798. for data_list in curs.fetchall():
  1799. match = re.compile(data_list[0], re.I)
  1800. if match.search(data):
  1801. ban_insert(
  1802. ip_check(),
  1803. '0' if data_list[1] == 'X' else data_list[1],
  1804. 'edit filter',
  1805. None,
  1806. 'tool:edit filter'
  1807. )
  1808. return 1
  1809. return 0
  1810. def do_title_length_check(name, check_type = 'document'):
  1811. curs = conn.cursor()
  1812. if check_type == 'topic':
  1813. curs.execute(db_change('select data from other where name = "title_topic_max_length"'))
  1814. db_data = curs.fetchall()
  1815. if db_data and db_data[0][0] != '':
  1816. db_data = int(number_check(db_data[0][0]))
  1817. if len(name) > db_data:
  1818. return 1
  1819. else:
  1820. curs.execute(db_change('select data from other where name = "title_max_length"'))
  1821. db_data = curs.fetchall()
  1822. if db_data and db_data[0][0] != '':
  1823. db_data = int(number_check(db_data[0][0]))
  1824. if len(name) > db_data:
  1825. return 1
  1826. return 0
  1827. # Func-insert
  1828. def do_add_thread(thread_code, thread_data, thread_top = '', thread_id = ''):
  1829. curs = conn.cursor()
  1830. if thread_id == '':
  1831. curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [thread_code])
  1832. db_data = curs.fetchall()
  1833. if db_data:
  1834. thread_id = str(int(db_data[0][0]) + 1)
  1835. else:
  1836. thread_id = '1'
  1837. curs.execute(db_change("insert into topic (id, data, date, ip, block, top, code) values (?, ?, ?, ?, ?, '', ?)"), [
  1838. thread_id,
  1839. thread_data,
  1840. get_time(),
  1841. ip_check(),
  1842. thread_top,
  1843. thread_code
  1844. ])
  1845. conn.commit()
  1846. def do_reload_recent_thread(topic_num, date, name = None, sub = None):
  1847. curs = conn.cursor()
  1848. curs.execute(db_change("select code from rd where code = ?"), [topic_num])
  1849. if curs.fetchall():
  1850. curs.execute(db_change("update rd set date = ? where code = ?"), [
  1851. date,
  1852. topic_num
  1853. ])
  1854. else:
  1855. curs.execute(db_change(
  1856. "insert into rd (title, sub, code, date, band, stop, agree, acl) values (?, ?, ?, ?, '', '', '', '')"
  1857. ), [
  1858. name,
  1859. sub,
  1860. topic_num,
  1861. date
  1862. ])
  1863. conn.commit()
  1864. def add_alarm(who, context):
  1865. curs = conn.cursor()
  1866. curs.execute(db_change(
  1867. 'insert into alarm (name, data, date) values (?, ?, ?)'
  1868. ), [who, context, get_time()])
  1869. conn.commit()
  1870. def add_user(user_name, user_pw, user_email = '', user_encode = ''):
  1871. curs = conn.cursor()
  1872. if user_encode == '':
  1873. user_pw_hash = pw_encode(user_pw)
  1874. curs.execute(db_change('select data from other where name = "encode"'))
  1875. data_encode = curs.fetchall()
  1876. data_encode = data_encode[0][0]
  1877. else:
  1878. user_pw_hash = user_pw
  1879. data_encode = user_encode
  1880. curs.execute(db_change("select id from user_set limit 1"))
  1881. if not curs.fetchall():
  1882. user_auth = 'owner'
  1883. else:
  1884. user_auth = 'user'
  1885. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'pw', ?)"), [
  1886. user_name,
  1887. user_pw_hash
  1888. ])
  1889. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'acl', ?)"), [
  1890. user_name,
  1891. user_auth
  1892. ])
  1893. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'date', ?)"), [
  1894. user_name,
  1895. get_time()
  1896. ])
  1897. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'encode', ?)"), [
  1898. user_name,
  1899. data_encode
  1900. ])
  1901. if user_email != '':
  1902. curs.execute(db_change("insert into user_set (name, id, data) values ('email', ?, ?)"), [
  1903. user_name,
  1904. user_email
  1905. ])
  1906. conn.commit()
  1907. def ua_plus(u_id, u_ip, u_agent, time):
  1908. curs = conn.cursor()
  1909. curs.execute(db_change("select data from other where name = 'ua_get'"))
  1910. rep_data = curs.fetchall()
  1911. if rep_data and rep_data[0][0] != '':
  1912. pass
  1913. else:
  1914. curs.execute(db_change(
  1915. "insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')"
  1916. ), [
  1917. u_id,
  1918. u_ip,
  1919. u_agent,
  1920. time
  1921. ])
  1922. conn.commit()
  1923. def ban_insert(name, end, why, login, blocker, type_d = None):
  1924. curs = conn.cursor()
  1925. now_time = get_time()
  1926. band = type_d if type_d else ''
  1927. curs.execute(db_change(
  1928. "update rb set ongoing = '' where end < ? and end != '' and ongoing = '1'"
  1929. ), [now_time])
  1930. curs.execute(db_change("" + \
  1931. "select block from rb " + \
  1932. "where ((end > ? and end != '') or end = '') and block = ? and " + \
  1933. "band = ? and ongoing = '1'" + \
  1934. ""), [now_time, name, band])
  1935. if curs.fetchall():
  1936. curs.execute(db_change(
  1937. "insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, ?)"
  1938. ), [
  1939. name,
  1940. 'release',
  1941. now_time,
  1942. blocker,
  1943. '',
  1944. band
  1945. ])
  1946. curs.execute(db_change(
  1947. "update rb set ongoing = '' where block = ? and band = ? and ongoing = '1'"
  1948. ), [name, band])
  1949. else:
  1950. login = 'O' if login != '' else ''
  1951. if end != '0':
  1952. end = int(number_check(end))
  1953. time = datetime.datetime.now()
  1954. plus = datetime.timedelta(seconds = end)
  1955. r_time = (time + plus).strftime("%Y-%m-%d %H:%M:%S")
  1956. else:
  1957. r_time = ''
  1958. curs.execute(db_change(
  1959. "insert into rb (block, end, today, blocker, why, band, ongoing, login) " + \
  1960. "values (?, ?, ?, ?, ?, ?, '1', ?)"
  1961. ), [
  1962. name,
  1963. r_time,
  1964. now_time,
  1965. blocker,
  1966. why,
  1967. band,
  1968. login
  1969. ])
  1970. conn.commit()
  1971. def history_plus(title, data, date, ip, send, leng, t_check = '', mode = ''):
  1972. curs = conn.cursor()
  1973. # 여기 좀 느린 듯
  1974. curs.execute(db_change('select data from other where name = "history_recording_off"'))
  1975. db_data = curs.fetchall()
  1976. if db_data and db_data[0][0] != '':
  1977. return 0
  1978. if mode == 'add':
  1979. curs.execute(db_change(
  1980. "select id from history where title = ? order by id + 0 asc limit 1"
  1981. ), [title])
  1982. id_data = curs.fetchall()
  1983. id_data = str(int(id_data[0][0]) - 1) if id_data else '0'
  1984. else:
  1985. curs.execute(db_change(
  1986. "select id from history where title = ? order by id + 0 desc limit 1"
  1987. ), [title])
  1988. id_data = curs.fetchall()
  1989. id_data = str(int(id_data[0][0]) + 1) if id_data else '1'
  1990. mode = mode if not re.search('^user:', title) else 'user'
  1991. send = re.sub(r'\(|\)|<|>', '', send)
  1992. send = send[:128] if len(send) > 128 else send
  1993. send = send + ' (' + t_check + ')' if t_check != '' else send
  1994. if mode != 'add' and mode != 'user':
  1995. curs.execute(db_change("select count(*) from rc where type = 'normal'"))
  1996. if curs.fetchall()[0][0] >= 200:
  1997. curs.execute(db_change(
  1998. "select id, title from rc where type = 'normal' order by date asc limit 1"
  1999. ))
  2000. rc_data = curs.fetchall()
  2001. if rc_data:
  2002. curs.execute(db_change(
  2003. 'delete from rc where id = ? and title = ? and type = "normal"'
  2004. ), [
  2005. rc_data[0][0],
  2006. rc_data[0][1]
  2007. ])
  2008. curs.execute(db_change(
  2009. "insert into rc (id, title, date, type) values (?, ?, ?, 'normal')"
  2010. ), [
  2011. id_data,
  2012. title,
  2013. date
  2014. ])
  2015. if mode != 'add':
  2016. curs.execute(db_change("select count(*) from rc where type = ?"), [mode])
  2017. if curs.fetchall()[0][0] >= 200:
  2018. curs.execute(db_change(
  2019. "select id, title from rc where type = ? order by date asc limit 1"
  2020. ), [mode])
  2021. rc_data = curs.fetchall()
  2022. if rc_data:
  2023. curs.execute(db_change(
  2024. 'delete from rc where id = ? and title = ? and type = ?'
  2025. ), [
  2026. rc_data[0][0],
  2027. rc_data[0][1],
  2028. mode
  2029. ])
  2030. curs.execute(db_change(
  2031. "insert into rc (id, title, date, type) values (?, ?, ?, ?)"
  2032. ), [
  2033. id_data,
  2034. title,
  2035. date,
  2036. mode
  2037. ])
  2038. curs.execute(db_change(
  2039. "insert into history (id, title, data, date, ip, send, leng, hide, type) " + \
  2040. "values (?, ?, ?, ?, ?, ?, ?, '', ?)"
  2041. ), [
  2042. id_data,
  2043. title,
  2044. data,
  2045. date,
  2046. ip,
  2047. send,
  2048. leng,
  2049. mode
  2050. ])
  2051. data_set_exist = '' if t_check != 'delete' else '1'
  2052. curs.execute(db_change("select doc_name from data_set where doc_name = ? and set_name = 'last_edit'"), [title])
  2053. db_data = curs.fetchall()
  2054. if db_data:
  2055. curs.execute(db_change("update data_set set set_data = ?, doc_rev = ? where doc_name = ? and set_name = 'last_edit'"), [date, data_set_exist, title])
  2056. else:
  2057. curs.execute(db_change("insert into data_set (doc_name, doc_rev, set_name, set_data) values (?, ?, 'last_edit', ?)"), [title, data_set_exist, date])
  2058. # Func-error
  2059. def re_error(data):
  2060. curs = conn.cursor()
  2061. conn.commit()
  2062. if data == '/ban':
  2063. if ban_check() == 1:
  2064. end = '<div id="opennamu_get_user_info">' + ip_check() + '</div>'
  2065. else:
  2066. end = '<ul class="opennamu_ul"><li>' + load_lang('authority_error') + '</li></ul>'
  2067. return easy_minify(flask.render_template(skin_check(),
  2068. imp = [load_lang('error'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  2069. data = '<h2>' + load_lang('error') + '</h2>' + end,
  2070. menu = 0
  2071. )), 401
  2072. else:
  2073. num = int(number_check(data.replace('/error/', '')))
  2074. if num == 1:
  2075. data = load_lang('no_login_error')
  2076. elif num == 2:
  2077. data = load_lang('no_exist_user_error')
  2078. elif num == 3:
  2079. data = load_lang('authority_error')
  2080. elif num == 4:
  2081. data = load_lang('no_admin_block_error')
  2082. elif num == 5:
  2083. data = load_lang('error_skin_set')
  2084. elif num == 6:
  2085. data = load_lang('same_id_exist_error')
  2086. elif num == 7:
  2087. data = load_lang('long_id_error')
  2088. elif num == 8:
  2089. data = load_lang('id_char_error') + ' <a href="/name_filter">(' + load_lang('id_filter_list') + ')</a>'
  2090. elif num == 9:
  2091. data = load_lang('file_exist_error')
  2092. elif num == 10:
  2093. data = load_lang('password_error')
  2094. elif num == 11:
  2095. data = load_lang('topic_long_error')
  2096. elif num == 12:
  2097. data = load_lang('email_error')
  2098. elif num == 13:
  2099. data = load_lang('recaptcha_error')
  2100. elif num == 14:
  2101. data = load_lang('file_extension_error') + ' <a href="/extension_filter">(' + load_lang('extension_filter_list') + ')</a>'
  2102. elif num == 15:
  2103. data = load_lang('edit_record_error')
  2104. elif num == 16:
  2105. data = load_lang('same_file_error')
  2106. elif num == 17:
  2107. curs.execute(db_change('select data from other where name = "upload"'))
  2108. db_data = curs.fetchall()
  2109. file_max = int(number_check(db_data[0][0])) if db_data and db_data[0][0] != '' else '2'
  2110. data = load_lang('file_capacity_error') + file_max
  2111. elif num == 18:
  2112. data = load_lang('email_send_error')
  2113. elif num == 19:
  2114. data = load_lang('move_error')
  2115. elif num == 20:
  2116. data = load_lang('password_diffrent_error')
  2117. elif num == 21:
  2118. data = load_lang('edit_filter_error')
  2119. elif num == 22:
  2120. data = load_lang('file_name_error')
  2121. elif num == 23:
  2122. data = load_lang('regex_error')
  2123. elif num == 24:
  2124. curs.execute(db_change("select data from other where name = 'slow_edit'"))
  2125. db_data = curs.fetchall()
  2126. db_data = '' if not db_data else db_data[0][0]
  2127. data = load_lang('fast_edit_error') + db_data
  2128. elif num == 25:
  2129. data = load_lang('too_many_dec_error')
  2130. elif num == 26:
  2131. data = load_lang('application_not_found')
  2132. elif num == 27:
  2133. data = load_lang("invalid_password_error")
  2134. elif num == 28:
  2135. data = load_lang('watchlist_overflow_error')
  2136. elif num == 29:
  2137. data = load_lang('copyright_disagreed')
  2138. elif num == 30:
  2139. data = load_lang('ie_wrong_callback')
  2140. elif num == 33:
  2141. data = load_lang('restart_fail_error')
  2142. elif num == 34:
  2143. data = load_lang("update_error") + ' <a href="https://github.com/opennamu/opennamu">(Github)</a>'
  2144. elif num == 35:
  2145. data = load_lang('same_email_error')
  2146. elif num == 36:
  2147. data = load_lang('input_email_error')
  2148. elif num == 37:
  2149. data = load_lang('error_edit_send_request')
  2150. elif num == 38:
  2151. curs.execute(db_change("select data from other where name = 'title_max_length'"))
  2152. db_data = curs.fetchall()
  2153. db_data = '' if not db_data else db_data[0][0]
  2154. data = load_lang('error_title_length_too_long') + db_data
  2155. elif num == 39:
  2156. curs.execute(db_change("select data from other where name = 'title_topic_max_length'"))
  2157. db_data = curs.fetchall()
  2158. db_data = '' if not db_data else db_data[0][0]
  2159. data = load_lang('error_title_length_too_long') + db_data
  2160. elif num == 40:
  2161. curs.execute(db_change("select data from other where name = 'password_min_length'"))
  2162. db_data = curs.fetchall()
  2163. if db_data and db_data[0][0] != '':
  2164. password_min_length = db_data[0][0]
  2165. else:
  2166. password_min_length = ''
  2167. data = load_lang('error_password_length_too_short') + password_min_length
  2168. else:
  2169. data = '???'
  2170. if num == 5:
  2171. if flask.request.path != '/skin_set':
  2172. data += '<br>' + load_lang('error_skin_set_old') + ' <a href="/skin_set">(' + load_lang('go') + ')</a>'
  2173. title = load_lang('skin_set')
  2174. tool = [['change', load_lang('user_setting')], ['change/skin_set/main', load_lang('main_skin_set')]]
  2175. load_skin_set = ''
  2176. return easy_minify(flask.render_template(skin_check(),
  2177. imp = [title, wiki_set(), wiki_custom(), wiki_css([0, 0])],
  2178. data = '' + \
  2179. '<div id="main_skin_set">' + \
  2180. '<h2>' + load_lang('error') + '</h2>' + \
  2181. '<ul class="opennamu_ul">' + \
  2182. '<li>' + data + '</a></li>' + \
  2183. '</ul>' + \
  2184. '</div>' + \
  2185. load_skin_set,
  2186. menu = tool
  2187. ))
  2188. else:
  2189. return easy_minify(flask.render_template(skin_check(),
  2190. imp = [load_lang('error'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  2191. data = '' + \
  2192. '<h2>' + load_lang('error') + '</h2>' + \
  2193. '<ul class="opennamu_ul">' + \
  2194. '<li>' + data + '</li>' + \
  2195. '</ul>' + \
  2196. '',
  2197. menu = 0
  2198. )), 400