func.py 107 KB

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