func.py 109 KB

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