app.py 115 KB

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