func.py 108 KB

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