app.py 112 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094
  1. from flask import Flask, request, session, render_template, send_file
  2. from werkzeug import secure_filename
  3. app = Flask(__name__)
  4. from urllib import parse
  5. import json
  6. import pymysql
  7. import time
  8. import re
  9. import bcrypt
  10. import os
  11. import difflib
  12. json_data = open('set.json').read()
  13. data = json.loads(json_data)
  14. print('오픈나무 시작 포트 : ' + data['port'])
  15. import logging
  16. log = logging.getLogger('werkzeug')
  17. log.setLevel(logging.ERROR)
  18. app.config['MAX_CONTENT_LENGTH'] = int(data['upload']) * 1024 * 1024
  19. conn = pymysql.connect(host = data['host'], user = data['user'], password = data['pw'], db = data['db'], charset = 'utf8mb4')
  20. curs = conn.cursor(pymysql.cursors.DictCursor)
  21. app.secret_key = data['key']
  22. ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
  23. def show_diff(seqm):
  24. output= []
  25. for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
  26. if opcode == 'equal':
  27. output.append(seqm.a[a0:a1])
  28. elif opcode == 'insert':
  29. output.append("<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>")
  30. elif opcode == 'delete':
  31. output.append("<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>")
  32. return ''.join(output)
  33. def allowed_file(filename):
  34. return '.' in filename and \
  35. filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
  36. def admincheck():
  37. if(session.get('Now') == True):
  38. ip = getip(request)
  39. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  40. rows = curs.fetchall()
  41. if(rows):
  42. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  43. return 1
  44. def namumark(title, data):
  45. data = re.sub('<', '&lt;', data)
  46. data = re.sub('>', '&gt;', data)
  47. data = re.sub('"', '&quot;', data)
  48. while True:
  49. m = re.search("\[include\((((?!\)\]).)*)\)\]", data)
  50. if(m):
  51. results = m.groups()
  52. if(results[0] == title):
  53. data = re.sub("\[include\((((?!\)\]).)*)\)\]", "<b>" + results[0] + "</b>", data, 1)
  54. else:
  55. curs.execute("select * from data where title = '" + pymysql.escape_string(results[0]) + "'")
  56. rows = curs.fetchall()
  57. if(rows):
  58. enddata = rows[0]['data']
  59. enddata = re.sub("\[include\((((?!\)\]).)*)\)\]", "", enddata)
  60. enddata = re.sub('<', '&lt;', enddata)
  61. enddata = re.sub('>', '&gt;', enddata)
  62. enddata = re.sub('"', '&quot;', enddata)
  63. data = re.sub("\[include\((((?!\)\]).)*)\)\]", enddata, data, 1)
  64. else:
  65. data = re.sub("\[include\((((?!\)\]).)*)\)\]", "[[" + results[0] + "]]", data, 1)
  66. else:
  67. break
  68. while True:
  69. m = re.search('^#(?:redirect|넘겨주기)\s([^\n]*)', data)
  70. if(m):
  71. results = m.groups()
  72. data = re.sub('^#(?:redirect|넘겨주기)\s([^\n]*)', '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(results[0]).replace('/','%2F') + '/redirect/' + parse.quote(title).replace('/','%2F') + '" />', data, 1)
  73. else:
  74. break
  75. data = '\n' + data + '\n'
  76. while True:
  77. m = re.search("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", data)
  78. if(m):
  79. result = m.groups()
  80. blockquote = result[0]
  81. blockquote = re.sub("\n&gt;\s?", "\n", blockquote)
  82. data = re.sub("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", "\n<blockquote>" + blockquote + "</blockquote>", data, 1)
  83. else:
  84. break
  85. h0c = 0;
  86. h1c = 0;
  87. h2c = 0;
  88. h3c = 0;
  89. h4c = 0;
  90. h5c = 0;
  91. last = 0;
  92. rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
  93. while True:
  94. m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', data)
  95. if(m):
  96. result = m.groups()
  97. wiki = len(result[0])
  98. if(last < wiki):
  99. last = wiki
  100. else:
  101. last = wiki;
  102. if(wiki == 1):
  103. h1c = 0
  104. h2c = 0
  105. h3c = 0
  106. h4c = 0
  107. h5c = 0
  108. elif(wiki == 2):
  109. h2c = 0
  110. h3c = 0
  111. h4c = 0
  112. h5c = 0
  113. elif(wiki == 3):
  114. h3c = 0
  115. h4c = 0
  116. h5c = 0
  117. elif(wiki == 4):
  118. h4c = 0
  119. h5c = 0
  120. elif(wiki == 5):
  121. h5c = 0
  122. if(wiki == 1):
  123. h0c = h0c + 1
  124. elif(wiki == 2):
  125. h1c = h1c + 1
  126. elif(wiki == 3):
  127. h2c = h2c + 1
  128. elif(wiki == 4):
  129. h3c = h3c + 1
  130. elif(wiki == 5):
  131. h4c = h4c + 1
  132. else:
  133. h5c = h5c + 1
  134. toc = str(h0c) + '.' + str(h1c) + '.' + str(h2c) + '.' + str(h3c) + '.' + str(h4c) + '.' + str(h5c) + '.'
  135. toc = re.sub("(?P<in>[0-9]0(?:[0]*)?)\.", '\g<in>#.', toc)
  136. toc = re.sub("0\.", '', toc)
  137. toc = re.sub("#\.", '.', toc)
  138. toc = re.sub("\.$", '', toc)
  139. rtoc = rtoc + '<a href="#s-' + toc + '">' + toc + '</a>. ' + result[1] + '<br>'
  140. data = re.sub('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', '<h' + str(wiki) + '><a href="#toc" id="s-' + toc + '">' + toc + '.</a> ' + result[1] + '</h' + str(wiki) + '>', data, 1);
  141. else:
  142. rtoc = rtoc + '</div>'
  143. break
  144. data = re.sub("\[목차\]", rtoc, data)
  145. data = re.sub("\[\[분류:(((?!\]\]).)*)\]\]", '', data)
  146. while True:
  147. p = re.compile("{{{((?:(?!{{{)(?!}}}).)*)}}}", re.DOTALL)
  148. m = p.search(data)
  149. if(m):
  150. results = m.groups()
  151. q = re.compile("^\+([1-5])\s(.*)$", re.DOTALL)
  152. n = q.search(results[0])
  153. w = re.compile("^\-([1-5])\s(.*)$", re.DOTALL)
  154. a = w.search(results[0])
  155. e = re.compile("^(#[0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  156. b = e.search(results[0])
  157. r = re.compile("^(#[0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  158. c = r.search(results[0])
  159. t = re.compile("^#(\w+)\s(.*)$", re.DOTALL)
  160. d = t.search(results[0])
  161. y = re.compile("^#!wiki\sstyle=&quot;((?:(?!&quot;|\n).)*)&quot;\n?\s\n(.*)$", re.DOTALL)
  162. l = y.search(results[0])
  163. if(n):
  164. result = n.groups()
  165. data = p.sub('<span class="font-size-' + result[0] + '">' + result[1] + '</span>', data, 1)
  166. elif(a):
  167. result = a.groups()
  168. data = p.sub('<span class="font-size-small-' + result[0] + '">' + result[1] + '</span>', data, 1)
  169. elif(b):
  170. result = b.groups()
  171. data = p.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', data, 1)
  172. elif(c):
  173. result = c.groups()
  174. data = p.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', data, 1)
  175. elif(d):
  176. result = d.groups()
  177. data = p.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', data, 1)
  178. elif(l):
  179. result = l.groups()
  180. data = p.sub('<div style="' + result[0] + '">' + result[1] + '</div>', data, 1)
  181. else:
  182. data = p.sub(results[0], data, 1)
  183. else:
  184. break
  185. data = re.sub("'''(?P<in>.+?)'''(?!')", '<b>\g<in></b>', data)
  186. data = re.sub("''(?P<in>.+?)''(?!')", '<i>\g<in></i>', data)
  187. data = re.sub('~~(?P<in>.+?)~~(?!~)', '<s>\g<in></s>', data)
  188. data = re.sub('--(?P<in>.+?)--(?!-)', '<s>\g<in></s>', data)
  189. data = re.sub('__(?P<in>.+?)__(?!_)', '<u>\g<in></u>', data)
  190. data = re.sub('\^\^(?P<in>.+?)\^\^(?!\^)', '<sup>\g<in></sup>', data)
  191. data = re.sub(',,(?P<in>.+?),,(?!,)', '<path:sub>\g<in></sub>', data)
  192. data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table><tbody><tr><td>\g<in></td></tr></tbody></table>', data)
  193. data = re.sub("##\s?(?P<in>[^\n]*)\n", "<div style='display:none;'>\g<in></div>", data);
  194. while True:
  195. m = re.search("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", data)
  196. if(m):
  197. c = m.groups()
  198. if(c[1]):
  199. n = re.search("width=([^ \n&]*)", c[1])
  200. e = re.search("height=([^ \n&]*)", c[1])
  201. if(n):
  202. a = n.groups()
  203. width = a[0]
  204. else:
  205. width = ''
  206. if(e):
  207. b = e.groups()
  208. height = b[0]
  209. else:
  210. height = ''
  211. img = re.sub("\.(?P<in>jpg|png|gif|jpeg)", "#\g<in>#", c[0])
  212. data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", '<img src="/image/' + img + '" width="' + width + '" height="' + height + '">', data, 1)
  213. else:
  214. img = re.sub("\.(?P<in>jpg|png|gif|jpeg)", "#\g<in>#", c[0])
  215. data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", "<img src='/image/" + img + "'>", data, 1)
  216. else:
  217. break
  218. data = re.sub("\[br\]",'<br>', data);
  219. while True:
  220. m = re.search("\[youtube\(((?:(?!,|\)\]).)*)(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?(?:,\s)?(?:height=((?:(?!,|\)\]).)*))?(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?\)\]", data)
  221. if(m):
  222. result = m.groups()
  223. if(result[1]):
  224. if(result[2]):
  225. width = result[1]
  226. height = result[2]
  227. else:
  228. width = result[1]
  229. height = '315'
  230. elif(result[2]):
  231. if(result[3]):
  232. height = result[2]
  233. width = result[3]
  234. else:
  235. height = result[2]
  236. width = '560'
  237. else:
  238. width = '560'
  239. height = '315'
  240. data = re.sub("\[youtube\(((?:(?!,|\)\]).)*)(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?(?:,\s)?(?:height=((?:(?!,|\)\]).)*))?(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?\)\]", '<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + result[0] + '" frameborder="0" allowfullscreen></iframe>', data, 1)
  241. else:
  242. break
  243. while True:
  244. 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)
  245. if(m):
  246. result = m.groups()
  247. if(result[1]):
  248. if(result[2]):
  249. width = result[1]
  250. height = result[2]
  251. else:
  252. width = result[1]
  253. height = ''
  254. elif(result[2]):
  255. if(result[3]):
  256. height = result[2]
  257. width = result[3]
  258. else:
  259. height = result[2]
  260. width = ''
  261. else:
  262. width = ''
  263. height = ''
  264. c = result[0]
  265. c = re.sub("\.(?P<in>jpg|png|gif|jpeg)", "#\g<in>#", c)
  266. 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)?))?)?", "<img width='" + width + "' height='" + height + "' src='" + c + "'>", data, 1)
  267. else:
  268. break
  269. while True:
  270. m = re.search("\[\[(((?!\]\]).)*)\]\]", data)
  271. if(m):
  272. result = m.groups()
  273. a = re.search("(((?!\|).)*)\|(.*)", result[0])
  274. if(a):
  275. results = a.groups()
  276. b = re.search("^http(?:s)?:\/\/", results[0])
  277. if(b):
  278. c = re.search("(?:\.jpg|\.png|\.gif|\.jpeg)", results[0])
  279. if(c):
  280. img = results[0]
  281. img = re.sub("\.(?P<in>jpg|png|gif|jpeg)", "#\g<in>#", img)
  282. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + img + '">' + results[2] + '</a>', data, 1)
  283. else:
  284. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + results[0] + '">' + results[2] + '</a>', data, 1)
  285. else:
  286. if(results[0] == title):
  287. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + results[2] + '</b>', data, 1)
  288. else:
  289. curs.execute("select * from data where title = '" + pymysql.escape_string(results[0]) + "'")
  290. rows = curs.fetchall()
  291. if(rows):
  292. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + results[0] + '" href="/w/' + parse.quote(results[0]).replace('/','%2F') + '">' + results[2] + '</a>', data, 1)
  293. else:
  294. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + results[0] + '" class="not_thing" href="/w/' + parse.quote(results[0]).replace('/','%2F') + '">' + results[2] + '</a>', data, 1)
  295. else:
  296. b = re.search("^http(?:s)?:\/\/", result[0])
  297. if(b):
  298. c = re.search("(?:\.jpg|\.png|\.gif|\.jpeg)", result[0])
  299. if(c):
  300. img = result[0]
  301. img = re.sub("\.(?P<in>jpg|png|gif|jpeg)", "#\g<in>#", img)
  302. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + img + '">' + result[0] + '</a>', data, 1)
  303. else:
  304. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + result[0] + '">' + result[0] + '</a>', data, 1)
  305. else:
  306. if(result[0] == title):
  307. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + result[0] + '</b>', data, 1)
  308. else:
  309. curs.execute("select * from data where title = '" + pymysql.escape_string(result[0]) + "'")
  310. rows = curs.fetchall()
  311. if(rows):
  312. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a href="/w/' + parse.quote(result[0]).replace('/','%2F') + '">' + result[0] + '</a>', data, 1)
  313. else:
  314. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="not_thing" href="/w/' + parse.quote(result[0]).replace('/','%2F') + '">' + result[0] + '</a>', data, 1)
  315. else:
  316. break
  317. while True:
  318. m = re.search("((?:(?:\s\*\s[^\n]*)\n?)+)", data)
  319. if(m):
  320. result = m.groups()
  321. end = str(result[0])
  322. end = re.sub("\s\*\s(?P<in>[^\n]*)", "<li>\g<in></li>", end)
  323. end = re.sub("\n", '', end)
  324. data = re.sub("((?:(?:\s\*\s[^\n]*)\n?)+)", '<ul id="list">' + end + '</ul>', data, 1)
  325. else:
  326. break
  327. data = re.sub('\[date\]', getnow(), data)
  328. data = re.sub("\[anchor\((?P<in>[^\[\]]*)\)\]", '<span id="\g<in>"></span>', data)
  329. data = re.sub("#(?P<in>jpg|png|gif|jpeg)#", ".\g<in>", data)
  330. data = re.sub("-{4,11}", "<hr>", data)
  331. while True:
  332. b = re.search("\r\n( +)", data)
  333. if(b):
  334. result = b.groups()
  335. tp = len(result[0])
  336. up = ''
  337. i = 0
  338. while True:
  339. up = up + '<span id="in"></span>'
  340. i = i + 1
  341. if(i == tp):
  342. break
  343. data = re.sub("\r\n( +)", '<br>' + up, data, 1)
  344. else:
  345. break
  346. a = 1
  347. tou = "<hr id='footnote'><div class='wiki-macro-footnote'><br>"
  348. while True:
  349. b = re.search("\[\*([^\s]*)\s(((?!\]).)*)\]", data)
  350. if(b):
  351. results = b.groups()
  352. if(results[0]):
  353. c = results[1]
  354. c = re.sub("<(?:[^>]*)>", '', c)
  355. tou = tou + "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + results[0] + "]</a> " + results[1] + "</span><br>"
  356. data = re.sub("\[\*([^\s]*)\s(((?!\]).)*)\]", "<sup><a class=\"footnotes\" title=\"" + c + "\" id=\"rfn-" + str(a) + "\" href=\"#fn-" + str(a) + "\">[" + results[0] + "]</a></sup>", data, 1)
  357. else:
  358. c = results[1]
  359. c = re.sub("<(?:[^>]*)>", '', c)
  360. tou = tou + "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + str(a) + "]</a> " + results[1] + "</span><br>"
  361. data = re.sub("\[\*([^\s]*)\s(((?!\]).)*)\]", '<sup><a class="footnotes" title="' + c + '" id="rfn-' + str(a) + '" href="#fn-' + str(a) + '">[' + str(a) + ']</a></sup>', data, 1)
  362. a = a + 1
  363. else:
  364. tou = tou + '</div>'
  365. if(tou == "<hr id='footnote'><div class='wiki-macro-footnote'><br></div>"):
  366. tou = ""
  367. break
  368. data = re.sub("\[각주\](?:(?:(?:<br>+)*(?:\s+)*(?:\r+)*(?:\n+))+)?$", "", data)
  369. data = re.sub("\[각주\]", "<br>" + tou, data)
  370. data = data + tou;
  371. while True:
  372. m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
  373. if(m):
  374. results = m.groups()
  375. table = results[0]
  376. while True:
  377. a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  378. if(a):
  379. row = ''
  380. cel = ''
  381. celstyle = ''
  382. rowstyle = ''
  383. alltable = ''
  384. result = a.groups()
  385. if(result[1]):
  386. q = re.search("&lt;table\s?width=((?:(?!&gt;).)*)&gt;", result[1])
  387. w = re.search("&lt;table\s?height=((?:(?!&gt;).)*)&gt;", result[1])
  388. e = re.search("&lt;table\s?align=((?:(?!&gt;).)*)&gt;", result[1])
  389. alltable = 'style="'
  390. celstyle = 'style="'
  391. rowstyle = 'style="'
  392. if(q):
  393. resultss = q.groups()
  394. alltable = alltable + 'width:' + resultss[0] + ';'
  395. if(w):
  396. resultss = w.groups()
  397. alltable = alltable + 'height:' + resultss[0] + ';'
  398. if(e):
  399. resultss = e.groups()
  400. if(resultss[0] == 'right'):
  401. alltable = alltable + 'margin-left:auto;'
  402. elif(resultss[0] == 'center'):
  403. alltable = alltable + 'margin:auto;'
  404. else:
  405. alltable = alltable + 'margin-right:auto;'
  406. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  407. if(r):
  408. resultss = r.groups()
  409. cel = 'colspan="' + resultss[0] + '"'
  410. else:
  411. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  412. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  413. if(t):
  414. resultss = t.groups()
  415. row = 'rowspan="' + resultss[0] + '"'
  416. ba = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  417. bb = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  418. bc = re.search("&lt;rowbgcolor=(\w+)&gt;", result[1])
  419. if(ba):
  420. resultss = ba.groups()
  421. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  422. elif(bb):
  423. resultss = bb.groups()
  424. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  425. elif(bc):
  426. resultss = bc.groups()
  427. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  428. z = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  429. x = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  430. c = re.search("&lt;table\s?bordercolor=(\w+)&gt;", result[1])
  431. if(z):
  432. resultss = z.groups()
  433. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  434. elif(x):
  435. resultss = x.groups()
  436. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  437. elif(c):
  438. resultss = c.groups()
  439. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  440. aq = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  441. aw = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  442. ae = re.search("&lt;table\s?bgcolor=(\w+)&gt;", result[1])
  443. if(aq):
  444. resultss = aq.groups()
  445. alltable = alltable + 'background:' + resultss[0] + ';'
  446. elif(aw):
  447. resultss = aw.groups()
  448. alltable = alltable + 'background:' + resultss[0] + ';'
  449. elif(ae):
  450. resultss = ae.groups()
  451. alltable = alltable + 'background:' + resultss[0] + ';'
  452. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  453. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  454. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  455. if(j):
  456. resultss = j.groups()
  457. celstyle = celstyle + 'background:' + resultss[0] + ';'
  458. elif(k):
  459. resultss = k.groups()
  460. celstyle = celstyle + 'background:' + resultss[0] + ';'
  461. elif(l):
  462. resultss = l.groups()
  463. celstyle = celstyle + 'background:' + resultss[0] + ';'
  464. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  465. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  466. ac = re.search("&lt;(\w+)&gt;", result[1])
  467. if(aa):
  468. resultss = aa.groups()
  469. celstyle = celstyle + 'background:' + resultss[0] + ';'
  470. elif(ab):
  471. resultss = ab.groups()
  472. celstyle = celstyle + 'background:' + resultss[0] + ';'
  473. elif(ac):
  474. resultss = ac.groups()
  475. celstyle = celstyle + 'background:' + resultss[0] + ';'
  476. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  477. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  478. if(qa):
  479. resultss = qa.groups()
  480. celstyle = celstyle + 'width:' + resultss[0] + ';'
  481. if(qb):
  482. resultss = qb.groups()
  483. celstyle = celstyle + 'height:' + resultss[0] + ';'
  484. i = re.search("&lt;\)&gt;", result[1])
  485. o = re.search("&lt;:&gt;", result[1])
  486. p = re.search("&lt;\(&gt;", result[1])
  487. if(i):
  488. celstyle = celstyle + 'text-align:right;'
  489. elif(o):
  490. celstyle = celstyle + 'text-align:center;'
  491. else:
  492. celstyle = celstyle + 'text-align:left;'
  493. alltable = alltable + '"'
  494. celstyle = celstyle + '"'
  495. rowstyle = rowstyle + '"'
  496. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "><tbody><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  497. else:
  498. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  499. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table><tbody><tr><td " + cel + ">", table, 1)
  500. else:
  501. break
  502. table = re.sub("\|\|$", "</td></tr></tbody></table>", table)
  503. while True:
  504. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  505. if(b):
  506. row = ''
  507. cel = ''
  508. celstyle = ''
  509. rowstyle = ''
  510. result = b.groups()
  511. if(result[1]):
  512. celstyle = 'style="'
  513. rowstyle = 'style="'
  514. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  515. if(r):
  516. resultss = r.groups()
  517. cel = 'colspan="' + resultss[0] + '"'
  518. else:
  519. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  520. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  521. if(t):
  522. resultss = t.groups()
  523. row = 'rowspan="' + resultss[0] + '"'
  524. ba = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  525. bb = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  526. bc = re.search("&lt;rowbgcolor=(\w+)&gt;", result[1])
  527. if(ba):
  528. resultss = ba.groups()
  529. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  530. elif(bb):
  531. resultss = bb.groups()
  532. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  533. elif(bc):
  534. resultss = bc.groups()
  535. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  536. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  537. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  538. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  539. if(j):
  540. resultss = j.groups()
  541. celstyle = celstyle + 'background:' + resultss[0] + ';'
  542. elif(k):
  543. resultss = k.groups()
  544. celstyle = celstyle + 'background:' + resultss[0] + ';'
  545. elif(l):
  546. resultss = l.groups()
  547. celstyle = celstyle + 'background:' + resultss[0] + ';'
  548. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  549. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  550. ac = re.search("&lt;(\w+)&gt;", result[1])
  551. if(aa):
  552. resultss = aa.groups()
  553. celstyle = celstyle + 'background:' + resultss[0] + ';'
  554. elif(ab):
  555. resultss = ab.groups()
  556. celstyle = celstyle + 'background:' + resultss[0] + ';'
  557. elif(ac):
  558. resultss = ac.groups()
  559. celstyle = celstyle + 'background:' + resultss[0] + ';'
  560. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  561. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  562. if(qa):
  563. resultss = qa.groups()
  564. celstyle = celstyle + 'width:' + resultss[0] + ';'
  565. if(qb):
  566. resultss = qb.groups()
  567. celstyle = celstyle + 'height:' + resultss[0] + ';'
  568. i = re.search("&lt;\)&gt;", result[1])
  569. o = re.search("&lt;:&gt;", result[1])
  570. p = re.search("&lt;\(&gt;", result[1])
  571. if(i):
  572. celstyle = celstyle + 'text-align:right;'
  573. elif(o):
  574. celstyle = celstyle + 'text-align:center;'
  575. else:
  576. celstyle = celstyle + 'text-align:left;'
  577. celstyle = celstyle + '"'
  578. rowstyle = rowstyle + '"'
  579. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  580. else:
  581. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  582. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr><td " + cel + ">", table, 1)
  583. else:
  584. break
  585. while True:
  586. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  587. if(c):
  588. row = ''
  589. cel = ''
  590. celstyle = ''
  591. result = c.groups()
  592. if(result[1]):
  593. celstyle = 'style="'
  594. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  595. if(r):
  596. resultss = r.groups()
  597. cel = 'colspan="' + resultss[0] + '"';
  598. else:
  599. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  600. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  601. if(t):
  602. resultss = t.groups()
  603. row = 'rowspan="' + resultss[0] + '"';
  604. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  605. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  606. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  607. if(j):
  608. resultss = j.groups()
  609. celstyle = celstyle + 'background:' + resultss[0] + ';'
  610. elif(k):
  611. resultss = k.groups()
  612. celstyle = celstyle + 'background:' + resultss[0] + ';'
  613. elif(l):
  614. resultss = l.groups()
  615. celstyle = celstyle + 'background:' + resultss[0] + ';'
  616. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  617. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  618. ac = re.search("&lt;(\w+)&gt;", result[1])
  619. if(aa):
  620. resultss = aa.groups()
  621. celstyle = celstyle + 'background:' + resultss[0] + ';'
  622. elif(ab):
  623. resultss = ab.groups()
  624. celstyle = celstyle + 'background:' + resultss[0] + ';'
  625. elif(ac):
  626. resultss = ac.groups()
  627. celstyle = celstyle + 'background:' + resultss[0] + ';'
  628. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  629. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  630. if(qa):
  631. resultss = qa.groups()
  632. celstyle = celstyle + 'width:' + resultss[0] + ';'
  633. if(qb):
  634. resultss = qb.groups()
  635. celstyle = celstyle + 'height:' + resultss[0] + ';'
  636. i = re.search("&lt;\)&gt;", result[1])
  637. o = re.search("&lt;:&gt;", result[1])
  638. p = re.search("&lt;\(&gt;", result[1])
  639. if(i):
  640. celstyle = celstyle + 'text-align:right;'
  641. elif(o):
  642. celstyle = celstyle + 'text-align:center;'
  643. else:
  644. celstyle = celstyle + 'text-align:left;'
  645. celstyle = celstyle + '"'
  646. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  647. else:
  648. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  649. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + ">", table, 1)
  650. else:
  651. break
  652. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  653. else:
  654. break
  655. data = re.sub('\n', '<br>', data)
  656. data = re.sub('^<br>', '', data)
  657. return str(data)
  658. def getip(request):
  659. if(session.get('Now') == True):
  660. ip = format(session['DREAMER'])
  661. else:
  662. if(request.headers.getlist("X-Forwarded-For")):
  663. ip = request.headers.getlist("X-Forwarded-For")[0]
  664. else:
  665. ip = request.remote_addr
  666. return ip
  667. def getcan(ip, name):
  668. m = re.search("^사용자:(.*)", name)
  669. if(m):
  670. g = m.groups()
  671. if(ip == g[0]):
  672. if(re.search("\.", g[0])):
  673. return 1
  674. else:
  675. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  676. rows = curs.fetchall()
  677. if(rows):
  678. return 1
  679. else:
  680. return 0
  681. else:
  682. return 1
  683. else:
  684. b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)", ip)
  685. if(b):
  686. results = b.groups()
  687. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  688. rowss = curs.fetchall()
  689. if(rowss):
  690. return 1
  691. else:
  692. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  693. rows = curs.fetchall()
  694. if(rows):
  695. return 1
  696. else:
  697. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  698. row = curs.fetchall()
  699. if(row):
  700. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  701. rows = curs.fetchall()
  702. if(row[0]['acl'] == 'user'):
  703. if(rows):
  704. return 0
  705. else:
  706. return 1
  707. elif(row[0]['acl'] == 'admin'):
  708. if(rows):
  709. if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'):
  710. return 0
  711. else:
  712. return 1
  713. else:
  714. return 1
  715. else:
  716. return 0
  717. else:
  718. return 0
  719. else:
  720. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  721. rows = curs.fetchall()
  722. if(rows):
  723. return 1
  724. else:
  725. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  726. row = curs.fetchall()
  727. if(row):
  728. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  729. rows = curs.fetchall()
  730. if(row[0]['acl'] == 'user'):
  731. if(rows):
  732. return 0
  733. else:
  734. return 1
  735. elif(row[0]['acl'] == 'admin'):
  736. if(rows):
  737. if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'):
  738. return 0
  739. else:
  740. return 1
  741. else:
  742. return 1
  743. else:
  744. return 0
  745. else:
  746. return 0
  747. def getban(ip):
  748. b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)", ip)
  749. if(b):
  750. results = b.groups()
  751. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  752. rowss = curs.fetchall()
  753. if(rowss):
  754. return 1
  755. else:
  756. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  757. rows = curs.fetchall()
  758. if(rows):
  759. return 1
  760. else:
  761. return 0
  762. else:
  763. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  764. rows = curs.fetchall()
  765. if(rows):
  766. return 1
  767. else:
  768. return 0
  769. def getdiscuss(ip, name, sub):
  770. b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)", ip)
  771. if(b):
  772. results = b.groups()
  773. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  774. rowss = curs.fetchall()
  775. if(rowss):
  776. return 1
  777. else:
  778. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  779. rows = curs.fetchall()
  780. if(rows):
  781. return 1
  782. else:
  783. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  784. rows = curs.fetchall()
  785. if(rows):
  786. return 1
  787. else:
  788. return 0
  789. else:
  790. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  791. rows = curs.fetchall()
  792. if(rows):
  793. return 1
  794. else:
  795. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  796. rows = curs.fetchall()
  797. if(rows):
  798. return 1
  799. else:
  800. return 0
  801. def getnow():
  802. now = time.localtime()
  803. 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)
  804. return s
  805. def recent(title, ip, today, send, leng):
  806. curs.execute("insert into rc (title, date, ip, send, leng, back) value ('" + pymysql.escape_string(title) + "', '" + today + "', '" + ip + "', '" + pymysql.escape_string(send) + "', '" + leng + "', '')")
  807. conn.commit()
  808. def discuss(title, sub, date):
  809. curs.execute("select * from rd where title = '" + pymysql.escape_string(title) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  810. rows = curs.fetchall()
  811. if(rows):
  812. curs.execute("update rd set date = '" + pymysql.escape_string(date) + "' where title = '" + pymysql.escape_string(title) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  813. else:
  814. curs.execute("insert into rd (title, sub, date) value ('" + pymysql.escape_string(title) + "', '" + pymysql.escape_string(sub) + "', '" + pymysql.escape_string(date) + "')")
  815. conn.commit()
  816. def block(block, end, today, blocker, why):
  817. 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) + "')")
  818. conn.commit()
  819. def history(title, data, date, ip, send, leng):
  820. curs.execute("select * from history where title = '" + pymysql.escape_string(title) + "' order by id+0 desc limit 1")
  821. rows = curs.fetchall()
  822. if(rows):
  823. number = int(rows[0]['id']) + 1
  824. 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 + "')")
  825. conn.commit()
  826. else:
  827. 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 + "')")
  828. conn.commit()
  829. def getleng(existing, change):
  830. if(existing < change):
  831. leng = change - existing
  832. leng = '+' + str(leng)
  833. elif(change < existing):
  834. leng = existing - change
  835. leng = '-' + str(leng)
  836. else:
  837. leng = '0'
  838. return leng;
  839. @app.route('/upload', methods=['GET', 'POST'])
  840. def upload():
  841. if(request.method == 'POST'):
  842. ip = getip(request)
  843. ban = getban(ip)
  844. if(ban == 1):
  845. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  846. else:
  847. file = request.files['file']
  848. if(file and allowed_file(file.filename)):
  849. filename = secure_filename(file.filename)
  850. if(os.path.exists(os.path.join('image', filename))):
  851. return render_template('index.html', logo = data['name'], title = '업로드', data = '동일한 이름의 파일이 있습니다.')
  852. else:
  853. file.save(os.path.join('image', filename))
  854. return render_template('index.html', logo = data['name'], title = '업로드', data = '완료 되었습니다.')
  855. else:
  856. return render_template('index.html', logo = data['name'], title = '업로드', data = 'jpg gif jpeg png만 가능 합니다.')
  857. else:
  858. ip = getip(request)
  859. ban = getban(ip)
  860. if(ban == 1):
  861. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  862. else:
  863. return render_template('index.html', logo = data['name'], title = '업로드', tn = 21, number = data['upload'])
  864. @app.route('/image/<path:name>')
  865. def image(name = None):
  866. filename = secure_filename(name)
  867. return send_file(os.path.join('image', filename), mimetype='image')
  868. @app.route('/')
  869. @app.route('/w/')
  870. def redirect():
  871. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  872. @app.route('/recentchanges')
  873. def recentchanges():
  874. i = 0
  875. div = '<div>'
  876. curs.execute("select * from rc order by date desc limit 50")
  877. rows = curs.fetchall()
  878. if(rows):
  879. admin = admincheck()
  880. while True:
  881. try:
  882. a = rows[i]
  883. except:
  884. div = div + '</div>'
  885. break
  886. if(rows[i]['send']):
  887. send = rows[i]['send']
  888. send = re.sub('<', '&lt;', send)
  889. send = re.sub('>', '&gt;', send)
  890. send = re.sub('&lt;a href="\/w\/(?P<in>[^"]*)"&gt;(?P<out>[^&]*)&lt;\/a&gt;', '<a href="/w/\g<in>">\g<out></a>', send)
  891. else:
  892. send = '<br>'
  893. title = rows[i]['title']
  894. title = re.sub('<', '&lt;', title)
  895. title = re.sub('>', '&gt;', title)
  896. m = re.search("\+", rows[i]['leng'])
  897. n = re.search("\-", rows[i]['leng'])
  898. if(m):
  899. leng = '<span style="color:green;">' + rows[i]['leng'] + '</span>'
  900. elif(n):
  901. leng = '<span style="color:red;">' + rows[i]['leng'] + '</span>'
  902. else:
  903. leng = '<span style="color:gray;">' + rows[i]['leng'] + '</span>'
  904. if(admin == 1):
  905. curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  906. row = curs.fetchall()
  907. if(row):
  908. if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'):
  909. ip = rows[i]['ip']
  910. else:
  911. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  912. row = curs.fetchall()
  913. if(row):
  914. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  915. else:
  916. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  917. else:
  918. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  919. row = curs.fetchall()
  920. if(row):
  921. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  922. else:
  923. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  924. else:
  925. ip = rows[i]['ip']
  926. div = div + '<table style="width: 100%;"><tbody><tr><td style="text-align: center;width:33.33%;"><a href="/w/' + parse.quote(rows[i]['title']).replace('/','%2F') + '">' + title + '</a> <a href="/history/' + parse.quote(rows[i]['title']).replace('/','%2F') + '/n/1">(역사)</a> (' + leng + ')</td><td style="text-align: center;width:33.33%;">' + ip + '</td><td style="text-align: center;width:33.33%;">' + rows[i]['date'] + '</td></tr><tr><td colspan="3" style="text-align: center;width:100%;">' + send + '</td></tr></tbody></table>'
  927. i = i + 1
  928. return render_template('index.html', logo = data['name'], rows = div, tn = 3, title = '최근 변경내역')
  929. else:
  930. return render_template('index.html', logo = data['name'], rows = '', tn = 3, title = '최근 변경내역')
  931. @app.route('/recentdiscuss')
  932. def recentdiscuss():
  933. i = 0
  934. div = '<div>'
  935. curs.execute("select * from rd order by date desc limit 50")
  936. rows = curs.fetchall()
  937. if(rows):
  938. while True:
  939. try:
  940. a = rows[i]
  941. except:
  942. div = div + '</div>'
  943. break
  944. title = rows[i]['title']
  945. title = re.sub('<', '&lt;', title)
  946. title = re.sub('>', '&gt;', title)
  947. sub = rows[i]['sub']
  948. sub = re.sub('<', '&lt;', sub)
  949. sub = re.sub('>', '&gt;', sub)
  950. div = div + '<table style="width: 100%;"><tbody><tr><td style="text-align: center;width:50%;"><a href="/topic/' + parse.quote(rows[i]['title']).replace('/','%2F') + '/sub/' + parse.quote(rows[i]['sub']).replace('/','%2F') + '">' + title + '</a> (' + sub + ')</td><td style="text-align: center;width:50%;">' + rows[i]['date'] + '</td></tr></tbody></table>'
  951. i = i + 1
  952. return render_template('index.html', logo = data['name'], rows = div, tn = 12, title = '최근 토론내역')
  953. else:
  954. return render_template('index.html', logo = data['name'], rows = '', tn = 12, title = '최근 토론내역')
  955. @app.route('/recentblock')
  956. def recentblock():
  957. i = 0
  958. div = '<div>'
  959. curs.execute("select * from rb order by today desc limit 50")
  960. rows = curs.fetchall()
  961. if(rows):
  962. while True:
  963. try:
  964. a = rows[i]
  965. except:
  966. div = div + '</div>'
  967. break
  968. why = rows[i]['why']
  969. why = re.sub('<', '&lt;', why)
  970. why = re.sub('>', '&gt;', why)
  971. div = div + '<table style="width: 100%;"><tbody><tr><td style="text-align: center;width:20%;">' + rows[i]['block'] + '</a></td><td style="text-align: center;width:20%;">' + rows[i]['blocker'] + '</td><td style="text-align: center;width:20%;">' + rows[i]['end'] + '</td><td style="text-align: center;width:20%;">' + rows[i]['why'] + '</td><td style="text-align: center;width:20%;">' + rows[i]['today'] + '</td></tr></tbody></table>'
  972. i = i + 1
  973. return render_template('index.html', logo = data['name'], rows = div, tn = 20, title = '최근 차단내역')
  974. else:
  975. return render_template('index.html', logo = data['name'], rows = '', tn = 20, title = '최근 차단내역')
  976. @app.route('/history/<path:name>/n/<int:number>', methods=['POST', 'GET'])
  977. def gethistory(name = None, number = None):
  978. if(request.method == 'POST'):
  979. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '/r/' + request.form["a"] + '/diff/' + request.form["b"] + '" />'
  980. else:
  981. v = number * 50
  982. i = v - 50
  983. div = '<div>'
  984. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' order by id+0 desc")
  985. rows = curs.fetchall()
  986. if(rows):
  987. admin = admincheck()
  988. while True:
  989. try:
  990. a = rows[i]
  991. except:
  992. div = div + '</div>'
  993. if(number != 1):
  994. div = div + '<br><a href="/history/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number - 1) + '">(이전)'
  995. break
  996. if(rows[i]['send']):
  997. send = rows[i]['send']
  998. send = re.sub('<', '&lt;', send)
  999. send = re.sub('>', '&gt;', send)
  1000. send = re.sub('&lt;a href="\/w\/(?P<in>[^"]*)"&gt;(?P<out>[^&]*)&lt;\/a&gt;', '<a href="/w/\g<in>">\g<out></a>', send)
  1001. else:
  1002. send = '<br>'
  1003. m = re.search("\+", rows[i]['leng'])
  1004. n = re.search("\-", rows[i]['leng'])
  1005. if(m):
  1006. leng = '<span style="color:green;">' + rows[i]['leng'] + '</span>'
  1007. elif(n):
  1008. leng = '<span style="color:red;">' + rows[i]['leng'] + '</span>'
  1009. else:
  1010. leng = '<span style="color:gray;">' + rows[i]['leng'] + '</span>'
  1011. if(admin == 1):
  1012. curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1013. row = curs.fetchall()
  1014. if(row):
  1015. if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'):
  1016. ip = rows[i]['ip']
  1017. else:
  1018. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1019. row = curs.fetchall()
  1020. if(row):
  1021. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1022. else:
  1023. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1024. else:
  1025. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1026. row = curs.fetchall()
  1027. if(row):
  1028. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1029. else:
  1030. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1031. else:
  1032. ip = rows[i]['ip']
  1033. div = div + '<table style="width: 100%;"><tbody><tr><td style="text-align: center;width:33.33%;">r' + rows[i]['id'] + '</a> <a href="/w/' + parse.quote(rows[i]['title']).replace('/','%2F') + '/r/' + rows[i]['id'] + '">(w)</a> <a href="/w/' + parse.quote(rows[i]['title']).replace('/','%2F') + '/raw/' + rows[i]['id'] + '">(Raw)</a> <a href="/revert/' + parse.quote(rows[i]['title']).replace('/','%2F') + '/r/' + rows[i]['id'] + '">(되돌리기)</a> (' + leng + ')</td><td style="text-align: center;width:33.33%;">' + ip + '</td><td style="text-align: center;width:33.33%;">' + rows[i]['date'] + '</td></tr><tr><td colspan="3" style="text-align: center;width:100%;">' + send + '</td></tr></tbody></table>'
  1034. if(i == v):
  1035. div = div + '</div>'
  1036. if(number == 1):
  1037. div = div + '<br><a href="/history/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number + 1) + '">(다음)'
  1038. else:
  1039. div = div + '<br><a href="/history/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number - 1) + '">(이전) <a href="/history/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number + 1) + '">(다음)'
  1040. break
  1041. else:
  1042. i = i + 1
  1043. return render_template('index.html', logo = data['name'], rows = div, tn = 5, title = name, page = parse.quote(name).replace('/','%2F'))
  1044. else:
  1045. return render_template('index.html', logo = data['name'], rows = '', tn = 5, title = name, page = parse.quote(name).replace('/','%2F'))
  1046. @app.route('/search', methods=['POST', 'GET'])
  1047. def search():
  1048. if(request.method == 'POST'):
  1049. curs.execute("select * from data where title = '" + pymysql.escape_string(request.form["search"]) + "'")
  1050. rows = curs.fetchall()
  1051. if(rows):
  1052. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '" />'
  1053. else:
  1054. curs.execute("select * from data where title like '%" + pymysql.escape_string(request.form["search"]) + "%'")
  1055. rows = curs.fetchall()
  1056. div = ''
  1057. if(rows):
  1058. i = 0
  1059. div = div + '<li>문서가 없습니다. <a href="/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '">바로가기</a></li><br>'
  1060. while True:
  1061. try:
  1062. div = div + '<li><a href="/w/' + parse.quote(rows[i]['title']).replace('/','%2F') + '">' + rows[i]['title'] + '</a></li>'
  1063. except:
  1064. break
  1065. i = i + 1
  1066. else:
  1067. div = div + '<li>문서가 없습니다. <a href="/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '">바로가기</a></li>'
  1068. return render_template('index.html', logo = data['name'], data = div, title = '검색')
  1069. else:
  1070. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1071. @app.route('/w/<path:name>')
  1072. def w(name = None):
  1073. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1074. rows = curs.fetchall()
  1075. if(rows):
  1076. if(rows[0]['acl'] == 'admin'):
  1077. acl = '(관리자)'
  1078. elif(rows[0]['acl'] == 'user'):
  1079. acl = '(유저)'
  1080. else:
  1081. acl = ''
  1082. enddata = namumark(name, rows[0]['data'])
  1083. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1084. if(m):
  1085. result = m.groups()
  1086. left = result[0]
  1087. else:
  1088. left = ''
  1089. 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)
  1090. else:
  1091. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 1)
  1092. @app.route('/w/<path:name>/redirect/<redirect>')
  1093. def redirectw(name = None, redirect = None):
  1094. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1095. rows = curs.fetchall()
  1096. if(rows):
  1097. if(rows[0]['acl'] == 'admin'):
  1098. acl = '(관리자)'
  1099. elif(rows[0]['acl'] == 'user'):
  1100. acl = '(유저)'
  1101. else:
  1102. acl = ''
  1103. newdata = rows[0]['data']
  1104. newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', ' * \g<in> 문서로 넘겨주기', newdata)
  1105. enddata = namumark(name, newdata)
  1106. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1107. if(m):
  1108. result = m.groups()
  1109. left = result[0]
  1110. else:
  1111. left = ''
  1112. test = redirect
  1113. redirect = re.sub('<', '&lt;', redirect)
  1114. redirect = re.sub('>', '&gt;', redirect)
  1115. redirect = re.sub('"', '&quot;', redirect)
  1116. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'], tn = 1, redirect = '<a href="/edit/' + parse.quote(test).replace('/','%2F') + '">' + redirect + '</a>에서 넘어 왔습니다.', left = left, acl = acl)
  1117. else:
  1118. test = redirect
  1119. redirect = re.sub('<', '&lt;', redirect)
  1120. redirect = re.sub('>', '&gt;', redirect)
  1121. redirect = re.sub('"', '&quot;', redirect)
  1122. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 1, redirect = '<a href="/edit/' + parse.quote(test).replace('/','%2F') + '">' + redirect + '</a>에서 넘어 왔습니다.')
  1123. @app.route('/w/<path:name>/r/<number>')
  1124. def rew(name = None, number = None):
  1125. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1126. rows = curs.fetchall()
  1127. if(rows):
  1128. enddata = namumark(name, rows[0]['data'])
  1129. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1130. if(m):
  1131. result = m.groups()
  1132. left = result[0]
  1133. else:
  1134. left = ''
  1135. 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)
  1136. else:
  1137. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 6)
  1138. @app.route('/w/<path:name>/raw/<number>')
  1139. def reraw(name = None, number = None):
  1140. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1141. rows = curs.fetchall()
  1142. if(rows):
  1143. enddata = re.sub('<', '&lt;', rows[0]['data'])
  1144. enddata = re.sub('>', '&gt;', enddata)
  1145. enddata = re.sub('"', '&quot;', enddata)
  1146. enddata = re.sub("\n", '<br>', enddata)
  1147. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'])
  1148. else:
  1149. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'])
  1150. @app.route('/raw/<path:name>')
  1151. def raw(name = None):
  1152. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1153. rows = curs.fetchall()
  1154. if(rows):
  1155. enddata = re.sub('<', '&lt;', rows[0]['data'])
  1156. enddata = re.sub('>', '&gt;', enddata)
  1157. enddata = re.sub('"', '&quot;', enddata)
  1158. enddata = re.sub("\n", '<br>', enddata)
  1159. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'], tn = 7)
  1160. else:
  1161. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 7)
  1162. @app.route('/revert/<path:name>/r/<number>', methods=['POST', 'GET'])
  1163. def revert(name = None, number = None):
  1164. if(request.method == 'POST'):
  1165. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1166. rows = curs.fetchall()
  1167. if(rows):
  1168. ip = getip(request)
  1169. can = getcan(ip, name)
  1170. if(can == 1):
  1171. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1172. else:
  1173. today = getnow()
  1174. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1175. row = curs.fetchall()
  1176. if(row):
  1177. leng = getleng(len(row[0]['data']), len(rows[0]['data']))
  1178. curs.execute("update data set data = '" + pymysql.escape_string(rows[0]['data']) + "' where title = '" + pymysql.escape_string(name) + "'")
  1179. conn.commit()
  1180. else:
  1181. leng = '+' + str(len(rows[0]['data']))
  1182. curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(rows[0]['data']) + "', '')")
  1183. conn.commit()
  1184. recent(name, ip, today, '문서를 ' + number + '판으로 되돌렸습니다.', leng)
  1185. history(name, rows[0]['data'], today, ip, '문서를 ' + number + '판으로 되돌렸습니다.', leng)
  1186. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1187. else:
  1188. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1189. else:
  1190. ip = getip(request)
  1191. can = getcan(ip, name)
  1192. if(can == 1):
  1193. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1194. else:
  1195. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1196. rows = curs.fetchall()
  1197. if(rows):
  1198. 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 = '정말 되돌리시겠습니까?')
  1199. else:
  1200. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1201. @app.route('/edit/<path:name>', methods=['POST', 'GET'])
  1202. def edit(name = None):
  1203. if(request.method == 'POST'):
  1204. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1205. rows = curs.fetchall()
  1206. if(rows):
  1207. ip = getip(request)
  1208. can = getcan(ip, name)
  1209. if(can == 1):
  1210. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1211. else:
  1212. today = getnow()
  1213. leng = getleng(len(rows[0]['data']), len(request.form["content"]))
  1214. recent(name, ip, today, request.form["send"], leng)
  1215. history(name, request.form["content"], today, ip, request.form["send"], leng)
  1216. curs.execute("update data set data = '" + pymysql.escape_string(request.form["content"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1217. conn.commit()
  1218. else:
  1219. ip = getip(request)
  1220. can = getcan(ip, name)
  1221. if(can == 1):
  1222. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1223. else:
  1224. today = getnow()
  1225. leng = '+' + str(len(request.form["content"]))
  1226. recent(name, ip, today, request.form["send"], leng)
  1227. history(name, request.form["content"], today, ip, request.form["send"], leng)
  1228. curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(request.form["content"]) + "', '')")
  1229. conn.commit()
  1230. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1231. else:
  1232. ip = getip(request)
  1233. can = getcan(ip, name)
  1234. if(can == 1):
  1235. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1236. else:
  1237. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1238. rows = curs.fetchall()
  1239. if(rows):
  1240. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = rows[0]['data'], tn = 2)
  1241. else:
  1242. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '', tn = 2)
  1243. @app.route('/preview/<path:name>', methods=['POST'])
  1244. def preview(name = None):
  1245. ip = getip(request)
  1246. can = getcan(ip, name)
  1247. if(can == 1):
  1248. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1249. else:
  1250. newdata = request.form["content"]
  1251. newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', ' * \g<in> 문서로 넘겨주기', newdata)
  1252. enddata = namumark(name, newdata)
  1253. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1254. if(m):
  1255. result = m.groups()
  1256. left = result[0]
  1257. else:
  1258. left = ''
  1259. m = re.search("^사용자:(.*)", name)
  1260. if(m):
  1261. g = m.groups()
  1262. if(ip == g[0]):
  1263. if(re.search("\.", g[0])):
  1264. return render_template('index.html', title = '사문 오류', logo = data['name'], data = '사문을 사용하려면 로그인 해야 합니다.')
  1265. else:
  1266. 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)
  1267. else:
  1268. return render_template('index.html', title = '사문 오류', logo = data['name'], data = '본인 사문이 아닙니다.')
  1269. else:
  1270. 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)
  1271. @app.route('/delete/<path:name>', methods=['POST', 'GET'])
  1272. def delete(name = None):
  1273. if(request.method == 'POST'):
  1274. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1275. rows = curs.fetchall()
  1276. if(rows):
  1277. ip = getip(request)
  1278. can = getcan(ip, name)
  1279. if(can == 1):
  1280. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1281. else:
  1282. today = getnow()
  1283. leng = '-' + str(len(rows[0]['data']))
  1284. recent(name, ip, today, '문서를 삭제 했습니다.', leng)
  1285. history(name, '', today, ip, '문서를 삭제 했습니다.', leng)
  1286. curs.execute("delete from data where title = '" + pymysql.escape_string(name) + "'")
  1287. conn.commit()
  1288. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1289. else:
  1290. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1291. else:
  1292. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1293. rows = curs.fetchall()
  1294. if(rows):
  1295. ip = getip(request)
  1296. can = getcan(ip, name)
  1297. if(can == 1):
  1298. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1299. else:
  1300. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), tn = 8, plus = '정말 삭제 하시겠습니까?')
  1301. else:
  1302. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1303. @app.route('/move/<path:name>', methods=['POST', 'GET'])
  1304. def move(name = None):
  1305. if(request.method == 'POST'):
  1306. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1307. rows = curs.fetchall()
  1308. if(rows):
  1309. ip = getip(request)
  1310. can = getcan(ip, name)
  1311. if(can == 1):
  1312. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1313. else:
  1314. today = getnow()
  1315. leng = '0'
  1316. curs.execute("select * from history where title = '" + pymysql.escape_string(request.form["title"]) + "'")
  1317. row = curs.fetchall()
  1318. if(row):
  1319. return render_template('index.html', title = '이동 오류', logo = data['name'], data = '이동 하려는 곳에 문서가 이미 있습니다.')
  1320. else:
  1321. recent(name, ip, today, '문서를 <a href="/w/' + pymysql.escape_string(parse.quote(request.form["title"]).replace('/','%2F')) + '">' + pymysql.escape_string(request.form["title"]) + '</a> 문서로 이동 했습니다.', leng)
  1322. history(name, rows[0]['data'], today, ip, '<a href="/w/' + pymysql.escape_string(parse.quote(name).replace('/','%2F')) + '">' + pymysql.escape_string(name) + '</a> 문서를 <a href="/w/' + pymysql.escape_string(parse.quote(request.form["title"]).replace('/','%2F')) + '">' + pymysql.escape_string(request.form["title"]) + '</a> 문서로 이동 했습니다.', leng)
  1323. curs.execute("update data set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1324. curs.execute("update history set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1325. conn.commit()
  1326. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["title"]).replace('/','%2F') + '" />'
  1327. else:
  1328. ip = getip(request)
  1329. can = getcan(ip, name)
  1330. if(can == 1):
  1331. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1332. else:
  1333. today = getnow()
  1334. leng = '0'
  1335. curs.execute("select * from history where title = '" + pymysql.escape_string(request.form["title"]) + "'")
  1336. row = curs.fetchall()
  1337. if(row):
  1338. return render_template('index.html', title = '이동 오류', logo = data['name'], data = '이동 하려는 곳에 문서가 이미 있습니다.')
  1339. else:
  1340. recent(name, ip, today, '문서를 <a href="/w/' + pymysql.escape_string(parse.quote(request.form["title"]).replace('/','%2F')) + '">' + pymysql.escape_string(request.form["title"]) + '</a> 문서로 이동 했습니다.', leng)
  1341. history(name, rows[0]['data'], today, ip, '<a href="/w/' + pymysql.escape_string(parse.quote(name).replace('/','%2F')) + '">' + pymysql.escape_string(name) + '</a> 문서를 <a href="/w/' + pymysql.escape_string(parse.quote(request.form["title"]).replace('/','%2F')) + '">' + pymysql.escape_string(request.form["title"]) + '</a> 문서로 이동 했습니다.', leng)
  1342. curs.execute("update history set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1343. conn.commit()
  1344. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["title"]).replace('/','%2F') + '" />'
  1345. else:
  1346. ip = getip(request)
  1347. can = getcan(ip, name)
  1348. if(can == 1):
  1349. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1350. else:
  1351. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), tn = 9, plus = '정말 이동 하시겠습니까?')
  1352. @app.route('/setup')
  1353. def setup():
  1354. curs.execute("create table if not exists data(title text not null, data longtext not null, acl text not null)")
  1355. 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)")
  1356. curs.execute("create table if not exists rc(title text not null, date text not null, ip text not null, send text not null, leng text not null, back text not null)")
  1357. curs.execute("create table if not exists rd(title text not null, sub text not null, date text not null)")
  1358. curs.execute("create table if not exists user(id text not null, pw text not null, acl text not null)")
  1359. curs.execute("create table if not exists ban(block text not null, end text not null, why text not null, band text not null)")
  1360. 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)")
  1361. curs.execute("create table if not exists stop(title text not null, sub text not null, close text not null)")
  1362. 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)")
  1363. curs.execute("create table if not exists login(user text not null, ip text not null, today text not null)")
  1364. return render_template('index.html', title = '설치 완료', logo = data['name'], data = '문제 없었음')
  1365. @app.route('/other')
  1366. def other():
  1367. return render_template('index.html', title = '기타 메뉴', logo = data['name'], data = '<li><a href="/titleindex">모든 문서</a><li><a href="/grammar">문법 설명</a></li><li><a href="/version">버전</a></li><li><a href="/recentblock">최근 차단내역</a></li><li><a href="/upload">업로드</a></li>')
  1368. @app.route('/titleindex')
  1369. def titleindex():
  1370. i = 0
  1371. div = '<div>'
  1372. curs.execute("select * from data")
  1373. rows = curs.fetchall()
  1374. if(rows):
  1375. while True:
  1376. try:
  1377. a = rows[i]
  1378. except:
  1379. div = div + '</div>'
  1380. break
  1381. div = div + '<li><a href="/w/' + parse.quote(rows[i]['title']).replace('/','%2F') + '">' + rows[i]['title'] + '</a></li>'
  1382. i = i + 1
  1383. curs.execute("select TABLE_ROWS from information_schema.tables where table_name = 'data';")
  1384. row = curs.fetchall()
  1385. return render_template('index.html', logo = data['name'], rows = div + '<br><span>이 위키에는 총 ' + str(row[0]['TABLE_ROWS']) + '개의 문서가 있습니다.</span>', tn = 4, title = '모든 문서')
  1386. else:
  1387. return render_template('index.html', logo = data['name'], rows = '', tn = 4, title = '모든 문서')
  1388. @app.route('/topic/<path:name>', methods=['POST', 'GET'])
  1389. def topic(name = None):
  1390. if(request.method == 'POST'):
  1391. return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(request.form["topic"]).replace('/','%2F') + '" />'
  1392. else:
  1393. div = '<div>'
  1394. i = 0
  1395. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' order by sub asc")
  1396. rows = curs.fetchall()
  1397. while True:
  1398. try:
  1399. a = rows[i]
  1400. except:
  1401. div = div + '</div>'
  1402. break
  1403. j = i + 1
  1404. indata = namumark(name, rows[i]['data'])
  1405. if(rows[i]['block'] == 'O'):
  1406. indata = '블라인드 되었습니다.'
  1407. block = 'style="background: gainsboro;"'
  1408. else:
  1409. block = ''
  1410. if(i == 0):
  1411. sub = rows[i]['sub']
  1412. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'")
  1413. row = curs.fetchall()
  1414. if(not row):
  1415. div = div + '<h2><a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(rows[i]['sub']).replace('/','%2F') + '">' + str((i + 1)) + '. ' + rows[i]['sub'] + '</a></h2>'
  1416. div = div + '<table id="toron"><tbody><tr><td id="toroncolorgreen"><a href="javascript:void(0);" id="' + str(j) + '">#' + str(j) + '</a> ' + rows[i]['ip'] + ' <span style="float:right;">' + rows[i]['date'] + '</span></td></tr><tr><td ' + block + '>' + indata + '</td></tr></tbody></table><br>'
  1417. else:
  1418. if(not sub == rows[i]['sub']):
  1419. sub = rows[i]['sub']
  1420. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'")
  1421. row = curs.fetchall()
  1422. if(not row):
  1423. div = div + '<h2><a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(rows[i]['sub']).replace('/','%2F') + '">' + str((i + 1)) + '. ' + rows[i]['sub'] + '</a></h2>'
  1424. div = div + '<table id="toron"><tbody><tr><td id="toroncolorgreen"><a href="javascript:void(0);" id="' + str(j) + '">#' + str(j) + '</a> ' + rows[i]['ip'] + ' <span style="float:right;">' + rows[i]['date'] + '</span></td></tr><tr><td ' + block + '>' + indata + '</td></tr></tbody></table><br>'
  1425. i = i + 1
  1426. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], plus = div, tn = 10, list = 1)
  1427. @app.route('/topic/<path:name>/close')
  1428. def topicstoplist(name = None):
  1429. if(request.method == 'POST'):
  1430. return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(request.form["topic"]).replace('/','%2F') + '" />'
  1431. else:
  1432. div = '<div>'
  1433. i = 0
  1434. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and close = 'O' order by sub asc")
  1435. rows = curs.fetchall()
  1436. while True:
  1437. try:
  1438. a = rows[i]
  1439. except:
  1440. div = div + '</div>'
  1441. break
  1442. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(rows[i]['sub']) + "' and id = '1'")
  1443. row = curs.fetchall()
  1444. if(row):
  1445. j = i + 1
  1446. indata = namumark(name, row[0]['data'])
  1447. if(row[0]['block'] == 'O'):
  1448. indata = '블라인드 되었습니다.'
  1449. block = 'style="background: gainsboro;"'
  1450. else:
  1451. block = ''
  1452. div = div + '<h2><a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(rows[i]['sub']).replace('/','%2F') + '">' + str((i + 1)) + '. ' + rows[i]['sub'] + '</a></h2>'
  1453. div = div + '<table id="toron"><tbody><tr><td id="toroncolorgreen"><a href="javascript:void(0);" id="' + str(j) + '">#' + str(j) + '</a> ' + row[0]['ip'] + ' <span style="float:right;">' + row[0]['date'] + '</span></td></tr><tr><td ' + block + '>' + indata + '</td></tr></tbody></table><br>'
  1454. i = i + 1
  1455. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], plus = div, tn = 10)
  1456. @app.route('/topic/<path:name>/sub/<path:sub>', methods=['POST', 'GET'])
  1457. def sub(name = None, sub = None):
  1458. if(request.method == 'POST'):
  1459. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
  1460. rows = curs.fetchall()
  1461. if(rows):
  1462. number = int(rows[0]['id']) + 1
  1463. else:
  1464. number = 1
  1465. ip = getip(request)
  1466. ban = getdiscuss(ip, name, sub)
  1467. if(ban == 1):
  1468. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1469. else:
  1470. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1471. rows = curs.fetchall()
  1472. if(rows):
  1473. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1474. ip = ip + ' - Admin'
  1475. today = getnow()
  1476. discuss(name, sub, today)
  1477. 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 + "', '')")
  1478. conn.commit()
  1479. return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '" />'
  1480. else:
  1481. ip = getip(request)
  1482. ban = getdiscuss(ip, name, sub)
  1483. admin = admincheck()
  1484. if(admin == 1):
  1485. div = '<div>' + '<a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '/close">(토론 닫기 및 열기)</a>' + ' <a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '/stop">(토론 정지 및 재개)</a><br><br>'
  1486. else:
  1487. div = '<div>'
  1488. i = 0
  1489. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 asc")
  1490. rows = curs.fetchall()
  1491. while True:
  1492. try:
  1493. a = rows[i]
  1494. except:
  1495. div = div + '</div>'
  1496. break
  1497. if(i == 0):
  1498. start = rows[i]['ip']
  1499. indata = namumark(name, rows[i]['data'])
  1500. if(rows[i]['block'] == 'O'):
  1501. indata = '블라인드 되었습니다.'
  1502. block = 'style="background: gainsboro;"'
  1503. else:
  1504. block = ''
  1505. m = re.search("\- (?:Close|Reopen|Stop|Restart)$", rows[i]['ip'])
  1506. if(m):
  1507. ip = rows[i]['ip']
  1508. else:
  1509. if(admin == 1):
  1510. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1511. row = curs.fetchall()
  1512. if(rows[i]['block'] == 'O'):
  1513. isblock = ' <a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '/b/' + str(i + 1) + '">(해제)</a>'
  1514. else:
  1515. isblock = ' <a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '/b/' + str(i + 1) + '">(블라인드)</a>'
  1516. n = re.search("\- (?:Admin)$", rows[i]['ip'])
  1517. if(n):
  1518. ip = rows[i]['ip'] + isblock
  1519. else:
  1520. if(row):
  1521. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>' + isblock
  1522. else:
  1523. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>' + isblock
  1524. else:
  1525. ip = rows[i]['ip']
  1526. if(rows[i]['ip'] == start):
  1527. j = i + 1
  1528. div = div + '<table id="toron"><tbody><tr><td id="toroncolorgreen"><a href="javascript:void(0);" id="' + str(j) + '">#' + str(j) + '</a> ' + ip + ' <span style="float:right;">' + rows[i]['date'] + '</span></td></tr><tr><td ' + block + '>' + indata + '</td></tr></tbody></table><br>'
  1529. else:
  1530. j = i + 1
  1531. div = div + '<table id="toron"><tbody><tr><td id="toroncolor"><a href="javascript:void(0);" id="' + str(j) + '">#' + str(j) + '</a> ' + ip + ' <span style="float:right;">' + rows[i]['date'] + '</span></td></tr><tr><td ' + block + '>' + indata + '</td></tr></tbody></table><br>'
  1532. i = i + 1
  1533. 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)
  1534. @app.route('/topic/<path:name>/sub/<path:sub>/b/<number>')
  1535. def blind(name = None, sub = None, number = None):
  1536. if(session.get('Now') == True):
  1537. ip = getip(request)
  1538. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1539. rows = curs.fetchall()
  1540. if(rows):
  1541. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1542. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'")
  1543. row = curs.fetchall()
  1544. if(row):
  1545. if(row[0]['block'] == 'O'):
  1546. curs.execute("update topic set block = '' where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'")
  1547. else:
  1548. curs.execute("update topic set block = 'O' where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'")
  1549. conn.commit()
  1550. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  1551. else:
  1552. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  1553. else:
  1554. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1555. else:
  1556. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  1557. else:
  1558. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  1559. @app.route('/topic/<path:name>/sub/<path:sub>/stop')
  1560. def topicstop(name = None, sub = None):
  1561. if(session.get('Now') == True):
  1562. ip = getip(request)
  1563. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1564. rows = curs.fetchall()
  1565. if(rows):
  1566. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1567. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
  1568. row = curs.fetchall()
  1569. if(row):
  1570. today = getnow()
  1571. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = ''")
  1572. rows = curs.fetchall()
  1573. if(rows):
  1574. 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', '')")
  1575. curs.execute("delete from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = ''")
  1576. else:
  1577. 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', '')")
  1578. curs.execute("insert into stop (title, sub, close) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', '')")
  1579. conn.commit()
  1580. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  1581. else:
  1582. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  1583. else:
  1584. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1585. else:
  1586. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  1587. else:
  1588. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  1589. @app.route('/topic/<path:name>/sub/<path:sub>/close')
  1590. def topicclose(name = None, sub = None):
  1591. if(session.get('Now') == True):
  1592. ip = getip(request)
  1593. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1594. rows = curs.fetchall()
  1595. if(rows):
  1596. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1597. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
  1598. row = curs.fetchall()
  1599. if(row):
  1600. today = getnow()
  1601. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'")
  1602. rows = curs.fetchall()
  1603. if(rows):
  1604. 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', '')")
  1605. curs.execute("delete from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'")
  1606. else:
  1607. 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', '')")
  1608. curs.execute("insert into stop (title, sub, close) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', 'O')")
  1609. conn.commit()
  1610. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  1611. else:
  1612. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  1613. else:
  1614. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1615. else:
  1616. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  1617. else:
  1618. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  1619. @app.route('/login', methods=['POST', 'GET'])
  1620. def login():
  1621. if(request.method == 'POST'):
  1622. ip = getip(request)
  1623. ban = getban(ip)
  1624. if(ban == 1):
  1625. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1626. else:
  1627. curs.execute("select * from user where id = '" + pymysql.escape_string(request.form["id"]) + "'")
  1628. rows = curs.fetchall()
  1629. if(rows):
  1630. if(session.get('Now') == True):
  1631. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '이미 로그인 되어 있습니다.')
  1632. elif(bcrypt.checkpw(bytes(request.form["pw"], 'utf-8'), bytes(rows[0]['pw'], 'utf-8'))):
  1633. session['Now'] = True
  1634. session['DREAMER'] = request.form["id"]
  1635. curs.execute("insert into login (user, ip, today) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(ip) + "', '" + pymysql.escape_string(getnow()) + "')")
  1636. conn.commit()
  1637. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1638. else:
  1639. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '비밀번호가 다릅니다.')
  1640. else:
  1641. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '없는 계정 입니다.')
  1642. else:
  1643. ip = getip(request)
  1644. ban = getban(ip)
  1645. if(ban == 1):
  1646. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1647. else:
  1648. if(session.get('Now') == True):
  1649. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '이미 로그인 되어 있습니다.')
  1650. else:
  1651. return render_template('index.html', title = '로그인', enter = '로그인', logo = data['name'], tn = 15)
  1652. @app.route('/check/<path:name>')
  1653. def check(name = None, sub = None, number = None):
  1654. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  1655. rows = curs.fetchall()
  1656. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1657. return render_template('index.html', title = '차단 오류', logo = data['name'], data = '관리자는 검사 할 수 없습니다.')
  1658. else:
  1659. if(admincheck() == 1):
  1660. 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)
  1661. if(m):
  1662. curs.execute("select * from login where ip = '" + pymysql.escape_string(name) + "' order by today desc")
  1663. row = curs.fetchall()
  1664. if(row):
  1665. i = 0
  1666. c = ''
  1667. while True:
  1668. try:
  1669. c = c + '<table style="width: 100%;"><tbody><tr><td style="text-align: center;width:33.33%;">' + row[i]['user'] + '</td><td style="text-align: center;width:33.33%;">' + row[i]['ip'] + '</td><td style="text-align: center;width:33.33%;">' + row[i]['today'] + '</td></tr></tbody></table>'
  1670. except:
  1671. break
  1672. i = i + 1
  1673. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = c)
  1674. else:
  1675. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = '')
  1676. else:
  1677. curs.execute("select * from login where user = '" + pymysql.escape_string(name) + "' order by today desc")
  1678. row = curs.fetchall()
  1679. if(row):
  1680. i = 0
  1681. c = ''
  1682. while True:
  1683. try:
  1684. c = c + '<table style="width: 100%;"><tbody><tr><td style="text-align: center;width:33.33%;">' + row[i]['user'] + '</td><td style="text-align: center;width:33.33%;">' + row[i]['ip'] + '</td><td style="text-align: center;width:33.33%;">' + row[i]['today'] + '</td></tr></tbody></table>'
  1685. except:
  1686. break
  1687. i = i + 1
  1688. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = c)
  1689. else:
  1690. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = '')
  1691. else:
  1692. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1693. @app.route('/register', methods=['POST', 'GET'])
  1694. def register():
  1695. if(request.method == 'POST'):
  1696. ip = getip(request)
  1697. ban = getban(ip)
  1698. if(ban == 1):
  1699. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1700. else:
  1701. m = re.search('(?:[^A-Za-zㄱ-힣0-9 ])', request.form["id"])
  1702. if(m):
  1703. return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '아이디에는 한글과 알파벳 공백만 허용 됩니다.')
  1704. else:
  1705. if(len(request.form["id"]) > 20):
  1706. return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '아이디는 20글자보다 짧아야 합니다.')
  1707. else:
  1708. curs.execute("select * from user where id = '" + pymysql.escape_string(request.form["id"]) + "'")
  1709. rows = curs.fetchall()
  1710. if(rows):
  1711. return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '동일한 아이디의 유저가 있습니다.')
  1712. else:
  1713. hashed = bcrypt.hashpw(bytes(request.form["pw"], 'utf-8'), bcrypt.gensalt())
  1714. if(request.form["id"] == data['owner']):
  1715. curs.execute("insert into user (id, pw, acl) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(hashed.decode()) + "', 'owner')")
  1716. else:
  1717. curs.execute("insert into user (id, pw, acl) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(hashed.decode()) + "', 'user')")
  1718. conn.commit()
  1719. return '<meta http-equiv="refresh" content="0;url=/login" />'
  1720. else:
  1721. ip = getip(request)
  1722. ban = getban(ip)
  1723. if(ban == 1):
  1724. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1725. else:
  1726. return render_template('index.html', title = '회원가입', enter = '회원가입', logo = data['name'], tn = 15)
  1727. @app.route('/logout')
  1728. def logout():
  1729. session['Now'] = False
  1730. session.pop('DREAMER', None)
  1731. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1732. @app.route('/ban/<path:name>', methods=['POST', 'GET'])
  1733. def ban(name = None):
  1734. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  1735. rows = curs.fetchall()
  1736. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1737. return render_template('index.html', title = '차단 오류', logo = data['name'], data = '관리자는 차단 할 수 없습니다.')
  1738. else:
  1739. if(request.method == 'POST'):
  1740. if(admincheck() == 1):
  1741. curs.execute("select * from ban where block = '" + pymysql.escape_string(name) + "'")
  1742. row = curs.fetchall()
  1743. if(row):
  1744. block(name, '해제', getnow(), ip, '')
  1745. curs.execute("delete from ban where block = '" + pymysql.escape_string(name) + "'")
  1746. else:
  1747. b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)$", name)
  1748. if(b):
  1749. block(name, request.form["end"], getnow(), ip, request.form["why"])
  1750. 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')")
  1751. else:
  1752. block(name, request.form["end"], getnow(), ip, request.form["why"])
  1753. 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"]) + "', '')")
  1754. conn.commit()
  1755. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1756. else:
  1757. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1758. else:
  1759. if(admincheck() == 1):
  1760. curs.execute("select * from ban where block = '" + pymysql.escape_string(name) + "'")
  1761. row = curs.fetchall()
  1762. if(row):
  1763. now = '차단 해제'
  1764. else:
  1765. b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)$", name)
  1766. if(b):
  1767. now = '대역 차단'
  1768. else:
  1769. now = '차단'
  1770. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 16, now = now, today = getnow())
  1771. else:
  1772. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1773. @app.route('/acl/<path:name>', methods=['POST', 'GET'])
  1774. def acl(name = None):
  1775. if(request.method == 'POST'):
  1776. if(admincheck() == 1):
  1777. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1778. row = curs.fetchall()
  1779. if(row):
  1780. if(request.form["select"] == 'admin'):
  1781. curs.execute("update data set acl = 'admin' where title = '" + pymysql.escape_string(name) + "'")
  1782. elif(request.form["select"] == 'user'):
  1783. curs.execute("update data set acl = 'user' where title = '" + pymysql.escape_string(name) + "'")
  1784. else:
  1785. curs.execute("update data set acl = '' where title = '" + pymysql.escape_string(name) + "'")
  1786. conn.commit()
  1787. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1788. else:
  1789. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1790. else:
  1791. if(admincheck() == 1):
  1792. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1793. row = curs.fetchall()
  1794. if(row):
  1795. if(row[0]['acl'] == 'admin'):
  1796. now = '관리자만'
  1797. elif(row[0]['acl'] == 'user'):
  1798. now = '유저 이상'
  1799. else:
  1800. now = '일반'
  1801. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 19, now = '현재 ACL 상태는 ' + now)
  1802. else:
  1803. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1804. else:
  1805. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1806. @app.route('/admin/<path:name>', methods=['POST', 'GET'])
  1807. def admin(name = None):
  1808. if(request.method == 'POST'):
  1809. if(session.get('Now') == True):
  1810. ip = getip(request)
  1811. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1812. rows = curs.fetchall()
  1813. if(rows):
  1814. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1815. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  1816. row = curs.fetchall()
  1817. if(row):
  1818. if(row[0]['acl'] == 'admin' or row[0]['acl'] == 'owner'):
  1819. curs.execute("update user set acl = 'user' where id = '" + pymysql.escape_string(name) + "'")
  1820. else:
  1821. curs.execute("update user set acl = '" + pymysql.escape_string(request.form["select"]) + "' where id = '" + pymysql.escape_string(name) + "'")
  1822. conn.commit()
  1823. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1824. else:
  1825. return render_template('index.html', title = '사용자 오류', logo = data['name'], data = '계정이 없습니다.')
  1826. else:
  1827. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1828. else:
  1829. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  1830. else:
  1831. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  1832. else:
  1833. if(session.get('Now') == True):
  1834. ip = getip(request)
  1835. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1836. rows = curs.fetchall()
  1837. if(rows):
  1838. if(rows[0]['acl'] == 'owner'):
  1839. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  1840. row = curs.fetchall()
  1841. if(row):
  1842. if(row[0]['acl'] == 'admin' or row[0]['acl'] == 'owner'):
  1843. now = '권한 해제'
  1844. else:
  1845. now = '권한 부여'
  1846. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 18, now = now)
  1847. else:
  1848. return render_template('index.html', title = '사용자 오류', logo = data['name'], data = '계정이 없습니다.')
  1849. else:
  1850. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1851. else:
  1852. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  1853. else:
  1854. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  1855. @app.route('/grammar')
  1856. def grammar():
  1857. return render_template('index.html', title = '문법 설명', logo = data['name'], tn = 17)
  1858. @app.route('/ban')
  1859. def aban():
  1860. ip = getip(request)
  1861. if(getban(ip) == 1):
  1862. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  1863. rows = curs.fetchall()
  1864. if(rows):
  1865. if(rows[0]['end']):
  1866. end = rows[0]['end'] + ' 까지 차단 상태 입니다. / 사유 : ' + rows[0]['why']
  1867. now = getnow()
  1868. now = re.sub(':', '', now)
  1869. now = re.sub('\-', '', now)
  1870. now = re.sub(' ', '', now)
  1871. now = int(now)
  1872. day = rows[0]['end']
  1873. day = re.sub('\-', '', day)
  1874. if(now >= int(day + '000000')):
  1875. curs.execute("delete from ban where block = '" + pymysql.escape_string(ip) + "'")
  1876. conn.commit()
  1877. end = '차단이 풀렸습니다. 다시 시도 해 보세요.'
  1878. else:
  1879. end = '영구 차단 상태 입니다. / 사유 : ' + rows[0]['why']
  1880. else:
  1881. b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)", ip)
  1882. if(b):
  1883. results = b.groups()
  1884. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  1885. row = curs.fetchall()
  1886. if(row):
  1887. if(row[0]['end']):
  1888. end = row[0]['end'] + ' 까지 차단 상태 입니다. / 사유 : ' + rows[0]['why']
  1889. now = getnow()
  1890. now = re.sub(':', '', now)
  1891. now = re.sub('\-', '', now)
  1892. now = re.sub(' ', '', now)
  1893. now = int(now)
  1894. day = row[0]['end']
  1895. day = re.sub('\-', '', day)
  1896. if(now >= int(day + '000000')):
  1897. curs.execute("delete from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  1898. conn.commit()
  1899. end = '차단이 풀렸습니다. 다시 시도 해 보세요.'
  1900. else:
  1901. end = '영구 차단 상태 입니다. / 사유 : ' + row[0]['why']
  1902. else:
  1903. end = '권한이 맞지 않는 상태 입니다.'
  1904. return render_template('index.html', title = '권한 오류', logo = data['name'], data = end)
  1905. @app.route('/w/<path:name>/r/<a>/diff/<b>')
  1906. def diff(name = None, a = None, b = None):
  1907. curs.execute("select * from history where id = '" + pymysql.escape_string(a) + "' and title = '" + pymysql.escape_string(name) + "'")
  1908. rows = curs.fetchall()
  1909. if(rows):
  1910. curs.execute("select * from history where id = '" + pymysql.escape_string(b) + "' and title = '" + pymysql.escape_string(name) + "'")
  1911. row = curs.fetchall()
  1912. if(row):
  1913. indata = re.sub('<', '&lt;', rows[0]['data'])
  1914. indata = re.sub('>', '&gt;', indata)
  1915. indata = re.sub('"', '&quot;', indata)
  1916. indata = re.sub('\n', '<br>', indata)
  1917. enddata = re.sub('<', '&lt;', row[0]['data'])
  1918. enddata = re.sub('>', '&gt;', enddata)
  1919. enddata = re.sub('"', '&quot;', enddata)
  1920. enddata = re.sub('\n', '<br>', enddata)
  1921. sm = difflib.SequenceMatcher(None, indata, enddata)
  1922. c = show_diff(sm)
  1923. return render_template('index.html', title = 'Diff', logo = data['name'], data = c)
  1924. else:
  1925. return render_template('index.html', title = 'Diff 오류', logo = data['name'], data = '<a href="/w/' + name + '">이 리비전이나 문서가 없습니다.</a>')
  1926. else:
  1927. return render_template('index.html', title = 'Diff 오류', logo = data['name'], data = '<a href="/w/' + name + '">이 리비전이나 문서가 없습니다.</a>')
  1928. @app.route('/version')
  1929. def version():
  1930. return render_template('index.html', title = '버전', logo = data['name'], tn = 14)
  1931. @app.route('/user')
  1932. def user():
  1933. ip = getip(request)
  1934. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1935. rows = curs.fetchall()
  1936. if(getban(ip) == 0):
  1937. if(rows):
  1938. if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'):
  1939. acl = '관리자'
  1940. else:
  1941. acl = '유저'
  1942. else:
  1943. acl = '일반'
  1944. else:
  1945. acl = '차단'
  1946. return render_template('index.html', title = '유저 메뉴', logo = data['name'], data = ip + '<br><br><span>권한 상태 : ' + acl + '<br><br><li><a href="/login">로그인</a></li><li><a href="/logout">로그아웃</a></li><li><a href="/register">회원가입</a></li>')
  1947. @app.route('/random')
  1948. def random():
  1949. curs.execute("select * from data order by rand() limit 1")
  1950. rows = curs.fetchall()
  1951. if(rows):
  1952. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(rows[0]['title']).replace('/','%2F') + '" />'
  1953. else:
  1954. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1955. @app.errorhandler(404)
  1956. def uncaughtError(error):
  1957. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1958. if __name__ == '__main__':
  1959. app.run(host = '0.0.0.0', port = int(data['port']))