func.py 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  1. # Init
  2. import sys
  3. import platform
  4. import json
  5. import smtplib
  6. import zipfile
  7. import shutil
  8. import logging
  9. import random
  10. from .func_mark import *
  11. for i in range(0, 2):
  12. try:
  13. from diff_match_patch import diff_match_patch
  14. import werkzeug.routing
  15. import werkzeug.debug
  16. import flask
  17. import flask_reggie
  18. import wsgiref.simple_server
  19. import urllib.request
  20. import email.mime.text
  21. import email.utils
  22. import email.header
  23. import requests
  24. import pymysql
  25. import PIL
  26. if sys.version_info < (3, 6):
  27. import sha3
  28. except ImportError as e:
  29. if i == 0:
  30. print(e)
  31. print('----')
  32. if platform.system() == 'Linux' or platform.system() == 'Windows':
  33. sys_pip_ins = os.system(
  34. 'python' + ('3' if platform.system() != 'Windows' else '') + ' ' + \
  35. '-m pip install --user -r requirements.txt'
  36. )
  37. if sys_pip_ins == 0:
  38. print('----')
  39. try:
  40. os.execl(sys.executable, sys.executable, *sys.argv)
  41. except:
  42. try:
  43. os.execl(sys.executable, '"' + sys.executable + '"', *sys.argv)
  44. except:
  45. print('Error : restart failed')
  46. raise
  47. else:
  48. print('Error : library install failed')
  49. raise
  50. print('----')
  51. print(e)
  52. raise
  53. global_lang = {}
  54. data_css_ver = '88'
  55. data_css = ''
  56. conn = ''
  57. curs = ''
  58. # Func
  59. # Func-main
  60. def load_conn(data):
  61. global conn
  62. global curs
  63. conn = data
  64. curs = conn.cursor()
  65. load_conn2(data)
  66. # Func-init
  67. class server_init:
  68. def __init__(self):
  69. self.env_dict = {
  70. 'host' : os.getenv('NAMU_HOST'),
  71. 'port' : os.getenv('NAMU_PORT'),
  72. 'language' : os.getenv('NAMU_LANG'),
  73. 'markup' : os.getenv('NAMU_MARKUP'),
  74. 'encode' : os.getenv('NAMU_ENCRYPT')
  75. }
  76. self.server_set_var = {
  77. 'host' : {
  78. 'display' : 'Host',
  79. 'require' : 'conv',
  80. 'default' : '0.0.0.0'
  81. }, 'port' : {
  82. 'display' : 'Port',
  83. 'require' : 'conv',
  84. 'default' : '3000'
  85. }, 'language' : {
  86. 'display' : 'Language',
  87. 'require' : 'select',
  88. 'default' : 'ko-KR',
  89. 'list' : ['ko-KR', 'en-US']
  90. }, 'markup' : {
  91. 'display' : 'Markup',
  92. 'require' : 'select',
  93. 'default' : 'namumark',
  94. 'list' : ['namumark', 'custom', 'raw']
  95. }, 'encode' : {
  96. 'display' : 'Encryption method',
  97. 'require' : 'select',
  98. 'default' : 'sha3',
  99. 'list' : ['sha3', 'sha256']
  100. }
  101. }
  102. def server_init(self):
  103. return self.server_set_var
  104. def init(self, key):
  105. if self.env_dict[key] != None:
  106. return self.env_dict[key]
  107. else:
  108. while 1:
  109. if self.server_set_var[key]['require'] == 'select':
  110. list_ = '[' + ', '.join(self.server_set_var[key]['list']) + ']'
  111. else:
  112. list_ = ''
  113. print('{} ({}) {} : '.format(
  114. self.server_set_var[key]['display'],
  115. self.server_set_var[key]['default'],
  116. list_
  117. ), end = '')
  118. server_set_val = input()
  119. if server_set_val:
  120. if self.server_set_var[key]['require'] == 'select':
  121. if server_set_val not in self.server_set_var[key]['list']:
  122. pass
  123. else:
  124. return server_set_val
  125. else:
  126. return server_set_val
  127. else:
  128. return self.server_set_var[key]['default']
  129. def update(ver_num, set_data):
  130. print('----')
  131. # 업데이트 하위 호환 유지 함수
  132. if ver_num < 3160027:
  133. print('Add init set')
  134. set_init()
  135. if ver_num < 3170002:
  136. curs.execute(db_change("select html from html_filter where kind = 'extension'"))
  137. if not curs.fetchall():
  138. for i in ['jpg', 'jpeg', 'png', 'gif', 'webp']:
  139. curs.execute(db_change("insert into html_filter (html, kind) values (?, 'extension')"), [i])
  140. if ver_num < 3170400:
  141. curs.execute(db_change("select title, sub, code from topic where id = '1'"))
  142. for i in curs.fetchall():
  143. curs.execute(db_change("update topic set code = ? where title = ? and sub = ?"), [i[2], i[0], i[1]])
  144. curs.execute(db_change("update rd set code = ? where title = ? and sub = ?"), [i[2], i[0], i[1]])
  145. if ver_num < 3171800:
  146. curs.execute(db_change("select data from other where name = 'recaptcha'"))
  147. change_rec = curs.fetchall()
  148. if change_rec and change_rec[0][0] != '':
  149. new_rec = re.search(r'data-sitekey="([^"]+)"', change_rec[0][0])
  150. if new_rec:
  151. curs.execute(db_change("update other set data = ? where name = 'recaptcha'"), [new_rec.group(1)])
  152. else:
  153. curs.execute(db_change("update other set data = '' where name = 'recaptcha'"))
  154. curs.execute(db_change("update other set data = '' where name = 'sec_re'"))
  155. if ver_num < 3172800 and set_data['db_type'] == 'mysql':
  156. get_data_mysql = json.loads(open('data/mysql.json').read())
  157. with open('data/mysql.json', 'w') as f:
  158. f.write('{ "user" : "' + get_data_mysql['user'] + '", "password" : "' + get_data_mysql['password'] + '", "host" : "localhost" }')
  159. if ver_num < 3183603:
  160. curs.execute(db_change("select block from ban where band = 'O'"))
  161. for i in curs.fetchall():
  162. curs.execute(db_change("update ban set block = ?, band = 'regex' where block = ? and band = 'O'"), [
  163. '^' + i[0].replace('.', '\\.'),
  164. i[0]
  165. ])
  166. curs.execute(db_change("select block from rb where band = 'O'"))
  167. for i in curs.fetchall():
  168. curs.execute(db_change("update rb set block = ?, band = 'regex' where block = ? and band = 'O'"), [
  169. '^' + i[0].replace('.', '\\.'),
  170. i[0]
  171. ])
  172. if ver_num < 3190201:
  173. today_time = get_time()
  174. curs.execute(db_change("select block, end, why, band, login from ban"))
  175. for i in curs.fetchall():
  176. curs.execute(db_change("insert into rb (block, end, today, why, band, login, ongoing) values (?, ?, ?, ?, ?, ?, ?)"), [
  177. i[0],
  178. i[1],
  179. today_time,
  180. i[2],
  181. i[3],
  182. i[4],
  183. '1'
  184. ])
  185. if ver_num < 3191301:
  186. curs.execute(db_change('' + \
  187. 'select id, title, date from history ' + \
  188. 'where not title like "user:%" ' + \
  189. 'order by date desc ' + \
  190. 'limit 50' + \
  191. ''))
  192. data_list = curs.fetchall()
  193. for get_data in data_list:
  194. curs.execute(db_change("insert into rc (id, title, date, type) values (?, ?, ?, 'normal')"), [
  195. get_data[0],
  196. get_data[1],
  197. get_data[2]
  198. ])
  199. if ver_num < 3202400:
  200. curs.execute(db_change("select data from other where name = 'update'"))
  201. get_data = curs.fetchall()
  202. if get_data and get_data[0][0] == 'master':
  203. curs.execute(db_change("update other set data = 'beta' where name = 'update'"), [])
  204. if ver_num < 3202600:
  205. curs.execute(db_change("select name, regex, sub from filter"))
  206. for i in curs.fetchall():
  207. curs.execute(db_change("insert into html_filter (html, kind, plus, plus_t) values (?, 'regex_filter', ?, ?)"), [
  208. i[0],
  209. i[1],
  210. i[2]
  211. ])
  212. curs.execute(db_change("select title, link, icon from inter"))
  213. for i in curs.fetchall():
  214. curs.execute(db_change("insert into html_filter (html, kind, plus, plus_t) values (?, 'inter_wiki', ?, ?)"), [
  215. i[0],
  216. i[1],
  217. i[2]
  218. ])
  219. if ver_num < 3203400:
  220. curs.execute(db_change("select user, css from custom"))
  221. for i in curs.fetchall():
  222. curs.execute(db_change("insert into user_set (name, id, data) values ('custom_css', ?, ?)"), [
  223. re.sub(r' \(head\)$', '', i[0]),
  224. i[1]
  225. ])
  226. if ver_num < 3205500:
  227. curs.execute(db_change("select title, decu, dis, view, why from acl"))
  228. for i in curs.fetchall():
  229. curs.execute(db_change("insert into acl (title, data, type) values (?, ?, ?)"), [i[0], i[1], 'decu'])
  230. curs.execute(db_change("insert into acl (title, data, type) values (?, ?, ?)"), [i[0], i[2], 'dis'])
  231. curs.execute(db_change("insert into acl (title, data, type) values (?, ?, ?)"), [i[0], i[3], 'view'])
  232. curs.execute(db_change("insert into acl (title, data, type) values (?, ?, ?)"), [i[0], i[4], 'why'])
  233. # 캐시 초기화
  234. if ver_num < 3300101:
  235. curs.execute(db_change('delete from cache_data'))
  236. conn.commit()
  237. print('Update completed')
  238. def set_init():
  239. # 초기값 설정 함수
  240. curs.execute(db_change("select html from html_filter where kind = 'email'"))
  241. if not curs.fetchall():
  242. for i in ['naver.com', 'gmail.com', 'daum.net', 'kakao.com']:
  243. curs.execute(db_change("insert into html_filter (html, kind) values (?, 'email')"), [i])
  244. curs.execute(db_change("select html from html_filter where kind = 'extension'"))
  245. if not curs.fetchall():
  246. for i in ['jpg', 'jpeg', 'png', 'gif', 'webp']:
  247. curs.execute(db_change("insert into html_filter (html, kind) values (?, 'extension')"), [i])
  248. curs.execute(db_change('select data from other where name = "smtp_server" or name = "smtp_port" or name = "smtp_security"'))
  249. if not curs.fetchall():
  250. for i in [['smtp_server', 'smtp.gmail.com'], ['smtp_port', '587'], ['smtp_security', 'starttls']]:
  251. curs.execute(db_change("insert into other (name, data) values (?, ?)"), [i[0], i[1]])
  252. # Func-simple
  253. def load_image_url():
  254. curs.execute(db_change('select data from other where name = "image_where"'))
  255. image_where = curs.fetchall()
  256. image_where = image_where[0][0] if image_where else 'data/images'
  257. return image_where
  258. def http_warring():
  259. return '''
  260. <div id="http_warring_text"></div>
  261. <script>
  262. if(window.location.protocol !== 'https:') {
  263. document.getElementById('http_warring_text').innerHTML = "''' + load_lang('http_warring') + '''";
  264. document.getElementById('http_warring_text').style.margin = "10px 0px 0px 0px";
  265. }
  266. </script>
  267. '''
  268. def load_domain():
  269. curs.execute(db_change("select data from other where name = 'domain'"))
  270. domain = curs.fetchall()
  271. domain = domain[0][0] if domain and domain[0][0] != '' else flask.request.host_url
  272. return domain
  273. def load_random_key(long = 64):
  274. return ''.join(random.choice("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") for i in range(long))
  275. def edit_button():
  276. insert_list = []
  277. curs.execute(db_change("select html, plus from html_filter where kind = 'edit_top'"))
  278. db_data = curs.fetchall()
  279. for get_data in db_data:
  280. insert_list += [[get_data[1], get_data[0]]]
  281. data = ''
  282. for insert_data in insert_list:
  283. data += '<a href="javascript:do_insert_data(\'content\', \'' + insert_data[0] + '\')">(' + insert_data[1] + ')</a> '
  284. if admin_check() == 1:
  285. data += (' ' if data != '' else '') + '<a href="/edit_top">(' + load_lang('add') + ')</a>'
  286. return data + '<hr class="main_hr">'
  287. def ip_warring():
  288. if ip_or_user() != 0:
  289. curs.execute(db_change('select data from other where name = "no_login_warring"'))
  290. data = curs.fetchall()
  291. if data and data[0][0] != '':
  292. text_data = '' + \
  293. '<span>' + data[0][0] + '</span>' + \
  294. '<hr class="main_hr">' + \
  295. ''
  296. else:
  297. text_data = '' + \
  298. '<span>' + load_lang('no_login_warring') + '</span>' + \
  299. '<hr class="main_hr">' + \
  300. ''
  301. else:
  302. text_data = ''
  303. return text_data
  304. def next_fix(link, num, page, end = 50):
  305. list_data = ''
  306. if num == 1:
  307. if len(page) == end:
  308. list_data += '' + \
  309. '<hr class="main_hr">' + \
  310. '<a href="' + link + str(num + 1) + '">(' + load_lang('next') + ')</a>' + \
  311. ''
  312. elif len(page) != end:
  313. list_data += '' + \
  314. '<hr class="main_hr">' + \
  315. '<a href="' + link + str(num - 1) + '">(' + load_lang('previous') + ')</a>' + \
  316. ''
  317. else:
  318. list_data += '' + \
  319. '<hr class="main_hr">' + \
  320. '<a href="' + link + str(num - 1) + '">(' + load_lang('previous') + ')</a> <a href="' + link + str(num + 1) + '">(' + load_lang('next') + ')</a>' + \
  321. ''
  322. return list_data
  323. def leng_check(first, second):
  324. if first < second:
  325. all_plus = '+' + str(second - first)
  326. elif second < first:
  327. all_plus = '-' + str(first - second)
  328. else:
  329. all_plus = '0'
  330. return all_plus
  331. def number_check(data):
  332. try:
  333. int(data)
  334. return data
  335. except:
  336. return '1'
  337. def redirect(data = '/'):
  338. return flask.redirect(flask.request.host_url[:-1] + data)
  339. def get_acl_list(type_d = 'normal'):
  340. if type_d == 'user':
  341. return ['', 'user', 'all']
  342. else:
  343. return ['', 'all', 'user', 'admin', 'owner', '50_edit', 'email', 'ban', 'before', '30_day', 'ban_admin']
  344. # Func-login
  345. def pw_encode(data, type_d = ''):
  346. if type_d == '':
  347. curs.execute(db_change('select data from other where name = "encode"'))
  348. set_data = curs.fetchall()
  349. type_d = set_data[0][0]
  350. if type_d == 'sha256':
  351. return hashlib.sha256(bytes(data, 'utf-8')).hexdigest()
  352. else:
  353. if sys.version_info < (3, 6):
  354. return sha3.sha3_256(bytes(data, 'utf-8')).hexdigest()
  355. else:
  356. return hashlib.sha3_256(bytes(data, 'utf-8')).hexdigest()
  357. def pw_check(data, data2, type_d = 'no', id_d = ''):
  358. curs.execute(db_change('select data from other where name = "encode"'))
  359. db_data = curs.fetchall()
  360. if type_d != 'no':
  361. if type_d == '':
  362. set_data = 'sha3'
  363. else:
  364. set_data = type_d
  365. else:
  366. set_data = db_data[0][0]
  367. re_data = 1 if pw_encode(data, set_data) == data2 else 0
  368. if db_data[0][0] != set_data and re_data == 1 and id_d != '':
  369. curs.execute(db_change("update user set pw = ?, encode = ? where id = ?"), [pw_encode(data), db_data[0][0], id_d])
  370. return re_data
  371. # Func-skin
  372. def easy_minify(data, tool = None):
  373. return data
  374. def load_lang(data, num = 2, safe = 0):
  375. global global_lang
  376. for i in range(0, 2):
  377. if i == 0:
  378. ip = ip_check()
  379. if ip_or_user(ip) == 0:
  380. curs.execute(db_change('select data from user_set where name = "lang" and id = ?'), [ip])
  381. rep_data = curs.fetchall()
  382. else:
  383. if 'lang' in flask.session:
  384. rep_data = [[flask.session['lang']]]
  385. else:
  386. continue
  387. else:
  388. curs.execute(db_change("select data from other where name = 'language'"))
  389. rep_data = curs.fetchall()
  390. if rep_data and rep_data[0][0] != '' and rep_data[0][0] != 'default':
  391. try:
  392. if not rep_data[0][0] in global_lang:
  393. lang = json.loads(open(os.path.join('lang', rep_data[0][0] + '.json'), encoding='utf8').read())
  394. global_lang[rep_data[0][0]] = lang
  395. else:
  396. lang = global_lang[rep_data[0][0]]
  397. except:
  398. continue
  399. if data in lang:
  400. return lang[data] if safe == 1 else html.escape(lang[data])
  401. else:
  402. continue
  403. else:
  404. continue
  405. return html.escape(data + ' (' + rep_data[0][0] + ')')
  406. def skin_check(set_n = 0):
  407. skin_list = load_skin('tenshi', 1)
  408. skin = skin_list[0]
  409. check_list = []
  410. ip = ip_check()
  411. if ip_or_user(ip) == 0:
  412. curs.execute(db_change('select data from user_set where name = "skin" and id = ?'), [ip])
  413. skin_exist = curs.fetchall()
  414. check_list += skin_exist
  415. else:
  416. if 'skin' in flask.session:
  417. check_list += [[flask.session['skin']]]
  418. curs.execute(db_change('select data from other where name = "skin"'))
  419. skin_exist = curs.fetchall()
  420. check_list += skin_exist
  421. for i in check_list:
  422. if i[0] != '' and i[0] in skin_list:
  423. skin = i[0]
  424. break
  425. return './views/' + skin + '/index.html' if set_n == 0 else skin
  426. def other2(data):
  427. global data_css
  428. global data_css_ver
  429. data += ['' for _ in range(0, 3 - len(data))]
  430. if data_css == '':
  431. for i_data in os.listdir(os.path.join("views", "main_css", "css")):
  432. if i_data != 'sub':
  433. data_css += '<link rel="stylesheet" href="/views/main_css/css/' + i_data + '?ver=' + data_css_ver + '">'
  434. for i_data in os.listdir(os.path.join("views", "main_css", "js")):
  435. if i_data != 'sub':
  436. data_css += '<script src="/views/main_css/js/' + i_data + '?ver=' + data_css_ver + '"></script>'
  437. data = data[0:2] + ['', '''
  438. <link rel="stylesheet"
  439. href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.7.2/build/styles/default.min.css">
  440. <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.7.2/build/highlight.min.js"></script>
  441. <link defer rel="stylesheet"
  442. href="https://cdn.jsdelivr.net/npm/katex@0.13.2/dist/katex.min.css"
  443. integrity="sha384-Cqd8ihRLum0CCg8rz0hYKPoLZ3uw+gES2rXQXycqnL5pgVQIflxAUDS7ZSjITLb5"
  444. crossorigin="anonymous">
  445. <script src="https://cdn.jsdelivr.net/npm/katex@0.13.2/dist/katex.min.js"
  446. integrity="sha384-1Or6BdeNQb0ezrmtGeqQHFpppNd7a/gw29xeiSikBbsb44xu3uAo8c7FwbF5jhbd"
  447. crossorigin="anonymous"></script>
  448. ''' + data_css + '<script>window.addEventListener(\'DOMContentLoaded\', main_css_skin_load);</script>'] + data[2:]
  449. return data
  450. def cut_100(data):
  451. if re.search(r'^\/w\/', flask.request.path):
  452. data = re.sub(r'<script>((\n*(((?!<\/script>).)+)\n*)+)<\/script>', '', data)
  453. data = re.sub(r'<hr class="main_hr">((\n*((.+)\n*))+)$', '', data)
  454. data = re.sub(r'<div id="cate_all">((\n*((.+)\n*))+)$', '', data)
  455. data = re.sub(r'<(((?!>).)*)>', ' ', data)
  456. data = re.sub(r'\n', ' ', data)
  457. data = re.sub(r'^ +', '', data)
  458. data = re.sub(r' +$', '', data)
  459. data = re.sub(r' {2,}', ' ', data)
  460. return data[0:100] + '...'
  461. else:
  462. return ''
  463. def wiki_set(num = 1):
  464. if num == 1:
  465. skin_name = skin_check(1)
  466. data_list = []
  467. curs.execute(db_change('select data from other where name = ?'), ['name'])
  468. db_data = curs.fetchall()
  469. data_list += [db_data[0][0]] if db_data and db_data[0][0] != '' else ['Wiki']
  470. curs.execute(db_change('select data from other where name = "license"'))
  471. db_data = curs.fetchall()
  472. data_list += [db_data[0][0]] if db_data and db_data[0][0] != '' else ['ARR']
  473. data_list += ['', '']
  474. curs.execute(db_change('select data from other where name = "logo" and coverage = ?'), [skin_name])
  475. db_data = curs.fetchall()
  476. if db_data and db_data[0][0] != '':
  477. data_list += [db_data[0][0]]
  478. else:
  479. curs.execute(db_change('select data from other where name = "logo" and coverage = ""'))
  480. db_data = curs.fetchall()
  481. data_list += [db_data[0][0]] if db_data and db_data[0][0] != '' else [data_list[0]]
  482. head_data = ''
  483. curs.execute(db_change("select data from other where name = 'head' and coverage = ''"))
  484. db_data = curs.fetchall()
  485. head_data += db_data[0][0] if db_data and db_data[0][0] != '' else ''
  486. curs.execute(db_change("select data from other where name = 'head' and coverage = ?"), [skin_name])
  487. db_data = curs.fetchall()
  488. head_data += db_data[0][0] if db_data and db_data[0][0] != '' else ''
  489. data_list += [head_data]
  490. elif num == 2:
  491. curs.execute(db_change('select data from other where name = "frontpage"'))
  492. db_data = curs.fetchall()
  493. data_list = db_data[0][0] if db_data and db_data[0][0] != '' else 'FrontPage'
  494. elif num == 3:
  495. curs.execute(db_change('select data from other where name = "upload"'))
  496. db_data = curs.fetchall()
  497. data_list = db_data[0][0] if db_data and db_data[0][0] != '' else '2'
  498. else:
  499. data_list = ''
  500. return data_list
  501. def custom():
  502. ip = ip_check()
  503. if ip_or_user(ip) == 0:
  504. user_icon = 1
  505. user_name = ip
  506. curs.execute(db_change("select data from user_set where id = ? and name = 'custom_css'"), [ip])
  507. user_head = curs.fetchall()
  508. user_head = user_head[0][0] if user_head else ''
  509. curs.execute(db_change('select data from user_set where name = "email" and id = ?'), [ip])
  510. email = curs.fetchall()
  511. email = email[0][0] if email else ''
  512. if admin_check('all') == 1:
  513. user_admin = '1'
  514. user_acl_list = []
  515. curs.execute(db_change("select acl from user where id = ?"), [ip])
  516. curs.execute(db_change('select acl from alist where name = ?'), [curs.fetchall()[0][0]])
  517. user_acl = curs.fetchall()
  518. for i in user_acl:
  519. user_acl_list += [i[0]]
  520. user_acl_list = user_acl_list if user_acl != [] else '0'
  521. else:
  522. user_admin = '0'
  523. user_acl_list = '0'
  524. curs.execute(db_change("select count(*) from alarm where name = ?"), [ip])
  525. count = curs.fetchall()
  526. user_notice = str(count[0][0]) if count else '0'
  527. else:
  528. user_icon = 0
  529. user_name = load_lang('user')
  530. email = ''
  531. user_admin = '0'
  532. user_acl_list = '0'
  533. user_notice = '0'
  534. user_head = flask.session['head'] if 'head' in flask.session else ''
  535. curs.execute(db_change("select title from rd where title = ? and stop = ''"), ['user:' + ip])
  536. user_topic = '1' if curs.fetchall() else '0'
  537. return [
  538. '',
  539. '',
  540. user_icon,
  541. user_head,
  542. email,
  543. user_name,
  544. user_admin,
  545. str(ban_check()),
  546. user_notice,
  547. user_acl_list,
  548. ip,
  549. user_topic
  550. ]
  551. def load_skin(data = '', set_n = 0, default = 0):
  552. # data -> 가장 앞에 있을 스킨 이름
  553. # set_n == 0 -> 스트링으로 반환
  554. # set_n == 1 -> 리스트로 반환
  555. # default == 0 -> 디폴트 미포함
  556. # default == 1 -> 디폴트 포함
  557. skin_return_data = '' if set_n == 0 else []
  558. system_file = ['main_css']
  559. skin_list_get = os.listdir(os.path.abspath('views'))
  560. if default == 1:
  561. skin_list_get += ['default']
  562. if data == '':
  563. curs.execute(db_change('select data from user_set where name = "skin" and id = ?'), [ip_check()])
  564. data = curs.fetchall()
  565. if not data:
  566. curs.execute(db_change('select data from other where name = "skin"'))
  567. data = curs.fetchall()
  568. if not data or data[0][0] == '':
  569. if default == 1:
  570. data = [['default']]
  571. else:
  572. data = [['tenshi']]
  573. else:
  574. data = [[data]]
  575. for skin_data in skin_list_get:
  576. see_data = skin_data if skin_data != 'default' else load_lang('default')
  577. if not skin_data in system_file:
  578. if data[0][0] == skin_data:
  579. if set_n == 0:
  580. skin_return_data = '<option value="' + skin_data + '">' + see_data + '</option>' + skin_return_data
  581. else:
  582. skin_return_data = [skin_data] + skin_return_data
  583. else:
  584. if set_n == 0:
  585. skin_return_data += '<option value="' + skin_data + '">' + see_data + '</option>'
  586. else:
  587. skin_return_data += [skin_data]
  588. return skin_return_data
  589. # Func-markup
  590. def render_set(doc_name = '', doc_data = '', data_type = 'view', data_in = '', doc_acl = ''):
  591. # data_type in ['view', 'raw', 'api_view', 'backlink']
  592. doc_acl = acl_check(doc_name, 'render') if doc_acl == '' else doc_acl
  593. doc_data = 0 if not doc_data else doc_data
  594. if doc_acl == 1:
  595. return 'HTTP Request 401.3'
  596. else:
  597. if data_type == 'raw':
  598. return doc_data
  599. else:
  600. if doc_data != 0:
  601. return render_do(doc_name, doc_data, data_type, data_in)
  602. else:
  603. return 'HTTP Request 404'
  604. # Func-request
  605. def send_email(who, title, data):
  606. try:
  607. curs.execute(db_change('' + \
  608. 'select name, data from other ' + \
  609. 'where name = "smtp_email" or name = "smtp_pass" or name = "smtp_server" or name = "smtp_port" or name = "smtp_security"' + \
  610. ''))
  611. rep_data = curs.fetchall()
  612. smtp_email = ''
  613. smtp_pass = ''
  614. smtp_server = ''
  615. smtp_security = ''
  616. smtp_port = ''
  617. smtp = ''
  618. for i in rep_data:
  619. if i[0] == 'smtp_email':
  620. smtp_email = i[1]
  621. elif i[0] == 'smtp_pass':
  622. smtp_pass = i[1]
  623. elif i[0] == 'smtp_server':
  624. smtp_server = i[1]
  625. elif i[0] == 'smtp_security':
  626. smtp_security = i[1]
  627. elif i[0] == 'smtp_port':
  628. smtp_port = i[1]
  629. smtp_port = int(smtp_port)
  630. if smtp_security == 'plain':
  631. smtp = smtplib.SMTP(smtp_server, smtp_port)
  632. elif smtp_security == 'starttls':
  633. smtp = smtplib.SMTP(smtp_server, smtp_port)
  634. smtp.starttls()
  635. else:
  636. # if smtp_security == 'tls':
  637. smtp = smtplib.SMTP_SSL(smtp_server, smtp_port)
  638. smtp.login(smtp_email, smtp_pass)
  639. domain = load_domain()
  640. wiki_name = wiki_set()[0]
  641. msg = email.mime.text.MIMEText(data)
  642. msg['Subject'] = title
  643. msg['From'] = 'openNAMU <noreply@' + domain + '>'
  644. msg['To'] = who
  645. smtp.sendmail('openNAMU@' + domain, who, msg.as_string())
  646. smtp.quit()
  647. return 1
  648. except Exception as e:
  649. print('----')
  650. print('Error : email send error')
  651. print(e)
  652. return 0
  653. def captcha_get():
  654. data = ''
  655. if ip_or_user() != 0:
  656. curs.execute(db_change('select data from other where name = "recaptcha"'))
  657. recaptcha = curs.fetchall()
  658. if recaptcha and recaptcha[0][0] != '':
  659. curs.execute(db_change('select data from other where name = "sec_re"'))
  660. sec_re = curs.fetchall()
  661. if sec_re and sec_re[0][0] != '':
  662. curs.execute(db_change('select data from other where name = "recaptcha_ver"'))
  663. rec_ver = curs.fetchall()
  664. if not rec_ver or rec_ver[0][0] == '':
  665. data += '' + \
  666. '<script src="https://www.google.com/recaptcha/api.js" async defer></script>' + \
  667. '<div class="g-recaptcha" data-sitekey="' + recaptcha[0][0] + '"></div>' + \
  668. '<hr class="main_hr">' + \
  669. ''
  670. else:
  671. data += '' + \
  672. '<script src="https://www.google.com/recaptcha/api.js?render=' + recaptcha[0][0] + '"></script>' + \
  673. '<input type="hidden" id="g-recaptcha" name="g-recaptcha">' + \
  674. '<script type="text/javascript">' + \
  675. 'grecaptcha.ready(function() {' + \
  676. 'grecaptcha.execute(\'' + recaptcha[0][0] + '\', {action: \'homepage\'}).then(function(token) {' + \
  677. 'document.getElementById(\'g-recaptcha\').value = token;' + \
  678. '});' + \
  679. '});' + \
  680. '</script>' + \
  681. ''
  682. return data
  683. def captcha_post(re_data, num = 1):
  684. if num == 1:
  685. curs.execute(db_change('select data from other where name = "sec_re"'))
  686. sec_re = curs.fetchall()
  687. if sec_re and sec_re[0][0] != '' and ip_or_user() != 0 and captcha_get() != '':
  688. try:
  689. data = urllib.request.urlopen('https://www.google.com/recaptcha/api/siteverify?secret=' + sec_re[0][0] + '&response=' + re_data)
  690. except:
  691. data = None
  692. if data and data.getcode() == 200:
  693. json_data = json.loads(data.read().decode(data.headers.get_content_charset()))
  694. if json_data['success'] == True:
  695. return 0
  696. else:
  697. return 1
  698. else:
  699. return 0
  700. else:
  701. return 0
  702. else:
  703. pass
  704. # Func-user
  705. def ip_or_user(data = ''):
  706. if data == '':
  707. data = ip_check()
  708. if re.search(r'(\.|:)', data):
  709. return 1
  710. else:
  711. return 0
  712. def admin_check(num = None, what = None, name = ''):
  713. ip = ip_check() if name == '' else name
  714. time_data = get_time()
  715. curs.execute(db_change("select acl from user where id = ?"), [ip])
  716. user = curs.fetchall()
  717. if user:
  718. back_num = num
  719. while 1:
  720. if num == 1:
  721. check = 'ban'
  722. elif num == 2:
  723. check = 'nothing'
  724. elif num == 3:
  725. check = 'toron'
  726. elif num == 4:
  727. check = 'check'
  728. elif num == 5:
  729. check = 'acl'
  730. elif num == 6:
  731. check = 'hidel'
  732. elif num == 7:
  733. check = 'give'
  734. else:
  735. check = 'owner'
  736. curs.execute(db_change('select name from alist where name = ? and acl = ?'), [user[0][0], check])
  737. if curs.fetchall():
  738. if what:
  739. curs.execute(db_change("insert into re_admin (who, what, time) values (?, ?, ?)"), [ip, what, time_data])
  740. conn.commit()
  741. return 1
  742. else:
  743. if back_num == 'all':
  744. if num == 'all':
  745. num = 1
  746. elif num != 8:
  747. num += 1
  748. else:
  749. break
  750. elif num:
  751. num = None
  752. else:
  753. break
  754. return 0
  755. def acl_check(name = 'test', tool = '', topic_num = '1'):
  756. ip = ip_check()
  757. get_ban = ban_check()
  758. acl_c = re.search(r"^user:((?:(?!\/).)*)", name) if name else None
  759. if tool == '' and acl_c:
  760. acl_n = acl_c.groups()
  761. if get_ban == 1:
  762. return 1
  763. if admin_check(5) == 1:
  764. return 0
  765. curs.execute(db_change("select data from acl where title = ? and type = 'decu'"), ['user:' + acl_n[0]])
  766. acl_data = curs.fetchall()
  767. if acl_data:
  768. if acl_data[0][0] == 'all':
  769. return 0
  770. elif acl_data[0][0] == 'user' and not ip_or_user(ip) == 1:
  771. return 0
  772. elif ip == acl_n[0] and not ip_or_user(ip) == 1:
  773. return 0
  774. else:
  775. if ip == acl_n[0] and not ip_or_user(ip) == 1 and not ip_or_user(acl_n[0]) == 1:
  776. return 0
  777. return 1
  778. if tool == 'topic':
  779. if not name:
  780. curs.execute(db_change("select title from rd where code = ?"), [topic_num])
  781. name = curs.fetchall()
  782. name = name[0][0] if name else 'test'
  783. end = 3
  784. elif tool == 'render' or tool == '' or tool == 'vote':
  785. if tool == '' and acl_check(name, 'render') == 1:
  786. return 1
  787. end = 2
  788. else:
  789. end = 1
  790. for i in range(0, end):
  791. if tool == '':
  792. if i == 0:
  793. curs.execute(db_change("select data from acl where title = ? and type = 'decu'"), [name])
  794. else:
  795. curs.execute(db_change('select data from other where name = "edit"'))
  796. num = 5
  797. elif tool == 'topic':
  798. if i == 0 and topic_num:
  799. curs.execute(db_change("select acl from rd where code = ?"), [topic_num])
  800. elif i == 1:
  801. curs.execute(db_change("select data from acl where title = ? and type = 'dis'"), [name])
  802. else:
  803. curs.execute(db_change('select data from other where name = "discussion"'))
  804. num = 3
  805. elif tool == 'upload':
  806. curs.execute(db_change("select data from other where name = 'upload_acl'"))
  807. num = 5
  808. elif tool == 'many_upload':
  809. curs.execute(db_change("select data from other where name = 'many_upload_acl'"))
  810. num = 5
  811. elif tool == 'vote':
  812. if i == 0:
  813. curs.execute(db_change('select acl from vote where id = ? and user = ""'), [topic_num])
  814. else:
  815. curs.execute(db_change('select data from other where name = "vote_acl"'))
  816. num = None
  817. else:
  818. # tool == 'render'
  819. if i == 0:
  820. curs.execute(db_change("select data from acl where title = ? and type = 'view'"), [name])
  821. else:
  822. curs.execute(db_change("select data from other where name = 'all_view_acl'"))
  823. num = 5
  824. acl_data = curs.fetchall()
  825. if (i == (end - 1) and (not acl_data or acl_data[0][0] == '' or acl_data[0][0] == 'normal')) and \
  826. get_ban == 1 and \
  827. tool != 'render':
  828. return 1
  829. elif acl_data and acl_data[0][0] != 'normal' and acl_data[0][0] != '':
  830. if acl_data[0][0] != 'ban' and get_ban == 1 and tool != 'render':
  831. return 1
  832. if acl_data[0][0] == 'all' or acl_data[0][0] == 'ban':
  833. return 0
  834. elif acl_data[0][0] == 'user':
  835. if ip_or_user(ip) != 1:
  836. return 0
  837. elif acl_data[0][0] == 'admin':
  838. if ip_or_user(ip) != 1:
  839. if admin_check(num) == 1:
  840. return 0
  841. elif acl_data[0][0] == '50_edit':
  842. if ip_or_user(ip) != 1:
  843. if admin_check(num) == 1:
  844. return 0
  845. else:
  846. curs.execute(db_change("select count(*) from history where ip = ?"), [ip])
  847. count = curs.fetchall()
  848. count = count[0][0] if count else 0
  849. if count >= 50:
  850. return 0
  851. elif acl_data[0][0] == 'before':
  852. if ip_or_user(ip) != 1:
  853. if admin_check(num) == 1:
  854. return 0
  855. curs.execute(db_change("select ip from history where title = ? and ip = ?"), [name, ip])
  856. if curs.fetchall():
  857. return 0
  858. elif acl_data[0][0] == '30_day':
  859. if ip_or_user(ip) != 1:
  860. if admin_check(num) == 1:
  861. return 0
  862. else:
  863. curs.execute(db_change("select date from user where id = ?"), [ip])
  864. user_date = curs.fetchall()[0][0]
  865. time_1 = datetime.datetime.strptime(user_date, '%Y-%m-%d %H:%M:%S') + datetime.timedelta(days = 30)
  866. time_2 = datetime.datetime.strptime(get_time(), '%Y-%m-%d %H:%M:%S')
  867. if time_2 > time_1:
  868. return 0
  869. elif acl_data[0][0] == 'email':
  870. if ip_or_user(ip) != 1:
  871. if admin_check(num) == 1:
  872. return 0
  873. else:
  874. curs.execute(db_change("select data from user_set where id = ? and name = 'email'"), [ip])
  875. if curs.fetchall():
  876. return 0
  877. elif acl_data[0][0] == 'owner':
  878. if admin_check() == 1:
  879. return 0
  880. elif acl_data[0][0] == 'ban_admin':
  881. if admin_check(1) == 1 or ban_check() == 1:
  882. return 0
  883. return 1
  884. else:
  885. if i == (end - 1):
  886. if tool == 'topic' and topic_num:
  887. curs.execute(db_change("select title from rd where code = ? and stop != ''"), [topic_num])
  888. if curs.fetchall():
  889. if admin_check(3, 'topic (code ' + topic_num + ')') == 1:
  890. return 0
  891. else:
  892. return 0
  893. else:
  894. return 0
  895. return 1
  896. def ban_check(ip = None, tool = None):
  897. ip = ip_check() if not ip else ip
  898. if admin_check(None, None, ip) == 1:
  899. return 0
  900. curs.execute(db_change("update rb set ongoing = '' where end < ? and end != '' and ongoing = '1'"), [get_time()])
  901. conn.commit()
  902. curs.execute(db_change("" + \
  903. "select login, block from rb " + \
  904. "where ((end > ? and end != '') or end = '') and band = 'regex' and ongoing = '1'" + \
  905. ""), [get_time()])
  906. regex_d = curs.fetchall()
  907. for test_r in regex_d:
  908. g_regex = re.compile(test_r[1])
  909. if g_regex.search(ip):
  910. if tool and tool == 'login':
  911. if test_r[0] != 'O':
  912. return 1
  913. else:
  914. return 1
  915. curs.execute(db_change("" + \
  916. "select login from rb " + \
  917. "where ((end > ? and end != '') or end = '') and block = ? and band = '' and ongoing = '1'" + \
  918. ""), [get_time(), ip])
  919. ban_d = curs.fetchall()
  920. if ban_d:
  921. if tool and tool == 'login':
  922. if ban_d[0][0] != 'O':
  923. return 1
  924. else:
  925. return 1
  926. return 0
  927. def ip_pas(raw_ip, type_d = 0):
  928. hide = 0
  929. end_ip = {}
  930. i = 0
  931. return_data = 0
  932. if type(raw_ip) != type([]):
  933. get_ip = [raw_ip]
  934. return_data = 1
  935. else:
  936. get_ip = raw_ip
  937. curs.execute(db_change("select data from other where name = 'ip_view'"))
  938. ip_view = curs.fetchall()
  939. ip_view = ip_view[0][0] if ip_view else ''
  940. ip_view = '' if admin_check(1) == 1 else ip_view
  941. get_ip = list(set(get_ip))
  942. for raw_ip in get_ip:
  943. change_ip = 0
  944. is_this_ip = ip_or_user(raw_ip)
  945. if is_this_ip != 0 and ip_view != '':
  946. ip = re.sub(r'\.([^.]*)\.([^.]*)$', '.*.*', raw_ip)
  947. ip = re.sub(r':([^:]*):([^:]*)$', ':*:*', raw_ip)
  948. change_ip = 1
  949. ip = raw_ip
  950. if type_d == 0:
  951. if is_this_ip == 0:
  952. ip = '<a href="/w/' + url_pas('user:' + raw_ip) + '">' + raw_ip + '</a>'
  953. if change_ip == 0:
  954. ip += ' <a href="/tool/' + url_pas(raw_ip) + '">(' + load_lang('tool') + ')</a>'
  955. end_ip[raw_ip] = ip
  956. if return_data == 1:
  957. return end_ip[raw_ip]
  958. else:
  959. return end_ip
  960. # Func-edit
  961. def slow_edit_check():
  962. curs.execute(db_change("select data from other where name = 'slow_edit'"))
  963. slow_edit = curs.fetchall()
  964. if slow_edit and slow_edit != '0' and admin_check(5) != 1:
  965. slow_edit = slow_edit[0][0]
  966. curs.execute(db_change("select date from history where ip = ? order by date desc limit 1"), [ip_check()])
  967. last_edit_data = curs.fetchall()
  968. if last_edit_data:
  969. last_edit_data = int(re.sub(' |:|-', '', last_edit_data[0][0]))
  970. now_edit_data = int((datetime.datetime.now() - datetime.timedelta(seconds = int(slow_edit))).strftime("%Y%m%d%H%M%S"))
  971. if last_edit_data > now_edit_data:
  972. return 1
  973. return 0
  974. def edit_filter_do(data):
  975. if admin_check(1) != 1:
  976. curs.execute(db_change("select plus, plus_t from html_filter where kind = 'regex_filter' and plus != ''"))
  977. for data_list in curs.fetchall():
  978. match = re.compile(data_list[0], re.I)
  979. if match.search(data):
  980. ban_insert(
  981. ip_check(),
  982. '0' if data_list[1] == 'X' else data_list[1],
  983. 'edit filter',
  984. None,
  985. 'tool:edit filter'
  986. )
  987. return 1
  988. return 0
  989. # Func-insert
  990. def add_alarm(who, context):
  991. curs.execute(db_change('insert into alarm (name, data, date) values (?, ?, ?)'), [who, context, get_time()])
  992. def ua_plus(id, ip, ua, time):
  993. curs.execute(db_change("select data from other where name = 'ua_get'"))
  994. rep_data = curs.fetchall()
  995. if rep_data and rep_data[0][0] != '':
  996. pass
  997. else:
  998. curs.execute(db_change("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')"), [id, ip, ua, time])
  999. def ban_insert(name, end, why, login, blocker, type_d = None):
  1000. now_time = get_time()
  1001. band = type_d if type_d else ''
  1002. curs.execute(db_change("update rb set ongoing = '' where end < ? and end != '' and ongoing = '1'"), [now_time])
  1003. curs.execute(db_change("" + \
  1004. "select block from rb where ((end > ? and end != '') or end = '') and block = ? and band = ? and ongoing = '1'" + \
  1005. ""), [now_time, name, band])
  1006. if curs.fetchall():
  1007. curs.execute(db_change("insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, ?)"), [
  1008. name,
  1009. 'release',
  1010. now_time,
  1011. blocker,
  1012. '',
  1013. band
  1014. ])
  1015. curs.execute(db_change("update rb set ongoing = '' where block = ? and band = ? and ongoing = '1'"), [name, band])
  1016. else:
  1017. login = 'O' if login != '' else ''
  1018. if end != '0':
  1019. end = int(number_check(end))
  1020. time = datetime.datetime.now()
  1021. plus = datetime.timedelta(seconds = end)
  1022. r_time = (time + plus).strftime("%Y-%m-%d %H:%M:%S")
  1023. else:
  1024. r_time = ''
  1025. curs.execute(db_change("insert into rb (block, end, today, blocker, why, band, ongoing, login) values (?, ?, ?, ?, ?, ?, '1', ?)"), [
  1026. name,
  1027. r_time,
  1028. now_time,
  1029. blocker,
  1030. why,
  1031. band,
  1032. login
  1033. ])
  1034. conn.commit()
  1035. def rd_plus(topic_num, date, name = None, sub = None):
  1036. curs.execute(db_change("select code from rd where code = ?"), [topic_num])
  1037. if curs.fetchall():
  1038. curs.execute(db_change("update rd set date = ? where code = ?"), [date, topic_num])
  1039. else:
  1040. curs.execute(db_change("insert into rd (title, sub, code, date) values (?, ?, ?, ?)"), [name, sub, topic_num, date])
  1041. conn.commit()
  1042. def history_plus(title, data, date, ip, send, leng, t_check = '', mode = ''):
  1043. if mode == 'add':
  1044. curs.execute(db_change("select id from history where title = ? order by id + 0 asc limit 1"), [title])
  1045. id_data = curs.fetchall()
  1046. id_data = str(int(id_data[0][0]) - 1) if id_data else '0'
  1047. else:
  1048. curs.execute(db_change("select id from history where title = ? order by id + 0 desc limit 1"), [title])
  1049. id_data = curs.fetchall()
  1050. id_data = str(int(id_data[0][0]) + 1) if id_data else '1'
  1051. mode = mode if not re.search('^user:', title) else 'user'
  1052. send = re.sub(r'\(|\)|<|>', '', send)
  1053. send = send[:128] if len(send) > 128 else send
  1054. send = send + ' (' + t_check + ')' if t_check != '' else send
  1055. if mode != 'add' and mode != 'user':
  1056. curs.execute(db_change("select count(*) from rc where type = 'normal'"))
  1057. if curs.fetchall()[0][0] >= 200:
  1058. curs.execute(db_change("select id, title from rc where type = 'normal' order by date asc limit 1"))
  1059. rc_data = curs.fetchall()
  1060. if rc_data:
  1061. curs.execute(db_change('delete from rc where id = ? and title = ? and type = "normal"'), [
  1062. rc_data[0][0],
  1063. rc_data[0][1]
  1064. ])
  1065. curs.execute(db_change("insert into rc (id, title, date, type) values (?, ?, ?, 'normal')"), [
  1066. id_data,
  1067. title,
  1068. date
  1069. ])
  1070. if mode != 'add':
  1071. curs.execute(db_change("select count(*) from rc where type = ?"), [mode])
  1072. if curs.fetchall()[0][0] >= 200:
  1073. curs.execute(db_change("select id, title from rc where type = ? order by date asc limit 1"), [mode])
  1074. rc_data = curs.fetchall()
  1075. if rc_data:
  1076. curs.execute(db_change('delete from rc where id = ? and title = ? and type = ?'), [
  1077. rc_data[0][0],
  1078. rc_data[0][1],
  1079. mode
  1080. ])
  1081. curs.execute(db_change("insert into rc (id, title, date, type) values (?, ?, ?, ?)"), [
  1082. id_data,
  1083. title,
  1084. date,
  1085. mode
  1086. ])
  1087. curs.execute(db_change("insert into history (id, title, data, date, ip, send, leng, hide, type) values (?, ?, ?, ?, ?, ?, ?, '', ?)"), [
  1088. id_data,
  1089. title,
  1090. data,
  1091. date,
  1092. ip,
  1093. send,
  1094. leng,
  1095. mode
  1096. ])
  1097. # Func-error
  1098. def re_error(data):
  1099. conn.commit()
  1100. if data == '/ban':
  1101. if ban_check() == 1:
  1102. end = '<div id="get_user_info"></div><script>load_user_info("' + ip_check() + '");</script>'
  1103. else:
  1104. end = '<ul class="inside_ul"><li>' + load_lang('authority_error') + '</li></ul>'
  1105. return easy_minify(flask.render_template(skin_check(),
  1106. imp = [load_lang('error'), wiki_set(1), custom(), other2([0, 0])],
  1107. data = '<h2>' + load_lang('error') + '</h2>' + end,
  1108. menu = 0
  1109. )), 401
  1110. else:
  1111. num = int(number_check(data.replace('/error/', '')))
  1112. if num == 1:
  1113. data = load_lang('no_login_error')
  1114. elif num == 2:
  1115. data = load_lang('no_exist_user_error')
  1116. elif num == 3:
  1117. data = load_lang('authority_error')
  1118. elif num == 4:
  1119. data = load_lang('no_admin_block_error')
  1120. elif num == 5:
  1121. data = load_lang('skin_error')
  1122. elif num == 6:
  1123. data = load_lang('same_id_exist_error')
  1124. elif num == 7:
  1125. data = load_lang('long_id_error')
  1126. elif num == 8:
  1127. data = load_lang('id_char_error') + ' <a href="/name_filter">(' + load_lang('id_filter_list') + ')</a>'
  1128. elif num == 9:
  1129. data = load_lang('file_exist_error')
  1130. elif num == 10:
  1131. data = load_lang('password_error')
  1132. elif num == 11:
  1133. data = load_lang('topic_long_error')
  1134. elif num == 12:
  1135. data = load_lang('email_error')
  1136. elif num == 13:
  1137. data = load_lang('recaptcha_error')
  1138. elif num == 14:
  1139. data = load_lang('file_extension_error') + ' <a href="/extension_filter">(' + load_lang('extension_filter_list') + ')</a>'
  1140. elif num == 15:
  1141. data = load_lang('edit_record_error')
  1142. elif num == 16:
  1143. data = load_lang('same_file_error')
  1144. elif num == 17:
  1145. data = load_lang('file_capacity_error') + wiki_set(3)
  1146. elif num == 18:
  1147. data = load_lang('email_send_error')
  1148. elif num == 19:
  1149. data = load_lang('decument_exist_error')
  1150. elif num == 20:
  1151. data = load_lang('password_diffrent_error')
  1152. elif num == 21:
  1153. data = load_lang('edit_filter_error')
  1154. elif num == 22:
  1155. data = load_lang('file_name_error')
  1156. elif num == 23:
  1157. data = load_lang('regex_error')
  1158. elif num == 24:
  1159. curs.execute(db_change("select data from other where name = 'slow_edit'"))
  1160. data = load_lang('fast_edit_error') + curs.fetchall()[0][0]
  1161. elif num == 25:
  1162. data = load_lang('too_many_dec_error')
  1163. elif num == 26:
  1164. data = load_lang('application_not_found')
  1165. elif num == 27:
  1166. data = load_lang("invalid_password_error")
  1167. elif num == 28:
  1168. data = load_lang('watchlist_overflow_error')
  1169. elif num == 29:
  1170. data = load_lang('copyright_disagreed')
  1171. elif num == 30:
  1172. data = load_lang('ie_wrong_callback')
  1173. elif num == 33:
  1174. data = load_lang('restart_fail_error')
  1175. elif num == 34:
  1176. data = load_lang("update_error") + ' <a href="https://github.com/2DU/opennamu">(Github)</a>'
  1177. elif num == 35:
  1178. data = load_lang('same_email_error')
  1179. elif num == 36:
  1180. data = load_lang('input_email_error')
  1181. else:
  1182. data = '???'
  1183. if num == 5:
  1184. get_url = flask.request.path
  1185. return easy_minify(flask.render_template(skin_check(),
  1186. imp = [(load_lang('skin_set') if get_url != '/main_skin_set' else load_lang('main_skin_set')), wiki_set(1), custom(), other2([0, 0])],
  1187. data = '' + \
  1188. '<div id="main_skin_set">' + \
  1189. '<h2>' + load_lang('error') + '</h2>' + \
  1190. '<ul class="inside_ul">' + \
  1191. '<li>' + data + ' <a href="/main_skin_set">(' + load_lang('main_skin_set') + ')</a></li>' + \
  1192. '</ul>' + \
  1193. '</div>' + \
  1194. ('<script>main_css_skin_set();</script>' if get_url == '/main_skin_set' else ''),
  1195. menu = ([['main_skin_set', load_lang('main_skin_set')]] if get_url != '/main_skin_set' else [['skin_set', load_lang('skin_set')]])
  1196. ))
  1197. else:
  1198. return easy_minify(flask.render_template(skin_check(),
  1199. imp = [load_lang('error'), wiki_set(1), custom(), other2([0, 0])],
  1200. data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + data + '</li></ul>',
  1201. menu = 0
  1202. )), 400