app.py 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111
  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. if(not re.search("^사용자:(.*)", title)):
  807. curs.execute("insert into rc (title, date, ip, send, leng, back) value ('" + pymysql.escape_string(title) + "', '" + today + "', '" + ip + "', '" + pymysql.escape_string(send) + "', '" + leng + "', '')")
  808. conn.commit()
  809. def discuss(title, sub, date):
  810. curs.execute("select * from rd where title = '" + pymysql.escape_string(title) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  811. rows = curs.fetchall()
  812. if(rows):
  813. curs.execute("update rd set date = '" + pymysql.escape_string(date) + "' where title = '" + pymysql.escape_string(title) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  814. else:
  815. curs.execute("insert into rd (title, sub, date) value ('" + pymysql.escape_string(title) + "', '" + pymysql.escape_string(sub) + "', '" + pymysql.escape_string(date) + "')")
  816. conn.commit()
  817. def block(block, end, today, blocker, why):
  818. 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) + "')")
  819. conn.commit()
  820. def history(title, data, date, ip, send, leng):
  821. curs.execute("select * from history where title = '" + pymysql.escape_string(title) + "' order by id+0 desc limit 1")
  822. rows = curs.fetchall()
  823. if(rows):
  824. number = int(rows[0]['id']) + 1
  825. 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 + "')")
  826. conn.commit()
  827. else:
  828. 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 + "')")
  829. conn.commit()
  830. def getleng(existing, change):
  831. if(existing < change):
  832. leng = change - existing
  833. leng = '+' + str(leng)
  834. elif(change < existing):
  835. leng = existing - change
  836. leng = '-' + str(leng)
  837. else:
  838. leng = '0'
  839. return leng;
  840. @app.route('/upload', methods=['GET', 'POST'])
  841. def upload():
  842. if(request.method == 'POST'):
  843. ip = getip(request)
  844. ban = getban(ip)
  845. if(ban == 1):
  846. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  847. else:
  848. file = request.files['file']
  849. if(file and allowed_file(file.filename)):
  850. filename = secure_filename(file.filename)
  851. if(os.path.exists(os.path.join('image', filename))):
  852. return render_template('index.html', logo = data['name'], title = '업로드', data = '동일한 이름의 파일이 있습니다.')
  853. else:
  854. file.save(os.path.join('image', filename))
  855. return render_template('index.html', logo = data['name'], title = '업로드', data = '완료 되었습니다.')
  856. else:
  857. return render_template('index.html', logo = data['name'], title = '업로드', data = 'jpg gif jpeg png만 가능 합니다.')
  858. else:
  859. ip = getip(request)
  860. ban = getban(ip)
  861. if(ban == 1):
  862. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  863. else:
  864. return render_template('index.html', logo = data['name'], title = '업로드', tn = 21, number = data['upload'])
  865. @app.route('/image/<path:name>')
  866. def image(name = None):
  867. filename = secure_filename(name)
  868. return send_file(os.path.join('image', filename), mimetype='image')
  869. @app.route('/')
  870. @app.route('/w/')
  871. def redirect():
  872. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  873. @app.route('/recentchanges')
  874. def recentchanges():
  875. i = 0
  876. div = '<div>'
  877. curs.execute("select * from rc order by date desc limit 50")
  878. rows = curs.fetchall()
  879. if(rows):
  880. admin = admincheck()
  881. while True:
  882. try:
  883. a = rows[i]
  884. except:
  885. div = div + '</div>'
  886. break
  887. if(rows[i]['send']):
  888. send = rows[i]['send']
  889. send = re.sub('<', '&lt;', send)
  890. send = re.sub('>', '&gt;', send)
  891. send = re.sub('&lt;a href="\/w\/(?P<in>[^"]*)"&gt;(?P<out>[^&]*)&lt;\/a&gt;', '<a href="/w/\g<in>">\g<out></a>', send)
  892. else:
  893. send = '<br>'
  894. title = rows[i]['title']
  895. title = re.sub('<', '&lt;', title)
  896. title = re.sub('>', '&gt;', title)
  897. m = re.search("\+", rows[i]['leng'])
  898. n = re.search("\-", rows[i]['leng'])
  899. if(m):
  900. leng = '<span style="color:green;">' + rows[i]['leng'] + '</span>'
  901. elif(n):
  902. leng = '<span style="color:red;">' + rows[i]['leng'] + '</span>'
  903. else:
  904. leng = '<span style="color:gray;">' + rows[i]['leng'] + '</span>'
  905. if(admin == 1):
  906. curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  907. row = curs.fetchall()
  908. if(row):
  909. if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'):
  910. ip = rows[i]['ip']
  911. else:
  912. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  913. row = curs.fetchall()
  914. if(row):
  915. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  916. else:
  917. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  918. else:
  919. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  920. row = curs.fetchall()
  921. if(row):
  922. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  923. else:
  924. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  925. else:
  926. ip = rows[i]['ip']
  927. 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>'
  928. i = i + 1
  929. return render_template('index.html', logo = data['name'], rows = div, tn = 3, title = '최근 변경내역')
  930. else:
  931. return render_template('index.html', logo = data['name'], rows = '', tn = 3, title = '최근 변경내역')
  932. @app.route('/recentdiscuss')
  933. def recentdiscuss():
  934. i = 0
  935. div = '<div>'
  936. curs.execute("select * from rd order by date desc limit 50")
  937. rows = curs.fetchall()
  938. if(rows):
  939. while True:
  940. try:
  941. a = rows[i]
  942. except:
  943. div = div + '</div>'
  944. break
  945. title = rows[i]['title']
  946. title = re.sub('<', '&lt;', title)
  947. title = re.sub('>', '&gt;', title)
  948. sub = rows[i]['sub']
  949. sub = re.sub('<', '&lt;', sub)
  950. sub = re.sub('>', '&gt;', sub)
  951. 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>'
  952. i = i + 1
  953. return render_template('index.html', logo = data['name'], rows = div, tn = 12, title = '최근 토론내역')
  954. else:
  955. return render_template('index.html', logo = data['name'], rows = '', tn = 12, title = '최근 토론내역')
  956. @app.route('/recentblock')
  957. def recentblock():
  958. i = 0
  959. div = '<div>'
  960. curs.execute("select * from rb order by today desc limit 50")
  961. rows = curs.fetchall()
  962. if(rows):
  963. while True:
  964. try:
  965. a = rows[i]
  966. except:
  967. div = div + '</div>'
  968. break
  969. why = rows[i]['why']
  970. why = re.sub('<', '&lt;', why)
  971. why = re.sub('>', '&gt;', why)
  972. 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>'
  973. i = i + 1
  974. return render_template('index.html', logo = data['name'], rows = div, tn = 20, title = '최근 차단내역')
  975. else:
  976. return render_template('index.html', logo = data['name'], rows = '', tn = 20, title = '최근 차단내역')
  977. @app.route('/history/<path:name>/n/<int:number>', methods=['POST', 'GET'])
  978. def gethistory(name = None, number = None):
  979. if(request.method == 'POST'):
  980. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '/r/' + request.form["a"] + '/diff/' + request.form["b"] + '" />'
  981. else:
  982. v = number * 50
  983. i = v - 50
  984. div = '<div>'
  985. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' order by id+0 desc")
  986. rows = curs.fetchall()
  987. if(rows):
  988. admin = admincheck()
  989. while True:
  990. try:
  991. a = rows[i]
  992. except:
  993. div = div + '</div>'
  994. if(number != 1):
  995. div = div + '<br><a href="/history/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number - 1) + '">(이전)'
  996. break
  997. if(rows[i]['send']):
  998. send = rows[i]['send']
  999. send = re.sub('<', '&lt;', send)
  1000. send = re.sub('>', '&gt;', send)
  1001. send = re.sub('&lt;a href="\/w\/(?P<in>[^"]*)"&gt;(?P<out>[^&]*)&lt;\/a&gt;', '<a href="/w/\g<in>">\g<out></a>', send)
  1002. else:
  1003. send = '<br>'
  1004. m = re.search("\+", rows[i]['leng'])
  1005. n = re.search("\-", rows[i]['leng'])
  1006. if(m):
  1007. leng = '<span style="color:green;">' + rows[i]['leng'] + '</span>'
  1008. elif(n):
  1009. leng = '<span style="color:red;">' + rows[i]['leng'] + '</span>'
  1010. else:
  1011. leng = '<span style="color:gray;">' + rows[i]['leng'] + '</span>'
  1012. if(admin == 1):
  1013. curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1014. row = curs.fetchall()
  1015. if(row):
  1016. if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'):
  1017. ip = rows[i]['ip']
  1018. else:
  1019. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1020. row = curs.fetchall()
  1021. if(row):
  1022. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1023. else:
  1024. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1025. else:
  1026. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1027. row = curs.fetchall()
  1028. if(row):
  1029. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1030. else:
  1031. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1032. else:
  1033. ip = rows[i]['ip']
  1034. 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>'
  1035. if(i == v):
  1036. div = div + '</div>'
  1037. if(number == 1):
  1038. div = div + '<br><a href="/history/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number + 1) + '">(다음)'
  1039. else:
  1040. 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) + '">(다음)'
  1041. break
  1042. else:
  1043. i = i + 1
  1044. return render_template('index.html', logo = data['name'], rows = div, tn = 5, title = name, page = parse.quote(name).replace('/','%2F'))
  1045. else:
  1046. return render_template('index.html', logo = data['name'], rows = '', tn = 5, title = name, page = parse.quote(name).replace('/','%2F'))
  1047. @app.route('/search', methods=['POST', 'GET'])
  1048. def search():
  1049. if(request.method == 'POST'):
  1050. curs.execute("select * from data where title = '" + pymysql.escape_string(request.form["search"]) + "'")
  1051. rows = curs.fetchall()
  1052. if(rows):
  1053. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '" />'
  1054. else:
  1055. curs.execute("select * from data where title like '%" + pymysql.escape_string(request.form["search"]) + "%'")
  1056. rows = curs.fetchall()
  1057. div = ''
  1058. if(rows):
  1059. i = 0
  1060. div = div + '<li>문서가 없습니다. <a href="/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '">바로가기</a></li><br>'
  1061. while True:
  1062. try:
  1063. div = div + '<li><a href="/w/' + parse.quote(rows[i]['title']).replace('/','%2F') + '">' + rows[i]['title'] + '</a></li>'
  1064. except:
  1065. break
  1066. i = i + 1
  1067. else:
  1068. return div + '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '" />'
  1069. return render_template('index.html', logo = data['name'], data = div, title = '검색')
  1070. else:
  1071. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1072. @app.route('/w/<path:name>')
  1073. def w(name = None):
  1074. m = re.search("^(.*)\/(.*)$", name)
  1075. if(m):
  1076. g = m.groups()
  1077. uppage = g[0]
  1078. style = ""
  1079. else:
  1080. uppage = ""
  1081. style = "display:none;"
  1082. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1083. rows = curs.fetchall()
  1084. if(rows):
  1085. if(rows[0]['acl'] == 'admin'):
  1086. acl = '(관리자)'
  1087. elif(rows[0]['acl'] == 'user'):
  1088. acl = '(유저)'
  1089. else:
  1090. acl = ''
  1091. enddata = namumark(name, rows[0]['data'])
  1092. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1093. if(m):
  1094. result = m.groups()
  1095. left = result[0]
  1096. else:
  1097. left = ''
  1098. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'], tn = 1, acl = acl, left = left, uppage = uppage, style = style)
  1099. else:
  1100. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 1, uppage = uppage, style = style)
  1101. @app.route('/w/<path:name>/redirect/<redirect>')
  1102. def redirectw(name = None, redirect = None):
  1103. m = re.search("^(.*)\/(.*)$", name)
  1104. if(m):
  1105. g = m.groups()
  1106. uppage = g[0]
  1107. style = ""
  1108. else:
  1109. uppage = ""
  1110. style = "display:none;"
  1111. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1112. rows = curs.fetchall()
  1113. if(rows):
  1114. if(rows[0]['acl'] == 'admin'):
  1115. acl = '(관리자)'
  1116. elif(rows[0]['acl'] == 'user'):
  1117. acl = '(유저)'
  1118. else:
  1119. acl = ''
  1120. newdata = rows[0]['data']
  1121. newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', ' * \g<in> 문서로 넘겨주기', newdata)
  1122. enddata = namumark(name, newdata)
  1123. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1124. if(m):
  1125. result = m.groups()
  1126. left = result[0]
  1127. else:
  1128. left = ''
  1129. test = redirect
  1130. redirect = re.sub('<', '&lt;', redirect)
  1131. redirect = re.sub('>', '&gt;', redirect)
  1132. redirect = re.sub('"', '&quot;', redirect)
  1133. 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, uppage = uppage, style = style)
  1134. else:
  1135. test = redirect
  1136. redirect = re.sub('<', '&lt;', redirect)
  1137. redirect = re.sub('>', '&gt;', redirect)
  1138. redirect = re.sub('"', '&quot;', redirect)
  1139. 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>에서 넘어 왔습니다.', uppage = uppage, style = style)
  1140. @app.route('/w/<path:name>/r/<number>')
  1141. def rew(name = None, number = None):
  1142. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1143. rows = curs.fetchall()
  1144. if(rows):
  1145. enddata = namumark(name, rows[0]['data'])
  1146. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1147. if(m):
  1148. result = m.groups()
  1149. left = result[0]
  1150. else:
  1151. left = ''
  1152. 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)
  1153. else:
  1154. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 6)
  1155. @app.route('/w/<path:name>/raw/<number>')
  1156. def reraw(name = None, number = None):
  1157. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1158. rows = curs.fetchall()
  1159. if(rows):
  1160. enddata = re.sub('<', '&lt;', rows[0]['data'])
  1161. enddata = re.sub('>', '&gt;', enddata)
  1162. enddata = re.sub('"', '&quot;', enddata)
  1163. enddata = re.sub("\n", '<br>', enddata)
  1164. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'])
  1165. else:
  1166. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'])
  1167. @app.route('/raw/<path:name>')
  1168. def raw(name = None):
  1169. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1170. rows = curs.fetchall()
  1171. if(rows):
  1172. enddata = re.sub('<', '&lt;', rows[0]['data'])
  1173. enddata = re.sub('>', '&gt;', enddata)
  1174. enddata = re.sub('"', '&quot;', enddata)
  1175. enddata = re.sub("\n", '<br>', enddata)
  1176. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'], tn = 7)
  1177. else:
  1178. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 7)
  1179. @app.route('/revert/<path:name>/r/<number>', methods=['POST', 'GET'])
  1180. def revert(name = None, number = None):
  1181. if(request.method == 'POST'):
  1182. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1183. rows = curs.fetchall()
  1184. if(rows):
  1185. ip = getip(request)
  1186. can = getcan(ip, name)
  1187. if(can == 1):
  1188. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1189. else:
  1190. today = getnow()
  1191. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1192. row = curs.fetchall()
  1193. if(row):
  1194. leng = getleng(len(row[0]['data']), len(rows[0]['data']))
  1195. curs.execute("update data set data = '" + pymysql.escape_string(rows[0]['data']) + "' where title = '" + pymysql.escape_string(name) + "'")
  1196. conn.commit()
  1197. else:
  1198. leng = '+' + str(len(rows[0]['data']))
  1199. curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(rows[0]['data']) + "', '')")
  1200. conn.commit()
  1201. recent(name, ip, today, '문서를 ' + number + '판으로 되돌렸습니다.', leng)
  1202. history(name, rows[0]['data'], today, ip, '문서를 ' + number + '판으로 되돌렸습니다.', leng)
  1203. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1204. else:
  1205. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1206. else:
  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. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1213. rows = curs.fetchall()
  1214. if(rows):
  1215. 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 = '정말 되돌리시겠습니까?')
  1216. else:
  1217. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1218. @app.route('/edit/<path:name>', methods=['POST', 'GET'])
  1219. def edit(name = None):
  1220. if(request.method == 'POST'):
  1221. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1222. rows = curs.fetchall()
  1223. if(rows):
  1224. ip = getip(request)
  1225. can = getcan(ip, name)
  1226. if(can == 1):
  1227. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1228. else:
  1229. today = getnow()
  1230. leng = getleng(len(rows[0]['data']), len(request.form["content"]))
  1231. recent(name, ip, today, request.form["send"], leng)
  1232. history(name, request.form["content"], today, ip, request.form["send"], leng)
  1233. curs.execute("update data set data = '" + pymysql.escape_string(request.form["content"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1234. conn.commit()
  1235. else:
  1236. ip = getip(request)
  1237. can = getcan(ip, name)
  1238. if(can == 1):
  1239. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1240. else:
  1241. today = getnow()
  1242. leng = '+' + str(len(request.form["content"]))
  1243. recent(name, ip, today, request.form["send"], leng)
  1244. history(name, request.form["content"], today, ip, request.form["send"], leng)
  1245. curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(request.form["content"]) + "', '')")
  1246. conn.commit()
  1247. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1248. else:
  1249. ip = getip(request)
  1250. can = getcan(ip, name)
  1251. if(can == 1):
  1252. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1253. else:
  1254. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1255. rows = curs.fetchall()
  1256. if(rows):
  1257. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = rows[0]['data'], tn = 2)
  1258. else:
  1259. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '', tn = 2)
  1260. @app.route('/preview/<path:name>', methods=['POST'])
  1261. def preview(name = None):
  1262. ip = getip(request)
  1263. can = getcan(ip, name)
  1264. if(can == 1):
  1265. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1266. else:
  1267. newdata = request.form["content"]
  1268. newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', ' * \g<in> 문서로 넘겨주기', newdata)
  1269. enddata = namumark(name, newdata)
  1270. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1271. if(m):
  1272. result = m.groups()
  1273. left = result[0]
  1274. else:
  1275. left = ''
  1276. m = re.search("^사용자:(.*)", name)
  1277. if(m):
  1278. g = m.groups()
  1279. if(ip == g[0]):
  1280. if(re.search("\.", g[0])):
  1281. return render_template('index.html', title = '사문 오류', logo = data['name'], data = '사문을 사용하려면 로그인 해야 합니다.')
  1282. else:
  1283. 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)
  1284. else:
  1285. return render_template('index.html', title = '사문 오류', logo = data['name'], data = '본인 사문이 아닙니다.')
  1286. else:
  1287. 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)
  1288. @app.route('/delete/<path:name>', methods=['POST', 'GET'])
  1289. def delete(name = None):
  1290. if(request.method == 'POST'):
  1291. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1292. rows = curs.fetchall()
  1293. if(rows):
  1294. ip = getip(request)
  1295. can = getcan(ip, name)
  1296. if(can == 1):
  1297. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1298. else:
  1299. today = getnow()
  1300. leng = '-' + str(len(rows[0]['data']))
  1301. recent(name, ip, today, '문서를 삭제 했습니다.', leng)
  1302. history(name, '', today, ip, '문서를 삭제 했습니다.', leng)
  1303. curs.execute("delete from data where title = '" + pymysql.escape_string(name) + "'")
  1304. conn.commit()
  1305. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1306. else:
  1307. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1308. else:
  1309. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1310. rows = curs.fetchall()
  1311. if(rows):
  1312. ip = getip(request)
  1313. can = getcan(ip, name)
  1314. if(can == 1):
  1315. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1316. else:
  1317. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), tn = 8, plus = '정말 삭제 하시겠습니까?')
  1318. else:
  1319. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1320. @app.route('/move/<path:name>', methods=['POST', 'GET'])
  1321. def move(name = None):
  1322. if(request.method == 'POST'):
  1323. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1324. rows = curs.fetchall()
  1325. if(rows):
  1326. ip = getip(request)
  1327. can = getcan(ip, name)
  1328. if(can == 1):
  1329. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1330. else:
  1331. today = getnow()
  1332. leng = '0'
  1333. curs.execute("select * from history where title = '" + pymysql.escape_string(request.form["title"]) + "'")
  1334. row = curs.fetchall()
  1335. if(row):
  1336. return render_template('index.html', title = '이동 오류', logo = data['name'], data = '이동 하려는 곳에 문서가 이미 있습니다.')
  1337. else:
  1338. 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)
  1339. 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)
  1340. curs.execute("update data set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1341. curs.execute("update history set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1342. conn.commit()
  1343. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["title"]).replace('/','%2F') + '" />'
  1344. else:
  1345. ip = getip(request)
  1346. can = getcan(ip, name)
  1347. if(can == 1):
  1348. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1349. else:
  1350. today = getnow()
  1351. leng = '0'
  1352. curs.execute("select * from history where title = '" + pymysql.escape_string(request.form["title"]) + "'")
  1353. row = curs.fetchall()
  1354. if(row):
  1355. return render_template('index.html', title = '이동 오류', logo = data['name'], data = '이동 하려는 곳에 문서가 이미 있습니다.')
  1356. else:
  1357. 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)
  1358. 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)
  1359. curs.execute("update history set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1360. conn.commit()
  1361. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["title"]).replace('/','%2F') + '" />'
  1362. else:
  1363. ip = getip(request)
  1364. can = getcan(ip, name)
  1365. if(can == 1):
  1366. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1367. else:
  1368. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), tn = 9, plus = '정말 이동 하시겠습니까?')
  1369. @app.route('/setup')
  1370. def setup():
  1371. curs.execute("create table if not exists data(title text not null, data longtext not null, acl text not null)")
  1372. 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)")
  1373. 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)")
  1374. curs.execute("create table if not exists rd(title text not null, sub text not null, date text not null)")
  1375. curs.execute("create table if not exists user(id text not null, pw text not null, acl text not null)")
  1376. curs.execute("create table if not exists ban(block text not null, end text not null, why text not null, band text not null)")
  1377. 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)")
  1378. curs.execute("create table if not exists stop(title text not null, sub text not null, close text not null)")
  1379. 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)")
  1380. curs.execute("create table if not exists login(user text not null, ip text not null, today text not null)")
  1381. return render_template('index.html', title = '설치 완료', logo = data['name'], data = '문제 없었음')
  1382. @app.route('/other')
  1383. def other():
  1384. 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>')
  1385. @app.route('/titleindex')
  1386. def titleindex():
  1387. i = 0
  1388. div = '<div>'
  1389. curs.execute("select * from data")
  1390. rows = curs.fetchall()
  1391. if(rows):
  1392. while True:
  1393. try:
  1394. a = rows[i]
  1395. except:
  1396. div = div + '</div>'
  1397. break
  1398. div = div + '<li><a href="/w/' + parse.quote(rows[i]['title']).replace('/','%2F') + '">' + rows[i]['title'] + '</a></li>'
  1399. i = i + 1
  1400. curs.execute("select TABLE_ROWS from information_schema.tables where table_name = 'data';")
  1401. row = curs.fetchall()
  1402. return render_template('index.html', logo = data['name'], rows = div + '<br><span>이 위키에는 총 ' + str(row[0]['TABLE_ROWS']) + '개의 문서가 있습니다.</span>', tn = 4, title = '모든 문서')
  1403. else:
  1404. return render_template('index.html', logo = data['name'], rows = '', tn = 4, title = '모든 문서')
  1405. @app.route('/topic/<path:name>', methods=['POST', 'GET'])
  1406. def topic(name = None):
  1407. if(request.method == 'POST'):
  1408. return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(request.form["topic"]).replace('/','%2F') + '" />'
  1409. else:
  1410. div = '<div>'
  1411. i = 0
  1412. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' order by sub asc")
  1413. rows = curs.fetchall()
  1414. while True:
  1415. try:
  1416. a = rows[i]
  1417. except:
  1418. div = div + '</div>'
  1419. break
  1420. j = i + 1
  1421. indata = namumark(name, rows[i]['data'])
  1422. if(rows[i]['block'] == 'O'):
  1423. indata = '블라인드 되었습니다.'
  1424. block = 'style="background: gainsboro;"'
  1425. else:
  1426. block = ''
  1427. if(i == 0):
  1428. sub = rows[i]['sub']
  1429. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'")
  1430. row = curs.fetchall()
  1431. if(not row):
  1432. 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>'
  1433. 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>'
  1434. else:
  1435. if(not sub == rows[i]['sub']):
  1436. sub = rows[i]['sub']
  1437. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'")
  1438. row = curs.fetchall()
  1439. if(not row):
  1440. 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>'
  1441. 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>'
  1442. i = i + 1
  1443. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], plus = div, tn = 10, list = 1)
  1444. @app.route('/topic/<path:name>/close')
  1445. def topicstoplist(name = None):
  1446. if(request.method == 'POST'):
  1447. return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(request.form["topic"]).replace('/','%2F') + '" />'
  1448. else:
  1449. div = '<div>'
  1450. i = 0
  1451. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and close = 'O' order by sub asc")
  1452. rows = curs.fetchall()
  1453. while True:
  1454. try:
  1455. a = rows[i]
  1456. except:
  1457. div = div + '</div>'
  1458. break
  1459. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(rows[i]['sub']) + "' and id = '1'")
  1460. row = curs.fetchall()
  1461. if(row):
  1462. j = i + 1
  1463. indata = namumark(name, row[0]['data'])
  1464. if(row[0]['block'] == 'O'):
  1465. indata = '블라인드 되었습니다.'
  1466. block = 'style="background: gainsboro;"'
  1467. else:
  1468. block = ''
  1469. 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>'
  1470. 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>'
  1471. i = i + 1
  1472. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], plus = div, tn = 10)
  1473. @app.route('/topic/<path:name>/sub/<path:sub>', methods=['POST', 'GET'])
  1474. def sub(name = None, sub = None):
  1475. if(request.method == 'POST'):
  1476. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
  1477. rows = curs.fetchall()
  1478. if(rows):
  1479. number = int(rows[0]['id']) + 1
  1480. else:
  1481. number = 1
  1482. ip = getip(request)
  1483. ban = getdiscuss(ip, name, sub)
  1484. if(ban == 1):
  1485. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1486. else:
  1487. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1488. rows = curs.fetchall()
  1489. if(rows):
  1490. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1491. ip = ip + ' - Admin'
  1492. today = getnow()
  1493. discuss(name, sub, today)
  1494. 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 + "', '')")
  1495. conn.commit()
  1496. return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '" />'
  1497. else:
  1498. ip = getip(request)
  1499. ban = getdiscuss(ip, name, sub)
  1500. admin = admincheck()
  1501. if(admin == 1):
  1502. 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>'
  1503. else:
  1504. div = '<div>'
  1505. i = 0
  1506. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 asc")
  1507. rows = curs.fetchall()
  1508. while True:
  1509. try:
  1510. a = rows[i]
  1511. except:
  1512. div = div + '</div>'
  1513. break
  1514. if(i == 0):
  1515. start = rows[i]['ip']
  1516. indata = namumark(name, rows[i]['data'])
  1517. if(rows[i]['block'] == 'O'):
  1518. indata = '블라인드 되었습니다.'
  1519. block = 'style="background: gainsboro;"'
  1520. else:
  1521. block = ''
  1522. m = re.search("\- (?:Close|Reopen|Stop|Restart)$", rows[i]['ip'])
  1523. if(m):
  1524. ip = rows[i]['ip']
  1525. else:
  1526. if(admin == 1):
  1527. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1528. row = curs.fetchall()
  1529. if(rows[i]['block'] == 'O'):
  1530. isblock = ' <a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '/b/' + str(i + 1) + '">(해제)</a>'
  1531. else:
  1532. isblock = ' <a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '/b/' + str(i + 1) + '">(블라인드)</a>'
  1533. n = re.search("\- (?:Admin)$", rows[i]['ip'])
  1534. if(n):
  1535. ip = rows[i]['ip'] + isblock
  1536. else:
  1537. if(row):
  1538. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>' + isblock
  1539. else:
  1540. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>' + isblock
  1541. else:
  1542. ip = rows[i]['ip']
  1543. if(rows[i]['ip'] == start):
  1544. j = i + 1
  1545. 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>'
  1546. else:
  1547. j = i + 1
  1548. 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>'
  1549. i = i + 1
  1550. 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)
  1551. @app.route('/topic/<path:name>/sub/<path:sub>/b/<number>')
  1552. def blind(name = None, sub = None, number = None):
  1553. if(session.get('Now') == True):
  1554. ip = getip(request)
  1555. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1556. rows = curs.fetchall()
  1557. if(rows):
  1558. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1559. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'")
  1560. row = curs.fetchall()
  1561. if(row):
  1562. if(row[0]['block'] == 'O'):
  1563. curs.execute("update topic set block = '' where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'")
  1564. else:
  1565. curs.execute("update topic set block = 'O' where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'")
  1566. conn.commit()
  1567. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  1568. else:
  1569. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  1570. else:
  1571. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1572. else:
  1573. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  1574. else:
  1575. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  1576. @app.route('/topic/<path:name>/sub/<path:sub>/stop')
  1577. def topicstop(name = None, sub = None):
  1578. if(session.get('Now') == True):
  1579. ip = getip(request)
  1580. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1581. rows = curs.fetchall()
  1582. if(rows):
  1583. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1584. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
  1585. row = curs.fetchall()
  1586. if(row):
  1587. today = getnow()
  1588. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = ''")
  1589. rows = curs.fetchall()
  1590. if(rows):
  1591. 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', '')")
  1592. curs.execute("delete from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = ''")
  1593. else:
  1594. 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', '')")
  1595. curs.execute("insert into stop (title, sub, close) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', '')")
  1596. conn.commit()
  1597. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  1598. else:
  1599. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  1600. else:
  1601. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1602. else:
  1603. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  1604. else:
  1605. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  1606. @app.route('/topic/<path:name>/sub/<path:sub>/close')
  1607. def topicclose(name = None, sub = None):
  1608. if(session.get('Now') == True):
  1609. ip = getip(request)
  1610. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1611. rows = curs.fetchall()
  1612. if(rows):
  1613. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1614. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
  1615. row = curs.fetchall()
  1616. if(row):
  1617. today = getnow()
  1618. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'")
  1619. rows = curs.fetchall()
  1620. if(rows):
  1621. 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', '')")
  1622. curs.execute("delete from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'")
  1623. else:
  1624. 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', '')")
  1625. curs.execute("insert into stop (title, sub, close) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', 'O')")
  1626. conn.commit()
  1627. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  1628. else:
  1629. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  1630. else:
  1631. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1632. else:
  1633. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  1634. else:
  1635. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  1636. @app.route('/login', methods=['POST', 'GET'])
  1637. def login():
  1638. if(request.method == 'POST'):
  1639. ip = getip(request)
  1640. ban = getban(ip)
  1641. if(ban == 1):
  1642. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1643. else:
  1644. curs.execute("select * from user where id = '" + pymysql.escape_string(request.form["id"]) + "'")
  1645. rows = curs.fetchall()
  1646. if(rows):
  1647. if(session.get('Now') == True):
  1648. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '이미 로그인 되어 있습니다.')
  1649. elif(bcrypt.checkpw(bytes(request.form["pw"], 'utf-8'), bytes(rows[0]['pw'], 'utf-8'))):
  1650. session['Now'] = True
  1651. session['DREAMER'] = request.form["id"]
  1652. curs.execute("insert into login (user, ip, today) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(ip) + "', '" + pymysql.escape_string(getnow()) + "')")
  1653. conn.commit()
  1654. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1655. else:
  1656. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '비밀번호가 다릅니다.')
  1657. else:
  1658. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '없는 계정 입니다.')
  1659. else:
  1660. ip = getip(request)
  1661. ban = getban(ip)
  1662. if(ban == 1):
  1663. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1664. else:
  1665. if(session.get('Now') == True):
  1666. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '이미 로그인 되어 있습니다.')
  1667. else:
  1668. return render_template('index.html', title = '로그인', enter = '로그인', logo = data['name'], tn = 15)
  1669. @app.route('/check/<path:name>')
  1670. def check(name = None, sub = None, number = None):
  1671. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  1672. rows = curs.fetchall()
  1673. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1674. return render_template('index.html', title = '차단 오류', logo = data['name'], data = '관리자는 검사 할 수 없습니다.')
  1675. else:
  1676. if(admincheck() == 1):
  1677. 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)
  1678. if(m):
  1679. curs.execute("select * from login where ip = '" + pymysql.escape_string(name) + "' order by today desc")
  1680. row = curs.fetchall()
  1681. if(row):
  1682. i = 0
  1683. c = ''
  1684. while True:
  1685. try:
  1686. 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>'
  1687. except:
  1688. break
  1689. i = i + 1
  1690. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = c)
  1691. else:
  1692. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = '')
  1693. else:
  1694. curs.execute("select * from login where user = '" + pymysql.escape_string(name) + "' order by today desc")
  1695. row = curs.fetchall()
  1696. if(row):
  1697. i = 0
  1698. c = ''
  1699. while True:
  1700. try:
  1701. 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>'
  1702. except:
  1703. break
  1704. i = i + 1
  1705. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = c)
  1706. else:
  1707. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = '')
  1708. else:
  1709. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1710. @app.route('/register', methods=['POST', 'GET'])
  1711. def register():
  1712. if(request.method == 'POST'):
  1713. ip = getip(request)
  1714. ban = getban(ip)
  1715. if(ban == 1):
  1716. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1717. else:
  1718. m = re.search('(?:[^A-Za-zㄱ-힣0-9 ])', request.form["id"])
  1719. if(m):
  1720. return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '아이디에는 한글과 알파벳 공백만 허용 됩니다.')
  1721. else:
  1722. if(len(request.form["id"]) > 20):
  1723. return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '아이디는 20글자보다 짧아야 합니다.')
  1724. else:
  1725. curs.execute("select * from user where id = '" + pymysql.escape_string(request.form["id"]) + "'")
  1726. rows = curs.fetchall()
  1727. if(rows):
  1728. return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '동일한 아이디의 유저가 있습니다.')
  1729. else:
  1730. hashed = bcrypt.hashpw(bytes(request.form["pw"], 'utf-8'), bcrypt.gensalt())
  1731. if(request.form["id"] == data['owner']):
  1732. curs.execute("insert into user (id, pw, acl) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(hashed.decode()) + "', 'owner')")
  1733. else:
  1734. curs.execute("insert into user (id, pw, acl) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(hashed.decode()) + "', 'user')")
  1735. conn.commit()
  1736. return '<meta http-equiv="refresh" content="0;url=/login" />'
  1737. else:
  1738. ip = getip(request)
  1739. ban = getban(ip)
  1740. if(ban == 1):
  1741. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1742. else:
  1743. return render_template('index.html', title = '회원가입', enter = '회원가입', logo = data['name'], tn = 15)
  1744. @app.route('/logout')
  1745. def logout():
  1746. session['Now'] = False
  1747. session.pop('DREAMER', None)
  1748. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1749. @app.route('/ban/<path:name>', methods=['POST', 'GET'])
  1750. def ban(name = None):
  1751. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  1752. rows = curs.fetchall()
  1753. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1754. return render_template('index.html', title = '차단 오류', logo = data['name'], data = '관리자는 차단 할 수 없습니다.')
  1755. else:
  1756. if(request.method == 'POST'):
  1757. if(admincheck() == 1):
  1758. curs.execute("select * from ban where block = '" + pymysql.escape_string(name) + "'")
  1759. row = curs.fetchall()
  1760. if(row):
  1761. block(name, '해제', getnow(), ip, '')
  1762. curs.execute("delete from ban where block = '" + pymysql.escape_string(name) + "'")
  1763. else:
  1764. b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)$", name)
  1765. if(b):
  1766. block(name, request.form["end"], getnow(), ip, request.form["why"])
  1767. 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')")
  1768. else:
  1769. block(name, request.form["end"], getnow(), ip, request.form["why"])
  1770. 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"]) + "', '')")
  1771. conn.commit()
  1772. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1773. else:
  1774. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1775. else:
  1776. if(admincheck() == 1):
  1777. curs.execute("select * from ban where block = '" + pymysql.escape_string(name) + "'")
  1778. row = curs.fetchall()
  1779. if(row):
  1780. now = '차단 해제'
  1781. else:
  1782. b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)$", name)
  1783. if(b):
  1784. now = '대역 차단'
  1785. else:
  1786. now = '차단'
  1787. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 16, now = now, today = getnow())
  1788. else:
  1789. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1790. @app.route('/acl/<path:name>', methods=['POST', 'GET'])
  1791. def acl(name = None):
  1792. if(request.method == 'POST'):
  1793. if(admincheck() == 1):
  1794. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1795. row = curs.fetchall()
  1796. if(row):
  1797. if(request.form["select"] == 'admin'):
  1798. curs.execute("update data set acl = 'admin' where title = '" + pymysql.escape_string(name) + "'")
  1799. elif(request.form["select"] == 'user'):
  1800. curs.execute("update data set acl = 'user' where title = '" + pymysql.escape_string(name) + "'")
  1801. else:
  1802. curs.execute("update data set acl = '' where title = '" + pymysql.escape_string(name) + "'")
  1803. conn.commit()
  1804. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1805. else:
  1806. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1807. else:
  1808. if(admincheck() == 1):
  1809. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1810. row = curs.fetchall()
  1811. if(row):
  1812. if(row[0]['acl'] == 'admin'):
  1813. now = '관리자만'
  1814. elif(row[0]['acl'] == 'user'):
  1815. now = '유저 이상'
  1816. else:
  1817. now = '일반'
  1818. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 19, now = '현재 ACL 상태는 ' + now)
  1819. else:
  1820. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1821. else:
  1822. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1823. @app.route('/admin/<path:name>', methods=['POST', 'GET'])
  1824. def admin(name = None):
  1825. if(request.method == 'POST'):
  1826. if(session.get('Now') == True):
  1827. ip = getip(request)
  1828. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1829. rows = curs.fetchall()
  1830. if(rows):
  1831. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  1832. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  1833. row = curs.fetchall()
  1834. if(row):
  1835. if(row[0]['acl'] == 'admin' or row[0]['acl'] == 'owner'):
  1836. curs.execute("update user set acl = 'user' where id = '" + pymysql.escape_string(name) + "'")
  1837. else:
  1838. curs.execute("update user set acl = '" + pymysql.escape_string(request.form["select"]) + "' where id = '" + pymysql.escape_string(name) + "'")
  1839. conn.commit()
  1840. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1841. else:
  1842. return render_template('index.html', title = '사용자 오류', logo = data['name'], data = '계정이 없습니다.')
  1843. else:
  1844. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1845. else:
  1846. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  1847. else:
  1848. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  1849. else:
  1850. if(session.get('Now') == True):
  1851. ip = getip(request)
  1852. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1853. rows = curs.fetchall()
  1854. if(rows):
  1855. if(rows[0]['acl'] == 'owner'):
  1856. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  1857. row = curs.fetchall()
  1858. if(row):
  1859. if(row[0]['acl'] == 'admin' or row[0]['acl'] == 'owner'):
  1860. now = '권한 해제'
  1861. else:
  1862. now = '권한 부여'
  1863. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 18, now = now)
  1864. else:
  1865. return render_template('index.html', title = '사용자 오류', logo = data['name'], data = '계정이 없습니다.')
  1866. else:
  1867. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  1868. else:
  1869. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  1870. else:
  1871. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  1872. @app.route('/grammar')
  1873. def grammar():
  1874. return render_template('index.html', title = '문법 설명', logo = data['name'], tn = 17)
  1875. @app.route('/ban')
  1876. def aban():
  1877. ip = getip(request)
  1878. if(getban(ip) == 1):
  1879. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  1880. rows = curs.fetchall()
  1881. if(rows):
  1882. if(rows[0]['end']):
  1883. end = rows[0]['end'] + ' 까지 차단 상태 입니다. / 사유 : ' + rows[0]['why']
  1884. now = getnow()
  1885. now = re.sub(':', '', now)
  1886. now = re.sub('\-', '', now)
  1887. now = re.sub(' ', '', now)
  1888. now = int(now)
  1889. day = rows[0]['end']
  1890. day = re.sub('\-', '', day)
  1891. if(now >= int(day + '000000')):
  1892. curs.execute("delete from ban where block = '" + pymysql.escape_string(ip) + "'")
  1893. conn.commit()
  1894. end = '차단이 풀렸습니다. 다시 시도 해 보세요.'
  1895. else:
  1896. end = '영구 차단 상태 입니다. / 사유 : ' + rows[0]['why']
  1897. else:
  1898. b = re.search("^([0-9](?:[0-9][0-9])?\.[0-9](?:[0-9][0-9])?)", ip)
  1899. if(b):
  1900. results = b.groups()
  1901. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  1902. row = curs.fetchall()
  1903. if(row):
  1904. if(row[0]['end']):
  1905. end = row[0]['end'] + ' 까지 차단 상태 입니다. / 사유 : ' + rows[0]['why']
  1906. now = getnow()
  1907. now = re.sub(':', '', now)
  1908. now = re.sub('\-', '', now)
  1909. now = re.sub(' ', '', now)
  1910. now = int(now)
  1911. day = row[0]['end']
  1912. day = re.sub('\-', '', day)
  1913. if(now >= int(day + '000000')):
  1914. curs.execute("delete from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  1915. conn.commit()
  1916. end = '차단이 풀렸습니다. 다시 시도 해 보세요.'
  1917. else:
  1918. end = '영구 차단 상태 입니다. / 사유 : ' + row[0]['why']
  1919. else:
  1920. end = '권한이 맞지 않는 상태 입니다.'
  1921. return render_template('index.html', title = '권한 오류', logo = data['name'], data = end)
  1922. @app.route('/w/<path:name>/r/<a>/diff/<b>')
  1923. def diff(name = None, a = None, b = None):
  1924. curs.execute("select * from history where id = '" + pymysql.escape_string(a) + "' and title = '" + pymysql.escape_string(name) + "'")
  1925. rows = curs.fetchall()
  1926. if(rows):
  1927. curs.execute("select * from history where id = '" + pymysql.escape_string(b) + "' and title = '" + pymysql.escape_string(name) + "'")
  1928. row = curs.fetchall()
  1929. if(row):
  1930. indata = re.sub('<', '&lt;', rows[0]['data'])
  1931. indata = re.sub('>', '&gt;', indata)
  1932. indata = re.sub('"', '&quot;', indata)
  1933. indata = re.sub('\n', '<br>', indata)
  1934. enddata = re.sub('<', '&lt;', row[0]['data'])
  1935. enddata = re.sub('>', '&gt;', enddata)
  1936. enddata = re.sub('"', '&quot;', enddata)
  1937. enddata = re.sub('\n', '<br>', enddata)
  1938. sm = difflib.SequenceMatcher(None, indata, enddata)
  1939. c = show_diff(sm)
  1940. return render_template('index.html', title = 'Diff', logo = data['name'], data = c)
  1941. else:
  1942. return render_template('index.html', title = 'Diff 오류', logo = data['name'], data = '<a href="/w/' + name + '">이 리비전이나 문서가 없습니다.</a>')
  1943. else:
  1944. return render_template('index.html', title = 'Diff 오류', logo = data['name'], data = '<a href="/w/' + name + '">이 리비전이나 문서가 없습니다.</a>')
  1945. @app.route('/version')
  1946. def version():
  1947. return render_template('index.html', title = '버전', logo = data['name'], tn = 14)
  1948. @app.route('/user')
  1949. def user():
  1950. ip = getip(request)
  1951. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  1952. rows = curs.fetchall()
  1953. if(getban(ip) == 0):
  1954. if(rows):
  1955. if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'):
  1956. acl = '관리자'
  1957. else:
  1958. acl = '유저'
  1959. else:
  1960. acl = '일반'
  1961. else:
  1962. acl = '차단'
  1963. 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>')
  1964. @app.route('/random')
  1965. def random():
  1966. curs.execute("select * from data order by rand() limit 1")
  1967. rows = curs.fetchall()
  1968. if(rows):
  1969. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(rows[0]['title']).replace('/','%2F') + '" />'
  1970. else:
  1971. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1972. @app.errorhandler(404)
  1973. def uncaughtError(error):
  1974. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1975. if __name__ == '__main__':
  1976. app.run(host = '0.0.0.0', port = int(data['port']))