func.py 109 KB

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