func.py 50 KB

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