app.py 112 KB

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