func.py 50 KB

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