2
0

app.py 146 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793
  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. conn.commit()
  179. except:
  180. pass
  181. @route('/setup', method=['GET', 'POST'])
  182. def setup():
  183. try:
  184. curs.execute("select title from data limit 1")
  185. except:
  186. try:
  187. curs.execute("create table data(title text, data text, acl text)")
  188. except:
  189. pass
  190. try:
  191. curs.execute("create table history(id text, title text, data text, date text, ip text, send text, leng text)")
  192. except:
  193. pass
  194. try:
  195. curs.execute("create table rd(title text, sub text, date text)")
  196. except:
  197. pass
  198. try:
  199. curs.execute("create table user(id text, pw text, acl text)")
  200. except:
  201. pass
  202. try:
  203. curs.execute("create table ban(block text, end text, why text, band text)")
  204. except:
  205. pass
  206. try:
  207. curs.execute("create table topic(id text, title text, sub text, data text, date text, ip text, block text, top text)")
  208. except:
  209. pass
  210. try:
  211. curs.execute("create table stop(title text, sub text, close text)")
  212. except:
  213. pass
  214. try:
  215. curs.execute("create table rb(block text, end text, today text, blocker text, why text)")
  216. except:
  217. pass
  218. try:
  219. curs.execute("create table back(title text, link text, type text)")
  220. except:
  221. pass
  222. try:
  223. curs.execute("create table cat(title text, cat text)")
  224. except:
  225. pass
  226. try:
  227. curs.execute("create table hidhi(title text, re text)")
  228. except:
  229. pass
  230. try:
  231. curs.execute("create table agreedis(title text, sub text)")
  232. except:
  233. pass
  234. try:
  235. curs.execute("create table custom(user text, css text)")
  236. except:
  237. pass
  238. try:
  239. curs.execute("create table other(name text, data text)")
  240. except:
  241. pass
  242. try:
  243. curs.execute("create table alist(name text, acl text)")
  244. curs.execute("insert into alist (name, acl) values ('소유자', 'owner')")
  245. except:
  246. pass
  247. try:
  248. curs.execute("create table re_admin(who text, what text, time text)")
  249. except:
  250. pass
  251. try:
  252. curs.execute("create table move(origin text, new text, date text, who text, send text)")
  253. except:
  254. pass
  255. try:
  256. curs.execute("create table alarm(name text, data text, date text)")
  257. except:
  258. pass
  259. try:
  260. curs.execute("create table ua_d(name text, ip text, ua text, today text, sub text)")
  261. except:
  262. pass
  263. conn.commit()
  264. return(redirect('/'))
  265. @route('/del_alarm')
  266. def del_alarm():
  267. curs.execute("delete from alarm where name = ?", [ip_check()])
  268. conn.commit()
  269. return(redirect('/alarm'))
  270. @route('/alarm')
  271. def alarm():
  272. ip = ip_check()
  273. if(re.search('(?:\.|:)', ip)):
  274. return(redirect('/login'))
  275. da = '<ul>'
  276. curs.execute("select data, date from alarm where name = ? order by date desc", [ip])
  277. dt = curs.fetchall()
  278. if(dt):
  279. da = '<a href="/del_alarm">(알람 삭제)</a><br><br>' + da
  280. for do in dt:
  281. da += '<li>' + do[0] + ' / ' + do[1] + '</li>'
  282. else:
  283. da += '<li>알림이 없습니다.</li>'
  284. da += '</ul>'
  285. return(
  286. html_minify(
  287. template('index',
  288. imp = ['알림', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  289. data = da,
  290. menu = [['user', '사용자']]
  291. )
  292. )
  293. )
  294. @route('/edit_set', method=['POST', 'GET'])
  295. @route('/edit_set/<num:int>', method=['POST', 'GET'])
  296. def edit_set(num = 0):
  297. if(num == 0):
  298. return(
  299. html_minify(
  300. template('index',
  301. imp = ['설정 편집', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  302. data = '<ul> \
  303. <li><a href="/edit_set/1">기본 설정</a></li> \
  304. <li><a href="/edit_set/2">문구 관련</a></li> \
  305. </ul>',
  306. menu = [['manager', '관리자']]
  307. )
  308. )
  309. )
  310. elif(num == 1):
  311. if(admin_check(None, 'edit_set') == 1):
  312. if(request.method == 'POST'):
  313. curs.execute("update other set data = ? where name = ?", [request.forms.name, 'name'])
  314. curs.execute("update other set data = ? where name = 'frontpage'", [request.forms.frontpage])
  315. curs.execute("update other set data = ? where name = 'license'", [request.forms.license])
  316. curs.execute("update other set data = ? where name = 'upload'", [request.forms.upload])
  317. curs.execute("update other set data = ? where name = 'skin'", [request.forms.skin])
  318. curs.execute("update other set data = ? where name = 'edit'", [request.forms.edit])
  319. curs.execute("update other set data = ? where name = 'reg'", [request.forms.reg])
  320. conn.commit()
  321. return(redirect('/edit_set/1'))
  322. else:
  323. i_list = ['name', 'frontpage', 'license', 'upload', 'skin', 'edit', 'reg']
  324. n_list = ['무명위키', '위키:대문', 'CC 0', '2', '', 'normal', '']
  325. d_list = []
  326. x = 0
  327. for i in i_list:
  328. curs.execute('select data from other where name = ?', [i])
  329. sql_d = curs.fetchall()
  330. if(sql_d):
  331. d_list += [sql_d[0][0]]
  332. else:
  333. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  334. d_list += [n_list[x]]
  335. x += 1
  336. conn.commit()
  337. div = ''
  338. if(d_list[5] == 'login'):
  339. div += '<option value="login">사용자</option>'
  340. div += '<option value="normal">일반</option>'
  341. div += '<option value="admin">관리자</option>'
  342. elif(d_list[5] == 'admin'):
  343. div += '<option value="admin">관리자</option>'
  344. div += '<option value="login">사용자</option>'
  345. div += '<option value="normal">일반</option>'
  346. else:
  347. div += '<option value="normal">일반</option>'
  348. div += '<option value="admin">관리자</option>'
  349. div += '<option value="login">사용자</option>'
  350. if(d_list[6]):
  351. ch_1 = 'checked="checked"'
  352. else:
  353. ch_1 = ''
  354. return(
  355. html_minify(
  356. template('index',
  357. imp = ['기본 설정', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  358. data = '<form method="post"> \
  359. <span>위키 이름 (기본 : 무명위키)</span> \
  360. <br> \
  361. <br> \
  362. <input placeholder="위키 이름" style="width: 100%;" type="text" name="name" value="' + d_list[0] + '"> \
  363. <br> \
  364. <br> \
  365. <span>시작 페이지 (기본 : 위키:대문)</span> \
  366. <br> \
  367. <br> \
  368. <input placeholder="시작 페이지" style="width: 100%;" type="text" name="frontpage" value="' + d_list[1] + '"> \
  369. <br> \
  370. <br> \
  371. <span>라이선스 (기본 : CC 0)</span> \
  372. <br> \
  373. <br> \
  374. <input placeholder="라이선스" style="width: 100%;" type="text" name="license" value="' + d_list[2] + '"> \
  375. <br> \
  376. <br> \
  377. <span>파일 용량 한도 (기본 : 2)</span> \
  378. <br> \
  379. <br> \
  380. <input placeholder="파일 용량 한도" style="width: 100%;" type="text" name="upload" value="' + d_list[3] + '"> \
  381. <br> \
  382. <br> \
  383. <span>스킨 (기본 : acme) (재시작 필요)</span> \
  384. <br> \
  385. <br> \
  386. <input placeholder="스킨" style="width: 100%;" type="text" name="skin" value="' + d_list[4] + '"> \
  387. <br> \
  388. <br> \
  389. <span>기본 ACL 설정 (기본 : 일반)</span> \
  390. <br> \
  391. <br> \
  392. <select name="edit"> \
  393. ' + div + ' \
  394. </select> \
  395. <br> \
  396. <br> \
  397. <input type="checkbox" name="reg" ' + ch_1 + '> 가입불가 \
  398. <br> \
  399. <br> \
  400. <button class="btn btn-primary" type="submit">저장</button> \
  401. </form>',
  402. menu = [['edit_set', '설정 편집']]
  403. )
  404. )
  405. )
  406. elif(num == 2):
  407. if(admin_check(None, 'edit_set') == 1):
  408. if(request.method == 'POST'):
  409. curs.execute("update other set data = ? where name = ?", [request.forms.contract, 'contract'])
  410. conn.commit()
  411. return(redirect('/edit_set/2'))
  412. else:
  413. i_list = ['contract']
  414. n_list = ['']
  415. d_list = []
  416. x = 0
  417. for i in i_list:
  418. curs.execute('select data from other where name = ?', [i])
  419. sql_d = curs.fetchall()
  420. if(sql_d):
  421. d_list += [sql_d[0][0]]
  422. else:
  423. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  424. d_list += [n_list[x]]
  425. x += 1
  426. conn.commit()
  427. return(
  428. html_minify(
  429. template('index',
  430. imp = ['문구 관련', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  431. data = '<form method="post"> \
  432. <span>가입 약관</span> \
  433. <br> \
  434. <br> \
  435. <input placeholder="가입 약관" style="width: 100%;" type="text" name="contract" value="' + d_list[0] + '"> \
  436. <br> \
  437. <br> \
  438. <button class="btn btn-primary" type="submit">저장</button> \
  439. </form>',
  440. menu = [['edit_set', '설정 편집']]
  441. )
  442. )
  443. )
  444. else:
  445. return(re_error('/ban'))
  446. @route('/not_close_topic')
  447. def not_close_topic():
  448. div = '<ul>'
  449. i = 1
  450. curs.execute('select title, sub from rd order by date desc')
  451. n_list = curs.fetchall()
  452. for data in n_list:
  453. curs.execute('select * from stop where title = ? and sub = ? and close = "O"', [data[0], data[1]])
  454. is_close = curs.fetchall()
  455. if(not is_close):
  456. div += '<li>' + str(i) + '. <a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[1]) + '">' + data[0] + ' (' + data[1] + ')</a></li>'
  457. i += 1
  458. div += '</ul>'
  459. return(
  460. html_minify(
  461. template('index',
  462. imp = ['열린 토론 목록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  463. data = div,
  464. menu = [['manager', '관리자']]
  465. )
  466. )
  467. )
  468. @route('/image/<name:path>')
  469. def static(name = None):
  470. if(os.path.exists(os.path.join('image', name))):
  471. return(static_file(name, root = 'image'))
  472. else:
  473. return(redirect('/'))
  474. @route('/acl_list')
  475. def acl_list():
  476. div = '<ul>'
  477. i = 0
  478. curs.execute("select title, acl from data where acl = 'admin' or acl = 'user' order by acl desc")
  479. list_data = curs.fetchall()
  480. for data in list_data:
  481. if(not re.search('^사용자:', data[0])):
  482. if(data[1] == 'admin'):
  483. acl = '관리자'
  484. else:
  485. acl = '사용자'
  486. div += '<li>' + str(i + 1) + '. <a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (' + acl + ')</li>'
  487. i += 1
  488. div += '</ul>'
  489. return(
  490. html_minify(
  491. template('index',
  492. imp = ['ACL 문서 목록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  493. data = div,
  494. menu = [['other', '기타']]
  495. )
  496. )
  497. )
  498. @route('/list_acl')
  499. def list_acl():
  500. div = '<ul>'
  501. i = 0
  502. curs.execute("select name, acl from alist order by name desc")
  503. list_data = curs.fetchall()
  504. for data in list_data:
  505. if(data[1] == 'ban'):
  506. acl = '차단'
  507. elif(data[1] == 'mdel'):
  508. acl = '많은 문서 삭제'
  509. elif(data[1] == 'toron'):
  510. acl = '토론 관리'
  511. elif(data[1] == 'check'):
  512. acl = '사용자 검사'
  513. elif(data[1] == 'acl'):
  514. acl = '문서 ACL'
  515. elif(data[1] == 'hidel'):
  516. acl = '역사 숨김'
  517. elif(data[1] == 'owner'):
  518. acl = '소유자'
  519. div += '<li>' + str(i + 1) + '. <a href="/admin_plus/' + url_pas(data[0]) + '">' + data[0] + '</a> (' + acl + ')</li>'
  520. i += 1
  521. div += '</ul><br><a href="/manager/8">(생성)</a>'
  522. return(
  523. html_minify(
  524. template('index',
  525. imp = ['ACL 목록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  526. data = re.sub('^<ul></ul><br>', '', div),
  527. menu = [['manager', '관리자']]
  528. )
  529. )
  530. )
  531. @route('/admin_plus/<name:path>', method=['POST', 'GET'])
  532. def admin_plus(name = None):
  533. if(admin_check(None, 'admin_plus (' + name + ')') == 1):
  534. if(request.method == 'POST'):
  535. curs.execute("delete from alist where name = ?", [name])
  536. if(request.forms.ban):
  537. curs.execute("insert into alist (name, acl) values (?, 'ban')", [name])
  538. if(request.forms.mdel):
  539. curs.execute("insert into alist (name, acl) values (?, 'mdel')", [name])
  540. if(request.forms.toron):
  541. curs.execute("insert into alist (name, acl) values (?, 'toron')", [name])
  542. if(request.forms.check):
  543. curs.execute("insert into alist (name, acl) values (?, 'check')", [name])
  544. if(request.forms.acl):
  545. curs.execute("insert into alist (name, acl) values (?, 'acl')", [name])
  546. if(request.forms.hidel):
  547. curs.execute("insert into alist (name, acl) values (?, 'hidel')", [name])
  548. if(request.forms.owner):
  549. curs.execute("insert into alist (name, acl) values (?, 'owner')", [name])
  550. conn.commit()
  551. return(redirect('/admin_plus/' + url_pas(name)))
  552. else:
  553. curs.execute('select acl from alist where name = ?', [name])
  554. test = curs.fetchall()
  555. data = '<ul>'
  556. exist_list = ['', '', '', '', '', '', '']
  557. for go in test:
  558. if(go[0] == 'ban'):
  559. exist_list[0] = 'checked="checked"'
  560. elif(go[0] == 'mdel'):
  561. exist_list[1] = 'checked="checked"'
  562. elif(go[0] == 'toron'):
  563. exist_list[2] = 'checked="checked"'
  564. elif(go[0] == 'check'):
  565. exist_list[3] = 'checked="checked"'
  566. elif(go[0] == 'acl'):
  567. exist_list[4] = 'checked="checked"'
  568. elif(go[0] == 'hidel'):
  569. exist_list[5] = 'checked="checked"'
  570. elif(go[0] == 'owner'):
  571. exist_list[6] = 'checked="checked"'
  572. data += '<li><input type="checkbox" name="ban" ' + exist_list[0] + '> 차단</li>'
  573. data += '<li><input type="checkbox" name="mdel" ' + exist_list[1] + '> 많은 문서 삭제</li>'
  574. data += '<li><input type="checkbox" name="toron" ' + exist_list[2] + '> 토론 관리</li>'
  575. data += '<li><input type="checkbox" name="check" ' + exist_list[3] + '> 사용자 검사</li>'
  576. data += '<li><input type="checkbox" name="acl" ' + exist_list[4] + '> 문서 ACL</li>'
  577. data += '<li><input type="checkbox" name="hidel" ' + exist_list[5] + '> 역사 숨김</li>'
  578. data += '<li><input type="checkbox" name="owner" ' + exist_list[6] + '> 소유자</li></ul>'
  579. return(
  580. html_minify(
  581. template('index',
  582. imp = ['관리 그룹 추가', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  583. data = '<form method="post">' \
  584. + data + \
  585. '<div class="form-actions"> \
  586. <button class="btn btn-primary" type="submit">저장</button> \
  587. </div> \
  588. </form>',
  589. menu = [['manager', '관리자']]
  590. )
  591. )
  592. )
  593. else:
  594. return(re_error('/error/3'))
  595. @route('/admin_list')
  596. def admin_list():
  597. i = 1
  598. div = '<ul>'
  599. curs.execute("select id, acl from user where not acl = 'user'")
  600. user_data = curs.fetchall()
  601. for data in user_data:
  602. name = ip_pas(data[0]) + ' (' + data[1] + ')'
  603. div += '<li>' + str(i) + '. ' + name + '</li>'
  604. i += 1
  605. div += '</ul>'
  606. return(
  607. html_minify(
  608. template('index',
  609. imp = ['관리자 목록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  610. data = div,
  611. menu = [['other', '기타']]
  612. )
  613. )
  614. )
  615. @route('/record/<name:path>')
  616. @route('/record/<name:path>/n/<num:int>')
  617. @route('/recent_changes')
  618. def recent_changes(name = None, num = 1):
  619. ydmin = admin_check(1, None)
  620. zdmin = admin_check(6, None)
  621. ban = ''
  622. send = '<br>'
  623. div = '<table style="width: 100%; text-align: center;"> \
  624. <tbody> \
  625. <tr> \
  626. <td style="width: 33.3%;">문서명</td> \
  627. <td style="width: 33.3%;">기여자</td> \
  628. <td style="width: 33.3%;">시간</td> \
  629. </tr>'
  630. if(name):
  631. if(num * 50 <= 0):
  632. v = 50
  633. else:
  634. v = num * 50
  635. i = v - 50
  636. div = '<a href="/user/' + url_pas(name) + '/topic">(토론 기록)</a><br><br>' + div
  637. curs.execute("select id, title, date, ip, send, leng from history where ip = ? order by date desc limit ?, ?", [name, str(i), str(v)])
  638. else:
  639. curs.execute("select id, title, date, ip, send, leng from history where not date = 'Dump' order by date desc limit 50")
  640. rows = curs.fetchall()
  641. for data in rows:
  642. send = '<br>'
  643. if(data[4]):
  644. if(not re.search("^(?: *)$", data[4])):
  645. send = data[4]
  646. title = html.escape(data[1])
  647. if(re.search("\+", data[5])):
  648. leng = '<span style="color:green;">' + data[5] + '</span>'
  649. elif(re.search("\-", data[5])):
  650. leng = '<span style="color:red;">' + data[5] + '</span>'
  651. else:
  652. leng = '<span style="color:gray;">' + data[5] + '</span>'
  653. if(ydmin == 1):
  654. curs.execute("select * from ban where block = ?", [data[3]])
  655. row = curs.fetchall()
  656. if(row):
  657. ban = ' <a href="/ban/' + url_pas(data[3]) + '">(해제)</a>'
  658. else:
  659. ban = ' <a href="/ban/' + url_pas(data[3]) + '">(차단)</a>'
  660. ip = ip_pas(data[3])
  661. if((int(data[0]) - 1) == 0):
  662. revert = ''
  663. else:
  664. 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>'
  665. style = ''
  666. curs.execute("select * from hidhi where title = ? and re = ?", [data[1], data[0]])
  667. row = curs.fetchall()
  668. if(zdmin == 1):
  669. if(row):
  670. ip += ' (숨김)'
  671. hidden = ' <a href="/history/' + url_pas(data[1]) + '/r/' + data[0] + '/hidden">(공개)'
  672. else:
  673. hidden = ' <a href="/history/' + url_pas(data[1]) + '/r/' + data[0] + '/hidden">(숨김)'
  674. else:
  675. if(row):
  676. ip = '숨김'
  677. hidden = ''
  678. send = '숨김'
  679. ban = ''
  680. style = 'display:none;'
  681. else:
  682. hidden = ''
  683. div += '<tr style="' + style + '"> \
  684. <td> \
  685. <a href="/w/' + url_pas(data[1]) + '">' + title + '</a> (<a href="/history/' + url_pas(data[1]) + '">' + data[0] + '판</a>) ' + revert + ' (' + leng + ') \
  686. </td> \
  687. <td>' + ip + ban + hidden + '</td> \
  688. <td>' + data[2] + '</td> \
  689. </tr> \
  690. <tr> \
  691. <td colspan="3">' + send + '</td> \
  692. </tr>'
  693. else:
  694. div += '</tbody> \
  695. </table>'
  696. if(name):
  697. curs.execute("select end, why from ban where block = ?", [name])
  698. ban_it = curs.fetchall()
  699. if(ban_it):
  700. sub = '(차단)'
  701. else:
  702. sub = 0
  703. title = '기여 기록'
  704. menu = [['other', '기타'], ['user', '사용자']]
  705. div += '<br><a href="/record/' + url_pas(name) + '/n/' + str(num - 1) + '">(이전)</a> <a href="/record/' + url_pas(name) + '/n/' + str(num + 1) + '">(이후)</a>'
  706. else:
  707. sub = 0
  708. menu = 0
  709. title = '최근 변경내역'
  710. return(
  711. html_minify(
  712. template('index',
  713. imp = [title, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), sub, 0],
  714. data = div,
  715. menu = menu
  716. )
  717. )
  718. )
  719. @route('/history/<name:path>/r/<num:int>/hidden')
  720. def history_hidden(name = None, num = None):
  721. if(admin_check(6, 'history_hidden (' + name + '#' + str(num) + ')') == 1):
  722. curs.execute("select * from hidhi where title = ? and re = ?", [name, str(num)])
  723. exist = curs.fetchall()
  724. if(exist):
  725. curs.execute("delete from hidhi where title = ? and re = ?", [name, str(num)])
  726. else:
  727. curs.execute("insert into hidhi (title, re) values (?, ?)", [name, str(num)])
  728. conn.commit()
  729. return(redirect('/history/' + url_pas(name)))
  730. @route('/user_log')
  731. @route('/user_log/n/<num:int>')
  732. def user_log(num = 1):
  733. if(num * 50 <= 0):
  734. i = 50
  735. else:
  736. i = num * 50
  737. j = i - 50
  738. list_data = '<ul>'
  739. ydmin = admin_check(1, None)
  740. curs.execute("select id from user limit ?, ?", [str(j), str(i)])
  741. user_list = curs.fetchall()
  742. for data in user_list:
  743. if(ydmin == 1):
  744. curs.execute("select block from ban where block = ?", [data[0]])
  745. ban_exist = curs.fetchall()
  746. if(ban_exist):
  747. ban_button = ' <a href="/ban/' + url_pas(data[0]) + '">(해제)</a>'
  748. else:
  749. ban_button = ' <a href="/ban/' + url_pas(data[0]) + '">(차단)</a>'
  750. else:
  751. ban_button = ''
  752. ip = ip_pas(data[0])
  753. list_data += '<li>' + str(j + 1) + '. ' + ip + ban_button + '</li>'
  754. j += 1
  755. else:
  756. list_data += '</ul><br><a href="/user_log/n/' + str(num - 1) + '">(이전)</a> <a href="/user_log/n/' + str(num + 1) + '">(이후)</a>'
  757. return(
  758. html_minify(
  759. template('index',
  760. imp = ['사용자 가입 기록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  761. data = list_data,
  762. menu = [['other', '기타']]
  763. )
  764. )
  765. )
  766. @route('/admin_log')
  767. @route('/admin_log/n/<num:int>')
  768. def user_log(num = 1):
  769. if(num * 50 <= 0):
  770. i = 50
  771. else:
  772. i = num * 50
  773. j = i - 50
  774. list_data = '<ul>'
  775. curs.execute("select who, what, time from re_admin order by time desc limit ?, ?", [str(j), str(i)])
  776. get_list = curs.fetchall()
  777. for data in get_list:
  778. ip = ip_pas(data[0])
  779. list_data += '<li>' + str(j + 1) + '. ' + ip + ' / ' + data[1] + ' / ' + data[2] + '</li>'
  780. j += 1
  781. else:
  782. list_data += '</ul><br> \
  783. <span>주의 : 권한 사용 안하고 열람만 해도 기록되는 경우도 있습니다.</span> \
  784. <br> \
  785. <br> \
  786. <a href="/admin_log/n/' + str(num - 1) + '">(이전)</a> <a href="/admin_log/n/' + str(num + 1) + '">(이후)</a>'
  787. return(
  788. html_minify(
  789. template('index',
  790. imp = ['관리자 권한 기록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  791. data = list_data,
  792. menu = [['other', '기타']]
  793. )
  794. )
  795. )
  796. @route('/give_log')
  797. @route('/give_log/n/<num:int>')
  798. def give_log(num = 1):
  799. if(num * 50 <= 0):
  800. i = 50
  801. else:
  802. i = num * 50
  803. j = i - 50
  804. list_data = '<ul>'
  805. back = ''
  806. curs.execute("select name, acl from alist order by name asc limit ?, ?", [str(j), str(i)])
  807. get_list = curs.fetchall()
  808. for data in get_list:
  809. if(back != data[0]):
  810. back = data[0]
  811. j += 1
  812. list_data += '<li>' + str(j) + '. ' + data[0] + ' (' + data[1] + ')</li>'
  813. else:
  814. list_data += '</ul><br><a href="/give_log/n/' + str(num - 1) + '">(이전)</a> <a href="/give_log/n/' + str(num + 1) + '">(이후)</a>'
  815. return(
  816. html_minify(
  817. template('index',
  818. imp = ['권한 목록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  819. data = list_data,
  820. menu = [['other', '기타']]
  821. )
  822. )
  823. )
  824. @route('/indexing')
  825. def indexing():
  826. if(admin_check(None, 'indexing') == 1):
  827. 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;")
  828. data = curs.fetchall()
  829. for table in data:
  830. print('----- ' + table[0] + ' -----')
  831. curs.execute('select sql from sqlite_master where name = ?', [table[0]])
  832. cul = curs.fetchall()
  833. r_cul = re.findall('(?:([^ (]*) text)', str(cul[0]))
  834. for n_cul in r_cul:
  835. print(n_cul)
  836. sql = 'create index index_' + table[0] + '_' + n_cul + ' on ' + table[0] + '(' + n_cul + ')'
  837. curs.execute(sql)
  838. conn.commit()
  839. return(redirect('/'))
  840. else:
  841. return(re_error('/error/3'))
  842. @route('/xref/<name:path>')
  843. @route('/xref/<name:path>/n/<num:int>')
  844. def xref(name = None, num = 1):
  845. if(num * 50 <= 0):
  846. v = 50
  847. else:
  848. v = num * 50
  849. i = v - 50
  850. div = '<ul>'
  851. curs.execute("delete from back where title = ? and link = ''", [name])
  852. conn.commit()
  853. curs.execute("select link, type from back where title = ? order by link asc limit ?, ?", [name, str(i), str(v)])
  854. rows = curs.fetchall()
  855. for data in rows:
  856. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a>'
  857. if(data[1]):
  858. div += ' (' + data[1] + ')'
  859. div += '</li>'
  860. else:
  861. 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>'
  862. return(
  863. html_minify(
  864. template('index',
  865. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (역링크)', 0],
  866. data = div,
  867. menu = [['w/' + url_pas(name), '문서']]
  868. )
  869. )
  870. )
  871. @route('/recent_discuss')
  872. @route('/recent_discuss/<tools:path>')
  873. def recent_discuss(tools = 'normal'):
  874. if(tools == 'normal' or tools == 'close'):
  875. div = ''
  876. if(tools == 'normal'):
  877. div += '<a href="/recent_discuss/close">(닫힌 토론)</a>'
  878. m_sub = 0
  879. else:
  880. div += '<a href="/recent_discuss">(열린 토론)</a>'
  881. m_sub = ' (닫힘)'
  882. div += '<br> \
  883. <br> \
  884. <table style="width: 100%; text-align: center;"> \
  885. <tbody> \
  886. <tr> \
  887. <td style="width: 50%;">토론명</td> \
  888. <td style="width: 50%;">시간</td> \
  889. </tr>'
  890. else:
  891. return(redirect('/'))
  892. curs.execute("select title, sub, date from rd order by date desc limit 50")
  893. rows = curs.fetchall()
  894. for data in rows:
  895. title = html.escape(data[0])
  896. sub = html.escape(data[1])
  897. close = 0
  898. if(tools == 'normal'):
  899. curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [data[0], data[1]])
  900. if(curs.fetchall()):
  901. close = 1
  902. else:
  903. curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [data[0], data[1]])
  904. if(not curs.fetchall()):
  905. close = 1
  906. if(close == 0):
  907. div += '<tr> \
  908. <td> \
  909. <a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[1]) + '">' + title + '</a> (' + sub + ') \
  910. </td> \
  911. <td>' + data[2] + '</td> \
  912. </tr>'
  913. else:
  914. div += '</tbody> \
  915. </table>'
  916. return(
  917. html_minify(
  918. template('index',
  919. imp = ['최근 토론내역', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), m_sub, 0],
  920. data = div,
  921. menu = 0
  922. )
  923. )
  924. )
  925. @route('/block_log')
  926. @route('/block_log/n/<num:int>')
  927. def block_log(num = 1):
  928. if(num * 50 <= 0):
  929. v = 50
  930. else:
  931. v = num * 50
  932. i = v - 50
  933. div = '<table style="width: 100%; text-align: center;"> \
  934. <tbody> \
  935. <tr> \
  936. <td style="width: 33.3%;">차단자</td> \
  937. <td style="width: 33.3%;">관리자</td> \
  938. <td style="width: 33.3%;">기간</td> \
  939. </tr> \
  940. <tr> \
  941. <td colspan="2">이유</td> \
  942. <td>시간</td> \
  943. </tr>'
  944. curs.execute("select why, block, blocker, end, today from rb order by today desc limit ?, ?", [str(i), str(v)])
  945. rows = curs.fetchall()
  946. for data in rows:
  947. why = html.escape(data[0])
  948. b = re.search("^([0-9]{1,3}\.[0-9]{1,3})$", data[1])
  949. if(b):
  950. ip = data[1] + ' (대역)'
  951. else:
  952. ip = ip_pas(data[1])
  953. if(data[3] != ''):
  954. end = data[3]
  955. else:
  956. end = '무기한'
  957. div += '<tr> \
  958. <td>' + ip + '</td> \
  959. <td>' + ip_pas(data[2]) + '</td> \
  960. <td>' + end + '</td> \
  961. </tr> \
  962. <tr> \
  963. <td colspan="2">' + why + '</td> \
  964. <td>' + data[4] + '</td> \
  965. </tr>'
  966. else:
  967. div += '</tbody> \
  968. </table> \
  969. <br> \
  970. <a href="/block_log/n/' + str(num - 1) + '">(이전)</a> <a href="/block_log/n/' + str(num + 1) + '">(이후)</a>'
  971. return(
  972. html_minify(
  973. template('index',
  974. imp = ['차단 기록', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  975. data = div,
  976. menu = [['other', '기타']]
  977. )
  978. )
  979. )
  980. @route('/history/<name:path>', method=['POST', 'GET'])
  981. @route('/history/<name:path>/n/<num:int>', method=['POST', 'GET'])
  982. def history_view(name = None, num = 1):
  983. if(request.method == 'POST'):
  984. return(redirect('/w/' + url_pas(name) + '/r/' + request.forms.b + '/diff/' + request.forms.a))
  985. else:
  986. select = ''
  987. if(num * 50 <= 0):
  988. i = 50
  989. else:
  990. i = num * 50
  991. j = i - 50
  992. admin1 = admin_check(1, None)
  993. admin2 = admin_check(6, None)
  994. div = '<table style="width: 100%; text-align: center;"> \
  995. <tbody> \
  996. <tr> \
  997. <td style="width: 33.3%;">판</td> \
  998. <td style="width: 33.3%;">기여자</td> \
  999. <td style="width: 33.3%;">시간</td> \
  1000. </tr>'
  1001. curs.execute("select send, leng, ip, date, title, id from history where title = ? order by id + 0 desc limit ?, ?", [name, str(j), str(i)])
  1002. all_data = curs.fetchall()
  1003. for data in all_data:
  1004. select += '<option value="' + data[5] + '">' + data[5] + '</option>'
  1005. if(data[0]):
  1006. send = data[0]
  1007. else:
  1008. send = '<br>'
  1009. if(re.search("^\+", data[1])):
  1010. leng = '<span style="color:green;">' + data[1] + '</span>'
  1011. elif(re.search("^\-", data[1])):
  1012. leng = '<span style="color:red;">' + data[1] + '</span>'
  1013. else:
  1014. leng = '<span style="color:gray;">' + data[1] + '</span>'
  1015. ip = ip_pas(data[2])
  1016. curs.execute("select block from ban where block = ?", [data[2]])
  1017. ban_it = curs.fetchall()
  1018. if(ban_it):
  1019. if(admin1 == 1):
  1020. ban = ' <a href="/ban/' + url_pas(data[2]) + '">(해제)</a>'
  1021. else:
  1022. ban = ' (X)'
  1023. else:
  1024. if(admin1 == 1):
  1025. ban = ' <a href="/ban/' + url_pas(data[2]) + '">(차단)</a>'
  1026. else:
  1027. ban = ''
  1028. curs.execute("select * from hidhi where title = ? and re = ?", [name, data[5]])
  1029. hid_it = curs.fetchall()
  1030. if(hid_it):
  1031. if(admin2):
  1032. hidden = ' <a href="/history/' + url_pas(name) + '/r/' + url_pas(data[5]) + '/hidden">(공개)'
  1033. hid = 0
  1034. else:
  1035. hid = 1
  1036. else:
  1037. if(admin2):
  1038. hidden = ' <a href="/history/' + url_pas(name) + '/r/' + url_pas(data[5]) + '/hidden">(숨김)'
  1039. hid = 0
  1040. else:
  1041. hidden = ''
  1042. hid = 0
  1043. if(hid == 1):
  1044. div += '<tr> \
  1045. <td colspan="3">숨김</td> \
  1046. </tr>'
  1047. else:
  1048. div += '<tr> \
  1049. <td> \
  1050. ' + data[5] + '판</a> <a href="/w/' + url_pas(name) + '/r/' + url_pas(data[5]) + '">(보기)</a> \
  1051. <a href="/raw/' + url_pas(name) + '/r/' + url_pas(data[5]) + '">(원본)</a> \
  1052. <a href="/revert/' + url_pas(name) + '/r/' + url_pas(data[5]) + '">(되돌리기)</a> (' + leng + ') \
  1053. </td> \
  1054. <td>' + ip + ban + hidden + '</td> \
  1055. <td>' + data[3] + '</td> \
  1056. </tr> \
  1057. <tr> \
  1058. <td colspan="3">' + send + '</td> \
  1059. </tr>'
  1060. else:
  1061. div += '</tbody> \
  1062. </table> \
  1063. <br> \
  1064. <a href="/history/' + url_pas(name) + '/n/' + str(num - 1) + '">(이전)</a> <a href="/history/' + url_pas(name) + '/n/' + str(num + 1) + '">(이후)</a>'
  1065. div = '<form method="post"> \
  1066. <select name="a"> \
  1067. ' + select + ' \
  1068. </select> \
  1069. <select name="b"> \
  1070. ' + select + ' \
  1071. </select> \
  1072. <button class="btn btn-primary" type="submit">비교</button> \
  1073. </form>' + div
  1074. return(
  1075. html_minify(
  1076. template('index',
  1077. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (역사)', 0],
  1078. data = div,
  1079. menu = [['w/' + url_pas(name), '문서'], ['move_data/' + url_pas(name), '이동 기록']]
  1080. )
  1081. )
  1082. )
  1083. @route('/search', method=['POST'])
  1084. def search():
  1085. return(redirect('/search/' + url_pas(request.forms.search)))
  1086. @route('/goto', method=['POST'])
  1087. def goto():
  1088. curs.execute("select title from data where title = ?", [request.forms.search])
  1089. data = curs.fetchall()
  1090. if(data):
  1091. return(redirect('/w/' + url_pas(request.forms.search)))
  1092. else:
  1093. return(redirect('/search/' + url_pas(request.forms.search)))
  1094. @route('/search/<name:path>')
  1095. @route('/search/<name:path>/n/<num:int>')
  1096. def deep_search(name = None, num = 1):
  1097. if(num * 50 <= 0):
  1098. v = num * 50
  1099. else:
  1100. v = 50
  1101. i = v - 50
  1102. div = '<ul>'
  1103. div_plus = ''
  1104. end = ''
  1105. curs.execute("select title from data where title like ?", ['%' + name + '%'])
  1106. title_list = curs.fetchall()
  1107. curs.execute("select title from data where data like ?", ['%' + name + '%'])
  1108. data_list = curs.fetchall()
  1109. curs.execute("select title from data where title = ?", [name])
  1110. exist = curs.fetchall()
  1111. if(exist):
  1112. div = '<ul><li>문서로 <a href="/w/' + url_pas(name) + '">바로가기</a></li><br><br>'
  1113. else:
  1114. div = '<ul><li>문서가 없습니다. <a class="not_thing" href="/w/' + url_pas(name) + '">바로가기</a></li><br><br>'
  1115. if(title_list):
  1116. no = 0
  1117. if(data_list):
  1118. all_list = title_list + data_list
  1119. else:
  1120. all_list = title_list
  1121. else:
  1122. if(data_list):
  1123. no = 1
  1124. all_list = data_list
  1125. else:
  1126. all_list = ''
  1127. if(all_list != ''):
  1128. for data in all_list:
  1129. try:
  1130. var_re = re.search(name, data[0])
  1131. except:
  1132. var_re = re.search('\\' + name, data[0])
  1133. if(var_re):
  1134. if(no == 0):
  1135. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (제목)</li>'
  1136. else:
  1137. div_plus += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (내용)</li>'
  1138. else:
  1139. no = 1
  1140. div_plus += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (내용)</li>'
  1141. else:
  1142. div += '<li>검색 결과 없음</li>'
  1143. div += div_plus + end
  1144. 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>'
  1145. return(
  1146. html_minify(
  1147. template('index',
  1148. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (검색)', 0],
  1149. data = div,
  1150. menu = 0
  1151. )
  1152. )
  1153. )
  1154. @route('/raw/<name:path>')
  1155. @route('/raw/<name:path>/r/<num:int>')
  1156. @route('/topic/<name:path>/sub/<sub_t:path>/raw/<num:int>')
  1157. def raw_view(name = None, sub_t = None, num = None):
  1158. v_name = name
  1159. sub = ' (원본)'
  1160. if(not sub_t and num):
  1161. curs.execute("select title from hidhi where title = ? and re = ?", [name, str(num)])
  1162. hid = curs.fetchall()
  1163. if(hid and admin_check(6, None) != 1):
  1164. return(re_error('/error/3'))
  1165. curs.execute("select data from history where title = ? and id = ?", [name, str(num)])
  1166. sub += ' (' + str(num) + '판)'
  1167. menu = [['history/' + url_pas(name), '역사']]
  1168. elif(sub_t):
  1169. curs.execute("select data from topic where id = ? and title = ? and sub = ? and block = ''", [str(num), name, sub_t])
  1170. v_name = '토론 원본'
  1171. sub = ' (' + str(num) + '번)'
  1172. menu = [['topic/' + url_pas(name) + '/sub/' + url_pas(sub_t) + '#' + str(num), '토론']]
  1173. else:
  1174. curs.execute("select data from data where title = ?", [name])
  1175. menu = [['w/' + url_pas(name), '문서']]
  1176. data = curs.fetchall()
  1177. if(data):
  1178. p_data = html.escape(data[0][0])
  1179. p_data = '<textarea readonly style="height: 80%;">' + p_data + '</textarea>'
  1180. return(
  1181. html_minify(
  1182. template('index',
  1183. imp = [v_name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), sub, 0],
  1184. data = p_data,
  1185. menu = menu
  1186. )
  1187. )
  1188. )
  1189. else:
  1190. return(redirect('/w/' + url_pas(name)))
  1191. @route('/revert/<name:path>/r/<num:int>', method=['POST', 'GET'])
  1192. def revert(name = None, num = None):
  1193. ip = ip_check()
  1194. can = acl_check(name)
  1195. today = get_time()
  1196. if(request.method == 'POST'):
  1197. curs.execute("select title from hidhi where title = ? and re = ?", [name, str(num)])
  1198. hid = curs.fetchall()
  1199. if(hid and admin_check(6, None) != 1):
  1200. return(re_error('/error/3'))
  1201. if(can == 1):
  1202. return(re_error('/ban'))
  1203. else:
  1204. curs.execute("delete from back where link = ?", [name])
  1205. curs.execute("delete from cat where cat = ?", [name])
  1206. conn.commit()
  1207. curs.execute("select data from history where title = ? and id = ?", [name, str(num)])
  1208. rows = curs.fetchall()
  1209. if(rows):
  1210. curs.execute("select data from data where title = ?", [name])
  1211. row = curs.fetchall()
  1212. if(row):
  1213. leng = leng_check(len(row[0][0]), len(rows[0][0]))
  1214. curs.execute("update data set data = ? where title = ?", [rows[0][0], name])
  1215. else:
  1216. leng = '+' + str(len(rows[0][0]))
  1217. curs.execute("insert into data (title, data, acl) values (?, ?, '')", [name, rows[0][0]])
  1218. history_plus(
  1219. name,
  1220. rows[0][0],
  1221. today,
  1222. ip,
  1223. request.forms.send + ' (' + str(num) + '판)',
  1224. leng
  1225. )
  1226. namumark(name, rows[0][0], 1, 0, 0)
  1227. conn.commit()
  1228. return(redirect('/w/' + url_pas(name)))
  1229. else:
  1230. curs.execute("select title from hidhi where title = ? and re = ?", [name, str(num)])
  1231. hid = curs.fetchall()
  1232. if(hid and admin_check(6, None) != 1):
  1233. return(re_error('/error/3'))
  1234. if(can == 1):
  1235. return(re_error('/ban'))
  1236. else:
  1237. curs.execute("select title from history where title = ? and id = ?", [name, str(num)])
  1238. rows = curs.fetchall()
  1239. if(rows):
  1240. l_c = custom(0)
  1241. if(l_c == 0):
  1242. plus = '<span>비 로그인 상태입니다. 비 로그인으로 작업 시 아이피가 역사에 기록됩니다.</span> \
  1243. <br> \
  1244. <br>'
  1245. else:
  1246. plus = ''
  1247. return(
  1248. html_minify(
  1249. template('index',
  1250. imp = [name, wiki_set(1), wiki_set(3), l_c, custom(1), custom(2), ' (되돌리기)', 0],
  1251. data = plus + ' \
  1252. <form method="post"> \
  1253. <input placeholder="사유" style="width: 100%;" class="form-control input-sm" name="send" type="text"> \
  1254. <br> \
  1255. <br> \
  1256. <button class="btn btn-primary" type="submit">되돌리기</button> \
  1257. </form>',
  1258. menu = [['history/' + url_pas(name), '역사'], ['recent_changes', '최근 변경']]
  1259. )
  1260. )
  1261. )
  1262. else:
  1263. return(redirect('/w/' + url_pas(name)))
  1264. @route('/m_del', method=['POST', 'GET'])
  1265. def m_del():
  1266. today = get_time()
  1267. ip = ip_check()
  1268. if(admin_check(2, 'm_del') == 1):
  1269. if(request.method == 'POST'):
  1270. data = request.forms.content + '\r\n'
  1271. m = re.findall('(.*)\r\n', data)
  1272. for g in m:
  1273. curs.execute("select data from data where title = ?", [g])
  1274. rows = curs.fetchall()
  1275. if(rows):
  1276. curs.execute("delete from back where title = ?", [g])
  1277. curs.execute("delete from cat where title = ?", [g])
  1278. leng = '-' + str(len(rows[0][0]))
  1279. curs.execute("delete from data where title = ?", [g])
  1280. history_plus(
  1281. g,
  1282. '',
  1283. today,
  1284. ip,
  1285. request.forms.send + ' (대량 삭제)',
  1286. leng
  1287. )
  1288. data = re.sub('(.*)\r\n', '', data, 1)
  1289. conn.commit()
  1290. return(redirect('/'))
  1291. else:
  1292. return(
  1293. html_minify(
  1294. template('index',
  1295. imp = ['많은 문서 삭제', wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), 0, 0],
  1296. data = '<span> \
  1297. 문서명 A \
  1298. <br> \
  1299. 문서명 B \
  1300. <br> \
  1301. 문서명 C \
  1302. <br> \
  1303. <br> \
  1304. 이런 식으로 적으세요. \
  1305. </span> \
  1306. <br> \
  1307. <br> \
  1308. <form method="post"> \
  1309. <textarea style="height: 80%;" name="content"></textarea> \
  1310. <br> \
  1311. <br> \
  1312. <input placeholder="사유" style="width: 100%;" class="form-control input-sm" name="send" type="text"> \
  1313. <br> \
  1314. <br> \
  1315. <div class="form-actions"> \
  1316. <button class="btn btn-primary" type="submit">삭제</button> \
  1317. </div> \
  1318. </form>',
  1319. menu = [['manager', '관리자']]
  1320. )
  1321. )
  1322. )
  1323. else:
  1324. return(re_error('/error/3'))
  1325. @route('/edit/<name:path>', method=['POST', 'GET'])
  1326. @route('/edit/<name:path>/section/<num:int>', method=['POST', 'GET'])
  1327. def edit(name = None, num = None):
  1328. ip = ip_check()
  1329. can = acl_check(name)
  1330. if(request.method == 'POST'):
  1331. if(can == 1):
  1332. return(re_error('/ban'))
  1333. if(len(request.forms.send) > 500):
  1334. return(re_error('/error/15'))
  1335. if(request.forms.otent == request.forms.content):
  1336. return(re_error('/error/18'))
  1337. today = get_time()
  1338. content = savemark(request.forms.content)
  1339. curs.execute("delete from back where link = ?", [name])
  1340. curs.execute("delete from cat where cat = ?", [name])
  1341. curs.execute("select data from data where title = ?", [name])
  1342. rows = curs.fetchall()
  1343. if(rows):
  1344. leng = leng_check(len(request.forms.otent), len(content))
  1345. if(num):
  1346. content = rows[0][0].replace(request.forms.otent, content)
  1347. curs.execute("update data set data = ? where title = ?", [content, name])
  1348. else:
  1349. leng = '+' + str(len(content))
  1350. curs.execute("insert into data (title, data, acl) values (?, ?, '')", [name, content])
  1351. history_plus(
  1352. name,
  1353. content,
  1354. today,
  1355. ip,
  1356. send_p(request.forms.send),
  1357. leng
  1358. )
  1359. namumark(name, content, 1, 0, 0)
  1360. include_check(name, content)
  1361. conn.commit()
  1362. return(redirect('/w/' + url_pas(name)))
  1363. else:
  1364. if(can == 1):
  1365. return(re_error('/ban'))
  1366. curs.execute("select data from data where title = ?", [name])
  1367. rows = curs.fetchall()
  1368. if(rows):
  1369. if(num):
  1370. i = 0
  1371. j = 0
  1372. data = rows[0][0] + '\r\n'
  1373. while(1):
  1374. m = re.search("((?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n(?:(?:(?:(?!(?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n).)*)(?:\n)?)+)", data)
  1375. if(m):
  1376. if(i == num - 1):
  1377. g = m.groups()
  1378. data = re.sub("\r\n$", "", g[0])
  1379. break
  1380. else:
  1381. data = re.sub("((?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n(?:(?:(?:(?!(?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n).)*)(?:\n)?)+)", "", data, 1)
  1382. i += 1
  1383. else:
  1384. j = 1
  1385. break
  1386. if(j == 0):
  1387. data = re.sub("\r\n$", "", data)
  1388. else:
  1389. data = rows[0][0]
  1390. else:
  1391. data = ''
  1392. if(num):
  1393. action = '/section/' + str(num)
  1394. else:
  1395. action = ''
  1396. return(
  1397. html_minify(
  1398. template('index',
  1399. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (수정)', 0],
  1400. data = '<form method="post" action="/edit/' + url_pas(name) + action + '"> \
  1401. <textarea style="height: 80%;" name="content">' + data + '</textarea> \
  1402. <textarea style="display: none; height: 80%;" name="otent">' + data + '</textarea> \
  1403. <br> \
  1404. <br> \
  1405. <input placeholder="사유" name="send" style="width: 100%;" type="text"> \
  1406. <br> \
  1407. <br> \
  1408. <div class="form-actions"> \
  1409. <button id="save" class="btn btn-primary" type="submit">저장</button> \
  1410. <button id="preview" class="btn" type="submit" formaction="/preview/' + url_pas(name) + action + '">미리보기</button> \
  1411. </div> \
  1412. </form>',
  1413. menu = [['w/' + url_pas(name), '문서']]
  1414. )
  1415. )
  1416. )
  1417. @route('/preview/<name:path>', method=['POST'])
  1418. @route('/preview/<name:path>/section/<num:int>', method=['POST'])
  1419. def preview(name = None, num = None):
  1420. ip = ip_check()
  1421. can = acl_check(name)
  1422. if(can == 1):
  1423. return(re_error('/ban'))
  1424. newdata = request.forms.content
  1425. newdata = re.sub('^#(?:redirect|넘겨주기) (?P<in>[^\n]*)', ' * [[\g<in>]] 문서로 넘겨주기', newdata)
  1426. enddata = namumark(name, newdata, 0, 0, 0)
  1427. if(num):
  1428. action = '/section/' + str(num)
  1429. else:
  1430. action = ''
  1431. return(
  1432. html_minify(
  1433. template('index',
  1434. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (미리보기)', 0],
  1435. data = '<form method="post" action="/edit/' + url_pas(name) + action + '"> \
  1436. <textarea style="height: 80%;" name="content">' + request.forms.content + '</textarea> \
  1437. <textarea style="display: none; height: 80%;" name="otent">' + request.forms.otent + '</textarea> \
  1438. <br> \
  1439. <br> \
  1440. <input placeholder="사유" name="send" style="width: 100%;" type="text"> \
  1441. <br> \
  1442. <br> \
  1443. <div class="form-actions"> \
  1444. <button id="save" class="btn btn-primary" type="submit">저장</button> \
  1445. <button id="preview" class="btn" type="submit" formaction="/preview/' + url_pas(name) + action + '">미리보기</button> \
  1446. </div> \
  1447. </form> \
  1448. <br>' + enddata,
  1449. menu = [['w/' + url_pas(name), '문서']]
  1450. )
  1451. )
  1452. )
  1453. @route('/delete/<name:path>', method=['POST', 'GET'])
  1454. def delete(name = None):
  1455. ip = ip_check()
  1456. can = acl_check(name)
  1457. if(request.method == 'POST'):
  1458. curs.execute("select data from data where title = ?", [name])
  1459. rows = curs.fetchall()
  1460. if(rows):
  1461. if(can == 1):
  1462. return(re_error('/ban'))
  1463. today = get_time()
  1464. leng = '-' + str(len(rows[0][0]))
  1465. history_plus(name, '', today, ip, request.forms.send + ' (삭제)', leng)
  1466. curs.execute("delete from back where link = ?", [name])
  1467. curs.execute("delete from cat where cat = ?", [name])
  1468. curs.execute("delete from data where title = ?", [name])
  1469. conn.commit()
  1470. return(redirect('/w/' + url_pas(name)))
  1471. else:
  1472. curs.execute("select title from data where title = ?", [name])
  1473. rows = curs.fetchall()
  1474. if(rows):
  1475. if(can == 1):
  1476. return(re_error('/ban'))
  1477. else:
  1478. l_c = custom(0)
  1479. if(l_c == 0):
  1480. plus = '<span>비 로그인 상태입니다. 비 로그인으로 작업 시 아이피가 역사에 기록됩니다.</span><br><br>'
  1481. else:
  1482. plus = ''
  1483. return(
  1484. html_minify(
  1485. template('index',
  1486. imp = [name, wiki_set(1), wiki_set(3), l_c, custom(1), custom(2), ' (삭제)', 0],
  1487. data = '<form method="post"> \
  1488. ' + plus + ' \
  1489. <input placeholder="사유" style="width: 100%;" class="form-control input-sm" name="send" type="text"> \
  1490. <br> \
  1491. <br> \
  1492. <button class="btn btn-primary" type="submit">삭제</button> \
  1493. </form>',
  1494. menu = [['w/' + url_pas(name), '문서']]
  1495. )
  1496. )
  1497. )
  1498. else:
  1499. return(redirect('/w/' + url_pas(name)))
  1500. @route('/move_data/<name:path>')
  1501. @route('/move_data/<name:path>/<n:int>')
  1502. def move_data(name = None, n = 1):
  1503. if(n > 0):
  1504. i = n
  1505. else:
  1506. i = 1
  1507. j = i * 50
  1508. da = '<ul>'
  1509. curs.execute("select origin, new, date, who, send from move where origin = ? or new = ? limit ?, ?", [name, name, j - 50, j])
  1510. for d in curs.fetchall():
  1511. if(d[4] == ''):
  1512. sn = '(없음)'
  1513. else:
  1514. sn = d[4]
  1515. 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>'
  1516. da += '</ul><br><a href="/move_data/' + name + '/' + str(n - 1) + '">(이전)</a> <a href="/move_data/' + name + '/' + str(n + 1) + '">(이후)</a>'
  1517. return(
  1518. html_minify(
  1519. template('index',
  1520. imp = [name, wiki_set(1), wiki_set(3), custom(0), custom(1), custom(2), ' (이동)', 0],
  1521. data = da,
  1522. menu = [['w/' + url_pas(name), '문서']]
  1523. )
  1524. )
  1525. )
  1526. @route('/move/<name:path>', method=['POST', 'GET'])
  1527. def move(name = None):
  1528. ip = ip_check()
  1529. can = acl_check(name)
  1530. today = get_time()
  1531. if(can == 1):
  1532. return(re_error('/ban'))
  1533. if(request.method == 'POST'):
  1534. curs.execute("select data from data where title = ?", [name])
  1535. rows = curs.fetchall()
  1536. leng = '0'
  1537. curs.execute("select title from history where title = ?", [request.forms.title])
  1538. row = curs.fetchall()
  1539. if(row):
  1540. return(re_error('/error/19'))
  1541. if(rows):
  1542. curs.execute("update data set title = ? where title = ?", [request.forms.title, name])
  1543. curs.execute("update back set link = ? where link = ?", [request.forms.title, name])
  1544. curs.execute("update cat set cat = ? where cat = ?", [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 cat where title = ? and cat = ''", [name])
  2836. conn.commit()
  2837. curs.execute("select cat from cat where title = ? order by cat 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.f_name):
  3000. name = request.forms.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.f_lice):
  3007. lice = request.forms.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. )