| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793 |
- from bottle import *
- from bottle.ext import beaker
- import json
- import sqlite3
- import bcrypt
- import os
- import difflib
- from css_html_js_minify import html_minify
- from multiprocessing import Process
- try:
- json_data = open('set.json').read()
- set_data = json.loads(json_data)
- except:
- new_json = []
- print('DB 이름 : ', end = '')
- new_json += [input()]
- print('포트 : ', end = '')
- new_json += [input()]
- with open("set.json", "w") as f:
- f.write('{ "db" : "' + new_json[0] + '", "port" : "' + new_json[1] + '" }')
-
- json_data = open('set.json').read()
- set_data = json.loads(json_data)
- conn = sqlite3.connect(set_data['db'] + '.db')
- curs = conn.cursor()
- session_opts = {
- 'session.type': 'file',
- 'session.data_dir': './app_session/',
- 'session.auto': 1
- }
- app = beaker.middleware.SessionMiddleware(app(), session_opts)
- from func import *
- BaseRequest.MEMFILE_MAX = 1000 ** 4
- def redirect(data):
- return('<meta http-equiv="refresh" content="0;url=' + data + '" />')
- def re_error(data):
- if(data == '/ban'):
- ip = ip_check()
- end = '권한이 맞지 않는 상태 입니다.'
- if(ban_check() == 1):
- curs.execute("select end, why from ban where block = ?", [ip])
- d = curs.fetchall()
- if(not d):
- m = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
- if(m):
- curs.execute("select end, why from ban where block = ? and band = 'O'", [m.groups()[0]])
- d = curs.fetchall()
- if(d):
- if(d[0][0]):
- end = d[0][0] + ' 까지 차단 상태 입니다. / 사유 : ' + d[0][1]
- now = re.sub(':', '', get_time())
- now = re.sub('\-', '', now)
- now = int(re.sub(' ', '', now))
-
- day = re.sub('\-', '', d[0][0])
-
- if(now >= int(day + '000000')):
- curs.execute("delete from ban where block = ?", [ip])
- conn.commit()
-
- end = '차단이 풀렸습니다. 다시 시도 해 보세요.'
- else:
- end = '영구 차단 상태 입니다. / 사유 : ' + d[0][1]
-
- return(
- html_minify(
- template('index',
- imp = ['권한 오류', wiki_set(1), custom(), other2([0, 0])],
- data = end,
- menu = 0
- )
- )
- )
- d = re.search('\/error\/([0-9]+)', data)
- if(d):
- num = int(d.groups()[0])
- if(num == 1):
- title = '권한 오류'
- data = '비 로그인 상태 입니다.'
- elif(num == 2):
- title = '권한 오류'
- data = '이 계정이 없습니다.'
- elif(num == 3):
- title = '권한 오류'
- data = '권한이 모자랍니다.'
- elif(num == 4):
- title = '권한 오류'
- data = '관리자는 차단, 검사 할 수 없습니다.'
- elif(num == 5):
- title = '사용자 오류'
- data = '그런 계정이 없습니다.'
- elif(num == 6):
- title = '가입 오류'
- data = '동일한 아이디의 사용자가 있습니다.'
- elif(num == 7):
- title = '가입 오류'
- data = '아이디는 20글자보다 짧아야 합니다.'
- elif(num == 8):
- title = '가입 오류'
- data = '아이디에는 한글과 알파벳과 공백만 허용 됩니다.'
- elif(num == 9):
- title = '파일 올리기 오류'
- data = '파일이 없습니다.'
- elif(num == 10):
- title = '변경 오류'
- data = '비밀번호가 다릅니다.'
- elif(num == 11):
- title = '로그인 오류'
- data = '이미 로그인 되어 있습니다.'
- elif(num == 14):
- title = '파일 올리기 오류'
- data = 'jpg, gif, jpeg, png, webp만 가능 합니다.'
- elif(num == 15):
- title = '편집 오류'
- data = '편집 기록은 500자를 넘을 수 없습니다.'
- elif(num == 16):
- title = '파일 올리기 오류'
- data = '동일한 이름의 파일이 있습니다.'
- elif(num == 17):
- title = '파일 올리기 오류'
- data = '파일 용량은 ' + wiki_set(3) + 'MB를 넘길 수 없습니다.'
- elif(num == 18):
- title = '편집 오류'
- data = '내용이 원래 문서와 동일 합니다.'
- elif(num == 19):
- title = '이동 오류'
- data = '이동 하려는 곳에 문서가 이미 있습니다.'
- elif(num == 20):
- title = '비밀번호 오류'
- data = '재 확인이랑 비밀번호가 다릅니다.'
- if(title):
- return(
- html_minify(
- template(
- 'index',
- imp = [title, wiki_set(1), custom(), other2([0, 0])],
- data = data,
- menu = 0
- )
- )
- )
- else:
- return(redirect('/'))
- else:
- return(redirect('/'))
- r_ver = '2.3.5'
- p_ver = 's'
- try:
- curs.execute("select title from data limit 1")
- try:
- curs.execute('select new from move limit 1')
- except:
- curs.execute("create table move(origin text, new text, date text, who text, send text)")
- print('move 테이블 생성')
- curs.execute('select data from other where name = "skin"')
- skin_exist = curs.fetchall()
- if(skin_exist):
- if(os.path.exists(os.path.abspath('./views/' + skin_exist[0][0] + '/index.tpl')) == 1):
- TEMPLATE_PATH.insert(0, './views/' + skin_exist[0][0] + '/')
- else:
- TEMPLATE_PATH.insert(0, './views/acme/')
- else:
- TEMPLATE_PATH.insert(0, './views/acme/')
- try:
- curs.execute('select name from alarm limit 1')
- except:
- curs.execute("create table alarm(name text, data text, date text)")
- print('alarm 테이블 생성')
- try:
- curs.execute('select name from ua_d limit 1')
- except:
- curs.execute("create table ua_d(name text, ip text, ua text, today text, sub text)")
- print('ua_d 테이블 생성')
- try:
- curs.execute('select user, ip, today from login')
- lo_d = curs.fetchall()
- for m_lo in lo_d:
- curs.execute("insert into ua_d (name, ip, ua, today, sub) values (?, ?, '', ?, '')", [m_lo[0], m_lo[1], m_lo[2]])
- curs.execute("drop table login")
- print('login 테이블 삭제')
- except:
- pass
- try:
- curs.execute('select title, cat from cat')
- lo_d = curs.fetchall()
- for m_lo in lo_d:
- curs.execute("insert into back (title, link, type) values (?, ?, 'cat')", [m_lo[0], m_lo[1]])
- curs.execute("drop table cat")
- print('cat 테이블 삭제')
- except:
- pass
- conn.commit()
- except:
- pass
-
- @route('/setup', method=['GET', 'POST'])
- def setup():
- try:
- curs.execute("select title from data limit 1")
- except:
- try:
- curs.execute("create table data(title text, data text, acl text)")
- except:
- pass
- try:
- curs.execute("create table history(id text, title text, data text, date text, ip text, send text, leng text)")
- except:
- pass
- try:
- curs.execute("create table rd(title text, sub text, date text)")
- except:
- pass
- try:
- curs.execute("create table user(id text, pw text, acl text)")
- except:
- pass
- try:
- curs.execute("create table ban(block text, end text, why text, band text)")
- except:
- pass
- try:
- curs.execute("create table topic(id text, title text, sub text, data text, date text, ip text, block text, top text)")
- except:
- pass
- try:
- curs.execute("create table stop(title text, sub text, close text)")
- except:
- pass
- try:
- curs.execute("create table rb(block text, end text, today text, blocker text, why text)")
- except:
- pass
- try:
- curs.execute("create table back(title text, link text, type text)")
- except:
- pass
- try:
- curs.execute("create table hidhi(title text, re text)")
- except:
- pass
- try:
- curs.execute("create table agreedis(title text, sub text)")
- except:
- pass
- try:
- curs.execute("create table custom(user text, css text)")
- except:
- pass
- try:
- curs.execute("create table other(name text, data text)")
- except:
- pass
- try:
- curs.execute("create table alist(name text, acl text)")
- curs.execute("insert into alist (name, acl) values ('소유자', 'owner')")
- except:
- pass
- try:
- curs.execute("create table re_admin(who text, what text, time text)")
- except:
- pass
- try:
- curs.execute("create table move(origin text, new text, date text, who text, send text)")
- except:
- pass
- try:
- curs.execute("create table alarm(name text, data text, date text)")
- except:
- pass
- try:
- curs.execute("create table ua_d(name text, ip text, ua text, today text, sub text)")
- except:
- pass
- conn.commit()
- return(redirect('/'))
- @route('/del_alarm')
- def del_alarm():
- curs.execute("delete from alarm where name = ?", [ip_check()])
- conn.commit()
- return(redirect('/alarm'))
- @route('/alarm')
- def alarm():
- ip = ip_check()
- if(re.search('(?:\.|:)', ip)):
- return(redirect('/login'))
- da = '<ul>'
- curs.execute("select data, date from alarm where name = ? order by date desc", [ip])
- dt = curs.fetchall()
- if(dt):
- da = '<a href="/del_alarm">(알람 삭제)</a><br><br>' + da
- for do in dt:
- da += '<li>' + do[0] + ' / ' + do[1] + '</li>'
- else:
- da += '<li>알림이 없습니다.</li>'
- da += '</ul>'
- return(
- html_minify(
- template('index',
- imp = ['알림', wiki_set(1), custom(), other2([0, 0])],
- data = da,
- menu = [['user', '사용자']]
- )
- )
- )
- @route('/edit_set', method=['POST', 'GET'])
- @route('/edit_set/<num:int>', method=['POST', 'GET'])
- def edit_set(num = 0):
- if(num == 0):
- return(
- html_minify(
- template('index',
- imp = ['설정 편집', wiki_set(1), custom(), other2([0, 0])],
- data = '<ul> \
- <li><a href="/edit_set/1">기본 설정</a></li> \
- <li><a href="/edit_set/2">문구 관련</a></li> \
- </ul>',
- menu = [['manager', '관리자']]
- )
- )
- )
- elif(num == 1):
- if(admin_check(None, 'edit_set') == 1):
- if(request.method == 'POST'):
- curs.execute("update other set data = ? where name = ?", [request.forms.name, 'name'])
- curs.execute("update other set data = ? where name = 'frontpage'", [request.forms.frontpage])
- curs.execute("update other set data = ? where name = 'license'", [request.forms.license])
- curs.execute("update other set data = ? where name = 'upload'", [request.forms.upload])
- curs.execute("update other set data = ? where name = 'skin'", [request.forms.skin])
- curs.execute("update other set data = ? where name = 'edit'", [request.forms.edit])
- curs.execute("update other set data = ? where name = 'reg'", [request.forms.reg])
- conn.commit()
- return(redirect('/edit_set/1'))
- else:
- i_list = ['name', 'frontpage', 'license', 'upload', 'skin', 'edit', 'reg']
- n_list = ['무명위키', '위키:대문', 'CC 0', '2', '', 'normal', '']
- d_list = []
-
- x = 0
- for i in i_list:
- curs.execute('select data from other where name = ?', [i])
- sql_d = curs.fetchall()
- if(sql_d):
- d_list += [sql_d[0][0]]
- else:
- curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
- d_list += [n_list[x]]
- x += 1
- conn.commit()
- div = ''
- if(d_list[5] == 'login'):
- div += '<option value="login">사용자</option>'
- div += '<option value="normal">일반</option>'
- div += '<option value="admin">관리자</option>'
- elif(d_list[5] == 'admin'):
- div += '<option value="admin">관리자</option>'
- div += '<option value="login">사용자</option>'
- div += '<option value="normal">일반</option>'
- else:
- div += '<option value="normal">일반</option>'
- div += '<option value="admin">관리자</option>'
- div += '<option value="login">사용자</option>'
- if(d_list[6]):
- ch_1 = 'checked="checked"'
- else:
- ch_1 = ''
- return(
- html_minify(
- template('index',
- imp = ['기본 설정', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <span>위키 이름 (기본 : 무명위키)</span> \
- <br> \
- <br> \
- <input placeholder="위키 이름" style="width: 100%;" type="text" name="name" value="' + d_list[0] + '"> \
- <br> \
- <br> \
- <span>시작 페이지 (기본 : 위키:대문)</span> \
- <br> \
- <br> \
- <input placeholder="시작 페이지" style="width: 100%;" type="text" name="frontpage" value="' + d_list[1] + '"> \
- <br> \
- <br> \
- <span>라이선스 (기본 : CC 0)</span> \
- <br> \
- <br> \
- <input placeholder="라이선스" style="width: 100%;" type="text" name="license" value="' + d_list[2] + '"> \
- <br> \
- <br> \
- <span>파일 용량 한도 (기본 : 2)</span> \
- <br> \
- <br> \
- <input placeholder="파일 용량 한도" style="width: 100%;" type="text" name="upload" value="' + d_list[3] + '"> \
- <br> \
- <br> \
- <span>스킨 (기본 : acme) (재시작 필요)</span> \
- <br> \
- <br> \
- <input placeholder="스킨" style="width: 100%;" type="text" name="skin" value="' + d_list[4] + '"> \
- <br> \
- <br> \
- <span>기본 ACL 설정 (기본 : 일반)</span> \
- <br> \
- <br> \
- <select name="edit"> \
- ' + div + ' \
- </select> \
- <br> \
- <br> \
- <input type="checkbox" name="reg" ' + ch_1 + '> 가입불가 \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">저장</button> \
- </form>',
- menu = [['edit_set', '설정 편집']]
- )
- )
- )
- elif(num == 2):
- if(admin_check(None, 'edit_set') == 1):
- if(request.method == 'POST'):
- curs.execute("update other set data = ? where name = ?", [request.forms.contract, 'contract'])
- conn.commit()
- return(redirect('/edit_set/2'))
- else:
- i_list = ['contract']
- n_list = ['']
- d_list = []
-
- x = 0
- for i in i_list:
- curs.execute('select data from other where name = ?', [i])
- sql_d = curs.fetchall()
- if(sql_d):
- d_list += [sql_d[0][0]]
- else:
- curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
- d_list += [n_list[x]]
- x += 1
- conn.commit()
- return(
- html_minify(
- template('index',
- imp = ['문구 관련', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <span>가입 약관</span> \
- <br> \
- <br> \
- <input placeholder="가입 약관" style="width: 100%;" type="text" name="contract" value="' + d_list[0] + '"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">저장</button> \
- </form>',
- menu = [['edit_set', '설정 편집']]
- )
- )
- )
- else:
- return(re_error('/ban'))
- @route('/not_close_topic')
- def not_close_topic():
- div = '<ul>'
- i = 1
- curs.execute('select title, sub from rd order by date desc')
- n_list = curs.fetchall()
- for data in n_list:
- curs.execute('select * from stop where title = ? and sub = ? and close = "O"', [data[0], data[1]])
- is_close = curs.fetchall()
- if(not is_close):
- div += '<li>' + str(i) + '. <a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[1]) + '">' + data[0] + ' (' + data[1] + ')</a></li>'
- i += 1
-
- div += '</ul>'
- return(
- html_minify(
- template('index',
- imp = ['열린 토론 목록', wiki_set(1), custom(), other2([0, 0])],
- data = div,
- menu = [['manager', '관리자']]
- )
- )
- )
- @route('/image/<name:path>')
- def static(name = None):
- if(os.path.exists(os.path.join('image', name))):
- return(static_file(name, root = 'image'))
- else:
- return(redirect('/'))
- @route('/acl_list')
- def acl_list():
- div = '<ul>'
- i = 0
- curs.execute("select title, acl from data where acl = 'admin' or acl = 'user' order by acl desc")
- list_data = curs.fetchall()
- for data in list_data:
- if(not re.search('^사용자:', data[0])):
- if(data[1] == 'admin'):
- acl = '관리자'
- else:
- acl = '사용자'
- div += '<li>' + str(i + 1) + '. <a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (' + acl + ')</li>'
-
- i += 1
-
- div += '</ul>'
-
- return(
- html_minify(
- template('index',
- imp = ['ACL 문서 목록', wiki_set(1), custom(), other2([0, 0])],
- data = div,
- menu = [['other', '기타']]
- )
- )
- )
-
- @route('/list_acl')
- def list_acl():
- div = '<ul>'
- i = 0
- curs.execute("select name, acl from alist order by name desc")
- list_data = curs.fetchall()
- for data in list_data:
- if(data[1] == 'ban'):
- acl = '차단'
- elif(data[1] == 'mdel'):
- acl = '많은 문서 삭제'
- elif(data[1] == 'toron'):
- acl = '토론 관리'
- elif(data[1] == 'check'):
- acl = '사용자 검사'
- elif(data[1] == 'acl'):
- acl = '문서 ACL'
- elif(data[1] == 'hidel'):
- acl = '역사 숨김'
- elif(data[1] == 'owner'):
- acl = '소유자'
-
- div += '<li>' + str(i + 1) + '. <a href="/admin_plus/' + url_pas(data[0]) + '">' + data[0] + '</a> (' + acl + ')</li>'
-
- i += 1
-
- div += '</ul><br><a href="/manager/8">(생성)</a>'
- return(
- html_minify(
- template('index',
- imp = ['ACL 목록', wiki_set(1), custom(), other2([0, 0])],
- data = re.sub('^<ul></ul><br>', '', div),
- menu = [['manager', '관리자']]
- )
- )
- )
- @route('/admin_plus/<name:path>', method=['POST', 'GET'])
- def admin_plus(name = None):
- if(admin_check(None, 'admin_plus (' + name + ')') == 1):
- if(request.method == 'POST'):
- curs.execute("delete from alist where name = ?", [name])
-
- if(request.forms.ban):
- curs.execute("insert into alist (name, acl) values (?, 'ban')", [name])
- if(request.forms.mdel):
- curs.execute("insert into alist (name, acl) values (?, 'mdel')", [name])
- if(request.forms.toron):
- curs.execute("insert into alist (name, acl) values (?, 'toron')", [name])
-
- if(request.forms.check):
- curs.execute("insert into alist (name, acl) values (?, 'check')", [name])
- if(request.forms.acl):
- curs.execute("insert into alist (name, acl) values (?, 'acl')", [name])
- if(request.forms.hidel):
- curs.execute("insert into alist (name, acl) values (?, 'hidel')", [name])
- if(request.forms.owner):
- curs.execute("insert into alist (name, acl) values (?, 'owner')", [name])
-
- conn.commit()
-
- return(redirect('/admin_plus/' + url_pas(name)))
- else:
- curs.execute('select acl from alist where name = ?', [name])
- test = curs.fetchall()
-
- data = '<ul>'
- exist_list = ['', '', '', '', '', '', '']
- for go in test:
- if(go[0] == 'ban'):
- exist_list[0] = 'checked="checked"'
- elif(go[0] == 'mdel'):
- exist_list[1] = 'checked="checked"'
- elif(go[0] == 'toron'):
- exist_list[2] = 'checked="checked"'
- elif(go[0] == 'check'):
- exist_list[3] = 'checked="checked"'
- elif(go[0] == 'acl'):
- exist_list[4] = 'checked="checked"'
- elif(go[0] == 'hidel'):
- exist_list[5] = 'checked="checked"'
- elif(go[0] == 'owner'):
- exist_list[6] = 'checked="checked"'
- data += '<li><input type="checkbox" name="ban" ' + exist_list[0] + '> 차단</li>'
- data += '<li><input type="checkbox" name="mdel" ' + exist_list[1] + '> 많은 문서 삭제</li>'
- data += '<li><input type="checkbox" name="toron" ' + exist_list[2] + '> 토론 관리</li>'
- data += '<li><input type="checkbox" name="check" ' + exist_list[3] + '> 사용자 검사</li>'
- data += '<li><input type="checkbox" name="acl" ' + exist_list[4] + '> 문서 ACL</li>'
- data += '<li><input type="checkbox" name="hidel" ' + exist_list[5] + '> 역사 숨김</li>'
- data += '<li><input type="checkbox" name="owner" ' + exist_list[6] + '> 소유자</li></ul>'
- return(
- html_minify(
- template('index',
- imp = ['관리 그룹 추가', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post">' \
- + data + \
- '<div class="form-actions"> \
- <button class="btn btn-primary" type="submit">저장</button> \
- </div> \
- </form>',
- menu = [['manager', '관리자']]
- )
- )
- )
- else:
- return(re_error('/error/3'))
-
- @route('/admin_list')
- def admin_list():
- i = 1
- div = '<ul>'
-
- curs.execute("select id, acl from user where not acl = 'user'")
- user_data = curs.fetchall()
- for data in user_data:
- name = ip_pas(data[0]) + ' (' + data[1] + ')'
- div += '<li>' + str(i) + '. ' + name + '</li>'
-
- i += 1
-
- div += '</ul>'
-
- return(
- html_minify(
- template('index',
- imp = ['관리자 목록', wiki_set(1), custom(), other2([0, 0])],
- data = div,
- menu = [['other', '기타']]
- )
- )
- )
-
- @route('/record/<name:path>')
- @route('/record/<name:path>/n/<num:int>')
- @route('/recent_changes')
- def recent_changes(name = None, num = 1):
- ydmin = admin_check(1, None)
- zdmin = admin_check(6, None)
- ban = ''
- send = '<br>'
- div = '<table style="width: 100%; text-align: center;"> \
- <tbody> \
- <tr> \
- <td style="width: 33.3%;">문서명</td> \
- <td style="width: 33.3%;">기여자</td> \
- <td style="width: 33.3%;">시간</td> \
- </tr>'
-
- if(name):
- if(num * 50 <= 0):
- v = 50
- else:
- v = num * 50
-
- i = v - 50
- div = '<a href="/user/' + url_pas(name) + '/topic">(토론 기록)</a><br><br>' + div
- curs.execute("select id, title, date, ip, send, leng from history where ip = ? order by date desc limit ?, ?", [name, str(i), str(v)])
- else:
- curs.execute("select id, title, date, ip, send, leng from history where not date = 'Dump' order by date desc limit 50")
- rows = curs.fetchall()
- for data in rows:
- send = '<br>'
- if(data[4]):
- if(not re.search("^(?: *)$", data[4])):
- send = data[4]
-
- title = html.escape(data[1])
-
- if(re.search("\+", data[5])):
- leng = '<span style="color:green;">' + data[5] + '</span>'
- elif(re.search("\-", data[5])):
- leng = '<span style="color:red;">' + data[5] + '</span>'
- else:
- leng = '<span style="color:gray;">' + data[5] + '</span>'
-
- if(ydmin == 1):
- curs.execute("select * from ban where block = ?", [data[3]])
- row = curs.fetchall()
- if(row):
- ban = ' <a href="/ban/' + url_pas(data[3]) + '">(해제)</a>'
- else:
- ban = ' <a href="/ban/' + url_pas(data[3]) + '">(차단)</a>'
-
- ip = ip_pas(data[3])
-
- if((int(data[0]) - 1) == 0):
- revert = ''
- else:
- 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>'
-
- style = ''
- curs.execute("select * from hidhi where title = ? and re = ?", [data[1], data[0]])
- row = curs.fetchall()
- if(zdmin == 1):
- if(row):
- ip += ' (숨김)'
- hidden = ' <a href="/history/' + url_pas(data[1]) + '/r/' + data[0] + '/hidden">(공개)'
- else:
- hidden = ' <a href="/history/' + url_pas(data[1]) + '/r/' + data[0] + '/hidden">(숨김)'
- else:
- if(row):
- ip = '숨김'
- hidden = ''
- send = '숨김'
- ban = ''
- style = 'display:none;'
- else:
- hidden = ''
-
- div += '<tr style="' + style + '"> \
- <td> \
- <a href="/w/' + url_pas(data[1]) + '">' + title + '</a> (<a href="/history/' + url_pas(data[1]) + '">' + data[0] + '판</a>) ' + revert + ' (' + leng + ') \
- </td> \
- <td>' + ip + ban + hidden + '</td> \
- <td>' + data[2] + '</td> \
- </tr> \
- <tr> \
- <td colspan="3">' + send + '</td> \
- </tr>'
- else:
- div += '</tbody> \
- </table>'
- if(name):
- curs.execute("select end, why from ban where block = ?", [name])
- ban_it = curs.fetchall()
- if(ban_it):
- sub = '(차단)'
- else:
- sub = 0
- title = '기여 기록'
- menu = [['other', '기타'], ['user', '사용자']]
- div += '<br><a href="/record/' + url_pas(name) + '/n/' + str(num - 1) + '">(이전)</a> <a href="/record/' + url_pas(name) + '/n/' + str(num + 1) + '">(이후)</a>'
- else:
- sub = 0
- menu = 0
- title = '최근 변경내역'
-
- return(
- html_minify(
- template('index',
- imp = [title, wiki_set(1), custom(), other2([sub, 0])],
- data = div,
- menu = menu
- )
- )
- )
-
- @route('/history/<name:path>/r/<num:int>/hidden')
- def history_hidden(name = None, num = None):
- if(admin_check(6, 'history_hidden (' + name + '#' + str(num) + ')') == 1):
- curs.execute("select * from hidhi where title = ? and re = ?", [name, str(num)])
- exist = curs.fetchall()
- if(exist):
- curs.execute("delete from hidhi where title = ? and re = ?", [name, str(num)])
- else:
- curs.execute("insert into hidhi (title, re) values (?, ?)", [name, str(num)])
-
- conn.commit()
-
- return(redirect('/history/' + url_pas(name)))
-
- @route('/user_log')
- @route('/user_log/n/<num:int>')
- def user_log(num = 1):
- if(num * 50 <= 0):
- i = 50
- else:
- i = num * 50
-
- j = i - 50
- list_data = '<ul>'
- ydmin = admin_check(1, None)
-
- curs.execute("select id from user limit ?, ?", [str(j), str(i)])
- user_list = curs.fetchall()
- for data in user_list:
- if(ydmin == 1):
- curs.execute("select block from ban where block = ?", [data[0]])
- ban_exist = curs.fetchall()
- if(ban_exist):
- ban_button = ' <a href="/ban/' + url_pas(data[0]) + '">(해제)</a>'
- else:
- ban_button = ' <a href="/ban/' + url_pas(data[0]) + '">(차단)</a>'
- else:
- ban_button = ''
-
- ip = ip_pas(data[0])
-
- list_data += '<li>' + str(j + 1) + '. ' + ip + ban_button + '</li>'
-
- j += 1
- else:
- list_data += '</ul><br><a href="/user_log/n/' + str(num - 1) + '">(이전)</a> <a href="/user_log/n/' + str(num + 1) + '">(이후)</a>'
- return(
- html_minify(
- template('index',
- imp = ['사용자 가입 기록', wiki_set(1), custom(), other2([0, 0])],
- data = list_data,
- menu = [['other', '기타']]
- )
- )
- )
- @route('/admin_log')
- @route('/admin_log/n/<num:int>')
- def user_log(num = 1):
- if(num * 50 <= 0):
- i = 50
- else:
- i = num * 50
-
- j = i - 50
- list_data = '<ul>'
-
- curs.execute("select who, what, time from re_admin order by time desc limit ?, ?", [str(j), str(i)])
- get_list = curs.fetchall()
- for data in get_list:
- ip = ip_pas(data[0])
-
- list_data += '<li>' + str(j + 1) + '. ' + ip + ' / ' + data[1] + ' / ' + data[2] + '</li>'
-
- j += 1
- else:
- list_data += '</ul><br> \
- <span>주의 : 권한 사용 안하고 열람만 해도 기록되는 경우도 있습니다.</span> \
- <br> \
- <br> \
- <a href="/admin_log/n/' + str(num - 1) + '">(이전)</a> <a href="/admin_log/n/' + str(num + 1) + '">(이후)</a>'
- return(
- html_minify(
- template('index',
- imp = ['관리자 권한 기록', wiki_set(1), custom(), other2([0, 0])],
- data = list_data,
- menu = [['other', '기타']]
- )
- )
- )
- @route('/give_log')
- @route('/give_log/n/<num:int>')
- def give_log(num = 1):
- if(num * 50 <= 0):
- i = 50
- else:
- i = num * 50
-
- j = i - 50
- list_data = '<ul>'
- back = ''
- curs.execute("select name, acl from alist order by name asc limit ?, ?", [str(j), str(i)])
- get_list = curs.fetchall()
- for data in get_list:
- if(back != data[0]):
- back = data[0]
- j += 1
- list_data += '<li>' + str(j) + '. ' + data[0] + ' (' + data[1] + ')</li>'
- else:
- list_data += '</ul><br><a href="/give_log/n/' + str(num - 1) + '">(이전)</a> <a href="/give_log/n/' + str(num + 1) + '">(이후)</a>'
- return(
- html_minify(
- template('index',
- imp = ['권한 목록', wiki_set(1), custom(), other2([0, 0])],
- data = list_data,
- menu = [['other', '기타']]
- )
- )
- )
- @route('/indexing')
- def indexing():
- if(admin_check(None, 'indexing') == 1):
- 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;")
- data = curs.fetchall()
- for table in data:
- print('----- ' + table[0] + ' -----')
- curs.execute('select sql from sqlite_master where name = ?', [table[0]])
- cul = curs.fetchall()
- r_cul = re.findall('(?:([^ (]*) text)', str(cul[0]))
- for n_cul in r_cul:
- print(n_cul)
- sql = 'create index index_' + table[0] + '_' + n_cul + ' on ' + table[0] + '(' + n_cul + ')'
- curs.execute(sql)
- conn.commit()
- return(redirect('/'))
- else:
- return(re_error('/error/3'))
-
- @route('/xref/<name:path>')
- @route('/xref/<name:path>/n/<num:int>')
- def xref(name = None, num = 1):
- if(num * 50 <= 0):
- v = 50
- else:
- v = num * 50
-
- i = v - 50
- div = '<ul>'
-
- curs.execute("delete from back where title = ? and link = ''", [name])
- conn.commit()
-
- curs.execute("select link, type from back where title = ? order by link asc limit ?, ?", [name, str(i), str(v)])
- rows = curs.fetchall()
- for data in rows:
- div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a>'
-
- if(data[1]):
- div += ' (' + data[1] + ')'
-
- div += '</li>'
- else:
- 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>'
-
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (역링크)', 0])],
- data = div,
- menu = [['w/' + url_pas(name), '문서']]
- )
- )
- )
-
- @route('/recent_discuss')
- @route('/recent_discuss/<tools:path>')
- def recent_discuss(tools = 'normal'):
- if(tools == 'normal' or tools == 'close'):
- div = ''
-
- if(tools == 'normal'):
- div += '<a href="/recent_discuss/close">(닫힌 토론)</a>'
- m_sub = 0
- else:
- div += '<a href="/recent_discuss">(열린 토론)</a>'
- m_sub = ' (닫힘)'
- div += '<br> \
- <br> \
- <table style="width: 100%; text-align: center;"> \
- <tbody> \
- <tr> \
- <td style="width: 50%;">토론명</td> \
- <td style="width: 50%;">시간</td> \
- </tr>'
- else:
- return(redirect('/'))
-
- curs.execute("select title, sub, date from rd order by date desc limit 50")
- rows = curs.fetchall()
- for data in rows:
- title = html.escape(data[0])
- sub = html.escape(data[1])
- close = 0
- if(tools == 'normal'):
- curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [data[0], data[1]])
- if(curs.fetchall()):
- close = 1
- else:
- curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [data[0], data[1]])
- if(not curs.fetchall()):
- close = 1
- if(close == 0):
- div += '<tr> \
- <td> \
- <a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[1]) + '">' + title + '</a> (' + sub + ') \
- </td> \
- <td>' + data[2] + '</td> \
- </tr>'
- else:
- div += '</tbody> \
- </table>'
-
- return(
- html_minify(
- template('index',
- imp = ['최근 토론내역', wiki_set(1), custom(), other2([m_sub, 0])],
- data = div,
- menu = 0
- )
- )
- )
- @route('/block_log')
- @route('/block_log/n/<num:int>')
- def block_log(num = 1):
- if(num * 50 <= 0):
- v = 50
- else:
- v = num * 50
-
- i = v - 50
- div = '<table style="width: 100%; text-align: center;"> \
- <tbody> \
- <tr> \
- <td style="width: 33.3%;">차단자</td> \
- <td style="width: 33.3%;">관리자</td> \
- <td style="width: 33.3%;">기간</td> \
- </tr> \
- <tr> \
- <td colspan="2">이유</td> \
- <td>시간</td> \
- </tr>'
-
- curs.execute("select why, block, blocker, end, today from rb order by today desc limit ?, ?", [str(i), str(v)])
- rows = curs.fetchall()
- for data in rows:
- why = html.escape(data[0])
-
- b = re.search("^([0-9]{1,3}\.[0-9]{1,3})$", data[1])
- if(b):
- ip = data[1] + ' (대역)'
- else:
- ip = ip_pas(data[1])
- if(data[3] != ''):
- end = data[3]
- else:
- end = '무기한'
-
- div += '<tr> \
- <td>' + ip + '</td> \
- <td>' + ip_pas(data[2]) + '</td> \
- <td>' + end + '</td> \
- </tr> \
- <tr> \
- <td colspan="2">' + why + '</td> \
- <td>' + data[4] + '</td> \
- </tr>'
- else:
- div += '</tbody> \
- </table> \
- <br> \
- <a href="/block_log/n/' + str(num - 1) + '">(이전)</a> <a href="/block_log/n/' + str(num + 1) + '">(이후)</a>'
-
- return(
- html_minify(
- template('index',
- imp = ['차단 기록', wiki_set(1), custom(), other2([0, 0])],
- data = div,
- menu = [['other', '기타']]
- )
- )
- )
- @route('/history/<name:path>', method=['POST', 'GET'])
- @route('/history/<name:path>/n/<num:int>', method=['POST', 'GET'])
- def history_view(name = None, num = 1):
- if(request.method == 'POST'):
- return(redirect('/w/' + url_pas(name) + '/r/' + request.forms.b + '/diff/' + request.forms.a))
- else:
- select = ''
- if(num * 50 <= 0):
- i = 50
- else:
- i = num * 50
-
- j = i - 50
-
- admin1 = admin_check(1, None)
- admin2 = admin_check(6, None)
-
- div = '<table style="width: 100%; text-align: center;"> \
- <tbody> \
- <tr> \
- <td style="width: 33.3%;">판</td> \
- <td style="width: 33.3%;">기여자</td> \
- <td style="width: 33.3%;">시간</td> \
- </tr>'
-
- curs.execute("select send, leng, ip, date, title, id from history where title = ? order by id + 0 desc limit ?, ?", [name, str(j), str(i)])
- all_data = curs.fetchall()
- for data in all_data:
- select += '<option value="' + data[5] + '">' + data[5] + '</option>'
-
- if(data[0]):
- send = data[0]
- else:
- send = '<br>'
-
- if(re.search("^\+", data[1])):
- leng = '<span style="color:green;">' + data[1] + '</span>'
- elif(re.search("^\-", data[1])):
- leng = '<span style="color:red;">' + data[1] + '</span>'
- else:
- leng = '<span style="color:gray;">' + data[1] + '</span>'
-
- ip = ip_pas(data[2])
-
- curs.execute("select block from ban where block = ?", [data[2]])
- ban_it = curs.fetchall()
- if(ban_it):
- if(admin1 == 1):
- ban = ' <a href="/ban/' + url_pas(data[2]) + '">(해제)</a>'
- else:
- ban = ' (X)'
- else:
- if(admin1 == 1):
- ban = ' <a href="/ban/' + url_pas(data[2]) + '">(차단)</a>'
- else:
- ban = ''
-
- curs.execute("select * from hidhi where title = ? and re = ?", [name, data[5]])
- hid_it = curs.fetchall()
- if(hid_it):
- if(admin2):
- hidden = ' <a href="/history/' + url_pas(name) + '/r/' + url_pas(data[5]) + '/hidden">(공개)'
- hid = 0
- else:
- hid = 1
- else:
- if(admin2):
- hidden = ' <a href="/history/' + url_pas(name) + '/r/' + url_pas(data[5]) + '/hidden">(숨김)'
- hid = 0
- else:
- hidden = ''
- hid = 0
-
- if(hid == 1):
- div += '<tr> \
- <td colspan="3">숨김</td> \
- </tr>'
- else:
- div += '<tr> \
- <td> \
- ' + data[5] + '판</a> <a href="/w/' + url_pas(name) + '/r/' + url_pas(data[5]) + '">(보기)</a> \
- <a href="/raw/' + url_pas(name) + '/r/' + url_pas(data[5]) + '">(원본)</a> \
- <a href="/revert/' + url_pas(name) + '/r/' + url_pas(data[5]) + '">(되돌리기)</a> (' + leng + ') \
- </td> \
- <td>' + ip + ban + hidden + '</td> \
- <td>' + data[3] + '</td> \
- </tr> \
- <tr> \
- <td colspan="3">' + send + '</td> \
- </tr>'
- else:
- div += '</tbody> \
- </table> \
- <br> \
- <a href="/history/' + url_pas(name) + '/n/' + str(num - 1) + '">(이전)</a> <a href="/history/' + url_pas(name) + '/n/' + str(num + 1) + '">(이후)</a>'
- div = '<form method="post"> \
- <select name="a"> \
- ' + select + ' \
- </select> \
- <select name="b"> \
- ' + select + ' \
- </select> \
- <button class="btn btn-primary" type="submit">비교</button> \
- </form>' + div
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (역사)', 0])],
- data = div,
- menu = [['w/' + url_pas(name), '문서'], ['move_data/' + url_pas(name), '이동 기록']]
- )
- )
- )
-
- @route('/search', method=['POST'])
- def search():
- return(redirect('/search/' + url_pas(request.forms.search)))
- @route('/goto', method=['POST'])
- def goto():
- curs.execute("select title from data where title = ?", [request.forms.search])
- data = curs.fetchall()
- if(data):
- return(redirect('/w/' + url_pas(request.forms.search)))
- else:
- return(redirect('/search/' + url_pas(request.forms.search)))
- @route('/search/<name:path>')
- @route('/search/<name:path>/n/<num:int>')
- def deep_search(name = None, num = 1):
- if(num * 50 <= 0):
- v = num * 50
- else:
- v = 50
- i = v - 50
- div = '<ul>'
- div_plus = ''
- end = ''
- curs.execute("select title from data where title like ?", ['%' + name + '%'])
- title_list = curs.fetchall()
- curs.execute("select title from data where data like ?", ['%' + name + '%'])
- data_list = curs.fetchall()
- curs.execute("select title from data where title = ?", [name])
- exist = curs.fetchall()
- if(exist):
- div = '<ul><li>문서로 <a href="/w/' + url_pas(name) + '">바로가기</a></li><br><br>'
- else:
- div = '<ul><li>문서가 없습니다. <a class="not_thing" href="/w/' + url_pas(name) + '">바로가기</a></li><br><br>'
- if(title_list):
- no = 0
- if(data_list):
- all_list = title_list + data_list
- else:
- all_list = title_list
- else:
- if(data_list):
- no = 1
- all_list = data_list
- else:
- all_list = ''
-
- if(all_list != ''):
- for data in all_list:
- try:
- var_re = re.search(name, data[0])
- except:
- var_re = re.search('\\' + name, data[0])
-
- if(var_re):
- if(no == 0):
- div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (제목)</li>'
- else:
- div_plus += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (내용)</li>'
- else:
- no = 1
- div_plus += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (내용)</li>'
- else:
- div += '<li>검색 결과 없음</li>'
- div += div_plus + end
- 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>'
-
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (검색)', 0])],
- data = div,
- menu = 0
- )
- )
- )
-
- @route('/raw/<name:path>')
- @route('/raw/<name:path>/r/<num:int>')
- @route('/topic/<name:path>/sub/<sub_t:path>/raw/<num:int>')
- def raw_view(name = None, sub_t = None, num = None):
- v_name = name
- sub = ' (원본)'
-
- if(not sub_t and num):
- curs.execute("select title from hidhi where title = ? and re = ?", [name, str(num)])
- hid = curs.fetchall()
- if(hid and admin_check(6, None) != 1):
- return(re_error('/error/3'))
-
- curs.execute("select data from history where title = ? and id = ?", [name, str(num)])
- sub += ' (' + str(num) + '판)'
- menu = [['history/' + url_pas(name), '역사']]
- elif(sub_t):
- curs.execute("select data from topic where id = ? and title = ? and sub = ? and block = ''", [str(num), name, sub_t])
- v_name = '토론 원본'
- sub = ' (' + str(num) + '번)'
- menu = [['topic/' + url_pas(name) + '/sub/' + url_pas(sub_t) + '#' + str(num), '토론']]
- else:
- curs.execute("select data from data where title = ?", [name])
-
- menu = [['w/' + url_pas(name), '문서']]
- data = curs.fetchall()
- if(data):
- p_data = html.escape(data[0][0])
-
- p_data = '<textarea readonly style="height: 80%;">' + p_data + '</textarea>'
-
- return(
- html_minify(
- template('index',
- imp = [v_name, wiki_set(1), custom(), other2([sub, 0])],
- data = p_data,
- menu = menu
- )
- )
- )
- else:
- return(redirect('/w/' + url_pas(name)))
-
- @route('/revert/<name:path>/r/<num:int>', method=['POST', 'GET'])
- def revert(name = None, num = None):
- ip = ip_check()
- can = acl_check(name)
- today = get_time()
-
- if(request.method == 'POST'):
- curs.execute("select title from hidhi where title = ? and re = ?", [name, str(num)])
- hid = curs.fetchall()
- if(hid and admin_check(6, None) != 1):
- return(re_error('/error/3'))
- if(can == 1):
- return(re_error('/ban'))
- else:
- curs.execute("delete from back where link = ?", [name])
- conn.commit()
- curs.execute("select data from history where title = ? and id = ?", [name, str(num)])
- rows = curs.fetchall()
- if(rows):
- curs.execute("select data from data where title = ?", [name])
- row = curs.fetchall()
- if(row):
- leng = leng_check(len(row[0][0]), len(rows[0][0]))
- curs.execute("update data set data = ? where title = ?", [rows[0][0], name])
- else:
- leng = '+' + str(len(rows[0][0]))
- curs.execute("insert into data (title, data, acl) values (?, ?, '')", [name, rows[0][0]])
-
- history_plus(
- name,
- rows[0][0],
- today,
- ip,
- request.forms.send + ' (' + str(num) + '판)',
- leng
- )
-
- namumark(name, rows[0][0], 1, 0, 0)
- conn.commit()
-
- return(redirect('/w/' + url_pas(name)))
- else:
- curs.execute("select title from hidhi where title = ? and re = ?", [name, str(num)])
- hid = curs.fetchall()
- if(hid and admin_check(6, None) != 1):
- return(re_error('/error/3'))
-
- if(can == 1):
- return(re_error('/ban'))
- else:
- curs.execute("select title from history where title = ? and id = ?", [name, str(num)])
- rows = curs.fetchall()
- if(rows):
- l = custom()
- if(l[2] == 0):
- plus = '<span>비 로그인 상태입니다. 비 로그인으로 작업 시 아이피가 역사에 기록됩니다.</span><br><br>'
- else:
- plus = ''
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), l, other2([' (되돌리기)', 0])],
- data = plus + ' \
- <form method="post"> \
- <input placeholder="사유" style="width: 100%;" class="form-control input-sm" name="send" type="text"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">되돌리기</button> \
- </form>',
- menu = [['history/' + url_pas(name), '역사'], ['recent_changes', '최근 변경']]
- )
- )
- )
- else:
- return(redirect('/w/' + url_pas(name)))
-
- @route('/m_del', method=['POST', 'GET'])
- def m_del():
- today = get_time()
- ip = ip_check()
- if(admin_check(2, 'm_del') == 1):
- if(request.method == 'POST'):
- data = request.forms.content + '\r\n'
- m = re.findall('(.*)\r\n', data)
- for g in m:
- curs.execute("select data from data where title = ?", [g])
- rows = curs.fetchall()
- if(rows):
- curs.execute("delete from back where title = ?", [g])
- leng = '-' + str(len(rows[0][0]))
- curs.execute("delete from data where title = ?", [g])
- history_plus(
- g,
- '',
- today,
- ip,
- request.forms.send + ' (대량 삭제)',
- leng
- )
- data = re.sub('(.*)\r\n', '', data, 1)
- conn.commit()
- return(redirect('/'))
- else:
- return(
- html_minify(
- template('index',
- imp = ['많은 문서 삭제', wiki_set(1), custom(), other2([0, 0])],
- data = '<span> \
- 문서명 A \
- <br> \
- 문서명 B \
- <br> \
- 문서명 C \
- <br> \
- <br> \
- 이런 식으로 적으세요. \
- </span> \
- <br> \
- <br> \
- <form method="post"> \
- <textarea style="height: 80%;" name="content"></textarea> \
- <br> \
- <br> \
- <input placeholder="사유" style="width: 100%;" class="form-control input-sm" name="send" type="text"> \
- <br> \
- <br> \
- <div class="form-actions"> \
- <button class="btn btn-primary" type="submit">삭제</button> \
- </div> \
- </form>',
- menu = [['manager', '관리자']]
- )
- )
- )
- else:
- return(re_error('/error/3'))
-
- @route('/edit/<name:path>', method=['POST', 'GET'])
- @route('/edit/<name:path>/section/<num:int>', method=['POST', 'GET'])
- def edit(name = None, num = None):
- ip = ip_check()
- can = acl_check(name)
-
- if(request.method == 'POST'):
- if(can == 1):
- return(re_error('/ban'))
- if(len(request.forms.send) > 500):
- return(re_error('/error/15'))
- if(request.forms.otent == request.forms.content):
- return(re_error('/error/18'))
- today = get_time()
- content = savemark(request.forms.content)
- curs.execute("delete from back where link = ?", [name])
- curs.execute("select data from data where title = ?", [name])
- rows = curs.fetchall()
- if(rows):
- leng = leng_check(len(request.forms.otent), len(content))
- if(num):
- content = rows[0][0].replace(request.forms.otent, content)
-
- curs.execute("update data set data = ? where title = ?", [content, name])
- else:
- leng = '+' + str(len(content))
- curs.execute("insert into data (title, data, acl) values (?, ?, '')", [name, content])
-
- history_plus(
- name,
- content,
- today,
- ip,
- send_p(request.forms.send),
- leng
- )
-
- namumark(name, content, 1, 0, 0)
- include_check(name, content)
- conn.commit()
-
- return(redirect('/w/' + url_pas(name)))
- else:
- if(can == 1):
- return(re_error('/ban'))
-
- curs.execute("select data from data where title = ?", [name])
- rows = curs.fetchall()
- if(rows):
- if(num):
- i = 0
- j = 0
-
- data = rows[0][0] + '\r\n'
- while(1):
- m = re.search("((?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n(?:(?:(?:(?!(?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n).)*)(?:\n)?)+)", data)
- if(m):
- if(i == num - 1):
- g = m.groups()
- data = re.sub("\r\n$", "", g[0])
-
- break
- else:
- data = re.sub("((?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n(?:(?:(?:(?!(?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n).)*)(?:\n)?)+)", "", data, 1)
-
- i += 1
- else:
- j = 1
-
- break
-
- if(j == 0):
- data = re.sub("\r\n$", "", data)
- else:
- data = rows[0][0]
- else:
- data = ''
- if(num):
- action = '/section/' + str(num)
- else:
- action = ''
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (수정)', 0])],
- data = '<form method="post" action="/edit/' + url_pas(name) + action + '"> \
- <textarea style="height: 80%;" name="content">' + data + '</textarea> \
- <textarea style="display: none; height: 80%;" name="otent">' + data + '</textarea> \
- <br> \
- <br> \
- <input placeholder="사유" name="send" style="width: 100%;" type="text"> \
- <br> \
- <br> \
- <div class="form-actions"> \
- <button id="save" class="btn btn-primary" type="submit">저장</button> \
- <button id="preview" class="btn" type="submit" formaction="/preview/' + url_pas(name) + action + '">미리보기</button> \
- </div> \
- </form>',
- menu = [['w/' + url_pas(name), '문서']]
- )
- )
- )
- @route('/preview/<name:path>', method=['POST'])
- @route('/preview/<name:path>/section/<num:int>', method=['POST'])
- def preview(name = None, num = None):
- ip = ip_check()
- can = acl_check(name)
-
- if(can == 1):
- return(re_error('/ban'))
-
- newdata = request.forms.content
- newdata = re.sub('^#(?:redirect|넘겨주기) (?P<in>[^\n]*)', ' * [[\g<in>]] 문서로 넘겨주기', newdata)
- enddata = namumark(name, newdata, 0, 0, 0)
- if(num):
- action = '/section/' + str(num)
- else:
- action = ''
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (미리보기)', 0])],
- data = '<form method="post" action="/edit/' + url_pas(name) + action + '"> \
- <textarea style="height: 80%;" name="content">' + request.forms.content + '</textarea> \
- <textarea style="display: none; height: 80%;" name="otent">' + request.forms.otent + '</textarea> \
- <br> \
- <br> \
- <input placeholder="사유" name="send" style="width: 100%;" type="text"> \
- <br> \
- <br> \
- <div class="form-actions"> \
- <button id="save" class="btn btn-primary" type="submit">저장</button> \
- <button id="preview" class="btn" type="submit" formaction="/preview/' + url_pas(name) + action + '">미리보기</button> \
- </div> \
- </form> \
- <br>' + enddata,
- menu = [['w/' + url_pas(name), '문서']]
- )
- )
- )
-
- @route('/delete/<name:path>', method=['POST', 'GET'])
- def delete(name = None):
- ip = ip_check()
- can = acl_check(name)
-
- if(request.method == 'POST'):
- curs.execute("select data from data where title = ?", [name])
- rows = curs.fetchall()
- if(rows):
- if(can == 1):
- return(re_error('/ban'))
- today = get_time()
-
- leng = '-' + str(len(rows[0][0]))
- history_plus(name, '', today, ip, request.forms.send + ' (삭제)', leng)
-
- curs.execute("delete from back where link = ?", [name])
- curs.execute("delete from data where title = ?", [name])
- conn.commit()
-
- return(redirect('/w/' + url_pas(name)))
- else:
- curs.execute("select title from data where title = ?", [name])
- rows = curs.fetchall()
- if(rows):
- if(can == 1):
- return(re_error('/ban'))
- else:
- l = custom()
- if(l[2] == 0):
- plus = '<span>비 로그인 상태입니다. 비 로그인으로 작업 시 아이피가 역사에 기록됩니다.</span><br><br>'
- else:
- plus = ''
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), l, other2([' (삭제)', 0])],
- data = '<form method="post"> \
- ' + plus + ' \
- <input placeholder="사유" style="width: 100%;" class="form-control input-sm" name="send" type="text"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">삭제</button> \
- </form>',
- menu = [['w/' + url_pas(name), '문서']]
- )
- )
- )
- else:
- return(redirect('/w/' + url_pas(name)))
-
- @route('/move_data/<name:path>')
- @route('/move_data/<name:path>/<n:int>')
- def move_data(name = None, n = 1):
- if(n > 0):
- i = n
- else:
- i = 1
-
- j = i * 50
- da = '<ul>'
-
- curs.execute("select origin, new, date, who, send from move where origin = ? or new = ? limit ?, ?", [name, name, j - 50, j])
- for d in curs.fetchall():
- if(d[4] == ''):
- sn = '(없음)'
- else:
- sn = d[4]
- 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>'
- da += '</ul><br><a href="/move_data/' + name + '/' + str(n - 1) + '">(이전)</a> <a href="/move_data/' + name + '/' + str(n + 1) + '">(이후)</a>'
-
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (이동)', 0])],
- data = da,
- menu = [['w/' + url_pas(name), '문서']]
- )
- )
- )
-
- @route('/move/<name:path>', method=['POST', 'GET'])
- def move(name = None):
- ip = ip_check()
- can = acl_check(name)
- today = get_time()
- if(can == 1):
- return(re_error('/ban'))
-
- if(request.method == 'POST'):
- curs.execute("select data from data where title = ?", [name])
- rows = curs.fetchall()
- leng = '0'
- curs.execute("select title from history where title = ?", [request.forms.title])
- row = curs.fetchall()
- if(row):
- return(re_error('/error/19'))
- if(rows):
- curs.execute("update data set title = ? where title = ?", [request.forms.title, name])
- curs.execute("update back set link = ? where link = ?", [request.forms.title, name])
-
- d = rows[0][0]
- else:
- d = ''
-
- history_plus(
- name,
- d,
- today,
- ip,
- request.forms.send + ' (<a href="/w/' + url_pas(name) + '">' + name + '</a> - <a href="/w/' + url_pas(request.forms.title) + '">' + request.forms.title + '</a> 이동)',
- leng
- )
-
- curs.execute('insert into move (origin, new, date, who, send) values (?, ?, ?, ?, ?)', [name, request.forms.title, today, ip, request.forms.send])
- curs.execute("update history set title = ? where title = ?", [request.forms.title, name])
- conn.commit()
-
- return(redirect('/w/' + url_pas(request.forms.title)))
- else:
- l = custom()
- if(l[2] == 0):
- plus = '<span>비 로그인 상태입니다. 비 로그인으로 작업 시 아이피가 역사에 기록됩니다.</span><br><br>'
- else:
- plus = ''
-
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), l, other2([' (이동)', 0])],
- data = '<form method="post"> \
- ' + plus + ' \
- <input placeholder="문서명" class="form-control input-sm" value="' + name + '" name="title" type="text"> \
- <br> \
- <br> \
- <input placeholder="사유" style="width: 100%;" class="form-control input-sm" name="send" type="text"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">이동</button> \
- </form>',
- menu = [['w/' + url_pas(name), '문서']]
- )
- )
- )
-
- @route('/other')
- def other():
- return(
- html_minify(
- template('index',
- imp = ['기타 메뉴', wiki_set(1), custom(), other2([0, 0])],
- data = namumark('', '[목차(없음)]\r\n' + \
- '== 기록 ==\r\n' + \
- ' * [[wiki:block_log|차단 기록]]\r\n' + \
- ' * [[wiki:user_log|가입 기록]]\r\n' + \
- ' * [[wiki:admin_log|권한 기록]]\r\n' + \
- ' * [[wiki:manager/6|사용자 기록]]\r\n' + \
- ' * [[wiki:not_close_topic|열린 토론 목록]]\r\n' + \
- '== 기타 ==\r\n' + \
- ' * [[wiki:title_index|모든 문서]]\r\n' + \
- ' * [[wiki:acl_list|ACL 문서]]\r\n' + \
- ' * [[wiki:admin_list|관리자 목록]]\r\n' + \
- ' * [[wiki:give_log|권한 목록]]\r\n' + \
- ' * [[wiki:upload|파일 올리기]]\r\n' + \
- '== 관리자 ==\r\n' + \
- ' * [[wiki:manager/1|관리자 메뉴]]\r\n' + \
- '== 버전 ==\r\n' + \
- '이 오픈나무는 [[https://github.com/2DU/openNAMU/blob/SQLite/version.md|' + r_ver + p_ver + ']]판 입니다.', 0, 0, 0),
- menu = 0
- )
- )
- )
-
- @route('/manager', method=['POST', 'GET'])
- @route('/manager/<num:int>', method=['POST', 'GET'])
- def manager(num = 1):
- if(num == 1):
- return(
- html_minify(
- template('index',
- imp = ['관리자 메뉴', wiki_set(1), custom(), other2([0, 0])],
- data = namumark('', '[목차(없음)]\r\n' + \
- '== 목록 ==\r\n' + \
- ' * [[wiki:manager/2|문서 ACL]]\r\n' + \
- ' * [[wiki:manager/3|사용자 검사]]\r\n' + \
- ' * [[wiki:manager/10|사용자 비교]]\r\n' + \
- ' * [[wiki:manager/4|사용자 차단]]\r\n' + \
- ' * [[wiki:manager/5|권한 주기]]\r\n' + \
- ' * [[wiki:m_del|여러 문서 삭제]]\r\n' + \
- '== 소유자 ==\r\n' + \
- ' * [[wiki:indexing|인덱싱]]\r\n' + \
- ' * [[wiki:manager/8|관리 그룹 생성]]\r\n' + \
- ' * [[wiki:edit_set|설정 편집]]\r\n' + \
- ' * [[wiki:manager/9|JSON 출력]]\r\n' + \
- ' * [[wiki:json_in|JSON 입력]]\r\n' + \
- '== 기타 ==\r\n' + \
- ' * 이 메뉴에 없는 기능은 해당 문서의 역사나 토론에서 바로 사용 가능함', 0, 0, 0),
- menu = [['other', '기타']]
- )
- )
- )
- elif(num == 2):
- if(request.method == 'POST'):
- return(redirect('/acl/' + url_pas(request.forms.name)))
- else:
- return(
- html_minify(
- template('index',
- imp = ['ACL 이동', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <input placeholder="문서명" name="name" type="text"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">이동</button> \
- </form>',
- menu = [['manager', '관리자']]
- )
- )
- )
- elif(num == 3):
- if(request.method == 'POST'):
- return(redirect('/check/' + url_pas(request.forms.name)))
- else:
- return(
- html_minify(
- template('index',
- imp = ['검사 이동', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <input placeholder="사용자명" name="name" type="text"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">이동</button> \
- </form>',
- menu = [['manager', '관리자']]
- )
- )
- )
- elif(num == 4):
- if(request.method == 'POST'):
- return(redirect('/ban/' + url_pas(request.forms.name)))
- else:
- return(
- html_minify(
- template('index',
- imp = ['차단 이동', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <input placeholder="사용자명" name="name" type="text"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">이동</button> \
- </form>',
- menu = [['manager', '관리자']]
- )
- )
- )
- elif(num == 5):
- if(request.method == 'POST'):
- return(redirect('/admin/' + url_pas(request.forms.name)))
- else:
- return(
- html_minify(
- template('index',
- imp = ['권한 이동', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <input placeholder="사용자명" name="name" type="text"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">이동</button> \
- </form>',
- menu = [['manager', '관리자']]
- )
- )
- )
- elif(num == 6):
- if(request.method == 'POST'):
- return(redirect('/record/' + url_pas(request.forms.name)))
- else:
- return(
- html_minify(
- template('index',
- imp = ['기록 이동', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <input placeholder="사용자명" name="name" type="text"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">이동</button> \
- </form>',
- menu = [['other', '기타']]
- )
- )
- )
- elif(num == 8):
- if(request.method == 'POST'):
- return(redirect('/admin_plus/' + url_pas(request.forms.name)))
- else:
- return(
- html_minify(
- template('index',
- imp = ['그룹 생성 이동', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <input placeholder="그룹명" name="name" type="text"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">이동</button> \
- </form>',
- menu = [['manager', '관리자']]
- )
- )
- )
- elif(num == 9):
- if(request.method == 'POST'):
- return(redirect('/json_out/' + url_pas(request.forms.name)))
- else:
- return(
- html_minify(
- template('index',
- imp = ['문서 출력 이동', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <input placeholder="문서명" name="name" type="text"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">이동</button> \
- </form>',
- menu = [['manager', '관리자']]
- )
- )
- )
- elif(num == 10):
- if(request.method == 'POST'):
- return(redirect('/check/' + url_pas(request.forms.name) + '/' + url_pas(request.forms.name2)))
- else:
- return(
- html_minify(
- template('index',
- imp = ['검사 이동', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <input placeholder="사용자명" name="name" type="text"> \
- <br> \
- <br> \
- <input placeholder="비교 대상" name="name2" type="text"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">이동</button> \
- </form>',
- menu = [['manager', '관리자']]
- )
- )
- )
- else:
- return(redirect('/'))
- @route('/json_out/<name:path>')
- def json_out(name = None):
- if(admin_check(None, 'json_out') == 1):
- curs.execute('select data from data where title = ?', [name])
- get_d = curs.fetchall()
- if(get_d):
- da = get_d[0][0]
- else:
- da = ''
- curs.execute('select ip from history where title = ? order by ip asc', [name])
- get_h = curs.fetchall()
- var_n = ''
- hi_d = ''
- for hi in get_h:
- if(hi[0] != var_n):
- var_n = hi[0]
- hi_d += json.dumps(hi[0]) + ', '
- else:
- hi_d = re.sub(', $', '', hi_d)
- if(hi_d == ''):
- return(redirect('/w/' + url_pas(name)))
-
- json_f = '{ "title" : ' + json.dumps(name) + ', "data" : ' + json.dumps(da) + ', "history" : [' + hi_d + '] }'
- return(json_f)
- else:
- return(re_error('/error/3'))
- @route('/json_in', method=['POST', 'GET'])
- def json_in():
- if(admin_check(None, 'json_in') == 1):
- if(request.method == 'POST'):
- data = json.loads(request.forms.data)
- title = data["title"]
- curs.execute('select title from history where title = ?', [title])
- get_d = curs.fetchall()
- if(get_d):
- return(redirect('/w/' + url_pas(title)))
- curs.execute('insert into data (title, data, acl) values (?, ?, "")', [title, data["data"]])
- i = 0
- date = get_time()
- for hi in data["history"]:
- i += 1
- if(i == 1):
- curs.execute('insert into history (id, title, data, date, ip, send, leng) values (?, ?, ?, ?, ?, "", ?)', [i, title, data["data"], date, hi, '+' + len(data["data"])])
- else:
- curs.execute('insert into history (id, title, data, date, ip, send, leng) values (?, ?, "", ?, ?, "", "0")', [i, title, date, hi])
- conn.commit()
- return(redirect('/w/' + url_pas(title)))
- else:
- return(
- html_minify(
- template('index',
- imp = ['문서 JSON 입력', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <textarea style="height: 80%;" name="data"></textarea> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">입력</button> \
- </form>',
- menu = [['manager', '관리자']]
- )
- )
- )
- else:
- return(re_error('/error/3'))
-
- @route('/title_index')
- @route('/title_index/<num:int>/<page:int>')
- def title_index(num = 1000, page = 1):
- if(page > 0):
- v_page = page * num
- else:
- v_page = 1 * num
- if(num != 0):
- i = [v_page - num + 1]
- else:
- i = [1, 0, 0, 0, 0, 0]
- 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>'
- if(num == 0):
- curs.execute("select title from data order by title asc")
- else:
- curs.execute("select title from data order by title asc limit ?, ?", [str(v_page - num), str(num)])
- title_list = curs.fetchall()
- for list_data in title_list:
- data += '<li>' + str(i[0]) + '. <a href="/w/' + url_pas(list_data[0]) + '">' + list_data[0] + '</a></li>'
- if(num == 0):
- if(re.search('^분류:', list_data[0])):
- i[1] += 1
- elif(re.search('^사용자:', list_data[0])):
- i[2] += 1
- elif(re.search('^틀:', list_data[0])):
- i[3] += 1
- elif(re.search('^파일:', list_data[0])):
- i[4] += 1
- else:
- i[5] += 1
-
- i[0] += 1
- if(num == 0):
- if(title_list):
- data += '<br><br><li>이 위키에는 총 ' + str(i[0]) + '개의 문서가 있습니다.</li><br><br> \
- <li>틀 문서는 총 ' + str(i[3]) + '개의 문서가 있습니다.</li> \
- <li>분류 문서는 총 ' + str(i[1]) + '개의 문서가 있습니다.</li> \
- <li>사용자 문서는 총 ' + str(i[2]) + '개의 문서가 있습니다.</li> \
- <li>파일 문서는 총 ' + str(i[4]) + '개의 문서가 있습니다.</li> \
- <li>나머지 문서는 총 ' + str(i[5]) + '개의 문서가 있습니다.</li>'
- else:
- data += '</ul><br><a href="/title_index/' + str(num) + '/' + str(page - 1) + '">(이전)</a> <a href="/title_index/' + str(num) + '/' + str(page + 1) + '">(이후)</a>'
-
- return(
- html_minify(
- template('index',
- imp = ['모든 문서', wiki_set(1), custom(), other2([' (' + str(num) + ')', 0])],
- data = data,
- menu = [['other', '기타']]
- )
- )
- )
-
- @route('/topic/<name:path>/sub/<sub:path>/b/<num:int>')
- def topic_block(name = None, sub = None, num = None):
- if(admin_check(3, 'blind (' + name + ' - ' + sub + '#' + str(num) + ')') == 1):
- curs.execute("select block from topic where title = ? and sub = ? and id = ?", [name, sub, str(num)])
- block = curs.fetchall()
- if(block):
- if(block[0][0] == 'O'):
- curs.execute("update topic set block = '' where title = ? and sub = ? and id = ?", [name, sub, str(num)])
- else:
- curs.execute("update topic set block = 'O' where title = ? and sub = ? and id = ?", [name, sub, str(num)])
- conn.commit()
-
- rd_plus(
- name,
- sub,
- get_time()
- )
-
- return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num)))
- else:
- return(re_error('/error/3'))
-
- @route('/topic/<name:path>/sub/<sub:path>/notice/<num:int>')
- def topic_top(name = None, sub = None, num = None):
- if(admin_check(3, 'notice (' + name + ' - ' + sub + '#' + str(num) + ')') == 1):
- curs.execute("select * from topic where title = ? and sub = ? and id = ?", [name, sub, str(num)])
- topic_data = curs.fetchall()
- if(topic_data):
- curs.execute("select top from topic where id = ? and title = ? and sub = ?", [str(num), name, sub])
- top_data = curs.fetchall()
- if(top_data):
- if(top_data[0][0] == 'O'):
- curs.execute("update topic set top = '' where title = ? and sub = ? and id = ?", [name, sub, str(num)])
- else:
- curs.execute("update topic set top = 'O' where title = ? and sub = ? and id = ?", [name, sub, str(num)])
- conn.commit()
-
- rd_plus(
- name,
- sub,
- get_time()
- )
- return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num)))
- else:
- return(re_error('/error/3'))
- @route('/topic/<name:path>/sub/<sub:path>/tool/agree')
- def topic_agree(name = None, sub = None):
- if(admin_check(3, 'agree (' + name + ' - ' + sub + ')') == 1):
- ip = ip_check()
-
- curs.execute("select id from topic where title = ? and sub = ? order by id + 0 desc limit 1", [name, sub])
- topic_check = curs.fetchall()
- if(topic_check):
- time = get_time()
-
- curs.execute("select title from agreedis where title = ? and sub = ?", [name, sub])
- agree = curs.fetchall()
- if(agree):
- 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])
- curs.execute("delete from agreedis where title = ? and sub = ?", [name, sub])
- else:
- 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])
- curs.execute("insert into agreedis (title, sub) values (?, ?)", [name, sub])
- conn.commit()
-
- rd_plus(
- name,
- sub,
- time
- )
-
- return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub)))
- else:
-
- return(re_error('/error/3'))
-
- @route('/topic/<name:path>/sub/<sub:path>/tool/<tool:path>')
- def topic_stop(name = None, sub = None, tool = None):
- if(tool == 'close'):
- close = 'O'
- n_close = ''
- data = '토론 닫음'
- n_data = '토론 다시 열기'
- elif(tool == 'stop'):
- close = ''
- n_close = 'O'
- data = '토론 정지'
- n_data = '토론 재 시작'
- else:
- return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub)))
- if(admin_check(3, 'topic stop and end (' + name + ' - ' + sub + ')') == 1):
- ip = ip_check()
-
- curs.execute("select id from topic where title = ? and sub = ? order by id + 0 desc limit 1", [name, sub])
- topic_check = curs.fetchall()
- if(topic_check):
- time = get_time()
-
- curs.execute("select title from stop where title = ? and sub = ? and close = ?", [name, sub, close])
- stop = curs.fetchall()
- if(stop):
- 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])
- curs.execute("delete from stop where title = ? and sub = ? and close = ?", [name, sub, close])
- else:
- 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])
- curs.execute("insert into stop (title, sub, close) values (?, ?, ?)", [name, sub, close])
- curs.execute("delete from stop where title = ? and sub = ? and close = ?", [name, sub, n_close])
-
- conn.commit()
-
- rd_plus(
- name,
- sub,
- time
- )
-
- return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub)))
- else:
-
- return(re_error('/error/3'))
- @route('/topic/<name:path>/sub/<sub:path>/admin/<num:int>')
- def topic_admin(name = None, sub = None, num = None):
- curs.execute("select block, ip from topic where title = ? and sub = ? and id = ?", [name, sub, str(num)])
- data = curs.fetchall()
- if(not data):
- return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub)))
- is_ban = '<li><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/b/' + str(num) + '">'
- if(data[0][0] == 'O'):
- is_ban += '가림 해제'
- else:
- is_ban += '가림'
- is_ban += '</a></li>'
- curs.execute("select id from topic where title = ? and sub = ? and id = ? and top = 'O'", [name, sub, str(num)])
- row = curs.fetchall()
-
- is_ban += '<li><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/notice/' + str(num) + '">'
- if(row):
- is_ban += '공지 해제'
- else:
- is_ban += '공지'
- is_ban += '</a></li>'
- curs.execute("select end from ban where block = ?", [data[0][1]])
- ban_it = curs.fetchall()
- ban = '<li><a href="/ban/' + url_pas(data[0][1]) + '">'
- if(ban_it):
- ban += '차단 해제'
- else:
- ban += '차단'
- ban += '</a></li>' + is_ban
- return(
- html_minify(
- template('index',
- imp = ['토론 관리', wiki_set(1), custom(), other2([' (' + str(num) + '번)', 0])],
- data = '<ul>' + ban + '</ul>',
- menu = [['topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num), '토론']]
- )
- )
- )
- @route('/topic/<name:path>/sub/<sub:path>', method=['POST', 'GET'])
- def topic(name = None, sub = None):
- ban = topic_check(name, sub)
- admin = admin_check(3, None)
-
- if(request.method == 'POST'):
- ip = ip_check()
- today = get_time()
- curs.execute("select id from topic where title = ? and sub = ? order by id + 0 desc limit 1", [name, sub])
- rows = curs.fetchall()
- if(rows):
- num = int(rows[0][0]) + 1
- else:
- num = 1
- m = re.search('^사용자:([^/]+)', name)
- if(m):
- d = m.groups()
- curs.execute('insert into alarm (name, data, date) values (?, ?, ?)', [d[0], ip + '님이 <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '">사용자 토론</a>을 시작했습니다.', today])
-
- if(ban == 1 and admin != 1):
- return(re_error('/ban'))
- rd_plus(name, sub, today)
-
- data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", "[br]", request.forms.content)
- m = re.findall("(?:#([0-9]+))", data)
- for da in m:
- curs.execute("select ip from topic where title = ? and sub = ? and id = ?", [name, sub, da])
- row = curs.fetchall()
- if(row):
- if(not re.search('(\.|:)', row[0][0])):
- 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])
- data = re.sub("(?P<in>#(?:[0-9]+))", '[[\g<in>]]', data)
- data = savemark(data)
-
- curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '')", [str(num), name, sub, data, today, ip])
- conn.commit()
-
- return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub)))
- else:
- s = ''
- div = ''
- curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [name, sub])
- cd = curs.fetchall()
- curs.execute("select title from stop where title = ? and sub = ? and close = ''", [name, sub])
- sd = curs.fetchall()
-
- if(admin == 1):
- if(cd):
- div += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/close">(열기)</a> '
- else:
- div += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/close">(닫기)</a> '
-
- if(sd):
- div += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/stop">(재개)</a> '
- else:
- div += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/stop">(정지)</a> '
- curs.execute("select title from agreedis where title = ? and sub = ?", [name, sub])
- if(curs.fetchall()):
- div += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/agree">(합의)</a>'
- else:
- div += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/agree">(취소)</a>'
-
- div += '<br><br>'
-
- if((sd or cd) and admin != 1):
- s = 'display: none;'
-
- curs.execute("select data, id, date, ip, block, top from topic where title = ? and sub = ? order by id + 0 asc", [name, sub])
- t1 = curs.fetchall()
- curs.execute("select data, id, date, ip from topic where title = ? and sub = ? and top = 'O' order by id + 0 asc", [name, sub])
- t2 = curs.fetchall()
- for d in t2:
- a = ''
- curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['notice (' + name + ' - ' + sub + '#' + d[1] + ')'])
- m = curs.fetchall()
- if(m):
- a += ' @' + m[0][0]
-
- div += '<table id="toron"> \
- <tbody> \
- <tr> \
- <td id="toron_color_red"> \
- <a href="#' + d[1] + '">#' + d[1] + '</a> ' + ip_pas(d[3]) + a + ' <span style="float:right;">' + d[2] + '</span> \
- </td> \
- </tr> \
- <tr> \
- <td>' + namumark('', d[0], 0, 0, 0) + '</td> \
- </tr> \
- </tbody> \
- </table> \
- <br>'
-
- i = 1
- for d in t1:
- if(i == 1):
- start = d[3]
-
- p = d[0]
- if(d[4] == 'O'):
- bd = 'style="background: gainsboro;"'
- if(admin != 1):
- curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['blind (' + name + ' - ' + sub + '#' + str(i) + ')'])
- b = curs.fetchall()
- if(b):
- p = '[[사용자:' + b[0][0] + ']]님이 가림'
- else:
- p = '관리자가 가림'
- else:
- bd = ''
- p = namumark('', p, 0, 0, 0)
- ip = ip_pas(d[3])
- curs.execute('select acl from user where id = ?', [d[3]])
- user_acl = curs.fetchall()
- if(user_acl and user_acl[0][0] != 'user'):
- ip += ' <a href="javascript:void(0);" title="관리자">★</a>'
- if(admin == 1 or bd == ''):
- ip += ' <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/raw/' + str(i) + '">(원본)</a>'
- if(admin == 1):
- ip += ' <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/admin/' + str(i) + '">(관리)</a>'
- curs.execute("select end from ban where block = ?", [d[3]])
- if(curs.fetchall()):
- ip += ' <a href="javascript:void(0);" title="차단자">†</a>'
-
- if(d[5] == '1'):
- c = '_blue'
- elif(d[3] == start):
- c = '_green'
- else:
- c = ''
-
- if(p == ''):
- p = '<br>'
-
- div += '<table id="toron"> \
- <tbody> \
- <tr> \
- <td id="toron_color' + c + '"> \
- <a href="javascript:void(0);" id="' + str(i) + '">#' + str(i) + '</a> ' + ip + ' <span style="float:right;">' + d[2] + '</span> \
- </td> \
- </tr> \
- <tr ' + bd + '> \
- <td>' + p + '</td> \
- </tr> \
- </tbody> \
- </table> \
- <br>'
-
- i += 1
- l = custom()
- if(ban != 1):
- data = '<a id="reload" href="javascript:void(0);" onclick="location.href.endsWith(\'#reload\') ? location.reload(true) : location.href = \'#reload\'"> \
- <i aria-hidden="true" class="fa fa-refresh"></i> \
- </a> \
- <form style="' + s + '" method="post"> \
- <br> \
- <textarea style="width: 100%; height: 100px;" name="content"></textarea> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">전송</button> \
- </form>'
- if(l[2] == 0 and s == ''):
- data += '<span>비 로그인 상태입니다. 비 로그인으로 작업 시 아이피가 토론에 기록됩니다.</span>'
- else:
- data = ''
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), l, other2([' (토론)', 0])],
- data = '<h2 style="margin-top: 0px;">' + sub + '</h2> \
- <br> \
- ' + div + ' \
- ' + data,
- menu = [['topic/' + url_pas(name), '목록']]
- )
- )
- )
-
- @route('/topic/<name:path>', method=['POST', 'GET'])
- @route('/topic/<name:path>/<tool:path>', method=['GET'])
- def close_topic_list(name = None, tool = None):
- div = ''
- i = 0
- list_d = 0
- if(request.method == 'POST'):
- t_num = ''
- while(1):
- curs.execute("select title from topic where title = ? and sub = ? limit 1", [name, request.forms.topic + t_num])
- if(curs.fetchall()):
- if(t_num == ''):
- t_num = ' 2'
- else:
- t_num = ' ' + str(int(t_num.replace(' ', '')) + 1)
- else:
- break
- return(redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(request.forms.topic + t_num)))
- else:
- plus = ''
- menu = [['topic/' + url_pas(name), '목록']]
- if(tool == 'close'):
- curs.execute("select sub from stop where title = ? and close = 'O' order by sub asc", [name])
- sub = '닫힘'
- elif(tool == 'agree'):
- curs.execute("select sub from agreedis where title = ? order by sub asc", [name])
- sub = '합의'
- else:
- curs.execute("select sub from rd where title = ? order by date desc", [name])
- sub = '토론 목록'
- menu = [['w/' + url_pas(name), '문서']]
- plus = '<br> \
- <a href="/topic/' + url_pas(name) + '/close">(닫힘)</a> <a href="/topic/' + url_pas(name) + '/agree">(합의)</a> \
- <br> \
- <br> \
- <input placeholder="토론명" class="form-control" name="topic" style="width: 100%;"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">만들기</button>'
- rows = curs.fetchall()
- for data in rows:
- curs.execute("select data, date, ip, block from topic where title = ? and sub = ? and id = '1'", [name, data[0]])
- row = curs.fetchall()
- if(row):
- it_p = 0
- if(sub == '토론 목록'):
- curs.execute("select title from stop where title = ? and sub = ? and close = 'O' order by sub asc", [name, data[0]])
- close = curs.fetchall()
- if(close):
- it_p = 1
-
- if(it_p != 1):
- div += '<h2><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(data[0]) + '">' + str((i + 1)) + '. ' + data[0] + '</a></h2>'
-
- i += 1
-
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (' + sub + ')', 0])],
- data = '<form style="margin-top: 0px;" method="post"> \
- ' + div + plus + ' \
- </form>',
- menu = menu
- )
- )
- )
-
- @route('/login', method=['POST', 'GET'])
- def login():
- session = request.environ.get('beaker.session')
- agent = request.environ.get('HTTP_USER_AGENT')
- ip = ip_check()
- ban = ban_check()
-
- if(request.method == 'POST'):
- if(ban == 1):
- return(re_error('/ban'))
- curs.execute("select pw from user where id = ?", [request.forms.id])
- user = curs.fetchall()
- if(user):
- if(session.get('Now') == 1):
- return(re_error('/error/11'))
- if(bcrypt.checkpw(bytes(request.forms.pw, 'utf-8'), bytes(user[0][0], 'utf-8'))):
- session['Now'] = 1
- session['DREAMER'] = request.forms.id
- curs.execute("select css from custom where user = ?", [request.forms.id])
- css_data = curs.fetchall()
- if(css_data):
- session['Daydream'] = css_data[0][0]
- else:
- session['Daydream'] = ''
-
- curs.execute("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')", [request.forms.id, ip, agent, get_time()])
- conn.commit()
-
- return(redirect('/user'))
- else:
- return(re_error('/error/10'))
- else:
- return(re_error('/error/5'))
- else:
- if(ban == 1):
- return(re_error('/ban'))
- if(session.get('Now') == 1):
- return(re_error('/error/11'))
- return(
- html_minify(
- template('index',
- imp = ['로그인', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <input placeholder="아이디" name="id" type="text"> \
- <br> \
- <br> \
- <input placeholder="비밀번호" name="pw" type="password"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">로그인</button> \
- <br> \
- <br> \
- <span>주의 : 만약 HTTPS 연결이 아닌 경우 데이터가 유출될 가능성이 있습니다. 이에 대해 책임지지 않습니다.</span> \
- </form>',
- menu = [['user', '사용자']]
- )
- )
- )
-
- @route('/change', method=['POST', 'GET'])
- def change_password():
- ip = ip_check()
- ban = ban_check()
-
- if(request.method == 'POST'):
- if(request.forms.pw2 == request.forms.pw3):
- if(ban == 1):
- return(re_error('/ban'))
- curs.execute("select pw from user where id = ?", [request.forms.id])
- user = curs.fetchall()
- if(user):
- if(re.search('(\.|:)', ip)):
- return(redirect('/login'))
- if(bcrypt.checkpw(bytes(request.forms.pw, 'utf-8'), bytes(user[0][0], 'utf-8'))):
- hashed = bcrypt.hashpw(bytes(request.forms.pw2, 'utf-8'), bcrypt.gensalt())
-
- curs.execute("update user set pw = ? where id = ?", [hashed.decode(), request.forms.id])
- conn.commit()
-
- return(redirect('/user'))
- else:
- return(re_error('/error/10'))
- else:
- return(re_error('/error/5'))
- else:
- return(re_error('/error/20'))
- else:
- if(ban == 1):
- return(re_error('/ban'))
- if(re.search('(\.|:)', ip)):
- return(redirect('/login'))
- return(
- html_minify(
- template('index',
- imp = ['비밀번호 변경', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- <input placeholder="아이디" name="id" type="text"> \
- <br> \
- <br> \
- <input placeholder="현재 비밀번호" name="pw" type="password"> \
- <br> \
- <br> \
- <input placeholder="변경할 비밀번호" name="pw2" type="password"> \
- <br> \
- <br> \
- <input placeholder="재 확인" name="pw3" type="password"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">변경</button> \
- <br> \
- <br> \
- <span>주의 : 만약 HTTPS 연결이 아닌 경우 데이터가 유출될 가능성이 있습니다. 이에 대해 책임지지 않습니다.</span> \
- </form>',
- menu = [['user', '사용자']]
- )
- )
- )
-
- @route('/check/<name:path>')
- @route('/check/<name:path>/<name2:path>')
- def user_check(name = None, name2 = None):
- curs.execute("select acl from user where id = ? or id = ?", [name, name2])
- user = curs.fetchall()
- if(user and user[0][0] != 'user'):
- if(admin_check(None, None) != 1):
- return(re_error('/error/4'))
- if(admin_check(4, 'check (' + name + ')') == 1):
- if(name2):
- if(re.search('(?:\.|:)', name)):
- if(re.search('(?:\.|:)', name2)):
- curs.execute("select name, ip, ua, today from ua_d where ip = ? or ip = ? order by today desc", [name, name2])
- else:
- curs.execute("select name, ip, ua, today from ua_d where ip = ? or name = ? order by today desc", [name, name2])
- else:
- if(re.search('(?:\.|:)', name2)):
- curs.execute("select name, ip, ua, today from ua_d where name = ? or ip = ? order by today desc", [name, name2])
- else:
- curs.execute("select name, ip, ua, today from ua_d where name = ? or name = ? order by today desc", [name, name2])
- elif(re.search('(?:\.|:)', name)):
- curs.execute("select name, ip, ua, today from ua_d where ip = ? order by today desc", [name])
- else:
- curs.execute("select name, ip, ua, today from ua_d where name = ? order by today desc", [name])
- row = curs.fetchall()
- if(row):
- c = '<table style="width: 100%; text-align: center;"> \
- <tbody> \
- <tr> \
- <td style="width: 33.3%;">이름</td> \
- <td style="width: 33.3%;">아이피</td> \
- <td style="width: 33.3%;">언제</td> \
- </tr>'
- for data in row:
- if(data[2]):
- ua = data[2]
- else:
- ua = '<br>'
- c += '<tr> \
- <td>' + ip_pas(data[0]) + '</td> \
- <td>' + ip_pas(data[1]) + '</td> \
- <td>' + data[3] + '</td> \
- </tr> \
- <tr><td colspan="3">' + ua + '</td></tr>'
- else:
- c += '</tbody> \
- </table>'
- else:
- c = ''
-
- return(
- html_minify(
- template('index',
- imp = ['다중 검사', wiki_set(1), custom(), other2([0, 0])],
- data = c,
- menu = [['manager', '관리자']]
- )
- )
- )
- else:
- return(re_error('/error/3'))
-
- @route('/register', method=['POST', 'GET'])
- def register():
- ip = ip_check()
- ban = ban_check()
- if(ban == 1):
- return(re_error('/ban'))
- if(not admin_check(None, None) == 1):
- curs.execute('select data from other where name = "reg"')
- set_d = curs.fetchall()
- if(set_d and set_d[0][0] == 'on'):
- return(re_error('/ban'))
-
- if(request.method == 'POST'):
- if(request.forms.pw == request.forms.pw2):
- if(re.search('(?:[^A-Za-zㄱ-힣0-9 ])', request.forms.id)):
- return(re_error('/error/8'))
- if(len(request.forms.id) > 32):
- return(re_error('/error/7'))
- curs.execute("select id from user where id = ?", [request.forms.id])
- rows = curs.fetchall()
- if(rows):
- return(re_error('/error/6'))
- hashed = bcrypt.hashpw(bytes(request.forms.pw, 'utf-8'), bcrypt.gensalt())
-
- curs.execute("select id from user limit 1")
- user_ex = curs.fetchall()
- if(not user_ex):
- curs.execute("insert into user (id, pw, acl) values (?, ?, '소유자')", [request.forms.id, hashed.decode()])
- else:
- curs.execute("insert into user (id, pw, acl) values (?, ?, 'user')", [request.forms.id, hashed.decode()])
- conn.commit()
-
- return(redirect('/login'))
- else:
- return(re_error('/error/20'))
- else:
- p = ''
- curs.execute('select data from other where name = "contract"')
- d = curs.fetchall()
- if(d):
- if(d[0][0] != ''):
- p = d[0][0] + '<br><br>'
- return(
- html_minify(
- template('index',
- imp = ['회원가입', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post"> \
- ' + p + ' \
- <input placeholder="아이디" name="id" type="text"> \
- <br> \
- <br> \
- <input placeholder="비밀번호" name="pw" type="password"> \
- <br> \
- <br> \
- <input placeholder="재 확인" name="pw2" type="password"> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">가입</button> \
- <br> \
- <br> \
- <span>주의 : 만약 HTTPS 연결이 아닌 경우 데이터가 유출될 가능성이 있습니다. 이에 대해 책임지지 않습니다.</span> \
- </form>',
- menu = [['user', '사용자']]
- )
- )
- )
-
- @route('/logout')
- def logout():
- session = request.environ.get('beaker.session')
- session['Now'] = 0
- session.pop('DREAMER', None)
- return(redirect('/user'))
-
- @route('/ban/<name:path>', method=['POST', 'GET'])
- def user_ban(name = None):
- curs.execute("select acl from user where id = ?", [name])
- user = curs.fetchall()
- if(user and user[0][0] != 'user'):
- if(admin_check(None, None) != 1):
- return(re_error('/error/4'))
- if(request.method == 'POST'):
- if(admin_check(1, 'ban (' + name + ')') == 1):
- ip = ip_check()
-
- if(request.forms.year == '09'):
- end = ''
- else:
- end = request.forms.year + '-' + request.forms.month + '-' + request.forms.day
- curs.execute("select block from ban where block = ?", [name])
- row = curs.fetchall()
- if(row):
- rb_plus(name, '해제', get_time(), ip, '')
-
- curs.execute("delete from ban where block = ?", [name])
- else:
- b = re.search("^([0-9]{1,3}\.[0-9]{1,3})$", name)
- if(b):
- band_d = 'O'
- else:
- band_d = ''
- rb_plus(name, end, get_time(), ip, request.forms.why)
- curs.execute("insert into ban (block, end, why, band) values (?, ?, ?, ?)", [name, end, request.forms.why, band_d])
- conn.commit()
- return(redirect('/ban/' + url_pas(name)))
- else:
- return(re_error('/error/3'))
- else:
- if(admin_check(1, None) == 1):
- curs.execute("select * from ban where block = ?", [name])
- row = curs.fetchall()
- if(row):
- now = '차단 해제'
- data = ''
- else:
- b = re.search("^([0-9]{1,3}\.[0-9]{1,3})$", name)
- if(b):
- now = '대역 차단'
- else:
- now = '차단'
- year_n = int("%04d" % (time.localtime().tm_year))
- year = '<option value="09">영구</option>'
- for i in range(year_n, year_n + 51):
- if(i == year_n):
- year += '<option value="' + str(i) + '" selected>' + str(i) + '</option>'
- else:
- year += '<option value="' + str(i) + '">' + str(i) + '</option>'
- month = '<option value="1" selected>1</option>'
- for i in range(2, 13):
- month += '<option value="' + str(i) + '">' + str(i) + '</option>'
- day = '<option value="1" selected>1</option>'
- for i in range(2, 32):
- day += '<option value="' + str(i) + '">' + str(i) + '</option>'
-
- data = '<select name="year"> \
- ' + year + ' \
- </select> \
- <select name="month"> \
- ' + month + ' \
- </select> \
- <select name="day"> \
- ' + day + ' \
- </select> \
- <br> \
- <br> \
- <input placeholder="사유" class="form-control" name="why" style="width: 100%;"> \
- <br> \
- <br>'
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (' + now + ')', 0])],
- data = '<form method="post"> \
- ' + data + ' \
- <button class="btn btn-primary" type="submit">' + now + '</button> \
- </form>',
- menu = [['manager', '관리자']]
- )
- )
- )
- else:
- return(re_error('/error/3'))
- @route('/user_acl/<name:path>', method=['POST', 'GET'])
- def acl(name = None):
- ip = ip_check()
- if(ip != name or re.search("(\.|:)", name)):
- return(redirect('/login'))
-
- if(request.method == 'POST'):
- curs.execute("select acl from data where title = ?", ['사용자:' + name])
- acl_d = curs.fetchall()
- if(acl_d):
- if(request.forms.select == 'all'):
- curs.execute("update data set acl = 'all' where title = ?", ['사용자:' + name])
- elif(request.forms.select == 'user'):
- curs.execute("update data set acl = 'user' where title = ?", ['사용자:' + name])
- else:
- curs.execute("update data set acl = '' where title = ?", ['사용자:' + name])
-
- conn.commit()
-
- return(redirect('/w/' + url_pas('사용자:' + name)))
- curs.execute("select acl from data where title = ?", ['사용자:' + name])
- acl_d = curs.fetchall()
- if(acl_d):
- if(acl_d[0][0] == 'all'):
- now = '모두'
- elif(acl_d[0][0] == 'user'):
- now = '사용자'
- else:
- now = '일반'
-
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (SET)', 0])],
- data = '<span>현재 ACL : ' + now + '</span> \
- <br> \
- <br> \
- <form method="post"> \
- <select name="select"> \
- <option value="all">모두</option> \
- <option value="user">사용자</option> \
- <option value="normal" selected="selected">일반</option> \
- </select> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">ACL 변경</button> \
- </form>',
- menu = [['user', '사용자']]
- )
- )
- )
- else:
- return(redirect('/w/' + url_pas(name)))
-
- @route('/acl/<name:path>', method=['POST', 'GET'])
- def acl(name = None):
- if(request.method == 'POST'):
- if(admin_check(5, 'acl (' + name + ')') == 1):
- curs.execute("select acl from data where title = ?", [name])
- row = curs.fetchall()
- if(row):
- if(request.forms.select == 'admin'):
- curs.execute("update data set acl = 'admin' where title = ?", [name])
- elif(request.forms.select == 'user'):
- curs.execute("update data set acl = 'user' where title = ?", [name])
- else:
- curs.execute("update data set acl = '' where title = ?", [name])
-
- conn.commit()
-
- return(redirect('/w/' + url_pas(name)))
- else:
- return(re_error('/error/3'))
- else:
- if(admin_check(5, None) == 1):
- curs.execute("select acl from data where title = ?", [name])
- row = curs.fetchall()
- if(row):
- if(row[0][0] == 'admin'):
- now = '관리자'
- elif(row[0][0] == 'user'):
- now = '사용자'
- else:
- now = '일반'
-
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (ACL)', 0])],
- data = '<span>현재 ACL : ' + now + '</span> \
- <br> \
- <br> \
- <form method="post"> \
- <select name="select"> \
- <option value="admin" selected="selected">관리자</option> \
- <option value="user">사용자</option> \
- <option value="normal">일반</option> \
- </select> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">ACL 변경</button> \
- </form>',
- menu = [['w/' + url_pas(name), '문서'], ['manager', '관리자']]
- )
- )
- )
- else:
- return(redirect('/w/' + url_pas(name)) )
- else:
- return(re_error('/error/3'))
-
- @route('/admin/<name:path>', method=['POST', 'GET'])
- def user_admin(name = None):
- if(request.method == 'POST'):
- if(admin_check(None, 'admin (' + name + ')') == 1):
- if(request.forms.select == 'X'):
- curs.execute("update user set acl = 'user' where id = ?", [name])
- else:
- curs.execute("update user set acl = ? where id = ?", [request.forms.select, name])
- conn.commit()
-
- return(redirect('/admin/' + url_pas(name)))
- else:
- return(re_error('/error/3'))
- else:
- if(admin_check(None, None) == 1):
- curs.execute("select acl from user where id = ?", [name])
- user = curs.fetchall()
- if(user):
- div = '<option value="X">X</option>'
-
- curs.execute('select name from alist order by name asc')
- get_alist = curs.fetchall()
- if(get_alist):
- i = 0
- name_rem = ''
- for data in get_alist:
- if(name_rem != data[0]):
- name_rem = data[0]
- if(user[0][0] == data[0]):
- div += '<option value="' + data[0] + '" selected="selected">' + data[0] + '</option>'
- else:
- div += '<option value="' + data[0] + '">' + data[0] + '</option>'
-
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (권한 부여)', 0])],
- data = '<form method="post"> \
- <select name="select"> \
- ' + div + ' \
- </select> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">변경</button> \
- </form>',
- menu = [['manager', '관리자']]
- )
- )
- )
- else:
- return(re_error('/error/5'))
- else:
- return(re_error('/error/3'))
-
- @route('/w/<name:path>/r/<a:int>/diff/<b:int>')
- def diff_data(name = None, a = None, b = None):
- curs.execute("select data from history where id = ? and title = ?", [str(a), name])
- a_raw_data = curs.fetchall()
- if(a_raw_data):
- curs.execute("select data from history where id = ? and title = ?", [str(b), name])
- b_raw_data = curs.fetchall()
- if(b_raw_data):
- a_data = html.escape(a_raw_data[0][0])
- b_data = html.escape(b_raw_data[0][0])
- if(a_data == b_data):
- result = '내용이 같습니다.'
- else:
- diff_data = difflib.SequenceMatcher(None, a_data, b_data)
- result_1 = diff(diff_data, 1)
- result_2 = diff(diff_data, 0)
- if(a_data == result_1):
- result = '<pre>' + result_2 + '</pre>'
- elif(b_data == result_2):
- result = '<pre>' + result_1 + '</pre>'
- else:
- result = '<pre>' + result_1 + '<hr>' + result_2 + '</pre>'
-
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (비교)', 0])],
- data = result,
- menu = [['history/' + url_pas(name), '역사']]
- )
- )
- )
- return(redirect('/history/' + url_pas(name)))
-
- @route('/down/<name:path>')
- def down(name = None):
- curs.execute("select title from data where title like ?", ['%' + name + '/%'])
- under = curs.fetchall()
-
- div = '<ul>'
- i = 0
- for data in under:
- div += '<li>' + str(i + 1) + '. <a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
- i += 1
-
- div += '</ul>'
-
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([' (하위)', 0])],
- data = div,
- menu = [['w/' + url_pas(name), '문서']]
- )
- )
- )
- @route('/w/<name:path>')
- @route('/w/<name:path>/r/<num:int>')
- @route('/w/<name:path>/from/<redirect:path>')
- def read_view(name = None, num = None, redirect = None):
- data_none = 0
- sub = ''
- acl = ''
- div = ''
- topic = 0
-
- if(not num):
- session = request.environ.get('beaker.session')
- if(session.get('View_List')):
- m = re.findall('([^\n]+)\n', session.get('View_List'))
- if(m[-1] != name):
- session['View_List'] += name + '\n'
- if(len(m) > 50):
- session['View_List'] = re.sub('([^\n]+)\n', '', session.get('View_List'), 1)
- else:
- session['View_List'] = name + '\n'
- curs.execute("select sub from rd where title = ? order by date desc", [name])
- rows = curs.fetchall()
- for data in rows:
- curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [name, data[0]])
- row = curs.fetchall()
- if(not row):
- topic = 1
-
- break
-
- curs.execute("select title from data where title like ?", ['%' + name + '/%'])
- under = curs.fetchall()
- if(under):
- down = 1
- else:
- down = 0
-
- m = re.search("^(.*)\/(.*)$", name)
- if(m):
- uppage = m.groups()[0]
- else:
- uppage = 0
-
- if(admin_check(5, None) == 1):
- admin_memu = 1
- else:
- admin_memu = 0
-
- if(re.search("^분류:", name)):
- curs.execute("delete from back where title = ? and type='cat' and link = ''", [name])
- conn.commit()
-
- curs.execute("select link from back where title = ? and type='cat' order by link asc", [name])
- rows = curs.fetchall()
- if(rows):
- div = '[목차(없음)]\r\n== 분류 ==\r\n'
- u_div = ''
- i = 0
-
- for data in rows:
- if(re.search('^분류:', data[0])):
- if(u_div == ''):
- u_div = '=== 하위 분류 ===\r\n'
- u_div += ' * [[:' + data[0] + ']]\r\n'
- else:
- div += ' * [[' + data[0] + ']]\r\n'
- div += u_div
- if(num):
- curs.execute("select title from hidhi where title = ? and re = ?", [name, str(num)])
- hid = curs.fetchall()
- if(hid and admin_check(6, None) != 1):
- return(redirect('/history/' + url_pas(name)))
- curs.execute("select title, data from history where title = ? and id = ?", [name, str(num)])
- else:
- curs.execute("select acl, data from data where title = ?", [name])
- rows = curs.fetchall()
- if(rows):
- if(not num):
- if(rows[0][0] == 'admin'):
- acl = ' (관리자)'
- elif(rows[0][0] == 'user'):
- acl = ' (사용자)'
-
- elsedata = rows[0][1]
- else:
- data_none = 1
- response.status = 404
- elsedata = ''
- m = re.search("^사용자:([^/]*)", name)
- if(m):
- g = m.groups()
-
- curs.execute("select acl from user where id = ?", [g[0]])
- test = curs.fetchall()
- if(test and test[0][0] != 'user'):
- acl = ' (관리자)'
- else:
- acl = ''
- if(rows):
- if(rows[0][0] == 'all'):
- acl += ' (모두)'
- elif(rows[0][0] == 'user'):
- acl += ' (사용자)'
- curs.execute("select block from ban where block = ?", [g[0]])
- user = curs.fetchall()
- if(user):
- sub = ' (차단)'
-
- if(redirect):
- elsedata = re.sub("^#(?:redirect|넘겨주기) (?P<in>[^\n]*)", " * [[\g<in>]] 문서로 넘겨주기", elsedata)
-
- enddata = namumark(name, elsedata, 0, 0, 1)
- if(data_none == 1):
- menu = [['edit/' + url_pas(name), '생성'], ['topic/' + url_pas(name), topic], ['history/' + url_pas(name), '역사'], ['move/' + url_pas(name), '이동'], ['xref/' + url_pas(name), '역링크']]
- else:
- 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), '역링크']]
- if(admin_memu == 1):
- menu += [['acl/' + url_pas(name), 'ACL']]
- if(redirect):
- menu += [['w/' + url_pas(name), '넘기기']]
- enddata = '<ul id="redirect"><li><a href="/w/' + url_pas(redirect) + '/from/' + url_pas(name) + '">' + redirect + '</a>에서 넘어 왔습니다.</li></ul><br>' + enddata
- if(uppage != 0):
- menu += [['w/' + url_pas(uppage), '상위']]
- if(down):
- menu += [['down/' + url_pas(name), '하위']]
- if(num):
- menu = [['history/' + url_pas(name), '역사']]
- sub = ' (' + str(num) + '판)'
- acl = ''
- r_date = 0
- else:
- curs.execute("select date from history where title = ? order by date desc limit 1", [name])
- date = curs.fetchall()
- if(date):
- r_date = date[0][0]
- else:
- r_date = 0
- return(
- html_minify(
- template('index',
- imp = [name, wiki_set(1), custom(), other2([sub + acl, r_date])],
- data = enddata + namumark(name, div, 0, 0, 0),
- menu = menu
- )
- )
- )
- @route('/user/<name:path>/topic')
- @route('/user/<name:path>/topic/<num:int>')
- def user_topic_list(name = None, num = 1):
- if(num * 50 <= 0):
- v = 50
- else:
- v = num * 50
-
- i = v - 50
- ydmin = admin_check(1, None)
- div = '<table style="width: 100%; text-align: center;"> \
- <tbody> \
- <tr> \
- <td style="width: 33.3%;">토론명</td> \
- <td style="width: 33.3%;">작성자</td> \
- <td style="width: 33.3%;">시간</td> \
- </tr>'
- div = '<a href="/record/' + url_pas(name) + '">(기여 기록)</a><br><br>' + div
-
- curs.execute("select title, id, sub, ip, date from topic where ip = ? order by date desc limit ?, ?", [name, str(i), str(v)])
- rows = curs.fetchall()
- if(rows):
- for data in rows:
- title = html.escape(data[0])
- sub = html.escape(data[2])
-
- if(ydmin == 1):
- curs.execute("select * from ban where block = ?", [data[3]])
- row = curs.fetchall()
- if(row):
- ban = ' <a href="/ban/' + url_pas(data[3]) + '">(해제)</a>'
- else:
- ban = ' <a href="/ban/' + url_pas(data[3]) + '">(차단)</a>'
- else:
- ban = ''
-
- ip = ip_pas(data[3])
-
- div += '<tr> \
- <td> \
- <a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[2]) + '#' + data[1] + '">' + title + '#' + data[1] + '</a> (' + sub + ') \
- </td> \
- <td>' + ip + ban + '</td> \
- <td>' + data[4] + '</td> \
- </tr>'
- else:
- div += '</tbody> \
- </table>'
- else:
- div = ''
-
- div += '<br><a href="/user/' + url_pas(name) + '/topic/' + str(num - 1) + '">(이전)</a> <a href="/user/' + url_pas(name) + '/topic/' + str(num + 1) + '">(이후)</a>'
-
- curs.execute("select end, why from ban where block = ?", [name])
- ban_it = curs.fetchall()
- if(ban_it):
- sub = ' (차단)'
- else:
- sub = 0
-
- return(
- html_minify(
- template('index',
- imp = ['토론 기록', wiki_set(1), custom(), other2([sub, 0])],
- data = div,
- menu = [['other', '기타'], ['user', '사용자']]
- )
- )
- )
-
- @route('/upload', method=['GET', 'POST'])
- def upload():
- if(ban_check() == 1):
- return(re_error('/ban'))
-
- if(request.method == 'POST'):
- data = request.files.f_data
- if(data):
- if(int(wiki_set(3)) * 1024 * 1024 < request.content_length):
- return re_error('/error/17')
-
- value = os.path.splitext(data.filename)[1]
- if(not value in ['.jpeg', '.jpg', '.gif', '.png', '.webp', '.JPEG', '.JPG', '.GIF', '.PNG', '.WEBP']):
- return re_error('/error/14')
-
- if(request.forms.get('f_name')):
- name = request.forms.get('f_name') + value
- else:
- name = data.filename
-
- piece = os.path.splitext(name)
- e_data = sha224(piece[0]) + piece[1]
-
- ip = ip_check()
- if(request.forms.get('f_lice')):
- lice = request.forms.get('f_lice')
- else:
- if(re.search('(?:\.|:)', ip)):
- lice = ip + ' 올림'
- else:
- lice = '[[사용자:' + ip + ']] 올림'
-
- if(os.path.exists(os.path.join('image', e_data))):
- return(re_error('/error/16'))
-
- data.save(os.path.join('image', e_data))
-
- curs.execute("select title from data where title = ?", ['파일:' + name])
- exist = curs.fetchall()
- if(exist):
- curs.execute("delete from data where title = ?", ['파일:' + name])
-
- curs.execute("insert into data (title, data, acl) values (?, ?, 'admin')", ['파일:' + name, '[[파일:' + name + ']][br][br]{{{[[파일:' + name + ']]}}}[br][br]' + lice])
- conn.commit()
-
- history_plus(
- '파일:' + name,
- '[[파일:' + name + ']][br][br]{{{[[파일:' + name + ']]}}}[br][br]' + lice,
- get_time(),
- ip,
- '(파일 올림)',
- '0'
- )
-
- return(redirect('/w/파일:' + name))
- else:
- return(re_error('/error/9'))
- else:
- return(
- html_minify(
- template('index',
- imp = ['파일 올리기', wiki_set(1), custom(), other2([0, 0])],
- data = '<form method="post" enctype="multipart/form-data" accept-charset="utf8"> \
- <input type="file" name="f_data"> \
- <br> \
- <br> \
- <input placeholder="파일 이름" name="f_name" type="text"> \
- <br> \
- <br> \
- <input placeholder="라이선스" name="f_lice" type="text"> \
- <br> \
- <br> \
- <span>한글이 되지 않을 때도 있습니다.</span> \
- <br> \
- <br> \
- <button class="btn btn-primary" type="submit">저장</button> \
- </form>',
- menu = [['other', '기타']]
- )
- )
- )
-
- @route('/user')
- def user_info():
- ip = ip_check()
- raw_ip = ip
-
- curs.execute("select acl from user where id = ?", [ip])
- rows = curs.fetchall()
- if(ban_check() == 0):
- if(rows):
- if(rows[0][0] != 'user'):
- acl = rows[0][0]
- else:
- acl = '사용자'
- else:
- acl = '일반'
- else:
- acl = '차단'
-
- ip = ip_pas(ip)
- l = custom()
- if(l[2] != 0):
- plus = ' * [[wiki:logout|로그아웃]]\r\n * [[wiki:change|비밀번호 변경]]'
- else:
- plus = ' * [[wiki:login|로그인]]'
- return(
- html_minify(
- template('index',
- imp = ['사용자 메뉴', wiki_set(1), l, other2([0, 0])],
- data = ip + '<br><br>' + namumark('', '권한 상태 : ' + acl + '\r\n' + \
- '[목차(없음)]\r\n' + \
- '== 로그인 ==\r\n' + \
- plus + '\r\n' + \
- ' * [[wiki:register|회원가입]]\r\n' + \
- '== 사용자 ==\r\n' + \
- ' * [[wiki:user_acl/' + url_pas(raw_ip) + '|사용자 문서 ACL]]\r\n' + \
- ' * [[wiki:custom_css|사용자 CSS]]\r\n' + \
- ' * [[wiki:custom_js|사용자 JS]]\r\n' + \
- '== 기타 ==\r\n' + \
- ' * [[wiki:alarm|알림]]\r\n' + \
- ' * [[wiki:view_log|지나온 문서]]\r\n' + \
- ' * [[wiki:count|기여 횟수]]\r\n', 0, 0, 0),
- menu = 0
- )
- )
- )
- @route('/view_log')
- def view_log():
- session = request.environ.get('beaker.session')
- data = '<ul>'
- if(session.get('View_List')):
- data += '<li>최근 50개</li><br><br>'
- m = re.findall('([^\n]+)\n', session.get('View_List'))
- for d in m:
- data += '<li><a href="/w/' + url_pas(d) + '">' + d + '</a></li>'
- else:
- data += '<li>기록 없음</li>'
- data += '</ul>'
- return(
- html_minify(
- template('index',
- imp = ['지나온 문서', wiki_set(1), custom(), other2([0, 0])],
- data = data,
- menu = [['user', '사용자']]
- )
- )
- )
- @route('/custom_css', method=['GET', 'POST'])
- def custom_css_view():
- session = request.environ.get('beaker.session')
- ip = ip_check()
- if(request.method == 'POST'):
- if(not re.search('(\.|:)', ip)):
- curs.execute("select * from custom where user = ?", [ip])
- css_data = curs.fetchall()
- if(css_data):
- curs.execute("update custom set css = ? where user = ?", [request.forms.content, ip])
- else:
- curs.execute("insert into custom (user, css) values (?, ?)", [ip, request.forms.content])
- conn.commit()
- session['Daydream'] = request.forms.content
- return(redirect('/user'))
- else:
- if(not re.search('(\.|:)', ip)):
- start = ''
- curs.execute("select css from custom where user = ?", [ip])
- css_data = curs.fetchall()
- if(css_data):
- data = css_data[0][0]
- else:
- data = ''
- else:
- start = '<span>비 로그인의 경우에는 로그인하면 날아갑니다.</span><br><br>'
- try:
- data = session['Daydream']
- except:
- data = ''
- return(
- html_minify(
- template('index',
- imp = ['사용자 CSS', wiki_set(1), custom(), other2([0, 0])],
- data = start + ' \
- <form method="post"> \
- <textarea rows="30" cols="100" name="content">'\
- + data + \
- '</textarea> \
- <br> \
- <br> \
- <div class="form-actions"> \
- <button class="btn btn-primary" type="submit">저장</button> \
- </div> \
- </form>',
- menu = [['user', '사용자']]
- )
- )
- )
- @route('/custom_js', method=['GET', 'POST'])
- def custom_js_view():
- session = request.environ.get('beaker.session')
- ip = ip_check()
- if(request.method == 'POST'):
- if(not re.search('(\.|:)', ip)):
- curs.execute("select * from custom where user = ?", [ip + ' (js)'])
- js_data = curs.fetchall()
- if(js_data):
- curs.execute("update custom set css = ? where user = ?", [request.forms.content, ip + ' (js)'])
- else:
- curs.execute("insert into custom (user, css) values (?, ?)", [ip + ' (js)', request.forms.content])
- conn.commit()
- session['AQUARIUM'] = request.forms.content
- return(redirect('/user'))
- else:
- if(not re.search('(\.|:)', ip)):
- start = ''
- curs.execute("select css from custom where user = ?", [ip + ' (js)'])
- js_data = curs.fetchall()
- if(js_data):
- data = js_data[0][0]
- else:
- data = ''
- else:
- start = '<span>비 로그인의 경우에는 로그인하면 날아갑니다.</span><br><br>'
- try:
- data = session['AQUARIUM']
- except:
- data = ''
- return(
- html_minify(
- template('index',
- imp = ['사용자 JS', wiki_set(1), custom(), other2([0, 0])],
- data = start + ' \
- <form method="post"> \
- <textarea rows="30" cols="100" name="content">'\
- + data + \
- '</textarea> \
- <br> \
- <br> \
- <div class="form-actions"> \
- <button class="btn btn-primary" type="submit">저장</button> \
- </div> \
- </form>',
- menu = [['user', '사용자']]
- )
- )
- )
- @route('/count')
- @route('/count/<name:path>')
- def count_edit(name = None):
- if(name == None):
- that = ip_check()
- else:
- that = name
- curs.execute("select count(title) from history where ip = ?", [that])
- count = curs.fetchall()
- if(count):
- data = count[0][0]
- else:
- data = 0
- curs.execute("select count(title) from topic where ip = ?", [that])
- count = curs.fetchall()
- if(count):
- t_data = count[0][0]
- else:
- t_data = 0
- return(
- html_minify(
- template('index',
- imp = ['기여 횟수', wiki_set(1), custom(), other2([0, 0])],
- data = namumark("", "||<-2><:> " + that + " ||\r\n||<:> 기여 횟수 ||<:> " + str(data) + "||\r\n||<:> 토론 횟수 ||<:> " + str(t_data) + "||", 0, 0, 0),
- menu = [['user', '사용자']]
- )
- )
- )
-
- @route('/random')
- def random():
- curs.execute("select title from data order by random() limit 1")
- rows = curs.fetchall()
- if(rows):
- return(redirect('/w/' + url_pas(rows[0][0])))
- else:
- return(redirect('/'))
-
- @route('/views/<name:path>')
- def views(name = None):
- if(re.search('\/', name)):
- m = re.search('^(.*)\/(.*)$', name)
- if(m):
- n = m.groups()
- plus = '/' + n[0]
- rename = n[1]
- else:
- plus = ''
- rename = name
- else:
- plus = ''
- rename = name
-
- return(
- static_file(rename,
- root = './views' + plus
- )
- )
- @error(404)
- def error_404(error):
- try:
- curs.execute("select title from data limit 1")
- return(redirect('/w/' + url_pas(wiki_set(2))))
- except:
- return(redirect('/setup'))
- @error(500)
- def error_500(error):
- try:
- curs.execute("select title from data limit 1")
- return(error)
- except:
- return(redirect('/setup'))
-
- run(
- app = app,
- server = 'tornado',
- host = '0.0.0.0',
- port = int(set_data['port'])
- )
|