func.py 91 KB

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