app.py 151 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763
  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?(?:[^)]*))+)?\)\]", '<div>' + enddata + '</div>', 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('<\/blockquote>((\r)?\n){2}<blockquote>', '</blockquote><br><blockquote>', data)
  888. data = re.sub('\n', '<br>', data)
  889. data = re.sub('^<br>', '', data)
  890. return str(data)
  891. def getip(request):
  892. if(session.get('Now') == True):
  893. ip = format(session['DREAMER'])
  894. else:
  895. if(request.headers.getlist("X-Forwarded-For")):
  896. ip = request.headers.getlist("X-Forwarded-For")[0]
  897. else:
  898. ip = request.remote_addr
  899. return ip
  900. def getcan(ip, name):
  901. m = re.search("^사용자:(.*)", name)
  902. n = re.search("^파일:(.*)", name)
  903. if(m):
  904. g = m.groups()
  905. if(ip == g[0]):
  906. if(re.search("\.", g[0])):
  907. return 1
  908. else:
  909. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  910. rows = curs.fetchall()
  911. if(rows):
  912. return 1
  913. else:
  914. return 0
  915. else:
  916. return 1
  917. elif(n):
  918. return 1
  919. else:
  920. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))", ip)
  921. if(b):
  922. results = b.groups()
  923. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  924. rowss = curs.fetchall()
  925. if(rowss):
  926. return 1
  927. else:
  928. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  929. rows = curs.fetchall()
  930. if(rows):
  931. return 1
  932. else:
  933. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  934. row = curs.fetchall()
  935. if(row):
  936. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  937. rows = curs.fetchall()
  938. if(row[0]['acl'] == 'user'):
  939. if(rows):
  940. return 0
  941. else:
  942. return 1
  943. elif(row[0]['acl'] == 'admin'):
  944. if(rows):
  945. if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'):
  946. return 0
  947. else:
  948. return 1
  949. else:
  950. return 1
  951. else:
  952. return 0
  953. else:
  954. return 0
  955. else:
  956. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  957. rows = curs.fetchall()
  958. if(rows):
  959. return 1
  960. else:
  961. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  962. row = curs.fetchall()
  963. if(row):
  964. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  965. rows = curs.fetchall()
  966. if(row[0]['acl'] == 'user'):
  967. if(rows):
  968. return 0
  969. else:
  970. return 1
  971. elif(row[0]['acl'] == 'admin'):
  972. if(rows):
  973. if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'):
  974. return 0
  975. else:
  976. return 1
  977. else:
  978. return 1
  979. else:
  980. return 0
  981. else:
  982. return 0
  983. def getban(ip):
  984. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))", ip)
  985. if(b):
  986. results = b.groups()
  987. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  988. rowss = curs.fetchall()
  989. if(rowss):
  990. return 1
  991. else:
  992. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  993. rows = curs.fetchall()
  994. if(rows):
  995. return 1
  996. else:
  997. return 0
  998. else:
  999. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  1000. rows = curs.fetchall()
  1001. if(rows):
  1002. return 1
  1003. else:
  1004. return 0
  1005. def getdiscuss(ip, name, sub):
  1006. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))", ip)
  1007. if(b):
  1008. results = b.groups()
  1009. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  1010. rowss = curs.fetchall()
  1011. if(rowss):
  1012. return 1
  1013. else:
  1014. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  1015. rows = curs.fetchall()
  1016. if(rows):
  1017. return 1
  1018. else:
  1019. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  1020. rows = curs.fetchall()
  1021. if(rows):
  1022. return 1
  1023. else:
  1024. return 0
  1025. else:
  1026. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  1027. rows = curs.fetchall()
  1028. if(rows):
  1029. return 1
  1030. else:
  1031. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  1032. rows = curs.fetchall()
  1033. if(rows):
  1034. return 1
  1035. else:
  1036. return 0
  1037. def getnow():
  1038. now = time.localtime()
  1039. 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)
  1040. return s
  1041. def discuss(title, sub, date):
  1042. curs.execute("select * from rd where title = '" + pymysql.escape_string(title) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  1043. rows = curs.fetchall()
  1044. if(rows):
  1045. curs.execute("update rd set date = '" + pymysql.escape_string(date) + "' where title = '" + pymysql.escape_string(title) + "' and sub = '" + pymysql.escape_string(sub) + "'")
  1046. else:
  1047. curs.execute("insert into rd (title, sub, date) value ('" + pymysql.escape_string(title) + "', '" + pymysql.escape_string(sub) + "', '" + pymysql.escape_string(date) + "')")
  1048. conn.commit()
  1049. def block(block, end, today, blocker, why):
  1050. 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) + "')")
  1051. conn.commit()
  1052. def history(title, data, date, ip, send, leng):
  1053. curs.execute("select * from history where title = '" + pymysql.escape_string(title) + "' order by id+0 desc limit 1")
  1054. rows = curs.fetchall()
  1055. if(rows):
  1056. number = int(rows[0]['id']) + 1
  1057. 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 + "')")
  1058. conn.commit()
  1059. else:
  1060. 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 + "')")
  1061. conn.commit()
  1062. def getleng(existing, change):
  1063. if(existing < change):
  1064. leng = change - existing
  1065. leng = '+' + str(leng)
  1066. elif(change < existing):
  1067. leng = existing - change
  1068. leng = '-' + str(leng)
  1069. else:
  1070. leng = '0'
  1071. return leng;
  1072. @app.route('/upload', methods=['GET', 'POST'])
  1073. def upload():
  1074. if(request.method == 'POST'):
  1075. ip = getip(request)
  1076. ban = getban(ip)
  1077. if(ban == 1):
  1078. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1079. else:
  1080. file = request.files['file']
  1081. if(file and allowed_file(file.filename)):
  1082. if(re.search('^([^./\\*<>|:?"]+)\.(jpg|gif|jpeg|png)$', file.filename)):
  1083. filename = file.filename
  1084. if(os.path.exists(os.path.join('image', filename))):
  1085. return render_template('index.html', logo = data['name'], title = '업로드 오류', data = '동일한 이름의 파일이 있습니다.')
  1086. else:
  1087. file.save(os.path.join('image', filename))
  1088. curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string('파일:' + filename) + "', '" + pymysql.escape_string('[[파일:' + filename + ']][br][br]{{{[[파일:' + filename + ']]}}}') + "', '')")
  1089. conn.commit()
  1090. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote('파일:' + filename).replace('/','%2F') + '" />'
  1091. else:
  1092. return render_template('index.html', logo = data['name'], title = '업로드 오류', data = '파일 명에 ./\*<>|:? 들은 불가능 합니다.')
  1093. else:
  1094. return render_template('index.html', logo = data['name'], title = '업로드 오류', data = 'jpg gif jpeg png만 가능 합니다.')
  1095. else:
  1096. ip = getip(request)
  1097. ban = getban(ip)
  1098. if(ban == 1):
  1099. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1100. else:
  1101. return render_template('index.html', logo = data['name'], title = '업로드', tn = 21, number = data['upload'])
  1102. @app.route('/image/<path:name>')
  1103. def image(name = None):
  1104. if(os.path.exists(os.path.join('image', name))):
  1105. return send_file(os.path.join('image', name), mimetype='image')
  1106. else:
  1107. return render_template('index.html', logo = data['name'], data = '이미지 없음.', title = '이미지 보기')
  1108. @app.route('/')
  1109. @app.route('/w/')
  1110. def redirect():
  1111. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1112. @app.route('/recentchanges')
  1113. def recentchanges():
  1114. i = 0
  1115. div = '<div>'
  1116. curs.execute("select * from history order by date desc limit 50")
  1117. rows = curs.fetchall()
  1118. if(rows):
  1119. admin = admincheck()
  1120. while True:
  1121. try:
  1122. a = rows[i]
  1123. except:
  1124. div = div + '</div>'
  1125. break
  1126. if(rows[i]['send']):
  1127. send = rows[i]['send']
  1128. send = re.sub('<a href="\/w\/(?P<in>[^"]*)">(?P<out>[^&]*)<\/a>', '<a href="/w/\g<in>">\g<out></a>', send)
  1129. else:
  1130. send = '<br>'
  1131. title = rows[i]['title']
  1132. title = re.sub('<', '&lt;', title)
  1133. title = re.sub('>', '&gt;', title)
  1134. m = re.search("\+", rows[i]['leng'])
  1135. n = re.search("\-", rows[i]['leng'])
  1136. if(m):
  1137. leng = '<span style="color:green;">' + rows[i]['leng'] + '</span>'
  1138. elif(n):
  1139. leng = '<span style="color:red;">' + rows[i]['leng'] + '</span>'
  1140. else:
  1141. leng = '<span style="color:gray;">' + rows[i]['leng'] + '</span>'
  1142. if(admin == 1):
  1143. curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1144. row = curs.fetchall()
  1145. if(row):
  1146. if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'):
  1147. ban = ''
  1148. else:
  1149. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1150. row = curs.fetchall()
  1151. if(row):
  1152. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1153. else:
  1154. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1155. else:
  1156. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1157. row = curs.fetchall()
  1158. if(row):
  1159. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1160. else:
  1161. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1162. else:
  1163. ban = ''
  1164. if(re.search('\.', rows[i]['ip'])):
  1165. ip = rows[i]['ip']
  1166. else:
  1167. curs.execute("select * from data where title = '사용자:" + pymysql.escape_string(rows[i]['ip']) + "'")
  1168. row = curs.fetchall()
  1169. if(row):
  1170. ip = '<a href="/w/' + parse.quote('사용자:' + rows[i]['ip']).replace('/','%2F') + '">' + rows[i]['ip'] + '</a>'
  1171. else:
  1172. ip = '<a class="not_thing" href="/w/' + parse.quote('사용자:' + rows[i]['ip']).replace('/','%2F') + '">' + rows[i]['ip'] + '</a>'
  1173. if((int(rows[i]['id']) - 1) == 0):
  1174. revert = ''
  1175. else:
  1176. revert = '<a href="/revert/' + parse.quote(rows[i]['title']).replace('/','%2F') + '/r/' + str(int(rows[i]['id']) - 1) + '">(되돌리기)</a>'
  1177. 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>'
  1178. i = i + 1
  1179. return render_template('index.html', logo = data['name'], rows = div, tn = 3, title = '최근 변경내역')
  1180. else:
  1181. return render_template('index.html', logo = data['name'], rows = '', tn = 3, title = '최근 변경내역')
  1182. @app.route('/record/<path:name>/n/<int:number>')
  1183. def record(name = None, number = None):
  1184. v = number * 50
  1185. i = v - 50
  1186. div = '<div>'
  1187. curs.execute("select * from history where ip = '" + pymysql.escape_string(name) + "' order by date desc")
  1188. rows = curs.fetchall()
  1189. if(rows):
  1190. admin = admincheck()
  1191. while True:
  1192. try:
  1193. a = rows[i]
  1194. except:
  1195. div = div + '</div>'
  1196. if(number != 1):
  1197. div = div + '<br><a href="/record/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number - 1) + '">(이전)'
  1198. break
  1199. if(rows[i]['send']):
  1200. send = rows[i]['send']
  1201. send = re.sub('<a href="\/w\/(?P<in>[^"]*)">(?P<out>[^&]*)<\/a>', '<a href="/w/\g<in>">\g<out></a>', send)
  1202. else:
  1203. send = '<br>'
  1204. title = rows[i]['title']
  1205. title = re.sub('<', '&lt;', title)
  1206. title = re.sub('>', '&gt;', title)
  1207. m = re.search("\+", rows[i]['leng'])
  1208. n = re.search("\-", rows[i]['leng'])
  1209. if(m):
  1210. leng = '<span style="color:green;">' + rows[i]['leng'] + '</span>'
  1211. elif(n):
  1212. leng = '<span style="color:red;">' + rows[i]['leng'] + '</span>'
  1213. else:
  1214. leng = '<span style="color:gray;">' + rows[i]['leng'] + '</span>'
  1215. if(admin == 1):
  1216. curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1217. row = curs.fetchall()
  1218. if(row):
  1219. if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'):
  1220. ip = rows[i]['ip']
  1221. else:
  1222. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1223. row = curs.fetchall()
  1224. if(row):
  1225. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1226. else:
  1227. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1228. else:
  1229. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1230. row = curs.fetchall()
  1231. if(row):
  1232. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1233. else:
  1234. ip = rows[i]['ip'] + ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1235. else:
  1236. ip = rows[i]['ip']
  1237. if((int(rows[i]['id']) - 1) == 0):
  1238. revert = ''
  1239. else:
  1240. revert = '<a href="/revert/' + parse.quote(rows[i]['title']).replace('/','%2F') + '/r/' + str(int(rows[i]['id']) - 1) + '">(되돌리기)</a>'
  1241. 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>'
  1242. if(i == v):
  1243. div = div + '</div>'
  1244. if(number == 1):
  1245. div = div + '<br><a href="/record/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number + 1) + '">(다음)'
  1246. else:
  1247. 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) + '">(다음)'
  1248. break
  1249. else:
  1250. i = i + 1
  1251. return render_template('index.html', logo = data['name'], rows = div, tn = 3, title = '유저 기록')
  1252. else:
  1253. return render_template('index.html', logo = data['name'], rows = '', tn = 3, title = '유저 기록')
  1254. @app.route('/userlog/n/<int:number>')
  1255. def userlog(number = None):
  1256. v = number * 50
  1257. i = v - 50
  1258. div = ''
  1259. curs.execute("select * from user")
  1260. rows = curs.fetchall()
  1261. if(rows):
  1262. admin = admincheck()
  1263. while True:
  1264. try:
  1265. a = rows[i]
  1266. except:
  1267. if(number != 1):
  1268. div = div + '<br><a href="/userlog/n/' + str(number - 1) + '">(이전)'
  1269. break
  1270. if(admin == 1):
  1271. curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['id']) + "'")
  1272. row = curs.fetchall()
  1273. if(row):
  1274. if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'):
  1275. ip = rows[i]['id']
  1276. else:
  1277. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['id']) + "'")
  1278. row = curs.fetchall()
  1279. if(row):
  1280. ip = rows[i]['id'] + ' <a href="/ban/' + parse.quote(rows[i]['id']).replace('/','%2F') + '">(해제)</a>'
  1281. else:
  1282. ip = rows[i]['id'] + ' <a href="/ban/' + parse.quote(rows[i]['id']).replace('/','%2F') + '">(차단)</a>'
  1283. else:
  1284. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['id']) + "'")
  1285. row = curs.fetchall()
  1286. if(row):
  1287. ip = rows[i]['id'] + ' <a href="/ban/' + parse.quote(rows[i]['id']).replace('/','%2F') + '">(해제)</a>'
  1288. else:
  1289. ip = rows[i]['id'] + ' <a href="/ban/' + parse.quote(rows[i]['id']).replace('/','%2F') + '">(차단)</a>'
  1290. else:
  1291. ip = rows[i]['id']
  1292. div = div + '<li>' + rows[i]['id'] + '</li>'
  1293. if(i == v):
  1294. if(number == 1):
  1295. div = div + '<br><a href="/userlog/n/' + str(number + 1) + '">(다음)'
  1296. else:
  1297. div = div + '<br><a href="/userlog/n/' + str(number - 1) + '">(이전) <a href="/userlog/n/' + str(number + 1) + '">(다음)'
  1298. break
  1299. else:
  1300. i = i + 1
  1301. return render_template('index.html', logo = data['name'], data = div, title = '유저 가입 기록')
  1302. else:
  1303. return render_template('index.html', logo = data['name'], data = '', title = '유저 가입 기록')
  1304. @app.route('/xref/<path:name>/n/<int:number>')
  1305. def xref(name = None, number = None):
  1306. v = number * 50
  1307. i = v - 50
  1308. div = ''
  1309. curs.execute("select * from back where title = '" + pymysql.escape_string(name) + "' order by link asc")
  1310. rows = curs.fetchall()
  1311. if(rows):
  1312. while True:
  1313. try:
  1314. a = rows[i]
  1315. except:
  1316. if(number != 1):
  1317. div = div + '<br><a href="/xref/n/' + str(number - 1) + '">(이전)'
  1318. break
  1319. curs.execute("select * from data where title = '" + pymysql.escape_string(rows[i]['link']) + "'")
  1320. row = curs.fetchall()
  1321. if(row):
  1322. aa = row[0]['data']
  1323. aa = re.sub("(?P<in>\[include\((?P<out>(?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\])", "\g<in>\n\n[[\g<out>]]\n\n", aa)
  1324. aa = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', '[[\g<in>]]', aa)
  1325. aa = namumark('', aa)
  1326. if(re.search("<a(?: class=\"not_thing\")? href=\"\/w\/" + parse.quote(name).replace('/','%2F') + "(?:\#[^\"]*)?\">([^<]*)<\/a>", aa)):
  1327. div = div + '<li><a href="/w/' + parse.quote(rows[i]['link']).replace('/','%2F') + '">' + rows[i]['link'] + '</a>'
  1328. if(rows[i]['type']):
  1329. div = div + ' (' + rows[i]['type'] + ')</li>'
  1330. else:
  1331. div = div + '</li>'
  1332. if(i == v):
  1333. if(number == 1):
  1334. div = div + '<br><a href="/xref/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number + 1) + '">(다음)'
  1335. else:
  1336. div = div + '<br><a href="/xref/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number - 1) + '">(이전) <a href="/userlog/n/' + str(number + 1) + '">(다음)'
  1337. break
  1338. else:
  1339. i = i + 1
  1340. else:
  1341. curs.execute("delete from back where title = '" + pymysql.escape_string(rows[i]['link']) + "' and link = '" + pymysql.escape_string(name) + "'")
  1342. conn.commit()
  1343. i = i + 1
  1344. v = v + 1
  1345. else:
  1346. curs.execute("delete from back where title = '" + pymysql.escape_string(rows[i]['link']) + "' and link = '" + pymysql.escape_string(name) + "'")
  1347. conn.commit()
  1348. i = i + 1
  1349. v = v + 1
  1350. return render_template('index.html', logo = data['name'], data = div, title = name, plus = '(역링크)')
  1351. else:
  1352. return render_template('index.html', logo = data['name'], data = '', title = name, plus = '(역링크)')
  1353. @app.route('/recentdiscuss')
  1354. def recentdiscuss():
  1355. i = 0
  1356. div = '<div>'
  1357. curs.execute("select * from rd order by date desc limit 50")
  1358. rows = curs.fetchall()
  1359. if(rows):
  1360. while True:
  1361. try:
  1362. a = rows[i]
  1363. except:
  1364. div = div + '</div>'
  1365. break
  1366. title = rows[i]['title']
  1367. title = re.sub('<', '&lt;', title)
  1368. title = re.sub('>', '&gt;', title)
  1369. sub = rows[i]['sub']
  1370. sub = re.sub('<', '&lt;', sub)
  1371. sub = re.sub('>', '&gt;', sub)
  1372. 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>'
  1373. i = i + 1
  1374. return render_template('index.html', logo = data['name'], rows = div, tn = 12, title = '최근 토론내역')
  1375. else:
  1376. return render_template('index.html', logo = data['name'], rows = '', tn = 12, title = '최근 토론내역')
  1377. @app.route('/blocklog/n/<int:number>')
  1378. def blocklog(number = None):
  1379. v = number * 50
  1380. i = v - 50
  1381. div = '<div>'
  1382. curs.execute("select * from rb order by today")
  1383. rows = curs.fetchall()
  1384. if(rows):
  1385. while True:
  1386. try:
  1387. a = rows[i]
  1388. except:
  1389. div = div + '</div>'
  1390. if(number != 1):
  1391. div = div + '<br><a href="/blocklog/n/' + str(number - 1) + '">(이전)'
  1392. break
  1393. why = rows[i]['why']
  1394. why = re.sub('<', '&lt;', why)
  1395. why = re.sub('>', '&gt;', why)
  1396. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))$", rows[i]['block'])
  1397. if(b):
  1398. ip = rows[i]['block'] + ' (대역)'
  1399. else:
  1400. ip = rows[i]['block']
  1401. 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>'
  1402. if(i == v):
  1403. div = div + '</div>'
  1404. if(number == 1):
  1405. div = div + '<br><a href="/blocklog/n/' + str(number + 1) + '">(다음)'
  1406. else:
  1407. div = div + '<br><a href="/blocklog/n/' + str(number - 1) + '">(이전) <a href="/blocklog/n/' + str(number + 1) + '">(다음)'
  1408. break
  1409. else:
  1410. i = i + 1
  1411. return render_template('index.html', logo = data['name'], rows = div, tn = 20, title = '유저 차단 기록')
  1412. else:
  1413. return render_template('index.html', logo = data['name'], rows = '', tn = 20, title = '유저 차단 기록')
  1414. @app.route('/history/<path:name>/n/<int:number>', methods=['POST', 'GET'])
  1415. def gethistory(name = None, number = None):
  1416. if(request.method == 'POST'):
  1417. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '/r/' + request.form["b"] + '/diff/' + request.form["a"] + '" />'
  1418. else:
  1419. select = ''
  1420. v = number * 50
  1421. i = v - 50
  1422. div = '<div>'
  1423. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' order by id+0 desc")
  1424. rows = curs.fetchall()
  1425. if(rows):
  1426. admin = admincheck()
  1427. while True:
  1428. try:
  1429. a = rows[i]
  1430. except:
  1431. div = div + '</div>'
  1432. if(number != 1):
  1433. div = div + '<br><a href="/history/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number - 1) + '">(이전)'
  1434. break
  1435. select = '<option value="' + str(i + 1) + '">' + str(i + 1) + '</option>' + select
  1436. if(rows[i]['send']):
  1437. send = rows[i]['send']
  1438. send = re.sub('<a href="\/w\/(?P<in>[^"]*)">(?P<out>[^&]*)<\/a>', '<a href="/w/\g<in>">\g<out></a>', send)
  1439. else:
  1440. send = '<br>'
  1441. m = re.search("\+", rows[i]['leng'])
  1442. n = re.search("\-", rows[i]['leng'])
  1443. if(m):
  1444. leng = '<span style="color:green;">' + rows[i]['leng'] + '</span>'
  1445. elif(n):
  1446. leng = '<span style="color:red;">' + rows[i]['leng'] + '</span>'
  1447. else:
  1448. leng = '<span style="color:gray;">' + rows[i]['leng'] + '</span>'
  1449. if(admin == 1):
  1450. curs.execute("select * from user where id = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1451. row = curs.fetchall()
  1452. if(row):
  1453. if(row[0]['acl'] == 'owner' or row[0]['acl'] == 'admin'):
  1454. ban = ''
  1455. else:
  1456. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1457. row = curs.fetchall()
  1458. if(row):
  1459. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1460. else:
  1461. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1462. else:
  1463. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  1464. row = curs.fetchall()
  1465. if(row):
  1466. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>'
  1467. else:
  1468. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>'
  1469. else:
  1470. ban = ''
  1471. if(re.search("\.", rows[i]["ip"])):
  1472. ip = rows[i]["ip"]
  1473. else:
  1474. curs.execute("select * from data where title = '사용자:" + pymysql.escape_string(rows[i]['ip']) + "'")
  1475. row = curs.fetchall()
  1476. if(row):
  1477. ip = '<a href="/w/' + parse.quote('사용자:' + rows[i]['ip']).replace('/','%2F') + '">' + rows[i]['ip'] + '</a>'
  1478. else:
  1479. ip = '<a class="not_thing" href="/w/' + parse.quote('사용자:' + rows[i]['ip']).replace('/','%2F') + '">' + rows[i]['ip'] + '</a>'
  1480. 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>'
  1481. if(i == v):
  1482. div = div + '</div>'
  1483. if(number == 1):
  1484. div = div + '<br><a href="/history/' + parse.quote(name).replace('/','%2F') + '/n/' + str(number + 1) + '">(다음)'
  1485. else:
  1486. 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) + '">(다음)'
  1487. break
  1488. else:
  1489. i = i + 1
  1490. return render_template('index.html', logo = data['name'], rows = div, tn = 5, title = name, page = parse.quote(name).replace('/','%2F'), select = select)
  1491. else:
  1492. return render_template('index.html', logo = data['name'], rows = '', tn = 5, title = name, page = parse.quote(name).replace('/','%2F'), select = select)
  1493. @app.route('/search', methods=['POST', 'GET'])
  1494. def search():
  1495. if(request.method == 'POST'):
  1496. curs.execute("select * from data where title = '" + pymysql.escape_string(request.form["search"]) + "'")
  1497. rows = curs.fetchall()
  1498. if(rows):
  1499. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '" />'
  1500. else:
  1501. curs.execute("select * from data where title like '%" + pymysql.escape_string(request.form["search"]) + "%'")
  1502. rows = curs.fetchall()
  1503. div = ''
  1504. if(rows):
  1505. i = 0
  1506. div = div + '<li>문서가 없습니다. <a href="/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '">바로가기</a></li><br>'
  1507. while True:
  1508. try:
  1509. div = div + '<li><a href="/w/' + parse.quote(rows[i]['title']).replace('/','%2F') + '">' + rows[i]['title'] + '</a></li>'
  1510. except:
  1511. break
  1512. i = i + 1
  1513. else:
  1514. return div + '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '" />'
  1515. return render_template('index.html', logo = data['name'], data = div, title = '검색')
  1516. else:
  1517. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  1518. @app.route('/w/<path:name>')
  1519. def w(name = None):
  1520. i = 0
  1521. curs.execute("select * from rd where title = '" + pymysql.escape_string(name) + "' order by date asc")
  1522. rows = curs.fetchall()
  1523. while True:
  1524. try:
  1525. a = rows[i]
  1526. except:
  1527. topic = ""
  1528. break
  1529. curs.execute("select * from stop where title = '" + pymysql.escape_string(rows[i]['title']) + "' and sub = '" + pymysql.escape_string(rows[i]['sub']) + "' and close = 'O'")
  1530. row = curs.fetchall()
  1531. if(not row):
  1532. topic = "open"
  1533. break
  1534. else:
  1535. i = i + 1
  1536. acl = ''
  1537. m = re.search("^(.*)\/(.*)$", name)
  1538. if(m):
  1539. g = m.groups()
  1540. uppage = g[0]
  1541. style = ""
  1542. else:
  1543. uppage = ""
  1544. style = "display:none;"
  1545. if(re.search("^분류:", name)):
  1546. curs.execute("select * from cat where title = '" + pymysql.escape_string(name) + "' order by cat asc")
  1547. rows = curs.fetchall()
  1548. if(rows):
  1549. div = ''
  1550. i = 0
  1551. while True:
  1552. try:
  1553. a = rows[i]
  1554. except:
  1555. break
  1556. curs.execute("select * from data where title = '" + pymysql.escape_string(rows[i]['cat']) + "'")
  1557. row = curs.fetchall()
  1558. if(row):
  1559. aa = row[0]['data']
  1560. aa = namumark('', aa)
  1561. bb = re.search('<div style="width:100%;border: 1px solid #777;padding: 5px;margin-top: 1em;">분류:((?:(?!<\/div>).)*)<\/div>', aa)
  1562. if(bb):
  1563. cc = bb.groups()
  1564. mm = re.search("^분류:(.*)", name)
  1565. if(mm):
  1566. ee = mm.groups()
  1567. if(re.search("<a href=\"\/w\/" + parse.quote(name).replace('/','%2F') + "\">" + ee[0] + "<\/a>", cc[0])):
  1568. div = div + '<li><a href="/w/' + parse.quote(rows[i]['cat']).replace('/','%2F') + '">' + rows[i]['cat'] + '</a></li>'
  1569. i = i + 1
  1570. else:
  1571. curs.execute("delete from cat where title = '" + pymysql.escape_string(rows[i]['cat']) + "' and cat = '" + pymysql.escape_string(name) + "'")
  1572. conn.commit()
  1573. i = i + 1
  1574. else:
  1575. curs.execute("delete from cat where title = '" + pymysql.escape_string(rows[i]['cat']) + "' and cat = '" + pymysql.escape_string(name) + "'")
  1576. conn.commit()
  1577. i = i + 1
  1578. else:
  1579. curs.execute("delete from cat where title = '" + pymysql.escape_string(rows[i]['cat']) + "' and cat = '" + pymysql.escape_string(name) + "'")
  1580. conn.commit()
  1581. i = i + 1
  1582. else:
  1583. curs.execute("delete from cat where title = '" + pymysql.escape_string(rows[i]['cat']) + "' and cat = '" + pymysql.escape_string(name) + "'")
  1584. conn.commit()
  1585. i = i + 1
  1586. div = '<h2>분류</h2>' + div
  1587. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1588. bb = curs.fetchall()
  1589. if(bb):
  1590. if(bb[0]['acl'] == 'admin'):
  1591. acl = '(관리자)'
  1592. elif(bb[0]['acl'] == 'user'):
  1593. acl = '(유저)'
  1594. else:
  1595. if(not acl):
  1596. acl = ''
  1597. enddata = namumark(name, bb[0]['data'])
  1598. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1599. if(m):
  1600. result = m.groups()
  1601. left = result[0]
  1602. else:
  1603. left = ''
  1604. 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)
  1605. else:
  1606. 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)
  1607. else:
  1608. 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)
  1609. else:
  1610. m = re.search("^사용자:(.*)", name)
  1611. if(m):
  1612. g = m.groups()
  1613. curs.execute("select * from user where id = '" + pymysql.escape_string(g[0]) + "'")
  1614. rows = curs.fetchall()
  1615. if(rows):
  1616. if(rows[0]['acl'] == 'owner'):
  1617. acl = '(소유자)'
  1618. elif(rows[0]['acl'] == 'admin'):
  1619. acl = '(관리자)'
  1620. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1621. rows = curs.fetchall()
  1622. if(rows):
  1623. if(rows[0]['acl'] == 'admin'):
  1624. acl = '(관리자)'
  1625. elif(rows[0]['acl'] == 'user'):
  1626. acl = '(유저)'
  1627. else:
  1628. if(not acl):
  1629. acl = ''
  1630. enddata = namumark(name, rows[0]['data'])
  1631. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1632. if(m):
  1633. result = m.groups()
  1634. left = result[0]
  1635. else:
  1636. left = ''
  1637. 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)
  1638. else:
  1639. 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)
  1640. @app.route('/w/<path:name>/redirect/<redirect>')
  1641. def redirectw(name = None, redirect = None):
  1642. i = 0
  1643. curs.execute("select * from rd where title = '" + pymysql.escape_string(name) + "' order by date asc")
  1644. rows = curs.fetchall()
  1645. while True:
  1646. try:
  1647. a = rows[i]
  1648. except:
  1649. topic = ""
  1650. break
  1651. curs.execute("select * from stop where title = '" + pymysql.escape_string(rows[i]['title']) + "' and sub = '" + pymysql.escape_string(rows[i]['sub']) + "' and close = 'O'")
  1652. row = curs.fetchall()
  1653. if(not row):
  1654. topic = "open"
  1655. break
  1656. else:
  1657. i = i + 1
  1658. m = re.search("^(.*)\/(.*)$", name)
  1659. if(m):
  1660. g = m.groups()
  1661. uppage = g[0]
  1662. style = ""
  1663. else:
  1664. uppage = ""
  1665. style = "display:none;"
  1666. 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)
  1667. @app.route('/w/<path:name>/r/<number>')
  1668. def rew(name = None, number = None):
  1669. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1670. rows = curs.fetchall()
  1671. if(rows):
  1672. enddata = namumark(name, rows[0]['data'])
  1673. m = re.search('<div id="toc">((?:(?!\/div>).)*)<\/div>', enddata)
  1674. if(m):
  1675. result = m.groups()
  1676. left = result[0]
  1677. else:
  1678. left = ''
  1679. 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)
  1680. else:
  1681. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 6)
  1682. @app.route('/w/<path:name>/raw/<number>')
  1683. def reraw(name = None, number = None):
  1684. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1685. rows = curs.fetchall()
  1686. if(rows):
  1687. enddata = re.sub('<', '&lt;', rows[0]['data'])
  1688. enddata = re.sub('>', '&gt;', enddata)
  1689. enddata = re.sub('"', '&quot;', enddata)
  1690. enddata = re.sub("\n", '<br>', enddata)
  1691. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'])
  1692. else:
  1693. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'])
  1694. @app.route('/raw/<path:name>')
  1695. def raw(name = None):
  1696. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1697. rows = curs.fetchall()
  1698. if(rows):
  1699. enddata = re.sub('<', '&lt;', rows[0]['data'])
  1700. enddata = re.sub('>', '&gt;', enddata)
  1701. enddata = re.sub('"', '&quot;', enddata)
  1702. enddata = re.sub("\n", '<br>', enddata)
  1703. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = enddata, license = data['license'], tn = 7)
  1704. else:
  1705. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '문서 없음', license = data['license'], tn = 7)
  1706. @app.route('/revert/<path:name>/r/<number>', methods=['POST', 'GET'])
  1707. def revert(name = None, number = None):
  1708. if(request.method == 'POST'):
  1709. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1710. rows = curs.fetchall()
  1711. if(rows):
  1712. ip = getip(request)
  1713. can = getcan(ip, name)
  1714. if(can == 1):
  1715. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1716. else:
  1717. today = getnow()
  1718. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1719. row = curs.fetchall()
  1720. if(row):
  1721. leng = getleng(len(row[0]['data']), len(rows[0]['data']))
  1722. curs.execute("update data set data = '" + pymysql.escape_string(rows[0]['data']) + "' where title = '" + pymysql.escape_string(name) + "'")
  1723. conn.commit()
  1724. else:
  1725. leng = '+' + str(len(rows[0]['data']))
  1726. curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(rows[0]['data']) + "', '')")
  1727. conn.commit()
  1728. history(name, rows[0]['data'], today, ip, '문서를 ' + number + '판으로 되돌렸습니다.', leng)
  1729. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1730. else:
  1731. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1732. else:
  1733. ip = getip(request)
  1734. can = getcan(ip, name)
  1735. if(can == 1):
  1736. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1737. else:
  1738. curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
  1739. rows = curs.fetchall()
  1740. if(rows):
  1741. 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 = '정말 되돌리시겠습니까?')
  1742. else:
  1743. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1744. @app.route('/edit/<path:name>', methods=['POST', 'GET'])
  1745. def edit(name = None):
  1746. if(request.method == 'POST'):
  1747. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1748. rows = curs.fetchall()
  1749. m = re.search('(?:[^A-Za-zㄱ-힣0-9 ])', request.form["send"])
  1750. if(m):
  1751. return render_template('index.html', title = '편집 오류', logo = data['name'], data = '편집 내용 기록에는 한글과 영어와 숫자, 공백만 허용 됩니다.')
  1752. else:
  1753. today = getnow()
  1754. content = re.sub("\[date\(now\)\]", today, request.form["content"])
  1755. if(rows):
  1756. if(rows[0]['data'] == content):
  1757. return render_template('index.html', title = '편집 오류', logo = data['name'], data = '내용이 원래 문서와 동일 합니다.')
  1758. else:
  1759. ip = getip(request)
  1760. can = getcan(ip, name)
  1761. if(can == 1):
  1762. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1763. else:
  1764. leng = getleng(len(rows[0]['data']), len(content))
  1765. history(name, content, today, ip, request.form["send"], leng)
  1766. curs.execute("update data set data = '" + pymysql.escape_string(content) + "' where title = '" + pymysql.escape_string(name) + "'")
  1767. conn.commit()
  1768. else:
  1769. ip = getip(request)
  1770. can = getcan(ip, name)
  1771. if(can == 1):
  1772. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1773. else:
  1774. leng = '+' + str(len(content))
  1775. history(name, content, today, ip, request.form["send"], leng)
  1776. curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(content) + "', '')")
  1777. conn.commit()
  1778. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1779. else:
  1780. ip = getip(request)
  1781. can = getcan(ip, name)
  1782. if(can == 1):
  1783. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1784. else:
  1785. curs.execute("select * from data where title = '" + pymysql.escape_string(data["help"]) + "'")
  1786. rows = curs.fetchall()
  1787. if(rows):
  1788. newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', ' * \g<in> 문서로 넘겨주기', rows[0]["data"])
  1789. left = namumark(name, newdata)
  1790. else:
  1791. left = ''
  1792. if(re.search('\.', ip)):
  1793. notice = '비 로그인 상태 입니다. 비 로그인으로 편집시 아이피가 역사에 기록 됩니다. 편집 시 동의 함으로 간주 됩니다.'
  1794. else:
  1795. notice = ''
  1796. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1797. rows = curs.fetchall()
  1798. if(rows):
  1799. 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)
  1800. else:
  1801. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), data = '', tn = 2, notice = notice, left = left)
  1802. @app.route('/preview/<path:name>', methods=['POST'])
  1803. def preview(name = None):
  1804. ip = getip(request)
  1805. can = getcan(ip, name)
  1806. if(can == 1):
  1807. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1808. else:
  1809. if(re.search('\.', ip)):
  1810. notice = '비 로그인 상태 입니다. 비 로그인으로 편집시 아이피가 역사에 기록 됩니다. 편집 시 동의 함으로 간주 됩니다.'
  1811. else:
  1812. notice = ''
  1813. newdata = request.form["content"]
  1814. newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', ' * \g<in> 문서로 넘겨주기', newdata)
  1815. enddata = namumark(name, newdata)
  1816. curs.execute("select * from data where title = '" + pymysql.escape_string(data["help"]) + "'")
  1817. rows = curs.fetchall()
  1818. if(rows):
  1819. newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', ' * \g<in> 문서로 넘겨주기', rows[0]["data"])
  1820. left = namumark(name, newdata)
  1821. else:
  1822. left = ''
  1823. 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)
  1824. @app.route('/delete/<path:name>', methods=['POST', 'GET'])
  1825. def delete(name = None):
  1826. if(request.method == 'POST'):
  1827. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1828. rows = curs.fetchall()
  1829. if(rows):
  1830. ip = getip(request)
  1831. can = getcan(ip, name)
  1832. if(can == 1):
  1833. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1834. else:
  1835. today = getnow()
  1836. leng = '-' + str(len(rows[0]['data']))
  1837. history(name, '', today, ip, '문서를 삭제 했습니다.', leng)
  1838. curs.execute("delete from data where title = '" + pymysql.escape_string(name) + "'")
  1839. conn.commit()
  1840. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1841. else:
  1842. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1843. else:
  1844. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1845. rows = curs.fetchall()
  1846. if(rows):
  1847. ip = getip(request)
  1848. can = getcan(ip, name)
  1849. if(can == 1):
  1850. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1851. else:
  1852. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), tn = 8, plus = '정말 삭제 하시겠습니까?')
  1853. else:
  1854. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  1855. @app.route('/move/<path:name>', methods=['POST', 'GET'])
  1856. def move(name = None):
  1857. if(request.method == 'POST'):
  1858. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  1859. rows = curs.fetchall()
  1860. if(rows):
  1861. ip = getip(request)
  1862. can = getcan(ip, name)
  1863. if(can == 1):
  1864. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1865. else:
  1866. today = getnow()
  1867. leng = '0'
  1868. curs.execute("select * from history where title = '" + pymysql.escape_string(request.form["title"]) + "'")
  1869. row = curs.fetchall()
  1870. if(row):
  1871. return render_template('index.html', title = '이동 오류', logo = data['name'], data = '이동 하려는 곳에 문서가 이미 있습니다.')
  1872. else:
  1873. 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)
  1874. curs.execute("update data set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1875. curs.execute("update history set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1876. conn.commit()
  1877. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["title"]).replace('/','%2F') + '" />'
  1878. else:
  1879. ip = getip(request)
  1880. can = getcan(ip, name)
  1881. if(can == 1):
  1882. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1883. else:
  1884. today = getnow()
  1885. leng = '0'
  1886. curs.execute("select * from history where title = '" + pymysql.escape_string(request.form["title"]) + "'")
  1887. row = curs.fetchall()
  1888. if(row):
  1889. return render_template('index.html', title = '이동 오류', logo = data['name'], data = '이동 하려는 곳에 문서가 이미 있습니다.')
  1890. else:
  1891. 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)
  1892. curs.execute("update history set title = '" + pymysql.escape_string(request.form["title"]) + "' where title = '" + pymysql.escape_string(name) + "'")
  1893. conn.commit()
  1894. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["title"]).replace('/','%2F') + '" />'
  1895. else:
  1896. ip = getip(request)
  1897. can = getcan(ip, name)
  1898. if(can == 1):
  1899. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  1900. else:
  1901. return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name).replace('/','%2F'), tn = 9, plus = '정말 이동 하시겠습니까?')
  1902. @app.route('/setup')
  1903. def setup():
  1904. curs.execute("create table if not exists data(title text not null, data longtext not null, acl text not null)")
  1905. 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)")
  1906. curs.execute("create table if not exists rd(title text not null, sub text not null, date text not null)")
  1907. curs.execute("create table if not exists user(id text not null, pw text not null, acl text not null)")
  1908. curs.execute("create table if not exists ban(block text not null, end text not null, why text not null, band text not null)")
  1909. 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)")
  1910. curs.execute("create table if not exists stop(title text not null, sub text not null, close text not null)")
  1911. 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)")
  1912. curs.execute("create table if not exists login(user text not null, ip text not null, today text not null)")
  1913. curs.execute("create table if not exists back(title text not null, link text not null, type text not null)")
  1914. curs.execute("create table if not exists cat(title text not null, cat text not null)")
  1915. return render_template('index.html', title = '설치 완료', logo = data['name'], data = '문제 없었음')
  1916. @app.route('/other')
  1917. def other():
  1918. 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>')
  1919. @app.route('/manager')
  1920. def manager():
  1921. 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>')
  1922. @app.route('/acl', methods=['POST', 'GET'])
  1923. def aclget():
  1924. if(request.method == 'POST'):
  1925. return '<meta http-equiv="refresh" content="0;url=/acl/' + parse.quote(request.form["name"]).replace('/','%2F') + '" />'
  1926. else:
  1927. 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>')
  1928. @app.route('/check', methods=['POST', 'GET'])
  1929. def checkget():
  1930. if(request.method == 'POST'):
  1931. return '<meta http-equiv="refresh" content="0;url=/check/' + parse.quote(request.form["name"]).replace('/','%2F') + '" />'
  1932. else:
  1933. 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>')
  1934. @app.route('/banget', methods=['POST', 'GET'])
  1935. def hebanget():
  1936. if(request.method == 'POST'):
  1937. return '<meta http-equiv="refresh" content="0;url=/ban/' + parse.quote(request.form["name"]).replace('/','%2F') + '" />'
  1938. else:
  1939. 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>')
  1940. @app.route('/admin', methods=['POST', 'GET'])
  1941. def adminget():
  1942. if(request.method == 'POST'):
  1943. return '<meta http-equiv="refresh" content="0;url=/admin/' + parse.quote(request.form["name"]).replace('/','%2F') + '" />'
  1944. else:
  1945. 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>')
  1946. @app.route('/record', methods=['POST', 'GET'])
  1947. def recordget():
  1948. if(request.method == 'POST'):
  1949. return '<meta http-equiv="refresh" content="0;url=/record/' + parse.quote(request.form["name"]).replace('/','%2F') + '/n/1" />'
  1950. else:
  1951. 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>')
  1952. @app.route('/titleindex')
  1953. def titleindex():
  1954. i = 0
  1955. div = '<div>'
  1956. curs.execute("select * from data order by title asc")
  1957. rows = curs.fetchall()
  1958. if(rows):
  1959. while True:
  1960. try:
  1961. a = rows[i]
  1962. except:
  1963. div = div + '</div>'
  1964. break
  1965. div = div + '<li><a href="/w/' + parse.quote(rows[i]['title']).replace('/','%2F') + '">' + rows[i]['title'] + '</a></li>'
  1966. i = i + 1
  1967. return render_template('index.html', logo = data['name'], rows = div + '<br><span>이 위키에는 총 ' + str(i + 1) + '개의 문서가 있습니다.</span>', tn = 4, title = '모든 문서')
  1968. else:
  1969. return render_template('index.html', logo = data['name'], rows = '', tn = 4, title = '모든 문서')
  1970. @app.route('/topic/<path:name>', methods=['POST', 'GET'])
  1971. def topic(name = None):
  1972. if(request.method == 'POST'):
  1973. return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(request.form["topic"]).replace('/','%2F') + '" />'
  1974. else:
  1975. div = '<div>'
  1976. i = 0
  1977. j = 1
  1978. curs.execute("select * from rd where title = '" + pymysql.escape_string(name) + "' order by date asc")
  1979. rows = curs.fetchall()
  1980. while True:
  1981. try:
  1982. a = rows[i]
  1983. except:
  1984. div = div + '</div>'
  1985. break
  1986. 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")
  1987. aa = curs.fetchall()
  1988. indata = namumark(name, aa[0]['data'])
  1989. if(aa[0]['block'] == 'O'):
  1990. indata = '블라인드 되었습니다.'
  1991. block = 'style="background: gainsboro;"'
  1992. else:
  1993. block = ''
  1994. curs.execute("select * from stop where title = '" + pymysql.escape_string(rows[i]['title']) + "' and sub = '" + pymysql.escape_string(rows[i]['sub']) + "' and close = 'O'")
  1995. row = curs.fetchall()
  1996. if(not row):
  1997. 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>'
  1998. 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>'
  1999. j = j + 1
  2000. i = i + 1
  2001. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], plus = div, tn = 10, list = 1)
  2002. @app.route('/topic/<path:name>/close')
  2003. def topicstoplist(name = None):
  2004. if(request.method == 'POST'):
  2005. return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(request.form["topic"]).replace('/','%2F') + '" />'
  2006. else:
  2007. div = '<div>'
  2008. i = 0
  2009. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and close = 'O' order by sub asc")
  2010. rows = curs.fetchall()
  2011. while True:
  2012. try:
  2013. a = rows[i]
  2014. except:
  2015. div = div + '</div>'
  2016. break
  2017. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(rows[i]['sub']) + "' and id = '1'")
  2018. row = curs.fetchall()
  2019. if(row):
  2020. j = i + 1
  2021. indata = namumark(name, row[0]['data'])
  2022. if(row[0]['block'] == 'O'):
  2023. indata = '블라인드 되었습니다.'
  2024. block = 'style="background: gainsboro;"'
  2025. else:
  2026. block = ''
  2027. 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>'
  2028. 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>'
  2029. i = i + 1
  2030. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], plus = div, tn = 10)
  2031. @app.route('/topic/<path:name>/sub/<path:sub>', methods=['POST', 'GET'])
  2032. def sub(name = None, sub = None):
  2033. if(request.method == 'POST'):
  2034. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
  2035. rows = curs.fetchall()
  2036. if(rows):
  2037. number = int(rows[0]['id']) + 1
  2038. else:
  2039. number = 1
  2040. ip = getip(request)
  2041. ban = getdiscuss(ip, name, sub)
  2042. if(ban == 1):
  2043. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2044. else:
  2045. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2046. rows = curs.fetchall()
  2047. if(rows):
  2048. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  2049. ip = ip + ' - Admin'
  2050. today = getnow()
  2051. discuss(name, sub, today)
  2052. aa = request.form["content"]
  2053. aa = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", "[br]", aa)
  2054. 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 + "', '')")
  2055. conn.commit()
  2056. return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '" />'
  2057. else:
  2058. ip = getip(request)
  2059. ban = getdiscuss(ip, name, sub)
  2060. admin = admincheck()
  2061. if(admin == 1):
  2062. 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>'
  2063. else:
  2064. div = '<div>'
  2065. i = 0
  2066. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 asc")
  2067. rows = curs.fetchall()
  2068. while True:
  2069. try:
  2070. a = rows[i]
  2071. except:
  2072. div = div + '</div>'
  2073. break
  2074. if(i == 0):
  2075. start = rows[i]['ip']
  2076. indata = namumark(name, rows[i]['data'])
  2077. if(rows[i]['block'] == 'O'):
  2078. indata = '블라인드 되었습니다.'
  2079. block = 'style="background: gainsboro;"'
  2080. else:
  2081. block = ''
  2082. m = re.search("([^-]*)\s\-\s(Close|Reopen|Stop|Restart)$", rows[i]['ip'])
  2083. if(m):
  2084. ban = ""
  2085. else:
  2086. if(admin == 1):
  2087. curs.execute("select * from ban where block = '" + pymysql.escape_string(rows[i]['ip']) + "'")
  2088. row = curs.fetchall()
  2089. if(rows[i]['block'] == 'O'):
  2090. isblock = ' <a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '/b/' + str(i + 1) + '">(해제)</a>'
  2091. else:
  2092. isblock = ' <a href="/topic/' + parse.quote(name).replace('/','%2F') + '/sub/' + parse.quote(sub).replace('/','%2F') + '/b/' + str(i + 1) + '">(블라인드)</a>'
  2093. n = re.search("\- (?:Admin)$", rows[i]['ip'])
  2094. if(n):
  2095. ban = isblock
  2096. else:
  2097. if(row):
  2098. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(해제)</a>' + isblock
  2099. else:
  2100. ban = ' <a href="/ban/' + parse.quote(rows[i]['ip']).replace('/','%2F') + '">(차단)</a>' + isblock
  2101. else:
  2102. ban = ""
  2103. m = re.search("([^-]*)\s\-\s(Close|Reopen|Stop|Restart|Admin)$", rows[i]['ip'])
  2104. if(m):
  2105. g = m.groups()
  2106. curs.execute("select * from data where title = '사용자:" + pymysql.escape_string(g[0]) + "'")
  2107. row = curs.fetchall()
  2108. if(row):
  2109. ip = '<a href="/w/' + parse.quote('사용자:' + g[0]).replace('/','%2F') + '">' + g[0] + '</a> - ' + g[1]
  2110. else:
  2111. ip = '<a class="not_thing" href="/w/' + parse.quote('사용자:' + g[0]).replace('/','%2F') + '">' + g[0] + '</a> - ' + g[1]
  2112. elif(re.search("\.", rows[i]["ip"])):
  2113. ip = rows[i]["ip"]
  2114. else:
  2115. curs.execute("select * from data where title = '사용자:" + pymysql.escape_string(rows[i]['ip']) + "'")
  2116. row = curs.fetchall()
  2117. if(row):
  2118. ip = '<a href="/w/' + parse.quote('사용자:' + rows[i]['ip']).replace('/','%2F') + '">' + rows[i]['ip'] + '</a>'
  2119. else:
  2120. ip = '<a class="not_thing" href="/w/' + parse.quote('사용자:' + rows[i]['ip']).replace('/','%2F') + '">' + rows[i]['ip'] + '</a>'
  2121. if(rows[i]['ip'] == start):
  2122. j = i + 1
  2123. 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>'
  2124. else:
  2125. j = i + 1
  2126. 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>'
  2127. i = i + 1
  2128. 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)
  2129. @app.route('/topic/<path:name>/sub/<path:sub>/b/<number>')
  2130. def blind(name = None, sub = None, number = None):
  2131. if(session.get('Now') == True):
  2132. ip = getip(request)
  2133. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2134. rows = curs.fetchall()
  2135. if(rows):
  2136. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  2137. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'")
  2138. row = curs.fetchall()
  2139. if(row):
  2140. if(row[0]['block'] == 'O'):
  2141. curs.execute("update topic set block = '' where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'")
  2142. else:
  2143. curs.execute("update topic set block = 'O' where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and id = '" + number + "'")
  2144. conn.commit()
  2145. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  2146. else:
  2147. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  2148. else:
  2149. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2150. else:
  2151. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  2152. else:
  2153. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  2154. @app.route('/topic/<path:name>/sub/<path:sub>/stop')
  2155. def topicstop(name = None, sub = None):
  2156. if(session.get('Now') == True):
  2157. ip = getip(request)
  2158. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2159. rows = curs.fetchall()
  2160. if(rows):
  2161. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  2162. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
  2163. row = curs.fetchall()
  2164. if(row):
  2165. today = getnow()
  2166. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = ''")
  2167. rows = curs.fetchall()
  2168. if(rows):
  2169. 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', '')")
  2170. curs.execute("delete from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = ''")
  2171. else:
  2172. 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', '')")
  2173. curs.execute("insert into stop (title, sub, close) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', '')")
  2174. conn.commit()
  2175. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  2176. else:
  2177. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  2178. else:
  2179. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2180. else:
  2181. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  2182. else:
  2183. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  2184. @app.route('/topic/<path:name>/sub/<path:sub>/close')
  2185. def topicclose(name = None, sub = None):
  2186. if(session.get('Now') == True):
  2187. ip = getip(request)
  2188. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2189. rows = curs.fetchall()
  2190. if(rows):
  2191. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  2192. curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
  2193. row = curs.fetchall()
  2194. if(row):
  2195. today = getnow()
  2196. curs.execute("select * from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'")
  2197. rows = curs.fetchall()
  2198. if(rows):
  2199. 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', '')")
  2200. curs.execute("delete from stop where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' and close = 'O'")
  2201. else:
  2202. 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', '')")
  2203. curs.execute("insert into stop (title, sub, close) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', 'O')")
  2204. conn.commit()
  2205. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  2206. else:
  2207. return '<meta http-equiv="refresh" content="0;url=/topic/' + name + '/sub/' + sub + '" />'
  2208. else:
  2209. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2210. else:
  2211. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  2212. else:
  2213. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  2214. @app.route('/login', methods=['POST', 'GET'])
  2215. def login():
  2216. if(request.method == 'POST'):
  2217. ip = getip(request)
  2218. ban = getban(ip)
  2219. if(ban == 1):
  2220. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2221. else:
  2222. curs.execute("select * from user where id = '" + pymysql.escape_string(request.form["id"]) + "'")
  2223. rows = curs.fetchall()
  2224. if(rows):
  2225. if(session.get('Now') == True):
  2226. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '이미 로그인 되어 있습니다.')
  2227. elif(bcrypt.checkpw(bytes(request.form["pw"], 'utf-8'), bytes(rows[0]['pw'], 'utf-8'))):
  2228. session['Now'] = True
  2229. session['DREAMER'] = request.form["id"]
  2230. curs.execute("insert into login (user, ip, today) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(ip) + "', '" + pymysql.escape_string(getnow()) + "')")
  2231. conn.commit()
  2232. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  2233. else:
  2234. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '비밀번호가 다릅니다.')
  2235. else:
  2236. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '없는 계정 입니다.')
  2237. else:
  2238. ip = getip(request)
  2239. ban = getban(ip)
  2240. if(ban == 1):
  2241. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2242. else:
  2243. if(session.get('Now') == True):
  2244. return render_template('index.html', title = '로그인 오류', logo = data['name'], data = '이미 로그인 되어 있습니다.')
  2245. else:
  2246. return render_template('index.html', title = '로그인', enter = '로그인', logo = data['name'], tn = 15)
  2247. @app.route('/change', methods=['POST', 'GET'])
  2248. def change():
  2249. if(request.method == 'POST'):
  2250. ip = getip(request)
  2251. ban = getban(ip)
  2252. if(ban == 1):
  2253. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2254. else:
  2255. curs.execute("select * from user where id = '" + pymysql.escape_string(request.form["id"]) + "'")
  2256. rows = curs.fetchall()
  2257. if(rows):
  2258. if(session.get('Now') == True):
  2259. return '<meta http-equiv="refresh" content="0;url=/logout" />'
  2260. elif(bcrypt.checkpw(bytes(request.form["pw"], 'utf-8'), bytes(rows[0]['pw'], 'utf-8'))):
  2261. hashed = bcrypt.hashpw(bytes(request.form["pw2"], 'utf-8'), bcrypt.gensalt())
  2262. curs.execute("update user set pw = '" + pymysql.escape_string(hashed.decode()) + "' where id = '" + pymysql.escape_string(request.form["id"]) + "'")
  2263. conn.commit()
  2264. return '<meta http-equiv="refresh" content="0;url=/login" />'
  2265. else:
  2266. return render_template('index.html', title = '변경 오류', logo = data['name'], data = '비밀번호가 다릅니다.')
  2267. else:
  2268. return render_template('index.html', title = '변경 오류', logo = data['name'], data = '없는 계정 입니다.')
  2269. else:
  2270. ip = getip(request)
  2271. ban = getban(ip)
  2272. if(ban == 1):
  2273. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2274. else:
  2275. if(session.get('Now') == True):
  2276. return '<meta http-equiv="refresh" content="0;url=/logout" />'
  2277. else:
  2278. return render_template('index.html', title = '비밀번호 변경', enter = '비밀번호 변경', logo = data['name'], tn = 15)
  2279. @app.route('/check/<path:name>')
  2280. def check(name = None, sub = None, number = None):
  2281. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  2282. rows = curs.fetchall()
  2283. if(rows and rows[0]['acl'] == 'owner' or rows and rows[0]['acl'] == 'admin'):
  2284. return render_template('index.html', title = '차단 오류', logo = data['name'], data = '관리자는 검사 할 수 없습니다.')
  2285. else:
  2286. if(admincheck() == 1):
  2287. 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)
  2288. if(m):
  2289. curs.execute("select * from login where ip = '" + pymysql.escape_string(name) + "' order by today desc")
  2290. row = curs.fetchall()
  2291. if(row):
  2292. i = 0
  2293. c = ''
  2294. while True:
  2295. try:
  2296. 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>'
  2297. except:
  2298. break
  2299. i = i + 1
  2300. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = c)
  2301. else:
  2302. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = '')
  2303. else:
  2304. curs.execute("select * from login where user = '" + pymysql.escape_string(name) + "' order by today desc")
  2305. row = curs.fetchall()
  2306. if(row):
  2307. i = 0
  2308. c = ''
  2309. while True:
  2310. try:
  2311. 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>'
  2312. except:
  2313. break
  2314. i = i + 1
  2315. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = c)
  2316. else:
  2317. return render_template('index.html', title = '다중 검사', logo = data['name'], tn = 22, rows = '')
  2318. else:
  2319. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2320. @app.route('/register', methods=['POST', 'GET'])
  2321. def register():
  2322. if(request.method == 'POST'):
  2323. ip = getip(request)
  2324. ban = getban(ip)
  2325. if(ban == 1):
  2326. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2327. else:
  2328. m = re.search('(?:[^A-Za-zㄱ-힣0-9 ])', request.form["id"])
  2329. if(m):
  2330. return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '아이디에는 한글과 알파벳 공백만 허용 됩니다.')
  2331. else:
  2332. if(len(request.form["id"]) > 20):
  2333. return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '아이디는 20글자보다 짧아야 합니다.')
  2334. else:
  2335. curs.execute("select * from user where id = '" + pymysql.escape_string(request.form["id"]) + "'")
  2336. rows = curs.fetchall()
  2337. if(rows):
  2338. return render_template('index.html', title = '회원가입 오류', logo = data['name'], data = '동일한 아이디의 유저가 있습니다.')
  2339. else:
  2340. hashed = bcrypt.hashpw(bytes(request.form["pw"], 'utf-8'), bcrypt.gensalt())
  2341. if(request.form["id"] == data['owner']):
  2342. curs.execute("insert into user (id, pw, acl) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(hashed.decode()) + "', 'owner')")
  2343. else:
  2344. curs.execute("insert into user (id, pw, acl) value ('" + pymysql.escape_string(request.form["id"]) + "', '" + pymysql.escape_string(hashed.decode()) + "', 'user')")
  2345. conn.commit()
  2346. return '<meta http-equiv="refresh" content="0;url=/login" />'
  2347. else:
  2348. ip = getip(request)
  2349. ban = getban(ip)
  2350. if(ban == 1):
  2351. return '<meta http-equiv="refresh" content="0;url=/ban" />'
  2352. else:
  2353. return render_template('index.html', title = '회원가입', enter = '회원가입', logo = data['name'], tn = 15)
  2354. @app.route('/logout')
  2355. def logout():
  2356. session['Now'] = False
  2357. session.pop('DREAMER', None)
  2358. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  2359. @app.route('/ban/<path:name>', methods=['POST', 'GET'])
  2360. def ban(name = None):
  2361. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  2362. rows = curs.fetchall()
  2363. if(rows and rows[0]['acl'] == 'owner' or rows and rows[0]['acl'] == 'admin'):
  2364. return render_template('index.html', title = '차단 오류', logo = data['name'], data = '관리자는 차단 할 수 없습니다.')
  2365. else:
  2366. if(request.method == 'POST'):
  2367. if(admincheck() == 1):
  2368. ip = getip(request)
  2369. curs.execute("select * from ban where block = '" + pymysql.escape_string(name) + "'")
  2370. row = curs.fetchall()
  2371. if(row):
  2372. block(name, '해제', getnow(), ip, '')
  2373. curs.execute("delete from ban where block = '" + pymysql.escape_string(name) + "'")
  2374. else:
  2375. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))$", name)
  2376. if(b):
  2377. block(name, request.form["end"], getnow(), ip, request.form["why"])
  2378. 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')")
  2379. else:
  2380. block(name, request.form["end"], getnow(), ip, request.form["why"])
  2381. 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"]) + "', '')")
  2382. conn.commit()
  2383. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  2384. else:
  2385. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2386. else:
  2387. if(admincheck() == 1):
  2388. curs.execute("select * from ban where block = '" + pymysql.escape_string(name) + "'")
  2389. row = curs.fetchall()
  2390. if(row):
  2391. now = '차단 해제'
  2392. else:
  2393. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))$", name)
  2394. if(b):
  2395. now = '대역 차단'
  2396. else:
  2397. now = '차단'
  2398. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 16, now = now, today = getnow())
  2399. else:
  2400. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2401. @app.route('/acl/<path:name>', methods=['POST', 'GET'])
  2402. def acl(name = None):
  2403. if(request.method == 'POST'):
  2404. if(admincheck() == 1):
  2405. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  2406. row = curs.fetchall()
  2407. if(row):
  2408. if(request.form["select"] == 'admin'):
  2409. curs.execute("update data set acl = 'admin' where title = '" + pymysql.escape_string(name) + "'")
  2410. elif(request.form["select"] == 'user'):
  2411. curs.execute("update data set acl = 'user' where title = '" + pymysql.escape_string(name) + "'")
  2412. else:
  2413. curs.execute("update data set acl = '' where title = '" + pymysql.escape_string(name) + "'")
  2414. conn.commit()
  2415. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  2416. else:
  2417. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2418. else:
  2419. if(admincheck() == 1):
  2420. curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
  2421. row = curs.fetchall()
  2422. if(row):
  2423. if(row[0]['acl'] == 'admin'):
  2424. now = '관리자만'
  2425. elif(row[0]['acl'] == 'user'):
  2426. now = '유저 이상'
  2427. else:
  2428. now = '일반'
  2429. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 19, now = '현재 ACL 상태는 ' + now)
  2430. else:
  2431. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name).replace('/','%2F') + '" />'
  2432. else:
  2433. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2434. @app.route('/admin/<path:name>', methods=['POST', 'GET'])
  2435. def admin(name = None):
  2436. if(request.method == 'POST'):
  2437. if(session.get('Now') == True):
  2438. ip = getip(request)
  2439. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2440. rows = curs.fetchall()
  2441. if(rows):
  2442. if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'):
  2443. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  2444. row = curs.fetchall()
  2445. if(row):
  2446. if(row[0]['acl'] == 'admin' or row[0]['acl'] == 'owner'):
  2447. curs.execute("update user set acl = 'user' where id = '" + pymysql.escape_string(name) + "'")
  2448. else:
  2449. curs.execute("update user set acl = '" + pymysql.escape_string(request.form["select"]) + "' where id = '" + pymysql.escape_string(name) + "'")
  2450. conn.commit()
  2451. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  2452. else:
  2453. return render_template('index.html', title = '사용자 오류', logo = data['name'], data = '계정이 없습니다.')
  2454. else:
  2455. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2456. else:
  2457. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  2458. else:
  2459. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  2460. else:
  2461. if(session.get('Now') == True):
  2462. ip = getip(request)
  2463. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2464. rows = curs.fetchall()
  2465. if(rows):
  2466. if(rows[0]['acl'] == 'owner'):
  2467. curs.execute("select * from user where id = '" + pymysql.escape_string(name) + "'")
  2468. row = curs.fetchall()
  2469. if(row):
  2470. if(row[0]['acl'] == 'admin' or row[0]['acl'] == 'owner'):
  2471. now = '권한 해제'
  2472. else:
  2473. now = '권한 부여'
  2474. return render_template('index.html', title = name, page = parse.quote(name).replace('/','%2F'), logo = data['name'], tn = 18, now = now)
  2475. else:
  2476. return render_template('index.html', title = '사용자 오류', logo = data['name'], data = '계정이 없습니다.')
  2477. else:
  2478. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '권한이 모자랍니다.')
  2479. else:
  2480. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '계정이 없습니다.')
  2481. else:
  2482. return render_template('index.html', title = '권한 오류', logo = data['name'], data = '비 로그인 상태 입니다.')
  2483. @app.route('/grammar')
  2484. def grammar():
  2485. return render_template('index.html', title = '문법 설명', logo = data['name'], tn = 17)
  2486. @app.route('/ban')
  2487. def aban():
  2488. ip = getip(request)
  2489. if(getban(ip) == 1):
  2490. curs.execute("select * from ban where block = '" + pymysql.escape_string(ip) + "'")
  2491. rows = curs.fetchall()
  2492. if(rows):
  2493. if(rows[0]['end']):
  2494. end = rows[0]['end'] + ' 까지 차단 상태 입니다. / 사유 : ' + rows[0]['why']
  2495. now = getnow()
  2496. now = re.sub(':', '', now)
  2497. now = re.sub('\-', '', now)
  2498. now = re.sub(' ', '', now)
  2499. now = int(now)
  2500. day = rows[0]['end']
  2501. day = re.sub('\-', '', day)
  2502. if(now >= int(day + '000000')):
  2503. curs.execute("delete from ban where block = '" + pymysql.escape_string(ip) + "'")
  2504. conn.commit()
  2505. end = '차단이 풀렸습니다. 다시 시도 해 보세요.'
  2506. else:
  2507. end = '영구 차단 상태 입니다. / 사유 : ' + rows[0]['why']
  2508. else:
  2509. b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))", ip)
  2510. if(b):
  2511. results = b.groups()
  2512. curs.execute("select * from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  2513. row = curs.fetchall()
  2514. if(row):
  2515. if(row[0]['end']):
  2516. end = row[0]['end'] + ' 까지 차단 상태 입니다. / 사유 : ' + rows[0]['why']
  2517. now = getnow()
  2518. now = re.sub(':', '', now)
  2519. now = re.sub('\-', '', now)
  2520. now = re.sub(' ', '', now)
  2521. now = int(now)
  2522. day = row[0]['end']
  2523. day = re.sub('\-', '', day)
  2524. if(now >= int(day + '000000')):
  2525. curs.execute("delete from ban where block = '" + pymysql.escape_string(results[0]) + "' and band = 'O'")
  2526. conn.commit()
  2527. end = '차단이 풀렸습니다. 다시 시도 해 보세요.'
  2528. else:
  2529. end = '영구 차단 상태 입니다. / 사유 : ' + row[0]['why']
  2530. else:
  2531. end = '권한이 맞지 않는 상태 입니다.'
  2532. return render_template('index.html', title = '권한 오류', logo = data['name'], data = end)
  2533. @app.route('/w/<path:name>/r/<a>/diff/<b>')
  2534. def diff(name = None, a = None, b = None):
  2535. curs.execute("select * from history where id = '" + pymysql.escape_string(a) + "' and title = '" + pymysql.escape_string(name) + "'")
  2536. rows = curs.fetchall()
  2537. if(rows):
  2538. curs.execute("select * from history where id = '" + pymysql.escape_string(b) + "' and title = '" + pymysql.escape_string(name) + "'")
  2539. row = curs.fetchall()
  2540. if(row):
  2541. indata = re.sub('<', '&lt;', rows[0]['data'])
  2542. indata = re.sub('>', '&gt;', indata)
  2543. indata = re.sub('"', '&quot;', indata)
  2544. indata = re.sub('\n', '<br>', indata)
  2545. enddata = re.sub('<', '&lt;', row[0]['data'])
  2546. enddata = re.sub('>', '&gt;', enddata)
  2547. enddata = re.sub('"', '&quot;', enddata)
  2548. enddata = re.sub('\n', '<br>', enddata)
  2549. sm = difflib.SequenceMatcher(None, indata, enddata)
  2550. c = show_diff(sm)
  2551. return render_template('index.html', title = name, logo = data['name'], data = c, plus = '(비교)')
  2552. else:
  2553. return render_template('index.html', title = 'Diff 오류', logo = data['name'], data = '<a href="/w/' + name + '">이 리비전이나 문서가 없습니다.</a>')
  2554. else:
  2555. return render_template('index.html', title = 'Diff 오류', logo = data['name'], data = '<a href="/w/' + name + '">이 리비전이나 문서가 없습니다.</a>')
  2556. @app.route('/version')
  2557. def version():
  2558. return render_template('index.html', title = '버전', logo = data['name'], tn = 14)
  2559. @app.route('/user')
  2560. def user():
  2561. ip = getip(request)
  2562. curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'")
  2563. rows = curs.fetchall()
  2564. if(getban(ip) == 0):
  2565. if(rows):
  2566. if(rows[0]['acl'] == 'admin' or rows[0]['acl'] == 'owner'):
  2567. if(rows[0]['acl'] == 'admin'):
  2568. acl = '관리자'
  2569. else:
  2570. acl = '소유자'
  2571. else:
  2572. acl = '유저'
  2573. else:
  2574. acl = '일반'
  2575. else:
  2576. acl = '차단'
  2577. 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>')
  2578. @app.route('/random')
  2579. def random():
  2580. curs.execute("select * from data order by rand() limit 1")
  2581. rows = curs.fetchall()
  2582. if(rows):
  2583. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(rows[0]['title']).replace('/','%2F') + '" />'
  2584. else:
  2585. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  2586. @app.errorhandler(404)
  2587. def uncaughtError(error):
  2588. return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
  2589. if __name__ == '__main__':
  2590. app.run(host = '0.0.0.0', port = int(data['port']), threaded = True)