app.py 115 KB

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