func.py 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141
  1. # Init
  2. import os
  3. import sys
  4. import platform
  5. import json
  6. import smtplib
  7. import zipfile
  8. import shutil
  9. import logging
  10. import random
  11. import email.mime.text
  12. import email.utils
  13. import email.header
  14. import urllib.request
  15. # Init-Version
  16. version_list = json.loads(open('version.json', encoding = 'utf8').read())
  17. print('Version : ' + version_list['beta']['r_ver'])
  18. print('DB set version : ' + version_list['beta']['c_ver'])
  19. print('Skin set version : ' + version_list['beta']['s_ver'])
  20. print('----')
  21. # Init-PIP_Install
  22. data_up_date = 1
  23. if os.path.exists(os.path.join('data', 'version.json')):
  24. data_load_ver = open(os.path.join('data', 'version.json'), encoding = 'utf8').read()
  25. if data_load_ver == version_list['beta']['r_ver']:
  26. data_up_date = 0
  27. if data_up_date == 1:
  28. with open(os.path.join('data', 'version.json'), 'w', encoding = 'utf8') as f:
  29. f.write(version_list['beta']['r_ver'])
  30. if platform.system() in ('Linux', 'Windows'):
  31. if platform.python_implementation() == 'PyPy':
  32. os.system(
  33. 'pypy' + ('3' if platform.system() != 'Windows' else '') + ' ' + \
  34. '-m pip install --upgrade --user -r requirements.txt'
  35. )
  36. else:
  37. os.system(
  38. 'python' + ('3' if platform.system() != 'Windows' else '') + ' ' + \
  39. '-m pip install --upgrade --user -r requirements.txt'
  40. )
  41. print('----')
  42. try:
  43. os.execl(sys.executable, sys.executable, *sys.argv)
  44. except:
  45. pass
  46. try:
  47. os.execl(sys.executable, '"' + sys.executable + '"', *sys.argv)
  48. except:
  49. print('Error : restart failed')
  50. raise
  51. else:
  52. print('Error : automatic installation is not supported.')
  53. print('Help : try "python3 -m pip install -r requirements.txt"')
  54. else:
  55. print('PIP check pass')
  56. print('----')
  57. # Init-Load
  58. from .func_mark import *
  59. from diff_match_patch import diff_match_patch
  60. import netius.servers
  61. import waitress
  62. import werkzeug.routing
  63. import werkzeug.debug
  64. import flask
  65. import requests
  66. import pymysql
  67. if sys.version_info < (3, 6):
  68. import sha3
  69. # Init-Global
  70. global_lang = {}
  71. global_wiki_set = {}
  72. global_db_set = ''
  73. conn = ''
  74. # Func
  75. # Func-main
  76. def load_conn(data):
  77. global conn
  78. conn = data
  79. def do_db_set(db_set):
  80. global global_db_set
  81. global_db_set = db_set
  82. # Func-init
  83. def get_init_set_list(need = 'all'):
  84. init_set_list = {
  85. 'host' : {
  86. 'display' : 'Host',
  87. 'require' : 'conv',
  88. 'default' : '0.0.0.0'
  89. }, 'port' : {
  90. 'display' : 'Port',
  91. 'require' : 'conv',
  92. 'default' : '3000'
  93. }, 'language' : {
  94. 'display' : 'Language',
  95. 'require' : 'select',
  96. 'default' : 'ko-KR',
  97. 'list' : ['ko-KR', 'en-US']
  98. }, 'markup' : {
  99. 'display' : 'Markup',
  100. 'require' : 'select',
  101. 'default' : 'namumark',
  102. 'list' : ['namumark', 'markdown', 'custom', 'raw']
  103. }, 'encode' : {
  104. 'display' : 'Encryption method',
  105. 'require' : 'select',
  106. 'default' : 'sha3',
  107. 'list' : ['sha3', 'sha3-512']
  108. }
  109. }
  110. return init_set_list
  111. class get_db_connect_old:
  112. def __init__(self, db_set):
  113. self.db_set = db_set
  114. self.conn = ''
  115. def db_load(self):
  116. if self.db_set['type'] == 'sqlite':
  117. self.conn = sqlite3.connect(
  118. self.db_set['name'] + '.db',
  119. check_same_thread = False,
  120. isolation_level = None
  121. )
  122. self.conn.execute('pragma journal_mode = wal')
  123. else:
  124. self.conn = pymysql.connect(
  125. host = self.db_set['mysql_host'],
  126. user = self.db_set['mysql_user'],
  127. password = self.db_set['mysql_pw'],
  128. charset = 'utf8mb4',
  129. port = int(self.db_set['mysql_port']),
  130. )
  131. curs = self.conn.cursor()
  132. try:
  133. curs.execute(db_change(
  134. 'create database ' + self.db_set['name'] + ' ' + \
  135. 'default character set utf8mb4;'
  136. ))
  137. except:
  138. pass
  139. self.conn.select_db(self.db_set['name'])
  140. load_conn(self.conn)
  141. return self.conn
  142. def db_get(self):
  143. # if self.db_set['type'] != 'sqlite':
  144. # self.conn.ping(reconnect = True)
  145. return self.conn
  146. class get_db_connect:
  147. # 임시 DB 커넥션 동작 구조
  148. # Init 파트
  149. # DB 커넥트(get_db_connect_old) -> func.py로 conn 넘겨줌
  150. # route 파트
  151. # DB 새로 커넥트 -> func.py에서 쓰던 conn은 conn_sub로 보관 ->
  152. # func.py로 conn 넘겨줌 -> 모든 라우터 과정이 끝나면 conn_sub를 다시 func.py에 conn으로 넘겨줌 ->
  153. # DB 커넥트 종료
  154. def __init__(self):
  155. global global_db_set
  156. global conn
  157. self.conn_sub = conn
  158. self.db_set = global_db_set
  159. def __enter__(self):
  160. if self.db_set['type'] == 'sqlite':
  161. self.conn = sqlite3.connect(
  162. self.db_set['name'] + '.db',
  163. check_same_thread = False,
  164. isolation_level = None
  165. )
  166. self.conn.execute('pragma journal_mode = wal')
  167. else:
  168. self.conn = pymysql.connect(
  169. host = self.db_set['mysql_host'],
  170. user = self.db_set['mysql_user'],
  171. password = self.db_set['mysql_pw'],
  172. charset = 'utf8mb4',
  173. port = int(self.db_set['mysql_port']),
  174. )
  175. curs = self.conn.cursor()
  176. try:
  177. curs.execute(db_change(
  178. 'create database ' + self.db_set['name'] + ' ' + \
  179. 'default character set utf8mb4;'
  180. ))
  181. except:
  182. pass
  183. self.conn.select_db(self.db_set['name'])
  184. load_conn(self.conn)
  185. return self.conn
  186. def __exit__(self, exc_type, exc_value, traceback):
  187. load_conn(self.conn_sub)
  188. self.conn.close()
  189. class class_check_json:
  190. def do_check_set_json():
  191. if os.getenv('NAMU_DB') or os.getenv('NAMU_DB_TYPE'):
  192. set_data = {}
  193. set_data['db'] = os.getenv('NAMU_DB') if os.getenv('NAMU_DB') else 'data'
  194. set_data['db_type'] = os.getenv('NAMU_DB_TYPE') if os.getenv('NAMU_DB_TYPE') else 'sqlite'
  195. else:
  196. if os.path.exists(os.path.join('data', 'set.json')):
  197. db_set_list = ['db', 'db_type']
  198. set_data = json.loads(open(
  199. os.path.join('data', 'set.json'),
  200. encoding = 'utf8'
  201. ).read())
  202. for i in db_set_list:
  203. if not i in set_data:
  204. os.remove(os.path.join('data', 'set.json'))
  205. break
  206. if not os.path.exists(os.path.join('data', 'set.json')):
  207. set_data = {}
  208. normal_db_type = ['sqlite', 'mysql']
  209. print('DB type (' + normal_db_type[0] + ') [' + ', '.join(normal_db_type) + '] : ', end = '')
  210. data_get = str(input())
  211. if data_get == '' or not data_get in normal_db_type:
  212. set_data['db_type'] = 'sqlite'
  213. else:
  214. set_data['db_type'] = data_get
  215. all_src = []
  216. if set_data['db_type'] == 'sqlite':
  217. for i_data in os.listdir("."):
  218. f_src = re.search(r"(.+)\.db$", i_data)
  219. if f_src:
  220. all_src += [f_src.group(1)]
  221. print('DB name (data) [' + ', '.join(all_src) + '] : ', end = '')
  222. data_get = str(input())
  223. if data_get == '':
  224. set_data['db'] = 'data'
  225. else:
  226. set_data['db'] = data_get
  227. with open(os.path.join('data', 'set.json'), 'w', encoding = 'utf8') as f:
  228. f.write(json.dumps(set_data))
  229. print('DB name : ' + set_data['db'])
  230. print('DB type : ' + set_data['db_type'])
  231. data_db_set = {}
  232. data_db_set['name'] = set_data['db']
  233. data_db_set['type'] = set_data['db_type']
  234. return data_db_set
  235. def do_check_mysql_json(data_db_set):
  236. if os.path.exists(os.path.join('data', 'mysql.json')):
  237. db_set_list = ['user', 'password', 'host', 'port']
  238. set_data = json.loads(
  239. open(
  240. os.path.join('data', 'mysql.json'),
  241. encoding = 'utf8'
  242. ).read()
  243. )
  244. for i in db_set_list:
  245. if not i in set_data:
  246. os.remove(os.path.join('data', 'mysql.json'))
  247. break
  248. set_data_mysql = set_data
  249. if not os.path.exists(os.path.join('data', 'mysql.json')):
  250. set_data_mysql = {}
  251. print('DB user ID : ', end = '')
  252. set_data_mysql['user'] = str(input())
  253. print('DB password : ', end = '')
  254. set_data_mysql['password'] = str(input())
  255. print('DB host (localhost) : ', end = '')
  256. set_data_mysql['host'] = str(input())
  257. if set_data_mysql['host'] == '':
  258. set_data_mysql['host'] = 'localhost'
  259. print('DB port (3306) : ', end = '')
  260. set_data_mysql['port'] = str(input())
  261. if set_data_mysql['port'] == '':
  262. set_data_mysql['port'] = '3306'
  263. with open(
  264. os.path.join('data', 'mysql.json'),
  265. 'w',
  266. encoding = 'utf8'
  267. ) as f:
  268. f.write(json.dumps(set_data_mysql))
  269. data_db_set['mysql_user'] = set_data_mysql['user']
  270. data_db_set['mysql_pw'] = set_data_mysql['password']
  271. if 'host' in set_data_mysql:
  272. data_db_set['mysql_host'] = set_data_mysql['host']
  273. else:
  274. data_db_set['mysql_host'] = 'localhost'
  275. if 'port' in set_data_mysql:
  276. data_db_set['mysql_port'] = set_data_mysql['port']
  277. else:
  278. data_db_set['mysql_port'] = '3306'
  279. return data_db_set
  280. def __init__(self):
  281. self.data_db_set = {}
  282. def __new__(self):
  283. self.data_db_set = self.do_check_set_json()
  284. if self.data_db_set['type'] == 'mysql':
  285. self.data_db_set = self.do_check_mysql_json(self.data_db_set)
  286. return self.data_db_set
  287. def update(ver_num, set_data):
  288. curs = conn.cursor()
  289. print('----')
  290. # 업데이트 하위 호환 유지 함수
  291. if ver_num < 3160027:
  292. print('Add init set')
  293. set_init()
  294. if ver_num < 3170002:
  295. curs.execute(db_change("select html from html_filter where kind = 'extension'"))
  296. if not curs.fetchall():
  297. for i in ['jpg', 'jpeg', 'png', 'gif', 'webp']:
  298. curs.execute(db_change(
  299. "insert into html_filter (html, kind) values (?, 'extension')"
  300. ), [i])
  301. if ver_num < 3170400:
  302. curs.execute(db_change("select title, sub, code from topic where id = '1'"))
  303. for i in curs.fetchall():
  304. curs.execute(db_change(
  305. "update topic set code = ? where title = ? and sub = ?"
  306. ), [
  307. i[2],
  308. i[0],
  309. i[1]
  310. ])
  311. curs.execute(db_change(
  312. "update rd set code = ? where title = ? and sub = ?"
  313. ), [
  314. i[2],
  315. i[0],
  316. i[1]
  317. ])
  318. if ver_num < 3171800:
  319. curs.execute(db_change("select data from other where name = 'recaptcha'"))
  320. change_rec = curs.fetchall()
  321. if change_rec and change_rec[0][0] != '':
  322. new_rec = re.search(r'data-sitekey="([^"]+)"', change_rec[0][0])
  323. if new_rec:
  324. curs.execute(db_change(
  325. "update other set data = ? where name = 'recaptcha'"
  326. ), [new_rec.group(1)])
  327. else:
  328. curs.execute(db_change("update other set data = '' where name = 'recaptcha'"))
  329. curs.execute(db_change("update other set data = '' where name = 'sec_re'"))
  330. if ver_num < 3172800 and \
  331. set_data['db_type'] == 'mysql':
  332. get_data_mysql = json.loads(open('data/mysql.json', encoding = 'utf8').read())
  333. with open('data/mysql.json', 'w') as f:
  334. f.write('{ "user" : "' + get_data_mysql['user'] + '", "password" : "' + get_data_mysql['password'] + '", "host" : "localhost" }')
  335. if ver_num < 3183603:
  336. curs.execute(db_change("select block from ban where band = 'O'"))
  337. for i in curs.fetchall():
  338. curs.execute(db_change(
  339. "update ban set block = ?, band = 'regex' where block = ? and band = 'O'"
  340. ), [
  341. '^' + i[0].replace('.', '\\.'),
  342. i[0]
  343. ])
  344. curs.execute(db_change("select block from rb where band = 'O'"))
  345. for i in curs.fetchall():
  346. curs.execute(db_change(
  347. "update rb set block = ?, band = 'regex' where block = ? and band = 'O'"
  348. ), [
  349. '^' + i[0].replace('.', '\\.'),
  350. i[0]
  351. ])
  352. if ver_num < 3190201:
  353. today_time = get_time()
  354. curs.execute(db_change("select block, end, why, band, login from ban"))
  355. for i in curs.fetchall():
  356. curs.execute(db_change(
  357. "insert into rb (block, end, today, why, band, login, ongoing) " + \
  358. "values (?, ?, ?, ?, ?, ?, ?)"
  359. ), [
  360. i[0],
  361. i[1],
  362. today_time,
  363. i[2],
  364. i[3],
  365. i[4],
  366. '1'
  367. ])
  368. if ver_num < 3191301:
  369. curs.execute(db_change('' + \
  370. 'select id, title, date from history ' + \
  371. 'where not title like "user:%" ' + \
  372. 'order by date desc ' + \
  373. 'limit 50' + \
  374. ''))
  375. data_list = curs.fetchall()
  376. for get_data in data_list:
  377. curs.execute(db_change(
  378. "insert into rc (id, title, date, type) values (?, ?, ?, 'normal')"
  379. ), [
  380. get_data[0],
  381. get_data[1],
  382. get_data[2]
  383. ])
  384. if ver_num < 3202400:
  385. curs.execute(db_change("select data from other where name = 'update'"))
  386. get_data = curs.fetchall()
  387. if get_data and get_data[0][0] == 'master':
  388. curs.execute(db_change("update other set data = 'beta' where name = 'update'"), [])
  389. if ver_num < 3202600:
  390. curs.execute(db_change("select name, regex, sub from filter"))
  391. for i in curs.fetchall():
  392. curs.execute(db_change(
  393. "insert into html_filter (html, kind, plus, plus_t) " + \
  394. "values (?, 'regex_filter', ?, ?)"
  395. ), [
  396. i[0],
  397. i[1],
  398. i[2]
  399. ])
  400. curs.execute(db_change("select title, link, icon from inter"))
  401. for i in curs.fetchall():
  402. curs.execute(db_change(
  403. "insert into html_filter (html, kind, plus, plus_t) " + \
  404. "values (?, 'inter_wiki', ?, ?)"), [
  405. i[0],
  406. i[1],
  407. i[2]
  408. ])
  409. if ver_num < 3203400:
  410. curs.execute(db_change("select user, css from custom"))
  411. for i in curs.fetchall():
  412. curs.execute(db_change(
  413. "insert into user_set (name, id, data) values ('custom_css', ?, ?)"
  414. ), [
  415. re.sub(r' \(head\)$', '', i[0]),
  416. i[1]
  417. ])
  418. if ver_num < 3205500:
  419. curs.execute(db_change("select title, decu, dis, view, why from acl"))
  420. for i in curs.fetchall():
  421. curs.execute(db_change(
  422. "insert into acl (title, data, type) values (?, ?, ?)"
  423. ), [i[0], i[1], 'decu'])
  424. curs.execute(db_change(
  425. "insert into acl (title, data, type) values (?, ?, ?)"
  426. ), [i[0], i[2], 'dis'])
  427. curs.execute(db_change(
  428. "insert into acl (title, data, type) values (?, ?, ?)"
  429. ), [i[0], i[3], 'view'])
  430. curs.execute(db_change(
  431. "insert into acl (title, data, type) values (?, ?, ?)"
  432. ), [i[0], i[4], 'why'])
  433. if ver_num < 3300101:
  434. # 캐시 초기화
  435. curs.execute(db_change('delete from cache_data'))
  436. if ver_num < 3300301:
  437. # regex_filter 오류 해결
  438. curs.execute(db_change(
  439. 'delete from html_filter where kind = "regex_filter" and html is null'
  440. ))
  441. if ver_num < 3302302:
  442. # user이랑 user_set 테이블의 통합
  443. curs.execute(db_change('select id, pw, acl, date, encode from user'))
  444. for i in curs.fetchall():
  445. curs.execute(db_change(
  446. "insert into user_set (name, id, data) values (?, ?, ?)"
  447. ), ['pw', i[0], i[1]])
  448. curs.execute(db_change(
  449. "insert into user_set (name, id, data) values (?, ?, ?)"
  450. ), ['acl', i[0], i[2]])
  451. curs.execute(db_change(
  452. "insert into user_set (name, id, data) values (?, ?, ?)"
  453. ), ['date', i[0], i[3]])
  454. curs.execute(db_change(
  455. "insert into user_set (name, id, data) values (?, ?, ?)"
  456. ), ['encode', i[0], i[4]])
  457. if ver_num < 3400101:
  458. # user_set이랑 user_application 테이블의 통합
  459. curs.execute(db_change('' + \
  460. 'select id, pw, date, encode, question, answer, ip, ua, email ' + \
  461. 'from user_application' + \
  462. ''))
  463. for i in curs.fetchall():
  464. sql_data = {}
  465. sql_data['id'] = i[0]
  466. sql_data['pw'] = i[1]
  467. sql_data['date'] = i[2]
  468. sql_data['encode'] = i[3]
  469. sql_data['question'] = i[4]
  470. sql_data['answer'] = i[5]
  471. sql_data['ip'] = i[6]
  472. sql_data['ua'] = i[7]
  473. sql_data['email'] = i[8]
  474. curs.execute(db_change(
  475. "insert into user_set (name, id, data) values (?, ?, ?)"
  476. ), ['application', i[0], json.dumps(sql_data)])
  477. if ver_num < 3500105:
  478. curs.execute(db_change(
  479. 'delete from acl where title like "file:%" and data = "admin" and type like "decu%"'
  480. ))
  481. if ver_num < 3500106:
  482. curs.execute(db_change("select data from other where name = 'domain'"))
  483. db_data = curs.fetchall()
  484. if db_data and db_data[0][0] != '':
  485. db_data = db_data[0][0]
  486. db_data = re.match(r'[^/]+\/\/([^/]+)', db_data)
  487. if db_data:
  488. db_data = db_data.group(1)
  489. curs.execute(db_change(
  490. "update other set data = ? where name = 'domain'"
  491. ), [
  492. db_data
  493. ])
  494. else:
  495. curs.execute(db_change(
  496. "update other set data = '' where name = 'domain'"
  497. ))
  498. conn.commit()
  499. # 아이피 상태인 이메일 제거 예정
  500. print('Update completed')
  501. def set_init_always(ver_num):
  502. curs = conn.cursor()
  503. curs.execute(db_change('delete from other where name = "ver"'))
  504. curs.execute(db_change('insert into other (name, data) values ("ver", ?)'), [ver_num])
  505. curs.execute(db_change('delete from alist where name = "owner"'))
  506. curs.execute(db_change('insert into alist (name, acl) values ("owner", "owner")'))
  507. if not os.path.exists(load_image_url()):
  508. os.makedirs(load_image_url())
  509. conn.commit()
  510. def set_init():
  511. curs = conn.cursor()
  512. # 초기값 설정 함수
  513. curs.execute(db_change("select html from html_filter where kind = 'email'"))
  514. if not curs.fetchall():
  515. for i in ['naver.com', 'gmail.com', 'daum.net', 'kakao.com']:
  516. curs.execute(db_change(
  517. "insert into html_filter (html, kind, plus, plus_t) values (?, 'email', '', '')"
  518. ), [i])
  519. curs.execute(db_change("select html from html_filter where kind = 'extension'"))
  520. if not curs.fetchall():
  521. for i in ['jpg', 'jpeg', 'png', 'gif', 'webp']:
  522. curs.execute(db_change(
  523. "insert into html_filter (html, kind, plus, plus_t) values (?, 'extension', '', '')"
  524. ), [i])
  525. curs.execute(db_change(
  526. 'select data from other ' + \
  527. 'where name = "smtp_server" or name = "smtp_port" or name = "smtp_security"'
  528. ))
  529. if not curs.fetchall():
  530. for i in [
  531. ['smtp_server', 'smtp.gmail.com'],
  532. ['smtp_port', '587'],
  533. ['smtp_security', 'starttls']
  534. ]:
  535. curs.execute(db_change(
  536. "insert into other (name, data) values (?, ?)"
  537. ), [i[0], i[1]])
  538. curs.execute(db_change('select data from other where name = "key"'))
  539. rep_data = curs.fetchall()
  540. if not rep_data:
  541. curs.execute(db_change('insert into other (name, data) values ("key", ?)'), [load_random_key()])
  542. curs.execute(db_change('select data from other where name = "count_all_title"'))
  543. if not curs.fetchall():
  544. curs.execute(db_change('insert into other (name, data) values ("count_all_title", "0")'))
  545. conn.commit()
  546. # Func-simple
  547. ## Func-simple-without_DB
  548. def get_default_admin_group():
  549. return ['owner', 'ban']
  550. def get_user_title_list():
  551. # default
  552. user_title = {
  553. '' : load_lang('default'),
  554. '🌳' : '🌳 namu',
  555. }
  556. # admin
  557. if admin_check('all') == 1:
  558. user_title['✅'] = '✅ admin'
  559. return user_title
  560. def load_random_key(long = 128):
  561. return ''.join(
  562. random.choice(
  563. "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  564. ) for i in range(long)
  565. )
  566. def http_warning():
  567. return '''
  568. <div id="opennamu_http_warning_text"></div>
  569. <span style="display: none;" id="opennamu_http_warning_text_lang">''' + load_lang('http_warning') + '''</span>
  570. <script>opennamu_do_warning_text();</script>
  571. '''
  572. def next_fix(link, num, page, end = 50):
  573. list_data = ''
  574. if num == 1:
  575. if len(page) == end:
  576. list_data += '' + \
  577. '<hr class="main_hr">' + \
  578. '<a href="' + link + str(num + 1) + '">(' + load_lang('next') + ')</a>' + \
  579. ''
  580. elif len(page) != end:
  581. list_data += '' + \
  582. '<hr class="main_hr">' + \
  583. '<a href="' + link + str(num - 1) + '">(' + load_lang('previous') + ')</a>' + \
  584. ''
  585. else:
  586. list_data += '' + \
  587. '<hr class="main_hr">' + \
  588. '<a href="' + link + str(num - 1) + '">(' + load_lang('previous') + ')</a> <a href="' + link + str(num + 1) + '">(' + load_lang('next') + ')</a>' + \
  589. ''
  590. return list_data
  591. def leng_check(A, B):
  592. # B -> new
  593. # A -> old
  594. return '0' if A == B else (('-' + str(A - B)) if A > B else ('+' + str(B - A)))
  595. def number_check(data):
  596. try:
  597. int(data)
  598. return data
  599. except:
  600. return '1'
  601. def check_int(data):
  602. try:
  603. int(data)
  604. return data
  605. except:
  606. return ''
  607. def redirect(data = '/'):
  608. return flask.redirect(load_domain('full') + data)
  609. def get_acl_list(type_d = 'normal'):
  610. if type_d == 'user':
  611. return ['', 'user', 'all']
  612. else:
  613. return ['', 'all', 'user', 'admin', 'owner', '50_edit', 'email', 'ban', 'before', '30_day', 'ban_admin', 'not_all']
  614. ## Func-simple-with_DB
  615. def load_image_url():
  616. curs = conn.cursor()
  617. curs.execute(db_change('select data from other where name = "image_where"'))
  618. image_where = curs.fetchall()
  619. image_where = image_where[0][0] if image_where else os.path.join('data', 'images')
  620. return image_where
  621. def load_domain(data_type = 'normal'):
  622. curs = conn.cursor()
  623. domain = ''
  624. if data_type == 'full':
  625. curs.execute(db_change("select data from other where name = 'http_select'"))
  626. db_data = curs.fetchall()
  627. domain += db_data[0][0] if db_data and db_data[0][0] != '' else 'http'
  628. domain += '://'
  629. curs.execute(db_change("select data from other where name = 'domain'"))
  630. db_data = curs.fetchall()
  631. domain += db_data[0][0] if db_data and db_data[0][0] != '' else flask.request.host
  632. domain += '/'
  633. else:
  634. curs.execute(db_change("select data from other where name = 'domain'"))
  635. db_data = curs.fetchall()
  636. domain += db_data[0][0] if db_data and db_data[0][0] != '' else flask.request.host
  637. return domain
  638. def edit_button(editor_display = '0'):
  639. curs = conn.cursor()
  640. insert_list = []
  641. curs.execute(db_change("select html, plus from html_filter where kind = 'edit_top'"))
  642. db_data = curs.fetchall()
  643. for get_data in db_data:
  644. insert_list += [[get_data[1], get_data[0]]]
  645. data = ''
  646. for insert_data in insert_list:
  647. data += '' + \
  648. '<a href="' + \
  649. 'javascript:do_insert_data(\'textarea_edit_view\', \'' + insert_data[0] + '\', ' + editor_display + ')' + \
  650. '">(' + insert_data[1] + ')</a> ' + \
  651. ''
  652. data += (' ' if data != '' else '') + '<a href="/edit_top">(' + load_lang('add') + ')</a>'
  653. data += '<hr class="main_hr">'
  654. return data
  655. def ip_warning():
  656. curs = conn.cursor()
  657. if ip_or_user() != 0:
  658. curs.execute(db_change('select data from other where name = "no_login_warning"'))
  659. data = curs.fetchall()
  660. if data and data[0][0] != '':
  661. text_data = '' + \
  662. '<span>' + data[0][0] + '</span>' + \
  663. '<hr class="main_hr">' + \
  664. ''
  665. else:
  666. text_data = '' + \
  667. '<span>' + load_lang('no_login_warning') + '</span>' + \
  668. '<hr class="main_hr">' + \
  669. ''
  670. else:
  671. text_data = ''
  672. return text_data
  673. # Func-login
  674. def pw_encode(data, db_data = ''):
  675. curs = conn.cursor()
  676. if db_data == '':
  677. curs.execute(db_change('select data from other where name = "encode"'))
  678. db_data = curs.fetchall()
  679. db_data = db_data[0][0] if db_data else 'sha3'
  680. if db_data == 'sha256':
  681. return hashlib.sha256(bytes(data, 'utf-8')).hexdigest()
  682. elif db_data == 'sha3-512':
  683. return hashlib.sha3_512(bytes(data, 'utf-8')).hexdigest()
  684. else: # type_d == 'sha3'
  685. return hashlib.sha3_256(bytes(data, 'utf-8')).hexdigest()
  686. def pw_check(data, data2, type_d = 'no', id_d = ''):
  687. curs = conn.cursor()
  688. curs.execute(db_change('select data from other where name = "encode"'))
  689. db_data = curs.fetchall()
  690. if type_d != 'no':
  691. if type_d == '':
  692. set_data = 'sha3'
  693. else:
  694. set_data = type_d
  695. else:
  696. set_data = db_data[0][0]
  697. re_data = 1 if pw_encode(data, set_data) == data2 else 0
  698. if db_data[0][0] != set_data and re_data == 1 and id_d != '':
  699. curs.execute(db_change("update user_set set data = ? where id = ? and name = 'pw'"), [
  700. pw_encode(data),
  701. id_d
  702. ])
  703. curs.execute(db_change("update user_set set data = ? where id = ? and name = 'encode'"), [
  704. db_data[0][0],
  705. id_d
  706. ])
  707. return re_data
  708. # Func-skin
  709. def easy_minify(data, tool = None):
  710. # without_DB
  711. return data
  712. def load_lang(data, safe = 0):
  713. curs = conn.cursor()
  714. global global_lang
  715. ip = ip_check()
  716. if ip_or_user(ip) == 0:
  717. curs.execute(db_change('select data from user_set where name = "lang" and id = ?'), [ip])
  718. rep_data = curs.fetchall()
  719. elif 'lang' in flask.session:
  720. rep_data = [[flask.session['lang']]]
  721. else:
  722. curs.execute(db_change("select data from other where name = 'language'"))
  723. rep_data = curs.fetchall()
  724. if not rep_data or rep_data[0][0] in ('', 'default'):
  725. curs.execute(db_change("select data from other where name = 'language'"))
  726. rep_data = curs.fetchall()
  727. if rep_data:
  728. lang_name = rep_data[0][0]
  729. else:
  730. lang_name = 'en-US'
  731. if lang_name in global_lang:
  732. lang = global_lang[lang_name]
  733. else:
  734. lang_list = os.listdir('lang')
  735. if (lang_name + '.json') in lang_list:
  736. lang = json.loads(open(
  737. os.path.join('lang', lang_name + '.json'),
  738. encoding = 'utf8'
  739. ).read())
  740. global_lang[lang_name] = lang
  741. else:
  742. lang = {}
  743. if data in lang:
  744. if safe == 1:
  745. return lang[data]
  746. else:
  747. return html.escape(lang[data])
  748. return html.escape(data + ' (' + lang_name + ')')
  749. def skin_check(set_n = 0):
  750. curs = conn.cursor()
  751. # 개편 필요?
  752. skin_list = load_skin('tenshi', 1)
  753. skin = skin_list[0]
  754. ip = ip_check()
  755. user_need_skin = ''
  756. if ip_or_user(ip) == 0:
  757. curs.execute(db_change('select data from user_set where name = "skin" and id = ?'), [ip])
  758. skin_exist = curs.fetchall()
  759. if skin_exist:
  760. user_need_skin = skin_exist[0][0]
  761. else:
  762. if 'skin' in flask.session:
  763. user_need_skin = flask.session['skin']
  764. if user_need_skin == '':
  765. curs.execute(db_change('select data from other where name = "skin"'))
  766. skin_exist = curs.fetchall()
  767. if skin_exist:
  768. user_need_skin = skin_exist[0][0]
  769. if user_need_skin != '' and user_need_skin in skin_list:
  770. skin = user_need_skin
  771. if set_n == 0:
  772. return './views/' + skin + '/index.html'
  773. else:
  774. return skin
  775. def wiki_css(data):
  776. # without_DB
  777. data += ['' for _ in range(0, 3 - len(data))]
  778. data_css = ''
  779. data_css_ver = '147'
  780. # Func JS
  781. data_css += '<script src="/views/main_css/js/func/func.js?ver=' + data_css_ver + '"></script>'
  782. data_css += '<script src="/views/main_css/js/func/http_warning_text.js?ver=' + data_css_ver + '"></script>'
  783. data_css += '<script src="/views/main_css/js/func/ie_end_of_life.js?ver=' + data_css_ver + '"></script>'
  784. data_css += '<script src="/views/main_css/js/func/shortcut.js?ver=' + data_css_ver + '"></script>'
  785. data_css += '<script src="/views/main_css/js/func/user_name_parser.js?ver=' + data_css_ver + '"></script>'
  786. # Render JS
  787. data_css += '<script src="/views/main_css/js/render/markdown.js?ver=' + data_css_ver + '"></script>'
  788. data_css += '<script src="/views/main_css/js/render/wiki.js?ver=' + data_css_ver + '"></script>'
  789. # Route JS
  790. data_css += '<script src="/views/main_css/js/route/thread.js?ver=' + data_css_ver + '"></script>'
  791. # 레거시 일반 JS
  792. data_css += '<script src="/views/main_css/js/load_editor.js?ver=' + data_css_ver + '"></script>'
  793. data_css += '<script src="/views/main_css/js/load_skin_set.js?ver=' + data_css_ver + '"></script>'
  794. data_css += '<script src="/views/main_css/js/load_something.js?ver=' + data_css_ver + '"></script>'
  795. # 레거시 렌더러 JS
  796. data_css += '<script src="/views/main_css/js/render_html.js?ver=' + data_css_ver + '"></script>'
  797. data_css += '<script src="/views/main_css/js/render_onmark.js?ver=' + data_css_ver + '"></script>'
  798. data_css += '<script src="/views/main_css/js/render_wiki.js?ver=' + data_css_ver + '"></script>'
  799. # Main CSS
  800. data_css += '<link rel="stylesheet" href="/views/main_css/css/main.css?ver=' + data_css_ver + '">'
  801. # External
  802. data_css += '<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.5.0/build/styles/default.min.css">'
  803. data_css += '<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.5.0/build/highlight.min.js"></script>'
  804. data_css += '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.3/dist/katex.min.css" integrity="sha384-KiWOvVjnN8qwAZbuQyWDIbfCLFhLXNETzBQjA/92pIowpC0d2O3nppDGQVgwd2nB" crossorigin="anonymous">'
  805. data_css += '<script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.3/dist/katex.min.js" integrity="sha384-0fdwu/T/EQMsQlrHCCHoH10pkPLlKA1jL5dFyUOvB3lfeT2540/2g6YgSi2BL14p" crossorigin="anonymous"></script>'
  806. data = data[0:2] + ['', data_css] + data[2:]
  807. return data
  808. def cut_100(data):
  809. # without_DB
  810. data = data.replace('<pre class="render_content_load" id="render_content_load">', '')
  811. data = data.replace('</pre>', ' ' * 100)
  812. return data[0 : 100]
  813. def wiki_set(num = 1):
  814. curs = conn.cursor()
  815. if num == 1:
  816. skin_name = skin_check(1)
  817. data_list = []
  818. curs.execute(db_change('select data from other where name = ?'), ['name'])
  819. db_data = curs.fetchall()
  820. data_list += [db_data[0][0]] if db_data and db_data[0][0] != '' else ['Wiki']
  821. curs.execute(db_change('select data from other where name = "license"'))
  822. db_data = curs.fetchall()
  823. data_list += [db_data[0][0]] if db_data and db_data[0][0] != '' else ['ARR']
  824. data_list += ['', '']
  825. curs.execute(db_change('select data from other where name = "logo" and coverage = ?'), [skin_name])
  826. db_data = curs.fetchall()
  827. if db_data and db_data[0][0] != '':
  828. data_list += [db_data[0][0]]
  829. else:
  830. curs.execute(db_change('select data from other where name = "logo" and coverage = ""'))
  831. db_data = curs.fetchall()
  832. data_list += [db_data[0][0]] if db_data and db_data[0][0] != '' else [data_list[0]]
  833. head_data = ''
  834. curs.execute(db_change("select data from other where name = 'head' and coverage = ''"))
  835. db_data = curs.fetchall()
  836. head_data += db_data[0][0] if db_data and db_data[0][0] != '' else ''
  837. curs.execute(db_change("select data from other where name = 'head' and coverage = ?"), [skin_name])
  838. db_data = curs.fetchall()
  839. head_data += db_data[0][0] if db_data and db_data[0][0] != '' else ''
  840. data_list += [head_data]
  841. elif num == 2:
  842. curs.execute(db_change('select data from other where name = "frontpage"'))
  843. db_data = curs.fetchall()
  844. data_list = db_data[0][0] if db_data and db_data[0][0] != '' else 'FrontPage'
  845. elif num == 3:
  846. curs.execute(db_change('select data from other where name = "upload"'))
  847. db_data = curs.fetchall()
  848. data_list = db_data[0][0] if db_data and db_data[0][0] != '' else '2'
  849. else:
  850. data_list = ''
  851. return data_list
  852. def wiki_custom():
  853. curs = conn.cursor()
  854. ip = ip_check()
  855. if ip_or_user(ip) == 0:
  856. user_icon = 1
  857. user_name = ip
  858. curs.execute(db_change("select data from user_set where id = ? and name = 'custom_css'"), [ip])
  859. user_head = curs.fetchall()
  860. user_head = user_head[0][0] if user_head else ''
  861. curs.execute(db_change('select data from user_set where name = "email" and id = ?'), [ip])
  862. email = curs.fetchall()
  863. email = email[0][0] if email else ''
  864. if admin_check('all') == 1:
  865. user_admin = '1'
  866. user_acl_list = []
  867. curs.execute(db_change("select data from user_set where id = ? and name = 'acl'"), [ip])
  868. curs.execute(db_change('select acl from alist where name = ?'), [curs.fetchall()[0][0]])
  869. user_acl = curs.fetchall()
  870. for i in user_acl:
  871. user_acl_list += [i[0]]
  872. user_acl_list = user_acl_list if user_acl != [] else '0'
  873. else:
  874. user_admin = '0'
  875. user_acl_list = '0'
  876. curs.execute(db_change("select count(*) from alarm where name = ?"), [ip])
  877. count = curs.fetchall()
  878. user_notice = str(count[0][0]) if count else '0'
  879. else:
  880. user_icon = 0
  881. user_name = load_lang('user')
  882. email = ''
  883. user_admin = '0'
  884. user_acl_list = '0'
  885. user_notice = '0'
  886. user_head = flask.session['head'] if 'head' in flask.session else ''
  887. curs.execute(db_change("select title from rd where title = ? and stop = ''"), ['user:' + ip])
  888. user_topic = '1' if curs.fetchall() else '0'
  889. split_path = flask.request.path.split('/')
  890. if len(split_path) > 1:
  891. split_path = split_path[1]
  892. else:
  893. split_path = 0
  894. return [
  895. '',
  896. '',
  897. user_icon,
  898. user_head,
  899. email,
  900. user_name,
  901. user_admin,
  902. str(ban_check()),
  903. user_notice,
  904. user_acl_list,
  905. ip,
  906. user_topic,
  907. split_path
  908. ]
  909. def load_skin(data = '', set_n = 0, default = 0):
  910. # without_DB
  911. # data -> 가장 앞에 있을 스킨 이름
  912. # set_n == 0 -> 스트링으로 반환
  913. # set_n == 1 -> 리스트로 반환
  914. # default == 0 -> 디폴트 미포함
  915. # default == 1 -> 디폴트 포함
  916. if set_n == 0:
  917. skin_return_data = ''
  918. else:
  919. skin_return_data = []
  920. skin_list_get = os.listdir('views')
  921. if default == 1:
  922. skin_list_get = ['default'] + skin_list_get
  923. for skin_data in skin_list_get:
  924. if skin_data != 'default':
  925. see_data = skin_data
  926. else:
  927. see_data = load_lang('default')
  928. if skin_data != 'main_css':
  929. if set_n == 0:
  930. if skin_data == data:
  931. skin_return_data = '' + \
  932. '<option value="' + skin_data + '">' + \
  933. see_data + \
  934. '</option>' + \
  935. '' + skin_return_data
  936. else:
  937. skin_return_data += '' + \
  938. '<option value="' + skin_data + '">' + \
  939. see_data + \
  940. '</option>' + \
  941. ''
  942. else:
  943. if skin_data == data:
  944. skin_return_data = [skin_data] + skin_return_data
  945. else:
  946. skin_return_data += [skin_data]
  947. return skin_return_data
  948. # Func-markup
  949. def render_set(doc_name = '', doc_data = '', data_type = 'view', data_in = '', doc_acl = ''):
  950. # without_DB
  951. # data_type in ['view', 'raw', 'api_view', 'backlink']
  952. doc_acl = acl_check(doc_name, 'render') if doc_acl == '' else doc_acl
  953. doc_data = 0 if doc_data == None else doc_data
  954. if doc_acl == 1:
  955. return 'HTTP Request 401.3'
  956. else:
  957. if data_type == 'raw':
  958. return doc_data
  959. else:
  960. if doc_data != 0:
  961. get_class_render = class_do_render(conn)
  962. return get_class_render.do_render(doc_name, doc_data, data_type, data_in)
  963. else:
  964. return 'HTTP Request 404'
  965. # Func-request
  966. def send_email(who, title, data):
  967. curs = conn.cursor()
  968. try:
  969. curs.execute(db_change('' + \
  970. 'select name, data from other ' + \
  971. 'where name = "smtp_email" or name = "smtp_pass" or name = "smtp_server" or name = "smtp_port" or name = "smtp_security"' + \
  972. ''))
  973. rep_data = curs.fetchall()
  974. smtp_email = ''
  975. smtp_pass = ''
  976. smtp_server = ''
  977. smtp_security = ''
  978. smtp_port = ''
  979. smtp = ''
  980. for i in rep_data:
  981. if i[0] == 'smtp_email':
  982. smtp_email = i[1]
  983. elif i[0] == 'smtp_pass':
  984. smtp_pass = i[1]
  985. elif i[0] == 'smtp_server':
  986. smtp_server = i[1]
  987. elif i[0] == 'smtp_security':
  988. smtp_security = i[1]
  989. elif i[0] == 'smtp_port':
  990. smtp_port = i[1]
  991. smtp_port = int(smtp_port)
  992. if smtp_security == 'plain':
  993. smtp = smtplib.SMTP(smtp_server, smtp_port)
  994. elif smtp_security == 'starttls':
  995. smtp = smtplib.SMTP(smtp_server, smtp_port)
  996. smtp.starttls()
  997. else:
  998. # if smtp_security == 'tls':
  999. smtp = smtplib.SMTP_SSL(smtp_server, smtp_port)
  1000. smtp.login(smtp_email, smtp_pass)
  1001. domain = load_domain()
  1002. wiki_name = wiki_set()[0]
  1003. msg = email.mime.text.MIMEText(data)
  1004. msg['Subject'] = title
  1005. msg['From'] = 'openNAMU <noreply@' + domain + '>'
  1006. msg['To'] = who
  1007. smtp.sendmail('openNAMU@' + domain, who, msg.as_string())
  1008. smtp.quit()
  1009. return 1
  1010. except Exception as e:
  1011. print('----')
  1012. print('Error : email send error')
  1013. print(e)
  1014. return 0
  1015. def captcha_get():
  1016. curs = conn.cursor()
  1017. data = ''
  1018. if ip_or_user() != 0:
  1019. curs.execute(db_change('select data from other where name = "recaptcha"'))
  1020. recaptcha = curs.fetchall()
  1021. curs.execute(db_change('select data from other where name = "sec_re"'))
  1022. sec_re = curs.fetchall()
  1023. curs.execute(db_change('select data from other where name = "recaptcha_ver"'))
  1024. rec_ver = curs.fetchall()
  1025. if recaptcha and recaptcha[0][0] != '' and sec_re and sec_re[0][0] != '':
  1026. if not rec_ver or rec_ver[0][0] == '':
  1027. data += '' + \
  1028. '<script src="https://www.google.com/recaptcha/api.js" async defer></script>' + \
  1029. '<div class="g-recaptcha" data-sitekey="' + recaptcha[0][0] + '"></div>' + \
  1030. '<hr class="main_hr">' + \
  1031. ''
  1032. elif rec_ver[0][0] == 'v3':
  1033. data += '' + \
  1034. '<script src="https://www.google.com/recaptcha/api.js?render=' + recaptcha[0][0] + '"></script>' + \
  1035. '<input type="hidden" id="g-recaptcha" name="g-recaptcha">' + \
  1036. '<script type="text/javascript">' + \
  1037. 'grecaptcha.ready(function() {' + \
  1038. 'grecaptcha.execute(\'' + recaptcha[0][0] + '\', {action: \'homepage\'}).then(function(token) {' + \
  1039. 'document.getElementById(\'g-recaptcha\').value = token;' + \
  1040. '});' + \
  1041. '});' + \
  1042. '</script>' + \
  1043. ''
  1044. else:
  1045. data += '''
  1046. <script src="https://js.hcaptcha.com/1/api.js" async defer></script>
  1047. <div class="h-captcha" data-sitekey="''' + recaptcha[0][0] + '''"></div>
  1048. <hr class="main_hr">
  1049. '''
  1050. return data
  1051. def captcha_post(re_data, num = 1):
  1052. curs = conn.cursor()
  1053. if num == 1 and ip_or_user() != 0:
  1054. curs.execute(db_change('select data from other where name = "sec_re"'))
  1055. sec_re = curs.fetchall()
  1056. curs.execute(db_change('select data from other where name = "recaptcha_ver"'))
  1057. rec_ver = curs.fetchall()
  1058. if captcha_get() != '':
  1059. if not rec_ver or rec_ver[0][0] in ('', 'v3'):
  1060. data = requests.get(
  1061. 'https://www.google.com/recaptcha/api/siteverify' + \
  1062. '?secret=' + sec_re[0][0] + '&response=' + re_data
  1063. )
  1064. if data.status_code == 200:
  1065. json_data = json.loads(data.text)
  1066. if json_data['success'] != True:
  1067. return 1
  1068. else:
  1069. data = requests.get(
  1070. 'https://hcaptcha.com/siteverify' + \
  1071. '?secret=' + sec_re[0][0] + '&response=' + re_data
  1072. )
  1073. if data.status_code == 200:
  1074. json_data = json.loads(data.text)
  1075. if json_data['success'] != True:
  1076. return 1
  1077. return 0
  1078. # Func-user
  1079. def ip_or_user(data = ''):
  1080. # without_DB
  1081. # 1 == ip
  1082. # 0 == reg
  1083. if data == '':
  1084. data = ip_check()
  1085. if re.search(r'(\.|:)', data):
  1086. return 1
  1087. else:
  1088. return 0
  1089. def admin_check(num = None, what = None, name = ''):
  1090. curs = conn.cursor()
  1091. ip = ip_check() if name == '' else name
  1092. time_data = get_time()
  1093. pass_ok = 0
  1094. if ip_or_user(ip) == 0:
  1095. curs.execute(db_change(
  1096. "select data from user_set where id = ? and name = 'acl'"
  1097. ), [ip])
  1098. user_auth = curs.fetchall()
  1099. if user_auth:
  1100. user_auth = user_auth[0][0]
  1101. check = {
  1102. 0 : 'owner',
  1103. 1 : 'ban',
  1104. 2 : 'nothing',
  1105. 3 : 'toron',
  1106. 4 : 'check',
  1107. 5 : 'acl',
  1108. 6 : 'hidel',
  1109. 7 : 'give'
  1110. }
  1111. if not num:
  1112. check = check[0]
  1113. elif num == 'all':
  1114. check = [check[i] for i in check]
  1115. else:
  1116. check = check[num]
  1117. curs.execute(db_change(
  1118. 'select name from alist where name = ? and acl = "owner"'
  1119. ), [user_auth])
  1120. if curs.fetchall():
  1121. pass_ok = 1
  1122. else:
  1123. if num == 'all':
  1124. curs.execute(db_change(
  1125. 'select name from alist where name = ?'
  1126. ), [user_auth])
  1127. else:
  1128. curs.execute(db_change(
  1129. 'select name from alist where name = ? and acl = ?'
  1130. ), [user_auth, check])
  1131. if curs.fetchall():
  1132. pass_ok = 1
  1133. if pass_ok == 1:
  1134. if what:
  1135. curs.execute(db_change(
  1136. "insert into re_admin (who, what, time) values (?, ?, ?)"
  1137. ), [ip, what, time_data])
  1138. conn.commit()
  1139. return 1
  1140. return 0
  1141. def acl_check(name = 'test', tool = '', topic_num = '1'):
  1142. curs = conn.cursor()
  1143. ip = ip_check()
  1144. get_ban = ban_check()
  1145. if tool == '' and name:
  1146. if tool == '' and acl_check(name, 'render') == 1:
  1147. return 1
  1148. user_page = re.search(r"^user:((?:(?!\/).)*)", name)
  1149. if user_page:
  1150. user_page = user_page.group(1)
  1151. if admin_check(5) == 1:
  1152. return 0
  1153. if get_ban == 1:
  1154. return 1
  1155. curs.execute(db_change(
  1156. "select data from acl where title = ? and type = 'decu'"
  1157. ), [name])
  1158. acl_data = curs.fetchall()
  1159. if acl_data:
  1160. if acl_data[0][0] == 'all':
  1161. return 0
  1162. elif acl_data[0][0] == 'user' and not ip_or_user(ip) == 1:
  1163. return 0
  1164. if ip == user_page and not ip_or_user(ip) == 1:
  1165. return 0
  1166. return 1
  1167. elif tool == 'topic':
  1168. curs.execute(db_change("select title from rd where code = ?"), [topic_num])
  1169. name = curs.fetchall()
  1170. name = name[0][0] if name else 'test'
  1171. if tool in ['topic']:
  1172. end = 3
  1173. elif tool in ['render', 'vote', '']:
  1174. end = 2
  1175. else:
  1176. end = 1
  1177. for i in range(0, end):
  1178. if tool == '':
  1179. if i == 0:
  1180. curs.execute(db_change(
  1181. "select data from acl where title = ? and type = 'decu'"
  1182. ), [name])
  1183. '''
  1184. elif i == 1:
  1185. curs.execute(db_change(
  1186. "select plus from html_filter where kind = 'document'"
  1187. ))
  1188. '''
  1189. else:
  1190. curs.execute(db_change(
  1191. 'select data from other where name = "edit"'
  1192. ))
  1193. num = 5
  1194. elif tool == 'topic':
  1195. if i == 0:
  1196. curs.execute(db_change(
  1197. "select acl from rd where code = ?"
  1198. ), [topic_num])
  1199. elif i == 1:
  1200. curs.execute(db_change(
  1201. "select data from acl where title = ? and type = 'dis'"
  1202. ), [name])
  1203. else:
  1204. curs.execute(db_change(
  1205. 'select data from other where name = "discussion"'
  1206. ))
  1207. num = 3
  1208. elif tool == 'upload':
  1209. curs.execute(db_change(
  1210. "select data from other where name = 'upload_acl'"
  1211. ))
  1212. num = 5
  1213. elif tool == 'many_upload':
  1214. curs.execute(db_change(
  1215. "select data from other where name = 'many_upload_acl'"
  1216. ))
  1217. num = 5
  1218. elif tool == 'vote':
  1219. if i == 0:
  1220. curs.execute(db_change(
  1221. 'select acl from vote where id = ? and user = ""'
  1222. ), [topic_num])
  1223. else:
  1224. curs.execute(db_change(
  1225. 'select data from other where name = "vote_acl"'
  1226. ))
  1227. num = None
  1228. else:
  1229. # tool == 'render'
  1230. if i == 0:
  1231. curs.execute(db_change(
  1232. "select data from acl where title = ? and type = 'view'"
  1233. ), [name])
  1234. else:
  1235. curs.execute(db_change("select data from other where name = 'all_view_acl'"))
  1236. num = 5
  1237. acl_data = curs.fetchall()
  1238. if not acl_data:
  1239. acl_data = [['normal']]
  1240. elif acl_data and acl_data[0][0] == '':
  1241. acl_data = [['normal']]
  1242. if acl_data[0][0] != 'normal':
  1243. if not acl_data[0][0] in ['ban', 'ban_admin'] and get_ban == 1 and tool != 'render':
  1244. return 1
  1245. if acl_data[0][0] in ['all', 'ban']:
  1246. return 0
  1247. elif acl_data[0][0] == 'user':
  1248. if ip_or_user(ip) != 1:
  1249. return 0
  1250. elif acl_data[0][0] == 'admin':
  1251. if ip_or_user(ip) != 1:
  1252. if admin_check(num) == 1:
  1253. return 0
  1254. elif acl_data[0][0] == '50_edit':
  1255. if ip_or_user(ip) != 1:
  1256. if admin_check(num) == 1:
  1257. return 0
  1258. else:
  1259. curs.execute(db_change(
  1260. "select count(*) from history where ip = ?"
  1261. ), [ip])
  1262. count = curs.fetchall()
  1263. count = count[0][0] if count else 0
  1264. if count >= 50:
  1265. return 0
  1266. elif acl_data[0][0] == 'before':
  1267. if ip_or_user(ip) != 1:
  1268. if admin_check(num) == 1:
  1269. return 0
  1270. curs.execute(db_change(
  1271. "select ip from history where title = ? and ip = ?"
  1272. ), [name, ip])
  1273. if curs.fetchall():
  1274. return 0
  1275. elif acl_data[0][0] == '30_day':
  1276. if ip_or_user(ip) != 1:
  1277. if admin_check(num) == 1:
  1278. return 0
  1279. else:
  1280. curs.execute(db_change(
  1281. "select data from user_set where id = ? and name = 'date'"
  1282. ), [ip])
  1283. user_date = curs.fetchall()[0][0]
  1284. time_1 = datetime.datetime.strptime(
  1285. user_date,
  1286. '%Y-%m-%d %H:%M:%S'
  1287. ) + datetime.timedelta(days = 30)
  1288. time_2 = datetime.datetime.strptime(
  1289. get_time(),
  1290. '%Y-%m-%d %H:%M:%S'
  1291. )
  1292. if time_2 > time_1:
  1293. return 0
  1294. elif acl_data[0][0] == 'email':
  1295. if ip_or_user(ip) != 1:
  1296. if admin_check(num) == 1:
  1297. return 0
  1298. else:
  1299. curs.execute(db_change(
  1300. "select data from user_set where id = ? and name = 'email'"
  1301. ), [ip])
  1302. if curs.fetchall():
  1303. return 0
  1304. elif acl_data[0][0] == 'owner':
  1305. if admin_check() == 1:
  1306. return 0
  1307. elif acl_data[0][0] == 'ban_admin':
  1308. if admin_check(1) == 1 or get_ban == 1:
  1309. return 0
  1310. elif acl_data[0][0] == 'not_all':
  1311. return 1
  1312. return 1
  1313. elif i == (end - 1):
  1314. if get_ban == 1 and tool != 'render':
  1315. return 1
  1316. if tool == 'topic':
  1317. curs.execute(db_change(
  1318. "select title from rd where code = ? and stop != ''"
  1319. ), [topic_num])
  1320. if curs.fetchall():
  1321. if admin_check(3, 'topic (code ' + topic_num + ')') == 1:
  1322. return 0
  1323. else:
  1324. return 1
  1325. else:
  1326. return 0
  1327. else:
  1328. return 0
  1329. return 1
  1330. def ban_check(ip = None, tool = ''):
  1331. curs = conn.cursor()
  1332. ip = ip_check() if not ip else ip
  1333. tool = '' if not tool else tool
  1334. if admin_check(None, None, ip) == 1:
  1335. return 0
  1336. curs.execute(db_change(
  1337. "update rb set ongoing = '' " + \
  1338. "where end < ? and end != '' and ongoing = '1'"
  1339. ), [get_time()])
  1340. conn.commit()
  1341. curs.execute(db_change("" + \
  1342. "select login, block from rb " + \
  1343. "where band = 'regex' and ongoing = '1'" + \
  1344. ""))
  1345. regex_d = curs.fetchall()
  1346. for test_r in regex_d:
  1347. g_regex = re.compile(test_r[1])
  1348. if g_regex.search(ip):
  1349. if tool == 'login':
  1350. if test_r[0] != 'O':
  1351. return 1
  1352. else:
  1353. return 1
  1354. curs.execute(db_change("" + \
  1355. "select login from rb " + \
  1356. "where block = ? and band = '' and ongoing = '1'" + \
  1357. "" + \
  1358. ""), [ip])
  1359. ban_d = curs.fetchall()
  1360. if ban_d:
  1361. if tool == 'login':
  1362. if ban_d[0][0] != 'O':
  1363. return 1
  1364. else:
  1365. return 1
  1366. return 0
  1367. def ip_pas(raw_ip, type_data = 0):
  1368. curs = conn.cursor()
  1369. hide = 0
  1370. end_ip = {}
  1371. return_data = 0
  1372. if type(raw_ip) != type([]):
  1373. get_ip = [raw_ip]
  1374. return_data = 1
  1375. else:
  1376. get_ip = raw_ip
  1377. curs.execute(db_change("select data from other where name = 'ip_view'"))
  1378. ip_view = curs.fetchall()
  1379. ip_view = ip_view[0][0] if ip_view else ''
  1380. ip_view = '' if admin_check(1) == 1 else ip_view
  1381. get_ip = list(set(get_ip))
  1382. for raw_ip in get_ip:
  1383. change_ip = 0
  1384. is_this_ip = ip_or_user(raw_ip)
  1385. if is_this_ip != 0 and ip_view != '':
  1386. ip = re.sub(r'\.([^.]*)\.([^.]*)$', '.*.*', raw_ip)
  1387. ip = re.sub(r':([^:]*):([^:]*)$', ':*:*', ip)
  1388. change_ip = 1
  1389. else:
  1390. ip = raw_ip
  1391. if type_data == 0 and change_ip == 0:
  1392. ip = '<span class="opennamu_ip_render">' + raw_ip + '</span>'
  1393. end_ip[raw_ip] = ip
  1394. if return_data == 1:
  1395. return end_ip[raw_ip]
  1396. else:
  1397. return end_ip
  1398. # Func-edit
  1399. def get_edit_text_bottom():
  1400. curs = conn.cursor()
  1401. b_text = ''
  1402. curs.execute(db_change('select data from other where name = "edit_bottom_text"'))
  1403. db_data= curs.fetchall()
  1404. if db_data and db_data[0][0] != '':
  1405. b_text = '' + \
  1406. '<hr class="main_hr">' + \
  1407. db_data[0][0] + \
  1408. '<hr class="main_hr">' + \
  1409. ''
  1410. return b_text
  1411. def get_edit_text_bottom_check_box():
  1412. curs = conn.cursor()
  1413. cccb_text = ''
  1414. curs.execute(db_change('select data from other where name = "copyright_checkbox_text"'))
  1415. sql_d = curs.fetchall()
  1416. if sql_d and sql_d[0][0] != '':
  1417. cccb_text = '' + \
  1418. '<hr class="main_hr">' + \
  1419. '<input type="checkbox" name="copyright_agreement" value="yes"> ' + sql_d[0][0] + \
  1420. '<hr class="main_hr">' + \
  1421. ''
  1422. return cccb_text
  1423. def do_edit_text_bottom_check_box_check(data):
  1424. curs = conn.cursor()
  1425. curs.execute(db_change('select data from other where name = "copyright_checkbox_text"'))
  1426. db_data = curs.fetchall()
  1427. if db_data and db_data[0][0] != '':
  1428. if data != 'yes':
  1429. return 1
  1430. return 0
  1431. def do_edit_send_check(data):
  1432. curs = conn.cursor()
  1433. curs.execute(db_change('select data from other where name = "edit_bottom_compulsion"'))
  1434. db_data = curs.fetchall()
  1435. if db_data and db_data[0][0] != '' and data == '':
  1436. return 1
  1437. return 0
  1438. def do_edit_slow_check():
  1439. curs = conn.cursor()
  1440. curs.execute(db_change("select data from other where name = 'slow_edit'"))
  1441. slow_edit = curs.fetchall()
  1442. if slow_edit and slow_edit != '0' and admin_check(5) != 1:
  1443. slow_edit = slow_edit[0][0]
  1444. curs.execute(db_change(
  1445. "select date from history where ip = ? order by date desc limit 1"
  1446. ), [ip_check()])
  1447. last_edit_data = curs.fetchall()
  1448. if last_edit_data:
  1449. last_edit_data = int(re.sub(' |:|-', '', last_edit_data[0][0]))
  1450. now_edit_data = int(
  1451. (datetime.datetime.now() - datetime.timedelta(
  1452. seconds = int(slow_edit))
  1453. ).strftime("%Y%m%d%H%M%S")
  1454. )
  1455. if last_edit_data > now_edit_data:
  1456. return 1
  1457. return 0
  1458. def do_edit_filter(data):
  1459. curs = conn.cursor()
  1460. if admin_check(1) != 1:
  1461. curs.execute(db_change(
  1462. "select plus, plus_t from html_filter where kind = 'regex_filter' and plus != ''"
  1463. ))
  1464. for data_list in curs.fetchall():
  1465. match = re.compile(data_list[0], re.I)
  1466. if match.search(data):
  1467. ban_insert(
  1468. ip_check(),
  1469. '0' if data_list[1] == 'X' else data_list[1],
  1470. 'edit filter',
  1471. None,
  1472. 'tool:edit filter'
  1473. )
  1474. return 1
  1475. return 0
  1476. # Func-insert
  1477. def add_alarm(who, context):
  1478. curs = conn.cursor()
  1479. curs.execute(db_change(
  1480. 'insert into alarm (name, data, date) values (?, ?, ?)'
  1481. ), [who, context, get_time()])
  1482. conn.commit()
  1483. def add_user(user_name, user_pw, user_email = '', user_encode = ''):
  1484. curs = conn.cursor()
  1485. if user_encode == '':
  1486. user_pw_hash = pw_encode(user_pw)
  1487. curs.execute(db_change('select data from other where name = "encode"'))
  1488. data_encode = curs.fetchall()
  1489. data_encode = data_encode[0][0]
  1490. else:
  1491. user_pw_hash = user_pw
  1492. data_encode = user_encode
  1493. curs.execute(db_change("select id from user_set limit 1"))
  1494. if not curs.fetchall():
  1495. user_auth = 'owner'
  1496. else:
  1497. user_auth = 'user'
  1498. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'pw', ?)"), [
  1499. user_name,
  1500. user_pw_hash
  1501. ])
  1502. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'acl', ?)"), [
  1503. user_name,
  1504. user_auth
  1505. ])
  1506. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'date', ?)"), [
  1507. user_name,
  1508. get_time()
  1509. ])
  1510. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'encode', ?)"), [
  1511. user_name,
  1512. data_encode
  1513. ])
  1514. if user_email != '':
  1515. curs.execute(db_change("insert into user_set (name, id, data) values ('email', ?, ?)"), [
  1516. user_name,
  1517. user_email
  1518. ])
  1519. conn.commit()
  1520. def ua_plus(u_id, u_ip, u_agent, time):
  1521. curs = conn.cursor()
  1522. curs.execute(db_change("select data from other where name = 'ua_get'"))
  1523. rep_data = curs.fetchall()
  1524. if rep_data and rep_data[0][0] != '':
  1525. pass
  1526. else:
  1527. curs.execute(db_change(
  1528. "insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')"
  1529. ), [
  1530. u_id,
  1531. u_ip,
  1532. u_agent,
  1533. time
  1534. ])
  1535. conn.commit()
  1536. def ban_insert(name, end, why, login, blocker, type_d = None):
  1537. curs = conn.cursor()
  1538. now_time = get_time()
  1539. band = type_d if type_d else ''
  1540. curs.execute(db_change(
  1541. "update rb set ongoing = '' where end < ? and end != '' and ongoing = '1'"
  1542. ), [now_time])
  1543. curs.execute(db_change("" + \
  1544. "select block from rb " + \
  1545. "where ((end > ? and end != '') or end = '') and block = ? and " + \
  1546. "band = ? and ongoing = '1'" + \
  1547. ""), [now_time, name, band])
  1548. if curs.fetchall():
  1549. curs.execute(db_change(
  1550. "insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, ?)"
  1551. ), [
  1552. name,
  1553. 'release',
  1554. now_time,
  1555. blocker,
  1556. '',
  1557. band
  1558. ])
  1559. curs.execute(db_change(
  1560. "update rb set ongoing = '' where block = ? and band = ? and ongoing = '1'"
  1561. ), [name, band])
  1562. else:
  1563. login = 'O' if login != '' else ''
  1564. if end != '0':
  1565. end = int(number_check(end))
  1566. time = datetime.datetime.now()
  1567. plus = datetime.timedelta(seconds = end)
  1568. r_time = (time + plus).strftime("%Y-%m-%d %H:%M:%S")
  1569. else:
  1570. r_time = ''
  1571. curs.execute(db_change(
  1572. "insert into rb (block, end, today, blocker, why, band, ongoing, login) " + \
  1573. "values (?, ?, ?, ?, ?, ?, '1', ?)"
  1574. ), [
  1575. name,
  1576. r_time,
  1577. now_time,
  1578. blocker,
  1579. why,
  1580. band,
  1581. login
  1582. ])
  1583. conn.commit()
  1584. def rd_plus(topic_num, date, name = None, sub = None):
  1585. curs = conn.cursor()
  1586. curs.execute(db_change("select code from rd where code = ?"), [topic_num])
  1587. if curs.fetchall():
  1588. curs.execute(db_change("update rd set date = ? where code = ?"), [date, topic_num])
  1589. else:
  1590. curs.execute(db_change(
  1591. "insert into rd (title, sub, code, date) values (?, ?, ?, ?)"
  1592. ), [name, sub, topic_num, date])
  1593. conn.commit()
  1594. def history_plus(title, data, date, ip, send, leng, t_check = '', mode = ''):
  1595. curs = conn.cursor()
  1596. if mode == 'add':
  1597. curs.execute(db_change(
  1598. "select id from history where title = ? order by id + 0 asc limit 1"
  1599. ), [title])
  1600. id_data = curs.fetchall()
  1601. id_data = str(int(id_data[0][0]) - 1) if id_data else '0'
  1602. else:
  1603. curs.execute(db_change(
  1604. "select id from history where title = ? order by id + 0 desc limit 1"
  1605. ), [title])
  1606. id_data = curs.fetchall()
  1607. id_data = str(int(id_data[0][0]) + 1) if id_data else '1'
  1608. mode = mode if not re.search('^user:', title) else 'user'
  1609. send = re.sub(r'\(|\)|<|>', '', send)
  1610. send = send[:128] if len(send) > 128 else send
  1611. send = send + ' (' + t_check + ')' if t_check != '' else send
  1612. if mode != 'add' and mode != 'user':
  1613. curs.execute(db_change("select count(*) from rc where type = 'normal'"))
  1614. if curs.fetchall()[0][0] >= 200:
  1615. curs.execute(db_change(
  1616. "select id, title from rc where type = 'normal' order by date asc limit 1"
  1617. ))
  1618. rc_data = curs.fetchall()
  1619. if rc_data:
  1620. curs.execute(db_change(
  1621. 'delete from rc where id = ? and title = ? and type = "normal"'
  1622. ), [
  1623. rc_data[0][0],
  1624. rc_data[0][1]
  1625. ])
  1626. curs.execute(db_change(
  1627. "insert into rc (id, title, date, type) values (?, ?, ?, 'normal')"
  1628. ), [
  1629. id_data,
  1630. title,
  1631. date
  1632. ])
  1633. if mode != 'add':
  1634. curs.execute(db_change("select count(*) from rc where type = ?"), [mode])
  1635. if curs.fetchall()[0][0] >= 200:
  1636. curs.execute(db_change(
  1637. "select id, title from rc where type = ? order by date asc limit 1"
  1638. ), [mode])
  1639. rc_data = curs.fetchall()
  1640. if rc_data:
  1641. curs.execute(db_change(
  1642. 'delete from rc where id = ? and title = ? and type = ?'
  1643. ), [
  1644. rc_data[0][0],
  1645. rc_data[0][1],
  1646. mode
  1647. ])
  1648. curs.execute(db_change(
  1649. "insert into rc (id, title, date, type) values (?, ?, ?, ?)"
  1650. ), [
  1651. id_data,
  1652. title,
  1653. date,
  1654. mode
  1655. ])
  1656. curs.execute(db_change(
  1657. "insert into history (id, title, data, date, ip, send, leng, hide, type) " + \
  1658. "values (?, ?, ?, ?, ?, ?, ?, '', ?)"
  1659. ), [
  1660. id_data,
  1661. title,
  1662. data,
  1663. date,
  1664. ip,
  1665. send,
  1666. leng,
  1667. mode
  1668. ])
  1669. # Func-error
  1670. def re_error(data):
  1671. curs = conn.cursor()
  1672. conn.commit()
  1673. if data == '/ban':
  1674. if ban_check() == 1:
  1675. end = '<div id="get_user_info"></div><script>load_user_info("' + ip_check() + '");</script>'
  1676. else:
  1677. end = '<ul class="inside_ul"><li>' + load_lang('authority_error') + '</li></ul>'
  1678. return easy_minify(flask.render_template(skin_check(),
  1679. imp = [load_lang('error'), wiki_set(1), wiki_custom(), wiki_css([0, 0])],
  1680. data = '<h2>' + load_lang('error') + '</h2>' + end,
  1681. menu = 0
  1682. )), 401
  1683. else:
  1684. num = int(number_check(data.replace('/error/', '')))
  1685. if num == 1:
  1686. data = load_lang('no_login_error')
  1687. elif num == 2:
  1688. data = load_lang('no_exist_user_error')
  1689. elif num == 3:
  1690. data = load_lang('authority_error')
  1691. elif num == 4:
  1692. data = load_lang('no_admin_block_error')
  1693. elif num == 5:
  1694. data = load_lang('error_skin_set')
  1695. elif num == 6:
  1696. data = load_lang('same_id_exist_error')
  1697. elif num == 7:
  1698. data = load_lang('long_id_error')
  1699. elif num == 8:
  1700. data = load_lang('id_char_error') + ' <a href="/name_filter">(' + load_lang('id_filter_list') + ')</a>'
  1701. elif num == 9:
  1702. data = load_lang('file_exist_error')
  1703. elif num == 10:
  1704. data = load_lang('password_error')
  1705. elif num == 11:
  1706. data = load_lang('topic_long_error')
  1707. elif num == 12:
  1708. data = load_lang('email_error')
  1709. elif num == 13:
  1710. data = load_lang('recaptcha_error')
  1711. elif num == 14:
  1712. data = load_lang('file_extension_error') + ' <a href="/extension_filter">(' + load_lang('extension_filter_list') + ')</a>'
  1713. elif num == 15:
  1714. data = load_lang('edit_record_error')
  1715. elif num == 16:
  1716. data = load_lang('same_file_error')
  1717. elif num == 17:
  1718. data = load_lang('file_capacity_error') + wiki_set(3)
  1719. elif num == 18:
  1720. data = load_lang('email_send_error')
  1721. elif num == 19:
  1722. data = load_lang('decument_exist_error')
  1723. elif num == 20:
  1724. data = load_lang('password_diffrent_error')
  1725. elif num == 21:
  1726. data = load_lang('edit_filter_error')
  1727. elif num == 22:
  1728. data = load_lang('file_name_error')
  1729. elif num == 23:
  1730. data = load_lang('regex_error')
  1731. elif num == 24:
  1732. curs.execute(db_change("select data from other where name = 'slow_edit'"))
  1733. slow_edit = curs.fetchall()
  1734. slow_edit = '' if not slow_edit else slow_edit[0][0]
  1735. data = load_lang('fast_edit_error') + slow_edit
  1736. elif num == 25:
  1737. data = load_lang('too_many_dec_error')
  1738. elif num == 26:
  1739. data = load_lang('application_not_found')
  1740. elif num == 27:
  1741. data = load_lang("invalid_password_error")
  1742. elif num == 28:
  1743. data = load_lang('watchlist_overflow_error')
  1744. elif num == 29:
  1745. data = load_lang('copyright_disagreed')
  1746. elif num == 30:
  1747. data = load_lang('ie_wrong_callback')
  1748. elif num == 33:
  1749. data = load_lang('restart_fail_error')
  1750. elif num == 34:
  1751. data = load_lang("update_error") + ' <a href="https://github.com/opennamu/opennamu">(Github)</a>'
  1752. elif num == 35:
  1753. data = load_lang('same_email_error')
  1754. elif num == 36:
  1755. data = load_lang('input_email_error')
  1756. elif num == 37:
  1757. data = load_lang('error_edit_send_request')
  1758. else:
  1759. data = '???'
  1760. if num == 5:
  1761. if not flask.request.path in ('/main_skin_set', '/change/skin_set/main'):
  1762. if flask.request.path != '/skin_set':
  1763. data += '<br>' + load_lang('error_skin_set_old') + ' <a href="/skin_set">(' + load_lang('go') + ')</a>'
  1764. title = load_lang('skin_set')
  1765. tool = [['change', load_lang('user_setting')]]
  1766. load_skin_set = ''
  1767. else:
  1768. title = load_lang('main_skin_set')
  1769. tool = [['change', load_lang('user_setting')]]
  1770. load_skin_set = '<script>main_css_skin_set();</script>'
  1771. return easy_minify(flask.render_template(skin_check(),
  1772. imp = [title, wiki_set(1), wiki_custom(), wiki_css([0, 0])],
  1773. data = '' + \
  1774. '<div id="main_skin_set">' + \
  1775. '<h2>' + load_lang('error') + '</h2>' + \
  1776. '<ul class="inside_ul">' + \
  1777. '<li>' + data + '</a></li>' + \
  1778. '</ul>' + \
  1779. '</div>' + \
  1780. load_skin_set,
  1781. menu = tool
  1782. ))
  1783. else:
  1784. return easy_minify(flask.render_template(skin_check(),
  1785. imp = [load_lang('error'), wiki_set(1), wiki_custom(), wiki_css([0, 0])],
  1786. data = '' + \
  1787. '<h2>' + load_lang('error') + '</h2>' + \
  1788. '<ul class="inside_ul">' + \
  1789. '<li>' + data + '</li>' + \
  1790. '</ul>' + \
  1791. '',
  1792. menu = 0
  1793. )), 400