app.py 110 KB

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