func.py 108 KB

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