from flask import Flask, request, session, render_template, send_file from werkzeug import secure_filename app = Flask(__name__) from urllib import parse import json import pymysql import time import re import bcrypt import os import difflib json_data = open('set.json').read() data = json.loads(json_data) print('오픈나무 시작 포트 : ' + data['port']) import logging log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) app.config['MAX_CONTENT_LENGTH'] = int(data['upload']) * 1024 * 1024 conn = pymysql.connect(host = data['host'], user = data['user'], password = data['pw'], db = data['db'], charset = 'utf8mb4') curs = conn.cursor(pymysql.cursors.DictCursor) app.secret_key = data['key'] ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif']) def show_diff(seqm): output= [] for opcode, a0, a1, b0, b1 in seqm.get_opcodes(): if opcode == 'equal': output.append(seqm.a[a0:a1]) elif opcode == 'insert': output.append("" + seqm.b[b0:b1] + "") elif opcode == 'delete': output.append("" + seqm.a[a0:a1] + "") return ''.join(output) def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS def admincheck(): if(session.get('Now') == True): ip = getip(request) curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'): return 1 def namumark(title, data): data = re.sub('<', '<', data) data = re.sub('>', '>', data) data = re.sub('"', '"', data) while True: m = re.search("\[include\((((?!\)\]).)*)\)\]", data) if(m): results = m.groups() if(results[0] == title): data = re.sub("\[include\((((?!\)\]).)*)\)\]", "" + results[0] + "", data, 1) else: curs.execute("select * from data where title = '" + pymysql.escape_string(results[0]) + "'") rows = curs.fetchall() if(rows): enddata = rows[0]['data'] enddata = re.sub("\[include\((((?!\)\]).)*)\)\]", "", enddata) enddata = re.sub('<', '<', enddata) enddata = re.sub('>', '>', enddata) enddata = re.sub('"', '"', enddata) data = re.sub("\[include\((((?!\)\]).)*)\)\]", enddata, data, 1) else: data = re.sub("\[include\((((?!\)\]).)*)\)\]", "[[" + results[0] + "]]", data, 1) else: break while True: m = re.search('^#(?:redirect|넘겨주기)\s([^\n]*)', data) if(m): results = m.groups() data = re.sub('^#(?:redirect|넘겨주기)\s([^\n]*)', '', data, 1) else: break data = '\n' + data + '\n' while True: m = re.search("\n>\s?((?:[^\n]*)(?:(?:(?:(?:\n>\s?)(?:[^\n]*))+)?))", data) if(m): result = m.groups() blockquote = result[0] blockquote = re.sub("\n>\s?", "\n", blockquote) data = re.sub("\n>\s?((?:[^\n]*)(?:(?:(?:(?:\n>\s?)(?:[^\n]*))+)?))", "\n
" + blockquote + "
", data, 1) else: break h0c = 0; h1c = 0; h2c = 0; h3c = 0; h4c = 0; h5c = 0; last = 0; rtoc = '
목차

' while True: m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', data) if(m): result = m.groups() wiki = len(result[0]) if(last < wiki): last = wiki else: last = wiki; if(wiki == 1): h1c = 0 h2c = 0 h3c = 0 h4c = 0 h5c = 0 elif(wiki == 2): h2c = 0 h3c = 0 h4c = 0 h5c = 0 elif(wiki == 3): h3c = 0 h4c = 0 h5c = 0 elif(wiki == 4): h4c = 0 h5c = 0 elif(wiki == 5): h5c = 0 if(wiki == 1): h0c = h0c + 1 elif(wiki == 2): h1c = h1c + 1 elif(wiki == 3): h2c = h2c + 1 elif(wiki == 4): h3c = h3c + 1 elif(wiki == 5): h4c = h4c + 1 else: h5c = h5c + 1 toc = str(h0c) + '.' + str(h1c) + '.' + str(h2c) + '.' + str(h3c) + '.' + str(h4c) + '.' + str(h5c) + '.' toc = re.sub("(?P[0-9]0(?:[0]*)?)\.", '\g#.', toc) toc = re.sub("0\.", '', toc) toc = re.sub("#\.", '.', toc) toc = re.sub("\.$", '', toc) rtoc = rtoc + '' + toc + '. ' + result[1] + '
' data = re.sub('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', '' + toc + '. ' + result[1] + '', data, 1); else: rtoc = rtoc + '
' break data = re.sub("\[목차\]", rtoc, data) data = re.sub("\[\[분류:(((?!\]\]).)*)\]\]", '', data) while True: p = re.compile("{{{((?:(?!{{{)(?!}}}).)*)}}}", re.DOTALL) m = p.search(data) if(m): results = m.groups() q = re.compile("^\+([1-5])\s(.*)$", re.DOTALL) n = q.search(results[0]) w = re.compile("^\-([1-5])\s(.*)$", re.DOTALL) a = w.search(results[0]) e = re.compile("^(#[0-9a-f-A-F]{6})\s(.*)$", re.DOTALL) b = e.search(results[0]) r = re.compile("^(#[0-9a-f-A-F]{3})\s(.*)$", re.DOTALL) c = r.search(results[0]) t = re.compile("^#(\w+)\s(.*)$", re.DOTALL) d = t.search(results[0]) qqq = re.compile("^@([0-9a-f-A-F]{6})\s(.*)$", re.DOTALL) qqe = qqq.search(results[0]) qqw = re.compile("^@([0-9a-f-A-F]{3})\s(.*)$", re.DOTALL) qqa = qqw.search(results[0]) qwe = re.compile("^@(\w+)\s(.*)$", re.DOTALL) qsd = qwe.search(results[0]) y = re.compile("^#!wiki\sstyle="((?:(?!"|\n).)*)"\n?\s\n(.*)$", re.DOTALL) l = y.search(results[0]) if(n): result = n.groups() data = p.sub('' + result[1] + '', data, 1) elif(a): result = a.groups() data = p.sub('' + result[1] + '', data, 1) elif(b): result = b.groups() data = p.sub('' + result[1] + '', data, 1) elif(c): result = c.groups() data = p.sub('' + result[1] + '', data, 1) elif(d): result = d.groups() data = p.sub('' + result[1] + '', data, 1) elif(qqe): result = qqe.groups() data = p.sub('' + result[1] + '', data, 1) elif(qqa): result = qqa.groups() data = p.sub('' + result[1] + '', data, 1) elif(qsd): result = qsd.groups() data = p.sub('' + result[1] + '', data, 1) elif(l): result = l.groups() data = p.sub('
' + result[1] + '
', data, 1) else: data = p.sub(results[0], data, 1) else: break data = re.sub("'''(?P.+?)'''(?!')", '\g', data) data = re.sub("''(?P.+?)''(?!')", '\g', data) data = re.sub('~~(?P.+?)~~(?!~)', '\g', data) data = re.sub('--(?P.+?)--(?!-)', '\g', data) data = re.sub('__(?P.+?)__(?!_)', '\g', data) data = re.sub('\^\^(?P.+?)\^\^(?!\^)', '\g', data) data = re.sub(',,(?P.+?),,(?!,)', '\g', data) data = re.sub('{{\|(?P(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '
\g
', data) data = re.sub("##\s?(?P[^\n]*)\n", "
\g
", data); while True: m = re.search("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", data) if(m): c = m.groups() if(c[1]): n = re.search("width=([^ \n&]*)", c[1]) e = re.search("height=([^ \n&]*)", c[1]) if(n): a = n.groups() width = a[0] else: width = '' if(e): b = e.groups() height = b[0] else: height = '' img = re.sub("\.(?Pjpg|png|gif|jpeg)", "#\g#", c[0]) data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", '', data, 1) else: img = re.sub("\.(?Pjpg|png|gif|jpeg)", "#\g#", c[0]) data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", "", data, 1) else: break data = re.sub("\[br\]",'
', data); while True: m = re.search("\[youtube\(((?:(?!,|\)\]).)*)(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?(?:,\s)?(?:height=((?:(?!,|\)\]).)*))?(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?\)\]", data) if(m): result = m.groups() if(result[1]): if(result[2]): width = result[1] height = result[2] else: width = result[1] height = '315' elif(result[2]): if(result[3]): height = result[2] width = result[3] else: height = result[2] width = '560' else: width = '560' height = '315' data = re.sub("\[youtube\(((?:(?!,|\)\]).)*)(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?(?:,\s)?(?:height=((?:(?!,|\)\]).)*))?(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?\)\]", '', data, 1) else: break while True: m = re.search("(http(?:s)?:\/\/(?:(?:(?:(?!\.jpg|\.png|\.gif|\.jpeg|#jpg#|#png#|#gif#|#jpeg#).)*)(?:\.jpg|\.png|\.gif|\.jpeg)))(?:(?:(?:\?)width=((?:[0-9]*)(?:px)?))?(?:(?:\?|&)height=((?:[0-9]*)(?:px)?))?(?:(?:&)width=((?:[0-9]*)(?:px)?))?)?", data) if(m): result = m.groups() if(result[1]): if(result[2]): width = result[1] height = result[2] else: width = result[1] height = '' elif(result[2]): if(result[3]): height = result[2] width = result[3] else: height = result[2] width = '' else: width = '' height = '' c = result[0] c = re.sub("\.(?Pjpg|png|gif|jpeg)", "#\g#", c) data = re.sub("(http(?:s)?:\/\/(?:(?:(?:(?!\.jpg|\.png|\.gif|\.jpeg|#jpg#|#png#|#gif#|#jpeg#).)*)(?:\.jpg|\.png|\.gif|\.jpeg)))(?:(?:(?:\?)width=((?:[0-9]*)(?:px)?))?(?:(?:\?|&)height=((?:[0-9]*)(?:px)?))?(?:(?:&)width=((?:[0-9]*)(?:px)?))?)?", "", data, 1) else: break while True: m = re.search("\[\[(((?!\]\]).)*)\]\]", data) if(m): result = m.groups() a = re.search("(((?!\|).)*)\|(.*)", result[0]) if(a): results = a.groups() b = re.search("^http(?:s)?:\/\/", results[0]) if(b): c = re.search("(?:\.jpg|\.png|\.gif|\.jpeg)", results[0]) if(c): img = results[0] img = re.sub("\.(?Pjpg|png|gif|jpeg)", "#\g#", img) data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + results[2] + '', data, 1) else: data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + results[2] + '', data, 1) else: if(results[0] == title): data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + results[2] + '', data, 1) else: curs.execute("select * from data where title = '" + pymysql.escape_string(results[0]) + "'") rows = curs.fetchall() if(rows): data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + results[2] + '', data, 1) else: data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + results[2] + '', data, 1) else: b = re.search("^http(?:s)?:\/\/", result[0]) if(b): c = re.search("(?:\.jpg|\.png|\.gif|\.jpeg)", result[0]) if(c): img = result[0] img = re.sub("\.(?Pjpg|png|gif|jpeg)", "#\g#", img) data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + '', data, 1) else: data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + '', data, 1) else: if(result[0] == title): data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + '', data, 1) else: curs.execute("select * from data where title = '" + pymysql.escape_string(result[0]) + "'") rows = curs.fetchall() if(rows): data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + '', data, 1) else: data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + '', data, 1) else: break while True: m = re.search("((?:(?:\s\*\s[^\n]*)\n?)+)", data) if(m): result = m.groups() end = str(result[0]) end = re.sub("\s\*\s(?P[^\n]*)", "
  • \g
  • ", end) end = re.sub("\n", '', end) data = re.sub("((?:(?:\s\*\s[^\n]*)\n?)+)", '
      ' + end + '
    ', data, 1) else: break data = re.sub('\[date\]', getnow(), data) data = re.sub("\[anchor\((?P[^\[\]]*)\)\]", '', data) data = re.sub("#(?Pjpg|png|gif|jpeg)#", ".\g", data) data = re.sub("-{4,11}", "
    ", data) while True: b = re.search("\r\n( +)", data) if(b): result = b.groups() tp = len(result[0]) up = '' i = 0 while True: up = up + '' i = i + 1 if(i == tp): break data = re.sub("\r\n( +)", '
    ' + up, data, 1) else: break a = 1 tou = "

    " while True: b = re.search("\[\*([^\s]*)\s(((?!\]).)*)\]", data) if(b): results = b.groups() if(results[0]): c = results[1] c = re.sub("<(?:[^>]*)>", '', c) tou = tou + "[" + results[0] + "] " + results[1] + "
    " data = re.sub("\[\*([^\s]*)\s(((?!\]).)*)\]", "[" + results[0] + "]", data, 1) else: c = results[1] c = re.sub("<(?:[^>]*)>", '', c) tou = tou + "[" + str(a) + "] " + results[1] + "
    " data = re.sub("\[\*([^\s]*)\s(((?!\]).)*)\]", '[' + str(a) + ']', data, 1) a = a + 1 else: tou = tou + '
    ' if(tou == "

    "): tou = "" break data = re.sub("\[각주\](?:(?:(?:
    +)*(?:\s+)*(?:\r+)*(?:\n+))+)?$", "", data) data = re.sub("\[각주\]", "
    " + tou, data) data = data + tou; while True: m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data) if(m): results = m.groups() table = results[0] while True: a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", table) if(a): row = '' cel = '' celstyle = '' rowstyle = '' alltable = '' result = a.groups() if(result[1]): q = re.search("<table\s?width=((?:(?!>).)*)>", result[1]) w = re.search("<table\s?height=((?:(?!>).)*)>", result[1]) e = re.search("<table\s?align=((?:(?!>).)*)>", result[1]) alltable = 'style="' celstyle = 'style="' rowstyle = 'style="' if(q): resultss = q.groups() alltable = alltable + 'width:' + resultss[0] + ';' if(w): resultss = w.groups() alltable = alltable + 'height:' + resultss[0] + ';' if(e): resultss = e.groups() if(resultss[0] == 'right'): alltable = alltable + 'margin-left:auto;' elif(resultss[0] == 'center'): alltable = alltable + 'margin:auto;' else: alltable = alltable + 'margin-right:auto;' ee = re.search("<table\s?textalign=((?:(?!>).)*)>", result[1]) if(ee): resultss = ee.groups() if(resultss[0] == 'right'): alltable = alltable + 'text-align:right;' elif(resultss[0] == 'center'): alltable = alltable + 'text-align:center;' else: alltable = alltable + 'text-align:left;' r = re.search("<-((?:(?!>).)*)>", result[1]) if(r): resultss = r.groups() cel = 'colspan="' + resultss[0] + '"' else: cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"' t = re.search("<\|((?:(?!>).)*)>", result[1]) if(t): resultss = t.groups() row = 'rowspan="' + resultss[0] + '"' ba = re.search("<rowbgcolor=(#[0-9a-f-A-F]{6})>", result[1]) bb = re.search("<rowbgcolor=(#[0-9a-f-A-F]{3})>", result[1]) bc = re.search("<rowbgcolor=(\w+)>", result[1]) if(ba): resultss = ba.groups() rowstyle = rowstyle + 'background:' + resultss[0] + ';' elif(bb): resultss = bb.groups() rowstyle = rowstyle + 'background:' + resultss[0] + ';' elif(bc): resultss = bc.groups() rowstyle = rowstyle + 'background:' + resultss[0] + ';' z = re.search("<table\s?bordercolor=(#[0-9a-f-A-F]{6})>", result[1]) x = re.search("<table\s?bordercolor=(#[0-9a-f-A-F]{3})>", result[1]) c = re.search("<table\s?bordercolor=(\w+)>", result[1]) if(z): resultss = z.groups() alltable = alltable + 'border:' + resultss[0] + ' 2px solid;' elif(x): resultss = x.groups() alltable = alltable + 'border:' + resultss[0] + ' 2px solid;' elif(c): resultss = c.groups() alltable = alltable + 'border:' + resultss[0] + ' 2px solid;' aq = re.search("<table\s?bgcolor=(#[0-9a-f-A-F]{6})>", result[1]) aw = re.search("<table\s?bgcolor=(#[0-9a-f-A-F]{3})>", result[1]) ae = re.search("<table\s?bgcolor=(\w+)>", result[1]) if(aq): resultss = aq.groups() alltable = alltable + 'background:' + resultss[0] + ';' elif(aw): resultss = aw.groups() alltable = alltable + 'background:' + resultss[0] + ';' elif(ae): resultss = ae.groups() alltable = alltable + 'background:' + resultss[0] + ';' j = re.search("<bgcolor=(#[0-9a-f-A-F]{6})>", result[1]) k = re.search("<bgcolor=(#[0-9a-f-A-F]{3})>", result[1]) l = re.search("<bgcolor=(\w+)>", result[1]) if(j): resultss = j.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' elif(k): resultss = k.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' elif(l): resultss = l.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' aa = re.search("<(#[0-9a-f-A-F]{6})>", result[1]) ab = re.search("<(#[0-9a-f-A-F]{3})>", result[1]) ac = re.search("<(\w+)>", result[1]) if(aa): resultss = aa.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' elif(ab): resultss = ab.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' elif(ac): resultss = ac.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' qa = re.search("<width=((?:(?!>).)*)>", result[1]) qb = re.search("<height=((?:(?!>).)*)>", result[1]) if(qa): resultss = qa.groups() celstyle = celstyle + 'width:' + resultss[0] + ';' if(qb): resultss = qb.groups() celstyle = celstyle + 'height:' + resultss[0] + ';' i = re.search("<\)>", result[1]) o = re.search("<:>", result[1]) p = re.search("<\(>", result[1]) if(i): celstyle = celstyle + 'text-align:right;' elif(o): celstyle = celstyle + 'text-align:center;' elif(p): celstyle = celstyle + 'text-align:left;' alltable = alltable + '"' celstyle = celstyle + '"' rowstyle = rowstyle + '"' table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "
    ", table, 1) else: cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"' table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "
    ", table, 1) else: break table = re.sub("\|\|$", "
    ", table) while True: b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", table) if(b): row = '' cel = '' celstyle = '' rowstyle = '' result = b.groups() if(result[1]): celstyle = 'style="' rowstyle = 'style="' r = re.search("<-((?:(?!>).)*)>", result[1]) if(r): resultss = r.groups() cel = 'colspan="' + resultss[0] + '"' else: cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"' t = re.search("<\|((?:(?!>).)*)>", result[1]) if(t): resultss = t.groups() row = 'rowspan="' + resultss[0] + '"' ba = re.search("<rowbgcolor=(#[0-9a-f-A-F]{6})>", result[1]) bb = re.search("<rowbgcolor=(#[0-9a-f-A-F]{3})>", result[1]) bc = re.search("<rowbgcolor=(\w+)>", result[1]) if(ba): resultss = ba.groups() rowstyle = rowstyle + 'background:' + resultss[0] + ';' elif(bb): resultss = bb.groups() rowstyle = rowstyle + 'background:' + resultss[0] + ';' elif(bc): resultss = bc.groups() rowstyle = rowstyle + 'background:' + resultss[0] + ';' j = re.search("<bgcolor=(#[0-9a-f-A-F]{6})>", result[1]) k = re.search("<bgcolor=(#[0-9a-f-A-F]{3})>", result[1]) l = re.search("<bgcolor=(\w+)>", result[1]) if(j): resultss = j.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' elif(k): resultss = k.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' elif(l): resultss = l.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' aa = re.search("<(#[0-9a-f-A-F]{6})>", result[1]) ab = re.search("<(#[0-9a-f-A-F]{3})>", result[1]) ac = re.search("<(\w+)>", result[1]) if(aa): resultss = aa.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' elif(ab): resultss = ab.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' elif(ac): resultss = ac.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' qa = re.search("<width=((?:(?!>).)*)>", result[1]) qb = re.search("<height=((?:(?!>).)*)>", result[1]) if(qa): resultss = qa.groups() celstyle = celstyle + 'width:' + resultss[0] + ';' if(qb): resultss = qb.groups() celstyle = celstyle + 'height:' + resultss[0] + ';' i = re.search("<\)>", result[1]) o = re.search("<:>", result[1]) p = re.search("<\(>", result[1]) if(i): celstyle = celstyle + 'text-align:right;' elif(o): celstyle = celstyle + 'text-align:center;' elif(p): celstyle = celstyle + 'text-align:left;' celstyle = celstyle + '"' rowstyle = rowstyle + '"' table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "
    ", table, 1) else: cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"' table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "
    ", table, 1) else: break while True: c = re.search("(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", table) if(c): row = '' cel = '' celstyle = '' result = c.groups() if(result[1]): celstyle = 'style="' r = re.search("<-((?:(?!>).)*)>", result[1]) if(r): resultss = r.groups() cel = 'colspan="' + resultss[0] + '"'; else: cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"' t = re.search("<\|((?:(?!>).)*)>", result[1]) if(t): resultss = t.groups() row = 'rowspan="' + resultss[0] + '"'; j = re.search("<bgcolor=(#[0-9a-f-A-F]{6})>", result[1]) k = re.search("<bgcolor=(#[0-9a-f-A-F]{3})>", result[1]) l = re.search("<bgcolor=(\w+)>", result[1]) if(j): resultss = j.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' elif(k): resultss = k.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' elif(l): resultss = l.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' aa = re.search("<(#[0-9a-f-A-F]{6})>", result[1]) ab = re.search("<(#[0-9a-f-A-F]{3})>", result[1]) ac = re.search("<(\w+)>", result[1]) if(aa): resultss = aa.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' elif(ab): resultss = ab.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' elif(ac): resultss = ac.groups() celstyle = celstyle + 'background:' + resultss[0] + ';' qa = re.search("<width=((?:(?!>).)*)>", result[1]) qb = re.search("<height=((?:(?!>).)*)>", result[1]) if(qa): resultss = qa.groups() celstyle = celstyle + 'width:' + resultss[0] + ';' if(qb): resultss = qb.groups() celstyle = celstyle + 'height:' + resultss[0] + ';' i = re.search("<\)>", result[1]) o = re.search("<:>", result[1]) p = re.search("<\(>", result[1]) if(i): celstyle = celstyle + 'text-align:right;' elif(o): celstyle = celstyle + 'text-align:center;' elif(p): celstyle = celstyle + 'text-align:left;' celstyle = celstyle + '"' table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "", table, 1) else: cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"' table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "", table, 1) else: break data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1) else: break data = re.sub('\n', '
    ', data) data = re.sub('^
    ', '', data) return str(data) def getip(request): if(session.get('Now') == True): ip = format(session['DREAMER']) else: if(request.headers.getlist("X-Forwarded-For")): ip = request.headers.getlist("X-Forwarded-For")[0] else: ip = request.remote_addr return ip def getcan(ip, name): m = re.search("^사용자:(.*)", name) if(m): g = m.groups() if(ip == g[0]): if(re.search("\.", g[0])): return 1 else: curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): return 1 else: return 0 else: return 1 else: b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)", ip) if(b): results = b.groups() curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'") rowss = curs.fetchall() if(rowss): return 1 else: curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): return 1 else: curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") row = curs.fetchall() if(row): curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(row[0]['acl'] == 'user'): if(rows): return 0 else: return 1 elif(row[0]['acl'] == 'admin'): if(rows): if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'): return 0 else: return 1 else: return 1 else: return 0 else: return 0 else: curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): return 1 else: curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") row = curs.fetchall() if(row): curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(row[0]['acl'] == 'user'): if(rows): return 0 else: return 1 elif(row[0]['acl'] == 'admin'): if(rows): if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'): return 0 else: return 1 else: return 1 else: return 0 else: return 0 def getban(ip): b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)", ip) if(b): results = b.groups() curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'") rowss = curs.fetchall() if(rowss): return 1 else: curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): return 1 else: return 0 else: curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): return 1 else: return 0 def getdiscuss(ip, name, sub): b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)", ip) if(b): results = b.groups() curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'") rowss = curs.fetchall() if(rowss): return 1 else: curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): return 1 else: curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "'") rows = curs.fetchall() if(rows): return 1 else: return 0 else: curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): return 1 else: curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "'") rows = curs.fetchall() if(rows): return 1 else: return 0 def getnow(): now = time.localtime() s = "%04d-%02d-%02d %02d:%02d:%02d" % (now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec) return s def discuss(title, sub, date): curs.execute("select * from rd where title = '" + pymysql.escape_string(title) + "' and sub = '" + pymysql.escape_string(sub) + "'") rows = curs.fetchall() if(rows): curs.execute("update rd set date = '" + pymysql.escape_string(date) + "' where title = '" + pymysql.escape_string(title) + "' and sub = '" + pymysql.escape_string(sub) + "'") else: curs.execute("insert into rd (title, sub, date) value ('" + pymysql.escape_string(title) + "', '" + pymysql.escape_string(sub) + "', '" + pymysql.escape_string(date) + "')") conn.commit() def block(block, end, today, blocker, why): curs.execute("insert into rb (block, end, today, blocker, why) value ('" + pymysql.escape_string(block) + "', '" + pymysql.escape_string(end) + "', '" + today + "', '" + pymysql.escape_string(blocker) + "', '" + pymysql.escape_string(why) + "')") conn.commit() def history(title, data, date, ip, send, leng): curs.execute("select * from history where title = '" + pymysql.escape_string(title) + "' order by id+0 desc limit 1") rows = curs.fetchall() if(rows): number = int(rows[0]['id']) + 1 curs.execute("insert into history (id, title, data, date, ip, send, leng) value ('" + str(number) + "', '" + pymysql.escape_string(title) + "', '" + pymysql.escape_string(data) + "', '" + date + "', '" + pymysql.escape_string(ip) + "', '" + pymysql.escape_string(send) + "', '" + leng + "')") conn.commit() else: curs.execute("insert into history (id, title, data, date, ip, send, leng) value ('1', '" + pymysql.escape_string(title) + "', '" + pymysql.escape_string(data) + "', '" + date + "', '" + pymysql.escape_string(ip) + "', '" + pymysql.escape_string(send + ' (새 문서)') + "', '" + leng + "')") conn.commit() def getleng(existing, change): if(existing < change): leng = change - existing leng = '+' + str(leng) elif(change < existing): leng = existing - change leng = '-' + str(leng) else: leng = '0' return leng; @app.route('/upload', methods=['GET', 'POST']) def upload(): if(request.method == 'POST'): ip = getip(request) ban = getban(ip) if(ban == 1): return '' else: file = request.files['file'] if(file and allowed_file(file.filename)): filename = secure_filename(file.filename) if(os.path.exists(os.path.join('image', filename))): return render_template('index.html', logo = data['name'], title = '업로드', data = '동일한 이름의 파일이 있습니다.') else: file.save(os.path.join('image', filename)) return render_template('index.html', logo = data['name'], title = '업로드', data = '완료 되었습니다.') else: return render_template('index.html', logo = data['name'], title = '업로드', data = 'jpg gif jpeg png만 가능 합니다.') else: ip = getip(request) ban = getban(ip) if(ban == 1): return '' else: return render_template('index.html', logo = data['name'], title = '업로드', tn = 21, number = data['upload']) @app.route('/image/') def image(name = None): filename = secure_filename(name) return send_file(os.path.join('image', filename), mimetype='image') @app.route('/') @app.route('/w/') def redirect(): return '' @app.route('/recentchanges') def recentchanges(): i = 0 div = '
    ' curs.execute("select * from history order by date desc limit 50") rows = curs.fetchall() if(rows): admin = admincheck() while True: try: a = rows[i] except: div = div + '
    ' break if(rows[i]['send']): send = rows[i]['send'] send = re.sub('(?P[^&]*)<\/a>', '\g', send) else: send = '
    ' title = rows[i]['title'] title = re.sub('<', '<', title) title = re.sub('>', '>', title) m = re.search("\+", rows[i]['leng']) n = re.search("\-", rows[i]['leng']) if(m): leng = '' + rows[i]['leng'] + '' elif(n): leng = '' + rows[i]['leng'] + '' else: leng = '' + rows[i]['leng'] + '' if(admin == 1): curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(row): if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'): ban = '' else: curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(row): ban = ' (해제)' else: ban = ' (차단)' else: curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(row): ban = ' (해제)' else: ban = ' (차단)' else: ban = '' if(re.search('\.', rows[i]['ip'])): ip = rows[i]['ip'] else: curs.execute("select * from data where title = '사용자:" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(row): ip = '' + rows[i]['ip'] + '' else: ip = '' + rows[i]['ip'] + '' if((int(rows[i]['id']) - 1) == 0): revert = '' else: revert = '(되돌리기)' div = div + '
    ' + title + ' (역사) ' + revert + ' (' + leng + ')' + ip + ban + '' + rows[i]['date'] + '
    ' + send + '
    ' i = i + 1 return render_template('index.html', logo = data['name'], rows = div, tn = 3, title = '최근 변경내역') else: return render_template('index.html', logo = data['name'], rows = '', tn = 3, title = '최근 변경내역') @app.route('/record//n/') def record(name = None, number = None): v = number * 50 i = v - 50 div = '
    ' curs.execute("select * from history where ip = '" + name + "' order by date desc") rows = curs.fetchall() if(rows): admin = admincheck() while True: try: a = rows[i] except: div = div + '
    ' if(number == 1): div = div + '
    (다음)' else: div = div + '
    (이전)' break if(rows[i]['send']): send = rows[i]['send'] send = re.sub('(?P[^&]*)<\/a>', '\g', send) else: send = '
    ' title = rows[i]['title'] title = re.sub('<', '<', title) title = re.sub('>', '>', title) m = re.search("\+", rows[i]['leng']) n = re.search("\-", rows[i]['leng']) if(m): leng = '' + rows[i]['leng'] + '' elif(n): leng = '' + rows[i]['leng'] + '' else: leng = '' + rows[i]['leng'] + '' if(admin == 1): curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(row): if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'): ip = rows[i]['ip'] else: curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(row): ip = rows[i]['ip'] + ' (해제)' else: ip = rows[i]['ip'] + ' (차단)' else: curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(row): ip = rows[i]['ip'] + ' (해제)' else: ip = rows[i]['ip'] + ' (차단)' else: ip = rows[i]['ip'] if((int(rows[i]['id']) - 1) == 0): revert = '' else: revert = '(되돌리기)' div = div + '
    ' + title + ' r' + rows[i]['id'] + ' (역사) ' + revert + ' (' + leng + ')' + ip + '' + rows[i]['date'] + '
    ' + send + '
    ' if(i == v): div = div + '' if(number == 1): div = div + '
    (다음)' else: div = div + '
    (이전) (다음)' break else: i = i + 1 return render_template('index.html', logo = data['name'], rows = div, tn = 3, title = '유저 기록') else: return render_template('index.html', logo = data['name'], rows = '', tn = 3, title = '유저 기록') @app.route('/recentdiscuss') def recentdiscuss(): i = 0 div = '
    ' curs.execute("select * from rd order by date desc limit 50") rows = curs.fetchall() if(rows): while True: try: a = rows[i] except: div = div + '
    ' break title = rows[i]['title'] title = re.sub('<', '<', title) title = re.sub('>', '>', title) sub = rows[i]['sub'] sub = re.sub('<', '<', sub) sub = re.sub('>', '>', sub) div = div + '
    ' + title + ' (' + sub + ')' + rows[i]['date'] + '
    ' i = i + 1 return render_template('index.html', logo = data['name'], rows = div, tn = 12, title = '최근 토론내역') else: return render_template('index.html', logo = data['name'], rows = '', tn = 12, title = '최근 토론내역') @app.route('/recentblock') def recentblock(): i = 0 div = '
    ' curs.execute("select * from rb order by today desc limit 50") rows = curs.fetchall() if(rows): while True: try: a = rows[i] except: div = div + '
    ' break why = rows[i]['why'] why = re.sub('<', '<', why) why = re.sub('>', '>', why) div = div + '
    ' + rows[i]['block'] + '' + rows[i]['blocker'] + '' + rows[i]['end'] + '' + rows[i]['why'] + '' + rows[i]['today'] + '
    ' i = i + 1 return render_template('index.html', logo = data['name'], rows = div, tn = 20, title = '최근 차단내역') else: return render_template('index.html', logo = data['name'], rows = '', tn = 20, title = '최근 차단내역') @app.route('/history//n/', methods=['POST', 'GET']) def gethistory(name = None, number = None): if(request.method == 'POST'): return '' else: select = '' v = number * 50 i = v - 50 div = '
    ' curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' order by id+0 desc") rows = curs.fetchall() if(rows): admin = admincheck() while True: try: a = rows[i] except: div = div + '
    ' if(number != 1): div = div + '
    (이전)' break select = '' + select if(rows[i]['send']): send = rows[i]['send'] send = re.sub('(?P[^&]*)<\/a>', '\g', send) else: send = '
    ' m = re.search("\+", rows[i]['leng']) n = re.search("\-", rows[i]['leng']) if(m): leng = '' + rows[i]['leng'] + '' elif(n): leng = '' + rows[i]['leng'] + '' else: leng = '' + rows[i]['leng'] + '' if(admin == 1): curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(row): if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'): ban = '' else: curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(row): ban = ' (해제)' else: ban = ' (차단)' else: curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(row): ban = ' (해제)' else: ban = ' (차단)' else: ban = '' if(re.search("\.", rows[i]["ip"])): ip = rows[i]["ip"] else: curs.execute("select * from data where title = '사용자:" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(row): ip = '' + rows[i]['ip'] + '' else: ip = '' + rows[i]['ip'] + '' div = div + '
    r' + rows[i]['id'] + ' (w) (Raw) (되돌리기) (' + leng + ')' + ip + ban + '' + rows[i]['date'] + '
    ' + send + '
    ' if(i == v): div = div + '' if(number == 1): div = div + '
    (다음)' else: div = div + '
    (이전) (다음)' break else: i = i + 1 return render_template('index.html', logo = data['name'], rows = div, tn = 5, title = name, page = parse.quote(name).replace('/','%2F'), select = select) else: return render_template('index.html', logo = data['name'], rows = '', tn = 5, title = name, page = parse.quote(name).replace('/','%2F'), select = select) @app.route('/search', methods=['POST', 'GET']) def search(): if(request.method == 'POST'): curs.execute("select * from data where title = '" + pymysql.escape_string(request.form["search"]) + "'") rows = curs.fetchall() if(rows): return '' else: curs.execute("select * from data where title like '%" + pymysql.escape_string(request.form["search"]) + "%'") rows = curs.fetchall() div = '' if(rows): i = 0 div = div + '
  • 문서가 없습니다. 바로가기

  • ' while True: try: div = div + '
  • ' + rows[i]['title'] + '
  • ' except: break i = i + 1 else: return div + '' return render_template('index.html', logo = data['name'], data = div, title = '검색') else: return '' @app.route('/w/') def w(name = None): acl = '' m = re.search("^(.*)\/(.*)$", name) if(m): g = m.groups() uppage = g[0] style = "" else: uppage = "" style = "display:none;" m = re.search("^사용자:(.*)", name) if(m): g = m.groups() curs.execute("select * from user where id = '" + pymysql.escape_string(g[0]) + "'") rows = curs.fetchall() if(rows): if(rows[0]['acl'] == 'owner'): acl = '(소유자)' elif(rows[0]['acl'] == 'admin'): acl = '(관리자)' curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") rows = curs.fetchall() if(rows): if(rows[0]['acl'] == 'admin'): acl = '(관리자)' elif(rows[0]['acl'] == 'user'): acl = '(유저)' else: if(not acl): acl = '' enddata = namumark(name, rows[0]['data']) m = re.search('
    ((?:(?!\/div>).)*)<\/div>', enddata) if(m): result = m.groups() left = result[0] else: left = '' return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'], tn = 1, acl = acl, left = left, uppage = uppage, style = style) else: return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 1, uppage = uppage, style = style, acl = acl) @app.route('/w//redirect/') def redirectw(name = None, redirect = None): m = re.search("^(.*)\/(.*)$", name) if(m): g = m.groups() uppage = g[0] style = "" else: uppage = "" style = "display:none;" curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") rows = curs.fetchall() if(rows): if(rows[0]['acl'] == 'admin'): acl = '(관리자)' elif(rows[0]['acl'] == 'user'): acl = '(유저)' else: acl = '' newdata = rows[0]['data'] newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P[^\n]*)', ' * \g 문서로 넘겨주기', newdata) enddata = namumark(name, newdata) m = re.search('
    ((?:(?!\/div>).)*)<\/div>', enddata) if(m): result = m.groups() left = result[0] else: left = '' test = redirect redirect = re.sub('<', '<', redirect) redirect = re.sub('>', '>', redirect) redirect = re.sub('"', '"', redirect) return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'], tn = 1, redirect = '' + redirect + '에서 넘어 왔습니다.', left = left, acl = acl, uppage = uppage, style = style) else: test = redirect redirect = re.sub('<', '<', redirect) redirect = re.sub('>', '>', redirect) redirect = re.sub('"', '"', redirect) return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 1, redirect = '' + redirect + '에서 넘어 왔습니다.', uppage = uppage, style = style) @app.route('/w//r/') def rew(name = None, number = None): curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'") rows = curs.fetchall() if(rows): enddata = namumark(name, rows[0]['data']) m = re.search('
    ((?:(?!\/div>).)*)<\/div>', enddata) if(m): result = m.groups() left = result[0] else: left = '' return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'], tn = 6, left = left) else: return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 6) @app.route('/w//raw/') def reraw(name = None, number = None): curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'") rows = curs.fetchall() if(rows): enddata = re.sub('<', '<', rows[0]['data']) enddata = re.sub('>', '>', enddata) enddata = re.sub('"', '"', enddata) enddata = re.sub("\n", '
    ', enddata) return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license']) else: return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license']) @app.route('/raw/') def raw(name = None): curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") rows = curs.fetchall() if(rows): enddata = re.sub('<', '<', rows[0]['data']) enddata = re.sub('>', '>', enddata) enddata = re.sub('"', '"', enddata) enddata = re.sub("\n", '
    ', enddata) return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'], tn = 7) else: return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 7) @app.route('/revert//r/', methods=['POST', 'GET']) def revert(name = None, number = None): if(request.method == 'POST'): curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'") rows = curs.fetchall() if(rows): ip = getip(request) can = getcan(ip, name) if(can == 1): return '' else: today = getnow() curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") row = curs.fetchall() if(row): leng = getleng(len(row[0]['data']), len(rows[0]['data'])) curs.execute("update data set data = '" + pymysql.escape_string(rows[0]['data']) + "' where title = '" + pymysql.escape_string(name) + "'") conn.commit() else: leng = '+' + str(len(rows[0]['data'])) curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(rows[0]['data']) + "', '')") conn.commit() history(name, rows[0]['data'], today, ip, '문서를 ' + number + '판으로 되돌렸습니다.', leng) return '' else: return '' else: ip = getip(request) can = getcan(ip, name) if(can == 1): return '' else: curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'") rows = curs.fetchall() if(rows): return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), r = parse.quote(number).replace('/','%2F'), tn = 13, plus = '정말 되돌리시겠습니까?') else: return '' @app.route('/edit/', methods=['POST', 'GET']) def edit(name = None): if(request.method == 'POST'): curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") rows = curs.fetchall() m = re.search('(?:[^A-Za-zㄱ-힣0-9 ])', request.form["send"]) if(m): return render_template('index.html', title = '편집 오류', logo = data['name'], data = '편집 내용 기록에는 한글과 영어와 숫자, 공백만 허용 됩니다.') else: if(rows): ip = getip(request) can = getcan(ip, name) if(can == 1): return '' else: today = getnow() leng = getleng(len(rows[0]['data']), len(request.form["content"])) history(name, request.form["content"], today, ip, request.form["send"], leng) curs.execute("update data set data = '" + pymysql.escape_string(request.form["content"]) + "' where title = '" + pymysql.escape_string(name) + "'") conn.commit() else: ip = getip(request) can = getcan(ip, name) if(can == 1): return '' else: today = getnow() leng = '+' + str(len(request.form["content"])) history(name, request.form["content"], today, ip, request.form["send"], leng) curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(request.form["content"]) + "', '')") conn.commit() return '' else: ip = getip(request) can = getcan(ip, name) if(can == 1): return '' else: if(re.search('\.', ip)): notice = '비 로그인 상태 입니다. 비 로그인으로 편집시 아이피가 역사에 기록 됩니다. 편집 시 동의 함으로 간주 됩니다.' else: notice = '' curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") rows = curs.fetchall() if(rows): return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = rows[0]['data'], tn = 2, notice = notice) else: return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '', tn = 2, notice = notice) @app.route('/preview/', methods=['POST']) def preview(name = None): ip = getip(request) can = getcan(ip, name) if(can == 1): return '' else: if(re.search('\.', ip)): notice = '비 로그인 상태 입니다. 비 로그인으로 편집시 아이피가 역사에 기록 됩니다. 편집 시 동의 함으로 간주 됩니다.' else: notice = '' newdata = request.form["content"] newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P[^\n]*)', ' * \g 문서로 넘겨주기', newdata) enddata = namumark(name, newdata) m = re.search('
    ((?:(?!\/div>).)*)<\/div>', enddata) if(m): result = m.groups() left = result[0] else: left = '' return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = request.form["content"], tn = 2, preview = 1, enddata = enddata, left = left, notice = notice) @app.route('/delete/', methods=['POST', 'GET']) def delete(name = None): if(request.method == 'POST'): curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") rows = curs.fetchall() if(rows): ip = getip(request) can = getcan(ip, name) if(can == 1): return '' else: today = getnow() leng = '-' + str(len(rows[0]['data'])) history(name, '', today, ip, '문서를 삭제 했습니다.', leng) curs.execute("delete from data where title = '" + pymysql.escape_string(name) + "'") conn.commit() return '' else: return '' else: curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") rows = curs.fetchall() if(rows): ip = getip(request) can = getcan(ip, name) if(can == 1): return '' else: return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), tn = 8, plus = '정말 삭제 하시겠습니까?') else: return '' @app.route('/move/', methods=['POST', 'GET']) def move(name = None): if(request.method == 'POST'): curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") rows = curs.fetchall() if(rows): ip = getip(request) can = getcan(ip, name) if(can == 1): return '' else: today = getnow() leng = '0' curs.execute("select * from history where title = '" + pymysql.escape_string(request.form["title"]) + "'") row = curs.fetchall() if(row): return render_template('index.html', title = '이동 오류', logo = data['name'], data = '이동 하려는 곳에 문서가 이미 있습니다.') else: history(name, rows[0]['data'], today, ip, '' + name + ' 문서를 ' + request.form["title"] + ' 문서로 이동 했습니다.', leng) curs.execute("update data set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'") curs.execute("update history set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'") conn.commit() return '' else: ip = getip(request) can = getcan(ip, name) if(can == 1): return '' else: today = getnow() leng = '0' curs.execute("select * from history where title = '" + pymysql.escape_string(request.form["title"]) + "'") row = curs.fetchall() if(row): return render_template('index.html', title = '이동 오류', logo = data['name'], data = '이동 하려는 곳에 문서가 이미 있습니다.') else: history(name, '', today, ip, '' + name + ' 문서를 ' + request.form["title"] + ' 문서로 이동 했습니다.', leng) curs.execute("update history set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'") conn.commit() return '' else: ip = getip(request) can = getcan(ip, name) if(can == 1): return '' else: return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), tn = 9, plus = '정말 이동 하시겠습니까?') @app.route('/setup') def setup(): curs.execute("create table if not exists data(title text not null, data longtext not null, acl text not null)") curs.execute("create table if not exists history(id text not null, title text not null, data longtext not null, date text not null, ip text not null, send text not null, leng text not null)") curs.execute("create table if not exists rd(title text not null, sub text not null, date text not null)") curs.execute("create table if not exists user(id text not null, pw text not null, acl text not null)") curs.execute("create table if not exists ban(block text not null, end text not null, why text not null, band text not null)") curs.execute("create table if not exists topic(id text not null, title text not null, sub text not null, data longtext not null, date text not null, ip text not null, block text not null)") curs.execute("create table if not exists stop(title text not null, sub text not null, close text not null)") curs.execute("create table if not exists rb(block text not null, end text not null, today text not null, blocker text not null, why text not null)") curs.execute("create table if not exists login(user text not null, ip text not null, today text not null)") return render_template('index.html', title = '설치 완료', logo = data['name'], data = '문제 없었음') @app.route('/other') def other(): return render_template('index.html', title = '기타 메뉴', logo = data['name'], data = '
  • 모든 문서
  • 문법 설명
  • 버전
  • 최근 차단내역
  • 업로드
  • ') @app.route('/titleindex') def titleindex(): i = 0 div = '
    ' curs.execute("select * from data") rows = curs.fetchall() if(rows): while True: try: a = rows[i] except: div = div + '
    ' break div = div + '
  • ' + rows[i]['title'] + '
  • ' i = i + 1 return render_template('index.html', logo = data['name'], rows = div + '
    이 위키에는 총 ' + str(i + 1) + '개의 문서가 있습니다.', tn = 4, title = '모든 문서') else: return render_template('index.html', logo = data['name'], rows = '', tn = 4, title = '모든 문서') @app.route('/topic/', methods=['POST', 'GET']) def topic(name = None): if(request.method == 'POST'): return '' else: div = '
    ' i = 0 curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' order by sub asc") rows = curs.fetchall() while True: try: a = rows[i] except: div = div + '
    ' break j = i + 1 indata = namumark(name, rows[i]['data']) if(rows[i]['block'] == 'O'): indata = '블라인드 되었습니다.' block = 'style="background: gainsboro;"' else: block = '' if(i == 0): sub = rows[i]['sub'] curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'") row = curs.fetchall() if(not row): div = div + '

    ' + str((i + 1)) + '. ' + rows[i]['sub'] + '

    ' div = div + '
    #' + str(j) + ' ' + rows[i]['ip'] + ' ' + rows[i]['date'] + '
    ' + indata + '

    ' else: if(not sub == rows[i]['sub']): sub = rows[i]['sub'] curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'") row = curs.fetchall() if(not row): div = div + '

    ' + str((i + 1)) + '. ' + rows[i]['sub'] + '

    ' div = div + '
    #' + str(j) + ' ' + rows[i]['ip'] + ' ' + rows[i]['date'] + '
    ' + indata + '

    ' i = i + 1 return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], plus = div, tn = 10, list = 1) @app.route('/topic//close') def topicstoplist(name = None): if(request.method == 'POST'): return '' else: div = '
    ' i = 0 curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and close = 'O' order by sub asc") rows = curs.fetchall() while True: try: a = rows[i] except: div = div + '
    ' break curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(rows[i]['sub']) + "' and id = '1'") row = curs.fetchall() if(row): j = i + 1 indata = namumark(name, row[0]['data']) if(row[0]['block'] == 'O'): indata = '블라인드 되었습니다.' block = 'style="background: gainsboro;"' else: block = '' div = div + '

    ' + str((i + 1)) + '. ' + rows[i]['sub'] + '

    ' div = div + '
    #' + str(j) + ' ' + row[0]['ip'] + ' ' + row[0]['date'] + '
    ' + indata + '

    ' i = i + 1 return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], plus = div, tn = 10) @app.route('/topic//sub/', methods=['POST', 'GET']) def sub(name = None, sub = None): if(request.method == 'POST'): curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1") rows = curs.fetchall() if(rows): number = int(rows[0]['id']) + 1 else: number = 1 ip = getip(request) ban = getdiscuss(ip, name, sub) if(ban == 1): return '' else: curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'): ip = ip + ' - Admin' today = getnow() discuss(name, sub, today) curs.execute("insert into topic (id, title, sub, data, date, ip, block) value ('" + str(number) + "', '" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', '" + pymysql.escape_string(request.form["content"]) + "', '" + today + "', '" + ip + "', '')") conn.commit() return '' else: ip = getip(request) ban = getdiscuss(ip, name, sub) admin = admincheck() if(admin == 1): div = '
    ' + '(토론 닫기 및 열기)' + ' (토론 정지 및 재개)

    ' else: div = '
    ' i = 0 curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 asc") rows = curs.fetchall() while True: try: a = rows[i] except: div = div + '
    ' break if(i == 0): start = rows[i]['ip'] indata = namumark(name, rows[i]['data']) if(rows[i]['block'] == 'O'): indata = '블라인드 되었습니다.' block = 'style="background: gainsboro;"' else: block = '' m = re.search("([^-]*)\s\-\s(Close|Reopen|Stop|Restart)$", rows[i]['ip']) if(m): ban = "" else: if(admin == 1): curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(rows[i]['block'] == 'O'): isblock = ' (해제)' else: isblock = ' (블라인드)' n = re.search("\- (?:Admin)$", rows[i]['ip']) if(n): ban = isblock else: if(row): ban = ' (해제)' + isblock else: ban = ' (차단)' + isblock else: ban = "" m = re.search("([^-]*)\s\-\s(Close|Reopen|Stop|Restart|Admin)$", rows[i]['ip']) if(m): g = m.groups() curs.execute("select * from data where title = '사용자:" + pymysql.escape_string(g[0]) + "'") row = curs.fetchall() if(row): ip = '' + g[0] + ' - ' + g[1] else: ip = '' + g[0] + ' - ' + g[1] elif(re.search("\.", rows[i]["ip"])): ip = rows[i]["ip"] else: curs.execute("select * from data where title = '사용자:" + pymysql.escape_string(rows[i]['ip']) + "'") row = curs.fetchall() if(row): ip = '' + rows[i]['ip'] + '' else: ip = '' + rows[i]['ip'] + '' if(rows[i]['ip'] == start): j = i + 1 div = div + '
    #' + str(j) + ' ' + ip + ban + ' ' + rows[i]['date'] + '
    ' + indata + '

    ' else: j = i + 1 div = div + '
    #' + str(j) + ' ' + ip + ban + ' ' + rows[i]['date'] + '
    ' + indata + '

    ' i = i + 1 return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), suburl = parse.quote(sub).replace('/','%2F'), sub = sub, logo = data['name'], rows = div, tn = 11, ban = ban) @app.route('/topic//sub//b/') def blind(name = None, sub = None, number = None): if(session.get('Now') == True): ip = getip(request) curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'): curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'") row = curs.fetchall() if(row): if(row[0]['block'] == 'O'): curs.execute("update topic set block = '' where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'") else: curs.execute("update topic set block = 'O' where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'") conn.commit() return '' else: return '' else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.') @app.route('/topic//sub//stop') def topicstop(name = None, sub = None): if(session.get('Now') == True): ip = getip(request) curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'): curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1") row = curs.fetchall() if(row): today = getnow() curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = ''") rows = curs.fetchall() if(rows): curs.execute("insert into topic (id, title, sub, data, date, ip, block) value ('" + pymysql.escape_string(str(int(row[0]['id']) + 1)) + "', '" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', 'Restart', '" + pymysql.escape_string(today) + "', '" + pymysql.escape_string(ip) + " - Restart', '')") curs.execute("delete from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = ''") else: curs.execute("insert into topic (id, title, sub, data, date, ip, block) value ('" + pymysql.escape_string(str(int(row[0]['id']) + 1)) + "', '" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', 'Stop', '" + pymysql.escape_string(today) + "', '" + pymysql.escape_string(ip) + " - Stop', '')") curs.execute("insert into stop (title, sub, close) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', '')") conn.commit() return '' else: return '' else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.') @app.route('/topic//sub//close') def topicclose(name = None, sub = None): if(session.get('Now') == True): ip = getip(request) curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'): curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1") row = curs.fetchall() if(row): today = getnow() curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'") rows = curs.fetchall() if(rows): curs.execute("insert into topic (id, title, sub, data, date, ip, block) value ('" + pymysql.escape_string(str(int(row[0]['id']) + 1)) + "', '" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', 'Reopen', '" + pymysql.escape_string(today) + "', '" + pymysql.escape_string(ip) + " - Reopen', '')") curs.execute("delete from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'") else: curs.execute("insert into topic (id, title, sub, data, date, ip, block) value ('" + pymysql.escape_string(str(int(row[0]['id']) + 1)) + "', '" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', 'Close', '" + pymysql.escape_string(today) + "', '" + pymysql.escape_string(ip) + " - Close', '')") curs.execute("insert into stop (title, sub, close) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', 'O')") conn.commit() return '' else: return '' else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.') @app.route('/login', methods=['POST', 'GET']) def login(): if(request.method == 'POST'): ip = getip(request) ban = getban(ip) if(ban == 1): return '' else: curs.execute("select * from user where id = '" + pymysql.escape_string(request.form["id"]) + "'") rows = curs.fetchall() if(rows): if(session.get('Now') == True): return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '이미 로그인 되어 있습니다.') elif(bcrypt.checkpw(bytes(request.form["pw"], 'utf-8'), bytes(rows[0]['pw'], 'utf-8'))): session['Now'] = True session['DREAMER'] = request.form["id"] curs.execute("insert into login (user, ip, today) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(ip) + "', '" + pymysql.escape_string(getnow()) + "')") conn.commit() return '' else: return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '비밀번호가 다릅니다.') else: return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '없는 계정 입니다.') else: ip = getip(request) ban = getban(ip) if(ban == 1): return '' else: if(session.get('Now') == True): return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '이미 로그인 되어 있습니다.') else: return render_template('index.html', title = '로그인', enter = '로그인', logo = data['name'], tn = 15) @app.route('/check/') def check(name = None, sub = None, number = None): curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'") rows = curs.fetchall() if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'): return render_template('index.html', title = '차단 오류', logo = data['name'], data = '관리자는 검사 할 수 없습니다.') else: if(admincheck() == 1): m = re.search('(?:[0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)', name) if(m): curs.execute("select * from login where ip = '" + pymysql.escape_string(name) + "' order by today desc") row = curs.fetchall() if(row): i = 0 c = '' while True: try: c = c + '
    ' + row[i]['user'] + '' + row[i]['ip'] + '' + row[i]['today'] + '
    ' except: break i = i + 1 return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = c) else: return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = '') else: curs.execute("select * from login where user = '" + pymysql.escape_string(name) + "' order by today desc") row = curs.fetchall() if(row): i = 0 c = '' while True: try: c = c + '
    ' + row[i]['user'] + '' + row[i]['ip'] + '' + row[i]['today'] + '
    ' except: break i = i + 1 return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = c) else: return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = '') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.') @app.route('/register', methods=['POST', 'GET']) def register(): if(request.method == 'POST'): ip = getip(request) ban = getban(ip) if(ban == 1): return '' else: m = re.search('(?:[^A-Za-zㄱ-힣0-9 ])', request.form["id"]) if(m): return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '아이디에는 한글과 알파벳 공백만 허용 됩니다.') else: if(len(request.form["id"]) > 20): return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '아이디는 20글자보다 짧아야 합니다.') else: curs.execute("select * from user where id = '" + pymysql.escape_string(request.form["id"]) + "'") rows = curs.fetchall() if(rows): return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '동일한 아이디의 유저가 있습니다.') else: hashed = bcrypt.hashpw(bytes(request.form["pw"], 'utf-8'), bcrypt.gensalt()) if(request.form["id"] == data['owner']): curs.execute("insert into user (id, pw, acl) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(hashed.decode()) + "', 'owner')") else: curs.execute("insert into user (id, pw, acl) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(hashed.decode()) + "', 'user')") conn.commit() return '' else: ip = getip(request) ban = getban(ip) if(ban == 1): return '' else: return render_template('index.html', title = '회원가입', enter = '회원가입', logo = data['name'], tn = 15) @app.route('/logout') def logout(): session['Now'] = False session.pop('DREAMER', None) return '' @app.route('/ban/', methods=['POST', 'GET']) def ban(name = None): curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'") rows = curs.fetchall() if(rows and rows[0]['acl'] == 'owner' or rows and rows[0]['acl'] == 'admin'): return render_template('index.html', title = '차단 오류', logo = data['name'], data = '관리자는 차단 할 수 없습니다.') else: if(request.method == 'POST'): if(admincheck() == 1): ip = getip(request) curs.execute("select * from ban where block = '" + pymysql.escape_string(name) + "'") row = curs.fetchall() if(row): block(name, '해제', getnow(), ip, '') curs.execute("delete from ban where block = '" + pymysql.escape_string(name) + "'") else: b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)$", name) if(b): block(name, request.form["end"], getnow(), ip, request.form["why"]) curs.execute("insert into ban (block, end, why, band) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(request.form["end"]) + "', '" + pymysql.escape_string(request.form["why"]) + "', 'O')") else: block(name, request.form["end"], getnow(), ip, request.form["why"]) curs.execute("insert into ban (block, end, why, band) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(request.form["end"]) + "', '" + pymysql.escape_string(request.form["why"]) + "', '')") conn.commit() return '' else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.') else: if(admincheck() == 1): curs.execute("select * from ban where block = '" + pymysql.escape_string(name) + "'") row = curs.fetchall() if(row): now = '차단 해제' else: b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)$", name) if(b): now = '대역 차단' else: now = '차단' return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 16, now = now, today = getnow()) else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.') @app.route('/acl/', methods=['POST', 'GET']) def acl(name = None): if(request.method == 'POST'): if(admincheck() == 1): curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") row = curs.fetchall() if(row): if(request.form["select"] == 'admin'): curs.execute("update data set acl = 'admin' where title = '" + pymysql.escape_string(name) + "'") elif(request.form["select"] == 'user'): curs.execute("update data set acl = 'user' where title = '" + pymysql.escape_string(name) + "'") else: curs.execute("update data set acl = '' where title = '" + pymysql.escape_string(name) + "'") conn.commit() return '' else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.') else: if(admincheck() == 1): curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'") row = curs.fetchall() if(row): if(row[0]['acl'] == 'admin'): now = '관리자만' elif(row[0]['acl'] == 'user'): now = '유저 이상' else: now = '일반' return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 19, now = '현재 ACL 상태는 ' + now) else: return '' else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.') @app.route('/admin/', methods=['POST', 'GET']) def admin(name = None): if(request.method == 'POST'): if(session.get('Now') == True): ip = getip(request) curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'): curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'") row = curs.fetchall() if(row): if(row[0]['acl'] == 'admin' or row[0]['acl'] == 'owner'): curs.execute("update user set acl = 'user' where id = '" + pymysql.escape_string(name) + "'") else: curs.execute("update user set acl = '" + pymysql.escape_string(request.form["select"]) + "' where id = '" + pymysql.escape_string(name) + "'") conn.commit() return '' else: return render_template('index.html', title = '사용자 오류', logo = data['name'], data = '계정이 없습니다.') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.') else: if(session.get('Now') == True): ip = getip(request) curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): if(rows[0]['acl'] == 'owner'): curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'") row = curs.fetchall() if(row): if(row[0]['acl'] == 'admin' or row[0]['acl'] == 'owner'): now = '권한 해제' else: now = '권한 부여' return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 18, now = now) else: return render_template('index.html', title = '사용자 오류', logo = data['name'], data = '계정이 없습니다.') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.') else: return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.') @app.route('/grammar') def grammar(): return render_template('index.html', title = '문법 설명', logo = data['name'], tn = 17) @app.route('/ban') def aban(): ip = getip(request) if(getban(ip) == 1): curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): if(rows[0]['end']): end = rows[0]['end'] + ' 까지 차단 상태 입니다. / 사유 : ' + rows[0]['why'] now = getnow() now = re.sub(':', '', now) now = re.sub('\-', '', now) now = re.sub(' ', '', now) now = int(now) day = rows[0]['end'] day = re.sub('\-', '', day) if(now >= int(day + '000000')): curs.execute("delete from ban where block = '" + pymysql.escape_string(ip) + "'") conn.commit() end = '차단이 풀렸습니다. 다시 시도 해 보세요.' else: end = '영구 차단 상태 입니다. / 사유 : ' + rows[0]['why'] else: b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)", ip) if(b): results = b.groups() curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'") row = curs.fetchall() if(row): if(row[0]['end']): end = row[0]['end'] + ' 까지 차단 상태 입니다. / 사유 : ' + rows[0]['why'] now = getnow() now = re.sub(':', '', now) now = re.sub('\-', '', now) now = re.sub(' ', '', now) now = int(now) day = row[0]['end'] day = re.sub('\-', '', day) if(now >= int(day + '000000')): curs.execute("delete from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'") conn.commit() end = '차단이 풀렸습니다. 다시 시도 해 보세요.' else: end = '영구 차단 상태 입니다. / 사유 : ' + row[0]['why'] else: end = '권한이 맞지 않는 상태 입니다.' return render_template('index.html', title = '권한 오류', logo = data['name'], data = end) @app.route('/w//r//diff/') def diff(name = None, a = None, b = None): curs.execute("select * from history where id = '" + pymysql.escape_string(a) + "' and title = '" + pymysql.escape_string(name) + "'") rows = curs.fetchall() if(rows): curs.execute("select * from history where id = '" + pymysql.escape_string(b) + "' and title = '" + pymysql.escape_string(name) + "'") row = curs.fetchall() if(row): indata = re.sub('<', '<', rows[0]['data']) indata = re.sub('>', '>', indata) indata = re.sub('"', '"', indata) indata = re.sub('\n', '
    ', indata) enddata = re.sub('<', '<', row[0]['data']) enddata = re.sub('>', '>', enddata) enddata = re.sub('"', '"', enddata) enddata = re.sub('\n', '
    ', enddata) sm = difflib.SequenceMatcher(None, indata, enddata) c = show_diff(sm) return render_template('index.html', title = 'Diff', logo = data['name'], data = c) else: return render_template('index.html', title = 'Diff 오류', logo = data['name'], data = '
    이 리비전이나 문서가 없습니다.') else: return render_template('index.html', title = 'Diff 오류', logo = data['name'], data = '이 리비전이나 문서가 없습니다.') @app.route('/version') def version(): return render_template('index.html', title = '버전', logo = data['name'], tn = 14) @app.route('/user') def user(): ip = getip(request) curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(getban(ip) == 0): if(rows): if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'): if(rows[0]['acl'] == 'admin'): acl = '관리자' else: acl = '소유자' else: acl = '유저' else: acl = '일반' else: acl = '차단' return render_template('index.html', title = '유저 메뉴', logo = data['name'], data = ip + '

    권한 상태 : ' + acl + '

  • 로그인
  • 로그아웃
  • 회원가입
  • ') @app.route('/random') def random(): curs.execute("select * from data order by rand() limit 1") rows = curs.fetchall() if(rows): return '' else: return '' @app.errorhandler(404) def uncaughtError(error): return '' if __name__ == '__main__': app.run(host = '0.0.0.0', port = int(data['port']), threaded = True)