app.py 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794
  1. from bottle import *
  2. from bottle.ext import beaker
  3. import json
  4. import sqlite3
  5. import bcrypt
  6. import os
  7. import difflib
  8. from css_html_js_minify import html_minify
  9. from multiprocessing import Process
  10. try:
  11. json_data = open('set.json').read()
  12. set_data = json.loads(json_data)
  13. except:
  14. new_json = []
  15. print('DB 이름 : ', end = '')
  16. new_json += [input()]
  17. print('포트 : ', end = '')
  18. new_json += [input()]
  19. with open("set.json", "w") as f:
  20. f.write('{ "db" : "' + new_json[0] + '", "port" : "' + new_json[1] + '" }')
  21. json_data = open('set.json').read()
  22. set_data = json.loads(json_data)
  23. conn = sqlite3.connect(set_data['db'] + '.db')
  24. curs = conn.cursor()
  25. session_opts = {
  26. 'session.type': 'file',
  27. 'session.data_dir': './app_session/',
  28. 'session.auto': 1
  29. }
  30. app = beaker.middleware.SessionMiddleware(app(), session_opts)
  31. from func import *
  32. BaseRequest.MEMFILE_MAX = 1000 ** 4
  33. def redirect(data):
  34. return('<meta http-equiv="refresh" content="0;url=' + data + '" />')
  35. def re_error(data):
  36. if(data == '/ban'):
  37. ip = ip_check()
  38. end = '권한이 맞지 않는 상태 입니다.'
  39. if(ban_check() == 1):
  40. curs.execute("select end, why from ban where block = ?", [ip])
  41. d = curs.fetchall()
  42. if(not d):
  43. m = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
  44. if(m):
  45. curs.execute("select end, why from ban where block = ? and band = 'O'", [m.groups()[0]])
  46. d = curs.fetchall()
  47. if(d):
  48. if(d[0][0]):
  49. end = d[0][0] + ' 까지 차단 상태 입니다. / 사유 : ' + d[0][1]
  50. now = re.sub(':', '', get_time())
  51. now = re.sub('\-', '', now)
  52. now = int(re.sub(' ', '', now))
  53. day = re.sub('\-', '', d[0][0])
  54. if(now >= int(day + '000000')):
  55. curs.execute("delete from ban where block = ?", [ip])
  56. conn.commit()
  57. end = '차단이 풀렸습니다. 다시 시도 해 보세요.'
  58. else:
  59. end = '영구 차단 상태 입니다. / 사유 : ' + d[0][1]
  60. return(
  61. html_minify(
  62. template('index',
  63. imp = ['권한 오류', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  64. data = end,
  65. menu = 0
  66. )
  67. )
  68. )
  69. d = re.search('\/error\/([0-9]+)', data)
  70. if(d):
  71. num = int(d.groups()[0])
  72. if(num == 1):
  73. title = '권한 오류'
  74. data = '비 로그인 상태 입니다.'
  75. elif(num == 2):
  76. title = '권한 오류'
  77. data = '이 계정이 없습니다.'
  78. elif(num == 3):
  79. title = '권한 오류'
  80. data = '권한이 모자랍니다.'
  81. elif(num == 4):
  82. title = '권한 오류'
  83. data = '관리자는 차단, 검사 할 수 없습니다.'
  84. elif(num == 5):
  85. title = '사용자 오류'
  86. data = '그런 계정이 없습니다.'
  87. elif(num == 6):
  88. title = '가입 오류'
  89. data = '동일한 아이디의 사용자가 있습니다.'
  90. elif(num == 7):
  91. title = '가입 오류'
  92. data = '아이디는 20글자보다 짧아야 합니다.'
  93. elif(num == 8):
  94. title = '가입 오류'
  95. data = '아이디에는 한글과 알파벳과 공백만 허용 됩니다.'
  96. elif(num == 9):
  97. title = '파일 올리기 오류'
  98. data = '파일이 없습니다.'
  99. elif(num == 10):
  100. title = '변경 오류'
  101. data = '비밀번호가 다릅니다.'
  102. elif(num == 11):
  103. title = '로그인 오류'
  104. data = '이미 로그인 되어 있습니다.'
  105. elif(num == 14):
  106. title = '파일 올리기 오류'
  107. data = 'jpg, gif, jpeg, png, webp만 가능 합니다.'
  108. elif(num == 15):
  109. title = '편집 오류'
  110. data = '편집 기록은 500자를 넘을 수 없습니다.'
  111. elif(num == 16):
  112. title = '파일 올리기 오류'
  113. data = '동일한 이름의 파일이 있습니다.'
  114. elif(num == 17):
  115. title = '파일 올리기 오류'
  116. data = '파일 용량은 ' + wiki_set(4) + 'MB를 넘길 수 없습니다.'
  117. elif(num == 18):
  118. title = '편집 오류'
  119. data = '내용이 원래 문서와 동일 합니다.'
  120. elif(num == 19):
  121. title = '이동 오류'
  122. data = '이동 하려는 곳에 문서가 이미 있습니다.'
  123. elif(num == 20):
  124. title = '비밀번호 오류'
  125. data = '재 확인이랑 비밀번호가 다릅니다.'
  126. if(title):
  127. return(
  128. html_minify(
  129. template(
  130. 'index',
  131. imp = [title, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  132. data = data,
  133. menu = 0
  134. )
  135. )
  136. )
  137. else:
  138. return(redirect('/'))
  139. else:
  140. return(redirect('/'))
  141. r_ver = '2.3.5'
  142. p_ver = ''
  143. try:
  144. curs.execute("select title from data limit 1")
  145. try:
  146. curs.execute('select new from move limit 1')
  147. except:
  148. curs.execute("create table move(origin text, new text, date text, who text, send text)")
  149. print('move 테이블 생성')
  150. curs.execute('select data from other where name = "skin"')
  151. skin_exist = curs.fetchall()
  152. if(skin_exist):
  153. if(os.path.exists(os.path.abspath('./views/' + skin_exist[0][0] + '/index.tpl')) == 1):
  154. TEMPLATE_PATH.insert(0, './views/' + skin_exist[0][0] + '/')
  155. else:
  156. TEMPLATE_PATH.insert(0, './views/acme/')
  157. else:
  158. TEMPLATE_PATH.insert(0, './views/acme/')
  159. try:
  160. curs.execute('select name from alarm limit 1')
  161. except:
  162. curs.execute("create table alarm(name text, data text, date text)")
  163. print('alarm 테이블 생성')
  164. try:
  165. curs.execute('select name from ua_d limit 1')
  166. except:
  167. curs.execute("create table ua_d(name text, ip text, ua text, today text, sub text)")
  168. print('ua_d 테이블 생성')
  169. try:
  170. curs.execute('select user, ip, today from login')
  171. lo_d = curs.fetchall()
  172. for m_lo in lo_d:
  173. curs.execute("insert into ua_d (name, ip, ua, today, sub) values (?, ?, '', ?, '')", [m_lo[0], m_lo[1], m_lo[2]])
  174. curs.execute("drop table login")
  175. print('login 테이블 삭제')
  176. except:
  177. pass
  178. try:
  179. curs.execute('select title, cat from cat')
  180. lo_d = curs.fetchall()
  181. for m_lo in lo_d:
  182. curs.execute("insert into back (title, link, type) values (?, ?, 'cat')", [m_lo[0], m_lo[1]])
  183. curs.execute("drop table cat")
  184. print('cat 테이블 삭제')
  185. except:
  186. pass
  187. conn.commit()
  188. except:
  189. pass
  190. @route('/setup', method=['GET', 'POST'])
  191. def setup():
  192. try:
  193. curs.execute("select title from data limit 1")
  194. except:
  195. try:
  196. curs.execute("create table data(title text, data text, acl text)")
  197. except:
  198. pass
  199. try:
  200. curs.execute("create table history(id text, title text, data text, date text, ip text, send text, leng text)")
  201. except:
  202. pass
  203. try:
  204. curs.execute("create table rd(title text, sub text, date text)")
  205. except:
  206. pass
  207. try:
  208. curs.execute("create table user(id text, pw text, acl text)")
  209. except:
  210. pass
  211. try:
  212. curs.execute("create table ban(block text, end text, why text, band text)")
  213. except:
  214. pass
  215. try:
  216. curs.execute("create table topic(id text, title text, sub text, data text, date text, ip text, block text, top text)")
  217. except:
  218. pass
  219. try:
  220. curs.execute("create table stop(title text, sub text, close text)")
  221. except:
  222. pass
  223. try:
  224. curs.execute("create table rb(block text, end text, today text, blocker text, why text)")
  225. except:
  226. pass
  227. try:
  228. curs.execute("create table back(title text, link text, type text)")
  229. except:
  230. pass
  231. try:
  232. curs.execute("create table hidhi(title text, re text)")
  233. except:
  234. pass
  235. try:
  236. curs.execute("create table agreedis(title text, sub text)")
  237. except:
  238. pass
  239. try:
  240. curs.execute("create table custom(user text, css text)")
  241. except:
  242. pass
  243. try:
  244. curs.execute("create table other(name text, data text)")
  245. except:
  246. pass
  247. try:
  248. curs.execute("create table alist(name text, acl text)")
  249. curs.execute("insert into alist (name, acl) values ('소유자', 'owner')")
  250. except:
  251. pass
  252. try:
  253. curs.execute("create table re_admin(who text, what text, time text)")
  254. except:
  255. pass
  256. try:
  257. curs.execute("create table move(origin text, new text, date text, who text, send text)")
  258. except:
  259. pass
  260. try:
  261. curs.execute("create table alarm(name text, data text, date text)")
  262. except:
  263. pass
  264. try:
  265. curs.execute("create table ua_d(name text, ip text, ua text, today text, sub text)")
  266. except:
  267. pass
  268. conn.commit()
  269. return(redirect('/'))
  270. @route('/del_alarm')
  271. def del_alarm():
  272. curs.execute("delete from alarm where name = ?", [ip_check()])
  273. conn.commit()
  274. return(redirect('/alarm'))
  275. @route('/alarm')
  276. def alarm():
  277. ip = ip_check()
  278. if(re.search('(?:\.|:)', ip)):
  279. return(redirect('/login'))
  280. da = '<ul>'
  281. curs.execute("select data, date from alarm where name = ? order by date desc", [ip])
  282. dt = curs.fetchall()
  283. if(dt):
  284. da = '<a href="/del_alarm">(알람 삭제)</a><br><br>' + da
  285. for do in dt:
  286. da += '<li>' + do[0] + ' / ' + do[1] + '</li>'
  287. else:
  288. da += '<li>알림이 없습니다.</li>'
  289. da += '</ul>'
  290. return(
  291. html_minify(
  292. template('index',
  293. imp = ['알림', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  294. data = da,
  295. menu = [['user', '사용자']]
  296. )
  297. )
  298. )
  299. @route('/edit_set', method=['POST', 'GET'])
  300. @route('/edit_set/<num:int>', method=['POST', 'GET'])
  301. def edit_set(num = 0):
  302. if(num == 0):
  303. return(
  304. html_minify(
  305. template('index',
  306. imp = ['설정 편집', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  307. data = '<ul> \
  308. <li><a href="/edit_set/1">기본 설정</a></li> \
  309. <li><a href="/edit_set/2">문구 관련</a></li> \
  310. </ul>',
  311. menu = [['manager', '관리자']]
  312. )
  313. )
  314. )
  315. elif(num == 1):
  316. if(admin_check(None, 'edit_set') == 1):
  317. if(request.method == 'POST'):
  318. curs.execute("update other set data = ? where name = ?", [request.forms.name, 'name'])
  319. curs.execute("update other set data = ? where name = 'frontpage'", [request.forms.frontpage])
  320. curs.execute("update other set data = ? where name = 'license'", [request.forms.license])
  321. curs.execute("update other set data = ? where name = 'upload'", [request.forms.upload])
  322. curs.execute("update other set data = ? where name = 'skin'", [request.forms.skin])
  323. curs.execute("update other set data = ? where name = 'edit'", [request.forms.edit])
  324. curs.execute("update other set data = ? where name = 'reg'", [request.forms.reg])
  325. conn.commit()
  326. return(redirect('/edit_set/1'))
  327. else:
  328. i_list = ['name', 'frontpage', 'license', 'upload', 'skin', 'edit', 'reg']
  329. n_list = ['무명위키', '위키:대문', 'CC 0', '2', '', 'normal', '']
  330. d_list = []
  331. x = 0
  332. for i in i_list:
  333. curs.execute('select data from other where name = ?', [i])
  334. sql_d = curs.fetchall()
  335. if(sql_d):
  336. d_list += [sql_d[0][0]]
  337. else:
  338. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  339. d_list += [n_list[x]]
  340. x += 1
  341. conn.commit()
  342. div = ''
  343. if(d_list[5] == 'login'):
  344. div += '<option value="login">사용자</option>'
  345. div += '<option value="normal">일반</option>'
  346. div += '<option value="admin">관리자</option>'
  347. elif(d_list[5] == 'admin'):
  348. div += '<option value="admin">관리자</option>'
  349. div += '<option value="login">사용자</option>'
  350. div += '<option value="normal">일반</option>'
  351. else:
  352. div += '<option value="normal">일반</option>'
  353. div += '<option value="admin">관리자</option>'
  354. div += '<option value="login">사용자</option>'
  355. if(d_list[6]):
  356. ch_1 = 'checked="checked"'
  357. else:
  358. ch_1 = ''
  359. return(
  360. html_minify(
  361. template('index',
  362. imp = ['기본 설정', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  363. data = '<form method="post"> \
  364. <span>위키 이름 (기본 : 무명위키)</span> \
  365. <br> \
  366. <br> \
  367. <input placeholder="위키 이름" style="width: 100%;" type="text" name="name" value="' + d_list[0] + '"> \
  368. <br> \
  369. <br> \
  370. <span>시작 페이지 (기본 : 위키:대문)</span> \
  371. <br> \
  372. <br> \
  373. <input placeholder="시작 페이지" style="width: 100%;" type="text" name="frontpage" value="' + d_list[1] + '"> \
  374. <br> \
  375. <br> \
  376. <span>라이선스 (기본 : CC 0)</span> \
  377. <br> \
  378. <br> \
  379. <input placeholder="라이선스" style="width: 100%;" type="text" name="license" value="' + d_list[2] + '"> \
  380. <br> \
  381. <br> \
  382. <span>파일 용량 한도 (기본 : 2)</span> \
  383. <br> \
  384. <br> \
  385. <input placeholder="파일 용량 한도" style="width: 100%;" type="text" name="upload" value="' + d_list[3] + '"> \
  386. <br> \
  387. <br> \
  388. <span>스킨 (기본 : acme) (재시작 필요)</span> \
  389. <br> \
  390. <br> \
  391. <input placeholder="스킨" style="width: 100%;" type="text" name="skin" value="' + d_list[4] + '"> \
  392. <br> \
  393. <br> \
  394. <span>기본 ACL 설정 (기본 : 일반)</span> \
  395. <br> \
  396. <br> \
  397. <select name="edit"> \
  398. ' + div + ' \
  399. </select> \
  400. <br> \
  401. <br> \
  402. <input type="checkbox" name="reg" ' + ch_1 + '> 가입불가 \
  403. <br> \
  404. <br> \
  405. <button class="btn btn-primary" type="submit">저장</button> \
  406. </form>',
  407. menu = [['edit_set', '설정 편집']]
  408. )
  409. )
  410. )
  411. elif(num == 2):
  412. if(admin_check(None, 'edit_set') == 1):
  413. if(request.method == 'POST'):
  414. curs.execute("update other set data = ? where name = ?", [request.forms.contract, 'contract'])
  415. conn.commit()
  416. return(redirect('/edit_set/2'))
  417. else:
  418. i_list = ['contract']
  419. n_list = ['']
  420. d_list = []
  421. x = 0
  422. for i in i_list:
  423. curs.execute('select data from other where name = ?', [i])
  424. sql_d = curs.fetchall()
  425. if(sql_d):
  426. d_list += [sql_d[0][0]]
  427. else:
  428. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  429. d_list += [n_list[x]]
  430. x += 1
  431. conn.commit()
  432. return(
  433. html_minify(
  434. template('index',
  435. imp = ['문구 관련', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  436. data = '<form method="post"> \
  437. <span>가입 약관</span> \
  438. <br> \
  439. <br> \
  440. <input placeholder="가입 약관" style="width: 100%;" type="text" name="contract" value="' + d_list[0] + '"> \
  441. <br> \
  442. <br> \
  443. <button class="btn btn-primary" type="submit">저장</button> \
  444. </form>',
  445. menu = [['edit_set', '설정 편집']]
  446. )
  447. )
  448. )
  449. else:
  450. return(re_error('/ban'))
  451. @route('/not_close_topic')
  452. def not_close_topic():
  453. div = '<ul>'
  454. i = 1
  455. curs.execute('select title, sub from rd order by date desc')
  456. n_list = curs.fetchall()
  457. for data in n_list:
  458. curs.execute('select * from stop where title = ? and sub = ? and close = "O"', [data[0], data[1]])
  459. is_close = curs.fetchall()
  460. if(not is_close):
  461. div += '<li>' + str(i) + '. <a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[1]) + '">' + data[0] + ' (' + data[1] + ')</a></li>'
  462. i += 1
  463. div += '</ul>'
  464. return(
  465. html_minify(
  466. template('index',
  467. imp = ['열린 토론 목록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  468. data = div,
  469. menu = [['manager', '관리자']]
  470. )
  471. )
  472. )
  473. @route('/image/<name:path>')
  474. def static(name = None):
  475. if(os.path.exists(os.path.join('image', name))):
  476. return(static_file(name, root = 'image'))
  477. else:
  478. return(redirect('/'))
  479. @route('/acl_list')
  480. def acl_list():
  481. div = '<ul>'
  482. i = 0
  483. curs.execute("select title, acl from data where acl = 'admin' or acl = 'user' order by acl desc")
  484. list_data = curs.fetchall()
  485. for data in list_data:
  486. if(not re.search('^사용자:', data[0])):
  487. if(data[1] == 'admin'):
  488. acl = '관리자'
  489. else:
  490. acl = '사용자'
  491. div += '<li>' + str(i + 1) + '. <a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (' + acl + ')</li>'
  492. i += 1
  493. div += '</ul>'
  494. return(
  495. html_minify(
  496. template('index',
  497. imp = ['ACL 문서 목록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  498. data = div,
  499. menu = [['other', '기타']]
  500. )
  501. )
  502. )
  503. @route('/list_acl')
  504. def list_acl():
  505. div = '<ul>'
  506. i = 0
  507. curs.execute("select name, acl from alist order by name desc")
  508. list_data = curs.fetchall()
  509. for data in list_data:
  510. if(data[1] == 'ban'):
  511. acl = '차단'
  512. elif(data[1] == 'mdel'):
  513. acl = '많은 문서 삭제'
  514. elif(data[1] == 'toron'):
  515. acl = '토론 관리'
  516. elif(data[1] == 'check'):
  517. acl = '사용자 검사'
  518. elif(data[1] == 'acl'):
  519. acl = '문서 ACL'
  520. elif(data[1] == 'hidel'):
  521. acl = '역사 숨김'
  522. elif(data[1] == 'owner'):
  523. acl = '소유자'
  524. div += '<li>' + str(i + 1) + '. <a href="/admin_plus/' + url_pas(data[0]) + '">' + data[0] + '</a> (' + acl + ')</li>'
  525. i += 1
  526. div += '</ul><br><a href="/manager/8">(생성)</a>'
  527. return(
  528. html_minify(
  529. template('index',
  530. imp = ['ACL 목록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  531. data = re.sub('^<ul></ul><br>', '', div),
  532. menu = [['manager', '관리자']]
  533. )
  534. )
  535. )
  536. @route('/admin_plus/<name:path>', method=['POST', 'GET'])
  537. def admin_plus(name = None):
  538. if(admin_check(None, 'admin_plus (' + name + ')') == 1):
  539. if(request.method == 'POST'):
  540. curs.execute("delete from alist where name = ?", [name])
  541. if(request.forms.ban):
  542. curs.execute("insert into alist (name, acl) values (?, 'ban')", [name])
  543. if(request.forms.mdel):
  544. curs.execute("insert into alist (name, acl) values (?, 'mdel')", [name])
  545. if(request.forms.toron):
  546. curs.execute("insert into alist (name, acl) values (?, 'toron')", [name])
  547. if(request.forms.check):
  548. curs.execute("insert into alist (name, acl) values (?, 'check')", [name])
  549. if(request.forms.acl):
  550. curs.execute("insert into alist (name, acl) values (?, 'acl')", [name])
  551. if(request.forms.hidel):
  552. curs.execute("insert into alist (name, acl) values (?, 'hidel')", [name])
  553. if(request.forms.owner):
  554. curs.execute("insert into alist (name, acl) values (?, 'owner')", [name])
  555. conn.commit()
  556. return(redirect('/admin_plus/' + url_pas(name)))
  557. else:
  558. curs.execute('select acl from alist where name = ?', [name])
  559. test = curs.fetchall()
  560. data = '<ul>'
  561. exist_list = ['', '', '', '', '', '', '']
  562. for go in test:
  563. if(go[0] == 'ban'):
  564. exist_list[0] = 'checked="checked"'
  565. elif(go[0] == 'mdel'):
  566. exist_list[1] = 'checked="checked"'
  567. elif(go[0] == 'toron'):
  568. exist_list[2] = 'checked="checked"'
  569. elif(go[0] == 'check'):
  570. exist_list[3] = 'checked="checked"'
  571. elif(go[0] == 'acl'):
  572. exist_list[4] = 'checked="checked"'
  573. elif(go[0] == 'hidel'):
  574. exist_list[5] = 'checked="checked"'
  575. elif(go[0] == 'owner'):
  576. exist_list[6] = 'checked="checked"'
  577. data += '<li><input type="checkbox" name="ban" ' + exist_list[0] + '> 차단</li>'
  578. data += '<li><input type="checkbox" name="mdel" ' + exist_list[1] + '> 많은 문서 삭제</li>'
  579. data += '<li><input type="checkbox" name="toron" ' + exist_list[2] + '> 토론 관리</li>'
  580. data += '<li><input type="checkbox" name="check" ' + exist_list[3] + '> 사용자 검사</li>'
  581. data += '<li><input type="checkbox" name="acl" ' + exist_list[4] + '> 문서 ACL</li>'
  582. data += '<li><input type="checkbox" name="hidel" ' + exist_list[5] + '> 역사 숨김</li>'
  583. data += '<li><input type="checkbox" name="owner" ' + exist_list[6] + '> 소유자</li></ul>'
  584. return(
  585. html_minify(
  586. template('index',
  587. imp = ['관리 그룹 추가', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  588. data = '<form method="post">' \
  589. + data + \
  590. '<div class="form-actions"> \
  591. <button class="btn btn-primary" type="submit">저장</button> \
  592. </div> \
  593. </form>',
  594. menu = [['manager', '관리자']]
  595. )
  596. )
  597. )
  598. else:
  599. return(re_error('/error/3'))
  600. @route('/admin_list')
  601. def admin_list():
  602. i = 1
  603. div = '<ul>'
  604. curs.execute("select id, acl from user where not acl = 'user'")
  605. user_data = curs.fetchall()
  606. for data in user_data:
  607. name = ip_pas(data[0]) + ' (' + data[1] + ')'
  608. div += '<li>' + str(i) + '. ' + name + '</li>'
  609. i += 1
  610. div += '</ul>'
  611. return(
  612. html_minify(
  613. template('index',
  614. imp = ['관리자 목록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  615. data = div,
  616. menu = [['other', '기타']]
  617. )
  618. )
  619. )
  620. @route('/record/<name:path>')
  621. @route('/record/<name:path>/n/<num:int>')
  622. @route('/recent_changes')
  623. def recent_changes(name = None, num = 1):
  624. ydmin = admin_check(1, None)
  625. zdmin = admin_check(6, None)
  626. ban = ''
  627. send = '<br>'
  628. div = '<table style="width: 100%; text-align: center;"> \
  629. <tbody> \
  630. <tr> \
  631. <td style="width: 33.3%;">문서명</td> \
  632. <td style="width: 33.3%;">기여자</td> \
  633. <td style="width: 33.3%;">시간</td> \
  634. </tr>'
  635. if(name):
  636. if(num * 50 <= 0):
  637. v = 50
  638. else:
  639. v = num * 50
  640. i = v - 50
  641. div = '<a href="/user/' + url_pas(name) + '/topic">(토론 기록)</a><br><br>' + div
  642. curs.execute("select id, title, date, ip, send, leng from history where ip = ? order by date desc limit ?, ?", [name, str(i), str(v)])
  643. else:
  644. curs.execute("select id, title, date, ip, send, leng from history where not date = 'Dump' order by date desc limit 50")
  645. rows = curs.fetchall()
  646. for data in rows:
  647. send = '<br>'
  648. if(data[4]):
  649. if(not re.search("^(?: *)$", data[4])):
  650. send = data[4]
  651. title = html.escape(data[1])
  652. if(re.search("\+", data[5])):
  653. leng = '<span style="color:green;">' + data[5] + '</span>'
  654. elif(re.search("\-", data[5])):
  655. leng = '<span style="color:red;">' + data[5] + '</span>'
  656. else:
  657. leng = '<span style="color:gray;">' + data[5] + '</span>'
  658. if(ydmin == 1):
  659. curs.execute("select * from ban where block = ?", [data[3]])
  660. row = curs.fetchall()
  661. if(row):
  662. ban = ' <a href="/ban/' + url_pas(data[3]) + '">(해제)</a>'
  663. else:
  664. ban = ' <a href="/ban/' + url_pas(data[3]) + '">(차단)</a>'
  665. ip = ip_pas(data[3])
  666. if((int(data[0]) - 1) == 0):
  667. revert = ''
  668. else:
  669. revert = '<a href="/w/' + url_pas(data[1]) + '/r/' + str(int(data[0]) - 1) + '/diff/' + data[0] + '">(비교)</a> <a href="/revert/' + url_pas(data[1]) + '/r/' + str(int(data[0]) - 1) + '">(되돌리기)</a>'
  670. style = ''
  671. curs.execute("select * from hidhi where title = ? and re = ?", [data[1], data[0]])
  672. row = curs.fetchall()
  673. if(zdmin == 1):
  674. if(row):
  675. ip += ' (숨김)'
  676. hidden = ' <a href="/history/' + url_pas(data[1]) + '/r/' + data[0] + '/hidden">(공개)'
  677. else:
  678. hidden = ' <a href="/history/' + url_pas(data[1]) + '/r/' + data[0] + '/hidden">(숨김)'
  679. else:
  680. if(row):
  681. ip = '숨김'
  682. hidden = ''
  683. send = '숨김'
  684. ban = ''
  685. style = 'display:none;'
  686. else:
  687. hidden = ''
  688. div += '<tr style="' + style + '"> \
  689. <td> \
  690. <a href="/w/' + url_pas(data[1]) + '">' + title + '</a> (<a href="/history/' + url_pas(data[1]) + '">' + data[0] + '판</a>) ' + revert + ' (' + leng + ') \
  691. </td> \
  692. <td>' + ip + ban + hidden + '</td> \
  693. <td>' + data[2] + '</td> \
  694. </tr> \
  695. <tr> \
  696. <td colspan="3">' + send + '</td> \
  697. </tr>'
  698. else:
  699. div += '</tbody> \
  700. </table>'
  701. if(name):
  702. curs.execute("select end, why from ban where block = ?", [name])
  703. ban_it = curs.fetchall()
  704. if(ban_it):
  705. sub = '(차단)'
  706. else:
  707. sub = 0
  708. title = '기여 기록'
  709. menu = [['other', '기타'], ['user', '사용자']]
  710. div += '<br><a href="/record/' + url_pas(name) + '/n/' + str(num - 1) + '">(이전)</a> <a href="/record/' + url_pas(name) + '/n/' + str(num + 1) + '">(이후)</a>'
  711. else:
  712. sub = 0
  713. menu = 0
  714. title = '최근 변경내역'
  715. return(
  716. html_minify(
  717. template('index',
  718. imp = [title, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), sub, 0],
  719. data = div,
  720. menu = menu
  721. )
  722. )
  723. )
  724. @route('/history/<name:path>/r/<num:int>/hidden')
  725. def history_hidden(name = None, num = None):
  726. if(admin_check(6, 'history_hidden (' + name + '#' + str(num) + ')') == 1):
  727. curs.execute("select * from hidhi where title = ? and re = ?", [name, str(num)])
  728. exist = curs.fetchall()
  729. if(exist):
  730. curs.execute("delete from hidhi where title = ? and re = ?", [name, str(num)])
  731. else:
  732. curs.execute("insert into hidhi (title, re) values (?, ?)", [name, str(num)])
  733. conn.commit()
  734. return(redirect('/history/' + url_pas(name)))
  735. @route('/user_log')
  736. @route('/user_log/n/<num:int>')
  737. def user_log(num = 1):
  738. if(num * 50 <= 0):
  739. i = 50
  740. else:
  741. i = num * 50
  742. j = i - 50
  743. list_data = '<ul>'
  744. ydmin = admin_check(1, None)
  745. curs.execute("select id from user limit ?, ?", [str(j), str(i)])
  746. user_list = curs.fetchall()
  747. for data in user_list:
  748. if(ydmin == 1):
  749. curs.execute("select block from ban where block = ?", [data[0]])
  750. ban_exist = curs.fetchall()
  751. if(ban_exist):
  752. ban_button = ' <a href="/ban/' + url_pas(data[0]) + '">(해제)</a>'
  753. else:
  754. ban_button = ' <a href="/ban/' + url_pas(data[0]) + '">(차단)</a>'
  755. else:
  756. ban_button = ''
  757. ip = ip_pas(data[0])
  758. list_data += '<li>' + str(j + 1) + '. ' + ip + ban_button + '</li>'
  759. j += 1
  760. else:
  761. list_data += '</ul><br><a href="/user_log/n/' + str(num - 1) + '">(이전)</a> <a href="/user_log/n/' + str(num + 1) + '">(이후)</a>'
  762. return(
  763. html_minify(
  764. template('index',
  765. imp = ['사용자 가입 기록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  766. data = list_data,
  767. menu = [['other', '기타']]
  768. )
  769. )
  770. )
  771. @route('/admin_log')
  772. @route('/admin_log/n/<num:int>')
  773. def user_log(num = 1):
  774. if(num * 50 <= 0):
  775. i = 50
  776. else:
  777. i = num * 50
  778. j = i - 50
  779. list_data = '<ul>'
  780. curs.execute("select who, what, time from re_admin order by time desc limit ?, ?", [str(j), str(i)])
  781. get_list = curs.fetchall()
  782. for data in get_list:
  783. ip = ip_pas(data[0])
  784. list_data += '<li>' + str(j + 1) + '. ' + ip + ' / ' + data[1] + ' / ' + data[2] + '</li>'
  785. j += 1
  786. else:
  787. list_data += '</ul><br> \
  788. <span>주의 : 권한 사용 안하고 열람만 해도 기록되는 경우도 있습니다.</span> \
  789. <br> \
  790. <br> \
  791. <a href="/admin_log/n/' + str(num - 1) + '">(이전)</a> <a href="/admin_log/n/' + str(num + 1) + '">(이후)</a>'
  792. return(
  793. html_minify(
  794. template('index',
  795. imp = ['관리자 권한 기록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  796. data = list_data,
  797. menu = [['other', '기타']]
  798. )
  799. )
  800. )
  801. @route('/give_log')
  802. @route('/give_log/n/<num:int>')
  803. def give_log(num = 1):
  804. if(num * 50 <= 0):
  805. i = 50
  806. else:
  807. i = num * 50
  808. j = i - 50
  809. list_data = '<ul>'
  810. back = ''
  811. curs.execute("select name, acl from alist order by name asc limit ?, ?", [str(j), str(i)])
  812. get_list = curs.fetchall()
  813. for data in get_list:
  814. if(back != data[0]):
  815. back = data[0]
  816. j += 1
  817. list_data += '<li>' + str(j) + '. ' + data[0] + ' (' + data[1] + ')</li>'
  818. else:
  819. list_data += '</ul><br><a href="/give_log/n/' + str(num - 1) + '">(이전)</a> <a href="/give_log/n/' + str(num + 1) + '">(이후)</a>'
  820. return(
  821. html_minify(
  822. template('index',
  823. imp = ['권한 목록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  824. data = list_data,
  825. menu = [['other', '기타']]
  826. )
  827. )
  828. )
  829. @route('/indexing')
  830. def indexing():
  831. if(admin_check(None, 'indexing') == 1):
  832. curs.execute("select name from sqlite_master where type in ('table', 'view') and name not like 'sqlite_%' union all select name from sqlite_temp_master where type in ('table', 'view') order by 1;")
  833. data = curs.fetchall()
  834. for table in data:
  835. print('----- ' + table[0] + ' -----')
  836. curs.execute('select sql from sqlite_master where name = ?', [table[0]])
  837. cul = curs.fetchall()
  838. r_cul = re.findall('(?:([^ (]*) text)', str(cul[0]))
  839. for n_cul in r_cul:
  840. print(n_cul)
  841. sql = 'create index index_' + table[0] + '_' + n_cul + ' on ' + table[0] + '(' + n_cul + ')'
  842. curs.execute(sql)
  843. conn.commit()
  844. return(redirect('/'))
  845. else:
  846. return(re_error('/error/3'))
  847. @route('/xref/<name:path>')
  848. @route('/xref/<name:path>/n/<num:int>')
  849. def xref(name = None, num = 1):
  850. if(num * 50 <= 0):
  851. v = 50
  852. else:
  853. v = num * 50
  854. i = v - 50
  855. div = '<ul>'
  856. curs.execute("delete from back where title = ? and link = ''", [name])
  857. conn.commit()
  858. curs.execute("select link, type from back where title = ? order by link asc limit ?, ?", [name, str(i), str(v)])
  859. rows = curs.fetchall()
  860. for data in rows:
  861. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a>'
  862. if(data[1]):
  863. div += ' (' + data[1] + ')'
  864. div += '</li>'
  865. else:
  866. div += '</ul><br><a href="/xref/' + url_pas(name) + '/n/' + str(num - 1) + '">(이전)</a> <a href="/xref/' + url_pas(name) + '/n/' + str(num + 1) + '">(이후)</a>'
  867. return(
  868. html_minify(
  869. template('index',
  870. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (역링크)', 0],
  871. data = div,
  872. menu = [['w/' + url_pas(name), '문서']]
  873. )
  874. )
  875. )
  876. @route('/recent_discuss')
  877. @route('/recent_discuss/<tools:path>')
  878. def recent_discuss(tools = 'normal'):
  879. if(tools == 'normal' or tools == 'close'):
  880. div = ''
  881. if(tools == 'normal'):
  882. div += '<a href="/recent_discuss/close">(닫힌 토론)</a>'
  883. m_sub = 0
  884. else:
  885. div += '<a href="/recent_discuss">(열린 토론)</a>'
  886. m_sub = ' (닫힘)'
  887. div += '<br> \
  888. <br> \
  889. <table style="width: 100%; text-align: center;"> \
  890. <tbody> \
  891. <tr> \
  892. <td style="width: 50%;">토론명</td> \
  893. <td style="width: 50%;">시간</td> \
  894. </tr>'
  895. else:
  896. return(redirect('/'))
  897. curs.execute("select title, sub, date from rd order by date desc limit 50")
  898. rows = curs.fetchall()
  899. for data in rows:
  900. title = html.escape(data[0])
  901. sub = html.escape(data[1])
  902. close = 0
  903. if(tools == 'normal'):
  904. curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [data[0], data[1]])
  905. if(curs.fetchall()):
  906. close = 1
  907. else:
  908. curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [data[0], data[1]])
  909. if(not curs.fetchall()):
  910. close = 1
  911. if(close == 0):
  912. div += '<tr> \
  913. <td> \
  914. <a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[1]) + '">' + title + '</a> (' + sub + ') \
  915. </td> \
  916. <td>' + data[2] + '</td> \
  917. </tr>'
  918. else:
  919. div += '</tbody> \
  920. </table>'
  921. return(
  922. html_minify(
  923. template('index',
  924. imp = ['최근 토론내역', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), m_sub, 0],
  925. data = div,
  926. menu = 0
  927. )
  928. )
  929. )
  930. @route('/block_log')
  931. @route('/block_log/n/<num:int>')
  932. def block_log(num = 1):
  933. if(num * 50 <= 0):
  934. v = 50
  935. else:
  936. v = num * 50
  937. i = v - 50
  938. div = '<table style="width: 100%; text-align: center;"> \
  939. <tbody> \
  940. <tr> \
  941. <td style="width: 33.3%;">차단자</td> \
  942. <td style="width: 33.3%;">관리자</td> \
  943. <td style="width: 33.3%;">기간</td> \
  944. </tr> \
  945. <tr> \
  946. <td colspan="2">이유</td> \
  947. <td>시간</td> \
  948. </tr>'
  949. curs.execute("select why, block, blocker, end, today from rb order by today desc limit ?, ?", [str(i), str(v)])
  950. rows = curs.fetchall()
  951. for data in rows:
  952. why = html.escape(data[0])
  953. b = re.search("^([0-9]{1,3}\.[0-9]{1,3})$", data[1])
  954. if(b):
  955. ip = data[1] + ' (대역)'
  956. else:
  957. ip = ip_pas(data[1])
  958. if(data[3] != ''):
  959. end = data[3]
  960. else:
  961. end = '무기한'
  962. div += '<tr> \
  963. <td>' + ip + '</td> \
  964. <td>' + ip_pas(data[2]) + '</td> \
  965. <td>' + end + '</td> \
  966. </tr> \
  967. <tr> \
  968. <td colspan="2">' + why + '</td> \
  969. <td>' + data[4] + '</td> \
  970. </tr>'
  971. else:
  972. div += '</tbody> \
  973. </table> \
  974. <br> \
  975. <a href="/block_log/n/' + str(num - 1) + '">(이전)</a> <a href="/block_log/n/' + str(num + 1) + '">(이후)</a>'
  976. return(
  977. html_minify(
  978. template('index',
  979. imp = ['차단 기록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  980. data = div,
  981. menu = [['other', '기타']]
  982. )
  983. )
  984. )
  985. @route('/history/<name:path>', method=['POST', 'GET'])
  986. @route('/history/<name:path>/n/<num:int>', method=['POST', 'GET'])
  987. def history_view(name = None, num = 1):
  988. if(request.method == 'POST'):
  989. return(redirect('/w/' + url_pas(name) + '/r/' + request.forms.b + '/diff/' + request.forms.a))
  990. else:
  991. select = ''
  992. if(num * 50 <= 0):
  993. i = 50
  994. else:
  995. i = num * 50
  996. j = i - 50
  997. admin1 = admin_check(1, None)
  998. admin2 = admin_check(6, None)
  999. div = '<table style="width: 100%; text-align: center;"> \
  1000. <tbody> \
  1001. <tr> \
  1002. <td style="width: 33.3%;">판</td> \
  1003. <td style="width: 33.3%;">기여자</td> \
  1004. <td style="width: 33.3%;">시간</td> \
  1005. </tr>'
  1006. curs.execute("select send, leng, ip, date, title, id from history where title = ? order by id + 0 desc limit ?, ?", [name, str(j), str(i)])
  1007. all_data = curs.fetchall()
  1008. for data in all_data:
  1009. select += '<option value="' + data[5] + '">' + data[5] + '</option>'
  1010. if(data[0]):
  1011. send = data[0]
  1012. else:
  1013. send = '<br>'
  1014. if(re.search("^\+", data[1])):
  1015. leng = '<span style="color:green;">' + data[1] + '</span>'
  1016. elif(re.search("^\-", data[1])):
  1017. leng = '<span style="color:red;">' + data[1] + '</span>'
  1018. else:
  1019. leng = '<span style="color:gray;">' + data[1] + '</span>'
  1020. ip = ip_pas(data[2])
  1021. curs.execute("select block from ban where block = ?", [data[2]])
  1022. ban_it = curs.fetchall()
  1023. if(ban_it):
  1024. if(admin1 == 1):
  1025. ban = ' <a href="/ban/' + url_pas(data[2]) + '">(해제)</a>'
  1026. else:
  1027. ban = ' (X)'
  1028. else:
  1029. if(admin1 == 1):
  1030. ban = ' <a href="/ban/' + url_pas(data[2]) + '">(차단)</a>'
  1031. else:
  1032. ban = ''
  1033. curs.execute("select * from hidhi where title = ? and re = ?", [name, data[5]])
  1034. hid_it = curs.fetchall()
  1035. if(hid_it):
  1036. if(admin2):
  1037. hidden = ' <a href="/history/' + url_pas(name) + '/r/' + url_pas(data[5]) + '/hidden">(공개)'
  1038. hid = 0
  1039. else:
  1040. hid = 1
  1041. else:
  1042. if(admin2):
  1043. hidden = ' <a href="/history/' + url_pas(name) + '/r/' + url_pas(data[5]) + '/hidden">(숨김)'
  1044. hid = 0
  1045. else:
  1046. hidden = ''
  1047. hid = 0
  1048. if(hid == 1):
  1049. div += '<tr> \
  1050. <td colspan="3">숨김</td> \
  1051. </tr>'
  1052. else:
  1053. div += '<tr> \
  1054. <td> \
  1055. ' + data[5] + '판</a> <a href="/w/' + url_pas(name) + '/r/' + url_pas(data[5]) + '">(보기)</a> \
  1056. <a href="/raw/' + url_pas(name) + '/r/' + url_pas(data[5]) + '">(원본)</a> \
  1057. <a href="/revert/' + url_pas(name) + '/r/' + url_pas(data[5]) + '">(되돌리기)</a> (' + leng + ') \
  1058. </td> \
  1059. <td>' + ip + ban + hidden + '</td> \
  1060. <td>' + data[3] + '</td> \
  1061. </tr> \
  1062. <tr> \
  1063. <td colspan="3">' + send + '</td> \
  1064. </tr>'
  1065. else:
  1066. div += '</tbody> \
  1067. </table> \
  1068. <br> \
  1069. <a href="/history/' + url_pas(name) + '/n/' + str(num - 1) + '">(이전)</a> <a href="/history/' + url_pas(name) + '/n/' + str(num + 1) + '">(이후)</a>'
  1070. div = '<form method="post"> \
  1071. <select name="a"> \
  1072. ' + select + ' \
  1073. </select> \
  1074. <select name="b"> \
  1075. ' + select + ' \
  1076. </select> \
  1077. <button class="btn btn-primary" type="submit">비교</button> \
  1078. </form>' + div
  1079. return(
  1080. html_minify(
  1081. template('index',
  1082. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (역사)', 0],
  1083. data = div,
  1084. menu = [['w/' + url_pas(name), '문서'], ['move_data/' + url_pas(name), '이동 기록']]
  1085. )
  1086. )
  1087. )
  1088. @route('/search', method=['POST'])
  1089. def search():
  1090. return(redirect('/search/' + url_pas(request.forms.search)))
  1091. @route('/goto', method=['POST'])
  1092. def goto():
  1093. curs.execute("select title from data where title = ?", [request.forms.search])
  1094. data = curs.fetchall()
  1095. if(data):
  1096. return(redirect('/w/' + url_pas(request.forms.search)))
  1097. else:
  1098. return(redirect('/search/' + url_pas(request.forms.search)))
  1099. @route('/search/<name:path>')
  1100. @route('/search/<name:path>/n/<num:int>')
  1101. def deep_search(name = None, num = 1):
  1102. if(num * 50 <= 0):
  1103. v = num * 50
  1104. else:
  1105. v = 50
  1106. i = v - 50
  1107. div = '<ul>'
  1108. div_plus = ''
  1109. end = ''
  1110. curs.execute("select title from data where title like ?", ['%' + name + '%'])
  1111. title_list = curs.fetchall()
  1112. curs.execute("select title from data where data like ?", ['%' + name + '%'])
  1113. data_list = curs.fetchall()
  1114. curs.execute("select title from data where title = ?", [name])
  1115. exist = curs.fetchall()
  1116. if(exist):
  1117. div = '<ul><li>문서로 <a href="/w/' + url_pas(name) + '">바로가기</a></li><br><br>'
  1118. else:
  1119. div = '<ul><li>문서가 없습니다. <a class="not_thing" href="/w/' + url_pas(name) + '">바로가기</a></li><br><br>'
  1120. if(title_list):
  1121. no = 0
  1122. if(data_list):
  1123. all_list = title_list + data_list
  1124. else:
  1125. all_list = title_list
  1126. else:
  1127. if(data_list):
  1128. no = 1
  1129. all_list = data_list
  1130. else:
  1131. all_list = ''
  1132. if(all_list != ''):
  1133. for data in all_list:
  1134. try:
  1135. var_re = re.search(name, data[0])
  1136. except:
  1137. var_re = re.search('\\' + name, data[0])
  1138. if(var_re):
  1139. if(no == 0):
  1140. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (제목)</li>'
  1141. else:
  1142. div_plus += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (내용)</li>'
  1143. else:
  1144. no = 1
  1145. div_plus += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (내용)</li>'
  1146. else:
  1147. div += '<li>검색 결과 없음</li>'
  1148. div += div_plus + end
  1149. div += '</ul><br><a href="/search/' + url_pas(name) + '/n/' + str(num - 1) + '">(이전)</a> <a href="/search/' + url_pas(name) + '/n/' + str(num + 1) + '">(이후)</a>'
  1150. return(
  1151. html_minify(
  1152. template('index',
  1153. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (검색)', 0],
  1154. data = div,
  1155. menu = 0
  1156. )
  1157. )
  1158. )
  1159. @route('/raw/<name:path>')
  1160. @route('/raw/<name:path>/r/<num:int>')
  1161. @route('/topic/<name:path>/sub/<sub_t:path>/raw/<num:int>')
  1162. def raw_view(name = None, sub_t = None, num = None):
  1163. v_name = name
  1164. sub = ' (원본)'
  1165. if(not sub_t and num):
  1166. curs.execute("select title from hidhi where title = ? and re = ?", [name, str(num)])
  1167. hid = curs.fetchall()
  1168. if(hid and admin_check(6, None) != 1):
  1169. return(re_error('/error/3'))
  1170. curs.execute("select data from history where title = ? and id = ?", [name, str(num)])
  1171. sub += ' (' + str(num) + '판)'
  1172. menu = [['history/' + url_pas(name), '역사']]
  1173. elif(sub_t):
  1174. curs.execute("select data from topic where id = ? and title = ? and sub = ? and block = ''", [str(num), name, sub_t])
  1175. v_name = '토론 원본'
  1176. sub = ' (' + str(num) + '번)'
  1177. menu = [['topic/' + url_pas(name) + '/sub/' + url_pas(sub_t) + '#' + str(num), '토론']]
  1178. else:
  1179. curs.execute("select data from data where title = ?", [name])
  1180. menu = [['w/' + url_pas(name), '문서']]
  1181. data = curs.fetchall()
  1182. if(data):
  1183. p_data = html.escape(data[0][0])
  1184. p_data = '<textarea readonly style="height: 80%;">' + p_data + '</textarea>'
  1185. return(
  1186. html_minify(
  1187. template('index',
  1188. imp = [v_name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), sub, 0],
  1189. data = p_data,
  1190. menu = menu
  1191. )
  1192. )
  1193. )
  1194. else:
  1195. return(redirect('/w/' + url_pas(name)))
  1196. @route('/revert/<name:path>/r/<num:int>', method=['POST', 'GET'])
  1197. def revert(name = None, num = None):
  1198. ip = ip_check()
  1199. can = acl_check(name)
  1200. today = get_time()
  1201. if(request.method == 'POST'):
  1202. curs.execute("select title from hidhi where title = ? and re = ?", [name, str(num)])
  1203. hid = curs.fetchall()
  1204. if(hid and admin_check(6, None) != 1):
  1205. return(re_error('/error/3'))
  1206. if(can == 1):
  1207. return(re_error('/ban'))
  1208. else:
  1209. curs.execute("delete from back where link = ?", [name])
  1210. conn.commit()
  1211. curs.execute("select data from history where title = ? and id = ?", [name, str(num)])
  1212. rows = curs.fetchall()
  1213. if(rows):
  1214. curs.execute("select data from data where title = ?", [name])
  1215. row = curs.fetchall()
  1216. if(row):
  1217. leng = leng_check(len(row[0][0]), len(rows[0][0]))
  1218. curs.execute("update data set data = ? where title = ?", [rows[0][0], name])
  1219. else:
  1220. leng = '+' + str(len(rows[0][0]))
  1221. curs.execute("insert into data (title, data, acl) values (?, ?, '')", [name, rows[0][0]])
  1222. history_plus(
  1223. name,
  1224. rows[0][0],
  1225. today,
  1226. ip,
  1227. request.forms.send + ' (' + str(num) + '판)',
  1228. leng
  1229. )
  1230. namumark(name, rows[0][0], 1, 0, 0)
  1231. conn.commit()
  1232. return(redirect('/w/' + url_pas(name)))
  1233. else:
  1234. curs.execute("select title from hidhi where title = ? and re = ?", [name, str(num)])
  1235. hid = curs.fetchall()
  1236. if(hid and admin_check(6, None) != 1):
  1237. return(re_error('/error/3'))
  1238. if(can == 1):
  1239. return(re_error('/ban'))
  1240. else:
  1241. curs.execute("select title from history where title = ? and id = ?", [name, str(num)])
  1242. rows = curs.fetchall()
  1243. if(rows):
  1244. l_c = custom(0)
  1245. if(l_c == 0):
  1246. plus = '<span>비 로그인 상태입니다. 비 로그인으로 작업 시 아이피가 역사에 기록됩니다.</span> \
  1247. <br> \
  1248. <br>'
  1249. else:
  1250. plus = ''
  1251. return(
  1252. html_minify(
  1253. template('index',
  1254. imp = [name, wiki_set(1), wiki_set(3), l_c, custom(1), custom(2), ' (되돌리기)', 0],
  1255. data = plus + ' \
  1256. <form method="post"> \
  1257. <input placeholder="사유" style="width: 100%;" class="form-control input-sm" name="send" type="text"> \
  1258. <br> \
  1259. <br> \
  1260. <button class="btn btn-primary" type="submit">되돌리기</button> \
  1261. </form>',
  1262. menu = [['history/' + url_pas(name), '역사'], ['recent_changes', '최근 변경']]
  1263. )
  1264. )
  1265. )
  1266. else:
  1267. return(redirect('/w/' + url_pas(name)))
  1268. @route('/m_del', method=['POST', 'GET'])
  1269. def m_del():
  1270. today = get_time()
  1271. ip = ip_check()
  1272. if(admin_check(2, 'm_del') == 1):
  1273. if(request.method == 'POST'):
  1274. data = request.forms.content + '\r\n'
  1275. m = re.findall('(.*)\r\n', data)
  1276. for g in m:
  1277. curs.execute("select data from data where title = ?", [g])
  1278. rows = curs.fetchall()
  1279. if(rows):
  1280. curs.execute("delete from back where title = ?", [g])
  1281. leng = '-' + str(len(rows[0][0]))
  1282. curs.execute("delete from data where title = ?", [g])
  1283. history_plus(
  1284. g,
  1285. '',
  1286. today,
  1287. ip,
  1288. request.forms.send + ' (대량 삭제)',
  1289. leng
  1290. )
  1291. data = re.sub('(.*)\r\n', '', data, 1)
  1292. conn.commit()
  1293. return(redirect('/'))
  1294. else:
  1295. return(
  1296. html_minify(
  1297. template('index',
  1298. imp = ['많은 문서 삭제', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1299. data = '<span> \
  1300. 문서명 A \
  1301. <br> \
  1302. 문서명 B \
  1303. <br> \
  1304. 문서명 C \
  1305. <br> \
  1306. <br> \
  1307. 이런 식으로 적으세요. \
  1308. </span> \
  1309. <br> \
  1310. <br> \
  1311. <form method="post"> \
  1312. <textarea style="height: 80%;" name="content"></textarea> \
  1313. <br> \
  1314. <br> \
  1315. <input placeholder="사유" style="width: 100%;" class="form-control input-sm" name="send" type="text"> \
  1316. <br> \
  1317. <br> \
  1318. <div class="form-actions"> \
  1319. <button class="btn btn-primary" type="submit">삭제</button> \
  1320. </div> \
  1321. </form>',
  1322. menu = [['manager', '관리자']]
  1323. )
  1324. )
  1325. )
  1326. else:
  1327. return(re_error('/error/3'))
  1328. @route('/edit/<name:path>', method=['POST', 'GET'])
  1329. @route('/edit/<name:path>/section/<num:int>', method=['POST', 'GET'])
  1330. def edit(name = None, num = None):
  1331. ip = ip_check()
  1332. can = acl_check(name)
  1333. if(request.method == 'POST'):
  1334. if(can == 1):
  1335. return(re_error('/ban'))
  1336. if(len(request.forms.send) > 500):
  1337. return(re_error('/error/15'))
  1338. if(request.forms.otent == request.forms.content):
  1339. return(re_error('/error/18'))
  1340. today = get_time()
  1341. content = savemark(request.forms.content)
  1342. curs.execute("delete from back where link = ?", [name])
  1343. curs.execute("select data from data where title = ?", [name])
  1344. rows = curs.fetchall()
  1345. if(rows):
  1346. leng = leng_check(len(request.forms.otent), len(content))
  1347. if(num):
  1348. content = rows[0][0].replace(request.forms.otent, content)
  1349. curs.execute("update data set data = ? where title = ?", [content, name])
  1350. else:
  1351. leng = '+' + str(len(content))
  1352. curs.execute("insert into data (title, data, acl) values (?, ?, '')", [name, content])
  1353. history_plus(
  1354. name,
  1355. content,
  1356. today,
  1357. ip,
  1358. send_p(request.forms.send),
  1359. leng
  1360. )
  1361. namumark(name, content, 1, 0, 0)
  1362. include_check(name, content)
  1363. conn.commit()
  1364. return(redirect('/w/' + url_pas(name)))
  1365. else:
  1366. if(can == 1):
  1367. return(re_error('/ban'))
  1368. curs.execute("select data from data where title = ?", [name])
  1369. rows = curs.fetchall()
  1370. if(rows):
  1371. if(num):
  1372. i = 0
  1373. j = 0
  1374. data = rows[0][0] + '\r\n'
  1375. while(1):
  1376. m = re.search("((?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n(?:(?:(?:(?!(?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n).)*)(?:\n)?)+)", data)
  1377. if(m):
  1378. if(i == num - 1):
  1379. g = m.groups()
  1380. data = re.sub("\r\n$", "", g[0])
  1381. break
  1382. else:
  1383. data = re.sub("((?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n(?:(?:(?:(?!(?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n).)*)(?:\n)?)+)", "", data, 1)
  1384. i += 1
  1385. else:
  1386. j = 1
  1387. break
  1388. if(j == 0):
  1389. data = re.sub("\r\n$", "", data)
  1390. else:
  1391. data = rows[0][0]
  1392. else:
  1393. data = ''
  1394. if(num):
  1395. action = '/section/' + str(num)
  1396. else:
  1397. action = ''
  1398. return(
  1399. html_minify(
  1400. template('index',
  1401. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (수정)', 0],
  1402. data = '<form method="post" action="/edit/' + url_pas(name) + action + '"> \
  1403. <textarea style="height: 80%;" name="content">' + data + '</textarea> \
  1404. <textarea style="display: none; height: 80%;" name="otent">' + data + '</textarea> \
  1405. <br> \
  1406. <br> \
  1407. <input placeholder="사유" name="send" style="width: 100%;" type="text"> \
  1408. <br> \
  1409. <br> \
  1410. <div class="form-actions"> \
  1411. <button id="save" class="btn btn-primary" type="submit">저장</button> \
  1412. <button id="preview" class="btn" type="submit" formaction="/preview/' + url_pas(name) + action + '">미리보기</button> \
  1413. </div> \
  1414. </form>',
  1415. menu = [['w/' + url_pas(name), '문서']]
  1416. )
  1417. )
  1418. )
  1419. @route('/preview/<name:path>', method=['POST'])
  1420. @route('/preview/<name:path>/section/<num:int>', method=['POST'])
  1421. def preview(name = None, num = None):
  1422. ip = ip_check()
  1423. can = acl_check(name)
  1424. if(can == 1):
  1425. return(re_error('/ban'))
  1426. newdata = request.forms.content
  1427. newdata = re.sub('^#(?:redirect|넘겨주기) (?P<in>[^\n]*)', ' * [[\g<in>]] 문서로 넘겨주기', newdata)
  1428. enddata = namumark(name, newdata, 0, 0, 0)
  1429. if(num):
  1430. action = '/section/' + str(num)
  1431. else:
  1432. action = ''
  1433. return(
  1434. html_minify(
  1435. template('index',
  1436. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (미리보기)', 0],
  1437. data = '<form method="post" action="/edit/' + url_pas(name) + action + '"> \
  1438. <textarea style="height: 80%;" name="content">' + request.forms.content + '</textarea> \
  1439. <textarea style="display: none; height: 80%;" name="otent">' + request.forms.otent + '</textarea> \
  1440. <br> \
  1441. <br> \
  1442. <input placeholder="사유" name="send" style="width: 100%;" type="text"> \
  1443. <br> \
  1444. <br> \
  1445. <div class="form-actions"> \
  1446. <button id="save" class="btn btn-primary" type="submit">저장</button> \
  1447. <button id="preview" class="btn" type="submit" formaction="/preview/' + url_pas(name) + action + '">미리보기</button> \
  1448. </div> \
  1449. </form> \
  1450. <br>' + enddata,
  1451. menu = [['w/' + url_pas(name), '문서']]
  1452. )
  1453. )
  1454. )
  1455. @route('/delete/<name:path>', method=['POST', 'GET'])
  1456. def delete(name = None):
  1457. ip = ip_check()
  1458. can = acl_check(name)
  1459. if(request.method == 'POST'):
  1460. curs.execute("select data from data where title = ?", [name])
  1461. rows = curs.fetchall()
  1462. if(rows):
  1463. if(can == 1):
  1464. return(re_error('/ban'))
  1465. today = get_time()
  1466. leng = '-' + str(len(rows[0][0]))
  1467. history_plus(name, '', today, ip, request.forms.send + ' (삭제)', leng)
  1468. curs.execute("delete from back where link = ?", [name])
  1469. curs.execute("delete from data where title = ?", [name])
  1470. conn.commit()
  1471. return(redirect('/w/' + url_pas(name)))
  1472. else:
  1473. curs.execute("select title from data where title = ?", [name])
  1474. rows = curs.fetchall()
  1475. if(rows):
  1476. if(can == 1):
  1477. return(re_error('/ban'))
  1478. else:
  1479. l_c = custom(0)
  1480. if(l_c == 0):
  1481. plus = '<span>비 로그인 상태입니다. 비 로그인으로 작업 시 아이피가 역사에 기록됩니다.</span><br><br>'
  1482. else:
  1483. plus = ''
  1484. return(
  1485. html_minify(
  1486. template('index',
  1487. imp = [name, wiki_set(1), wiki_set(3), l_c, custom(1), custom(2), ' (삭제)', 0],
  1488. data = '<form method="post"> \
  1489. ' + plus + ' \
  1490. <input placeholder="사유" style="width: 100%;" class="form-control input-sm" name="send" type="text"> \
  1491. <br> \
  1492. <br> \
  1493. <button class="btn btn-primary" type="submit">삭제</button> \
  1494. </form>',
  1495. menu = [['w/' + url_pas(name), '문서']]
  1496. )
  1497. )
  1498. )
  1499. else:
  1500. return(redirect('/w/' + url_pas(name)))
  1501. @route('/move_data/<name:path>')
  1502. @route('/move_data/<name:path>/<n:int>')
  1503. def move_data(name = None, n = 1):
  1504. if(n > 0):
  1505. i = n
  1506. else:
  1507. i = 1
  1508. j = i * 50
  1509. da = '<ul>'
  1510. curs.execute("select origin, new, date, who, send from move where origin = ? or new = ? limit ?, ?", [name, name, j - 50, j])
  1511. for d in curs.fetchall():
  1512. if(d[4] == ''):
  1513. sn = '(없음)'
  1514. else:
  1515. sn = d[4]
  1516. da += '<li><a href="/move_data/' + url_pas(d[0]) + '">' + d[0] + '</a> >> <a href="/move_data/' + url_pas(d[1]) + '">' + d[1] + '</a> / ' + d[2] + ' / ' + d[3] + ' / ' + sn + '</li>'
  1517. da += '</ul><br><a href="/move_data/' + name + '/' + str(n - 1) + '">(이전)</a> <a href="/move_data/' + name + '/' + str(n + 1) + '">(이후)</a>'
  1518. return(
  1519. html_minify(
  1520. template('index',
  1521. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (이동)', 0],
  1522. data = da,
  1523. menu = [['w/' + url_pas(name), '문서']]
  1524. )
  1525. )
  1526. )
  1527. @route('/move/<name:path>', method=['POST', 'GET'])
  1528. def move(name = None):
  1529. ip = ip_check()
  1530. can = acl_check(name)
  1531. today = get_time()
  1532. if(can == 1):
  1533. return(re_error('/ban'))
  1534. if(request.method == 'POST'):
  1535. curs.execute("select data from data where title = ?", [name])
  1536. rows = curs.fetchall()
  1537. leng = '0'
  1538. curs.execute("select title from history where title = ?", [request.forms.title])
  1539. row = curs.fetchall()
  1540. if(row):
  1541. return(re_error('/error/19'))
  1542. if(rows):
  1543. curs.execute("update data set title = ? where title = ?", [request.forms.title, name])
  1544. curs.execute("update back set link = ? where link = ?", [request.forms.title, name])
  1545. d = rows[0][0]
  1546. else:
  1547. d = ''
  1548. history_plus(
  1549. name,
  1550. d,
  1551. today,
  1552. ip,
  1553. request.forms.send + ' (<a href="/w/' + url_pas(name) + '">' + name + '</a> - <a href="/w/' + url_pas(request.forms.title) + '">' + request.forms.title + '</a> 이동)',
  1554. leng
  1555. )
  1556. curs.execute('insert into move (origin, new, date, who, send) values (?, ?, ?, ?, ?)', [name, request.forms.title, today, ip, request.forms.send])
  1557. curs.execute("update history set title = ? where title = ?", [request.forms.title, name])
  1558. conn.commit()
  1559. return(redirect('/w/' + url_pas(request.forms.title)))
  1560. else:
  1561. l_c = custom(0)
  1562. if(l_c == 0):
  1563. plus = '<span>비 로그인 상태입니다. 비 로그인으로 작업 시 아이피가 역사에 기록됩니다.</span><br><br>'
  1564. else:
  1565. plus = ''
  1566. return(
  1567. html_minify(
  1568. template('index',
  1569. imp = [name, wiki_set(1), wiki_set(3), l_c, custom(1), custom(2), ' (이동)', 0],
  1570. data = '<form method="post"> \
  1571. ' + plus + ' \
  1572. <input placeholder="문서명" class="form-control input-sm" value="' + name + '" name="title" type="text"> \
  1573. <br> \
  1574. <br> \
  1575. <input placeholder="사유" style="width: 100%;" class="form-control input-sm" name="send" type="text"> \
  1576. <br> \
  1577. <br> \
  1578. <button class="btn btn-primary" type="submit">이동</button> \
  1579. </form>',
  1580. menu = [['w/' + url_pas(name), '문서']]
  1581. )
  1582. )
  1583. )
  1584. @route('/other')
  1585. def other():
  1586. return(
  1587. html_minify(
  1588. template('index',
  1589. imp = ['기타 메뉴', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1590. data = namumark('', '[목차(없음)]\r\n' + \
  1591. '== 기록 ==\r\n' + \
  1592. ' * [[wiki:block_log|차단 기록]]\r\n' + \
  1593. ' * [[wiki:user_log|가입 기록]]\r\n' + \
  1594. ' * [[wiki:admin_log|권한 기록]]\r\n' + \
  1595. ' * [[wiki:manager/6|사용자 기록]]\r\n' + \
  1596. ' * [[wiki:not_close_topic|열린 토론 목록]]\r\n' + \
  1597. '== 기타 ==\r\n' + \
  1598. ' * [[wiki:title_index|모든 문서]]\r\n' + \
  1599. ' * [[wiki:acl_list|ACL 문서]]\r\n' + \
  1600. ' * [[wiki:admin_list|관리자 목록]]\r\n' + \
  1601. ' * [[wiki:give_log|권한 목록]]\r\n' + \
  1602. ' * [[wiki:upload|파일 올리기]]\r\n' + \
  1603. '== 관리자 ==\r\n' + \
  1604. ' * [[wiki:manager/1|관리자 메뉴]]\r\n' + \
  1605. '== 버전 ==\r\n' + \
  1606. '이 오픈나무는 [[https://github.com/2DU/openNAMU/blob/SQLite/version.md|' + r_ver + p_ver + ']]판 입니다.', 0, 0, 0),
  1607. menu = 0
  1608. )
  1609. )
  1610. )
  1611. @route('/manager', method=['POST', 'GET'])
  1612. @route('/manager/<num:int>', method=['POST', 'GET'])
  1613. def manager(num = 1):
  1614. if(num == 1):
  1615. return(
  1616. html_minify(
  1617. template('index',
  1618. imp = ['관리자 메뉴', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1619. data = namumark('', '[목차(없음)]\r\n' + \
  1620. '== 목록 ==\r\n' + \
  1621. ' * [[wiki:manager/2|문서 ACL]]\r\n' + \
  1622. ' * [[wiki:manager/3|사용자 검사]]\r\n' + \
  1623. ' * [[wiki:manager/10|사용자 비교]]\r\n' + \
  1624. ' * [[wiki:manager/4|사용자 차단]]\r\n' + \
  1625. ' * [[wiki:manager/5|권한 주기]]\r\n' + \
  1626. ' * [[wiki:m_del|여러 문서 삭제]]\r\n' + \
  1627. '== 소유자 ==\r\n' + \
  1628. ' * [[wiki:indexing|인덱싱]]\r\n' + \
  1629. ' * [[wiki:manager/8|관리 그룹 생성]]\r\n' + \
  1630. ' * [[wiki:edit_set|설정 편집]]\r\n' + \
  1631. ' * [[wiki:manager/9|JSON 출력]]\r\n' + \
  1632. ' * [[wiki:json_in|JSON 입력]]\r\n' + \
  1633. '== 기타 ==\r\n' + \
  1634. ' * 이 메뉴에 없는 기능은 해당 문서의 역사나 토론에서 바로 사용 가능함', 0, 0, 0),
  1635. menu = [['other', '기타']]
  1636. )
  1637. )
  1638. )
  1639. elif(num == 2):
  1640. if(request.method == 'POST'):
  1641. return(redirect('/acl/' + url_pas(request.forms.name)))
  1642. else:
  1643. return(
  1644. html_minify(
  1645. template('index',
  1646. imp = ['ACL 이동', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1647. data = '<form method="post"> \
  1648. <input placeholder="문서명" name="name" type="text"> \
  1649. <br> \
  1650. <br> \
  1651. <button class="btn btn-primary" type="submit">이동</button> \
  1652. </form>',
  1653. menu = [['manager', '관리자']]
  1654. )
  1655. )
  1656. )
  1657. elif(num == 3):
  1658. if(request.method == 'POST'):
  1659. return(redirect('/check/' + url_pas(request.forms.name)))
  1660. else:
  1661. return(
  1662. html_minify(
  1663. template('index',
  1664. imp = ['검사 이동', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1665. data = '<form method="post"> \
  1666. <input placeholder="사용자명" name="name" type="text"> \
  1667. <br> \
  1668. <br> \
  1669. <button class="btn btn-primary" type="submit">이동</button> \
  1670. </form>',
  1671. menu = [['manager', '관리자']]
  1672. )
  1673. )
  1674. )
  1675. elif(num == 4):
  1676. if(request.method == 'POST'):
  1677. return(redirect('/ban/' + url_pas(request.forms.name)))
  1678. else:
  1679. return(
  1680. html_minify(
  1681. template('index',
  1682. imp = ['차단 이동', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1683. data = '<form method="post"> \
  1684. <input placeholder="사용자명" name="name" type="text"> \
  1685. <br> \
  1686. <br> \
  1687. <button class="btn btn-primary" type="submit">이동</button> \
  1688. </form>',
  1689. menu = [['manager', '관리자']]
  1690. )
  1691. )
  1692. )
  1693. elif(num == 5):
  1694. if(request.method == 'POST'):
  1695. return(redirect('/admin/' + url_pas(request.forms.name)))
  1696. else:
  1697. return(
  1698. html_minify(
  1699. template('index',
  1700. imp = ['권한 이동', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1701. data = '<form method="post"> \
  1702. <input placeholder="사용자명" name="name" type="text"> \
  1703. <br> \
  1704. <br> \
  1705. <button class="btn btn-primary" type="submit">이동</button> \
  1706. </form>',
  1707. menu = [['manager', '관리자']]
  1708. )
  1709. )
  1710. )
  1711. elif(num == 6):
  1712. if(request.method == 'POST'):
  1713. return(redirect('/record/' + url_pas(request.forms.name)))
  1714. else:
  1715. return(
  1716. html_minify(
  1717. template('index',
  1718. imp = ['기록 이동', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1719. data = '<form method="post"> \
  1720. <input placeholder="사용자명" name="name" type="text"> \
  1721. <br> \
  1722. <br> \
  1723. <button class="btn btn-primary" type="submit">이동</button> \
  1724. </form>',
  1725. menu = [['other', '기타']]
  1726. )
  1727. )
  1728. )
  1729. elif(num == 8):
  1730. if(request.method == 'POST'):
  1731. return(redirect('/admin_plus/' + url_pas(request.forms.name)))
  1732. else:
  1733. return(
  1734. html_minify(
  1735. template('index',
  1736. imp = ['그룹 생성 이동', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1737. data = '<form method="post"> \
  1738. <input placeholder="그룹명" name="name" type="text"> \
  1739. <br> \
  1740. <br> \
  1741. <button class="btn btn-primary" type="submit">이동</button> \
  1742. </form>',
  1743. menu = [['manager', '관리자']]
  1744. )
  1745. )
  1746. )
  1747. elif(num == 9):
  1748. if(request.method == 'POST'):
  1749. return(redirect('/json_out/' + url_pas(request.forms.name)))
  1750. else:
  1751. return(
  1752. html_minify(
  1753. template('index',
  1754. imp = ['문서 출력 이동', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1755. data = '<form method="post"> \
  1756. <input placeholder="문서명" name="name" type="text"> \
  1757. <br> \
  1758. <br> \
  1759. <button class="btn btn-primary" type="submit">이동</button> \
  1760. </form>',
  1761. menu = [['manager', '관리자']]
  1762. )
  1763. )
  1764. )
  1765. elif(num == 10):
  1766. if(request.method == 'POST'):
  1767. return(redirect('/check/' + url_pas(request.forms.name) + '/' + url_pas(request.forms.name2)))
  1768. else:
  1769. return(
  1770. html_minify(
  1771. template('index',
  1772. imp = ['검사 이동', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1773. data = '<form method="post"> \
  1774. <input placeholder="사용자명" name="name" type="text"> \
  1775. <br> \
  1776. <br> \
  1777. <input placeholder="비교 대상" name="name2" type="text"> \
  1778. <br> \
  1779. <br> \
  1780. <button class="btn btn-primary" type="submit">이동</button> \
  1781. </form>',
  1782. menu = [['manager', '관리자']]
  1783. )
  1784. )
  1785. )
  1786. else:
  1787. return(redirect('/'))
  1788. @route('/json_out/<name:path>')
  1789. def json_out(name = None):
  1790. if(admin_check(None, 'json_out') == 1):
  1791. curs.execute('select data from data where title = ?', [name])
  1792. get_d = curs.fetchall()
  1793. if(get_d):
  1794. da = get_d[0][0]
  1795. else:
  1796. da = ''
  1797. curs.execute('select ip from history where title = ? order by ip asc', [name])
  1798. get_h = curs.fetchall()
  1799. var_n = ''
  1800. hi_d = ''
  1801. for hi in get_h:
  1802. if(hi[0] != var_n):
  1803. var_n = hi[0]
  1804. hi_d += json.dumps(hi[0]) + ', '
  1805. else:
  1806. hi_d = re.sub(', $', '', hi_d)
  1807. if(hi_d == ''):
  1808. return(redirect('/w/' + url_pas(name)))
  1809. json_f = '{ "title" : ' + json.dumps(name) + ', "data" : ' + json.dumps(da) + ', "history" : [' + hi_d + '] }'
  1810. return(json_f)
  1811. else:
  1812. return(re_error('/error/3'))
  1813. @route('/json_in', method=['POST', 'GET'])
  1814. def json_in():
  1815. if(admin_check(None, 'json_in') == 1):
  1816. if(request.method == 'POST'):
  1817. data = json.loads(request.forms.data)
  1818. title = data["title"]
  1819. curs.execute('select title from history where title = ?', [title])
  1820. get_d = curs.fetchall()
  1821. if(get_d):
  1822. return(redirect('/w/' + url_pas(title)))
  1823. curs.execute('insert into data (title, data, acl) values (?, ?, "")', [title, data["data"]])
  1824. i = 0
  1825. date = get_time()
  1826. for hi in data["history"]:
  1827. i += 1
  1828. if(i == 1):
  1829. curs.execute('insert into history (id, title, data, date, ip, send, leng) values (?, ?, ?, ?, ?, "", ?)', [i, title, data["data"], date, hi, '+' + len(data["data"])])
  1830. else:
  1831. curs.execute('insert into history (id, title, data, date, ip, send, leng) values (?, ?, "", ?, ?, "", "0")', [i, title, date, hi])
  1832. conn.commit()
  1833. return(redirect('/w/' + url_pas(title)))
  1834. else:
  1835. return(
  1836. html_minify(
  1837. template('index',
  1838. imp = ['문서 JSON 입력', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1839. data = '<form method="post"> \
  1840. <textarea style="height: 80%;" name="data"></textarea> \
  1841. <br> \
  1842. <br> \
  1843. <button class="btn btn-primary" type="submit">입력</button> \
  1844. </form>',
  1845. menu = [['manager', '관리자']]
  1846. )
  1847. )
  1848. )
  1849. else:
  1850. return(re_error('/error/3'))
  1851. @route('/title_index')
  1852. @route('/title_index/<num:int>/<page:int>')
  1853. def title_index(num = 1000, page = 1):
  1854. if(page > 0):
  1855. v_page = page * num
  1856. else:
  1857. v_page = 1 * num
  1858. if(num != 0):
  1859. i = [v_page - num + 1]
  1860. else:
  1861. i = [1, 0, 0, 0, 0, 0]
  1862. data = '<ul><a href="/title_index/0/1">(전체)</a> <a href="/title_index/500/1">(500)</a> <a href="/title_index/5000/1">(5000개)</a> <a href="/title_index/10000/1">(10000개)</a> <a href="/title_index/50000/1">(50000개)</a><br><br>'
  1863. if(num == 0):
  1864. curs.execute("select title from data order by title asc")
  1865. else:
  1866. curs.execute("select title from data order by title asc limit ?, ?", [str(v_page - num), str(num)])
  1867. title_list = curs.fetchall()
  1868. for list_data in title_list:
  1869. data += '<li>' + str(i[0]) + '. <a href="/w/' + url_pas(list_data[0]) + '">' + list_data[0] + '</a></li>'
  1870. if(num == 0):
  1871. if(re.search('^분류:', list_data[0])):
  1872. i[1] += 1
  1873. elif(re.search('^사용자:', list_data[0])):
  1874. i[2] += 1
  1875. elif(re.search('^틀:', list_data[0])):
  1876. i[3] += 1
  1877. elif(re.search('^파일:', list_data[0])):
  1878. i[4] += 1
  1879. else:
  1880. i[5] += 1
  1881. i[0] += 1
  1882. if(num == 0):
  1883. if(title_list):
  1884. data += '<br><br><li>이 위키에는 총 ' + str(i[0]) + '개의 문서가 있습니다.</li><br><br> \
  1885. <li>틀 문서는 총 ' + str(i[3]) + '개의 문서가 있습니다.</li> \
  1886. <li>분류 문서는 총 ' + str(i[1]) + '개의 문서가 있습니다.</li> \
  1887. <li>사용자 문서는 총 ' + str(i[2]) + '개의 문서가 있습니다.</li> \
  1888. <li>파일 문서는 총 ' + str(i[4]) + '개의 문서가 있습니다.</li> \
  1889. <li>나머지 문서는 총 ' + str(i[5]) + '개의 문서가 있습니다.</li>'
  1890. else:
  1891. data += '</ul><br><a href="/title_index/' + str(num) + '/' + str(page - 1) + '">(이전)</a> <a href="/title_index/' + str(num) + '/' + str(page + 1) + '">(이후)</a>'
  1892. return(
  1893. html_minify(
  1894. template('index',
  1895. imp = ['모든 문서', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (' + str(num) + ')', 0],
  1896. data = data,
  1897. menu = [['other', '기타']]
  1898. )
  1899. )
  1900. )
  1901. @route('/topic/<name:path>/sub/<sub:path>/b/<num:int>')
  1902. def topic_block(name = None, sub = None, num = None):
  1903. if(admin_check(3, 'blind (' + name + ' - ' + sub + '#' + str(num) + ')') == 1):
  1904. curs.execute("select block from topic where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1905. block = curs.fetchall()
  1906. if(block):
  1907. if(block[0][0] == 'O'):
  1908. curs.execute("update topic set block = '' where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1909. else:
  1910. curs.execute("update topic set block = 'O' where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1911. conn.commit()
  1912. rd_plus(
  1913. name,
  1914. sub,
  1915. get_time()
  1916. )
  1917. return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num)))
  1918. else:
  1919. return(re_error('/error/3'))
  1920. @route('/topic/<name:path>/sub/<sub:path>/notice/<num:int>')
  1921. def topic_top(name = None, sub = None, num = None):
  1922. if(admin_check(3, 'notice (' + name + ' - ' + sub + '#' + str(num) + ')') == 1):
  1923. curs.execute("select * from topic where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1924. topic_data = curs.fetchall()
  1925. if(topic_data):
  1926. curs.execute("select top from topic where id = ? and title = ? and sub = ?", [str(num), name, sub])
  1927. top_data = curs.fetchall()
  1928. if(top_data):
  1929. if(top_data[0][0] == 'O'):
  1930. curs.execute("update topic set top = '' where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1931. else:
  1932. curs.execute("update topic set top = 'O' where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1933. conn.commit()
  1934. rd_plus(
  1935. name,
  1936. sub,
  1937. get_time()
  1938. )
  1939. return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num)))
  1940. else:
  1941. return(re_error('/error/3'))
  1942. @route('/topic/<name:path>/sub/<sub:path>/tool/agree')
  1943. def topic_agree(name = None, sub = None):
  1944. if(admin_check(3, 'agree (' + name + ' - ' + sub + ')') == 1):
  1945. ip = ip_check()
  1946. curs.execute("select id from topic where title = ? and sub = ? order by id + 0 desc limit 1", [name, sub])
  1947. topic_check = curs.fetchall()
  1948. if(topic_check):
  1949. time = get_time()
  1950. curs.execute("select title from agreedis where title = ? and sub = ?", [name, sub])
  1951. agree = curs.fetchall()
  1952. if(agree):
  1953. curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, '합의 결렬', ?, ?, '', '1')", [str(int(topic_check[0][0]) + 1), name, sub, time, ip])
  1954. curs.execute("delete from agreedis where title = ? and sub = ?", [name, sub])
  1955. else:
  1956. curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, '합의 완료', ?, ?, '', '1')", [str(int(topic_check[0][0]) + 1), name, sub, time, ip])
  1957. curs.execute("insert into agreedis (title, sub) values (?, ?)", [name, sub])
  1958. conn.commit()
  1959. rd_plus(
  1960. name,
  1961. sub,
  1962. time
  1963. )
  1964. return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub)))
  1965. else:
  1966. return(re_error('/error/3'))
  1967. @route('/topic/<name:path>/sub/<sub:path>/tool/<tool:path>')
  1968. def topic_stop(name = None, sub = None, tool = None):
  1969. if(tool == 'close'):
  1970. close = 'O'
  1971. n_close = ''
  1972. data = '토론 닫음'
  1973. n_data = '토론 다시 열기'
  1974. elif(tool == 'stop'):
  1975. close = ''
  1976. n_close = 'O'
  1977. data = '토론 정지'
  1978. n_data = '토론 재 시작'
  1979. else:
  1980. return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub)))
  1981. if(admin_check(3, 'topic stop and end (' + name + ' - ' + sub + ')') == 1):
  1982. ip = ip_check()
  1983. curs.execute("select id from topic where title = ? and sub = ? order by id + 0 desc limit 1", [name, sub])
  1984. topic_check = curs.fetchall()
  1985. if(topic_check):
  1986. time = get_time()
  1987. curs.execute("select title from stop where title = ? and sub = ? and close = ?", [name, sub, close])
  1988. stop = curs.fetchall()
  1989. if(stop):
  1990. curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '1')", [str(int(topic_check[0][0]) + 1), name, sub, n_data, time, ip])
  1991. curs.execute("delete from stop where title = ? and sub = ? and close = ?", [name, sub, close])
  1992. else:
  1993. curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '1')", [str(int(topic_check[0][0]) + 1), name, sub, data, time, ip])
  1994. curs.execute("insert into stop (title, sub, close) values (?, ?, ?)", [name, sub, close])
  1995. curs.execute("delete from stop where title = ? and sub = ? and close = ?", [name, sub, n_close])
  1996. conn.commit()
  1997. rd_plus(
  1998. name,
  1999. sub,
  2000. time
  2001. )
  2002. return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub)))
  2003. else:
  2004. return(re_error('/error/3'))
  2005. @route('/topic/<name:path>/sub/<sub:path>/admin/<num:int>')
  2006. def topic_admin(name = None, sub = None, num = None):
  2007. curs.execute("select block, ip from topic where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  2008. data = curs.fetchall()
  2009. if(not data):
  2010. return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub)))
  2011. is_ban = '<li><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/b/' + str(num) + '">'
  2012. if(data[0][0] == 'O'):
  2013. is_ban += '가림 해제'
  2014. else:
  2015. is_ban += '가림'
  2016. is_ban += '</a></li>'
  2017. curs.execute("select id from topic where title = ? and sub = ? and id = ? and top = 'O'", [name, sub, str(num)])
  2018. row = curs.fetchall()
  2019. is_ban += '<li><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/notice/' + str(num) + '">'
  2020. if(row):
  2021. is_ban += '공지 해제'
  2022. else:
  2023. is_ban += '공지'
  2024. is_ban += '</a></li>'
  2025. curs.execute("select end from ban where block = ?", [data[0][1]])
  2026. ban_it = curs.fetchall()
  2027. ban = '<li><a href="/ban/' + url_pas(data[0][1]) + '">'
  2028. if(ban_it):
  2029. ban += '차단 해제'
  2030. else:
  2031. ban += '차단'
  2032. ban += '</a></li>' + is_ban
  2033. return(
  2034. html_minify(
  2035. template('index',
  2036. imp = ['토론 관리', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (' + str(num) + '번)', 0],
  2037. data = '<ul>' + ban + '</ul>',
  2038. menu = [['topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num), '토론']]
  2039. )
  2040. )
  2041. )
  2042. @route('/topic/<name:path>/sub/<sub:path>', method=['POST', 'GET'])
  2043. def topic(name = None, sub = None):
  2044. ban = topic_check(name, sub)
  2045. admin = admin_check(3, None)
  2046. if(request.method == 'POST'):
  2047. ip = ip_check()
  2048. today = get_time()
  2049. curs.execute("select id from topic where title = ? and sub = ? order by id + 0 desc limit 1", [name, sub])
  2050. rows = curs.fetchall()
  2051. if(rows):
  2052. num = int(rows[0][0]) + 1
  2053. else:
  2054. num = 1
  2055. m = re.search('^사용자:([^/]+)', name)
  2056. if(m):
  2057. d = m.groups()
  2058. curs.execute('insert into alarm (name, data, date) values (?, ?, ?)', [d[0], ip + '님이 <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '">사용자 토론</a>을 시작했습니다.', today])
  2059. if(ban == 1 and admin != 1):
  2060. return(re_error('/ban'))
  2061. rd_plus(name, sub, today)
  2062. data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", "[br]", request.forms.content)
  2063. m = re.findall("(?:#([0-9]+))", data)
  2064. for da in m:
  2065. curs.execute("select ip from topic where title = ? and sub = ? and id = ?", [name, sub, da])
  2066. row = curs.fetchall()
  2067. if(row):
  2068. if(not re.search('(\.|:)', row[0][0])):
  2069. curs.execute('insert into alarm (name, data, date) values (?, ?, ?)', [row[0][0], ip + '님이 <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num) + '">토론</a>에서 언급 했습니다.', today])
  2070. data = re.sub("(?P<in>#(?:[0-9]+))", '[[\g<in>]]', data)
  2071. data = savemark(data)
  2072. curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '')", [str(num), name, sub, data, today, ip])
  2073. conn.commit()
  2074. return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub)))
  2075. else:
  2076. s = ''
  2077. div = ''
  2078. curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [name, sub])
  2079. cd = curs.fetchall()
  2080. curs.execute("select title from stop where title = ? and sub = ? and close = ''", [name, sub])
  2081. sd = curs.fetchall()
  2082. if(admin == 1):
  2083. if(cd):
  2084. div += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/close">(열기)</a> '
  2085. else:
  2086. div += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/close">(닫기)</a> '
  2087. if(sd):
  2088. div += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/stop">(재개)</a> '
  2089. else:
  2090. div += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/stop">(정지)</a> '
  2091. curs.execute("select title from agreedis where title = ? and sub = ?", [name, sub])
  2092. if(curs.fetchall()):
  2093. div += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/agree">(합의)</a>'
  2094. else:
  2095. div += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/agree">(취소)</a>'
  2096. div += '<br><br>'
  2097. if((sd or cd) and admin != 1):
  2098. s = 'display: none;'
  2099. curs.execute("select data, id, date, ip, block, top from topic where title = ? and sub = ? order by id + 0 asc", [name, sub])
  2100. t1 = curs.fetchall()
  2101. curs.execute("select data, id, date, ip from topic where title = ? and sub = ? and top = 'O' order by id + 0 asc", [name, sub])
  2102. t2 = curs.fetchall()
  2103. for d in t2:
  2104. a = ''
  2105. curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['notice (' + name + ' - ' + sub + '#' + d[1] + ')'])
  2106. m = curs.fetchall()
  2107. if(m):
  2108. a += ' @' + m[0][0]
  2109. div += '<table id="toron"> \
  2110. <tbody> \
  2111. <tr> \
  2112. <td id="toron_color_red"> \
  2113. <a href="#' + d[1] + '">#' + d[1] + '</a> ' + ip_pas(d[3]) + a + ' <span style="float:right;">' + d[2] + '</span> \
  2114. </td> \
  2115. </tr> \
  2116. <tr> \
  2117. <td>' + namumark('', d[0], 0, 0, 0) + '</td> \
  2118. </tr> \
  2119. </tbody> \
  2120. </table> \
  2121. <br>'
  2122. i = 1
  2123. for d in t1:
  2124. if(i == 1):
  2125. start = d[3]
  2126. p = d[0]
  2127. if(d[4] == 'O'):
  2128. bd = 'style="background: gainsboro;"'
  2129. if(admin != 1):
  2130. curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['blind (' + name + ' - ' + sub + '#' + str(i) + ')'])
  2131. b = curs.fetchall()
  2132. if(b):
  2133. p = '[[사용자:' + b[0][0] + ']]님이 가림'
  2134. else:
  2135. p = '관리자가 가림'
  2136. else:
  2137. bd = ''
  2138. p = namumark('', p, 0, 0, 0)
  2139. ip = ip_pas(d[3])
  2140. curs.execute('select acl from user where id = ?', [d[3]])
  2141. user_acl = curs.fetchall()
  2142. if(user_acl and user_acl[0][0] != 'user'):
  2143. ip += ' <a href="javascript:void(0);" title="관리자">★</a>'
  2144. if(admin == 1 or bd == ''):
  2145. ip += ' <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/raw/' + str(i) + '">(원본)</a>'
  2146. if(admin == 1):
  2147. ip += ' <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/admin/' + str(i) + '">(관리)</a>'
  2148. curs.execute("select end from ban where block = ?", [d[3]])
  2149. if(curs.fetchall()):
  2150. ip += ' <a href="javascript:void(0);" title="차단자">†</a>'
  2151. if(d[5] == '1'):
  2152. c = '_blue'
  2153. elif(d[3] == start):
  2154. c = '_green'
  2155. else:
  2156. c = ''
  2157. if(p == ''):
  2158. p = '<br>'
  2159. div += '<table id="toron"> \
  2160. <tbody> \
  2161. <tr> \
  2162. <td id="toron_color' + c + '"> \
  2163. <a href="javascript:void(0);" id="' + str(i) + '">#' + str(i) + '</a> ' + ip + ' <span style="float:right;">' + d[2] + '</span> \
  2164. </td> \
  2165. </tr> \
  2166. <tr ' + bd + '> \
  2167. <td>' + p + '</td> \
  2168. </tr> \
  2169. </tbody> \
  2170. </table> \
  2171. <br>'
  2172. i += 1
  2173. l = custom(0)
  2174. if(ban != 1):
  2175. data = '<a id="reload" href="javascript:void(0);" onclick="location.href.endsWith(\'#reload\') ? location.reload(true) : location.href = \'#reload\'"> \
  2176. <i aria-hidden="true" class="fa fa-refresh"></i> \
  2177. </a> \
  2178. <form style="' + s + '" method="post"> \
  2179. <br> \
  2180. <textarea style="width: 100%; height: 100px;" name="content"></textarea> \
  2181. <br> \
  2182. <br> \
  2183. <button class="btn btn-primary" type="submit">전송</button> \
  2184. </form>'
  2185. if(l == 0 and s == ''):
  2186. data += '<span>비 로그인 상태입니다. 비 로그인으로 작업 시 아이피가 토론에 기록됩니다.</span>'
  2187. else:
  2188. data = ''
  2189. return(
  2190. html_minify(
  2191. template('index',
  2192. imp = [name, wiki_set(1), wiki_set(3), l, custom(1), custom(2), ' (토론)', 0],
  2193. data = '<h2 style="margin-top: 0px;">' + sub + '</h2> \
  2194. <br> \
  2195. ' + div + ' \
  2196. ' + data,
  2197. menu = [['topic/' + url_pas(name), '목록']]
  2198. )
  2199. )
  2200. )
  2201. @route('/topic/<name:path>', method=['POST', 'GET'])
  2202. @route('/topic/<name:path>/<tool:path>', method=['GET'])
  2203. def close_topic_list(name = None, tool = None):
  2204. div = ''
  2205. i = 0
  2206. list_d = 0
  2207. if(request.method == 'POST'):
  2208. t_num = ''
  2209. while(1):
  2210. curs.execute("select title from topic where title = ? and sub = ? limit 1", [name, request.forms.topic + t_num])
  2211. if(curs.fetchall()):
  2212. if(t_num == ''):
  2213. t_num = ' 2'
  2214. else:
  2215. t_num = ' ' + str(int(t_num.replace(' ', '')) + 1)
  2216. else:
  2217. break
  2218. return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(request.forms.topic + t_num)))
  2219. else:
  2220. plus = ''
  2221. menu = [['topic/' + url_pas(name), '목록']]
  2222. if(tool == 'close'):
  2223. curs.execute("select sub from stop where title = ? and close = 'O' order by sub asc", [name])
  2224. sub = '닫힘'
  2225. elif(tool == 'agree'):
  2226. curs.execute("select sub from agreedis where title = ? order by sub asc", [name])
  2227. sub = '합의'
  2228. else:
  2229. curs.execute("select sub from rd where title = ? order by date desc", [name])
  2230. sub = '토론 목록'
  2231. menu = [['w/' + url_pas(name), '문서']]
  2232. plus = '<br> \
  2233. <a href="/topic/' + url_pas(name) + '/close">(닫힘)</a> <a href="/topic/' + url_pas(name) + '/agree">(합의)</a> \
  2234. <br> \
  2235. <br> \
  2236. <input placeholder="토론명" class="form-control" name="topic" style="width: 100%;"> \
  2237. <br> \
  2238. <br> \
  2239. <button class="btn btn-primary" type="submit">만들기</button>'
  2240. rows = curs.fetchall()
  2241. for data in rows:
  2242. curs.execute("select data, date, ip, block from topic where title = ? and sub = ? and id = '1'", [name, data[0]])
  2243. row = curs.fetchall()
  2244. if(row):
  2245. it_p = 0
  2246. if(sub == '토론 목록'):
  2247. curs.execute("select title from stop where title = ? and sub = ? and close = 'O' order by sub asc", [name, data[0]])
  2248. close = curs.fetchall()
  2249. if(close):
  2250. it_p = 1
  2251. if(it_p != 1):
  2252. div += '<h2><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(data[0]) + '">' + str((i + 1)) + '. ' + data[0] + '</a></h2>'
  2253. i += 1
  2254. return(
  2255. html_minify(
  2256. template('index',
  2257. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (' + sub + ')', 0],
  2258. data = '<form style="margin-top: 0px;" method="post"> \
  2259. ' + div + plus + ' \
  2260. </form>',
  2261. menu = menu
  2262. )
  2263. )
  2264. )
  2265. @route('/login', method=['POST', 'GET'])
  2266. def login():
  2267. session = request.environ.get('beaker.session')
  2268. agent = request.environ.get('HTTP_USER_AGENT')
  2269. ip = ip_check()
  2270. ban = ban_check()
  2271. if(request.method == 'POST'):
  2272. if(ban == 1):
  2273. return(re_error('/ban'))
  2274. curs.execute("select pw from user where id = ?", [request.forms.id])
  2275. user = curs.fetchall()
  2276. if(user):
  2277. if(session.get('Now') == 1):
  2278. return(re_error('/error/11'))
  2279. if(bcrypt.checkpw(bytes(request.forms.pw, 'utf-8'), bytes(user[0][0], 'utf-8'))):
  2280. session['Now'] = 1
  2281. session['DREAMER'] = request.forms.id
  2282. curs.execute("select css from custom where user = ?", [request.forms.id])
  2283. css_data = curs.fetchall()
  2284. if(css_data):
  2285. session['Daydream'] = css_data[0][0]
  2286. else:
  2287. session['Daydream'] = ''
  2288. curs.execute("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')", [request.forms.id, ip, agent, get_time()])
  2289. conn.commit()
  2290. return(redirect('/user'))
  2291. else:
  2292. return(re_error('/error/10'))
  2293. else:
  2294. return(re_error('/error/5'))
  2295. else:
  2296. if(ban == 1):
  2297. return(re_error('/ban'))
  2298. if(session.get('Now') == 1):
  2299. return(re_error('/error/11'))
  2300. return(
  2301. html_minify(
  2302. template('index',
  2303. imp = ['로그인', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  2304. data = '<form method="post"> \
  2305. <input placeholder="아이디" name="id" type="text"> \
  2306. <br> \
  2307. <br> \
  2308. <input placeholder="비밀번호" name="pw" type="password"> \
  2309. <br> \
  2310. <br> \
  2311. <button class="btn btn-primary" type="submit">로그인</button> \
  2312. <br> \
  2313. <br> \
  2314. <span>주의 : 만약 HTTPS 연결이 아닌 경우 데이터가 유출될 가능성이 있습니다. 이에 대해 책임지지 않습니다.</span> \
  2315. </form>',
  2316. menu = [['user', '사용자']]
  2317. )
  2318. )
  2319. )
  2320. @route('/change', method=['POST', 'GET'])
  2321. def change_password():
  2322. ip = ip_check()
  2323. ban = ban_check()
  2324. if(request.method == 'POST'):
  2325. if(request.forms.pw2 == request.forms.pw3):
  2326. if(ban == 1):
  2327. return(re_error('/ban'))
  2328. curs.execute("select pw from user where id = ?", [request.forms.id])
  2329. user = curs.fetchall()
  2330. if(user):
  2331. if(re.search('(\.|:)', ip)):
  2332. return(redirect('/login'))
  2333. if(bcrypt.checkpw(bytes(request.forms.pw, 'utf-8'), bytes(user[0][0], 'utf-8'))):
  2334. hashed = bcrypt.hashpw(bytes(request.forms.pw2, 'utf-8'), bcrypt.gensalt())
  2335. curs.execute("update user set pw = ? where id = ?", [hashed.decode(), request.forms.id])
  2336. conn.commit()
  2337. return(redirect('/user'))
  2338. else:
  2339. return(re_error('/error/10'))
  2340. else:
  2341. return(re_error('/error/5'))
  2342. else:
  2343. return(re_error('/error/20'))
  2344. else:
  2345. if(ban == 1):
  2346. return(re_error('/ban'))
  2347. if(re.search('(\.|:)', ip)):
  2348. return(redirect('/login'))
  2349. return(
  2350. html_minify(
  2351. template('index',
  2352. imp = ['비밀번호 변경', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  2353. data = '<form method="post"> \
  2354. <input placeholder="아이디" name="id" type="text"> \
  2355. <br> \
  2356. <br> \
  2357. <input placeholder="현재 비밀번호" name="pw" type="password"> \
  2358. <br> \
  2359. <br> \
  2360. <input placeholder="변경할 비밀번호" name="pw2" type="password"> \
  2361. <br> \
  2362. <br> \
  2363. <input placeholder="재 확인" name="pw3" type="password"> \
  2364. <br> \
  2365. <br> \
  2366. <button class="btn btn-primary" type="submit">변경</button> \
  2367. <br> \
  2368. <br> \
  2369. <span>주의 : 만약 HTTPS 연결이 아닌 경우 데이터가 유출될 가능성이 있습니다. 이에 대해 책임지지 않습니다.</span> \
  2370. </form>',
  2371. menu = [['user', '사용자']]
  2372. )
  2373. )
  2374. )
  2375. @route('/check/<name:path>')
  2376. @route('/check/<name:path>/<name2:path>')
  2377. def user_check(name = None, name2 = None):
  2378. curs.execute("select acl from user where id = ? or id = ?", [name, name2])
  2379. user = curs.fetchall()
  2380. if(user and user[0][0] != 'user'):
  2381. if(admin_check(None, None) != 1):
  2382. return(re_error('/error/4'))
  2383. if(admin_check(4, 'check (' + name + ')') == 1):
  2384. if(name2):
  2385. if(re.search('(?:\.|:)', name)):
  2386. if(re.search('(?:\.|:)', name2)):
  2387. curs.execute("select name, ip, ua, today from ua_d where ip = ? or ip = ? order by today desc", [name, name2])
  2388. else:
  2389. curs.execute("select name, ip, ua, today from ua_d where ip = ? or name = ? order by today desc", [name, name2])
  2390. else:
  2391. if(re.search('(?:\.|:)', name2)):
  2392. curs.execute("select name, ip, ua, today from ua_d where name = ? or ip = ? order by today desc", [name, name2])
  2393. else:
  2394. curs.execute("select name, ip, ua, today from ua_d where name = ? or name = ? order by today desc", [name, name2])
  2395. elif(re.search('(?:\.|:)', name)):
  2396. curs.execute("select name, ip, ua, today from ua_d where ip = ? order by today desc", [name])
  2397. else:
  2398. curs.execute("select name, ip, ua, today from ua_d where name = ? order by today desc", [name])
  2399. row = curs.fetchall()
  2400. if(row):
  2401. c = '<table style="width: 100%; text-align: center;"> \
  2402. <tbody> \
  2403. <tr> \
  2404. <td style="width: 33.3%;">이름</td> \
  2405. <td style="width: 33.3%;">아이피</td> \
  2406. <td style="width: 33.3%;">언제</td> \
  2407. </tr>'
  2408. for data in row:
  2409. if(data[2]):
  2410. ua = data[2]
  2411. else:
  2412. ua = '<br>'
  2413. c += '<tr> \
  2414. <td>' + ip_pas(data[0]) + '</td> \
  2415. <td>' + ip_pas(data[1]) + '</td> \
  2416. <td>' + data[3] + '</td> \
  2417. </tr> \
  2418. <tr><td colspan="3">' + ua + '</td></tr>'
  2419. else:
  2420. c += '</tbody> \
  2421. </table>'
  2422. else:
  2423. c = ''
  2424. return(
  2425. html_minify(
  2426. template('index',
  2427. imp = ['다중 검사', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  2428. data = c,
  2429. menu = [['manager', '관리자']]
  2430. )
  2431. )
  2432. )
  2433. else:
  2434. return(re_error('/error/3'))
  2435. @route('/register', method=['POST', 'GET'])
  2436. def register():
  2437. ip = ip_check()
  2438. ban = ban_check()
  2439. if(ban == 1):
  2440. return(re_error('/ban'))
  2441. if(not admin_check(None, None) == 1):
  2442. curs.execute('select data from other where name = "reg"')
  2443. set_d = curs.fetchall()
  2444. if(set_d and set_d[0][0] == 'on'):
  2445. return(re_error('/ban'))
  2446. if(request.method == 'POST'):
  2447. if(request.forms.pw == request.forms.pw2):
  2448. if(re.search('(?:[^A-Za-zㄱ-힣0-9 ])', request.forms.id)):
  2449. return(re_error('/error/8'))
  2450. if(len(request.forms.id) > 32):
  2451. return(re_error('/error/7'))
  2452. curs.execute("select id from user where id = ?", [request.forms.id])
  2453. rows = curs.fetchall()
  2454. if(rows):
  2455. return(re_error('/error/6'))
  2456. hashed = bcrypt.hashpw(bytes(request.forms.pw, 'utf-8'), bcrypt.gensalt())
  2457. curs.execute("select id from user limit 1")
  2458. user_ex = curs.fetchall()
  2459. if(not user_ex):
  2460. curs.execute("insert into user (id, pw, acl) values (?, ?, '소유자')", [request.forms.id, hashed.decode()])
  2461. else:
  2462. curs.execute("insert into user (id, pw, acl) values (?, ?, 'user')", [request.forms.id, hashed.decode()])
  2463. conn.commit()
  2464. return(redirect('/login'))
  2465. else:
  2466. return(re_error('/error/20'))
  2467. else:
  2468. p = ''
  2469. curs.execute('select data from other where name = "contract"')
  2470. d = curs.fetchall()
  2471. if(d):
  2472. if(d[0][0] != ''):
  2473. p = d[0][0] + '<br><br>'
  2474. return(
  2475. html_minify(
  2476. template('index',
  2477. imp = ['회원가입', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  2478. data = '<form method="post"> \
  2479. ' + p + ' \
  2480. <input placeholder="아이디" name="id" type="text"> \
  2481. <br> \
  2482. <br> \
  2483. <input placeholder="비밀번호" name="pw" type="password"> \
  2484. <br> \
  2485. <br> \
  2486. <input placeholder="재 확인" name="pw2" type="password"> \
  2487. <br> \
  2488. <br> \
  2489. <button class="btn btn-primary" type="submit">가입</button> \
  2490. <br> \
  2491. <br> \
  2492. <span>주의 : 만약 HTTPS 연결이 아닌 경우 데이터가 유출될 가능성이 있습니다. 이에 대해 책임지지 않습니다.</span> \
  2493. </form>',
  2494. menu = [['user', '사용자']]
  2495. )
  2496. )
  2497. )
  2498. @route('/logout')
  2499. def logout():
  2500. session = request.environ.get('beaker.session')
  2501. session['Now'] = 0
  2502. session.pop('DREAMER', None)
  2503. return(redirect('/user'))
  2504. @route('/ban/<name:path>', method=['POST', 'GET'])
  2505. def user_ban(name = None):
  2506. curs.execute("select acl from user where id = ?", [name])
  2507. user = curs.fetchall()
  2508. if(user and user[0][0] != 'user'):
  2509. if(admin_check(None, None) != 1):
  2510. return(re_error('/error/4'))
  2511. if(request.method == 'POST'):
  2512. if(admin_check(1, 'ban (' + name + ')') == 1):
  2513. ip = ip_check()
  2514. if(request.forms.year == '09'):
  2515. end = ''
  2516. else:
  2517. end = request.forms.year + '-' + request.forms.month + '-' + request.forms.day
  2518. curs.execute("select block from ban where block = ?", [name])
  2519. row = curs.fetchall()
  2520. if(row):
  2521. rb_plus(name, '해제', get_time(), ip, '')
  2522. curs.execute("delete from ban where block = ?", [name])
  2523. else:
  2524. b = re.search("^([0-9]{1,3}\.[0-9]{1,3})$", name)
  2525. if(b):
  2526. band_d = 'O'
  2527. else:
  2528. band_d = ''
  2529. rb_plus(name, end, get_time(), ip, request.forms.why)
  2530. curs.execute("insert into ban (block, end, why, band) values (?, ?, ?, ?)", [name, end, request.forms.why, band_d])
  2531. conn.commit()
  2532. return(redirect('/ban/' + url_pas(name)))
  2533. else:
  2534. return(re_error('/error/3'))
  2535. else:
  2536. if(admin_check(1, None) == 1):
  2537. curs.execute("select * from ban where block = ?", [name])
  2538. row = curs.fetchall()
  2539. if(row):
  2540. now = '차단 해제'
  2541. data = ''
  2542. else:
  2543. b = re.search("^([0-9]{1,3}\.[0-9]{1,3})$", name)
  2544. if(b):
  2545. now = '대역 차단'
  2546. else:
  2547. now = '차단'
  2548. year_n = int("%04d" % (time.localtime().tm_year))
  2549. year = '<option value="09">영구</option>'
  2550. for i in range(year_n, year_n + 51):
  2551. if(i == year_n):
  2552. year += '<option value="' + str(i) + '" selected>' + str(i) + '</option>'
  2553. else:
  2554. year += '<option value="' + str(i) + '">' + str(i) + '</option>'
  2555. month = '<option value="1" selected>1</option>'
  2556. for i in range(2, 13):
  2557. month += '<option value="' + str(i) + '">' + str(i) + '</option>'
  2558. day = '<option value="1" selected>1</option>'
  2559. for i in range(2, 32):
  2560. day += '<option value="' + str(i) + '">' + str(i) + '</option>'
  2561. data = '<select name="year"> \
  2562. ' + year + ' \
  2563. </select> \
  2564. <select name="month"> \
  2565. ' + month + ' \
  2566. </select> \
  2567. <select name="day"> \
  2568. ' + day + ' \
  2569. </select> \
  2570. <br> \
  2571. <br> \
  2572. <input placeholder="사유" class="form-control" name="why" style="width: 100%;"> \
  2573. <br> \
  2574. <br>'
  2575. return(
  2576. html_minify(
  2577. template('index',
  2578. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (' + now + ')', 0],
  2579. data = '<form method="post"> \
  2580. ' + data + ' \
  2581. <button class="btn btn-primary" type="submit">' + now + '</button> \
  2582. </form>',
  2583. menu = [['manager', '관리자']]
  2584. )
  2585. )
  2586. )
  2587. else:
  2588. return(re_error('/error/3'))
  2589. @route('/user_acl/<name:path>', method=['POST', 'GET'])
  2590. def acl(name = None):
  2591. ip = ip_check()
  2592. if(ip != name or re.search("(\.|:)", name)):
  2593. return(redirect('/login'))
  2594. if(request.method == 'POST'):
  2595. curs.execute("select acl from data where title = ?", ['사용자:' + name])
  2596. acl_d = curs.fetchall()
  2597. if(acl_d):
  2598. if(request.forms.select == 'all'):
  2599. curs.execute("update data set acl = 'all' where title = ?", ['사용자:' + name])
  2600. elif(request.forms.select == 'user'):
  2601. curs.execute("update data set acl = 'user' where title = ?", ['사용자:' + name])
  2602. else:
  2603. curs.execute("update data set acl = '' where title = ?", ['사용자:' + name])
  2604. conn.commit()
  2605. return(redirect('/w/' + url_pas('사용자:' + name)))
  2606. curs.execute("select acl from data where title = ?", ['사용자:' + name])
  2607. acl_d = curs.fetchall()
  2608. if(acl_d):
  2609. if(acl_d[0][0] == 'all'):
  2610. now = '모두'
  2611. elif(acl_d[0][0] == 'user'):
  2612. now = '사용자'
  2613. else:
  2614. now = '일반'
  2615. return(
  2616. html_minify(
  2617. template('index',
  2618. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (SET)', 0],
  2619. data = '<span>현재 ACL : ' + now + '</span> \
  2620. <br> \
  2621. <br> \
  2622. <form method="post"> \
  2623. <select name="select"> \
  2624. <option value="all">모두</option> \
  2625. <option value="user">사용자</option> \
  2626. <option value="normal" selected="selected">일반</option> \
  2627. </select> \
  2628. <br> \
  2629. <br> \
  2630. <button class="btn btn-primary" type="submit">ACL 변경</button> \
  2631. </form>',
  2632. menu = [['user', '사용자']]
  2633. )
  2634. )
  2635. )
  2636. else:
  2637. return(redirect('/w/' + url_pas(name)))
  2638. @route('/acl/<name:path>', method=['POST', 'GET'])
  2639. def acl(name = None):
  2640. if(request.method == 'POST'):
  2641. if(admin_check(5, 'acl (' + name + ')') == 1):
  2642. curs.execute("select acl from data where title = ?", [name])
  2643. row = curs.fetchall()
  2644. if(row):
  2645. if(request.forms.select == 'admin'):
  2646. curs.execute("update data set acl = 'admin' where title = ?", [name])
  2647. elif(request.forms.select == 'user'):
  2648. curs.execute("update data set acl = 'user' where title = ?", [name])
  2649. else:
  2650. curs.execute("update data set acl = '' where title = ?", [name])
  2651. conn.commit()
  2652. return(redirect('/w/' + url_pas(name)))
  2653. else:
  2654. return(re_error('/error/3'))
  2655. else:
  2656. if(admin_check(5, None) == 1):
  2657. curs.execute("select acl from data where title = ?", [name])
  2658. row = curs.fetchall()
  2659. if(row):
  2660. if(row[0][0] == 'admin'):
  2661. now = '관리자'
  2662. elif(row[0][0] == 'user'):
  2663. now = '사용자'
  2664. else:
  2665. now = '일반'
  2666. return(
  2667. html_minify(
  2668. template('index',
  2669. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (ACL)', 0],
  2670. data = '<span>현재 ACL : ' + now + '</span> \
  2671. <br> \
  2672. <br> \
  2673. <form method="post"> \
  2674. <select name="select"> \
  2675. <option value="admin" selected="selected">관리자</option> \
  2676. <option value="user">사용자</option> \
  2677. <option value="normal">일반</option> \
  2678. </select> \
  2679. <br> \
  2680. <br> \
  2681. <button class="btn btn-primary" type="submit">ACL 변경</button> \
  2682. </form>',
  2683. menu = [['w/' + url_pas(name), '문서'], ['manager', '관리자']]
  2684. )
  2685. )
  2686. )
  2687. else:
  2688. return(redirect('/w/' + url_pas(name)) )
  2689. else:
  2690. return(re_error('/error/3'))
  2691. @route('/admin/<name:path>', method=['POST', 'GET'])
  2692. def user_admin(name = None):
  2693. if(request.method == 'POST'):
  2694. if(admin_check(None, 'admin (' + name + ')') == 1):
  2695. if(request.forms.select == 'X'):
  2696. curs.execute("update user set acl = 'user' where id = ?", [name])
  2697. else:
  2698. curs.execute("update user set acl = ? where id = ?", [request.forms.select, name])
  2699. conn.commit()
  2700. return(redirect('/admin/' + url_pas(name)))
  2701. else:
  2702. return(re_error('/error/3'))
  2703. else:
  2704. if(admin_check(None, None) == 1):
  2705. curs.execute("select acl from user where id = ?", [name])
  2706. user = curs.fetchall()
  2707. if(user):
  2708. div = '<option value="X">X</option>'
  2709. curs.execute('select name from alist order by name asc')
  2710. get_alist = curs.fetchall()
  2711. if(get_alist):
  2712. i = 0
  2713. name_rem = ''
  2714. for data in get_alist:
  2715. if(name_rem != data[0]):
  2716. name_rem = data[0]
  2717. if(user[0][0] == data[0]):
  2718. div += '<option value="' + data[0] + '" selected="selected">' + data[0] + '</option>'
  2719. else:
  2720. div += '<option value="' + data[0] + '">' + data[0] + '</option>'
  2721. return(
  2722. html_minify(
  2723. template('index',
  2724. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (권한 부여)', 0],
  2725. data = '<form method="post"> \
  2726. <select name="select"> \
  2727. ' + div + ' \
  2728. </select> \
  2729. <br> \
  2730. <br> \
  2731. <button class="btn btn-primary" type="submit">변경</button> \
  2732. </form>',
  2733. menu = [['manager', '관리자']]
  2734. )
  2735. )
  2736. )
  2737. else:
  2738. return(re_error('/error/5'))
  2739. else:
  2740. return(re_error('/error/3'))
  2741. @route('/w/<name:path>/r/<a:int>/diff/<b:int>')
  2742. def diff_data(name = None, a = None, b = None):
  2743. curs.execute("select data from history where id = ? and title = ?", [str(a), name])
  2744. a_raw_data = curs.fetchall()
  2745. if(a_raw_data):
  2746. curs.execute("select data from history where id = ? and title = ?", [str(b), name])
  2747. b_raw_data = curs.fetchall()
  2748. if(b_raw_data):
  2749. a_data = html.escape(a_raw_data[0][0])
  2750. b_data = html.escape(b_raw_data[0][0])
  2751. if(a_data == b_data):
  2752. result = '내용이 같습니다.'
  2753. else:
  2754. diff_data = difflib.SequenceMatcher(None, a_data, b_data)
  2755. result_1 = diff(diff_data, 1)
  2756. result_2 = diff(diff_data, 0)
  2757. if(a_data == result_1):
  2758. result = '<pre>' + result_2 + '</pre>'
  2759. elif(b_data == result_2):
  2760. result = '<pre>' + result_1 + '</pre>'
  2761. else:
  2762. result = '<pre>' + result_1 + '<hr>' + result_2 + '</pre>'
  2763. return(
  2764. html_minify(
  2765. template('index',
  2766. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (비교)', 0],
  2767. data = result,
  2768. menu = [['history/' + url_pas(name), '역사']]
  2769. )
  2770. )
  2771. )
  2772. return(redirect('/history/' + url_pas(name)))
  2773. @route('/down/<name:path>')
  2774. def down(name = None):
  2775. curs.execute("select title from data where title like ?", ['%' + name + '/%'])
  2776. under = curs.fetchall()
  2777. div = '<ul>'
  2778. i = 0
  2779. for data in under:
  2780. div += '<li>' + str(i + 1) + '. <a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  2781. i += 1
  2782. div += '</ul>'
  2783. return(
  2784. html_minify(
  2785. template('index',
  2786. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (하위)', 0],
  2787. data = div,
  2788. menu = [['w/' + url_pas(name), '문서']]
  2789. )
  2790. )
  2791. )
  2792. @route('/w/<name:path>')
  2793. @route('/w/<name:path>/r/<num:int>')
  2794. @route('/w/<name:path>/from/<redirect:path>')
  2795. def read_view(name = None, num = None, redirect = None):
  2796. data_none = 0
  2797. sub = ''
  2798. acl = ''
  2799. div = ''
  2800. topic = 0
  2801. if(not num):
  2802. session = request.environ.get('beaker.session')
  2803. if(session.get('View_List')):
  2804. m = re.findall('([^\n]+)\n', session.get('View_List'))
  2805. if(m[-1] != name):
  2806. session['View_List'] += name + '\n'
  2807. if(len(m) > 50):
  2808. session['View_List'] = re.sub('([^\n]+)\n', '', session.get('View_List'), 1)
  2809. else:
  2810. session['View_List'] = name + '\n'
  2811. curs.execute("select sub from rd where title = ? order by date desc", [name])
  2812. rows = curs.fetchall()
  2813. for data in rows:
  2814. curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [name, data[0]])
  2815. row = curs.fetchall()
  2816. if(not row):
  2817. topic = 1
  2818. break
  2819. curs.execute("select title from data where title like ?", ['%' + name + '/%'])
  2820. under = curs.fetchall()
  2821. if(under):
  2822. down = 1
  2823. else:
  2824. down = 0
  2825. m = re.search("^(.*)\/(.*)$", name)
  2826. if(m):
  2827. uppage = m.groups()[0]
  2828. else:
  2829. uppage = 0
  2830. if(admin_check(5, None) == 1):
  2831. admin_memu = 1
  2832. else:
  2833. admin_memu = 0
  2834. if(re.search("^분류:", name)):
  2835. curs.execute("delete from back where title = ? and type='cat' and link = ''", [name])
  2836. conn.commit()
  2837. curs.execute("select link from back where title = ? and type='cat' order by link asc", [name])
  2838. rows = curs.fetchall()
  2839. if(rows):
  2840. div = '[목차(없음)]\r\n== 분류 ==\r\n'
  2841. u_div = ''
  2842. i = 0
  2843. for data in rows:
  2844. if(re.search('^분류:', data[0])):
  2845. if(u_div == ''):
  2846. u_div = '=== 하위 분류 ===\r\n'
  2847. u_div += ' * [[:' + data[0] + ']]\r\n'
  2848. else:
  2849. div += ' * [[' + data[0] + ']]\r\n'
  2850. div += u_div
  2851. if(num):
  2852. curs.execute("select title from hidhi where title = ? and re = ?", [name, str(num)])
  2853. hid = curs.fetchall()
  2854. if(hid and admin_check(6, None) != 1):
  2855. return(redirect('/history/' + url_pas(name)))
  2856. curs.execute("select title, data from history where title = ? and id = ?", [name, str(num)])
  2857. else:
  2858. curs.execute("select acl, data from data where title = ?", [name])
  2859. rows = curs.fetchall()
  2860. if(rows):
  2861. if(not num):
  2862. if(rows[0][0] == 'admin'):
  2863. acl = ' (관리자)'
  2864. elif(rows[0][0] == 'user'):
  2865. acl = ' (사용자)'
  2866. elsedata = rows[0][1]
  2867. else:
  2868. data_none = 1
  2869. response.status = 404
  2870. elsedata = ''
  2871. m = re.search("^사용자:([^/]*)", name)
  2872. if(m):
  2873. g = m.groups()
  2874. curs.execute("select acl from user where id = ?", [g[0]])
  2875. test = curs.fetchall()
  2876. if(test and test[0][0] != 'user'):
  2877. acl = ' (관리자)'
  2878. else:
  2879. acl = ''
  2880. if(rows):
  2881. if(rows[0][0] == 'all'):
  2882. acl += ' (모두)'
  2883. elif(rows[0][0] == 'user'):
  2884. acl += ' (사용자)'
  2885. curs.execute("select block from ban where block = ?", [g[0]])
  2886. user = curs.fetchall()
  2887. if(user):
  2888. sub = ' (차단)'
  2889. if(redirect):
  2890. elsedata = re.sub("^#(?:redirect|넘겨주기) (?P<in>[^\n]*)", " * [[\g<in>]] 문서로 넘겨주기", elsedata)
  2891. enddata = namumark(name, elsedata, 0, 0, 1)
  2892. if(data_none == 1):
  2893. menu = [['edit/' + url_pas(name), '생성'], ['topic/' + url_pas(name), topic], ['history/' + url_pas(name), '역사'], ['move/' + url_pas(name), '이동'], ['xref/' + url_pas(name), '역링크']]
  2894. else:
  2895. menu = [['edit/' + url_pas(name), '수정'], ['topic/' + url_pas(name), topic], ['history/' + url_pas(name), '역사'], ['delete/' + url_pas(name), '삭제'], ['move/' + url_pas(name), '이동'], ['raw/' + url_pas(name), '원본'], ['xref/' + url_pas(name), '역링크']]
  2896. if(admin_memu == 1):
  2897. menu += [['acl/' + url_pas(name), 'ACL']]
  2898. if(redirect):
  2899. menu += [['w/' + url_pas(name), '넘기기']]
  2900. enddata = '<ul id="redirect"><li><a href="/w/' + url_pas(redirect) + '/from/' + url_pas(name) + '">' + redirect + '</a>에서 넘어 왔습니다.</li></ul><br>' + enddata
  2901. if(uppage != 0):
  2902. menu += [['w/' + url_pas(uppage), '상위']]
  2903. if(down):
  2904. menu += [['down/' + url_pas(name), '하위']]
  2905. if(num):
  2906. menu = [['history/' + url_pas(name), '역사']]
  2907. sub = ' (' + str(num) + '판)'
  2908. acl = ''
  2909. r_date = 0
  2910. else:
  2911. curs.execute("select date from history where title = ? order by date desc limit 1", [name])
  2912. date = curs.fetchall()
  2913. if(date):
  2914. r_date = date[0][0]
  2915. else:
  2916. r_date = 0
  2917. return(
  2918. html_minify(
  2919. template('index',
  2920. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), sub + acl, r_date],
  2921. data = enddata + namumark(name, div, 0, 0, 0),
  2922. menu = menu
  2923. )
  2924. )
  2925. )
  2926. @route('/user/<name:path>/topic')
  2927. @route('/user/<name:path>/topic/<num:int>')
  2928. def user_topic_list(name = None, num = 1):
  2929. if(num * 50 <= 0):
  2930. v = 50
  2931. else:
  2932. v = num * 50
  2933. i = v - 50
  2934. ydmin = admin_check(1, None)
  2935. div = '<table style="width: 100%; text-align: center;"> \
  2936. <tbody> \
  2937. <tr> \
  2938. <td style="width: 33.3%;">토론명</td> \
  2939. <td style="width: 33.3%;">작성자</td> \
  2940. <td style="width: 33.3%;">시간</td> \
  2941. </tr>'
  2942. div = '<a href="/record/' + url_pas(name) + '">(기여 기록)</a><br><br>' + div
  2943. curs.execute("select title, id, sub, ip, date from topic where ip = ? order by date desc limit ?, ?", [name, str(i), str(v)])
  2944. rows = curs.fetchall()
  2945. if(rows):
  2946. for data in rows:
  2947. title = html.escape(data[0])
  2948. sub = html.escape(data[2])
  2949. if(ydmin == 1):
  2950. curs.execute("select * from ban where block = ?", [data[3]])
  2951. row = curs.fetchall()
  2952. if(row):
  2953. ban = ' <a href="/ban/' + url_pas(data[3]) + '">(해제)</a>'
  2954. else:
  2955. ban = ' <a href="/ban/' + url_pas(data[3]) + '">(차단)</a>'
  2956. else:
  2957. ban = ''
  2958. ip = ip_pas(data[3])
  2959. div += '<tr> \
  2960. <td> \
  2961. <a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[2]) + '#' + data[1] + '">' + title + '#' + data[1] + '</a> (' + sub + ') \
  2962. </td> \
  2963. <td>' + ip + ban + '</td> \
  2964. <td>' + data[4] + '</td> \
  2965. </tr>'
  2966. else:
  2967. div += '</tbody> \
  2968. </table>'
  2969. else:
  2970. div = ''
  2971. div += '<br><a href="/user/' + url_pas(name) + '/topic/' + str(num - 1) + '">(이전)</a> <a href="/user/' + url_pas(name) + '/topic/' + str(num + 1) + '">(이후)</a>'
  2972. curs.execute("select end, why from ban where block = ?", [name])
  2973. ban_it = curs.fetchall()
  2974. if(ban_it):
  2975. sub = ' (차단)'
  2976. else:
  2977. sub = 0
  2978. return(
  2979. html_minify(
  2980. template('index',
  2981. imp = ['토론 기록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), sub, 0],
  2982. data = div,
  2983. menu = [['other', '기타'], ['user', '사용자']]
  2984. )
  2985. )
  2986. )
  2987. @route('/upload', method=['GET', 'POST'])
  2988. def upload():
  2989. if(ban_check() == 1):
  2990. return(re_error('/ban'))
  2991. if(request.method == 'POST'):
  2992. data = request.files.f_data
  2993. if(data):
  2994. if(int(wiki_set(4)) * 1024 * 1024 < request.content_length):
  2995. return re_error('/error/17')
  2996. value = os.path.splitext(data.filename)[1]
  2997. if(not value in ['.jpeg', '.jpg', '.gif', '.png', '.webp', '.JPEG', '.JPG', '.GIF', '.PNG', '.WEBP']):
  2998. return re_error('/error/14')
  2999. if(request.forms.get('f_name')):
  3000. name = request.forms.get('f_name') + value
  3001. else:
  3002. name = data.filename
  3003. piece = os.path.splitext(name)
  3004. e_data = sha224(piece[0]) + piece[1]
  3005. ip = ip_check()
  3006. if(request.forms.get('f_lice')):
  3007. lice = request.forms.get('f_lice')
  3008. else:
  3009. if(re.search('(?:\.|:)', ip)):
  3010. lice = ip + ' 올림'
  3011. else:
  3012. lice = '[[사용자:' + ip + ']] 올림'
  3013. if(os.path.exists(os.path.join('image', e_data))):
  3014. return(re_error('/error/16'))
  3015. data.save(os.path.join('image', e_data))
  3016. curs.execute("select title from data where title = ?", ['파일:' + name])
  3017. exist = curs.fetchall()
  3018. if(exist):
  3019. curs.execute("delete from data where title = ?", ['파일:' + name])
  3020. curs.execute("insert into data (title, data, acl) values (?, ?, 'admin')", ['파일:' + name, '[[파일:' + name + ']][br][br]{{{[[파일:' + name + ']]}}}[br][br]' + lice])
  3021. conn.commit()
  3022. history_plus(
  3023. '파일:' + name,
  3024. '[[파일:' + name + ']][br][br]{{{[[파일:' + name + ']]}}}[br][br]' + lice,
  3025. get_time(),
  3026. ip,
  3027. '(파일 올림)',
  3028. '0'
  3029. )
  3030. return(redirect('/w/파일:' + name))
  3031. else:
  3032. return(re_error('/error/9'))
  3033. else:
  3034. return(
  3035. html_minify(
  3036. template('index',
  3037. imp = ['파일 올리기', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  3038. data = '<form method="post" enctype="multipart/form-data" accept-charset="utf8"> \
  3039. <input type="file" name="f_data"> \
  3040. <br> \
  3041. <br> \
  3042. <input placeholder="파일 이름" name="f_name" type="text"> \
  3043. <br> \
  3044. <br> \
  3045. <input placeholder="라이선스" name="f_lice" type="text"> \
  3046. <br> \
  3047. <br> \
  3048. <span>한글이 되지 않을 때도 있습니다.</span> \
  3049. <br> \
  3050. <br> \
  3051. <button class="btn btn-primary" type="submit">저장</button> \
  3052. </form>',
  3053. menu = [['other', '기타']]
  3054. )
  3055. )
  3056. )
  3057. @route('/user')
  3058. def user_info():
  3059. ip = ip_check()
  3060. raw_ip = ip
  3061. curs.execute("select acl from user where id = ?", [ip])
  3062. rows = curs.fetchall()
  3063. if(ban_check() == 0):
  3064. if(rows):
  3065. if(rows[0][0] != 'user'):
  3066. acl = rows[0][0]
  3067. else:
  3068. acl = '사용자'
  3069. else:
  3070. acl = '일반'
  3071. else:
  3072. acl = '차단'
  3073. ip = ip_pas(ip)
  3074. if(custom(0) != 0):
  3075. plus = ' * [[wiki:logout|로그아웃]]\r\n * [[wiki:change|비밀번호 변경]]'
  3076. else:
  3077. plus = ' * [[wiki:login|로그인]]'
  3078. return(
  3079. html_minify(
  3080. template('index',
  3081. imp = ['사용자 메뉴', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  3082. data = ip + '<br><br>' + namumark('', '권한 상태 : ' + acl + '\r\n' + \
  3083. '[목차(없음)]\r\n' + \
  3084. '== 로그인 ==\r\n' + \
  3085. plus + '\r\n' + \
  3086. ' * [[wiki:register|회원가입]]\r\n' + \
  3087. '== 사용자 ==\r\n' + \
  3088. ' * [[wiki:user_acl/' + url_pas(raw_ip) + '|사용자 문서 ACL]]\r\n' + \
  3089. ' * [[wiki:custom_css|사용자 CSS]]\r\n' + \
  3090. ' * [[wiki:custom_js|사용자 JS]]\r\n' + \
  3091. '== 기타 ==\r\n' + \
  3092. ' * [[wiki:alarm|알림]]\r\n' + \
  3093. ' * [[wiki:view_log|지나온 문서]]\r\n' + \
  3094. ' * [[wiki:count|기여 횟수]]\r\n', 0, 0, 0),
  3095. menu = 0
  3096. )
  3097. )
  3098. )
  3099. @route('/view_log')
  3100. def view_log():
  3101. session = request.environ.get('beaker.session')
  3102. data = '<ul>'
  3103. if(session.get('View_List')):
  3104. data += '<li>최근 50개</li><br><br>'
  3105. m = re.findall('([^\n]+)\n', session.get('View_List'))
  3106. for d in m:
  3107. data += '<li><a href="/w/' + url_pas(d) + '">' + d + '</a></li>'
  3108. else:
  3109. data += '<li>기록 없음</li>'
  3110. data += '</ul>'
  3111. return(
  3112. html_minify(
  3113. template('index',
  3114. imp = ['지나온 문서', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  3115. data = data,
  3116. menu = [['user', '사용자']]
  3117. )
  3118. )
  3119. )
  3120. @route('/custom_css', method=['GET', 'POST'])
  3121. def custom_css_view():
  3122. session = request.environ.get('beaker.session')
  3123. ip = ip_check()
  3124. if(request.method == 'POST'):
  3125. if(not re.search('(\.|:)', ip)):
  3126. curs.execute("select * from custom where user = ?", [ip])
  3127. css_data = curs.fetchall()
  3128. if(css_data):
  3129. curs.execute("update custom set css = ? where user = ?", [request.forms.content, ip])
  3130. else:
  3131. curs.execute("insert into custom (user, css) values (?, ?)", [ip, request.forms.content])
  3132. conn.commit()
  3133. session['Daydream'] = request.forms.content
  3134. return(redirect('/user'))
  3135. else:
  3136. if(not re.search('(\.|:)', ip)):
  3137. start = ''
  3138. curs.execute("select css from custom where user = ?", [ip])
  3139. css_data = curs.fetchall()
  3140. if(css_data):
  3141. data = css_data[0][0]
  3142. else:
  3143. data = ''
  3144. else:
  3145. start = '<span>비 로그인의 경우에는 로그인하면 날아갑니다.</span><br><br>'
  3146. try:
  3147. data = session['Daydream']
  3148. except:
  3149. data = ''
  3150. return(
  3151. html_minify(
  3152. template('index',
  3153. imp = ['사용자 CSS', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  3154. data = start + ' \
  3155. <form method="post"> \
  3156. <textarea rows="30" cols="100" name="content">'\
  3157. + data + \
  3158. '</textarea> \
  3159. <br> \
  3160. <br> \
  3161. <div class="form-actions"> \
  3162. <button class="btn btn-primary" type="submit">저장</button> \
  3163. </div> \
  3164. </form>',
  3165. menu = [['user', '사용자']]
  3166. )
  3167. )
  3168. )
  3169. @route('/custom_js', method=['GET', 'POST'])
  3170. def custom_js_view():
  3171. session = request.environ.get('beaker.session')
  3172. ip = ip_check()
  3173. if(request.method == 'POST'):
  3174. if(not re.search('(\.|:)', ip)):
  3175. curs.execute("select * from custom where user = ?", [ip + ' (js)'])
  3176. js_data = curs.fetchall()
  3177. if(js_data):
  3178. curs.execute("update custom set css = ? where user = ?", [request.forms.content, ip + ' (js)'])
  3179. else:
  3180. curs.execute("insert into custom (user, css) values (?, ?)", [ip + ' (js)', request.forms.content])
  3181. conn.commit()
  3182. session['AQUARIUM'] = request.forms.content
  3183. return(redirect('/user'))
  3184. else:
  3185. if(not re.search('(\.|:)', ip)):
  3186. start = ''
  3187. curs.execute("select css from custom where user = ?", [ip + ' (js)'])
  3188. js_data = curs.fetchall()
  3189. if(js_data):
  3190. data = js_data[0][0]
  3191. else:
  3192. data = ''
  3193. else:
  3194. start = '<span>비 로그인의 경우에는 로그인하면 날아갑니다.</span><br><br>'
  3195. try:
  3196. data = session['AQUARIUM']
  3197. except:
  3198. data = ''
  3199. return(
  3200. html_minify(
  3201. template('index',
  3202. imp = ['사용자 JS', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  3203. data = start + ' \
  3204. <form method="post"> \
  3205. <textarea rows="30" cols="100" name="content">'\
  3206. + data + \
  3207. '</textarea> \
  3208. <br> \
  3209. <br> \
  3210. <div class="form-actions"> \
  3211. <button class="btn btn-primary" type="submit">저장</button> \
  3212. </div> \
  3213. </form>',
  3214. menu = [['user', '사용자']]
  3215. )
  3216. )
  3217. )
  3218. @route('/count')
  3219. @route('/count/<name:path>')
  3220. def count_edit(name = None):
  3221. if(name == None):
  3222. that = ip_check()
  3223. else:
  3224. that = name
  3225. curs.execute("select count(title) from history where ip = ?", [that])
  3226. count = curs.fetchall()
  3227. if(count):
  3228. data = count[0][0]
  3229. else:
  3230. data = 0
  3231. curs.execute("select count(title) from topic where ip = ?", [that])
  3232. count = curs.fetchall()
  3233. if(count):
  3234. t_data = count[0][0]
  3235. else:
  3236. t_data = 0
  3237. return(
  3238. html_minify(
  3239. template('index',
  3240. imp = ['기여 횟수', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  3241. data = namumark("", "||<-2><:> " + that + " ||\r\n||<:> 기여 횟수 ||<:> " + str(data) + "||\r\n||<:> 토론 횟수 ||<:> " + str(t_data) + "||", 0, 0, 0),
  3242. menu = [['user', '사용자']]
  3243. )
  3244. )
  3245. )
  3246. @route('/random')
  3247. def random():
  3248. curs.execute("select title from data order by random() limit 1")
  3249. rows = curs.fetchall()
  3250. if(rows):
  3251. return(redirect('/w/' + url_pas(rows[0][0])))
  3252. else:
  3253. return(redirect('/'))
  3254. @route('/views/<name:path>')
  3255. def views(name = None):
  3256. if(re.search('\/', name)):
  3257. m = re.search('^(.*)\/(.*)$', name)
  3258. if(m):
  3259. n = m.groups()
  3260. plus = '/' + n[0]
  3261. rename = n[1]
  3262. else:
  3263. plus = ''
  3264. rename = name
  3265. else:
  3266. plus = ''
  3267. rename = name
  3268. return(
  3269. static_file(rename,
  3270. root = './views' + plus
  3271. )
  3272. )
  3273. @error(404)
  3274. def error_404(error):
  3275. try:
  3276. curs.execute("select title from data limit 1")
  3277. return(redirect('/w/' + url_pas(wiki_set(2))))
  3278. except:
  3279. return(redirect('/setup'))
  3280. @error(500)
  3281. def error_500(error):
  3282. try:
  3283. curs.execute("select title from data limit 1")
  3284. return(error)
  3285. except:
  3286. return(redirect('/setup'))
  3287. run(
  3288. app = app,
  3289. server = 'tornado',
  3290. host = '0.0.0.0',
  3291. port = int(set_data['port'])
  3292. )