2
0

app.py 151 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762
  1. from flask import Flask, request, session, render_template, send_file
  2. app = Flask(__name__)
  3. from urllib import parse
  4. import json
  5. import pymysql
  6. import time
  7. import re
  8. import bcrypt
  9. import os
  10. import difflib
  11. json_data = open('set.json').read()
  12. data = json.loads(json_data)
  13. print('오픈나무 시작 포트 : ' + data['port'])
  14. import logging
  15. log = logging.getLogger('werkzeug')
  16. log.setLevel(logging.ERROR)
  17. app.config['MAX_CONTENT_LENGTH'] = int(data['upload']) * 1024 * 1024
  18. conn = pymysql.connect(host = data['host'], user = data['user'], password = data['pw'], db = data['db'], charset = 'utf8mb4')
  19. curs = conn.cursor(pymysql.cursors.DictCursor)
  20. app.secret_key = data['key']
  21. ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
  22. def show_diff(seqm):
  23. output= []
  24. for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
  25. if opcode == 'equal':
  26. output.append(seqm.a[a0:a1])
  27. elif opcode == 'insert':
  28. output.append("<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>")
  29. elif opcode == 'delete':
  30. output.append("<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>")
  31. return ''.join(output)
  32. def allowed_file(filename):
  33. return '.' in filename and \
  34. filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
  35. def admincheck():
  36. if(session.get('Now') == True):
  37. ip = getip(request)
  38. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  39. rows = curs.fetchall()
  40. if(rows):
  41. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  42. return 1
  43. def namumark(title, data):
  44. data = re.sub('<', '&lt;', data)
  45. data = re.sub('>', '&gt;', data)
  46. data = re.sub('"', '&quot;', data)
  47. while True:
  48. p = re.compile("{{{((?:(?!{{{)(?!}}}).)*)}}}", re.DOTALL)
  49. m = p.search(data)
  50. if(m):
  51. results = m.groups()
  52. q = re.compile("^\+([1-5])\s(.*)$", re.DOTALL)
  53. n = q.search(results[0])
  54. w = re.compile("^\-([1-5])\s(.*)$", re.DOTALL)
  55. a = w.search(results[0])
  56. e = re.compile("^(#[0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  57. b = e.search(results[0])
  58. r = re.compile("^(#[0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  59. c = r.search(results[0])
  60. t = re.compile("^#(\w+)\s(.*)$", re.DOTALL)
  61. d = t.search(results[0])
  62. qqq = re.compile("^@([0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  63. qqe = qqq.search(results[0])
  64. qqw = re.compile("^@([0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  65. qqa = qqw.search(results[0])
  66. qwe = re.compile("^@(\w+)\s(.*)$", re.DOTALL)
  67. qsd = qwe.search(results[0])
  68. qawe = re.compile("^#!noin\s(.*)$", re.DOTALL)
  69. qasd = qawe.search(results[0])
  70. y = re.compile("^#!wiki\sstyle=&quot;((?:(?!&quot;|\n).)*)&quot;\n?\s\n(.*)$", re.DOTALL)
  71. l = y.search(results[0])
  72. if(n):
  73. result = n.groups()
  74. data = p.sub('<span class="font-size-' + result[0] + '">' + result[1] + '</span>', data, 1)
  75. elif(a):
  76. result = a.groups()
  77. data = p.sub('<span class="font-size-small-' + result[0] + '">' + result[1] + '</span>', data, 1)
  78. elif(b):
  79. result = b.groups()
  80. data = p.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', data, 1)
  81. elif(c):
  82. result = c.groups()
  83. data = p.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', data, 1)
  84. elif(d):
  85. result = d.groups()
  86. data = p.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', data, 1)
  87. elif(qqe):
  88. result = qqe.groups()
  89. data = p.sub('<span style="background:#' + result[0] + '">' + result[1] + '</span>', data, 1)
  90. elif(qqa):
  91. result = qqa.groups()
  92. data = p.sub('<span style="background:#' + result[0] + '">' + result[1] + '</span>', data, 1)
  93. elif(qsd):
  94. result = qsd.groups()
  95. data = p.sub('<span style="background:' + result[0] + '">' + result[1] + '</span>', data, 1)
  96. elif(l):
  97. result = l.groups()
  98. data = p.sub('<div style="' + result[0] + '">' + result[1] + '</div>', data, 1)
  99. elif(qasd):
  100. result = qasd.groups()
  101. data = p.sub(result[0], data, 1)
  102. else:
  103. data = p.sub('<code>' + results[0] + '</code>', data, 1)
  104. else:
  105. break
  106. while True:
  107. a = re.compile("<code>(((?!<\/code>).)*)<\/code>", re.DOTALL)
  108. m = a.search(data)
  109. if(m):
  110. g = m.groups()
  111. j = re.sub("<\/span>", "}}}", g[0])
  112. j = re.sub("<\/div>", "}}}", j)
  113. j = re.sub('<span class="font\-size\-(?P<in>[1-6])">', "{{{+\g<in> ", j)
  114. j = re.sub('<span class="font\-size\-small\-(?P<in>[1-6])">', "{{{-\g<in> ", j)
  115. j = re.sub('<span style="color:(?:#)?(?P<in>[^"]*)">', "{{{#\g<in> ", j)
  116. j = re.sub('<span style="background:(?:#)?(?P<in>[^"]*)">', "{{{@\g<in> ", j)
  117. j = re.sub('<div style="(?P<in>[^"]*)">', "{{{#!wiki style=&quot;\g<in>&quot;\n", j)
  118. j = re.sub("(?P<in>.)", "<span>\g<in></span>", j)
  119. data = a.sub(j, data, 1)
  120. else:
  121. break
  122. data = re.sub("<span>&</span><span>l</span><span>t</span><span>;</span>", "<span>&lt;</span>", data)
  123. data = re.sub("<span>&</span><span>g</span><span>t</span><span>;</span>", "<span>&gt;</span>", data)
  124. data = re.sub("\[anchor\((?P<in>[^\[\]]*)\)\]", '<span id="\g<in>"></span>', data)
  125. data = re.sub('\[date\(now\)\]', getnow(), data)
  126. while True:
  127. m = re.search("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", data)
  128. if(m):
  129. results = m.groups()
  130. if(results[0] == title):
  131. data = re.sub("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", "<b>" + results[0] + "</b>", data, 1)
  132. else:
  133. curs.execute("select * from data where title = '" + pymysql.escape_string(results[0]) + "'")
  134. rows = curs.fetchall()
  135. if(rows):
  136. curs.execute("select * from back where title = '" + pymysql.escape_string(results[0]) + "' and link = '" + pymysql.escape_string(title) + "' and type = 'include'")
  137. abb = curs.fetchall()
  138. if(not abb):
  139. curs.execute("insert into back (title, link, type) value ('" + pymysql.escape_string(results[0]) + "', '" + pymysql.escape_string(title) + "', 'include')")
  140. conn.commit()
  141. enddata = rows[0]['data']
  142. enddata = re.sub("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", "", enddata)
  143. enddata = re.sub('<', '&lt;', enddata)
  144. enddata = re.sub('>', '&gt;', enddata)
  145. enddata = re.sub('"', '&quot;', enddata)
  146. while True:
  147. p = re.compile("{{{((?:(?!{)(?!}).)*)}}}", re.DOTALL)
  148. m = p.search(enddata)
  149. if(m):
  150. nnn = m.groups()
  151. q = re.compile("^\+([1-5])\s(.*)$", re.DOTALL)
  152. n = q.search(nnn[0])
  153. w = re.compile("^\-([1-5])\s(.*)$", re.DOTALL)
  154. a = w.search(nnn[0])
  155. e = re.compile("^(#[0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  156. b = e.search(nnn[0])
  157. r = re.compile("^(#[0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  158. c = r.search(nnn[0])
  159. t = re.compile("^#(\w+)\s(.*)$", re.DOTALL)
  160. d = t.search(nnn[0])
  161. qqq = re.compile("^@([0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  162. qqe = qqq.search(nnn[0])
  163. qqw = re.compile("^@([0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  164. qqa = qqw.search(nnn[0])
  165. qwe = re.compile("^@(\w+)\s(.*)$", re.DOTALL)
  166. qsd = qwe.search(nnn[0])
  167. qawe = re.compile("^#!noin\s(.*)$", re.DOTALL)
  168. qasd = qawe.search(nnn[0])
  169. y = re.compile("^#!wiki\sstyle=&quot;((?:(?!&quot;|\n).)*)&quot;\n?\s\n(.*)$", re.DOTALL)
  170. l = y.search(nnn[0])
  171. if(n):
  172. result = n.groups()
  173. enddata = p.sub('<span class="font-size-' + result[0] + '">' + result[1] + '</span>', enddata, 1)
  174. elif(a):
  175. result = a.groups()
  176. enddata = p.sub('<span class="font-size-small-' + result[0] + '">' + result[1] + '</span>', enddata, 1)
  177. elif(b):
  178. result = b.groups()
  179. enddata = p.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', enddata, 1)
  180. elif(c):
  181. result = c.groups()
  182. enddata = p.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', enddata, 1)
  183. elif(d):
  184. result = d.groups()
  185. enddata = p.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', enddata, 1)
  186. elif(qqe):
  187. result = qqe.groups()
  188. enddata = p.sub('<span style="background:#' + result[0] + '">' + result[1] + '</span>', enddata, 1)
  189. elif(qqa):
  190. result = qqa.groups()
  191. enddata = p.sub('<span style="background:#' + result[0] + '">' + result[1] + '</span>', enddata, 1)
  192. elif(qsd):
  193. result = qsd.groups()
  194. enddata = p.sub('<span style="background:' + result[0] + '">' + result[1] + '</span>', enddata, 1)
  195. elif(l):
  196. result = l.groups()
  197. enddata = p.sub('<div style="' + result[0] + '">' + result[1] + '</div>', enddata, 1)
  198. elif(qasd):
  199. enddata = p.sub("", enddata, 1)
  200. else:
  201. enddata = p.sub('<code>' + nnn[0] + '</code>', enddata, 1)
  202. else:
  203. break
  204. while True:
  205. a = re.compile("<code>(((?!<\/code>).)*)<\/code>", re.DOTALL)
  206. m = a.search(enddata)
  207. if(m):
  208. g = m.groups()
  209. j = re.sub("<\/span>", "}}}", g[0])
  210. j = re.sub("<\/div>", "}}}", j)
  211. j = re.sub('<span class="font\-size\-(?P<in>[1-6])">', "{{{+\g<in> ", j)
  212. j = re.sub('<span class="font\-size\-small\-(?P<in>[1-6])">', "{{{-\g<in> ", j)
  213. j = re.sub('<span style="color:(?:#)?(?P<in>[^"]*)">', "{{{#\g<in> ", j)
  214. j = re.sub('<span style="background:(?:#)?(?P<in>[^"]*)">', "{{{@\g<in> ", j)
  215. j = re.sub('<div style="(?P<in>[^"]*)">', "{{{#!wiki style=&quot;\g<in>&quot;\n", j)
  216. j = re.sub("(?P<in>.)", "<span>\g<in></span>", j)
  217. enddata = a.sub(j, enddata, 1)
  218. else:
  219. break
  220. enddata = re.sub("<span>&</span><span>l</span><span>t</span><span>;</span>", "<span>&lt;</span>", enddata)
  221. enddata = re.sub("<span>&</span><span>g</span><span>t</span><span>;</span>", "<span>&gt;</span>", enddata)
  222. if(results[1]):
  223. a = results[1]
  224. while True:
  225. g = re.search("([^= ,]*)\=([^,]*)", a)
  226. if(g):
  227. result = g.groups()
  228. enddata = re.sub("@" + result[0] + "@", result[1], enddata)
  229. a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
  230. else:
  231. break
  232. data = re.sub("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", '\n' + enddata + '\n', data, 1)
  233. else:
  234. data = re.sub("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", "[[" + results[0] + "]]", data, 1)
  235. else:
  236. break
  237. while True:
  238. m = re.search('^#(?:redirect|넘겨주기)\s([^\n]*)', data)
  239. if(m):
  240. results = m.groups()
  241. aa = re.search("^(.*)(#(?:.*))$", results[0])
  242. if(aa):
  243. results = aa.groups()
  244. 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') + results[1] + '" />', data, 1)
  245. else:
  246. 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)
  247. curs.execute("select * from back where title = '" + pymysql.escape_string(results[0]) + "' and link = '" + pymysql.escape_string(title) + "' and type = 'redirect'")
  248. abb = curs.fetchall()
  249. if(not abb):
  250. curs.execute("insert into back (title, link, type) value ('" + pymysql.escape_string(results[0]) + "', '" + pymysql.escape_string(title) + "', 'redirect')")
  251. conn.commit()
  252. else:
  253. break
  254. data = '\n' + data + '\n'
  255. while True:
  256. m = re.search("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", data)
  257. if(m):
  258. result = m.groups()
  259. blockquote = result[0]
  260. blockquote = re.sub("\n&gt;\s?", "\n", blockquote)
  261. data = re.sub("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", "\n<blockquote>" + blockquote + "</blockquote>", data, 1)
  262. else:
  263. break
  264. h0c = 0;
  265. h1c = 0;
  266. h2c = 0;
  267. h3c = 0;
  268. h4c = 0;
  269. h5c = 0;
  270. last = 0;
  271. rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
  272. while True:
  273. m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', data)
  274. if(m):
  275. result = m.groups()
  276. wiki = len(result[0])
  277. if(last < wiki):
  278. last = wiki
  279. else:
  280. last = wiki;
  281. if(wiki == 1):
  282. h1c = 0
  283. h2c = 0
  284. h3c = 0
  285. h4c = 0
  286. h5c = 0
  287. elif(wiki == 2):
  288. h2c = 0
  289. h3c = 0
  290. h4c = 0
  291. h5c = 0
  292. elif(wiki == 3):
  293. h3c = 0
  294. h4c = 0
  295. h5c = 0
  296. elif(wiki == 4):
  297. h4c = 0
  298. h5c = 0
  299. elif(wiki == 5):
  300. h5c = 0
  301. if(wiki == 1):
  302. h0c = h0c + 1
  303. elif(wiki == 2):
  304. h1c = h1c + 1
  305. elif(wiki == 3):
  306. h2c = h2c + 1
  307. elif(wiki == 4):
  308. h3c = h3c + 1
  309. elif(wiki == 5):
  310. h4c = h4c + 1
  311. else:
  312. h5c = h5c + 1
  313. toc = str(h0c) + '.' + str(h1c) + '.' + str(h2c) + '.' + str(h3c) + '.' + str(h4c) + '.' + str(h5c) + '.'
  314. toc = re.sub("(?P<in>[0-9]0(?:[0]*)?)\.", '\g<in>#.', toc)
  315. toc = re.sub("0\.", '', toc)
  316. toc = re.sub("#\.", '.', toc)
  317. toc = re.sub("\.$", '', toc)
  318. rtoc = rtoc + '<a href="#s-' + toc + '">' + toc + '</a>. ' + result[1] + '<br>'
  319. c = re.sub(" $", "", result[1])
  320. data = re.sub('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', '<h' + str(wiki) + ' id="' + c + '"><a href="#toc" id="s-' + toc + '">' + toc + '.</a> ' + c + '</h' + str(wiki) + '>', data, 1);
  321. else:
  322. rtoc = rtoc + '</div>'
  323. break
  324. data = re.sub("\[목차\]", rtoc, data)
  325. category = ''
  326. while True:
  327. m = re.search("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", data)
  328. if(m):
  329. g = m.groups()
  330. if(not title == g[0]):
  331. curs.execute("select * from cat where title = '" + pymysql.escape_string(g[0]) + "' and cat = '" + pymysql.escape_string(title) + "'")
  332. abb = curs.fetchall()
  333. if(not abb):
  334. curs.execute("insert into cat (title, cat) value ('" + pymysql.escape_string(g[0]) + "', '" + pymysql.escape_string(title) + "')")
  335. conn.commit()
  336. if(category == ''):
  337. category = category + '<a href="/w/' + parse.quote(g[0]).replace('/','%2F') + '">' + re.sub("분류:", "", g[0]) + '</a>'
  338. else:
  339. category = category + ' / ' + '<a href="/w/' + parse.quote(g[0]).replace('/','%2F') + '">' + re.sub("분류:", "", g[0]) + '</a>'
  340. data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", '', data, 1)
  341. else:
  342. break
  343. data = re.sub("'''(?P<in>.+?)'''(?!')", '<b>\g<in></b>', data)
  344. data = re.sub("''(?P<in>.+?)''(?!')", '<i>\g<in></i>', data)
  345. data = re.sub('~~(?P<in>.+?)~~(?!~)', '<s>\g<in></s>', data)
  346. data = re.sub('--(?P<in>.+?)--(?!-)', '<s>\g<in></s>', data)
  347. data = re.sub('__(?P<in>.+?)__(?!_)', '<u>\g<in></u>', data)
  348. data = re.sub('\^\^(?P<in>.+?)\^\^(?!\^)', '<sup>\g<in></sup>', data)
  349. data = re.sub(',,(?P<in>.+?),,(?!,)', '<sub>\g<in></sub>', data)
  350. data = re.sub('&lt;math&gt;(?P<in>((?!&lt;math&gt;).)*)&lt;\/math&gt;', '$\g<in>$', data)
  351. data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table><tbody><tr><td>\g<in></td></tr></tbody></table>', data)
  352. data = re.sub('\[ruby\((?P<in>[^\|]*)\|(?P<out>[^\)]*)\)\]', '<ruby>\g<in><rp>(</rp><rt>\g<out></rt><rp>)</rp></ruby>', data)
  353. data = re.sub("##\s?(?P<in>[^\n]*)\n", "<div style='display:none;'>\g<in></div>", data);
  354. while True:
  355. m = re.search("\[\[파일:((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", data)
  356. if(m):
  357. c = m.groups()
  358. if(c[1]):
  359. n = re.search("width=([^ \n&]*)", c[1])
  360. e = re.search("height=([^ \n&]*)", c[1])
  361. if(n):
  362. a = n.groups()
  363. width = a[0]
  364. else:
  365. width = ''
  366. if(e):
  367. b = e.groups()
  368. height = b[0]
  369. else:
  370. height = ''
  371. img = re.sub("\.(?P<in>jpg|png|gif|jpeg)", "#\g<in>#", c[0])
  372. data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", '<a href="/w/파일:' + img + '"><img src="/image/' + img + '" width="' + width + '" height="' + height + '"></a>', data, 1)
  373. else:
  374. img = re.sub("\.(?P<in>jpg|png|gif|jpeg)", "#\g<in>#", c[0])
  375. data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", "<a href='/w/파일:" + img + "'><img src='/image/" + img + "'></a>", data, 1)
  376. if(not re.search("^파일:([^\n]*)", title)):
  377. curs.execute("select * from back where title = '" + pymysql.escape_string(c[0]) + "' and link = '" + pymysql.escape_string(title) + "' and type = 'redirect'")
  378. abb = curs.fetchall()
  379. if(not abb):
  380. curs.execute("insert into back (title, link, type) value ('파일:" + pymysql.escape_string(c[0]) + "', '" + pymysql.escape_string(title) + "', 'file')")
  381. conn.commit()
  382. else:
  383. break
  384. data = re.sub("\[br\]",'<br>', data);
  385. while True:
  386. m = re.search("\[youtube\(((?:(?!,|\)\]).)*)(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?(?:,\s)?(?:height=((?:(?!,|\)\]).)*))?(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?\)\]", data)
  387. if(m):
  388. result = m.groups()
  389. if(result[1]):
  390. if(result[2]):
  391. width = result[1]
  392. height = result[2]
  393. else:
  394. width = result[1]
  395. height = '315'
  396. elif(result[2]):
  397. if(result[3]):
  398. height = result[2]
  399. width = result[3]
  400. else:
  401. height = result[2]
  402. width = '560'
  403. else:
  404. width = '560'
  405. height = '315'
  406. 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)
  407. else:
  408. break
  409. data = re.sub("\[\[(?::(?P<in>(?:분류|파일):(?:(?:(?!\]\]).)*)))\]\]", "[[\g<in>]]", data)
  410. while True:
  411. m = re.search("\[\[(((?!\]\]).)*)\]\]", data)
  412. if(m):
  413. result = m.groups()
  414. a = re.search("((?:(?!\|).)*)\|(.*)", result[0])
  415. if(a):
  416. results = a.groups()
  417. aa = re.search("^(.*)(#(?:.*))$", results[0])
  418. if(aa):
  419. g = results[1]
  420. results = aa.groups()
  421. b = re.search("^http(?:s)?:\/\/", results[0])
  422. if(b):
  423. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + results[0] + results[1] + '">' + g + '</a>', data, 1)
  424. else:
  425. if(results[0] == title):
  426. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + g + '</b>', data, 1)
  427. else:
  428. curs.execute("select * from data where title = '" + pymysql.escape_string(results[0]) + "'")
  429. rows = curs.fetchall()
  430. if(rows):
  431. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + results[0] + results[1] + '" href="/w/' + parse.quote(results[0]).replace('/','%2F') + results[1] + '">' + g + '</a>', data, 1)
  432. else:
  433. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + results[0] + results[1] + '" class="not_thing" href="/w/' + parse.quote(results[0]).replace('/','%2F') + results[1] + '">' + g + '</a>', data, 1)
  434. curs.execute("select * from back where title = '" + pymysql.escape_string(results[0]) + "' and link = '" + pymysql.escape_string(title) + "'")
  435. rows = curs.fetchall()
  436. if(not rows):
  437. curs.execute("insert into back (title, link, type) value ('" + pymysql.escape_string(results[0]) + "', '" + pymysql.escape_string(title) + "', '')")
  438. conn.commit()
  439. else:
  440. b = re.search("^http(?:s)?:\/\/", results[0])
  441. if(b):
  442. c = re.search("(?:\.jpg|\.png|\.gif|\.jpeg)", results[0])
  443. if(c):
  444. img = results[0]
  445. img = re.sub("\.(?P<in>jpg|png|gif|jpeg)", "#\g<in>#", img)
  446. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + img + '">' + results[1] + '</a>', data, 1)
  447. else:
  448. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + results[0] + '">' + results[1] + '</a>', data, 1)
  449. else:
  450. if(results[0] == title):
  451. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + results[1] + '</b>', data, 1)
  452. else:
  453. curs.execute("select * from data where title = '" + pymysql.escape_string(results[0]) + "'")
  454. rows = curs.fetchall()
  455. if(rows):
  456. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + results[0] + '" href="/w/' + parse.quote(results[0]).replace('/','%2F') + '">' + results[1] + '</a>', data, 1)
  457. else:
  458. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + results[0] + '" class="not_thing" href="/w/' + parse.quote(results[0]).replace('/','%2F') + '">' + results[1] + '</a>', data, 1)
  459. curs.execute("select * from back where title = '" + pymysql.escape_string(results[0]) + "' and link = '" + pymysql.escape_string(title) + "'")
  460. rows = curs.fetchall()
  461. if(not rows):
  462. curs.execute("insert into back (title, link, type) value ('" + pymysql.escape_string(results[0]) + "', '" + pymysql.escape_string(title) + "', '')")
  463. conn.commit()
  464. else:
  465. aa = re.search("^(.*)(#(?:.*))$", result[0])
  466. if(aa):
  467. result = aa.groups()
  468. b = re.search("^http(?:s)?:\/\/", result[0])
  469. if(b):
  470. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + result[0] + result[1] + '">' + result[0] + result[1] + '</a>', data, 1)
  471. else:
  472. if(result[0] == title):
  473. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + result[0] + result[1] + '</b>', data, 1)
  474. else:
  475. curs.execute("select * from data where title = '" + pymysql.escape_string(result[0]) + "'")
  476. rows = curs.fetchall()
  477. if(rows):
  478. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a href="/w/' + parse.quote(result[0]).replace('/','%2F') + result[1] + '">' + result[0] + result[1] + '</a>', data, 1)
  479. else:
  480. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="not_thing" href="/w/' + parse.quote(result[0]).replace('/','%2F') + result[1] + '">' + result[0] + result[1] + '</a>', data, 1)
  481. curs.execute("select * from back where title = '" + pymysql.escape_string(result[0]) + "' and link = '" + pymysql.escape_string(title) + "'")
  482. rows = curs.fetchall()
  483. if(not rows):
  484. curs.execute("insert into back (title, link, type) value ('" + pymysql.escape_string(result[0]) + "', '" + pymysql.escape_string(title) + "', '')")
  485. conn.commit()
  486. else:
  487. b = re.search("^http(?:s)?:\/\/", result[0])
  488. if(b):
  489. c = re.search("(?:\.jpg|\.png|\.gif|\.jpeg)", result[0])
  490. if(c):
  491. img = result[0]
  492. img = re.sub("\.(?P<in>jpg|png|gif|jpeg)", "#\g<in>#", img)
  493. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + img + '">' + img + '</a>', data, 1)
  494. else:
  495. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + result[0] + '">' + result[0] + '</a>', data, 1)
  496. else:
  497. if(result[0] == title):
  498. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + result[0] + '</b>', data, 1)
  499. else:
  500. curs.execute("select * from data where title = '" + pymysql.escape_string(result[0]) + "'")
  501. rows = curs.fetchall()
  502. if(rows):
  503. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a href="/w/' + parse.quote(result[0]).replace('/','%2F') + '">' + result[0] + '</a>', data, 1)
  504. else:
  505. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="not_thing" href="/w/' + parse.quote(result[0]).replace('/','%2F') + '">' + result[0] + '</a>', data, 1)
  506. curs.execute("select * from back where title = '" + pymysql.escape_string(result[0]) + "' and link = '" + pymysql.escape_string(title) + "'")
  507. rows = curs.fetchall()
  508. if(not rows):
  509. curs.execute("insert into back (title, link, type) value ('" + pymysql.escape_string(result[0]) + "', '" + pymysql.escape_string(title) + "', '')")
  510. conn.commit()
  511. else:
  512. break
  513. while True:
  514. 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)
  515. if(m):
  516. result = m.groups()
  517. if(result[1]):
  518. if(result[2]):
  519. width = result[1]
  520. height = result[2]
  521. else:
  522. width = result[1]
  523. height = ''
  524. elif(result[2]):
  525. if(result[3]):
  526. height = result[2]
  527. width = result[3]
  528. else:
  529. height = result[2]
  530. width = ''
  531. else:
  532. width = ''
  533. height = ''
  534. c = result[0]
  535. c = re.sub("\.(?P<in>jpg|png|gif|jpeg)", "#\g<in>#", c)
  536. 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)
  537. else:
  538. break
  539. while True:
  540. m = re.search("((?:(?:\s\*\s[^\n]*)\n?)+)", data)
  541. if(m):
  542. result = m.groups()
  543. end = str(result[0])
  544. end = re.sub("\s\*\s(?P<in>[^\n]*)", "<li>\g<in></li>", end)
  545. end = re.sub("\n", '', end)
  546. data = re.sub("((?:(?:\s\*\s[^\n]*)\n?)+)", '<ul id="list">' + end + '</ul>', data, 1)
  547. else:
  548. break
  549. data = re.sub('\[date\]', getnow(), data)
  550. data = re.sub("#(?P<in>jpg|png|gif|jpeg)#", ".\g<in>", data)
  551. data = re.sub("-{4,11}", "<hr>", data)
  552. while True:
  553. b = re.search("\r\n( +)", data)
  554. if(b):
  555. result = b.groups()
  556. tp = len(result[0])
  557. up = ''
  558. i = 0
  559. while True:
  560. up = up + '<span id="in"></span>'
  561. i = i + 1
  562. if(i == tp):
  563. break
  564. data = re.sub("\r\n( +)", '<br>' + up, data, 1)
  565. else:
  566. break
  567. a = 1
  568. tou = "<hr id='footnote'><div class='wiki-macro-footnote'><br>"
  569. while True:
  570. b = re.search("\[\*([^\s]*)\s(((?!\]).)*)\]", data)
  571. if(b):
  572. results = b.groups()
  573. if(results[0]):
  574. c = results[1]
  575. c = re.sub("<(?:[^>]*)>", '', c)
  576. tou = tou + "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + results[0] + "]</a> " + results[1] + "</span><br>"
  577. 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)
  578. else:
  579. c = results[1]
  580. c = re.sub("<(?:[^>]*)>", '', c)
  581. tou = tou + "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + str(a) + "]</a> " + results[1] + "</span><br>"
  582. 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)
  583. a = a + 1
  584. else:
  585. tou = tou + '</div>'
  586. if(tou == "<hr id='footnote'><div class='wiki-macro-footnote'><br></div>"):
  587. tou = ""
  588. break
  589. data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
  590. data = re.sub("\[각주\]", "<br>" + tou, data)
  591. data = data + tou
  592. if(category):
  593. data = data + '<div style="width:100%;border: 1px solid #777;padding: 5px;margin-top: 1em;">분류: ' + category + '</div>'
  594. while True:
  595. m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
  596. if(m):
  597. results = m.groups()
  598. table = results[0]
  599. while True:
  600. a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  601. if(a):
  602. row = ''
  603. cel = ''
  604. celstyle = ''
  605. rowstyle = ''
  606. alltable = ''
  607. result = a.groups()
  608. if(result[1]):
  609. q = re.search("&lt;table\s?width=((?:(?!&gt;).)*)&gt;", result[1])
  610. w = re.search("&lt;table\s?height=((?:(?!&gt;).)*)&gt;", result[1])
  611. e = re.search("&lt;table\s?align=((?:(?!&gt;).)*)&gt;", result[1])
  612. alltable = 'style="'
  613. celstyle = 'style="'
  614. rowstyle = 'style="'
  615. if(q):
  616. resultss = q.groups()
  617. alltable = alltable + 'width:' + resultss[0] + ';'
  618. if(w):
  619. resultss = w.groups()
  620. alltable = alltable + 'height:' + resultss[0] + ';'
  621. if(e):
  622. resultss = e.groups()
  623. if(resultss[0] == 'right'):
  624. alltable = alltable + 'margin-left:auto;'
  625. elif(resultss[0] == 'center'):
  626. alltable = alltable + 'margin:auto;'
  627. else:
  628. alltable = alltable + 'margin-right:auto;'
  629. ee = re.search("&lt;table\s?textalign=((?:(?!&gt;).)*)&gt;", result[1])
  630. if(ee):
  631. resultss = ee.groups()
  632. if(resultss[0] == 'right'):
  633. alltable = alltable + 'text-align:right;'
  634. elif(resultss[0] == 'center'):
  635. alltable = alltable + 'text-align:center;'
  636. else:
  637. alltable = alltable + 'text-align:left;'
  638. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  639. if(r):
  640. resultss = r.groups()
  641. cel = 'colspan="' + resultss[0] + '"'
  642. else:
  643. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  644. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  645. if(t):
  646. resultss = t.groups()
  647. row = 'rowspan="' + resultss[0] + '"'
  648. ba = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  649. bb = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  650. bc = re.search("&lt;rowbgcolor=(\w+)&gt;", result[1])
  651. if(ba):
  652. resultss = ba.groups()
  653. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  654. elif(bb):
  655. resultss = bb.groups()
  656. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  657. elif(bc):
  658. resultss = bc.groups()
  659. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  660. z = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  661. x = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  662. c = re.search("&lt;table\s?bordercolor=(\w+)&gt;", result[1])
  663. if(z):
  664. resultss = z.groups()
  665. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  666. elif(x):
  667. resultss = x.groups()
  668. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  669. elif(c):
  670. resultss = c.groups()
  671. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  672. aq = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  673. aw = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  674. ae = re.search("&lt;table\s?bgcolor=(\w+)&gt;", result[1])
  675. if(aq):
  676. resultss = aq.groups()
  677. alltable = alltable + 'background:' + resultss[0] + ';'
  678. elif(aw):
  679. resultss = aw.groups()
  680. alltable = alltable + 'background:' + resultss[0] + ';'
  681. elif(ae):
  682. resultss = ae.groups()
  683. alltable = alltable + 'background:' + resultss[0] + ';'
  684. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  685. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  686. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  687. if(j):
  688. resultss = j.groups()
  689. celstyle = celstyle + 'background:' + resultss[0] + ';'
  690. elif(k):
  691. resultss = k.groups()
  692. celstyle = celstyle + 'background:' + resultss[0] + ';'
  693. elif(l):
  694. resultss = l.groups()
  695. celstyle = celstyle + 'background:' + resultss[0] + ';'
  696. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  697. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  698. ac = re.search("&lt;(\w+)&gt;", result[1])
  699. if(aa):
  700. resultss = aa.groups()
  701. celstyle = celstyle + 'background:' + resultss[0] + ';'
  702. elif(ab):
  703. resultss = ab.groups()
  704. celstyle = celstyle + 'background:' + resultss[0] + ';'
  705. elif(ac):
  706. resultss = ac.groups()
  707. celstyle = celstyle + 'background:' + resultss[0] + ';'
  708. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  709. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  710. if(qa):
  711. resultss = qa.groups()
  712. celstyle = celstyle + 'width:' + resultss[0] + ';'
  713. if(qb):
  714. resultss = qb.groups()
  715. celstyle = celstyle + 'height:' + resultss[0] + ';'
  716. i = re.search("&lt;\)&gt;", result[1])
  717. o = re.search("&lt;:&gt;", result[1])
  718. p = re.search("&lt;\(&gt;", result[1])
  719. if(i):
  720. celstyle = celstyle + 'text-align:right;'
  721. elif(o):
  722. celstyle = celstyle + 'text-align:center;'
  723. elif(p):
  724. celstyle = celstyle + 'text-align:left;'
  725. alltable = alltable + '"'
  726. celstyle = celstyle + '"'
  727. rowstyle = rowstyle + '"'
  728. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "><tbody><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  729. else:
  730. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  731. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table><tbody><tr><td " + cel + ">", table, 1)
  732. else:
  733. break
  734. table = re.sub("\|\|$", "</td></tr></tbody></table>", table)
  735. while True:
  736. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  737. if(b):
  738. row = ''
  739. cel = ''
  740. celstyle = ''
  741. rowstyle = ''
  742. result = b.groups()
  743. if(result[1]):
  744. celstyle = 'style="'
  745. rowstyle = 'style="'
  746. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  747. if(r):
  748. resultss = r.groups()
  749. cel = 'colspan="' + resultss[0] + '"'
  750. else:
  751. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  752. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  753. if(t):
  754. resultss = t.groups()
  755. row = 'rowspan="' + resultss[0] + '"'
  756. ba = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  757. bb = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  758. bc = re.search("&lt;rowbgcolor=(\w+)&gt;", result[1])
  759. if(ba):
  760. resultss = ba.groups()
  761. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  762. elif(bb):
  763. resultss = bb.groups()
  764. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  765. elif(bc):
  766. resultss = bc.groups()
  767. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  768. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  769. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  770. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  771. if(j):
  772. resultss = j.groups()
  773. celstyle = celstyle + 'background:' + resultss[0] + ';'
  774. elif(k):
  775. resultss = k.groups()
  776. celstyle = celstyle + 'background:' + resultss[0] + ';'
  777. elif(l):
  778. resultss = l.groups()
  779. celstyle = celstyle + 'background:' + resultss[0] + ';'
  780. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  781. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  782. ac = re.search("&lt;(\w+)&gt;", result[1])
  783. if(aa):
  784. resultss = aa.groups()
  785. celstyle = celstyle + 'background:' + resultss[0] + ';'
  786. elif(ab):
  787. resultss = ab.groups()
  788. celstyle = celstyle + 'background:' + resultss[0] + ';'
  789. elif(ac):
  790. resultss = ac.groups()
  791. celstyle = celstyle + 'background:' + resultss[0] + ';'
  792. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  793. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  794. if(qa):
  795. resultss = qa.groups()
  796. celstyle = celstyle + 'width:' + resultss[0] + ';'
  797. if(qb):
  798. resultss = qb.groups()
  799. celstyle = celstyle + 'height:' + resultss[0] + ';'
  800. i = re.search("&lt;\)&gt;", result[1])
  801. o = re.search("&lt;:&gt;", result[1])
  802. p = re.search("&lt;\(&gt;", result[1])
  803. if(i):
  804. celstyle = celstyle + 'text-align:right;'
  805. elif(o):
  806. celstyle = celstyle + 'text-align:center;'
  807. elif(p):
  808. celstyle = celstyle + 'text-align:left;'
  809. celstyle = celstyle + '"'
  810. rowstyle = rowstyle + '"'
  811. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  812. else:
  813. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  814. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr><td " + cel + ">", table, 1)
  815. else:
  816. break
  817. while True:
  818. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  819. if(c):
  820. row = ''
  821. cel = ''
  822. celstyle = ''
  823. result = c.groups()
  824. if(result[1]):
  825. celstyle = 'style="'
  826. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  827. if(r):
  828. resultss = r.groups()
  829. cel = 'colspan="' + resultss[0] + '"';
  830. else:
  831. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  832. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  833. if(t):
  834. resultss = t.groups()
  835. row = 'rowspan="' + resultss[0] + '"';
  836. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  837. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  838. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  839. if(j):
  840. resultss = j.groups()
  841. celstyle = celstyle + 'background:' + resultss[0] + ';'
  842. elif(k):
  843. resultss = k.groups()
  844. celstyle = celstyle + 'background:' + resultss[0] + ';'
  845. elif(l):
  846. resultss = l.groups()
  847. celstyle = celstyle + 'background:' + resultss[0] + ';'
  848. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  849. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  850. ac = re.search("&lt;(\w+)&gt;", result[1])
  851. if(aa):
  852. resultss = aa.groups()
  853. celstyle = celstyle + 'background:' + resultss[0] + ';'
  854. elif(ab):
  855. resultss = ab.groups()
  856. celstyle = celstyle + 'background:' + resultss[0] + ';'
  857. elif(ac):
  858. resultss = ac.groups()
  859. celstyle = celstyle + 'background:' + resultss[0] + ';'
  860. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  861. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  862. if(qa):
  863. resultss = qa.groups()
  864. celstyle = celstyle + 'width:' + resultss[0] + ';'
  865. if(qb):
  866. resultss = qb.groups()
  867. celstyle = celstyle + 'height:' + resultss[0] + ';'
  868. i = re.search("&lt;\)&gt;", result[1])
  869. o = re.search("&lt;:&gt;", result[1])
  870. p = re.search("&lt;\(&gt;", result[1])
  871. if(i):
  872. celstyle = celstyle + 'text-align:right;'
  873. elif(o):
  874. celstyle = celstyle + 'text-align:center;'
  875. elif(p):
  876. celstyle = celstyle + 'text-align:left;'
  877. celstyle = celstyle + '"'
  878. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  879. else:
  880. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  881. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + ">", table, 1)
  882. else:
  883. break
  884. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  885. else:
  886. break
  887. data = re.sub('\n', '<br>', data)
  888. data = re.sub('^<br>', '', data)
  889. return str(data)
  890. def getip(request):
  891. if(session.get('Now') == True):
  892. ip = format(session['DREAMER'])
  893. else:
  894. if(request.headers.getlist("X-Forwarded-For")):
  895. ip = request.headers.getlist("X-Forwarded-For")[0]
  896. else:
  897. ip = request.remote_addr
  898. return ip
  899. def getcan(ip, name):
  900. m = re.search("^사용자:(.*)", name)
  901. n = re.search("^파일:(.*)", name)
  902. if(m):
  903. g = m.groups()
  904. if(ip == g[0]):
  905. if(re.search("\.", g[0])):
  906. return 1
  907. else:
  908. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  909. rows = curs.fetchall()
  910. if(rows):
  911. return 1
  912. else:
  913. return 0
  914. else:
  915. return 1
  916. elif(n):
  917. return 1
  918. else:
  919. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))", ip)
  920. if(b):
  921. results = b.groups()
  922. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  923. rowss = curs.fetchall()
  924. if(rowss):
  925. return 1
  926. else:
  927. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  928. rows = curs.fetchall()
  929. if(rows):
  930. return 1
  931. else:
  932. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  933. row = curs.fetchall()
  934. if(row):
  935. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  936. rows = curs.fetchall()
  937. if(row[0]['acl'] == 'user'):
  938. if(rows):
  939. return 0
  940. else:
  941. return 1
  942. elif(row[0]['acl'] == 'admin'):
  943. if(rows):
  944. if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'):
  945. return 0
  946. else:
  947. return 1
  948. else:
  949. return 1
  950. else:
  951. return 0
  952. else:
  953. return 0
  954. else:
  955. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  956. rows = curs.fetchall()
  957. if(rows):
  958. return 1
  959. else:
  960. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  961. row = curs.fetchall()
  962. if(row):
  963. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  964. rows = curs.fetchall()
  965. if(row[0]['acl'] == 'user'):
  966. if(rows):
  967. return 0
  968. else:
  969. return 1
  970. elif(row[0]['acl'] == 'admin'):
  971. if(rows):
  972. if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'):
  973. return 0
  974. else:
  975. return 1
  976. else:
  977. return 1
  978. else:
  979. return 0
  980. else:
  981. return 0
  982. def getban(ip):
  983. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))", ip)
  984. if(b):
  985. results = b.groups()
  986. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  987. rowss = curs.fetchall()
  988. if(rowss):
  989. return 1
  990. else:
  991. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  992. rows = curs.fetchall()
  993. if(rows):
  994. return 1
  995. else:
  996. return 0
  997. else:
  998. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  999. rows = curs.fetchall()
  1000. if(rows):
  1001. return 1
  1002. else:
  1003. return 0
  1004. def getdiscuss(ip, name, sub):
  1005. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))", ip)
  1006. if(b):
  1007. results = b.groups()
  1008. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  1009. rowss = curs.fetchall()
  1010. if(rowss):
  1011. return 1
  1012. else:
  1013. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  1014. rows = curs.fetchall()
  1015. if(rows):
  1016. return 1
  1017. else:
  1018. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  1019. rows = curs.fetchall()
  1020. if(rows):
  1021. return 1
  1022. else:
  1023. return 0
  1024. else:
  1025. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  1026. rows = curs.fetchall()
  1027. if(rows):
  1028. return 1
  1029. else:
  1030. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  1031. rows = curs.fetchall()
  1032. if(rows):
  1033. return 1
  1034. else:
  1035. return 0
  1036. def getnow():
  1037. now = time.localtime()
  1038. 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)
  1039. return s
  1040. def discuss(title, sub, date):
  1041. curs.execute("select * from rd where title = '" + pymysql.escape_string(title) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  1042. rows = curs.fetchall()
  1043. if(rows):
  1044. curs.execute("update rd set date = '" + pymysql.escape_string(date) + "' where title = '" + pymysql.escape_string(title) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  1045. else:
  1046. curs.execute("insert into rd (title, sub, date) value ('" + pymysql.escape_string(title) + "', '" + pymysql.escape_string(sub) + "', '" + pymysql.escape_string(date) + "')")
  1047. conn.commit()
  1048. def block(block, end, today, blocker, why):
  1049. 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) + "')")
  1050. conn.commit()
  1051. def history(title, data, date, ip, send, leng):
  1052. curs.execute("select * from history where title = '" + pymysql.escape_string(title) + "' order by id+0 desc limit 1")
  1053. rows = curs.fetchall()
  1054. if(rows):
  1055. number = int(rows[0]['id']) + 1
  1056. 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 + "')")
  1057. conn.commit()
  1058. else:
  1059. 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 + "')")
  1060. conn.commit()
  1061. def getleng(existing, change):
  1062. if(existing < change):
  1063. leng = change - existing
  1064. leng = '+' + str(leng)
  1065. elif(change < existing):
  1066. leng = existing - change
  1067. leng = '-' + str(leng)
  1068. else:
  1069. leng = '0'
  1070. return leng;
  1071. @app.route('/upload', methods=['GET', 'POST'])
  1072. def upload():
  1073. if(request.method == 'POST'):
  1074. ip = getip(request)
  1075. ban = getban(ip)
  1076. if(ban == 1):
  1077. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1078. else:
  1079. file = request.files['file']
  1080. if(file and allowed_file(file.filename)):
  1081. if(re.search('^([^./\\*<>|:?"]+)\.(jpg|gif|jpeg|png)$', file.filename)):
  1082. filename = file.filename
  1083. if(os.path.exists(os.path.join('image', filename))):
  1084. return render_template('index.html', logo = data['name'], title = '업로드 오류', data = '동일한 이름의 파일이 있습니다.')
  1085. else:
  1086. file.save(os.path.join('image', filename))
  1087. curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string('파일:' + filename) + "', '" + pymysql.escape_string('[[파일:' + filename + ']][br][br]{{{[[파일:' + filename + ']]}}}') + "', '')")
  1088. conn.commit()
  1089. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote('파일:' + filename).replace('/','%2F') + '" />'
  1090. else:
  1091. return render_template('index.html', logo = data['name'], title = '업로드 오류', data = '파일 명에 ./\*<>|:? 들은 불가능 합니다.')
  1092. else:
  1093. return render_template('index.html', logo = data['name'], title = '업로드 오류', data = 'jpg gif jpeg png만 가능 합니다.')
  1094. else:
  1095. ip = getip(request)
  1096. ban = getban(ip)
  1097. if(ban == 1):
  1098. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1099. else:
  1100. return render_template('index.html', logo = data['name'], title = '업로드', tn = 21, number = data['upload'])
  1101. @app.route('/image/<path:name>')
  1102. def image(name = None):
  1103. if(os.path.exists(os.path.join('image', name))):
  1104. return send_file(os.path.join('image', name), mimetype='image')
  1105. else:
  1106. return render_template('index.html', logo = data['name'], data = '이미지 없음.', title = '이미지 보기')
  1107. @app.route('/')
  1108. @app.route('/w/')
  1109. def redirect():
  1110. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1111. @app.route('/recentchanges')
  1112. def recentchanges():
  1113. i = 0
  1114. div = '<div>'
  1115. curs.execute("select * from history order by date desc limit 50")
  1116. rows = curs.fetchall()
  1117. if(rows):
  1118. admin = admincheck()
  1119. while True:
  1120. try:
  1121. a = rows[i]
  1122. except:
  1123. div = div + '</div>'
  1124. break
  1125. if(rows[i]['send']):
  1126. send = rows[i]['send']
  1127. send = re.sub('<a href="\/w\/(?P<in>[^"]*)">(?P<out>[^&]*)<\/a>', '<a href="/w/\g<in>">\g<out></a>', send)
  1128. else:
  1129. send = '<br>'
  1130. title = rows[i]['title']
  1131. title = re.sub('<', '&lt;', title)
  1132. title = re.sub('>', '&gt;', title)
  1133. m = re.search("\+", rows[i]['leng'])
  1134. n = re.search("\-", rows[i]['leng'])
  1135. if(m):
  1136. leng = '<span style="color:green;">' + rows[i]['leng'] + '</span>'
  1137. elif(n):
  1138. leng = '<span style="color:red;">' + rows[i]['leng'] + '</span>'
  1139. else:
  1140. leng = '<span style="color:gray;">' + rows[i]['leng'] + '</span>'
  1141. if(admin == 1):
  1142. curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1143. row = curs.fetchall()
  1144. if(row):
  1145. if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'):
  1146. ban = ''
  1147. else:
  1148. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1149. row = curs.fetchall()
  1150. if(row):
  1151. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1152. else:
  1153. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1154. else:
  1155. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1156. row = curs.fetchall()
  1157. if(row):
  1158. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1159. else:
  1160. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1161. else:
  1162. ban = ''
  1163. if(re.search('\.', rows[i]['ip'])):
  1164. ip = rows[i]['ip']
  1165. else:
  1166. curs.execute("select * from data where title = '사용자:" + pymysql.escape_string(rows[i]['ip']) + "'")
  1167. row = curs.fetchall()
  1168. if(row):
  1169. ip = '<a href="/w/' + parse.quote('사용자:' + rows[i]['ip']).replace('/','%2F') + '">' + rows[i]['ip'] + '</a>'
  1170. else:
  1171. ip = '<a class="not_thing" href="/w/' + parse.quote('사용자:' + rows[i]['ip']).replace('/','%2F') + '">' + rows[i]['ip'] + '</a>'
  1172. if((int(rows[i]['id']) - 1) == 0):
  1173. revert = ''
  1174. else:
  1175. revert = '<a href="/revert/' + parse.quote(rows[i]['title']).replace('/','%2F') + '/r/' + str(int(rows[i]['id']) - 1) + '">(되돌리기)</a>'
  1176. 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> ' + revert + ' (' + leng + ')</td><td style="text-align: center;width:33.33%;">' + ip + ban + '</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>'
  1177. i = i + 1
  1178. return render_template('index.html', logo = data['name'], rows = div, tn = 3, title = '최근 변경내역')
  1179. else:
  1180. return render_template('index.html', logo = data['name'], rows = '', tn = 3, title = '최근 변경내역')
  1181. @app.route('/record/<path:name>/n/<int:number>')
  1182. def record(name = None, number = None):
  1183. v = number * 50
  1184. i = v - 50
  1185. div = '<div>'
  1186. curs.execute("select * from history where ip = '" + pymysql.escape_string(name) + "' order by date desc")
  1187. rows = curs.fetchall()
  1188. if(rows):
  1189. admin = admincheck()
  1190. while True:
  1191. try:
  1192. a = rows[i]
  1193. except:
  1194. div = div + '</div>'
  1195. if(number != 1):
  1196. div = div + '<br><a href="/record/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number - 1) + '">(이전)'
  1197. break
  1198. if(rows[i]['send']):
  1199. send = rows[i]['send']
  1200. send = re.sub('<a href="\/w\/(?P<in>[^"]*)">(?P<out>[^&]*)<\/a>', '<a href="/w/\g<in>">\g<out></a>', send)
  1201. else:
  1202. send = '<br>'
  1203. title = rows[i]['title']
  1204. title = re.sub('<', '&lt;', title)
  1205. title = re.sub('>', '&gt;', title)
  1206. m = re.search("\+", rows[i]['leng'])
  1207. n = re.search("\-", rows[i]['leng'])
  1208. if(m):
  1209. leng = '<span style="color:green;">' + rows[i]['leng'] + '</span>'
  1210. elif(n):
  1211. leng = '<span style="color:red;">' + rows[i]['leng'] + '</span>'
  1212. else:
  1213. leng = '<span style="color:gray;">' + rows[i]['leng'] + '</span>'
  1214. if(admin == 1):
  1215. curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1216. row = curs.fetchall()
  1217. if(row):
  1218. if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'):
  1219. ip = rows[i]['ip']
  1220. else:
  1221. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1222. row = curs.fetchall()
  1223. if(row):
  1224. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1225. else:
  1226. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1227. else:
  1228. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1229. row = curs.fetchall()
  1230. if(row):
  1231. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1232. else:
  1233. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1234. else:
  1235. ip = rows[i]['ip']
  1236. if((int(rows[i]['id']) - 1) == 0):
  1237. revert = ''
  1238. else:
  1239. revert = '<a href="/revert/' + parse.quote(rows[i]['title']).replace('/','%2F') + '/r/' + str(int(rows[i]['id']) - 1) + '">(되돌리기)</a>'
  1240. 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> r' + rows[i]['id'] + ' <a href="/history/' + parse.quote(rows[i]['title']).replace('/','%2F') + '/n/1">(역사)</a> ' + revert + ' (' + 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>'
  1241. if(i == v):
  1242. div = div + '</div>'
  1243. if(number == 1):
  1244. div = div + '<br><a href="/record/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number + 1) + '">(다음)'
  1245. else:
  1246. div = div + '<br><a href="/record/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number - 1) + '">(이전) <a href="/record/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number + 1) + '">(다음)'
  1247. break
  1248. else:
  1249. i = i + 1
  1250. return render_template('index.html', logo = data['name'], rows = div, tn = 3, title = '유저 기록')
  1251. else:
  1252. return render_template('index.html', logo = data['name'], rows = '', tn = 3, title = '유저 기록')
  1253. @app.route('/userlog/n/<int:number>')
  1254. def userlog(number = None):
  1255. v = number * 50
  1256. i = v - 50
  1257. div = ''
  1258. curs.execute("select * from user")
  1259. rows = curs.fetchall()
  1260. if(rows):
  1261. admin = admincheck()
  1262. while True:
  1263. try:
  1264. a = rows[i]
  1265. except:
  1266. if(number != 1):
  1267. div = div + '<br><a href="/userlog/n/' + str(number - 1) + '">(이전)'
  1268. break
  1269. if(admin == 1):
  1270. curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['id']) + "'")
  1271. row = curs.fetchall()
  1272. if(row):
  1273. if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'):
  1274. ip = rows[i]['id']
  1275. else:
  1276. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['id']) + "'")
  1277. row = curs.fetchall()
  1278. if(row):
  1279. ip = rows[i]['id'] + ' <a href="/ban/' + parse.quote(rows[i]['id']).replace('/','%2F') + '">(해제)</a>'
  1280. else:
  1281. ip = rows[i]['id'] + ' <a href="/ban/' + parse.quote(rows[i]['id']).replace('/','%2F') + '">(차단)</a>'
  1282. else:
  1283. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['id']) + "'")
  1284. row = curs.fetchall()
  1285. if(row):
  1286. ip = rows[i]['id'] + ' <a href="/ban/' + parse.quote(rows[i]['id']).replace('/','%2F') + '">(해제)</a>'
  1287. else:
  1288. ip = rows[i]['id'] + ' <a href="/ban/' + parse.quote(rows[i]['id']).replace('/','%2F') + '">(차단)</a>'
  1289. else:
  1290. ip = rows[i]['id']
  1291. div = div + '<li>' + rows[i]['id'] + '</li>'
  1292. if(i == v):
  1293. if(number == 1):
  1294. div = div + '<br><a href="/userlog/n/' + str(number + 1) + '">(다음)'
  1295. else:
  1296. div = div + '<br><a href="/userlog/n/' + str(number - 1) + '">(이전) <a href="/userlog/n/' + str(number + 1) + '">(다음)'
  1297. break
  1298. else:
  1299. i = i + 1
  1300. return render_template('index.html', logo = data['name'], data = div, title = '유저 가입 기록')
  1301. else:
  1302. return render_template('index.html', logo = data['name'], data = '', title = '유저 가입 기록')
  1303. @app.route('/xref/<path:name>/n/<int:number>')
  1304. def xref(name = None, number = None):
  1305. v = number * 50
  1306. i = v - 50
  1307. div = ''
  1308. curs.execute("select * from back where title = '" + pymysql.escape_string(name) + "' order by link asc")
  1309. rows = curs.fetchall()
  1310. if(rows):
  1311. while True:
  1312. try:
  1313. a = rows[i]
  1314. except:
  1315. if(number != 1):
  1316. div = div + '<br><a href="/xref/n/' + str(number - 1) + '">(이전)'
  1317. break
  1318. curs.execute("select * from data where title = '" + pymysql.escape_string(rows[i]['link']) + "'")
  1319. row = curs.fetchall()
  1320. if(row):
  1321. aa = row[0]['data']
  1322. aa = re.sub("(?P<in>\[include\((?P<out>(?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\])", "\g<in>\n\n[[\g<out>]]\n\n", aa)
  1323. aa = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', '[[\g<in>]]', aa)
  1324. aa = namumark('', aa)
  1325. if(re.search("<a(?: class=\"not_thing\")? href=\"\/w\/" + parse.quote(name).replace('/','%2F') + "(?:\#[^\"]*)?\">([^<]*)<\/a>", aa)):
  1326. div = div + '<li><a href="/w/' + parse.quote(rows[i]['link']).replace('/','%2F') + '">' + rows[i]['link'] + '</a>'
  1327. if(rows[i]['type']):
  1328. div = div + ' (' + rows[i]['type'] + ')</li>'
  1329. else:
  1330. div = div + '</li>'
  1331. if(i == v):
  1332. if(number == 1):
  1333. div = div + '<br><a href="/xref/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number + 1) + '">(다음)'
  1334. else:
  1335. div = div + '<br><a href="/xref/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number - 1) + '">(이전) <a href="/userlog/n/' + str(number + 1) + '">(다음)'
  1336. break
  1337. else:
  1338. i = i + 1
  1339. else:
  1340. curs.execute("delete from back where title = '" + pymysql.escape_string(rows[i]['link']) + "' and link = '" + pymysql.escape_string(name) + "'")
  1341. conn.commit()
  1342. i = i + 1
  1343. v = v + 1
  1344. else:
  1345. curs.execute("delete from back where title = '" + pymysql.escape_string(rows[i]['link']) + "' and link = '" + pymysql.escape_string(name) + "'")
  1346. conn.commit()
  1347. i = i + 1
  1348. v = v + 1
  1349. return render_template('index.html', logo = data['name'], data = div, title = name, plus = '(역링크)')
  1350. else:
  1351. return render_template('index.html', logo = data['name'], data = '', title = name, plus = '(역링크)')
  1352. @app.route('/recentdiscuss')
  1353. def recentdiscuss():
  1354. i = 0
  1355. div = '<div>'
  1356. curs.execute("select * from rd order by date desc limit 50")
  1357. rows = curs.fetchall()
  1358. if(rows):
  1359. while True:
  1360. try:
  1361. a = rows[i]
  1362. except:
  1363. div = div + '</div>'
  1364. break
  1365. title = rows[i]['title']
  1366. title = re.sub('<', '&lt;', title)
  1367. title = re.sub('>', '&gt;', title)
  1368. sub = rows[i]['sub']
  1369. sub = re.sub('<', '&lt;', sub)
  1370. sub = re.sub('>', '&gt;', sub)
  1371. 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>'
  1372. i = i + 1
  1373. return render_template('index.html', logo = data['name'], rows = div, tn = 12, title = '최근 토론내역')
  1374. else:
  1375. return render_template('index.html', logo = data['name'], rows = '', tn = 12, title = '최근 토론내역')
  1376. @app.route('/blocklog/n/<int:number>')
  1377. def blocklog(number = None):
  1378. v = number * 50
  1379. i = v - 50
  1380. div = '<div>'
  1381. curs.execute("select * from rb order by today")
  1382. rows = curs.fetchall()
  1383. if(rows):
  1384. while True:
  1385. try:
  1386. a = rows[i]
  1387. except:
  1388. div = div + '</div>'
  1389. if(number != 1):
  1390. div = div + '<br><a href="/blocklog/n/' + str(number - 1) + '">(이전)'
  1391. break
  1392. why = rows[i]['why']
  1393. why = re.sub('<', '&lt;', why)
  1394. why = re.sub('>', '&gt;', why)
  1395. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))$", rows[i]['block'])
  1396. if(b):
  1397. ip = rows[i]['block'] + ' (대역)'
  1398. else:
  1399. ip = rows[i]['block']
  1400. div = div + '<table style="width: 100%;"><tbody><tr><td style="text-align: center;width:20%;">' + ip + '</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>'
  1401. if(i == v):
  1402. div = div + '</div>'
  1403. if(number == 1):
  1404. div = div + '<br><a href="/blocklog/n/' + str(number + 1) + '">(다음)'
  1405. else:
  1406. div = div + '<br><a href="/blocklog/n/' + str(number - 1) + '">(이전) <a href="/blocklog/n/' + str(number + 1) + '">(다음)'
  1407. break
  1408. else:
  1409. i = i + 1
  1410. return render_template('index.html', logo = data['name'], rows = div, tn = 20, title = '유저 차단 기록')
  1411. else:
  1412. return render_template('index.html', logo = data['name'], rows = '', tn = 20, title = '유저 차단 기록')
  1413. @app.route('/history/<path:name>/n/<int:number>', methods=['POST', 'GET'])
  1414. def gethistory(name = None, number = None):
  1415. if(request.method == 'POST'):
  1416. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '/r/' + request.form["b"] + '/diff/' + request.form["a"] + '" />'
  1417. else:
  1418. select = ''
  1419. v = number * 50
  1420. i = v - 50
  1421. div = '<div>'
  1422. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' order by id+0 desc")
  1423. rows = curs.fetchall()
  1424. if(rows):
  1425. admin = admincheck()
  1426. while True:
  1427. try:
  1428. a = rows[i]
  1429. except:
  1430. div = div + '</div>'
  1431. if(number != 1):
  1432. div = div + '<br><a href="/history/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number - 1) + '">(이전)'
  1433. break
  1434. select = '<option value="' + str(i + 1) + '">' + str(i + 1) + '</option>' + select
  1435. if(rows[i]['send']):
  1436. send = rows[i]['send']
  1437. send = re.sub('<a href="\/w\/(?P<in>[^"]*)">(?P<out>[^&]*)<\/a>', '<a href="/w/\g<in>">\g<out></a>', send)
  1438. else:
  1439. send = '<br>'
  1440. m = re.search("\+", rows[i]['leng'])
  1441. n = re.search("\-", rows[i]['leng'])
  1442. if(m):
  1443. leng = '<span style="color:green;">' + rows[i]['leng'] + '</span>'
  1444. elif(n):
  1445. leng = '<span style="color:red;">' + rows[i]['leng'] + '</span>'
  1446. else:
  1447. leng = '<span style="color:gray;">' + rows[i]['leng'] + '</span>'
  1448. if(admin == 1):
  1449. curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1450. row = curs.fetchall()
  1451. if(row):
  1452. if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'):
  1453. ban = ''
  1454. else:
  1455. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1456. row = curs.fetchall()
  1457. if(row):
  1458. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1459. else:
  1460. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1461. else:
  1462. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1463. row = curs.fetchall()
  1464. if(row):
  1465. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1466. else:
  1467. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1468. else:
  1469. ban = ''
  1470. if(re.search("\.", rows[i]["ip"])):
  1471. ip = rows[i]["ip"]
  1472. else:
  1473. curs.execute("select * from data where title = '사용자:" + pymysql.escape_string(rows[i]['ip']) + "'")
  1474. row = curs.fetchall()
  1475. if(row):
  1476. ip = '<a href="/w/' + parse.quote('사용자:' + rows[i]['ip']).replace('/','%2F') + '">' + rows[i]['ip'] + '</a>'
  1477. else:
  1478. ip = '<a class="not_thing" href="/w/' + parse.quote('사용자:' + rows[i]['ip']).replace('/','%2F') + '">' + rows[i]['ip'] + '</a>'
  1479. 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 + ban + '</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>'
  1480. if(i == v):
  1481. div = div + '</div>'
  1482. if(number == 1):
  1483. div = div + '<br><a href="/history/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number + 1) + '">(다음)'
  1484. else:
  1485. 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) + '">(다음)'
  1486. break
  1487. else:
  1488. i = i + 1
  1489. return render_template('index.html', logo = data['name'], rows = div, tn = 5, title = name, page = parse.quote(name).replace('/','%2F'), select = select)
  1490. else:
  1491. return render_template('index.html', logo = data['name'], rows = '', tn = 5, title = name, page = parse.quote(name).replace('/','%2F'), select = select)
  1492. @app.route('/search', methods=['POST', 'GET'])
  1493. def search():
  1494. if(request.method == 'POST'):
  1495. curs.execute("select * from data where title = '" + pymysql.escape_string(request.form["search"]) + "'")
  1496. rows = curs.fetchall()
  1497. if(rows):
  1498. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '" />'
  1499. else:
  1500. curs.execute("select * from data where title like '%" + pymysql.escape_string(request.form["search"]) + "%'")
  1501. rows = curs.fetchall()
  1502. div = ''
  1503. if(rows):
  1504. i = 0
  1505. div = div + '<li>문서가 없습니다. <a href="/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '">바로가기</a></li><br>'
  1506. while True:
  1507. try:
  1508. div = div + '<li><a href="/w/' + parse.quote(rows[i]['title']).replace('/','%2F') + '">' + rows[i]['title'] + '</a></li>'
  1509. except:
  1510. break
  1511. i = i + 1
  1512. else:
  1513. return div + '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '" />'
  1514. return render_template('index.html', logo = data['name'], data = div, title = '검색')
  1515. else:
  1516. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1517. @app.route('/w/<path:name>')
  1518. def w(name = None):
  1519. i = 0
  1520. curs.execute("select * from rd where title = '" + pymysql.escape_string(name) + "' order by date asc")
  1521. rows = curs.fetchall()
  1522. while True:
  1523. try:
  1524. a = rows[i]
  1525. except:
  1526. topic = ""
  1527. break
  1528. curs.execute("select * from stop where title = '" + pymysql.escape_string(rows[i]['title']) + "' and sub = '" + pymysql.escape_string(rows[i]['sub']) + "' and close = 'O'")
  1529. row = curs.fetchall()
  1530. if(not row):
  1531. topic = "open"
  1532. break
  1533. else:
  1534. i = i + 1
  1535. acl = ''
  1536. m = re.search("^(.*)\/(.*)$", name)
  1537. if(m):
  1538. g = m.groups()
  1539. uppage = g[0]
  1540. style = ""
  1541. else:
  1542. uppage = ""
  1543. style = "display:none;"
  1544. if(re.search("^분류:", name)):
  1545. curs.execute("select * from cat where title = '" + pymysql.escape_string(name) + "' order by cat asc")
  1546. rows = curs.fetchall()
  1547. if(rows):
  1548. div = ''
  1549. i = 0
  1550. while True:
  1551. try:
  1552. a = rows[i]
  1553. except:
  1554. break
  1555. curs.execute("select * from data where title = '" + pymysql.escape_string(rows[i]['cat']) + "'")
  1556. row = curs.fetchall()
  1557. if(row):
  1558. aa = row[0]['data']
  1559. aa = namumark('', aa)
  1560. bb = re.search('<div style="width:100%;border: 1px solid #777;padding: 5px;margin-top: 1em;">분류:((?:(?!<\/div>).)*)<\/div>', aa)
  1561. if(bb):
  1562. cc = bb.groups()
  1563. mm = re.search("^분류:(.*)", name)
  1564. if(mm):
  1565. ee = mm.groups()
  1566. if(re.search("<a href=\"\/w\/" + parse.quote(name).replace('/','%2F') + "\">" + ee[0] + "<\/a>", cc[0])):
  1567. div = div + '<li><a href="/w/' + parse.quote(rows[i]['cat']).replace('/','%2F') + '">' + rows[i]['cat'] + '</a></li>'
  1568. i = i + 1
  1569. else:
  1570. curs.execute("delete from cat where title = '" + pymysql.escape_string(rows[i]['cat']) + "' and cat = '" + pymysql.escape_string(name) + "'")
  1571. conn.commit()
  1572. i = i + 1
  1573. else:
  1574. curs.execute("delete from cat where title = '" + pymysql.escape_string(rows[i]['cat']) + "' and cat = '" + pymysql.escape_string(name) + "'")
  1575. conn.commit()
  1576. i = i + 1
  1577. else:
  1578. curs.execute("delete from cat where title = '" + pymysql.escape_string(rows[i]['cat']) + "' and cat = '" + pymysql.escape_string(name) + "'")
  1579. conn.commit()
  1580. i = i + 1
  1581. else:
  1582. curs.execute("delete from cat where title = '" + pymysql.escape_string(rows[i]['cat']) + "' and cat = '" + pymysql.escape_string(name) + "'")
  1583. conn.commit()
  1584. i = i + 1
  1585. div = '<h2>분류</h2>' + div
  1586. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1587. bb = curs.fetchall()
  1588. if(bb):
  1589. if(bb[0]['acl'] == 'admin'):
  1590. acl = '(관리자)'
  1591. elif(bb[0]['acl'] == 'user'):
  1592. acl = '(유저)'
  1593. else:
  1594. if(not acl):
  1595. acl = ''
  1596. enddata = namumark(name, bb[0]['data'])
  1597. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1598. if(m):
  1599. result = m.groups()
  1600. left = result[0]
  1601. else:
  1602. left = ''
  1603. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata + '<br>' + div, license = data['license'], tn = 1, uppage = uppage, style = style, acl = acl, topic = topic)
  1604. else:
  1605. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = div, license = data['license'], tn = 1, uppage = uppage, style = style, acl = acl, topic = topic)
  1606. else:
  1607. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '분류 문서 없음', license = data['license'], tn = 1, uppage = uppage, style = style, acl = acl, topic = topic)
  1608. else:
  1609. m = re.search("^사용자:(.*)", name)
  1610. if(m):
  1611. g = m.groups()
  1612. curs.execute("select * from user where id = '" + pymysql.escape_string(g[0]) + "'")
  1613. rows = curs.fetchall()
  1614. if(rows):
  1615. if(rows[0]['acl'] == 'owner'):
  1616. acl = '(소유자)'
  1617. elif(rows[0]['acl'] == 'admin'):
  1618. acl = '(관리자)'
  1619. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1620. rows = curs.fetchall()
  1621. if(rows):
  1622. if(rows[0]['acl'] == 'admin'):
  1623. acl = '(관리자)'
  1624. elif(rows[0]['acl'] == 'user'):
  1625. acl = '(유저)'
  1626. else:
  1627. if(not acl):
  1628. acl = ''
  1629. enddata = namumark(name, rows[0]['data'])
  1630. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1631. if(m):
  1632. result = m.groups()
  1633. left = result[0]
  1634. else:
  1635. left = ''
  1636. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'], tn = 1, acl = acl, left = left, uppage = uppage, style = style, topic = topic)
  1637. else:
  1638. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 1, uppage = uppage, style = style, acl = acl, topic = topic)
  1639. @app.route('/w/<path:name>/redirect/<redirect>')
  1640. def redirectw(name = None, redirect = None):
  1641. i = 0
  1642. curs.execute("select * from rd where title = '" + pymysql.escape_string(name) + "' order by date asc")
  1643. rows = curs.fetchall()
  1644. while True:
  1645. try:
  1646. a = rows[i]
  1647. except:
  1648. topic = ""
  1649. break
  1650. curs.execute("select * from stop where title = '" + pymysql.escape_string(rows[i]['title']) + "' and sub = '" + pymysql.escape_string(rows[i]['sub']) + "' and close = 'O'")
  1651. row = curs.fetchall()
  1652. if(not row):
  1653. topic = "open"
  1654. break
  1655. else:
  1656. i = i + 1
  1657. m = re.search("^(.*)\/(.*)$", name)
  1658. if(m):
  1659. g = m.groups()
  1660. uppage = g[0]
  1661. style = ""
  1662. else:
  1663. uppage = ""
  1664. style = "display:none;"
  1665. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '<a href="/w/' + parse.quote(name).replace('/','%2F') + '">문서 보기</a>', license = data['license'], tn = 1, redirect = '<a href="/w/' + parse.quote(redirect).replace('/','%2F') + '/redirect/' + parse.quote(name).replace('/','%2F') + '">' + redirect + '</a>에서 넘어 왔습니다.', uppage = uppage, style = style, topic = topic)
  1666. @app.route('/w/<path:name>/r/<number>')
  1667. def rew(name = None, number = None):
  1668. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1669. rows = curs.fetchall()
  1670. if(rows):
  1671. enddata = namumark(name, rows[0]['data'])
  1672. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1673. if(m):
  1674. result = m.groups()
  1675. left = result[0]
  1676. else:
  1677. left = ''
  1678. 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)
  1679. else:
  1680. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 6)
  1681. @app.route('/w/<path:name>/raw/<number>')
  1682. def reraw(name = None, number = None):
  1683. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1684. rows = curs.fetchall()
  1685. if(rows):
  1686. enddata = re.sub('<', '&lt;', rows[0]['data'])
  1687. enddata = re.sub('>', '&gt;', enddata)
  1688. enddata = re.sub('"', '&quot;', enddata)
  1689. enddata = re.sub("\n", '<br>', enddata)
  1690. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'])
  1691. else:
  1692. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'])
  1693. @app.route('/raw/<path:name>')
  1694. def raw(name = None):
  1695. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1696. rows = curs.fetchall()
  1697. if(rows):
  1698. enddata = re.sub('<', '&lt;', rows[0]['data'])
  1699. enddata = re.sub('>', '&gt;', enddata)
  1700. enddata = re.sub('"', '&quot;', enddata)
  1701. enddata = re.sub("\n", '<br>', enddata)
  1702. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'], tn = 7)
  1703. else:
  1704. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 7)
  1705. @app.route('/revert/<path:name>/r/<number>', methods=['POST', 'GET'])
  1706. def revert(name = None, number = None):
  1707. if(request.method == 'POST'):
  1708. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1709. rows = curs.fetchall()
  1710. if(rows):
  1711. ip = getip(request)
  1712. can = getcan(ip, name)
  1713. if(can == 1):
  1714. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1715. else:
  1716. today = getnow()
  1717. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1718. row = curs.fetchall()
  1719. if(row):
  1720. leng = getleng(len(row[0]['data']), len(rows[0]['data']))
  1721. curs.execute("update data set data = '" + pymysql.escape_string(rows[0]['data']) + "' where title = '" + pymysql.escape_string(name) + "'")
  1722. conn.commit()
  1723. else:
  1724. leng = '+' + str(len(rows[0]['data']))
  1725. curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(rows[0]['data']) + "', '')")
  1726. conn.commit()
  1727. history(name, rows[0]['data'], today, ip, '문서를 ' + number + '판으로 되돌렸습니다.', leng)
  1728. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1729. else:
  1730. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1731. else:
  1732. ip = getip(request)
  1733. can = getcan(ip, name)
  1734. if(can == 1):
  1735. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1736. else:
  1737. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1738. rows = curs.fetchall()
  1739. if(rows):
  1740. 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 = '정말 되돌리시겠습니까?')
  1741. else:
  1742. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1743. @app.route('/edit/<path:name>', methods=['POST', 'GET'])
  1744. def edit(name = None):
  1745. if(request.method == 'POST'):
  1746. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1747. rows = curs.fetchall()
  1748. m = re.search('(?:[^A-Za-zㄱ-힣0-9 ])', request.form["send"])
  1749. if(m):
  1750. return render_template('index.html', title = '편집 오류', logo = data['name'], data = '편집 내용 기록에는 한글과 영어와 숫자, 공백만 허용 됩니다.')
  1751. else:
  1752. today = getnow()
  1753. content = re.sub("\[date\(now\)\]", today, request.form["content"])
  1754. if(rows):
  1755. if(rows[0]['data'] == content):
  1756. return render_template('index.html', title = '편집 오류', logo = data['name'], data = '내용이 원래 문서와 동일 합니다.')
  1757. else:
  1758. ip = getip(request)
  1759. can = getcan(ip, name)
  1760. if(can == 1):
  1761. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1762. else:
  1763. leng = getleng(len(rows[0]['data']), len(content))
  1764. history(name, content, today, ip, request.form["send"], leng)
  1765. curs.execute("update data set data = '" + pymysql.escape_string(content) + "' where title = '" + pymysql.escape_string(name) + "'")
  1766. conn.commit()
  1767. else:
  1768. ip = getip(request)
  1769. can = getcan(ip, name)
  1770. if(can == 1):
  1771. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1772. else:
  1773. leng = '+' + str(len(content))
  1774. history(name, content, today, ip, request.form["send"], leng)
  1775. curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(content) + "', '')")
  1776. conn.commit()
  1777. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1778. else:
  1779. ip = getip(request)
  1780. can = getcan(ip, name)
  1781. if(can == 1):
  1782. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1783. else:
  1784. curs.execute("select * from data where title = '" + pymysql.escape_string(data["help"]) + "'")
  1785. rows = curs.fetchall()
  1786. if(rows):
  1787. newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', ' * \g<in> 문서로 넘겨주기', rows[0]["data"])
  1788. left = namumark(name, newdata)
  1789. else:
  1790. left = ''
  1791. if(re.search('\.', ip)):
  1792. notice = '비 로그인 상태 입니다. 비 로그인으로 편집시 아이피가 역사에 기록 됩니다. 편집 시 동의 함으로 간주 됩니다.'
  1793. else:
  1794. notice = ''
  1795. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1796. rows = curs.fetchall()
  1797. if(rows):
  1798. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = rows[0]['data'], tn = 2, notice = notice, left = left)
  1799. else:
  1800. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '', tn = 2, notice = notice, left = left)
  1801. @app.route('/preview/<path:name>', methods=['POST'])
  1802. def preview(name = None):
  1803. ip = getip(request)
  1804. can = getcan(ip, name)
  1805. if(can == 1):
  1806. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1807. else:
  1808. if(re.search('\.', ip)):
  1809. notice = '비 로그인 상태 입니다. 비 로그인으로 편집시 아이피가 역사에 기록 됩니다. 편집 시 동의 함으로 간주 됩니다.'
  1810. else:
  1811. notice = ''
  1812. newdata = request.form["content"]
  1813. newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', ' * \g<in> 문서로 넘겨주기', newdata)
  1814. enddata = namumark(name, newdata)
  1815. curs.execute("select * from data where title = '" + pymysql.escape_string(data["help"]) + "'")
  1816. rows = curs.fetchall()
  1817. if(rows):
  1818. newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', ' * \g<in> 문서로 넘겨주기', rows[0]["data"])
  1819. left = namumark(name, newdata)
  1820. else:
  1821. left = ''
  1822. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = request.form["content"], tn = 2, preview = 1, enddata = enddata, left = left, notice = notice)
  1823. @app.route('/delete/<path:name>', methods=['POST', 'GET'])
  1824. def delete(name = None):
  1825. if(request.method == 'POST'):
  1826. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1827. rows = curs.fetchall()
  1828. if(rows):
  1829. ip = getip(request)
  1830. can = getcan(ip, name)
  1831. if(can == 1):
  1832. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1833. else:
  1834. today = getnow()
  1835. leng = '-' + str(len(rows[0]['data']))
  1836. history(name, '', today, ip, '문서를 삭제 했습니다.', leng)
  1837. curs.execute("delete from data where title = '" + pymysql.escape_string(name) + "'")
  1838. conn.commit()
  1839. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1840. else:
  1841. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1842. else:
  1843. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1844. rows = curs.fetchall()
  1845. if(rows):
  1846. ip = getip(request)
  1847. can = getcan(ip, name)
  1848. if(can == 1):
  1849. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1850. else:
  1851. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), tn = 8, plus = '정말 삭제 하시겠습니까?')
  1852. else:
  1853. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1854. @app.route('/move/<path:name>', methods=['POST', 'GET'])
  1855. def move(name = None):
  1856. if(request.method == 'POST'):
  1857. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1858. rows = curs.fetchall()
  1859. if(rows):
  1860. ip = getip(request)
  1861. can = getcan(ip, name)
  1862. if(can == 1):
  1863. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1864. else:
  1865. today = getnow()
  1866. leng = '0'
  1867. curs.execute("select * from history where title = '" + pymysql.escape_string(request.form["title"]) + "'")
  1868. row = curs.fetchall()
  1869. if(row):
  1870. return render_template('index.html', title = '이동 오류', logo = data['name'], data = '이동 하려는 곳에 문서가 이미 있습니다.')
  1871. else:
  1872. history(name, rows[0]['data'], today, ip, '<a href="/w/' + parse.quote(name).replace('/','%2F') + '">' + name + '</a> 문서를 <a href="/w/' + parse.quote(request.form["title"]).replace('/','%2F') + '">' + request.form["title"] + '</a> 문서로 이동 했습니다.', leng)
  1873. curs.execute("update data set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1874. curs.execute("update history set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1875. conn.commit()
  1876. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["title"]).replace('/','%2F') + '" />'
  1877. else:
  1878. ip = getip(request)
  1879. can = getcan(ip, name)
  1880. if(can == 1):
  1881. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1882. else:
  1883. today = getnow()
  1884. leng = '0'
  1885. curs.execute("select * from history where title = '" + pymysql.escape_string(request.form["title"]) + "'")
  1886. row = curs.fetchall()
  1887. if(row):
  1888. return render_template('index.html', title = '이동 오류', logo = data['name'], data = '이동 하려는 곳에 문서가 이미 있습니다.')
  1889. else:
  1890. history(name, '', today, ip, '<a href="/w/' + parse.quote(name).replace('/','%2F') + '">' + name + '</a> 문서를 <a href="/w/' + parse.quote(request.form["title"]).replace('/','%2F') + '">' + request.form["title"] + '</a> 문서로 이동 했습니다.', leng)
  1891. curs.execute("update history set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1892. conn.commit()
  1893. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["title"]).replace('/','%2F') + '" />'
  1894. else:
  1895. ip = getip(request)
  1896. can = getcan(ip, name)
  1897. if(can == 1):
  1898. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1899. else:
  1900. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), tn = 9, plus = '정말 이동 하시겠습니까?')
  1901. @app.route('/setup')
  1902. def setup():
  1903. curs.execute("create table if not exists data(title text not null, data longtext not null, acl text not null)")
  1904. 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)")
  1905. curs.execute("create table if not exists rd(title text not null, sub text not null, date text not null)")
  1906. curs.execute("create table if not exists user(id text not null, pw text not null, acl text not null)")
  1907. curs.execute("create table if not exists ban(block text not null, end text not null, why text not null, band text not null)")
  1908. 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)")
  1909. curs.execute("create table if not exists stop(title text not null, sub text not null, close text not null)")
  1910. 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)")
  1911. curs.execute("create table if not exists login(user text not null, ip text not null, today text not null)")
  1912. curs.execute("create table if not exists back(title text not null, link text not null, type text not null)")
  1913. curs.execute("create table if not exists cat(title text not null, cat text not null)")
  1914. return render_template('index.html', title = '설치 완료', logo = data['name'], data = '문제 없었음')
  1915. @app.route('/other')
  1916. def other():
  1917. return render_template('index.html', title = '기타 메뉴', logo = data['name'], data = '<li><a href="/titleindex">모든 문서</a></li><li><a href="/grammar">문법 설명</a></li><li><a href="/version">버전</a></li><li><a href="/blocklog/n/1">유저 차단 기록</a></li><li><a href="/userlog/n/1">유저 가입 기록</a></li><li><a href="/upload">업로드</a></li><li><a href="/manager">관리자 메뉴</a></li><li><a href="/record">유저 기록</a></li>')
  1918. @app.route('/manager')
  1919. def manager():
  1920. return render_template('index.html', title = '관리자 메뉴', logo = data['name'], data = '<li><a href="/acl">문서 ACL</a></li><li><a href="/check">유저 체크</a></li><li><a href="/banget">유저 차단</a></li><li><a href="/admin">관리자 권한 주기</a></li>')
  1921. @app.route('/acl', methods=['POST', 'GET'])
  1922. def aclget():
  1923. if(request.method == 'POST'):
  1924. return '<meta http-equiv="refresh" content="0;url=/acl/' + parse.quote(request.form["name"]).replace('/','%2F') + '" />'
  1925. else:
  1926. return render_template('index.html', title = 'ACL 이동', logo = data['name'], data = '<form id="usrform" method="POST" action="/acl"><input name="name" type="text"><br><br><button class="btn btn-primary" type="submit">이동</button></form>')
  1927. @app.route('/check', methods=['POST', 'GET'])
  1928. def checkget():
  1929. if(request.method == 'POST'):
  1930. return '<meta http-equiv="refresh" content="0;url=/check/' + parse.quote(request.form["name"]).replace('/','%2F') + '" />'
  1931. else:
  1932. return render_template('index.html', title = '유저 체크 이동', logo = data['name'], data = '<form id="usrform" method="POST" action="/check"><input name="name" type="text"><br><br><button class="btn btn-primary" type="submit">이동</button></form>')
  1933. @app.route('/banget', methods=['POST', 'GET'])
  1934. def hebanget():
  1935. if(request.method == 'POST'):
  1936. return '<meta http-equiv="refresh" content="0;url=/ban/' + parse.quote(request.form["name"]).replace('/','%2F') + '" />'
  1937. else:
  1938. return render_template('index.html', title = '유저 차단 이동', logo = data['name'], data = '<form id="usrform" method="POST" action="/banget"><input name="name" type="text"><br><br><button class="btn btn-primary" type="submit">이동</button><br><br><span>아이피 앞 두자리 (XXX.XXX) 입력하면 대역 차단</span></form>')
  1939. @app.route('/admin', methods=['POST', 'GET'])
  1940. def adminget():
  1941. if(request.method == 'POST'):
  1942. return '<meta http-equiv="refresh" content="0;url=/admin/' + parse.quote(request.form["name"]).replace('/','%2F') + '" />'
  1943. else:
  1944. return render_template('index.html', title = '관리자 권한 이동', logo = data['name'], data = '<form id="usrform" method="POST" action="/admin"><input name="name" type="text"><br><br><button class="btn btn-primary" type="submit">이동</button></form>')
  1945. @app.route('/record', methods=['POST', 'GET'])
  1946. def recordget():
  1947. if(request.method == 'POST'):
  1948. return '<meta http-equiv="refresh" content="0;url=/record/' + parse.quote(request.form["name"]).replace('/','%2F') + '/n/1" />'
  1949. else:
  1950. return render_template('index.html', title = '유저 기록 이동', logo = data['name'], data = '<form id="usrform" method="POST" action="/record"><input name="name" type="text"><br><br><button class="btn btn-primary" type="submit">이동</button></form>')
  1951. @app.route('/titleindex')
  1952. def titleindex():
  1953. i = 0
  1954. div = '<div>'
  1955. curs.execute("select * from data order by title asc")
  1956. rows = curs.fetchall()
  1957. if(rows):
  1958. while True:
  1959. try:
  1960. a = rows[i]
  1961. except:
  1962. div = div + '</div>'
  1963. break
  1964. div = div + '<li><a href="/w/' + parse.quote(rows[i]['title']).replace('/','%2F') + '">' + rows[i]['title'] + '</a></li>'
  1965. i = i + 1
  1966. return render_template('index.html', logo = data['name'], rows = div + '<br><span>이 위키에는 총 ' + str(i + 1) + '개의 문서가 있습니다.</span>', tn = 4, title = '모든 문서')
  1967. else:
  1968. return render_template('index.html', logo = data['name'], rows = '', tn = 4, title = '모든 문서')
  1969. @app.route('/topic/<path:name>', methods=['POST', 'GET'])
  1970. def topic(name = None):
  1971. if(request.method == 'POST'):
  1972. return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(request.form["topic"]).replace('/','%2F') + '" />'
  1973. else:
  1974. div = '<div>'
  1975. i = 0
  1976. j = 1
  1977. curs.execute("select * from rd where title = '" + pymysql.escape_string(name) + "' order by date asc")
  1978. rows = curs.fetchall()
  1979. while True:
  1980. try:
  1981. a = rows[i]
  1982. except:
  1983. div = div + '</div>'
  1984. break
  1985. curs.execute("select * from topic where title = '" + pymysql.escape_string(rows[i]['title']) + "' and sub = '" + pymysql.escape_string(rows[i]['sub']) + "' and id = '1' order by sub asc")
  1986. aa = curs.fetchall()
  1987. indata = namumark(name, aa[0]['data'])
  1988. if(aa[0]['block'] == 'O'):
  1989. indata = '블라인드 되었습니다.'
  1990. block = 'style="background: gainsboro;"'
  1991. else:
  1992. block = ''
  1993. curs.execute("select * from stop where title = '" + pymysql.escape_string(rows[i]['title']) + "' and sub = '" + pymysql.escape_string(rows[i]['sub']) + "' and close = 'O'")
  1994. row = curs.fetchall()
  1995. if(not row):
  1996. div = div + '<h2><a href="/topic/' + parse.quote(rows[i]['title']).replace('/','%2F') + '/sub/' + parse.quote(rows[i]['sub']).replace('/','%2F') + '">' + str(j) + '. ' + rows[i]['sub'] + '</a></h2>'
  1997. div = div + '<table id="toron"><tbody><tr><td id="toroncolorgreen"><a href="javascript:void(0);" id="1">#1</a> ' + aa[0]['ip'] + ' <span style="float:right;">' + aa[0]['date'] + '</span></td></tr><tr><td ' + block + '>' + indata + '</td></tr></tbody></table><br>'
  1998. j = j + 1
  1999. i = i + 1
  2000. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], plus = div, tn = 10, list = 1)
  2001. @app.route('/topic/<path:name>/close')
  2002. def topicstoplist(name = None):
  2003. if(request.method == 'POST'):
  2004. return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(request.form["topic"]).replace('/','%2F') + '" />'
  2005. else:
  2006. div = '<div>'
  2007. i = 0
  2008. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and close = 'O' order by sub asc")
  2009. rows = curs.fetchall()
  2010. while True:
  2011. try:
  2012. a = rows[i]
  2013. except:
  2014. div = div + '</div>'
  2015. break
  2016. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(rows[i]['sub']) + "' and id = '1'")
  2017. row = curs.fetchall()
  2018. if(row):
  2019. j = i + 1
  2020. indata = namumark(name, row[0]['data'])
  2021. if(row[0]['block'] == 'O'):
  2022. indata = '블라인드 되었습니다.'
  2023. block = 'style="background: gainsboro;"'
  2024. else:
  2025. block = ''
  2026. 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>'
  2027. 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>'
  2028. i = i + 1
  2029. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], plus = div, tn = 10)
  2030. @app.route('/topic/<path:name>/sub/<path:sub>', methods=['POST', 'GET'])
  2031. def sub(name = None, sub = None):
  2032. if(request.method == 'POST'):
  2033. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
  2034. rows = curs.fetchall()
  2035. if(rows):
  2036. number = int(rows[0]['id']) + 1
  2037. else:
  2038. number = 1
  2039. ip = getip(request)
  2040. ban = getdiscuss(ip, name, sub)
  2041. if(ban == 1):
  2042. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2043. else:
  2044. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2045. rows = curs.fetchall()
  2046. if(rows):
  2047. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  2048. ip = ip + ' - Admin'
  2049. today = getnow()
  2050. discuss(name, sub, today)
  2051. aa = request.form["content"]
  2052. aa = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", "[br]", aa)
  2053. 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(aa) + "', '" + today + "', '" + ip + "', '')")
  2054. conn.commit()
  2055. return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '" />'
  2056. else:
  2057. ip = getip(request)
  2058. ban = getdiscuss(ip, name, sub)
  2059. admin = admincheck()
  2060. if(admin == 1):
  2061. 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>'
  2062. else:
  2063. div = '<div>'
  2064. i = 0
  2065. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 asc")
  2066. rows = curs.fetchall()
  2067. while True:
  2068. try:
  2069. a = rows[i]
  2070. except:
  2071. div = div + '</div>'
  2072. break
  2073. if(i == 0):
  2074. start = rows[i]['ip']
  2075. indata = namumark(name, rows[i]['data'])
  2076. if(rows[i]['block'] == 'O'):
  2077. indata = '블라인드 되었습니다.'
  2078. block = 'style="background: gainsboro;"'
  2079. else:
  2080. block = ''
  2081. m = re.search("([^-]*)\s\-\s(Close|Reopen|Stop|Restart)$", rows[i]['ip'])
  2082. if(m):
  2083. ban = ""
  2084. else:
  2085. if(admin == 1):
  2086. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  2087. row = curs.fetchall()
  2088. if(rows[i]['block'] == 'O'):
  2089. isblock = ' <a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '/b/' + str(i + 1) + '">(해제)</a>'
  2090. else:
  2091. isblock = ' <a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '/b/' + str(i + 1) + '">(블라인드)</a>'
  2092. n = re.search("\- (?:Admin)$", rows[i]['ip'])
  2093. if(n):
  2094. ban = isblock
  2095. else:
  2096. if(row):
  2097. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>' + isblock
  2098. else:
  2099. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>' + isblock
  2100. else:
  2101. ban = ""
  2102. m = re.search("([^-]*)\s\-\s(Close|Reopen|Stop|Restart|Admin)$", rows[i]['ip'])
  2103. if(m):
  2104. g = m.groups()
  2105. curs.execute("select * from data where title = '사용자:" + pymysql.escape_string(g[0]) + "'")
  2106. row = curs.fetchall()
  2107. if(row):
  2108. ip = '<a href="/w/' + parse.quote('사용자:' + g[0]).replace('/','%2F') + '">' + g[0] + '</a> - ' + g[1]
  2109. else:
  2110. ip = '<a class="not_thing" href="/w/' + parse.quote('사용자:' + g[0]).replace('/','%2F') + '">' + g[0] + '</a> - ' + g[1]
  2111. elif(re.search("\.", rows[i]["ip"])):
  2112. ip = rows[i]["ip"]
  2113. else:
  2114. curs.execute("select * from data where title = '사용자:" + pymysql.escape_string(rows[i]['ip']) + "'")
  2115. row = curs.fetchall()
  2116. if(row):
  2117. ip = '<a href="/w/' + parse.quote('사용자:' + rows[i]['ip']).replace('/','%2F') + '">' + rows[i]['ip'] + '</a>'
  2118. else:
  2119. ip = '<a class="not_thing" href="/w/' + parse.quote('사용자:' + rows[i]['ip']).replace('/','%2F') + '">' + rows[i]['ip'] + '</a>'
  2120. if(rows[i]['ip'] == start):
  2121. j = i + 1
  2122. div = div + '<table id="toron"><tbody><tr><td id="toroncolorgreen"><a href="javascript:void(0);" id="' + str(j) + '">#' + str(j) + '</a> ' + ip + ban + ' <span style="float:right;">' + rows[i]['date'] + '</span></td></tr><tr><td ' + block + '>' + indata + '</td></tr></tbody></table><br>'
  2123. else:
  2124. j = i + 1
  2125. div = div + '<table id="toron"><tbody><tr><td id="toroncolor"><a href="javascript:void(0);" id="' + str(j) + '">#' + str(j) + '</a> ' + ip + ban + ' <span style="float:right;">' + rows[i]['date'] + '</span></td></tr><tr><td ' + block + '>' + indata + '</td></tr></tbody></table><br>'
  2126. i = i + 1
  2127. 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)
  2128. @app.route('/topic/<path:name>/sub/<path:sub>/b/<number>')
  2129. def blind(name = None, sub = None, number = None):
  2130. if(session.get('Now') == True):
  2131. ip = getip(request)
  2132. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2133. rows = curs.fetchall()
  2134. if(rows):
  2135. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  2136. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'")
  2137. row = curs.fetchall()
  2138. if(row):
  2139. if(row[0]['block'] == 'O'):
  2140. curs.execute("update topic set block = '' where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'")
  2141. else:
  2142. curs.execute("update topic set block = 'O' where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'")
  2143. conn.commit()
  2144. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  2145. else:
  2146. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  2147. else:
  2148. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2149. else:
  2150. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  2151. else:
  2152. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  2153. @app.route('/topic/<path:name>/sub/<path:sub>/stop')
  2154. def topicstop(name = None, sub = None):
  2155. if(session.get('Now') == True):
  2156. ip = getip(request)
  2157. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2158. rows = curs.fetchall()
  2159. if(rows):
  2160. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  2161. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
  2162. row = curs.fetchall()
  2163. if(row):
  2164. today = getnow()
  2165. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = ''")
  2166. rows = curs.fetchall()
  2167. if(rows):
  2168. 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', '')")
  2169. curs.execute("delete from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = ''")
  2170. else:
  2171. 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', '')")
  2172. curs.execute("insert into stop (title, sub, close) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', '')")
  2173. conn.commit()
  2174. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  2175. else:
  2176. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  2177. else:
  2178. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2179. else:
  2180. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  2181. else:
  2182. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  2183. @app.route('/topic/<path:name>/sub/<path:sub>/close')
  2184. def topicclose(name = None, sub = None):
  2185. if(session.get('Now') == True):
  2186. ip = getip(request)
  2187. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2188. rows = curs.fetchall()
  2189. if(rows):
  2190. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  2191. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
  2192. row = curs.fetchall()
  2193. if(row):
  2194. today = getnow()
  2195. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'")
  2196. rows = curs.fetchall()
  2197. if(rows):
  2198. 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', '')")
  2199. curs.execute("delete from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'")
  2200. else:
  2201. 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', '')")
  2202. curs.execute("insert into stop (title, sub, close) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', 'O')")
  2203. conn.commit()
  2204. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  2205. else:
  2206. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  2207. else:
  2208. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2209. else:
  2210. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  2211. else:
  2212. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  2213. @app.route('/login', methods=['POST', 'GET'])
  2214. def login():
  2215. if(request.method == 'POST'):
  2216. ip = getip(request)
  2217. ban = getban(ip)
  2218. if(ban == 1):
  2219. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2220. else:
  2221. curs.execute("select * from user where id = '" + pymysql.escape_string(request.form["id"]) + "'")
  2222. rows = curs.fetchall()
  2223. if(rows):
  2224. if(session.get('Now') == True):
  2225. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '이미 로그인 되어 있습니다.')
  2226. elif(bcrypt.checkpw(bytes(request.form["pw"], 'utf-8'), bytes(rows[0]['pw'], 'utf-8'))):
  2227. session['Now'] = True
  2228. session['DREAMER'] = request.form["id"]
  2229. curs.execute("insert into login (user, ip, today) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(ip) + "', '" + pymysql.escape_string(getnow()) + "')")
  2230. conn.commit()
  2231. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  2232. else:
  2233. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '비밀번호가 다릅니다.')
  2234. else:
  2235. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '없는 계정 입니다.')
  2236. else:
  2237. ip = getip(request)
  2238. ban = getban(ip)
  2239. if(ban == 1):
  2240. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2241. else:
  2242. if(session.get('Now') == True):
  2243. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '이미 로그인 되어 있습니다.')
  2244. else:
  2245. return render_template('index.html', title = '로그인', enter = '로그인', logo = data['name'], tn = 15)
  2246. @app.route('/change', methods=['POST', 'GET'])
  2247. def change():
  2248. if(request.method == 'POST'):
  2249. ip = getip(request)
  2250. ban = getban(ip)
  2251. if(ban == 1):
  2252. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2253. else:
  2254. curs.execute("select * from user where id = '" + pymysql.escape_string(request.form["id"]) + "'")
  2255. rows = curs.fetchall()
  2256. if(rows):
  2257. if(session.get('Now') == True):
  2258. return '<meta http-equiv="refresh" content="0;url=/logout" />'
  2259. elif(bcrypt.checkpw(bytes(request.form["pw"], 'utf-8'), bytes(rows[0]['pw'], 'utf-8'))):
  2260. hashed = bcrypt.hashpw(bytes(request.form["pw2"], 'utf-8'), bcrypt.gensalt())
  2261. curs.execute("update user set pw = '" + pymysql.escape_string(hashed.decode()) + "' where id = '" + pymysql.escape_string(request.form["id"]) + "'")
  2262. conn.commit()
  2263. return '<meta http-equiv="refresh" content="0;url=/login" />'
  2264. else:
  2265. return render_template('index.html', title = '변경 오류', logo = data['name'], data = '비밀번호가 다릅니다.')
  2266. else:
  2267. return render_template('index.html', title = '변경 오류', logo = data['name'], data = '없는 계정 입니다.')
  2268. else:
  2269. ip = getip(request)
  2270. ban = getban(ip)
  2271. if(ban == 1):
  2272. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2273. else:
  2274. if(session.get('Now') == True):
  2275. return '<meta http-equiv="refresh" content="0;url=/logout" />'
  2276. else:
  2277. return render_template('index.html', title = '비밀번호 변경', enter = '비밀번호 변경', logo = data['name'], tn = 15)
  2278. @app.route('/check/<path:name>')
  2279. def check(name = None, sub = None, number = None):
  2280. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  2281. rows = curs.fetchall()
  2282. if(rows and rows[0]['acl'] == 'owner' or rows and rows[0]['acl'] == 'admin'):
  2283. return render_template('index.html', title = '차단 오류', logo = data['name'], data = '관리자는 검사 할 수 없습니다.')
  2284. else:
  2285. if(admincheck() == 1):
  2286. 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)
  2287. if(m):
  2288. curs.execute("select * from login where ip = '" + pymysql.escape_string(name) + "' order by today desc")
  2289. row = curs.fetchall()
  2290. if(row):
  2291. i = 0
  2292. c = ''
  2293. while True:
  2294. try:
  2295. 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>'
  2296. except:
  2297. break
  2298. i = i + 1
  2299. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = c)
  2300. else:
  2301. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = '')
  2302. else:
  2303. curs.execute("select * from login where user = '" + pymysql.escape_string(name) + "' order by today desc")
  2304. row = curs.fetchall()
  2305. if(row):
  2306. i = 0
  2307. c = ''
  2308. while True:
  2309. try:
  2310. 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>'
  2311. except:
  2312. break
  2313. i = i + 1
  2314. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = c)
  2315. else:
  2316. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = '')
  2317. else:
  2318. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2319. @app.route('/register', methods=['POST', 'GET'])
  2320. def register():
  2321. if(request.method == 'POST'):
  2322. ip = getip(request)
  2323. ban = getban(ip)
  2324. if(ban == 1):
  2325. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2326. else:
  2327. m = re.search('(?:[^A-Za-zㄱ-힣0-9 ])', request.form["id"])
  2328. if(m):
  2329. return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '아이디에는 한글과 알파벳 공백만 허용 됩니다.')
  2330. else:
  2331. if(len(request.form["id"]) > 20):
  2332. return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '아이디는 20글자보다 짧아야 합니다.')
  2333. else:
  2334. curs.execute("select * from user where id = '" + pymysql.escape_string(request.form["id"]) + "'")
  2335. rows = curs.fetchall()
  2336. if(rows):
  2337. return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '동일한 아이디의 유저가 있습니다.')
  2338. else:
  2339. hashed = bcrypt.hashpw(bytes(request.form["pw"], 'utf-8'), bcrypt.gensalt())
  2340. if(request.form["id"] == data['owner']):
  2341. curs.execute("insert into user (id, pw, acl) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(hashed.decode()) + "', 'owner')")
  2342. else:
  2343. curs.execute("insert into user (id, pw, acl) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(hashed.decode()) + "', 'user')")
  2344. conn.commit()
  2345. return '<meta http-equiv="refresh" content="0;url=/login" />'
  2346. else:
  2347. ip = getip(request)
  2348. ban = getban(ip)
  2349. if(ban == 1):
  2350. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2351. else:
  2352. return render_template('index.html', title = '회원가입', enter = '회원가입', logo = data['name'], tn = 15)
  2353. @app.route('/logout')
  2354. def logout():
  2355. session['Now'] = False
  2356. session.pop('DREAMER', None)
  2357. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  2358. @app.route('/ban/<path:name>', methods=['POST', 'GET'])
  2359. def ban(name = None):
  2360. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  2361. rows = curs.fetchall()
  2362. if(rows and rows[0]['acl'] == 'owner' or rows and rows[0]['acl'] == 'admin'):
  2363. return render_template('index.html', title = '차단 오류', logo = data['name'], data = '관리자는 차단 할 수 없습니다.')
  2364. else:
  2365. if(request.method == 'POST'):
  2366. if(admincheck() == 1):
  2367. ip = getip(request)
  2368. curs.execute("select * from ban where block = '" + pymysql.escape_string(name) + "'")
  2369. row = curs.fetchall()
  2370. if(row):
  2371. block(name, '해제', getnow(), ip, '')
  2372. curs.execute("delete from ban where block = '" + pymysql.escape_string(name) + "'")
  2373. else:
  2374. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))$", name)
  2375. if(b):
  2376. block(name, request.form["end"], getnow(), ip, request.form["why"])
  2377. 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')")
  2378. else:
  2379. block(name, request.form["end"], getnow(), ip, request.form["why"])
  2380. 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"]) + "', '')")
  2381. conn.commit()
  2382. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  2383. else:
  2384. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2385. else:
  2386. if(admincheck() == 1):
  2387. curs.execute("select * from ban where block = '" + pymysql.escape_string(name) + "'")
  2388. row = curs.fetchall()
  2389. if(row):
  2390. now = '차단 해제'
  2391. else:
  2392. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))$", name)
  2393. if(b):
  2394. now = '대역 차단'
  2395. else:
  2396. now = '차단'
  2397. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 16, now = now, today = getnow())
  2398. else:
  2399. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2400. @app.route('/acl/<path:name>', methods=['POST', 'GET'])
  2401. def acl(name = None):
  2402. if(request.method == 'POST'):
  2403. if(admincheck() == 1):
  2404. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  2405. row = curs.fetchall()
  2406. if(row):
  2407. if(request.form["select"] == 'admin'):
  2408. curs.execute("update data set acl = 'admin' where title = '" + pymysql.escape_string(name) + "'")
  2409. elif(request.form["select"] == 'user'):
  2410. curs.execute("update data set acl = 'user' where title = '" + pymysql.escape_string(name) + "'")
  2411. else:
  2412. curs.execute("update data set acl = '' where title = '" + pymysql.escape_string(name) + "'")
  2413. conn.commit()
  2414. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  2415. else:
  2416. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2417. else:
  2418. if(admincheck() == 1):
  2419. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  2420. row = curs.fetchall()
  2421. if(row):
  2422. if(row[0]['acl'] == 'admin'):
  2423. now = '관리자만'
  2424. elif(row[0]['acl'] == 'user'):
  2425. now = '유저 이상'
  2426. else:
  2427. now = '일반'
  2428. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 19, now = '현재 ACL 상태는 ' + now)
  2429. else:
  2430. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  2431. else:
  2432. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2433. @app.route('/admin/<path:name>', methods=['POST', 'GET'])
  2434. def admin(name = None):
  2435. if(request.method == 'POST'):
  2436. if(session.get('Now') == True):
  2437. ip = getip(request)
  2438. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2439. rows = curs.fetchall()
  2440. if(rows):
  2441. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  2442. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  2443. row = curs.fetchall()
  2444. if(row):
  2445. if(row[0]['acl'] == 'admin' or row[0]['acl'] == 'owner'):
  2446. curs.execute("update user set acl = 'user' where id = '" + pymysql.escape_string(name) + "'")
  2447. else:
  2448. curs.execute("update user set acl = '" + pymysql.escape_string(request.form["select"]) + "' where id = '" + pymysql.escape_string(name) + "'")
  2449. conn.commit()
  2450. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  2451. else:
  2452. return render_template('index.html', title = '사용자 오류', logo = data['name'], data = '계정이 없습니다.')
  2453. else:
  2454. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2455. else:
  2456. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  2457. else:
  2458. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  2459. else:
  2460. if(session.get('Now') == True):
  2461. ip = getip(request)
  2462. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2463. rows = curs.fetchall()
  2464. if(rows):
  2465. if(rows[0]['acl'] == 'owner'):
  2466. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  2467. row = curs.fetchall()
  2468. if(row):
  2469. if(row[0]['acl'] == 'admin' or row[0]['acl'] == 'owner'):
  2470. now = '권한 해제'
  2471. else:
  2472. now = '권한 부여'
  2473. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 18, now = now)
  2474. else:
  2475. return render_template('index.html', title = '사용자 오류', logo = data['name'], data = '계정이 없습니다.')
  2476. else:
  2477. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2478. else:
  2479. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  2480. else:
  2481. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  2482. @app.route('/grammar')
  2483. def grammar():
  2484. return render_template('index.html', title = '문법 설명', logo = data['name'], tn = 17)
  2485. @app.route('/ban')
  2486. def aban():
  2487. ip = getip(request)
  2488. if(getban(ip) == 1):
  2489. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  2490. rows = curs.fetchall()
  2491. if(rows):
  2492. if(rows[0]['end']):
  2493. end = rows[0]['end'] + ' 까지 차단 상태 입니다. / 사유 : ' + rows[0]['why']
  2494. now = getnow()
  2495. now = re.sub(':', '', now)
  2496. now = re.sub('\-', '', now)
  2497. now = re.sub(' ', '', now)
  2498. now = int(now)
  2499. day = rows[0]['end']
  2500. day = re.sub('\-', '', day)
  2501. if(now >= int(day + '000000')):
  2502. curs.execute("delete from ban where block = '" + pymysql.escape_string(ip) + "'")
  2503. conn.commit()
  2504. end = '차단이 풀렸습니다. 다시 시도 해 보세요.'
  2505. else:
  2506. end = '영구 차단 상태 입니다. / 사유 : ' + rows[0]['why']
  2507. else:
  2508. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))", ip)
  2509. if(b):
  2510. results = b.groups()
  2511. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  2512. row = curs.fetchall()
  2513. if(row):
  2514. if(row[0]['end']):
  2515. end = row[0]['end'] + ' 까지 차단 상태 입니다. / 사유 : ' + rows[0]['why']
  2516. now = getnow()
  2517. now = re.sub(':', '', now)
  2518. now = re.sub('\-', '', now)
  2519. now = re.sub(' ', '', now)
  2520. now = int(now)
  2521. day = row[0]['end']
  2522. day = re.sub('\-', '', day)
  2523. if(now >= int(day + '000000')):
  2524. curs.execute("delete from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  2525. conn.commit()
  2526. end = '차단이 풀렸습니다. 다시 시도 해 보세요.'
  2527. else:
  2528. end = '영구 차단 상태 입니다. / 사유 : ' + row[0]['why']
  2529. else:
  2530. end = '권한이 맞지 않는 상태 입니다.'
  2531. return render_template('index.html', title = '권한 오류', logo = data['name'], data = end)
  2532. @app.route('/w/<path:name>/r/<a>/diff/<b>')
  2533. def diff(name = None, a = None, b = None):
  2534. curs.execute("select * from history where id = '" + pymysql.escape_string(a) + "' and title = '" + pymysql.escape_string(name) + "'")
  2535. rows = curs.fetchall()
  2536. if(rows):
  2537. curs.execute("select * from history where id = '" + pymysql.escape_string(b) + "' and title = '" + pymysql.escape_string(name) + "'")
  2538. row = curs.fetchall()
  2539. if(row):
  2540. indata = re.sub('<', '&lt;', rows[0]['data'])
  2541. indata = re.sub('>', '&gt;', indata)
  2542. indata = re.sub('"', '&quot;', indata)
  2543. indata = re.sub('\n', '<br>', indata)
  2544. enddata = re.sub('<', '&lt;', row[0]['data'])
  2545. enddata = re.sub('>', '&gt;', enddata)
  2546. enddata = re.sub('"', '&quot;', enddata)
  2547. enddata = re.sub('\n', '<br>', enddata)
  2548. sm = difflib.SequenceMatcher(None, indata, enddata)
  2549. c = show_diff(sm)
  2550. return render_template('index.html', title = name, logo = data['name'], data = c, plus = '(비교)')
  2551. else:
  2552. return render_template('index.html', title = 'Diff 오류', logo = data['name'], data = '<a href="/w/' + name + '">이 리비전이나 문서가 없습니다.</a>')
  2553. else:
  2554. return render_template('index.html', title = 'Diff 오류', logo = data['name'], data = '<a href="/w/' + name + '">이 리비전이나 문서가 없습니다.</a>')
  2555. @app.route('/version')
  2556. def version():
  2557. return render_template('index.html', title = '버전', logo = data['name'], tn = 14)
  2558. @app.route('/user')
  2559. def user():
  2560. ip = getip(request)
  2561. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2562. rows = curs.fetchall()
  2563. if(getban(ip) == 0):
  2564. if(rows):
  2565. if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'):
  2566. if(rows[0]['acl'] == 'admin'):
  2567. acl = '관리자'
  2568. else:
  2569. acl = '소유자'
  2570. else:
  2571. acl = '유저'
  2572. else:
  2573. acl = '일반'
  2574. else:
  2575. acl = '차단'
  2576. 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><li><a href="/change">비밀번호 변경</a></li>')
  2577. @app.route('/random')
  2578. def random():
  2579. curs.execute("select * from data order by rand() limit 1")
  2580. rows = curs.fetchall()
  2581. if(rows):
  2582. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(rows[0]['title']).replace('/','%2F') + '" />'
  2583. else:
  2584. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  2585. @app.errorhandler(404)
  2586. def uncaughtError(error):
  2587. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  2588. if __name__ == '__main__':
  2589. app.run(host = '0.0.0.0', port = int(data['port']), threaded = True)