app.py 159 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858
  1. import werkzeug.routing
  2. import flask_compress
  3. import flask_reggie
  4. import tornado.ioloop
  5. import tornado.httpserver
  6. import tornado.wsgi
  7. import urllib.request
  8. import platform
  9. import zipfile
  10. import bcrypt
  11. import difflib
  12. import shutil
  13. import threading
  14. import logging
  15. import random
  16. import sys
  17. from func import *
  18. r_ver = 'v3.0.6-Master-04'
  19. c_ver = ''.join(re.findall('[0-9]', r_ver))
  20. print('Version : ' + r_ver)
  21. try:
  22. json_data = open('set.json').read()
  23. set_data = json.loads(json_data)
  24. except:
  25. while 1:
  26. print('DB Name : ', end = '')
  27. new_json = str(input())
  28. if new_json != '':
  29. with open('set.json', 'w') as f:
  30. f.write('{ "db" : "' + new_json + '" }')
  31. json_data = open('set.json').read()
  32. set_data = json.loads(json_data)
  33. break
  34. else:
  35. print('Insert Values')
  36. pass
  37. if os.path.exists(set_data['db'] + '.db'):
  38. setup_tool = 0
  39. else:
  40. setup_tool = 1
  41. conn = sqlite3.connect(set_data['db'] + '.db', check_same_thread = False)
  42. curs = conn.cursor()
  43. load_conn(conn)
  44. logging.basicConfig(level = logging.ERROR)
  45. app = flask.Flask(__name__, template_folder = './')
  46. flask_reggie.Reggie(app)
  47. compress = flask_compress.Compress()
  48. compress.init_app(app)
  49. class EverythingConverter(werkzeug.routing.PathConverter):
  50. regex = '.*?'
  51. app.jinja_env.filters['md5_replace'] = md5_replace
  52. app.jinja_env.filters['load_lang'] = load_lang
  53. app.url_map.converters['everything'] = EverythingConverter
  54. curs.execute('create table if not exists data(test text)')
  55. curs.execute('create table if not exists cache_data(test text)')
  56. curs.execute('create table if not exists history(test text)')
  57. curs.execute('create table if not exists rd(test text)')
  58. curs.execute('create table if not exists user(test text)')
  59. curs.execute('create table if not exists user_set(test text)')
  60. curs.execute('create table if not exists ban(test text)')
  61. curs.execute('create table if not exists topic(test text)')
  62. curs.execute('create table if not exists stop(test text)')
  63. curs.execute('create table if not exists rb(test text)')
  64. curs.execute('create table if not exists back(test text)')
  65. curs.execute('create table if not exists agreedis(test text)')
  66. curs.execute('create table if not exists custom(test text)')
  67. curs.execute('create table if not exists other(test text)')
  68. curs.execute('create table if not exists alist(test text)')
  69. curs.execute('create table if not exists re_admin(test text)')
  70. curs.execute('create table if not exists alarm(test text)')
  71. curs.execute('create table if not exists ua_d(test text)')
  72. curs.execute('create table if not exists filter(test text)')
  73. curs.execute('create table if not exists scan(test text)')
  74. curs.execute('create table if not exists acl(test text)')
  75. curs.execute('create table if not exists inter(test text)')
  76. curs.execute('create table if not exists html_filter(test text)')
  77. if setup_tool == 0:
  78. curs.execute('select data from other where name = "ver"')
  79. ver_set_data = curs.fetchall()
  80. if not ver_set_data:
  81. setup_tool = 1
  82. else:
  83. if c_ver > ver_set_data[0][0]:
  84. setup_tool = 1
  85. if setup_tool != 0:
  86. create_data = {}
  87. create_data['all_data'] = [
  88. 'data',
  89. 'cache_data',
  90. 'history',
  91. 'rd',
  92. 'user',
  93. 'user_set',
  94. 'ban',
  95. 'topic',
  96. 'stop',
  97. 'rb',
  98. 'back',
  99. 'agreedis',
  100. 'custom',
  101. 'other',
  102. 'alist',
  103. 're_admin',
  104. 'alarm',
  105. 'ua_d',
  106. 'filter',
  107. 'scan',
  108. 'acl',
  109. 'inter',
  110. 'html_filter'
  111. ]
  112. create_data['data'] = ['title', 'data']
  113. create_data['cache_data'] = ['title', 'data']
  114. create_data['history'] = ['id', 'title', 'data', 'date', 'ip', 'send', 'leng', 'hide']
  115. create_data['rd'] = ['title', 'sub', 'date', 'band']
  116. create_data['user'] = ['id', 'pw', 'acl', 'date']
  117. create_data['user_set'] = ['name', 'id', 'data']
  118. create_data['ban'] = ['block', 'end', 'why', 'band', 'login']
  119. create_data['topic'] = ['id', 'title', 'sub', 'data', 'date', 'ip', 'block', 'top']
  120. create_data['stop'] = ['title', 'sub', 'close']
  121. create_data['rb'] = ['block', 'end', 'today', 'blocker', 'why', 'band']
  122. create_data['back'] = ['title', 'link', 'type']
  123. create_data['agreedis'] = ['title', 'sub']
  124. create_data['custom'] = ['user', 'css']
  125. create_data['other'] = ['name', 'data']
  126. create_data['alist'] = ['name', 'acl']
  127. create_data['re_admin'] = ['who', 'what', 'time']
  128. create_data['alarm'] = ['name', 'data', 'date']
  129. create_data['ua_d'] = ['name', 'ip', 'ua', 'today', 'sub']
  130. create_data['filter'] = ['name', 'regex', 'sub']
  131. create_data['scan'] = ['user', 'title']
  132. create_data['acl'] = ['title', 'dec', 'dis', 'why']
  133. create_data['inter'] = ['title', 'link']
  134. create_data['html_filter'] = ['html']
  135. for create_table in create_data['all_data']:
  136. for create in create_data[create_table]:
  137. try:
  138. curs.execute('select ' + create + ' from ' + create_table + ' limit 1')
  139. except:
  140. curs.execute("alter table " + create_table + " add " + create + " text default ''")
  141. update()
  142. curs.execute('select name from alist where acl = "owner"')
  143. if not curs.fetchall():
  144. curs.execute('delete from alist where name = "owner"')
  145. curs.execute('insert into alist (name, acl) values ("owner", "owner")')
  146. if not os.path.exists('image'):
  147. os.makedirs('image')
  148. if not os.path.exists('views'):
  149. os.makedirs('views')
  150. if os.getenv('NAMU_PORT') is not None:
  151. rep_port = os.getenv('NAMU_PORT')
  152. else:
  153. curs.execute('select data from other where name = "port"')
  154. rep_data = curs.fetchall()
  155. if not rep_data:
  156. while 1:
  157. print('Port : ', end = '')
  158. rep_port = int(input())
  159. if rep_port:
  160. curs.execute('insert into other (name, data) values ("port", ?)', [rep_port])
  161. break
  162. else:
  163. pass
  164. else:
  165. rep_port = rep_data[0][0]
  166. print('Port : ' + str(rep_port))
  167. try:
  168. if not os.path.exists('robots.txt'):
  169. curs.execute('select data from other where name = "robot"')
  170. robot_test = curs.fetchall()
  171. if robot_test:
  172. fw_test = open('./robots.txt', 'w')
  173. fw_test.write(re.sub('\r\n', '\n', robot_test[0][0]))
  174. fw_test.close()
  175. else:
  176. fw_test = open('./robots.txt', 'w')
  177. fw_test.write('User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/')
  178. fw_test.close()
  179. curs.execute('insert into other (name, data) values ("robot", "User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/")')
  180. print('robots.txt create')
  181. except:
  182. pass
  183. curs.execute('select data from other where name = "key"')
  184. rep_data = curs.fetchall()
  185. if not rep_data:
  186. rep_key = ''.join(random.choice("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") for i in range(16))
  187. if rep_key:
  188. curs.execute('insert into other (name, data) values ("key", ?)', [rep_key])
  189. else:
  190. rep_key = rep_data[0][0]
  191. curs.execute("select data from other where name = 'language'")
  192. rep_data = curs.fetchall()
  193. if not rep_data:
  194. support_language = ['ko-KR', 'en-US']
  195. if os.getenv('NAMU_LANG') is not None:
  196. if os.getenv('NAMU_LANG') in support_language:
  197. curs.execute("insert into other (name, data) values ('language', ?)", [os.getenv('NAMU_LANG')])
  198. rep_language = os.getenv('NAMU_LANG')
  199. else:
  200. print('Language {} is not supported!'.format(os.getenv('NAMU_LANG')))
  201. rep_language = 'en-US'
  202. else:
  203. while 1:
  204. print('Language [{}] : '.format(' '.join(support_language)))
  205. rep_language = str(input())
  206. if rep_language in support_language:
  207. curs.execute("insert into other (name, data) values ('language', ?)", [rep_language])
  208. break
  209. else:
  210. pass
  211. else:
  212. rep_language = rep_data[0][0]
  213. print('Language : ' + str(rep_language))
  214. curs.execute('delete from other where name = "ver"')
  215. curs.execute('insert into other (name, data) values ("ver", ?)', [c_ver])
  216. json_data = open(os.path.join('language', rep_language + '.json'), 'rt', encoding='utf-8').read()
  217. lang_data = json.loads(json_data)
  218. def back_up():
  219. try:
  220. shutil.copyfile(set_data['db'] + '.db', 'back_' + set_data['db'] + '.db')
  221. print('Back up : Ok')
  222. except:
  223. print('Back up : Error')
  224. threading.Timer(60 * 60 * back_time, back_up).start()
  225. try:
  226. curs.execute('select data from other where name = "back_up"')
  227. back_up_time = curs.fetchall()
  228. back_time = int(back_up_time[0][0])
  229. except:
  230. back_time = 0
  231. if back_time != 0:
  232. print('Back up state : ' + str(back_time) + ' hours interval')
  233. if __name__ == '__main__':
  234. back_up()
  235. else:
  236. print('Back up state : Turn off')
  237. conn.commit()
  238. @app.route('/del_alarm')
  239. def del_alarm():
  240. curs.execute("delete from alarm where name = ?", [ip_check()])
  241. conn.commit()
  242. return redirect('/alarm')
  243. @app.route('/alarm')
  244. def alarm():
  245. if custom()[2] == 0:
  246. return redirect('/login')
  247. data = '<ul>'
  248. curs.execute("select data, date from alarm where name = ? order by date desc", [ip_check()])
  249. data_list = curs.fetchall()
  250. if data_list:
  251. data = '<a href="/del_alarm">(' + load_lang('delete') + ')</a><hr>' + data
  252. for data_one in data_list:
  253. data += '<li>' + data_one[0] + ' (' + data_one[1] + ')</li>'
  254. else:
  255. data += '<li>' + load_lang('no_alarm') + '</li>'
  256. data += '</ul>'
  257. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  258. imp = [load_lang('alarm'), wiki_set(), custom(), other2([0, 0])],
  259. data = data,
  260. menu = [['user', load_lang('user')]]
  261. ))
  262. @app.route('/<regex("inter_wiki|html_filter"):tools>')
  263. def inter_wiki(tools = None):
  264. div = ''
  265. admin = admin_check(None, None)
  266. if tools == 'inter_wiki':
  267. del_link = 'del_inter_wiki'
  268. plus_link = 'plus_inter_wiki'
  269. title = load_lang('interwiki') + ' ' + load_lang('list')
  270. div = ''
  271. curs.execute('select title, link from inter')
  272. else:
  273. del_link = 'del_html_filter'
  274. plus_link = 'plus_html_filter'
  275. title = 'HTML' + load_lang('filter') + ' ' + load_lang('list')
  276. div = '<ul><li>span</li><li>div</li><li>iframe</li></ul>'
  277. curs.execute('select html from html_filter')
  278. db_data = curs.fetchall()
  279. if db_data:
  280. div += '<ul>'
  281. for data in db_data:
  282. if tools == 'inter_wiki':
  283. div += '<li>' + data[0] + ' : <a id="out_link" href="' + data[1] + '">' + data[1] + '</a>'
  284. else:
  285. div += '<li>' + data[0]
  286. if admin == 1:
  287. div += ' <a href="/' + del_link + '/' + url_pas(data[0]) + '">(' + load_lang('delete') + ')</a>'
  288. div += '</li>'
  289. div += '</ul>'
  290. if admin == 1:
  291. div += '<hr><a href="/' + plus_link + '">(' + load_lang('plus') + ')</a>'
  292. else:
  293. if admin == 1:
  294. div += '<a href="/' + plus_link + '">(' + load_lang('plus') + ')</a>'
  295. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  296. imp = [title, wiki_set(), custom(), other2([0, 0])],
  297. data = div,
  298. menu = [['other', load_lang('other')]]
  299. ))
  300. @app.route('/<regex("del_(inter_wiki|html_filter)"):tools>/<name>')
  301. def del_inter(tools = None, name = None):
  302. if admin_check(None, None) == 1:
  303. if tools == 'del_inter_wiki':
  304. curs.execute("delete from inter where title = ?", [name])
  305. else:
  306. curs.execute("delete from html_filter where html = ?", [name])
  307. conn.commit()
  308. return redirect('/' + re.sub('^del_', '', tools))
  309. else:
  310. return re_error('/error/3')
  311. @app.route('/<regex("plus_(inter_wiki|html_filter)"):tools>', methods=['POST', 'GET'])
  312. def plus_inter(tools = None):
  313. if flask.request.method == 'POST':
  314. if tools == 'plus_inter_wiki':
  315. curs.execute('insert into inter (title, link) values (?, ?)', [flask.request.form.get('title', None), flask.request.form.get('link', None)])
  316. else:
  317. curs.execute('insert into html_filter (html) values (?)', [flask.request.form.get('title', None)])
  318. conn.commit()
  319. admin_check(None, 'inter_wiki_plus')
  320. return redirect('/' + re.sub('^plus_', '', tools))
  321. else:
  322. if tools == 'plus_inter_wiki':
  323. title = load_lang('interwiki') + ' ' + load_lang('plus')
  324. form_data = '<input placeholder="' + load_lang('name') + '" type="text" name="title"><hr><input placeholder="Link" type="text" name="link">'
  325. else:
  326. title = 'HTML ' + load_lang('filter') + ' ' + load_lang('plus')
  327. form_data = '<input placeholder="HTML" type="text" name="title">'
  328. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  329. imp = [title, wiki_set(), custom(), other2([0, 0])],
  330. data = '''
  331. <form method="post">
  332. ''' + form_data + '''
  333. <hr>
  334. <button type="submit">''' + load_lang('plus') + '''</button>
  335. </form>
  336. ''',
  337. menu = [['other', load_lang('other')]]
  338. ))
  339. @app.route('/setting')
  340. @app.route('/setting/<int:num>', methods=['POST', 'GET'])
  341. def setting(num = 0):
  342. if num != 0 and admin_check(None, None) != 1:
  343. return re_error('/ban')
  344. if num == 0:
  345. li_list = [load_lang('main'), load_lang('set_text'), load_lang('main_head'), 'robots.txt', 'Google']
  346. x = 0
  347. li_data = ''
  348. for li in li_list:
  349. x += 1
  350. li_data += '<li><a href="/setting/' + str(x) + '">' + li + '</a></li>'
  351. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  352. imp = [load_lang('setting'), wiki_set(), custom(), other2([0, 0])],
  353. data = '<h2>' + load_lang('list') + '</h2><ul>' + li_data + '</ul>',
  354. menu = [['manager', load_lang('admin')]]
  355. ))
  356. elif num == 1:
  357. i_list = ['name', 'logo', 'frontpage', 'license', 'upload', 'skin', 'edit', 'reg', 'ip_view', 'back_up', 'port', 'key', 'update']
  358. n_list = ['Wiki', '', 'FrontPage', 'CC 0', '2', '', 'normal', '', '', '0', '3000', 'Test', 'stable']
  359. if flask.request.method == 'POST':
  360. i = 0
  361. for data in i_list:
  362. curs.execute("update other set data = ? where name = ?", [flask.request.form.get(data, n_list[i]), data])
  363. i += 1
  364. conn.commit()
  365. admin_check(None, 'edit_set')
  366. return redirect('/setting/1')
  367. else:
  368. d_list = []
  369. x = 0
  370. for i in i_list:
  371. curs.execute('select data from other where name = ?', [i])
  372. sql_d = curs.fetchall()
  373. if sql_d:
  374. d_list += [sql_d[0][0]]
  375. else:
  376. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  377. d_list += [n_list[x]]
  378. x += 1
  379. conn.commit()
  380. div = ''
  381. if d_list[6] == 'login':
  382. div += '<option value="login">' + load_lang('subscriber') + '</option>'
  383. div += '<option value="normal">' + load_lang('normal') + '</option>'
  384. div += '<option value="admin">' + load_lang('admin') + '</option>'
  385. elif d_list[6] == 'admin':
  386. div += '<option value="admin">' + load_lang('admin') + '</option>'
  387. div += '<option value="login">' + load_lang('subscriber') + '</option>'
  388. div += '<option value="normal">' + load_lang('normal') + '</option>'
  389. else:
  390. div += '<option value="normal">' + load_lang('normal') + '</option>'
  391. div += '<option value="admin">' + load_lang('admin') + '</option>'
  392. div += '<option value="login">' + load_lang('subscriber') + '</option>'
  393. ch_1 = ''
  394. if d_list[7]:
  395. ch_1 = 'checked="checked"'
  396. ch_2 = ''
  397. if d_list[8]:
  398. ch_2 = 'checked="checked"'
  399. div2 = load_skin(d_list[5])
  400. div3 =''
  401. if d_list[12] == 'stable':
  402. div3 += '<option value="stable">stable</option>'
  403. div3 += '<option value="master">master</option>'
  404. else:
  405. div3 += '<option value="master">master</option>'
  406. div3 += '<option value="stable">stable</option>'
  407. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  408. imp = [load_lang('main'), wiki_set(), custom(), other2([0, 0])],
  409. data = '''
  410. <form method="post">
  411. <span>''' + load_lang('name') + '''</span>
  412. <br>
  413. <br>
  414. <input placeholder="''' + load_lang('name') + '''" type="text" name="name" value="''' + html.escape(d_list[0]) + '''">
  415. <hr>
  416. <span>''' + load_lang('logo') + ''' (HTML)</span>
  417. <br>
  418. <br>
  419. <input placeholder="''' + load_lang('logo') + '''" type="text" name="logo" value="''' + html.escape(d_list[1]) + '''">
  420. <hr>
  421. <span>''' + load_lang('frontpage') + '''</span>
  422. <br>
  423. <br>
  424. <input placeholder="''' + load_lang('frontpage') + '''" type="text" name="frontpage" value="''' + html.escape(d_list[2]) + '''">
  425. <hr>
  426. <span>''' + load_lang('license') + ''' (HTML)</span>
  427. <br>
  428. <br>
  429. <input placeholder="''' + load_lang('license') + '''" type="text" name="license" value="''' + html.escape(d_list[3]) + '''">
  430. <hr>
  431. <span>''' + load_lang('max_file_size') + ''' [MB]</span>
  432. <br>
  433. <br>
  434. <input placeholder="''' + load_lang('max_file_size') + '''" type="text" name="upload" value="''' + html.escape(d_list[4]) + '''">
  435. <hr>
  436. <span>''' + load_lang('back_up_interval') + ' [' + load_lang('hour') + '] (OFF : 0) {' + load_lang('need_to_restart') + '''}</span>
  437. <br>
  438. <br>
  439. <input placeholder="''' + load_lang('back_up_interval') + '''" type="text" name="back_up" value="''' + html.escape(d_list[9]) + '''">
  440. <hr>
  441. <span>''' + load_lang('skin') + '''</span>
  442. <br>
  443. <br>
  444. <select name="skin">''' + div2 + '''</select>
  445. <hr>
  446. <span>''' + load_lang('default_acl') + '''</span>
  447. <br>
  448. <br>
  449. <select name="edit">''' + div + '''</select>
  450. <hr>
  451. <input type="checkbox" name="reg" ''' + ch_1 + '''> ''' + load_lang('unable_register') + '''
  452. <hr>
  453. <input type="checkbox" name="ip_view" ''' + ch_2 + '''> ''' + load_lang('ip_hidden') + '''
  454. <hr>
  455. <span>''' + load_lang('port') + '''</span>
  456. <br>
  457. <br>
  458. <input placeholder="''' + load_lang('port') + '''" type="text" name="port" value="''' + html.escape(d_list[10]) + '''">
  459. <hr>
  460. <span>''' + load_lang('secret_key') + '''</span>
  461. <br>
  462. <br>
  463. <input placeholder="''' + load_lang('secret_key') + '''" type="password" name="key" value="''' + html.escape(d_list[11]) + '''">
  464. <hr>
  465. <span>''' + load_lang('update_branch') + '''</span>
  466. <br>
  467. <br>
  468. <select name="update">''' + div3 + '''</select>
  469. <hr>
  470. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  471. </form>
  472. ''',
  473. menu = [['setting', load_lang('setting')]]
  474. ))
  475. elif num == 2:
  476. if flask.request.method == 'POST':
  477. curs.execute("update other set data = ? where name = ?", [flask.request.form.get('contract', None), 'contract'])
  478. curs.execute("update other set data = ? where name = ?", [flask.request.form.get('no_login_warring', None), 'no_login_warring'])
  479. conn.commit()
  480. admin_check(None, 'edit_set')
  481. return redirect('/setting/2')
  482. else:
  483. i_list = ['contract', 'no_login_warring']
  484. n_list = ['', '']
  485. d_list = []
  486. x = 0
  487. for i in i_list:
  488. curs.execute('select data from other where name = ?', [i])
  489. sql_d = curs.fetchall()
  490. if sql_d:
  491. d_list += [sql_d[0][0]]
  492. else:
  493. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  494. d_list += [n_list[x]]
  495. x += 1
  496. conn.commit()
  497. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  498. imp = [load_lang('set_text'), wiki_set(), custom(), other2([0, 0])],
  499. data = '''
  500. <form method="post">
  501. <span>Register Text</span>
  502. <br>
  503. <br>
  504. <input placeholder="Register Text" type="text" name="contract" value="''' + html.escape(d_list[0]) + '''">
  505. <hr>
  506. <span>Non-Login Alert</span>
  507. <br>
  508. <br>
  509. <input placeholder="Non-Login Alert" type="text" name="no_login_warring" value="''' + html.escape(d_list[1]) + '''">
  510. <hr>
  511. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  512. </form>
  513. ''',
  514. menu = [['setting', load_lang('setting')]]
  515. ))
  516. elif num == 3:
  517. if flask.request.method == 'POST':
  518. curs.execute("select name from other where name = 'head'")
  519. if curs.fetchall():
  520. curs.execute("update other set data = ? where name = 'head'", [flask.request.form.get('content', None)])
  521. else:
  522. curs.execute("insert into other (name, data) values ('head', ?)", [flask.request.form.get('content', None)])
  523. conn.commit()
  524. admin_check(None, 'edit_set')
  525. return redirect('/setting/3')
  526. else:
  527. curs.execute("select data from other where name = 'head'")
  528. head = curs.fetchall()
  529. if head:
  530. data = head[0][0]
  531. else:
  532. data = ''
  533. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  534. imp = [load_lang('main_head'), wiki_set(), custom(), other2([0, 0])],
  535. data = '''
  536. <form method="post">
  537. <textarea rows="25" name="content">''' + html.escape(data) + '''</textarea>
  538. <hr>
  539. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  540. </form>
  541. ''',
  542. menu = [['setting', load_lang('setting')]]
  543. ))
  544. elif num == 4:
  545. if flask.request.method == 'POST':
  546. curs.execute("select name from other where name = 'robot'")
  547. if curs.fetchall():
  548. curs.execute("update other set data = ? where name = 'robot'", [flask.request.form.get('content', None)])
  549. else:
  550. curs.execute("insert into other (name, data) values ('robot', ?)", [flask.request.form.get('content', None)])
  551. conn.commit()
  552. fw = open('./robots.txt', 'w')
  553. fw.write(re.sub('\r\n', '\n', flask.request.form.get('content', None)))
  554. fw.close()
  555. admin_check(None, 'edit_set')
  556. return redirect('/setting/4')
  557. else:
  558. curs.execute("select data from other where name = 'robot'")
  559. robot = curs.fetchall()
  560. if robot:
  561. data = robot[0][0]
  562. else:
  563. data = ''
  564. f = open('./robots.txt', 'r')
  565. lines = f.readlines()
  566. f.close()
  567. if not data or data == '':
  568. data = ''.join(lines)
  569. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  570. imp = ['robots.txt', wiki_set(), custom(), other2([0, 0])],
  571. data = '''
  572. <a href="/robots.txt">(View)</a>
  573. <hr>
  574. <form method="post">
  575. <textarea rows="25" name="content">''' + html.escape(data) + '''</textarea>
  576. <hr>
  577. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  578. </form>
  579. ''',
  580. menu = [['setting', load_lang('setting')]]
  581. ))
  582. elif num == 5:
  583. if flask.request.method == 'POST':
  584. curs.execute("update other set data = ? where name = 'recaptcha'", [flask.request.form.get('recaptcha', None)])
  585. curs.execute("update other set data = ? where name = 'sec_re'", [flask.request.form.get('sec_re', None)])
  586. conn.commit()
  587. admin_check(None, 'edit_set')
  588. return redirect('/setting/5')
  589. else:
  590. i_list = ['recaptcha', 'sec_re']
  591. n_list = ['', '']
  592. d_list = []
  593. x = 0
  594. for i in i_list:
  595. curs.execute('select data from other where name = ?', [i])
  596. sql_d = curs.fetchall()
  597. if sql_d:
  598. d_list += [sql_d[0][0]]
  599. else:
  600. curs.execute('insert into other (name, data) values (?, ?)', [i, n_list[x]])
  601. d_list += [n_list[x]]
  602. x += 1
  603. conn.commit()
  604. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  605. imp = ['Google', wiki_set(), custom(), other2([0, 0])],
  606. data = '''
  607. <form method="post">
  608. <span>reCAPTCHA (HTML)</span>
  609. <br>
  610. <br>
  611. <input placeholder="reCAPTCHA (HTML)" type="text" name="recaptcha" value="''' + html.escape(d_list[0]) + '''">
  612. <hr>
  613. <span>reCAPTCHA (Secret key)</span>
  614. <br>
  615. <br>
  616. <input placeholder="reCAPTCHA (Secret key)" type="text" name="sec_re" value="''' + html.escape(d_list[1]) + '''">
  617. <hr>
  618. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  619. </form>
  620. ''',
  621. menu = [['setting', load_lang('setting')]]
  622. ))
  623. else:
  624. return redirect('/')
  625. @app.route('/not_close_topic')
  626. def not_close_topic():
  627. div = '<ul>'
  628. curs.execute('select title, sub from rd order by date desc')
  629. n_list = curs.fetchall()
  630. for data in n_list:
  631. curs.execute('select * from stop where title = ? and sub = ? and close = "O"', [data[0], data[1]])
  632. is_close = curs.fetchall()
  633. if not is_close:
  634. div += '<li><a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[1]) + '">' + data[0] + ' (' + data[1] + ')</a></li>'
  635. div += '</ul>'
  636. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  637. imp = [load_lang('open') + ' ' + load_lang('discussion') + ' ' + load_lang('list'), wiki_set(), custom(), other2([0, 0])],
  638. data = div,
  639. menu = [['manager', load_lang('admin')]]
  640. ))
  641. @app.route('/image/<name>')
  642. def image_view(name = None):
  643. if os.path.exists(os.path.join('image', name)):
  644. return flask.send_from_directory('./image', name)
  645. else:
  646. return redirect('/')
  647. @app.route('/acl_list')
  648. def acl_list():
  649. div = '<ul>'
  650. curs.execute("select title, dec from acl where dec = 'admin' or dec = 'user' order by title desc")
  651. list_data = curs.fetchall()
  652. for data in list_data:
  653. if not re.search('^user:', data[0]) and not re.search('^file:', data[0]):
  654. if data[1] == 'admin':
  655. acl = load_lang('admin')
  656. else:
  657. acl = load_lang('subscriber')
  658. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (' + acl + ')</li>'
  659. div += '</ul>'
  660. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  661. imp = ['ACL ' + load_lang('document') + ' ' + load_lang('list'), wiki_set(), custom(), other2([0, 0])],
  662. data = div,
  663. menu = [['other', load_lang('other')]]
  664. ))
  665. @app.route('/admin_plus/<name>', methods=['POST', 'GET'])
  666. def admin_plus(name = None):
  667. if flask.request.method == 'POST':
  668. if admin_check(None, 'admin_plus (' + name + ')') != 1:
  669. return re_error('/error/3')
  670. curs.execute("delete from alist where name = ?", [name])
  671. if flask.request.form.get('ban', 0) != 0:
  672. curs.execute("insert into alist (name, acl) values (?, 'ban')", [name])
  673. if flask.request.form.get('toron', 0) != 0:
  674. curs.execute("insert into alist (name, acl) values (?, 'toron')", [name])
  675. if flask.request.form.get('check', 0) != 0:
  676. curs.execute("insert into alist (name, acl) values (?, 'check')", [name])
  677. if flask.request.form.get('acl', 0) != 0:
  678. curs.execute("insert into alist (name, acl) values (?, 'acl')", [name])
  679. if flask.request.form.get('hidel', 0) != 0:
  680. curs.execute("insert into alist (name, acl) values (?, 'hidel')", [name])
  681. if flask.request.form.get('give', 0) != 0:
  682. curs.execute("insert into alist (name, acl) values (?, 'give')", [name])
  683. if flask.request.form.get('owner', 0) != 0:
  684. curs.execute("insert into alist (name, acl) values (?, 'owner')", [name])
  685. conn.commit()
  686. return redirect('/admin_plus/' + url_pas(name))
  687. else:
  688. data = '<ul>'
  689. exist_list = ['', '', '', '', '', '', '', '']
  690. curs.execute('select acl from alist where name = ?', [name])
  691. acl_list = curs.fetchall()
  692. for go in acl_list:
  693. if go[0] == 'ban':
  694. exist_list[0] = 'checked="checked"'
  695. elif go[0] == 'toron':
  696. exist_list[2] = 'checked="checked"'
  697. elif go[0] == 'check':
  698. exist_list[3] = 'checked="checked"'
  699. elif go[0] == 'acl':
  700. exist_list[4] = 'checked="checked"'
  701. elif go[0] == 'hidel':
  702. exist_list[5] = 'checked="checked"'
  703. elif go[0] == 'give':
  704. exist_list[6] = 'checked="checked"'
  705. elif go[0] == 'owner':
  706. exist_list[7] = 'checked="checked"'
  707. if admin_check(None, None) != 1:
  708. state = 'disabled'
  709. else:
  710. state = ''
  711. data += '<li><input type="checkbox" ' + state + ' name="ban" ' + exist_list[0] + '> ' + load_lang('ban') + '</li>'
  712. data += '<li><input type="checkbox" ' + state + ' name="toron" ' + exist_list[2] + '> ' + load_lang('discussion') + '</li>'
  713. data += '<li><input type="checkbox" ' + state + ' name="check" ' + exist_list[3] + '> ' + load_lang('user') + ' ' + load_lang('check') + '</li>'
  714. data += '<li><input type="checkbox" ' + state + ' name="acl" ' + exist_list[4] + '> ' + load_lang('document') + ' ACL</li>'
  715. data += '<li><input type="checkbox" ' + state + ' name="hidel" ' + exist_list[5] + '> ' + load_lang('history') + ' ' + load_lang('hide') + '</li>'
  716. data += '<li><input type="checkbox" ' + state + ' name="give" ' + exist_list[6] + '> ' + load_lang('authority') + '</li>'
  717. data += '<li><input type="checkbox" ' + state + ' name="owner" ' + exist_list[7] + '> ' + load_lang('owner') + '</li></ul>'
  718. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  719. imp = [load_lang('admin_group') + ' ' + load_lang('plus'), wiki_set(), custom(), other2([0, 0])],
  720. data = '''
  721. <form method="post">
  722. ''' + data + '''
  723. <hr>
  724. <button id="save" ''' + state + ''' type="submit">''' + load_lang('save') + '''</button>
  725. </form>
  726. ''',
  727. menu = [['manager', load_lang('admin')]]
  728. ))
  729. @app.route('/admin_list')
  730. def admin_list():
  731. div = '<ul>'
  732. curs.execute("select id, acl, date from user where not acl = 'user' order by date desc")
  733. for data in curs.fetchall():
  734. name = ip_pas(data[0]) + ' <a href="/admin_plus/' + url_pas(data[1]) + '">(' + data[1] + ')</a>'
  735. if data[2] != '':
  736. name += '(' + data[2] + ')'
  737. div += '<li>' + name + '</li>'
  738. div += '</ul>'
  739. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  740. imp = [load_lang('admin') + ' ' + load_lang('list'), wiki_set(), custom(), other2([0, 0])],
  741. data = div,
  742. menu = [['other', load_lang('other')]]
  743. ))
  744. @app.route('/hidden/<everything:name>')
  745. def history_hidden(name = None):
  746. num = int(flask.request.args.get('num', 0))
  747. if admin_check(6, 'history_hidden (' + name + '#' + str(num) + ')') == 1:
  748. curs.execute("select title from history where title = ? and id = ? and hide = 'O'", [name, str(num)])
  749. if curs.fetchall():
  750. curs.execute("update history set hide = '' where title = ? and id = ?", [name, str(num)])
  751. else:
  752. curs.execute("update history set hide = 'O' where title = ? and id = ?", [name, str(num)])
  753. conn.commit()
  754. return redirect('/history/' + url_pas(name))
  755. @app.route('/user_log')
  756. def user_log():
  757. num = int(flask.request.args.get('num', 1))
  758. if num * 50 > 0:
  759. sql_num = num * 50 - 50
  760. else:
  761. sql_num = 0
  762. list_data = '<ul>'
  763. admin_one = admin_check(1, None)
  764. curs.execute("select id, date from user order by date desc limit ?, '50'", [str(sql_num)])
  765. user_list = curs.fetchall()
  766. for data in user_list:
  767. if admin_one == 1:
  768. curs.execute("select block from ban where block = ?", [data[0]])
  769. if curs.fetchall():
  770. ban_button = ' <a href="/ban/' + url_pas(data[0]) + '">(' + load_lang('release') + ')</a>'
  771. else:
  772. ban_button = ' <a href="/ban/' + url_pas(data[0]) + '">(' + load_lang('ban') + ')</a>'
  773. else:
  774. ban_button = ''
  775. list_data += '<li>' + ip_pas(data[0]) + ban_button
  776. if data[1] != '':
  777. list_data += ' (' + data[1] + ')'
  778. list_data += '</li>'
  779. if num == 1:
  780. curs.execute("select count(id) from user")
  781. user_count = curs.fetchall()
  782. if user_count:
  783. count = user_count[0][0]
  784. else:
  785. count = 0
  786. list_data += '</ul><hr><ul><li>All : ' + str(count) + '</li></ul>'
  787. list_data += next_fix('/user_log?num=', num, user_list)
  788. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  789. imp = [load_lang('recent') + ' ' + load_lang('subscriber'), wiki_set(), custom(), other2([0, 0])],
  790. data = list_data,
  791. menu = 0
  792. ))
  793. @app.route('/admin_log')
  794. def admin_log():
  795. num = int(flask.request.args.get('num', 1))
  796. if num * 50 > 0:
  797. sql_num = num * 50 - 50
  798. else:
  799. sql_num = 0
  800. list_data = '<ul>'
  801. curs.execute("select who, what, time from re_admin order by time desc limit ?, '50'", [str(sql_num)])
  802. get_list = curs.fetchall()
  803. for data in get_list:
  804. list_data += '<li>' + ip_pas(data[0]) + ' / ' + data[1] + ' / ' + data[2] + '</li>'
  805. list_data += '</ul>'
  806. list_data += next_fix('/admin_log?num=', num, get_list)
  807. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  808. imp = [load_lang('recent') + ' ' + load_lang('authority'), wiki_set(), custom(), other2([0, 0])],
  809. data = list_data,
  810. menu = 0
  811. ))
  812. @app.route('/give_log')
  813. def give_log():
  814. list_data = '<ul>'
  815. back = ''
  816. curs.execute("select distinct name from alist order by name asc")
  817. for data in curs.fetchall():
  818. if back != data[0]:
  819. back = data[0]
  820. list_data += '<li><a href="/admin_plus/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  821. list_data += '</ul><hr><a href="/manager/8">(' + load_lang('create') + ')</a>'
  822. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  823. imp = [load_lang('admin_group') + ' ' + load_lang('list'), wiki_set(), custom(), other2([0, 0])],
  824. data = list_data,
  825. menu = [['other', load_lang('other')]]
  826. ))
  827. @app.route('/indexing')
  828. def indexing():
  829. if admin_check(None, 'indexing') != 1:
  830. return re_error('/error/3')
  831. curs.execute("select name from sqlite_master where type = 'index'")
  832. data = curs.fetchall()
  833. if data:
  834. for delete_index in data:
  835. print('Delete : ' + delete_index[0])
  836. sql = 'drop index if exists ' + delete_index[0]
  837. try:
  838. curs.execute(sql)
  839. except:
  840. pass
  841. else:
  842. 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;")
  843. for table in curs.fetchall():
  844. curs.execute('select sql from sqlite_master where name = ?', [table[0]])
  845. cul = curs.fetchall()
  846. r_cul = re.findall('(?:([^ (]*) text)', str(cul[0]))
  847. for n_cul in r_cul:
  848. print('Create : index_' + table[0] + '_' + n_cul)
  849. sql = 'create index index_' + table[0] + '_' + n_cul + ' on ' + table[0] + '(' + n_cul + ')'
  850. try:
  851. curs.execute(sql)
  852. except:
  853. pass
  854. conn.commit()
  855. return redirect('/')
  856. @app.route('/re_start', methods=['POST', 'GET'])
  857. def re_start():
  858. if admin_check(None, 're_start') != 1:
  859. return re_error('/error/3')
  860. if flask.request.method == 'POST':
  861. os.execl(sys.executable, sys.executable, *sys.argv)
  862. else:
  863. print('Re Start')
  864. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  865. imp = [load_lang('server') + ' ' + load_lang('restart'), wiki_set(), custom(), other2([0, 0])],
  866. data = '<form method="post"><button type="submit">' + load_lang('restart') + '</button></form>',
  867. menu = [['manager', load_lang('admin')]]
  868. ))
  869. @app.route('/update')
  870. def update():
  871. if admin_check(None, 'update') != 1:
  872. return re_error('/error/3')
  873. curs.execute('select data from other where name = "update"')
  874. up_data = curs.fetchall()
  875. if up_data:
  876. up_data = up_data[0][0]
  877. else:
  878. up_data = 'stable'
  879. if platform.system() == 'Linux':
  880. print('Update')
  881. os.system('git remote rm origin')
  882. os.system('git remote add origin https://github.com/2DU/openNAMU.git')
  883. ok = os.system('git fetch origin ' + up_data)
  884. ok = os.system('git reset --hard origin/' + up_data)
  885. if ok == 0:
  886. return redirect('/re_start')
  887. else:
  888. if platform.system() == 'Windows':
  889. print('Download')
  890. urllib.request.urlretrieve('https://github.com/2DU/openNAMU/archive/' + up_data + '.zip', 'update.zip')
  891. print('Zip Extract')
  892. zipfile.ZipFile('update.zip').extractall('')
  893. print('Move')
  894. ok = os.system('xcopy /y /r openNAMU-' + up_data + ' .')
  895. if ok == 0:
  896. print('Remove')
  897. os.system('rd /s /q openNAMU-' + up_data)
  898. os.system('del update.zip')
  899. return redirect('/re_start')
  900. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  901. imp = [load_lang('update'), wiki_set(), custom(), other2([0, 0])],
  902. data = 'Auto update is not support. <a href="https://github.com/2DU/openNAMU">(GitHub)</a>',
  903. menu = [['manager/1', load_lang('admin')]]
  904. ))
  905. @app.route('/xref/<everything:name>')
  906. def xref(name = None):
  907. num = int(flask.request.args.get('num', 1))
  908. if num * 50 > 0:
  909. sql_num = num * 50 - 50
  910. else:
  911. sql_num = 0
  912. div = '<ul>'
  913. curs.execute("select link, type from back where title = ? and not type = 'cat' and not type = 'no' order by link asc limit ?, '50'", [name, str(sql_num)])
  914. data_list = curs.fetchall()
  915. for data in data_list:
  916. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a>'
  917. if data[1]:
  918. div += ' (' + data[1] + ')'
  919. div += '</li>'
  920. if re.search('^' + load_lang('template', 1) + ':', data[0]):
  921. div += '<li><a id="inside" href="/xref/' + url_pas(data[0]) + '">' + data[0] + '</a> (' + load_lang('backlink') + ')</li>'
  922. div += '</ul>' + next_fix('/xref/' + url_pas(name) + '?num=', num, data_list)
  923. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  924. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('backlink') + ')', 0])],
  925. data = div,
  926. menu = [['w/' + url_pas(name), load_lang('document')]]
  927. ))
  928. @app.route('/please')
  929. def please():
  930. num = int(flask.request.args.get('num', 1))
  931. if num * 50 > 0:
  932. sql_num = num * 50 - 50
  933. else:
  934. sql_num = 0
  935. div = '<ul>'
  936. var = ''
  937. curs.execute("select distinct title from back where type = 'no' order by title asc limit ?, '50'", [str(sql_num)])
  938. data_list = curs.fetchall()
  939. for data in data_list:
  940. if var != data[0]:
  941. div += '<li><a id="not_thing" href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  942. var = data[0]
  943. div += '</ul>' + next_fix('/please?num=', num, data_list)
  944. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  945. imp = [load_lang('need') + ' ' + load_lang('document'), wiki_set(), custom(), other2([0, 0])],
  946. data = div,
  947. menu = [['other', load_lang('other')]]
  948. ))
  949. @app.route('/recent_discuss')
  950. def recent_discuss():
  951. div = ''
  952. if flask.request.args.get('what', 'normal') == 'normal':
  953. div += '<a href="/recent_discuss?what=close">(' + load_lang('close') + ')</a>'
  954. m_sub = 0
  955. else:
  956. div += '<a href="/recent_discuss">(' + load_lang('open') + ')</a>'
  957. m_sub = ' (' + load_lang('close') + ')'
  958. div += '<hr><table style="width: 100%; text-align: center;"><tbody><tr><td style="width: 50%;">' + load_lang('discussion') + ' ' + load_lang('name') + '</td><td style="width: 50%;">' + load_lang('time') + '</td></tr>'
  959. curs.execute("select title, sub, date from rd order by date desc limit 50")
  960. for data in curs.fetchall():
  961. title = html.escape(data[0])
  962. sub = html.escape(data[1])
  963. close = 0
  964. if flask.request.args.get('what', 'normal') == 'normal':
  965. curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [data[0], data[1]])
  966. if curs.fetchall():
  967. close = 1
  968. else:
  969. curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [data[0], data[1]])
  970. if not curs.fetchall():
  971. close = 1
  972. if close == 0:
  973. div += '<tr><td><a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[1]) + '">' + title + '</a> (' + sub + ')</td><td>' + data[2] + '</td></tr>'
  974. else:
  975. div += '</tbody></table>'
  976. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  977. imp = [load_lang('recent') + ' ' + load_lang('discussion'), wiki_set(), custom(), other2([m_sub, 0])],
  978. data = div,
  979. menu = 0
  980. ))
  981. @app.route('/block_log')
  982. @app.route('/block_log/<regex("ip|user|never_end|can_end|end|now|edit_filter"):tool2>')
  983. @app.route('/<regex("block_user|block_admin"):tool>/<name>')
  984. def block_log(name = None, tool = None, tool2 = None):
  985. num = int(flask.request.args.get('num', 1))
  986. if num * 50 > 0:
  987. sql_num = num * 50 - 50
  988. else:
  989. sql_num = 0
  990. div = '''
  991. <table style="width: 100%; text-align: center;">
  992. <tbody>
  993. <tr>
  994. <td style="width: 33.3%;">''' + load_lang('blocked') + '''</td>
  995. <td style="width: 33.3%;">''' + load_lang('admin') + '''</td>
  996. <td style="width: 33.3%;">''' + load_lang('period') + '''</td>
  997. </tr>
  998. '''
  999. data_list = ''
  1000. if not name:
  1001. if not tool2:
  1002. div = '''
  1003. <a href="/manager/11">(''' + load_lang('blocked') + ''')</a> <a href="/manager/12">(''' + load_lang('admin') + ''')</a>
  1004. <hr>
  1005. <a href="/block_log/ip">(IP)</a> <a href="/block_log/user">(''' + load_lang('subscriber') + ')</a> <a href="/block_log/never_end">(' + load_lang('limitless') + ')</a> <a href="/block_log/can_end">(' + load_lang('period') + ')</a> <a href="/block_log/end">(' + load_lang('release') + ')</a> <a href="/block_log/now">(' + load_lang('now') + ')</a> <a href="/block_log/edit_filter">(' + load_lang('edit') + ' ' + load_lang('filter') + ''')</a>
  1006. <hr>
  1007. ''' + div
  1008. sub = 0
  1009. menu = 0
  1010. curs.execute("select why, block, blocker, end, today from rb order by today desc limit ?, '50'", [str(sql_num)])
  1011. else:
  1012. menu = [['block_log', load_lang('normal')]]
  1013. if tool2 == 'ip':
  1014. sub = ' (IP)'
  1015. curs.execute("select why, block, blocker, end, today from rb where (block like ? or block like ?) order by today desc limit ?, '50'", ['%.%', '%:%', str(sql_num)])
  1016. elif tool2 == 'user':
  1017. sub = ' (' + load_lang('subscriber') + ')'
  1018. curs.execute("select why, block, blocker, end, today from rb where not (block like ? or block like ?) order by today desc limit ?, '50'", ['%.%', '%:%', str(sql_num)])
  1019. elif tool2 == 'never_end':
  1020. sub = '(' + load_lang('limitless') + ')'
  1021. curs.execute("select why, block, blocker, end, today from rb where not end like ? and not end like ? order by today desc limit ?, '50'", ['%:%', '%' + load_lang('release', 1) + '%', str(sql_num)])
  1022. elif tool2 == 'end':
  1023. sub = '(' + load_lang('release') + ')'
  1024. curs.execute("select why, block, blocker, end, today from rb where end = ? order by today desc limit ?, '50'", [load_lang('release', 1), str(sql_num)])
  1025. elif tool2 == 'now':
  1026. sub = '(' + load_lang('now') + ')'
  1027. data_list = []
  1028. curs.execute("select block from ban limit ?, '50'", [str(sql_num)])
  1029. for in_data in curs.fetchall():
  1030. curs.execute("select why, block, blocker, end, today from rb where block = ? order by today desc limit 1", [in_data[0]])
  1031. data_list = [curs.fetchall()[0]] + data_list
  1032. elif tool2 == 'edit_filter':
  1033. sub = '(' + load_lang('edit') + ' ' + load_lang('filter') + ')'
  1034. curs.execute("select why, block, blocker, end, today from rb where blocker = ? order by today desc limit ?, '50'", [load_lang('tool', 1) + ':' + load_lang('edit', 1) + ' ' + load_lang('filter', 1), str(sql_num)])
  1035. else:
  1036. sub = '(' + load_lang('period') + ')'
  1037. curs.execute("select why, block, blocker, end, today from rb where end like ? order by today desc limit ?, '50'", ['%\-%', str(sql_num)])
  1038. else:
  1039. menu = [['block_log', load_lang('normal')]]
  1040. if tool == 'block_user':
  1041. sub = ' (' + load_lang('blocked') + ')'
  1042. curs.execute("select why, block, blocker, end, today from rb where block = ? order by today desc limit ?, '50'", [name, str(sql_num)])
  1043. else:
  1044. sub = ' (' + load_lang('admin') + ')'
  1045. curs.execute("select why, block, blocker, end, today from rb where blocker = ? order by today desc limit ?, '50'", [name, str(sql_num)])
  1046. if data_list == '':
  1047. data_list = curs.fetchall()
  1048. for data in data_list:
  1049. why = html.escape(data[0])
  1050. if why == '':
  1051. why = '<br>'
  1052. band = re.search("^([0-9]{1,3}\.[0-9]{1,3})$", data[1])
  1053. if band:
  1054. ip = data[1] + ' (' + load_lang('band') + ')'
  1055. else:
  1056. ip = ip_pas(data[1])
  1057. if data[3] != '':
  1058. end = data[3]
  1059. else:
  1060. end = load_lang('limitless') + ''
  1061. div += '<tr><td>' + ip + '</td><td>' + ip_pas(data[2]) + '</td><td>Start : ' + data[4] + '<br>End : ' + end + '</td></tr>'
  1062. div += '<tr><td colspan="3">' + why + '</td></tr>'
  1063. div += '</tbody></table>'
  1064. if not name:
  1065. if not tool2:
  1066. div += next_fix('/block_log?num=', num, data_list)
  1067. else:
  1068. div += next_fix('/block_log/' + url_pas(tool2) + '?num=', num, data_list)
  1069. else:
  1070. div += next_fix('/' + url_pas(tool) + '/' + url_pas(name) + '?num=', num, data_list)
  1071. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1072. imp = [load_lang('recent') + ' ' + load_lang('ban'), wiki_set(), custom(), other2([sub, 0])],
  1073. data = div,
  1074. menu = menu
  1075. ))
  1076. @app.route('/search', methods=['POST'])
  1077. def search():
  1078. return redirect('/search/' + url_pas(flask.request.form.get('search', None)))
  1079. @app.route('/goto', methods=['POST'])
  1080. def goto():
  1081. curs.execute("select title from data where title = ?", [flask.request.form.get('search', None)])
  1082. data = curs.fetchall()
  1083. if data:
  1084. return redirect('/w/' + url_pas(flask.request.form.get('search', None)))
  1085. else:
  1086. return redirect('/search/' + url_pas(flask.request.form.get('search', None)))
  1087. @app.route('/search/<everything:name>')
  1088. def deep_search(name = None):
  1089. num = int(flask.request.args.get('num', 1))
  1090. if num * 50 > 0:
  1091. sql_num = num * 50 - 50
  1092. else:
  1093. sql_num = 0
  1094. div = '<ul>'
  1095. div_plus = ''
  1096. no = 0
  1097. start = 2
  1098. test = ''
  1099. curs.execute("select title from data where title = ?", [name])
  1100. if curs.fetchall():
  1101. div = '<ul><li><a href="/w/' + url_pas(name) + '">' + name + '</a></li></ul><hr><ul>'
  1102. else:
  1103. div = '<ul><li><a id="not_thing" href="/w/' + url_pas(name) + '">' + name + '</a></li></ul><hr><ul>'
  1104. curs.execute("select distinct title, case when title like ? then '제목' else '내용' end from data where title like ? or data like ? order by case when title like ? then 1 else 2 end limit ?, '50'", ['%' + name + '%', '%' + name + '%', '%' + name + '%', '%' + name + '%', str(sql_num)])
  1105. all_list = curs.fetchall()
  1106. if all_list:
  1107. test = all_list[0][1]
  1108. for data in all_list:
  1109. if data[1] != test:
  1110. div_plus += '</ul><hr><ul>'
  1111. test = data[1]
  1112. div_plus += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (' + data[1] + ')</li>'
  1113. else:
  1114. div += '<li>404</li>'
  1115. div += div_plus + '</ul>'
  1116. div += next_fix('/search/' + url_pas(name) + '?num=', num, all_list)
  1117. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1118. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('search') + ')', 0])],
  1119. data = div,
  1120. menu = 0
  1121. ))
  1122. @app.route('/raw/<everything:name>')
  1123. @app.route('/topic/<everything:name>/sub/<sub_title>/raw/<int:num>')
  1124. def raw_view(name = None, sub_title = None, num = None):
  1125. v_name = name
  1126. sub = ' (' + load_lang('raw') + ')'
  1127. if not num:
  1128. num = flask.request.args.get('num', None)
  1129. if num:
  1130. num = int(num)
  1131. if not sub_title and num:
  1132. curs.execute("select title from history where title = ? and id = ? and hide = 'O'", [name, str(num)])
  1133. if curs.fetchall() and admin_check(6, None) != 1:
  1134. return re_error('/error/3')
  1135. curs.execute("select data from history where title = ? and id = ?", [name, str(num)])
  1136. sub += ' (' + str(num) + load_lang('version') + ')'
  1137. menu = [['history/' + url_pas(name), load_lang('history')]]
  1138. elif sub_title:
  1139. curs.execute("select data from topic where id = ? and title = ? and sub = ? and block = ''", [str(num), name, sub_title])
  1140. v_name = load_lang('discussion') + ' Raw'
  1141. sub = ' (' + str(num) + ')'
  1142. menu = [['topic/' + url_pas(name) + '/sub/' + url_pas(sub_title) + '#' + str(num), load_lang('discussion')], ['topic/' + url_pas(name) + '/sub/' + url_pas(sub_title) + '/admin/' + str(num), load_lang('tool')]]
  1143. else:
  1144. curs.execute("select data from data where title = ?", [name])
  1145. menu = [['w/' + url_pas(name), load_lang('document')]]
  1146. data = curs.fetchall()
  1147. if data:
  1148. p_data = html.escape(data[0][0])
  1149. p_data = '<textarea readonly rows="25">' + p_data + '</textarea>'
  1150. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1151. imp = [v_name, wiki_set(), custom(), other2([sub, 0])],
  1152. data = p_data,
  1153. menu = menu
  1154. ))
  1155. else:
  1156. return redirect('/w/' + url_pas(name))
  1157. @app.route('/revert/<everything:name>', methods=['POST', 'GET'])
  1158. def revert(name = None):
  1159. num = int(flask.request.args.get('num', 0))
  1160. curs.execute("select title from history where title = ? and id = ? and hide = 'O'", [name, str(num)])
  1161. if curs.fetchall() and admin_check(6, None) != 1:
  1162. return re_error('/error/3')
  1163. if acl_check(name) == 1:
  1164. return re_error('/ban')
  1165. if flask.request.method == 'POST':
  1166. if captcha_post(flask.request.form.get('g-recaptcha-response', None)) == 1:
  1167. return re_error('/error/13')
  1168. else:
  1169. captcha_post('', 0)
  1170. curs.execute("delete from back where link = ?", [name])
  1171. conn.commit()
  1172. curs.execute("select data from history where title = ? and id = ?", [name, str(num)])
  1173. data = curs.fetchall()
  1174. if data:
  1175. curs.execute("select data from data where title = ?", [name])
  1176. data_old = curs.fetchall()
  1177. if data_old:
  1178. leng = leng_check(len(data_old[0][0]), len(data[0][0]))
  1179. curs.execute("update data set data = ? where title = ?", [data[0][0], name])
  1180. else:
  1181. leng = ' +' + str(len(data[0][0]))
  1182. curs.execute("insert into data (title, data) values (?, ?)", [name, data[0][0]])
  1183. history_plus(name, data[0][0], get_time(), ip_check(), flask.request.form.get('send', None) + ' (' + str(num) + load_lang('version', 1) + ')', leng)
  1184. namumark(
  1185. title = name,
  1186. data = data[0][0],
  1187. num = 1
  1188. )
  1189. conn.commit()
  1190. return redirect('/w/' + url_pas(name))
  1191. else:
  1192. curs.execute("select title from history where title = ? and id = ?", [name, str(num)])
  1193. if not curs.fetchall():
  1194. return redirect('/w/' + url_pas(name))
  1195. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1196. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('revert') + ')', 0])],
  1197. data = '''
  1198. <form method="post">
  1199. <span>''' + flask.request.args.get('num', '0') + load_lang('version') + '''</span>
  1200. <hr>
  1201. ''' + ip_warring() + '''
  1202. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  1203. <hr>
  1204. ''' + captcha_get() + '''
  1205. <button type="submit">''' + load_lang('revert') + '''</button>
  1206. </form>
  1207. ''',
  1208. menu = [['history/' + url_pas(name), load_lang('history')], ['recent_changes', load_lang('recent') + ' ' + load_lang('change')]]
  1209. ))
  1210. @app.route('/edit_filter')
  1211. def edit_filter():
  1212. div = '<ul>'
  1213. curs.execute("select name from filter")
  1214. data = curs.fetchall()
  1215. for data_list in data:
  1216. div += '<li><a href="/edit_filter/' + url_pas(data_list[0]) + '">' + data_list[0] + '</a></li>'
  1217. div += '</ul>'
  1218. if data:
  1219. div += '<hr><a href="/manager/9">(' + load_lang('plus') + ')</a>'
  1220. else:
  1221. div = '<a href="/manager/9">(' + load_lang('plus') + ')</a>'
  1222. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1223. imp = [load_lang('edit') + ' ' + load_lang('filter') + ' ' + load_lang('list'), wiki_set(), custom(), other2([0, 0])],
  1224. data = div,
  1225. menu = [['manager', load_lang('admin')]]
  1226. ))
  1227. @app.route('/edit_filter/<name>/delete', methods=['POST', 'GET'])
  1228. def delete_edit_filter(name = None):
  1229. if admin_check(1, 'edit_filter delete') != 1:
  1230. return re_error('/error/3')
  1231. curs.execute("delete from filter where name = ?", [name])
  1232. conn.commit()
  1233. return redirect('/edit_filter')
  1234. @app.route('/edit_filter/<name>', methods=['POST', 'GET'])
  1235. def set_edit_filter(name = None):
  1236. if flask.request.method == 'POST':
  1237. if admin_check(1, 'edit_filter edit') != 1:
  1238. return re_error('/error/3')
  1239. if flask.request.form.get('ban', None):
  1240. end = 'X'
  1241. else:
  1242. end = ''
  1243. curs.execute("select name from filter where name = ?", [name])
  1244. if curs.fetchall():
  1245. curs.execute("update filter set regex = ?, sub = ? where name = ?", [flask.request.form.get('content', 'Test'), end, name])
  1246. else:
  1247. curs.execute("insert into filter (name, regex, sub) values (?, ?, ?)", [name, flask.request.form.get('content', 'Test'), end])
  1248. conn.commit()
  1249. return redirect('/edit_filter/' + url_pas(name))
  1250. else:
  1251. curs.execute("select regex, sub from filter where name = ?", [name])
  1252. exist = curs.fetchall()
  1253. if exist:
  1254. textarea = exist[0][0]
  1255. if exist[0][1] == 'X':
  1256. time_data = 'checked="checked"'
  1257. else:
  1258. time_data = ''
  1259. else:
  1260. textarea = ''
  1261. time_data = ''
  1262. if admin_check(1, None) != 1:
  1263. stat = 'disabled'
  1264. else:
  1265. stat = ''
  1266. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1267. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('edit') + ' ' + load_lang('filter') + ')', 0])],
  1268. data = '''
  1269. <form method="post">
  1270. <input ''' + stat + ''' placeholder="Regex" name="content" value="''' + html.escape(textarea) + '''" type="text">
  1271. <hr>
  1272. <input ''' + stat + ''' type="checkbox" ''' + time_data + ''' name="ban">
  1273. ''' + load_lang('ban') + '''
  1274. <hr>
  1275. <button ''' + stat + ''' id="save" type="submit">''' + load_lang('save') + '''</button>
  1276. </form>
  1277. ''',
  1278. menu = [['edit_filter', load_lang('list')], ['edit_filter/' + url_pas(name) + '/delete', load_lang('delete')]]
  1279. ))
  1280. @app.route('/edit/<everything:name>', methods=['POST', 'GET'])
  1281. def edit(name = None):
  1282. ip = ip_check()
  1283. if acl_check(name) == 1:
  1284. return re_error('/ban')
  1285. if flask.request.method == 'POST':
  1286. if admin_check(1, 'edit_filter pass') != 1:
  1287. curs.execute("select regex, sub from filter")
  1288. for data_list in curs.fetchall():
  1289. match = re.compile(data_list[0])
  1290. if match.search(flask.request.form.get('content', None)):
  1291. if data_list[1] == 'X':
  1292. ban_insert(
  1293. ip,
  1294. '',
  1295. load_lang('edit', 1) + ' ' + load_lang('filter', 1),
  1296. None,
  1297. load_lang('tool', 1) + ':' + load_lang('edit', 1) + ' ' + load_lang('filter', 1)
  1298. )
  1299. return re_error('/error/21')
  1300. if captcha_post(flask.request.form.get('g-recaptcha-response', None)) == 1:
  1301. return re_error('/error/13')
  1302. else:
  1303. captcha_post('', 0)
  1304. if len(flask.request.form.get('send', None)) > 500:
  1305. return re_error('/error/15')
  1306. if flask.request.form.get('otent', None) == flask.request.form.get('content', None):
  1307. return redirect('/w/' + url_pas(name))
  1308. today = get_time()
  1309. content = savemark(flask.request.form.get('content', None))
  1310. curs.execute("select data from data where title = ?", [name])
  1311. old = curs.fetchall()
  1312. if old:
  1313. leng = leng_check(len(flask.request.form.get('otent', None)), len(content))
  1314. if flask.request.args.get('section', None):
  1315. i = 1
  1316. data = re.sub('\r\n', '\n', '\r\n' + old[0][0] + '\r\n')
  1317. while 1:
  1318. replace_data = re.search('\n(={1,6}) ?((?:(?!=).)+) ?={1,6}\n', data)
  1319. if replace_data:
  1320. replace_data = replace_data.groups()[0]
  1321. if i == int(flask.request.args.get('section', None)):
  1322. data = re.sub('\n(?P<in>={1,6}) ?(?P<out>(?:(?!=).)+) ?={1,6}\n', '\n<real h' + str(len(replace_data)) + '>\g<out></real h' + str(len(replace_data)) + '>\n', data, 1)
  1323. else:
  1324. data = re.sub('\n(?P<in>={1,6}) ?(?P<out>(?:(?!=).)+) ?={1,6}\n', '\n<h' + str(len(replace_data)) + '>\g<out></h' + str(len(replace_data)) + '>\n', data, 1)
  1325. i += 1
  1326. else:
  1327. break
  1328. new_data = re.sub('\r\n', '\n', '\r\n' + flask.request.form.get('otent', None) + '\r\n')
  1329. while 1:
  1330. replace_data = re.search('\n(={1,6}) ?((?:(?!=).)+) ?={1,6}\n', new_data)
  1331. if replace_data:
  1332. replace_data = replace_data.groups()[0]
  1333. new_data = re.sub('\n(?P<in>={1,6}) ?(?P<out>(?:(?!=).)+) ?={1,6}\n', '\n<real h' + str(len(replace_data)) + '>\g<out></real h' + str(len(replace_data)) + '>\n', new_data, 1)
  1334. else:
  1335. break
  1336. content = data.replace(new_data, '\n' + content + '\n')
  1337. while 1:
  1338. replace_data = re.search('\n<(?:real )?h([1-6])>((?:(?!<h).)+) ?<\/(?:real )?h[1-6]>\n', content)
  1339. if replace_data:
  1340. replace_data = replace_data.groups()[0]
  1341. content = re.sub('\n<(?:real )?h([1-6])>(?P<out>(?:(?!<h).)+) ?<\/(?:real )?h[1-6]>\n', '\n' + ('=' * int(replace_data)) + ' \g<out> ' + ('=' * int(replace_data)) + '\n', content, 1)
  1342. else:
  1343. break
  1344. content = re.sub('^\n', '', content)
  1345. content = re.sub('\n$', '', content)
  1346. curs.execute("update data set data = ? where title = ?", [content, name])
  1347. else:
  1348. leng = ' +' + str(len(content))
  1349. curs.execute("insert into data (title, data) values (?, ?)", [name, content])
  1350. curs.execute("select user from scan where title = ?", [name])
  1351. for user_data in curs.fetchall():
  1352. curs.execute("insert into alarm (name, data, date) values (?, ?, ?)", [ip, ip + ' - <a href="/w/' + url_pas(name) + '">' + name + '</a> (Edit)', today])
  1353. history_plus(name, content, today, ip, flask.request.form.get('send', None), leng)
  1354. curs.execute("delete from back where link = ?", [name])
  1355. curs.execute("delete from back where title = ? and type = 'no'", [name])
  1356. namumark(
  1357. title = name,
  1358. data = content,
  1359. num = 1
  1360. )
  1361. conn.commit()
  1362. return redirect('/w/' + url_pas(name))
  1363. else:
  1364. curs.execute("select data from data where title = ?", [name])
  1365. new = curs.fetchall()
  1366. if new:
  1367. if flask.request.args.get('section', None):
  1368. test_data = '\n' + re.sub('\r\n', '\n', new[0][0]) + '\n'
  1369. section_data = re.findall('((?:={1,6}) ?(?:(?:(?!=).)+) ?={1,6}\n(?:(?:(?!(?:={1,6}) ?(?:(?:(?!=).)+) ?={1,6}\n).)*\n*)*)', test_data)
  1370. data = section_data[int(flask.request.args.get('section', None)) - 1]
  1371. else:
  1372. data = new[0][0]
  1373. else:
  1374. data = ''
  1375. data_old = data
  1376. if not flask.request.args.get('section', None):
  1377. get_name = '''
  1378. <a href="/manager/15?plus=''' + url_pas(name) + '''">(Load)</a>
  1379. <hr>
  1380. '''
  1381. action = ''
  1382. else:
  1383. get_name = ''
  1384. action = '?section=' + flask.request.args.get('section', None)
  1385. if flask.request.args.get('plus', None):
  1386. curs.execute("select data from data where title = ?", [flask.request.args.get('plus', None)])
  1387. get_data = curs.fetchall()
  1388. if get_data:
  1389. data = get_data[0][0]
  1390. get_name = ''
  1391. js_data = edit_help_button()
  1392. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1393. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('edit') + ')', 0])],
  1394. data = get_name + js_data[0] + '''
  1395. <form method="post" action="/edit/''' + url_pas(name) + action + '''">
  1396. ''' + js_data[1] + '''
  1397. <textarea id="content" rows="25" name="content">''' + html.escape(re.sub('\n$', '', data)) + '''</textarea>
  1398. <textarea style="display: none;" name="otent">''' + html.escape(re.sub('\n$', '', data_old)) + '''</textarea>
  1399. <hr>
  1400. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  1401. <hr>
  1402. ''' + captcha_get() + ip_warring() + '''
  1403. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  1404. <button id="preview" type="submit" formaction="/preview/''' + url_pas(name) + action + '">' + load_lang('preview') + '''</button>
  1405. </form>
  1406. ''',
  1407. menu = [['w/' + url_pas(name), load_lang('document')], ['delete/' + url_pas(name), load_lang('delete')], ['move/' + url_pas(name), load_lang('move')]]
  1408. ))
  1409. @app.route('/preview/<everything:name>', methods=['POST'])
  1410. def preview(name = None):
  1411. ip = ip_check()
  1412. if acl_check(name) == 1:
  1413. return re_error('/ban')
  1414. new_data = re.sub('\r\n#(?:redirect|넘겨주기) (?P<in>(?:(?!\r\n).)+)\r\n', ' * Redirect to [[\g<in>]]', '\r\n' + flask.request.form.get('content', None) + '\r\n')
  1415. new_data = re.sub('^\r\n', '', new_data)
  1416. new_data = re.sub('\r\n$', '', new_data)
  1417. end_data = namumark(
  1418. title = name,
  1419. data = new_data
  1420. )
  1421. if flask.request.args.get('section', None):
  1422. action = '?section=' + flask.request.args.get('section', None)
  1423. else:
  1424. action = ''
  1425. js_data = edit_help_button()
  1426. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1427. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('preview') + ')', 0])],
  1428. data = js_data[0] + '''
  1429. <form method="post" action="/edit/''' + url_pas(name) + action + '''">
  1430. ''' + js_data[1] + '''
  1431. <textarea id="content" rows="25" name="content">''' + html.escape(flask.request.form.get('content', None)) + '''</textarea>
  1432. <textarea style="display: none;" name="otent">''' + html.escape(flask.request.form.get('otent', None)) + '''</textarea>
  1433. <hr>
  1434. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  1435. <hr>
  1436. ''' + captcha_get() + '''
  1437. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  1438. <button id="preview" type="submit" formaction="/preview/''' + url_pas(name) + action + '">' + load_lang('preview') + '''</button>
  1439. </form>
  1440. <hr>
  1441. ''' + end_data,
  1442. menu = [['w/' + url_pas(name), load_lang('document')]]
  1443. ))
  1444. @app.route('/delete/<everything:name>', methods=['POST', 'GET'])
  1445. def delete(name = None):
  1446. ip = ip_check()
  1447. if acl_check(name) == 1:
  1448. return re_error('/ban')
  1449. if flask.request.method == 'POST':
  1450. if captcha_post(flask.request.form.get('g-recaptcha-response', None)) == 1:
  1451. return re_error('/error/13')
  1452. else:
  1453. captcha_post('', 0)
  1454. curs.execute("select data from data where title = ?", [name])
  1455. data = curs.fetchall()
  1456. if data:
  1457. today = get_time()
  1458. leng = '-' + str(len(data[0][0]))
  1459. history_plus(
  1460. name,
  1461. '',
  1462. today,
  1463. ip,
  1464. flask.request.form.get('send', None) + ' (' + load_lang('delete', 1) + ')',
  1465. leng
  1466. )
  1467. curs.execute("select title, link from back where title = ? and not type = 'cat' and not type = 'no'", [name])
  1468. for data in curs.fetchall():
  1469. curs.execute("insert into back (title, link, type) values (?, ?, 'no')", [data[0], data[1]])
  1470. curs.execute("delete from back where link = ?", [name])
  1471. curs.execute("delete from data where title = ?", [name])
  1472. conn.commit()
  1473. return redirect('/w/' + url_pas(name))
  1474. else:
  1475. curs.execute("select title from data where title = ?", [name])
  1476. if not curs.fetchall():
  1477. return redirect('/w/' + url_pas(name))
  1478. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1479. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('delete') + ')', 0])],
  1480. data = '''
  1481. <form method="post">
  1482. ''' + ip_warring() + '''
  1483. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  1484. <hr>
  1485. ''' + captcha_get() + '''
  1486. <button type="submit">''' + load_lang('delete') + '''</button>
  1487. </form>
  1488. ''',
  1489. menu = [['w/' + url_pas(name), load_lang('document')]]
  1490. ))
  1491. @app.route('/move_data/<everything:name>')
  1492. def move_data(name = None):
  1493. data = '<ul>'
  1494. curs.execute("select send, date, ip from history where send like ? or send like ? order by date desc", ['%<a href="/w/' + url_pas(name) + '">' + name + '</a> ' + load_lang('move', 1) + ')%', '%(<a href="/w/' + url_pas(name) + '">' + name + '</a>%'])
  1495. for for_data in curs.fetchall():
  1496. match = re.findall('<a href="\/w\/(?:(?:(?!">).)+)">((?:(?!<\/a>).)+)<\/a>', for_data[0])
  1497. send = re.sub('\([^\)]+\)$', '', for_data[0])
  1498. data += '<li><a href="/move_data/' + url_pas(match[0]) + '">' + match[0] + '</a> - <a href="/move_data/' + url_pas(match[1]) + '">' + match[1] + '</a>'
  1499. if re.search('^( *)+$', send):
  1500. data += ' / ' + for_data[2] + ' / ' + for_data[1] + '</li>'
  1501. else:
  1502. data += ' / ' + for_data[2] + ' / ' + for_data[1] + ' / ' + send + '</li>'
  1503. data += '</ul>'
  1504. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1505. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('move') + ' ' + load_lang('history') + ')', 0])],
  1506. data = data,
  1507. menu = [['history/' + url_pas(name), load_lang('history')]]
  1508. ))
  1509. @app.route('/move/<everything:name>', methods=['POST', 'GET'])
  1510. def move(name = None):
  1511. if acl_check(name) == 1:
  1512. return re_error('/ban')
  1513. if flask.request.method == 'POST':
  1514. if captcha_post(flask.request.form.get('g-recaptcha-response', None)) == 1:
  1515. return re_error('/error/13')
  1516. else:
  1517. captcha_post('', 0)
  1518. curs.execute("select title from history where title = ?", [flask.request.form.get('title', None)])
  1519. if curs.fetchall():
  1520. return re_error('/error/19')
  1521. curs.execute("select data from data where title = ?", [name])
  1522. data = curs.fetchall()
  1523. if data:
  1524. curs.execute("update data set title = ? where title = ?", [flask.request.form.get('title', None), name])
  1525. curs.execute("update back set link = ? where link = ?", [flask.request.form.get('title', None), name])
  1526. data_in = data[0][0]
  1527. else:
  1528. data_in = ''
  1529. history_plus(
  1530. name,
  1531. data_in,
  1532. get_time(),
  1533. ip_check(),
  1534. flask.request.form.get('send', None) + ' (<a>' + name + '</a> - <a>' + flask.request.form.get('title', None) + '</a> ' + load_lang('move', 1) + ')',
  1535. '0'
  1536. )
  1537. curs.execute("select title, link from back where title = ? and not type = 'cat' and not type = 'no'", [name])
  1538. for data in curs.fetchall():
  1539. curs.execute("insert into back (title, link, type) values (?, ?, 'no')", [data[0], data[1]])
  1540. curs.execute("update history set title = ? where title = ?", [flask.request.form.get('title', None), name])
  1541. conn.commit()
  1542. return redirect('/w/' + url_pas(flask.request.form.get('title', None)))
  1543. else:
  1544. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1545. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('move') + ')', 0])],
  1546. data = '''
  1547. <form method="post">
  1548. ''' + ip_warring() + '''
  1549. <input placeholder="''' + load_lang('document') + ' ' + load_lang('name') + '" value="' + name + '''" name="title" type="text">
  1550. <hr>
  1551. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  1552. <hr>
  1553. ''' + captcha_get() + '''
  1554. <button type="submit">''' + load_lang('move') + '''</button>
  1555. </form>
  1556. ''',
  1557. menu = [['w/' + url_pas(name), load_lang('document')]]
  1558. ))
  1559. @app.route('/other')
  1560. def other():
  1561. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1562. imp = [load_lang('other') + ' ' + load_lang('tool'), wiki_set(), custom(), other2([0, 0])],
  1563. data = '''
  1564. <h2>''' + load_lang('record') + '''</h2>
  1565. <ul>
  1566. <li><a href="/manager/6">''' + load_lang('edit') + '''</a></li>
  1567. <li><a href="/manager/7">''' + load_lang('discussion') + '''</a></li>
  1568. </ul>
  1569. <br>
  1570. <h2>''' + load_lang('list') + '''</h2>
  1571. <ul>
  1572. <li><a href="/admin_list">''' + load_lang('admin') + '''</a></li>
  1573. <li><a href="/give_log">''' + load_lang('admin_group') + '''</a></li>
  1574. <li><a href="/not_close_topic">''' + load_lang('open') + ' ' + load_lang('discussion') + '''</a></li>
  1575. <li><a href="/title_index">''' + load_lang('all') + ' ' + load_lang('document') + '''</a></li>
  1576. <li><a href="/acl_list">ACL ''' + load_lang('document') + '''</a></li>
  1577. <li><a href="/please">''' + load_lang('need') + ' ' + load_lang('document') + '''</a></li>
  1578. </ul>
  1579. <br>
  1580. <h2>''' + load_lang('other') + '''</h2>
  1581. <ul>
  1582. <li><a href="/upload">''' + load_lang('upload') + '''</a></li>
  1583. <li><a href="/manager/10">''' + load_lang('document') + ' ' + load_lang('search') + '''</a></li>
  1584. </ul>
  1585. <br>
  1586. <h2>''' + load_lang('admin') + '''</h2>
  1587. <ul>
  1588. <li><a href="/manager/1">''' + load_lang('admin') + ' ' + load_lang('tool') + '''</a></li>
  1589. </ul>
  1590. <br>
  1591. <h2>''' + load_lang('normal_version') + '''</h2>
  1592. <ul>
  1593. <li>''' + load_lang('normal_version') + ' : <a id="out_link" href="https://github.com/2DU/openNAMU/blob/master/version.md">' + r_ver + '''</a></li>
  1594. </ul>
  1595. ''',
  1596. menu = 0
  1597. ))
  1598. @app.route('/manager', methods=['POST', 'GET'])
  1599. @app.route('/manager/<int:num>', methods=['POST', 'GET'])
  1600. def manager(num = 1):
  1601. title_list = {
  1602. 0 : [load_lang('document') + ' ' + load_lang('name'), 'acl'],
  1603. 1 : [0, 'check'],
  1604. 2 : [0, 'ban'],
  1605. 3 : [0, 'admin'],
  1606. 4 : [0, 'record'],
  1607. 5 : [0, 'topic_record'],
  1608. 6 : [load_lang('name'), 'admin_plus'],
  1609. 7 : [load_lang('name'), 'edit_filter'],
  1610. 8 : [load_lang('document') + ' ' + load_lang('name'), 'search'],
  1611. 9 : [0, 'block_user'],
  1612. 10 : [0, 'block_admin'],
  1613. 11 : [load_lang('document') + ' ' + load_lang('name'), 'watch_list'],
  1614. 12 : [load_lang('compare'), 'check'],
  1615. 13 : [load_lang('document') + ' ' + load_lang('name'), 'edit']
  1616. }
  1617. if num == 1:
  1618. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1619. imp = [load_lang('admin') + ' ' + load_lang('tool'), wiki_set(), custom(), other2([0, 0])],
  1620. data = '''
  1621. <h2>''' + load_lang('admin') + '''</h2>
  1622. <ul>
  1623. <li><a href="/manager/2">''' + load_lang('document') + ''' ACL</a></li>
  1624. <li><a href="/manager/3">''' + load_lang('user') + ' ' + load_lang('check') + '''</a></li>
  1625. <li><a href="/manager/4">''' + load_lang('user') + ' ' + load_lang('ban') + '''</a></li>
  1626. <li><a href="/manager/5">''' + load_lang('subscriber') + ' ' + load_lang('authority') + '''</a></li>
  1627. <li><a href="/edit_filter">''' + load_lang('edit') + ' ' + load_lang('filter') + '''</a></li>
  1628. </ul>
  1629. <br>
  1630. <h2>''' + load_lang('owner') + '''</h2>
  1631. <ul>
  1632. <li><a href="/indexing">''' + load_lang('indexing') + ' (' + load_lang('create') + ' or ' + load_lang('delete') + ''')</a></li>
  1633. <li><a href="/manager/8">''' + load_lang('admin_group') + ' ' + load_lang('create') + '''</a></li>
  1634. <li><a href="/setting">''' + load_lang('setting') + ' ' + load_lang('edit') + '''</a></li>
  1635. <li><a href="/re_start">''' + load_lang('server') + ' ' + load_lang('restart') + '''</a></li>
  1636. <li><a href="/update">''' + load_lang('update') + '''</a></li>
  1637. <li><a href="/inter_wiki">''' + load_lang('interwiki') + '''</a></li>
  1638. </ul>
  1639. ''',
  1640. menu = [['other', load_lang('other')]]
  1641. ))
  1642. elif not num - 1 > len(title_list):
  1643. if flask.request.method == 'POST':
  1644. if flask.request.args.get('plus', None):
  1645. return redirect('/' + title_list[(num - 2)][1] + '/' + url_pas(flask.request.args.get('plus', None)) + '?plus=' + flask.request.form.get('name', None))
  1646. else:
  1647. return redirect('/' + title_list[(num - 2)][1] + '/' + url_pas(flask.request.form.get('name', None)))
  1648. else:
  1649. if title_list[(num - 2)][0] == 0:
  1650. placeholder = load_lang('user') + ' ' + load_lang('name')
  1651. else:
  1652. placeholder = title_list[(num - 2)][0]
  1653. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1654. imp = ['Redirect', wiki_set(), custom(), other2([0, 0])],
  1655. data = '''
  1656. <form method="post">
  1657. <input placeholder="''' + placeholder + '''" name="name" type="text">
  1658. <hr>
  1659. <button type="submit">''' + load_lang('move') + '''</button>
  1660. </form>
  1661. ''',
  1662. menu = [['manager', load_lang('admin')]]
  1663. ))
  1664. else:
  1665. return redirect('/')
  1666. @app.route('/title_index')
  1667. def title_index():
  1668. page = int(flask.request.args.get('page', 1))
  1669. num = int(flask.request.args.get('num', 100))
  1670. if page * num > 0:
  1671. sql_num = page * num - num
  1672. else:
  1673. sql_num = 0
  1674. all_list = sql_num + 1
  1675. if num > 1000:
  1676. return re_error('/error/3')
  1677. data = '<a href="/title_index?num=250">(250)</a> <a href="/title_index?num=500">(500)</a> <a href="/title_index?num=1000">(1000)</a>'
  1678. curs.execute("select title from data order by title asc limit ?, ?", [str(sql_num), str(num)])
  1679. title_list = curs.fetchall()
  1680. if title_list:
  1681. data += '<hr><ul>'
  1682. for list_data in title_list:
  1683. data += '<li>' + str(all_list) + '. <a href="/w/' + url_pas(list_data[0]) + '">' + list_data[0] + '</a></li>'
  1684. all_list += 1
  1685. if page == 1:
  1686. count_end = []
  1687. curs.execute("select count(title) from data")
  1688. count = curs.fetchall()
  1689. if count:
  1690. count_end += [count[0][0]]
  1691. else:
  1692. count_end += [0]
  1693. sql_list = [load_lang('template', 1) + ':', 'category:', 'user:', 'file:']
  1694. for sql in sql_list:
  1695. curs.execute("select count(title) from data where title like ?", [sql + '%'])
  1696. count = curs.fetchall()
  1697. if count:
  1698. count_end += [count[0][0]]
  1699. else:
  1700. count_end += [0]
  1701. count_end += [count_end[0] - count_end[1] - count_end[2] - count_end[3] - count_end[4]]
  1702. data += '</ul><hr><ul><li>All : ' + str(count_end[0]) + '</li></ul><hr><ul>'
  1703. data += '<li>' + load_lang('template') + ' : ' + str(count_end[1]) + '</li>'
  1704. data += '<li>' + load_lang('category') + ' : ' + str(count_end[2]) + '</li>'
  1705. data += '<li>' + load_lang('user') + ' : ' + str(count_end[3]) + '</li>'
  1706. data += '<li>' + load_lang('file') + ' : ' + str(count_end[4]) + '</li>'
  1707. data += '<li>Other : ' + str(count_end[5]) + '</li>'
  1708. data += '</ul>' + next_fix('/title_index?num=' + str(num) + '&page=', page, title_list, num)
  1709. sub = ' (' + str(num) + ')'
  1710. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1711. imp = [load_lang('all') + ' ' + load_lang('document'), wiki_set(), custom(), other2([sub, 0])],
  1712. data = data,
  1713. menu = [['other', load_lang('other')]]
  1714. ))
  1715. @app.route('/topic/<everything:name>/sub/<sub>/b/<int:num>')
  1716. def topic_block(name = None, sub = None, num = None):
  1717. if admin_check(3, 'blind (' + name + ' - ' + sub + '#' + str(num) + ')') != 1:
  1718. return re_error('/error/3')
  1719. curs.execute("select block from topic where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1720. block = curs.fetchall()
  1721. if block:
  1722. if block[0][0] == 'O':
  1723. curs.execute("update topic set block = '' where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1724. else:
  1725. curs.execute("update topic set block = 'O' where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1726. rd_plus(name, sub, get_time())
  1727. conn.commit()
  1728. return redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num))
  1729. @app.route('/topic/<everything:name>/sub/<sub>/notice/<int:num>')
  1730. def topic_top(name = None, sub = None, num = None):
  1731. if admin_check(3, 'notice (' + name + ' - ' + sub + '#' + str(num) + ')') != 1:
  1732. return re_error('/error/3')
  1733. curs.execute("select title from topic where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1734. if curs.fetchall():
  1735. curs.execute("select top from topic where id = ? and title = ? and sub = ?", [str(num), name, sub])
  1736. top_data = curs.fetchall()
  1737. if top_data:
  1738. if top_data[0][0] == 'O':
  1739. curs.execute("update topic set top = '' where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1740. else:
  1741. curs.execute("update topic set top = 'O' where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1742. rd_plus(name, sub, get_time())
  1743. conn.commit()
  1744. return redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num))
  1745. @app.route('/topic/<everything:name>/sub/<sub>/tool/<regex("close|stop|agree"):tool>')
  1746. def topic_stop(name = None, sub = None, tool = None):
  1747. if tool == 'close':
  1748. set_list = [
  1749. 'O',
  1750. '',
  1751. load_lang('discussion', 1) + ' ' + load_lang('close', 1),
  1752. load_lang('discussion', 1) + ' ' + load_lang('open', 1)
  1753. ]
  1754. elif tool == 'stop':
  1755. set_list = [
  1756. '',
  1757. 'O',
  1758. load_lang('discussion', 1) + ' ' + load_lang('stop', 1),
  1759. load_lang('discussion', 1) + ' ' + load_lang('restart', 1)
  1760. ]
  1761. elif tool == 'agree':
  1762. pass
  1763. else:
  1764. return redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub))
  1765. if admin_check(3, 'topic ' + tool + ' (' + name + ' - ' + sub + ')') != 1:
  1766. return re_error('/error/3')
  1767. ip = ip_check()
  1768. time = get_time()
  1769. curs.execute("select id from topic where title = ? and sub = ? order by id + 0 desc limit 1", [name, sub])
  1770. topic_check = curs.fetchall()
  1771. if topic_check:
  1772. if tool == 'agree':
  1773. curs.execute("select title from agreedis where title = ? and sub = ?", [name, sub])
  1774. if curs.fetchall():
  1775. curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, '" + load_lang('agreement', 1) + " Fail', ?, ?, '', '1')", [str(int(topic_check[0][0]) + 1), name, sub, time, ip])
  1776. curs.execute("delete from agreedis where title = ? and sub = ?", [name, sub])
  1777. else:
  1778. curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, '" + load_lang('agreement', 1) + " OK', ?, ?, '', '1')", [str(int(topic_check[0][0]) + 1), name, sub, time, ip])
  1779. curs.execute("insert into agreedis (title, sub) values (?, ?)", [name, sub])
  1780. else:
  1781. curs.execute("select title from stop where title = ? and sub = ? and close = ?", [name, sub, set_list[0]])
  1782. if curs.fetchall():
  1783. curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '1')", [str(int(topic_check[0][0]) + 1), name, sub, set_list[3], time, ip])
  1784. curs.execute("delete from stop where title = ? and sub = ? and close = ?", [name, sub, set_list[0]])
  1785. else:
  1786. curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '1')", [str(int(topic_check[0][0]) + 1), name, sub, set_list[2], time, ip])
  1787. curs.execute("insert into stop (title, sub, close) values (?, ?, ?)", [name, sub, set_list[0]])
  1788. curs.execute("delete from stop where title = ? and sub = ? and close = ?", [name, sub, set_list[1]])
  1789. rd_plus(name, sub, time)
  1790. conn.commit()
  1791. return redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub))
  1792. @app.route('/topic/<everything:name>/sub/<sub>/admin/<int:num>')
  1793. def topic_admin(name = None, sub = None, num = None):
  1794. curs.execute("select block, ip, date from topic where title = ? and sub = ? and id = ?", [name, sub, str(num)])
  1795. data = curs.fetchall()
  1796. if not data:
  1797. return redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub))
  1798. ban = ''
  1799. if admin_check(3, None) == 1:
  1800. ban += '</ul><br><h2>' + load_lang('admin') + ' ' + load_lang('tool') + '</h2><ul>'
  1801. is_ban = '<li><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/b/' + str(num) + '">'
  1802. if data[0][0] == 'O':
  1803. is_ban += load_lang('hide') + ' ' + load_lang('release')
  1804. else:
  1805. is_ban += load_lang('hide')
  1806. is_ban += '</a></li>'
  1807. is_ban += '<li><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/notice/' + str(num) + '">'
  1808. curs.execute("select id from topic where title = ? and sub = ? and id = ? and top = 'O'", [name, sub, str(num)])
  1809. if curs.fetchall():
  1810. is_ban += load_lang('notice') + ' ' + load_lang('release')
  1811. else:
  1812. is_ban += load_lang('notice') + ''
  1813. is_ban += '</a></li></ul>'
  1814. ban += '<li><a href="/ban/' + url_pas(data[0][1]) + '">'
  1815. curs.execute("select end from ban where block = ?", [data[0][1]])
  1816. if curs.fetchall():
  1817. ban += load_lang('ban') + ' ' + load_lang('release')
  1818. else:
  1819. ban += load_lang('ban')
  1820. ban += '</a></li>' + is_ban
  1821. ban += '</ul><br><h2>' + load_lang('other') + ' ' + load_lang('tool') + '</h2><ul>'
  1822. ban += '<li><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/raw/' + str(num) + '">Raw</a></li>'
  1823. ban = '<li>' + load_lang('time') + ' : ' + data[0][2] + '</li>' + ban
  1824. if ip_or_user(data[0][1]) == 1:
  1825. ban = '<li>' + load_lang('writer') + ' : ' + data[0][1] + ' <a href="/record/' + url_pas(data[0][1]) + '">(' + load_lang('record') + ')</a></li>' + ban
  1826. else:
  1827. ban = '<li>' + load_lang('writer') + ' : <a href="/w/user:' + data[0][1] + '">' + data[0][1] + '</a> <a href="/record/' + url_pas(data[0][1]) + '">(' + load_lang('record') + ')</a></li>' + ban
  1828. ban = '<h2>' + load_lang('state') + '</h2><ul>' + ban
  1829. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1830. imp = [load_lang('discussion') + ' ' + load_lang('tool'), wiki_set(), custom(), other2([' (' + str(num) + ')', 0])],
  1831. data = ban,
  1832. menu = [['topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num), load_lang('discussion')]]
  1833. ))
  1834. @app.route('/topic/<everything:name>/sub/<sub>', methods=['POST', 'GET'])
  1835. def topic(name = None, sub = None):
  1836. ban = topic_check(name, sub)
  1837. admin = admin_check(3, None)
  1838. if flask.request.method == 'POST':
  1839. if captcha_post(flask.request.form.get('g-recaptcha-response', None)) == 1:
  1840. return re_error('/error/13')
  1841. else:
  1842. captcha_post('', 0)
  1843. ip = ip_check()
  1844. today = get_time()
  1845. if ban == 1:
  1846. return re_error('/ban')
  1847. curs.execute("select id from topic where title = ? and sub = ? order by id + 0 desc limit 1", [name, sub])
  1848. old_num = curs.fetchall()
  1849. if old_num:
  1850. num = int(old_num[0][0]) + 1
  1851. else:
  1852. num = 1
  1853. match = re.search('^user:([^/]+)', name)
  1854. if match:
  1855. curs.execute('insert into alarm (name, data, date) values (?, ?, ?)', [match.groups()[0], ip + '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '">' + load_lang('user', 1) + ' - ' + load_lang('discussion', 1) + '</a> (My)', today])
  1856. data = re.sub('\[\[((?:분류|category):(?:(?:(?!\]\]).)*))\]\]', '[br]', flask.request.form.get('content', None))
  1857. for rd_data in re.findall("(?:#([0-9]+))", data):
  1858. curs.execute("select ip from topic where title = ? and sub = ? and id = ?", [name, sub, rd_data])
  1859. ip_data = curs.fetchall()
  1860. if ip_data and ip_or_user(ip_data[0][0]) == 0:
  1861. curs.execute('insert into alarm (name, data, date) values (?, ?, ?)', [ip_data[0][0], ip + ' - <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num) + '">' + load_lang('discussion', 1) + '</a>', today])
  1862. data = re.sub("(?P<in>#(?:[0-9]+))", '[[\g<in>]]', data)
  1863. data = savemark(data)
  1864. rd_plus(name, sub, today)
  1865. curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '')", [str(num), name, sub, data, today, ip])
  1866. conn.commit()
  1867. return redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub))
  1868. else:
  1869. curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [name, sub])
  1870. close_data = curs.fetchall()
  1871. curs.execute("select title from stop where title = ? and sub = ? and close = ''", [name, sub])
  1872. stop_data = curs.fetchall()
  1873. curs.execute("select id from topic where title = ? and sub = ? limit 1", [name, sub])
  1874. topic_exist = curs.fetchall()
  1875. display = ''
  1876. all_data = ''
  1877. data = ''
  1878. number = 1
  1879. if admin == 1 and topic_exist:
  1880. if close_data:
  1881. all_data += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/close">(' + load_lang('open') + ')</a> '
  1882. else:
  1883. all_data += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/close">(' + load_lang('close') + ')</a> '
  1884. if stop_data:
  1885. all_data += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/stop">(' + load_lang('restart') + ')</a> '
  1886. else:
  1887. all_data += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/stop">(' + load_lang('stop') + ')</a> '
  1888. curs.execute("select title from agreedis where title = ? and sub = ?", [name, sub])
  1889. if curs.fetchall():
  1890. all_data += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/agree">(' + load_lang('release') + ')</a>'
  1891. else:
  1892. all_data += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/agree">(' + load_lang('agreement') + ')</a>'
  1893. all_data += '<hr>'
  1894. if (close_data or stop_data) and admin != 1:
  1895. display = 'display: none;'
  1896. curs.execute("select data, id, date, ip, block, top from topic where title = ? and sub = ? order by id + 0 asc", [name, sub])
  1897. topic = curs.fetchall()
  1898. curs.execute("select data, id, date, ip from topic where title = ? and sub = ? and top = 'O' order by id + 0 asc", [name, sub])
  1899. for topic_data in curs.fetchall():
  1900. who_plus = ''
  1901. curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['notice (' + name + ' - ' + sub + '#' + topic_data[1] + ')'])
  1902. topic_data_top = curs.fetchall()
  1903. if topic_data_top:
  1904. who_plus += ' <span style="margin-right: 5px;">@' + topic_data_top[0][0] + ' </span>'
  1905. all_data += '<table id="toron"><tbody><tr><td id="toron_color_red">'
  1906. all_data += '<a href="#' + topic_data[1] + '">#' + topic_data[1] + '</a> ' + ip_pas(topic_data[3]) + who_plus + ' <span style="float: right;">' + topic_data[2] + '</span>'
  1907. all_data += '</td></tr><tr><td>' + namumark(data = topic_data[0]) + '</td></tr></tbody></table><br>'
  1908. for topic_data in topic:
  1909. if number == 1:
  1910. start = topic_data[3]
  1911. if topic_data[4] == 'O':
  1912. blind_data = 'style="background: gainsboro;"'
  1913. if admin != 1:
  1914. curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['blind (' + name + ' - ' + sub + '#' + str(number) + ')'])
  1915. who_blind = curs.fetchall()
  1916. if who_blind:
  1917. user_write = '[[user:' + who_blind[0][0] + ']] ' + load_lang('hide')
  1918. else:
  1919. user_write = load_lang('hide')
  1920. else:
  1921. blind_data = ''
  1922. user_write = namumark(data = topic_data[0])
  1923. ip = ip_pas(topic_data[3])
  1924. curs.execute('select acl from user where id = ?', [topic_data[3]])
  1925. user_acl = curs.fetchall()
  1926. if user_acl and user_acl[0][0] != 'user':
  1927. ip += ' <a href="javascript:void(0);" title="' + load_lang('admin') + '">★</a>'
  1928. if admin == 1 or blind_data == '':
  1929. ip += ' <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/admin/' + str(number) + '">(' + load_lang('tool') + ')</a>'
  1930. curs.execute("select end from ban where block = ?", [topic_data[3]])
  1931. if curs.fetchall():
  1932. ip += ' <a href="javascript:void(0);" title="' + load_lang('blocked') + '">†</a>'
  1933. if topic_data[5] == '1':
  1934. color = '_blue'
  1935. elif topic_data[3] == start:
  1936. color = '_green'
  1937. else:
  1938. color = ''
  1939. if user_write == '':
  1940. user_write = '<br>'
  1941. all_data += '<table id="toron"><tbody><tr><td id="toron_color' + color + '">'
  1942. all_data += '<a href="javascript:void(0);" id="' + str(number) + '">#' + str(number) + '</a> ' + ip + '</span>'
  1943. all_data += '</td></tr><tr ' + blind_data + '><td>' + user_write + '</td></tr></tbody></table><br>'
  1944. number += 1
  1945. if ban != 1 or admin == 1:
  1946. data += '''
  1947. <a id="reload" href="javascript:void(0);" onclick="location.href.endsWith(\'#reload\')? location.reload(true):location.href=\'#reload\'">(''' + load_lang('reload') + ''')</a>
  1948. <form style="''' + display + '''" method="post">
  1949. <br>
  1950. <textarea style="height: 100px;" name="content"></textarea>
  1951. <hr>
  1952. ''' + captcha_get()
  1953. if display == '':
  1954. data += ip_warring()
  1955. data += '<button type="submit">' + load_lang('send') + '</button></form>'
  1956. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  1957. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('discussion') + ')', 0])],
  1958. data = '<h2 id="topic_top_title">' + sub + '</h2>' + all_data + data,
  1959. menu = [['topic/' + url_pas(name), load_lang('list')]]
  1960. ))
  1961. @app.route('/topic/<everything:name>', methods=['POST', 'GET'])
  1962. @app.route('/topic/<everything:name>/<regex("close|agree"):tool>', methods=['GET'])
  1963. def close_topic_list(name = None, tool = None):
  1964. div = ''
  1965. list_d = 0
  1966. if flask.request.method == 'POST':
  1967. t_num = ''
  1968. while 1:
  1969. curs.execute("select title from topic where title = ? and sub = ? limit 1", [name, flask.request.form.get('topic', None) + t_num])
  1970. if curs.fetchall():
  1971. if t_num == '':
  1972. t_num = ' 2'
  1973. else:
  1974. t_num = ' ' + str(int(t_num.replace(' ', '')) + 1)
  1975. else:
  1976. break
  1977. return redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(flask.request.form.get('topic', None) + t_num))
  1978. else:
  1979. plus = ''
  1980. menu = [['topic/' + url_pas(name), load_lang('list')]]
  1981. if tool == 'close':
  1982. curs.execute("select sub from stop where title = ? and close = 'O' order by sub asc", [name])
  1983. sub = load_lang('close') + ''
  1984. elif tool == 'agree':
  1985. curs.execute("select sub from agreedis where title = ? order by sub asc", [name])
  1986. sub = load_lang('agreement') + ''
  1987. else:
  1988. curs.execute("select sub from rd where title = ? order by date desc", [name])
  1989. sub = load_lang('discussion') + ' ' + load_lang('list')
  1990. menu = [['w/' + url_pas(name), load_lang('document')]]
  1991. plus = '''
  1992. <a href="/topic/''' + url_pas(name) + '''/close">(''' + load_lang('close') + ''')</a> <a href="/topic/''' + url_pas(name) + '''/agree">(''' + load_lang('agreement') + ''')</a>
  1993. <hr>
  1994. <input placeholder="''' + load_lang('discussion') + ' ' + load_lang('name') + '''" name="topic" type="text">
  1995. <hr>
  1996. <button type="submit">''' + load_lang('open') + '''</button>
  1997. '''
  1998. for data in curs.fetchall():
  1999. curs.execute("select data, date, ip, block from topic where title = ? and sub = ? and id = '1'", [name, data[0]])
  2000. if curs.fetchall():
  2001. it_p = 0
  2002. if sub == load_lang('discussion') + ' ' + load_lang('list'):
  2003. curs.execute("select title from stop where title = ? and sub = ? and close = 'O' order by sub asc", [name, data[0]])
  2004. if curs.fetchall():
  2005. it_p = 1
  2006. if it_p != 1:
  2007. div += '<h2><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(data[0]) + '">' + data[0] + '</a></h2>'
  2008. if div == '':
  2009. plus = re.sub('^<br>', '', plus)
  2010. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2011. imp = [name, wiki_set(), custom(), other2([' (' + sub + ')', 0])],
  2012. data = '<form method="post">' + div + plus + '</form>',
  2013. menu = menu
  2014. ))
  2015. @app.route('/login', methods=['POST', 'GET'])
  2016. def login():
  2017. if custom()[2] != 0:
  2018. return redirect('/user')
  2019. ip = ip_check()
  2020. agent = flask.request.headers.get('User-Agent')
  2021. curs.execute("select block from ban where block = ? and login = 'O'", [ip])
  2022. if not curs.fetchall():
  2023. match = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
  2024. if match:
  2025. match = match.groups()[0]
  2026. else:
  2027. match = 'Not'
  2028. curs.execute("select block from ban where block = ? and login = 'O'", [match])
  2029. if not curs.fetchall():
  2030. ban = ban_check()
  2031. else:
  2032. ban = 0
  2033. else:
  2034. ban = 0
  2035. if ban == 1:
  2036. return re_error('/ban')
  2037. if flask.request.method == 'POST':
  2038. if captcha_post(flask.request.form.get('g-recaptcha-response', None)) == 1:
  2039. return re_error('/error/13')
  2040. else:
  2041. captcha_post('', 0)
  2042. curs.execute("select pw from user where id = ?", [flask.request.form.get('id', None)])
  2043. user = curs.fetchall()
  2044. if not user:
  2045. return re_error('/error/2')
  2046. if not bcrypt.checkpw(bytes(flask.request.form.get('pw', None), 'utf-8'), bytes(user[0][0], 'utf-8')):
  2047. return re_error('/error/10')
  2048. flask.session['Now'] = 1
  2049. flask.session['DREAMER'] = flask.request.form.get('id', None)
  2050. curs.execute("select css from custom where user = ?", [flask.request.form.get('id', None)])
  2051. css_data = curs.fetchall()
  2052. if css_data:
  2053. flask.session['Daydream'] = css_data[0][0]
  2054. else:
  2055. flask.session['Daydream'] = ''
  2056. curs.execute("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')", [flask.request.form.get('id', None), ip, agent, get_time()])
  2057. conn.commit()
  2058. return redirect('/user')
  2059. else:
  2060. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2061. imp = [load_lang('login'), wiki_set(), custom(), other2([0, 0])],
  2062. data = '''
  2063. <form method="post">
  2064. <input placeholder="ID" name="id" type="text">
  2065. <hr>
  2066. <input placeholder="PassWord" name="pw" type="password">
  2067. <hr>
  2068. ''' + captcha_get() + '''
  2069. <button type="submit">''' + load_lang('login') + '''</button>
  2070. <hr>
  2071. <span>''' + load_lang('http_warring') + '''</span>
  2072. </form>
  2073. ''',
  2074. menu = [['user', load_lang('user')]]
  2075. ))
  2076. @app.route('/change', methods=['POST', 'GET'])
  2077. def change_password():
  2078. if ban_check() == 1:
  2079. return re_error('/ban')
  2080. if custom()[2] == 0:
  2081. return redirect('/login')
  2082. ip = ip_check()
  2083. if flask.request.method == 'POST':
  2084. if flask.request.form.get('pw', None):
  2085. if flask.request.form.get('pw2', None) != flask.request.form.get('pw3', None):
  2086. return re_error('/error/20')
  2087. curs.execute("select pw from user where id = ?", [flask.session['DREAMER']])
  2088. user = curs.fetchall()
  2089. if not user:
  2090. return re_error('/error/10')
  2091. if not bcrypt.checkpw(bytes(flask.request.form.get('pw', None), 'utf-8'), bytes(user[0][0], 'utf-8')):
  2092. return re_error('/error/2')
  2093. hashed = bcrypt.hashpw(bytes(flask.request.form.get('pw2', None), 'utf-8'), bcrypt.gensalt())
  2094. curs.execute("update user set pw = ? where id = ?", [hashed.decode(), flask.session['DREAMER']])
  2095. curs.execute('select data from user_set where name = "email" and id = ?', [ip])
  2096. if curs.fetchall():
  2097. curs.execute("update user_set set data = ? where name = 'email' and id = ?", [flask.request.form.get('email', ''), ip])
  2098. else:
  2099. curs.execute("insert into user_set (name, id, data) values ('email', ?, ?)", [ip, flask.request.form.get('email', '')])
  2100. curs.execute('select data from user_set where name = "skin" and id = ?', [ip])
  2101. if curs.fetchall():
  2102. curs.execute("update user_set set skin = ? where name = 'skin' and id = ?", [flask.request.form.get('skin', ''), ip])
  2103. else:
  2104. curs.execute("insert into user_set (name, id, data) values ('skin', ?, ?)", [ip, flask.request.form.get('skin', '')])
  2105. conn.commit()
  2106. return redirect('/change')
  2107. else:
  2108. curs.execute('select data from user_set where name = "email" and id = ?', [ip])
  2109. data = curs.fetchall()
  2110. if data:
  2111. email = data[0][0]
  2112. else:
  2113. email = ''
  2114. div2 = load_skin()
  2115. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2116. imp = [load_lang('user') + ' ' + load_lang('setting') + ' ' + load_lang('edit'), wiki_set(), custom(), other2([0, 0])],
  2117. data = '''
  2118. <form method="post">
  2119. <span>ID : ''' + ip + '''</span>
  2120. <hr>
  2121. <input placeholder="Now" name="pw" type="password">
  2122. <br>
  2123. <br>
  2124. <input placeholder="Change" name="pw2" type="password">
  2125. <br>
  2126. <br>
  2127. <input placeholder="Re" name="pw3" type="password">
  2128. <hr>
  2129. <input placeholder="Email" name="email" type="text" value="''' + email + '''">
  2130. <hr>
  2131. <span>''' + load_lang('user') + ' ' + load_lang('skin') + '''</span>
  2132. <br>
  2133. <br>
  2134. <select name="skin">''' + div2 + '''</select>
  2135. <hr>
  2136. <button type="submit">''' + load_lang('edit') + '''</button>
  2137. <hr>
  2138. <span>''' + load_lang('http_warring') + '''</span>
  2139. </form>
  2140. ''',
  2141. menu = [['user', load_lang('user')]]
  2142. ))
  2143. @app.route('/check/<name>')
  2144. def user_check(name = None):
  2145. curs.execute("select acl from user where id = ? or id = ?", [name, flask.request.args.get('plus', 'Yes-Error')])
  2146. user = curs.fetchall()
  2147. if user and user[0][0] != 'user':
  2148. if admin_check(None, None) != 1:
  2149. return re_error('/error/4')
  2150. if admin_check(4, 'check (' + name + ')') != 1:
  2151. return re_error('/error/3')
  2152. num = int(flask.request.args.get('num', 1))
  2153. if num * 50 > 0:
  2154. sql_num = num * 50 - 50
  2155. else:
  2156. sql_num = 0
  2157. if flask.request.args.get('plus', None):
  2158. end_check = 1
  2159. if ip_or_user(name) == 1:
  2160. if ip_or_user(flask.request.args.get('plus', None)) == 1:
  2161. curs.execute("select name, ip, ua, today from ua_d where ip = ? or ip = ? order by today desc limit ?, '50'", [name, flask.request.args.get('plus', None), sql_num])
  2162. else:
  2163. curs.execute("select name, ip, ua, today from ua_d where ip = ? or name = ? order by today desc limit ?, '50'", [name, flask.request.args.get('plus', None), sql_num])
  2164. else:
  2165. if ip_or_user(flask.request.args.get('plus', None)) == 1:
  2166. curs.execute("select name, ip, ua, today from ua_d where name = ? or ip = ? order by today desc limit ?, '50'", [name, flask.request.args.get('plus', None), sql_num])
  2167. else:
  2168. curs.execute("select name, ip, ua, today from ua_d where name = ? or name = ? order by today desc limit ?, '50'", [name, flask.request.args.get('plus', None), sql_num])
  2169. else:
  2170. end_check = 0
  2171. if ip_or_user(name) == 1:
  2172. curs.execute("select name, ip, ua, today from ua_d where ip = ? order by today desc limit ?, '50'", [name, sql_num])
  2173. else:
  2174. curs.execute("select name, ip, ua, today from ua_d where name = ? order by today desc limit ?, '50'", [name, sql_num])
  2175. record = curs.fetchall()
  2176. if record:
  2177. if not flask.request.args.get('plus', None):
  2178. div = '<a href="/manager/14?plus=' + url_pas(name) + '">(' + load_lang('compare') + ')</a> <a href="/easy_check/' + url_pas(name) + '">(' + load_lang('easy') + ')</a><hr>'
  2179. else:
  2180. div = '<a href="/check/' + url_pas(name) + '">(' + name + ')</a> <a href="/check/' + url_pas(flask.request.args.get('plus', None)) + '">(' + flask.request.args.get('plus', None) + ')</a><hr>'
  2181. div += '<table style="width: 100%; text-align: center;"><tbody><tr>'
  2182. div += '<td style="width: 33.3%;">' + load_lang('name') + '</td><td style="width: 33.3%;">IP</td><td style="width: 33.3%;">' + load_lang('time') + '</td></tr>'
  2183. for data in record:
  2184. if data[2]:
  2185. ua = data[2]
  2186. else:
  2187. ua = '<br>'
  2188. div += '<tr><td>' + ip_pas(data[0]) + '</td><td>' + ip_pas(data[1]) + '</td><td>' + data[3] + '</td></tr>'
  2189. div += '<tr><td colspan="3">' + ua + '</td></tr>'
  2190. div += '</tbody></table>'
  2191. else:
  2192. return re_error('/error/2')
  2193. if end_check == 1:
  2194. div += next_fix('/check/' + url_pas(name) + '?plus=' + flask.request.args.get('plus', None) + '&num=', num, record)
  2195. else:
  2196. div += next_fix('/check/' + url_pas(name) + '?num=', num, record)
  2197. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2198. imp = [load_lang('check'), wiki_set(), custom(), other2([0, 0])],
  2199. data = div,
  2200. menu = [['manager', load_lang('admin')]]
  2201. ))
  2202. @app.route('/easy_check/<name>')
  2203. def user_easy_check(name = None):
  2204. curs.execute("select acl from user where id = ? or id = ?", [name, flask.request.args.get('plus', 'Yes-Error')])
  2205. user = curs.fetchall()
  2206. if user and user[0][0] != 'user':
  2207. if admin_check(None, None) != 1:
  2208. return re_error('/error/4')
  2209. if admin_check(4, 'easy check (' + name + ')') != 1:
  2210. return re_error('/error/3')
  2211. num = int(flask.request.args.get('num', 1))
  2212. if num * 50 > 0:
  2213. sql_num = num * 50 - 50
  2214. else:
  2215. sql_num = 0
  2216. div = ''
  2217. div += next_fix('/easy_check/' + url_pas(name) + '?num=', num, [])
  2218. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2219. imp = [load_lang('easy') + ' ' + load_lang('check'), wiki_set(), custom(), other2([0, 0])],
  2220. data = div,
  2221. menu = [['check/' + url_pas(name), load_lang('normal')]]
  2222. ))
  2223. @app.route('/register', methods=['POST', 'GET'])
  2224. def register():
  2225. if ban_check() == 1:
  2226. return re_error('/ban')
  2227. if custom()[2] != 0:
  2228. return redirect('/user')
  2229. if not admin_check(None, None) == 1:
  2230. curs.execute('select data from other where name = "reg"')
  2231. set_d = curs.fetchall()
  2232. if set_d and set_d[0][0] == 'on':
  2233. return re_error('/ban')
  2234. if flask.request.method == 'POST':
  2235. if captcha_post(flask.request.form.get('g-recaptcha-response', None)) == 1:
  2236. return re_error('/error/13')
  2237. else:
  2238. captcha_post('', 0)
  2239. if flask.request.form.get('pw', None) != flask.request.form.get('pw2', None):
  2240. return re_error('/error/20')
  2241. if re.search('(?:[^A-Za-zㄱ-힣0-9 ])', flask.request.form.get('id', None)):
  2242. return re_error('/error/8')
  2243. if len(flask.request.form.get('id', None)) > 32:
  2244. return re_error('/error/7')
  2245. curs.execute("select id from user where id = ?", [flask.request.form.get('id', None)])
  2246. if curs.fetchall():
  2247. return re_error('/error/6')
  2248. hashed = bcrypt.hashpw(bytes(flask.request.form.get('pw', None), 'utf-8'), bcrypt.gensalt())
  2249. curs.execute("select id from user limit 1")
  2250. if not curs.fetchall():
  2251. curs.execute("insert into user (id, pw, acl, date) values (?, ?, 'owner', ?)", [flask.request.form.get('id', None), hashed.decode(), get_time()])
  2252. first = 1
  2253. else:
  2254. curs.execute("insert into user (id, pw, acl, date) values (?, ?, 'user', ?)", [flask.request.form.get('id', None), hashed.decode(), get_time()])
  2255. first = 0
  2256. flask.session['Now'] = 1
  2257. flask.session['DREAMER'] = flask.request.form.get('id', None)
  2258. flask.session['Daydream'] = ''
  2259. ip = ip_check()
  2260. agent = flask.request.headers.get('User-Agent')
  2261. curs.execute("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')", [flask.request.form.get('id', None), ip, agent, get_time()])
  2262. conn.commit()
  2263. if first == 0:
  2264. return redirect('/change')
  2265. else:
  2266. return redirect('/setting/1')
  2267. else:
  2268. contract = ''
  2269. curs.execute('select data from other where name = "contract"')
  2270. data = curs.fetchall()
  2271. if data and data[0][0] != '':
  2272. contract = data[0][0] + '<hr>'
  2273. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2274. imp = [load_lang('register'), wiki_set(), custom(), other2([0, 0])],
  2275. data = '''
  2276. <form method="post">
  2277. ''' + contract + '''
  2278. <input placeholder="ID" name="id" type="text">
  2279. <hr>
  2280. <input placeholder="PassWord" name="pw" type="password">
  2281. <hr>
  2282. <input placeholder="Re" name="pw2" type="password">
  2283. <hr>
  2284. ''' + captcha_get() + '''
  2285. <button type="submit">''' + load_lang('register') + '''</button>
  2286. <hr>
  2287. <span>''' + load_lang('http_warring') + '''</span>
  2288. </form>
  2289. ''',
  2290. menu = [['user', load_lang('user')]]
  2291. ))
  2292. @app.route('/logout')
  2293. def logout():
  2294. flask.session['Now'] = 0
  2295. flask.session.pop('DREAMER', None)
  2296. return redirect('/user')
  2297. @app.route('/ban/<name>', methods=['POST', 'GET'])
  2298. def user_ban(name = None):
  2299. curs.execute("select acl from user where id = ?", [name])
  2300. user = curs.fetchall()
  2301. if not user:
  2302. return re_error('/error/2')
  2303. if user and user[0][0] != 'user':
  2304. if admin_check(None, None) != 1:
  2305. return re_error('/error/4')
  2306. if flask.request.method == 'POST':
  2307. if admin_check(1, 'ban (' + name + ')') != 1:
  2308. return re_error('/error/3')
  2309. if flask.request.form.get('limitless', '') == '':
  2310. end = flask.request.form.get('second', '0')
  2311. else:
  2312. end = '0'
  2313. ban_insert(name, end, flask.request.form.get('why', ''), flask.request.form.get('login', ''), ip_check())
  2314. return redirect('/ban/' + url_pas(name))
  2315. else:
  2316. if admin_check(1, None) != 1:
  2317. return re_error('/error/3')
  2318. curs.execute("select end, why from ban where block = ?", [name])
  2319. end = curs.fetchall()
  2320. if end:
  2321. now = load_lang('release')
  2322. if end[0][0] == '':
  2323. data = '<ul><li>' + load_lang('limitless') + ' ' + load_lang('ban') + '</li>'
  2324. else:
  2325. data = '<ul><li>' + load_lang('ban') + ' : ' + end[0][0] + '</li>'
  2326. if end[0][1] != '':
  2327. data += '<li>' + load_lang('why') + ' : ' + end[0][1] + '</li></ul><hr>'
  2328. else:
  2329. data += '</ul><hr>'
  2330. else:
  2331. if re.search("^([0-9]{1,3}\.[0-9]{1,3})$", name):
  2332. now = load_lang('band') + ' ' + load_lang('ban')
  2333. else:
  2334. now = load_lang('ban')
  2335. now_time = get_time()
  2336. m = re.search('^([0-9]{4})-([0-9]{2})-([0-9]{2})', now_time)
  2337. g = m.groups()
  2338. if ip_or_user(name) == 1:
  2339. plus = '<input type="checkbox" name="login"> ' + load_lang('login') + ' ' + load_lang('able') + '<hr>'
  2340. else:
  2341. plus = ''
  2342. data = '<input placeholder="' + load_lang('second') + '" name="second" type="text"><hr><input type="checkbox" name="limitless"> ' + load_lang('limitless') + '<hr>'
  2343. data += '<input placeholder="' + load_lang('why') + '" name="why" type="text"><hr>' + plus
  2344. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2345. imp = [name, wiki_set(), custom(), other2([' (' + now + ')', 0])],
  2346. data = '<form method="post">' + data + '<button type="submit">' + now + '</button></form>',
  2347. menu = [['manager', load_lang('admin')]]
  2348. ))
  2349. @app.route('/acl/<everything:name>', methods=['POST', 'GET'])
  2350. def acl(name = None):
  2351. check_ok = ''
  2352. if flask.request.method == 'POST':
  2353. check_data = 'acl (' + name + ')'
  2354. else:
  2355. check_data = None
  2356. user_data = re.search('^user:(.+)$', name)
  2357. if user_data:
  2358. if check_data and custom()[2] == 0:
  2359. return redirect('/login')
  2360. if user_data.groups()[0] != ip_check():
  2361. if admin_check(5, check_data) != 1:
  2362. if check_data:
  2363. return re_error('/error/3')
  2364. else:
  2365. check_ok = 'disabled'
  2366. else:
  2367. if admin_check(5, check_data) != 1:
  2368. if check_data:
  2369. return re_error('/error/3')
  2370. else:
  2371. check_ok = 'disabled'
  2372. if flask.request.method == 'POST':
  2373. curs.execute("select title from acl where title = ?", [name])
  2374. if curs.fetchall():
  2375. curs.execute("update acl set dec = ? where title = ?", [flask.request.form.get('dec', ''), name])
  2376. curs.execute("update acl set dis = ? where title = ?", [flask.request.form.get('dis', ''), name])
  2377. curs.execute("update acl set why = ? where title = ?", [flask.request.form.get('why', ''), name])
  2378. else:
  2379. curs.execute("insert into acl (title, dec, dis, why) values (?, ?, ?, ?)", [name, flask.request.form.get('dec', ''), flask.request.form.get('dis', ''), flask.request.form.get('why', '')])
  2380. curs.execute("select title from acl where title = ? and dec = '' and dis = ''", [name])
  2381. if curs.fetchall():
  2382. curs.execute("delete from acl where title = ?", [name])
  2383. conn.commit()
  2384. return redirect('/acl/' + url_pas(name))
  2385. else:
  2386. data = '<h2>' + load_lang('document') + ' ACL</h2><select name="dec" ' + check_ok + '>'
  2387. if re.search('^user:', name):
  2388. acl_list = [['', load_lang('normal')], ['user', load_lang('subscriber')], ['all', load_lang('all')]]
  2389. else:
  2390. acl_list = [['', load_lang('normal')], ['user', load_lang('subscriber')], ['admin', load_lang('admin')]]
  2391. curs.execute("select dec from acl where title = ?", [name])
  2392. acl_data = curs.fetchall()
  2393. for data_list in acl_list:
  2394. if acl_data and acl_data[0][0] == data_list[0]:
  2395. check = 'selected="selected"'
  2396. else:
  2397. check = ''
  2398. data += '<option value="' + data_list[0] + '" ' + check + '>' + data_list[1] + '</option>'
  2399. data += '</select>'
  2400. if not re.search('^user:', name):
  2401. data += '<br><br><h2>' + load_lang('discussion') + ' ACL</h2><select name="dis" ' + check_ok + '>'
  2402. curs.execute("select dis, why from acl where title = ?", [name])
  2403. acl_data = curs.fetchall()
  2404. for data_list in acl_list:
  2405. if acl_data and acl_data[0][0] == data_list[0]:
  2406. check = 'selected="selected"'
  2407. else:
  2408. check = ''
  2409. data += '<option value="' + data_list[0] + '" ' + check + '>' + data_list[1] + '</option>'
  2410. data += '</select>'
  2411. if acl_data:
  2412. data += '<hr><input value="' + html.escape(acl_data[0][1]) + '" placeholder="' + load_lang('why') + '" name="why" type="text" ' + check_ok + '>'
  2413. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2414. imp = [name, wiki_set(), custom(), other2([' (ACL)', 0])],
  2415. data = '''
  2416. <form method="post">
  2417. ''' + data + '''
  2418. <hr>
  2419. <button type="submit" ''' + check_ok + '''>ACL ''' + load_lang('edit') + '''</button>
  2420. </form>
  2421. ''',
  2422. menu = [['w/' + url_pas(name), load_lang('document')], ['manager', load_lang('admin')]]
  2423. ))
  2424. @app.route('/admin/<name>', methods=['POST', 'GET'])
  2425. def user_admin(name = None):
  2426. owner = admin_check(None, None)
  2427. curs.execute("select acl from user where id = ?", [name])
  2428. user = curs.fetchall()
  2429. if not user:
  2430. return re_error('/error/2')
  2431. else:
  2432. if owner != 1:
  2433. curs.execute('select name from alist where name = ? and acl = "owner"', [user[0][0]])
  2434. if curs.fetchall():
  2435. return re_error('/error/3')
  2436. if ip_check() == name:
  2437. return re_error('/error/3')
  2438. if flask.request.method == 'POST':
  2439. if admin_check(7, 'admin (' + name + ')') != 1:
  2440. return re_error('/error/3')
  2441. if owner != 1:
  2442. curs.execute('select name from alist where name = ? and acl = "owner"', [flask.request.form.get('select', None)])
  2443. if curs.fetchall():
  2444. return re_error('/error/3')
  2445. if flask.request.form.get('select', None) == 'X':
  2446. curs.execute("update user set acl = 'user' where id = ?", [name])
  2447. else:
  2448. curs.execute("update user set acl = ? where id = ?", [flask.request.form.get('select', None), name])
  2449. conn.commit()
  2450. return redirect('/admin/' + url_pas(name))
  2451. else:
  2452. if admin_check(7, None) != 1:
  2453. return re_error('/error/3')
  2454. div = '<option value="X">X</option>'
  2455. i = 0
  2456. name_rem = ''
  2457. curs.execute('select distinct name from alist order by name asc')
  2458. for data in curs.fetchall():
  2459. if user[0][0] == data[0]:
  2460. div += '<option value="' + data[0] + '" selected="selected">' + data[0] + '</option>'
  2461. else:
  2462. if owner != 1:
  2463. curs.execute('select name from alist where name = ? and acl = "owner"', [data[0]])
  2464. if not curs.fetchall():
  2465. div += '<option value="' + data[0] + '">' + data[0] + '</option>'
  2466. else:
  2467. div += '<option value="' + data[0] + '">' + data[0] + '</option>'
  2468. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2469. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('authority') + ')', 0])],
  2470. data = '''
  2471. <form method="post">
  2472. <select name="select">''' + div + '''</select>
  2473. <hr>
  2474. <button type="submit">''' + load_lang('edit') + '''</button>
  2475. </form>
  2476. ''',
  2477. menu = [['manager', load_lang('admin')]]
  2478. ))
  2479. @app.route('/diff/<everything:name>')
  2480. def diff_data(name = None):
  2481. first = flask.request.args.get('first', '1')
  2482. second = flask.request.args.get('second', '1')
  2483. curs.execute("select data from history where id = ? and title = ?", [first, name])
  2484. first_raw_data = curs.fetchall()
  2485. if first_raw_data:
  2486. curs.execute("select data from history where id = ? and title = ?", [second, name])
  2487. second_raw_data = curs.fetchall()
  2488. if second_raw_data:
  2489. first_data = html.escape(first_raw_data[0][0])
  2490. second_data = html.escape(second_raw_data[0][0])
  2491. if first == second:
  2492. result = 'Same.'
  2493. else:
  2494. diff_data = difflib.SequenceMatcher(None, first_data, second_data)
  2495. result = re.sub('\r', '', diff(diff_data))
  2496. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2497. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('compare') + ')', 0])],
  2498. data = '<pre>' + result + '</pre>',
  2499. menu = [['history/' + url_pas(name), load_lang('history')]]
  2500. ))
  2501. return redirect('/history/' + url_pas(name))
  2502. @app.route('/down/<everything:name>')
  2503. def down(name = None):
  2504. div = '<ul>'
  2505. curs.execute("select title from data where title like ?", ['%' + name + '/%'])
  2506. for data in curs.fetchall():
  2507. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  2508. div += '</ul>'
  2509. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2510. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('under') + ')', 0])],
  2511. data = div,
  2512. menu = [['w/' + url_pas(name), load_lang('document')]]
  2513. ))
  2514. @app.route('/w/<everything:name>')
  2515. def read_view(name = None):
  2516. data_none = 0
  2517. sub = ''
  2518. acl = ''
  2519. div = ''
  2520. num = flask.request.args.get('num', None)
  2521. if num:
  2522. num = int(num)
  2523. curs.execute("select sub from rd where title = ? order by date desc", [name])
  2524. for data in curs.fetchall():
  2525. curs.execute("select title from stop where title = ? and sub = ? and close = 'O'", [name, data[0]])
  2526. if not curs.fetchall():
  2527. sub += ' (' + load_lang('discussion') + ')'
  2528. break
  2529. curs.execute("select title from data where title like ?", ['%' + name + '/%'])
  2530. if curs.fetchall():
  2531. down = 1
  2532. else:
  2533. down = 0
  2534. m = re.search("^(.*)\/(.*)$", name)
  2535. if m:
  2536. uppage = m.groups()[0]
  2537. else:
  2538. uppage = 0
  2539. if admin_check(5, None) == 1:
  2540. admin_memu = 1
  2541. else:
  2542. admin_memu = 0
  2543. if re.search('^category:', name):
  2544. curs.execute("select link from back where title = ? and type = 'cat' order by link asc", [name])
  2545. back = curs.fetchall()
  2546. if back:
  2547. div = '<br><h2 id="cate_normal">' + load_lang('category') + '</h2><ul>'
  2548. u_div = ''
  2549. i = 0
  2550. for data in back:
  2551. if re.search('^category:', data[0]):
  2552. u_div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  2553. elif re.search('^' + load_lang('template', 1) + ':', data[0]):
  2554. curs.execute("select data from data where title = ?", [data[0]])
  2555. db_data = curs.fetchall()
  2556. if db_data:
  2557. if re.search('\[\[' + name + '#include]]', db_data[0][0]):
  2558. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> <a href="/xref/' + url_pas(data[0]) + '">(' + load_lang('backlink') + ')</a></li>'
  2559. else:
  2560. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  2561. else:
  2562. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  2563. else:
  2564. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  2565. div += '</ul>'
  2566. if div == '<br><h2 id="cate_normal">' + load_lang('category') + '</h2><ul></ul>':
  2567. div = ''
  2568. if u_div != '':
  2569. div += '<br><h2 id="cate_under">' + load_lang('under') + ' ' + load_lang('category') + '</h2><ul>' + u_div + '</ul>'
  2570. if num:
  2571. curs.execute("select title from history where title = ? and id = ? and hide = 'O'", [name, str(num)])
  2572. if curs.fetchall() and admin_check(6, None) != 1:
  2573. return redirect('/history/' + url_pas(name))
  2574. curs.execute("select title, data from history where title = ? and id = ?", [name, str(num)])
  2575. else:
  2576. curs.execute("select title, data from data where title = ?", [name])
  2577. data = curs.fetchall()
  2578. if data:
  2579. else_data = data[0][1]
  2580. response_data = 200
  2581. else:
  2582. data_none = 1
  2583. response_data = 404
  2584. else_data = ''
  2585. m = re.search("^user:([^/]*)", name)
  2586. if m:
  2587. g = m.groups()
  2588. curs.execute("select acl from user where id = ?", [g[0]])
  2589. test = curs.fetchall()
  2590. if test and test[0][0] != 'user':
  2591. acl = ' (' + load_lang('admin') + ')'
  2592. else:
  2593. curs.execute("select block from ban where block = ?", [g[0]])
  2594. if curs.fetchall():
  2595. sub += ' (' + load_lang('ban') + ')'
  2596. else:
  2597. acl = ''
  2598. curs.execute("select dec from acl where title = ?", [name])
  2599. data = curs.fetchall()
  2600. if data:
  2601. acl += ' (ACL)'
  2602. if flask.request.args.get('froms', None):
  2603. else_data = re.sub('\r\n#(?:redirect|넘겨주기) (?P<in>(?:(?!\r\n).)+)\r\n', ' * Redirect to [[\g<in>]]', '\r\n' + else_data + '\r\n')
  2604. else_data = re.sub('^\r\n', '', else_data)
  2605. else_data = re.sub('\r\n$', '', else_data)
  2606. end_data = namumark(
  2607. title = name,
  2608. data = else_data
  2609. )
  2610. if num:
  2611. menu = [['history/' + url_pas(name), load_lang('history')]]
  2612. sub = ' (' + str(num) + load_lang('version') + ')'
  2613. acl = ''
  2614. r_date = 0
  2615. else:
  2616. if data_none == 1:
  2617. menu = [['edit/' + url_pas(name), load_lang('create')]]
  2618. else:
  2619. menu = [['edit/' + url_pas(name), load_lang('edit')]]
  2620. menu += [['topic/' + url_pas(name), load_lang('discussion')], ['history/' + url_pas(name), load_lang('history')], ['xref/' + url_pas(name), load_lang('backlink')], ['acl/' + url_pas(name), 'ACL']]
  2621. if flask.request.args.get('froms', None):
  2622. menu += [['w/' + url_pas(name), load_lang('pass')]]
  2623. end_data = '<ul id="redirect"><li>Redirect from <a href="/w/' + url_pas(flask.request.args.get('froms', None)) + '?froms=' + url_pas(name) + '">' + flask.request.args.get('froms', None) + '</a></li></ul><br>' + end_data
  2624. if uppage != 0:
  2625. menu += [['w/' + url_pas(uppage), load_lang('upper')]]
  2626. if down:
  2627. menu += [['down/' + url_pas(name), load_lang('under')]]
  2628. curs.execute("select date from history where title = ? order by date desc limit 1", [name])
  2629. date = curs.fetchall()
  2630. if date:
  2631. r_date = date[0][0]
  2632. else:
  2633. r_date = 0
  2634. div = end_data + div
  2635. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2636. imp = [flask.request.args.get('show', name), wiki_set(), custom(), other2([sub + acl, r_date])],
  2637. data = div,
  2638. menu = menu
  2639. )), response_data
  2640. @app.route('/topic_record/<name>')
  2641. def user_topic_list(name = None):
  2642. num = int(flask.request.args.get('num', 1))
  2643. if num * 50 > 0:
  2644. sql_num = num * 50 - 50
  2645. else:
  2646. sql_num = 0
  2647. one_admin = admin_check(1, None)
  2648. div = '<table style="width: 100%; text-align: center;"><tbody><tr>'
  2649. div += '<td style="width: 33.3%;">' + load_lang('discussion') + ' ' + load_lang('name') + '</td><td style="width: 33.3%;">' + load_lang('writer') + '</td><td style="width: 33.3%;">' + load_lang('time') + '</td></tr>'
  2650. curs.execute("select title, id, sub, ip, date from topic where ip = ? order by date desc limit ?, '50'", [name, str(sql_num)])
  2651. data_list = curs.fetchall()
  2652. for data in data_list:
  2653. title = html.escape(data[0])
  2654. sub = html.escape(data[2])
  2655. if one_admin == 1:
  2656. curs.execute("select * from ban where block = ?", [data[3]])
  2657. if curs.fetchall():
  2658. ban = ' <a href="/ban/' + url_pas(data[3]) + '">(' + load_lang('release') + ')</a>'
  2659. else:
  2660. ban = ' <a href="/ban/' + url_pas(data[3]) + '">(' + load_lang('ban') + ')</a>'
  2661. else:
  2662. ban = ''
  2663. div += '<tr><td><a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[2]) + '#' + data[1] + '">' + title + '#' + data[1] + '</a> (' + sub + ')</td>'
  2664. div += '<td>' + ip_pas(data[3]) + ban + '</td><td>' + data[4] + '</td></tr>'
  2665. div += '</tbody></table>'
  2666. div += next_fix('/topic_record/' + url_pas(name) + '?num=', num, data_list)
  2667. curs.execute("select end from ban where block = ?", [name])
  2668. if curs.fetchall():
  2669. sub = ' (' + load_lang('ban') + ')'
  2670. else:
  2671. sub = 0
  2672. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2673. imp = [load_lang('discussion') + ' ' + load_lang('record'), wiki_set(), custom(), other2([sub, 0])],
  2674. data = div,
  2675. menu = [['other', load_lang('other')], ['user', load_lang('user')], ['count/' + url_pas(name), load_lang('count')], ['record/' + url_pas(name), load_lang('record')]]
  2676. ))
  2677. @app.route('/recent_changes')
  2678. @app.route('/<regex("record"):tool>/<name>')
  2679. @app.route('/<regex("history"):tool>/<everything:name>', methods=['POST', 'GET'])
  2680. def recent_changes(name = None, tool = 'record'):
  2681. if flask.request.method == 'POST':
  2682. return redirect('/diff/' + url_pas(name) + '?first=' + flask.request.form.get('b', None) + '&second=' + flask.request.form.get('a', None))
  2683. else:
  2684. one_admin = admin_check(1, None)
  2685. six_admin = admin_check(6, None)
  2686. ban = ''
  2687. select = ''
  2688. what = flask.request.args.get('what', 'all')
  2689. div = '<table style="width: 100%; text-align: center;"><tbody><tr>'
  2690. if name:
  2691. num = int(flask.request.args.get('num', 1))
  2692. if num * 50 > 0:
  2693. sql_num = num * 50 - 50
  2694. else:
  2695. sql_num = 0
  2696. if tool == 'history':
  2697. div += '<td style="width: 33.3%;">' + load_lang('version') + '</td><td style="width: 33.3%;">' + load_lang('editor') + '</td><td style="width: 33.3%;">' + load_lang('time') + '</td></tr>'
  2698. curs.execute("select id, title, date, ip, send, leng from history where title = ? order by id + 0 desc limit ?, '50'", [name, str(sql_num)])
  2699. else:
  2700. div += '<td style="width: 33.3%;">' + load_lang('document') + ' ' + load_lang('name') + '</td><td style="width: 33.3%;">' + load_lang('editor') + '</td><td style="width: 33.3%;">' + load_lang('time') + '</td></tr>'
  2701. if what == 'all':
  2702. div = '<a href="/record/' + url_pas(name) + '?what=revert">(' + load_lang('revert') + ')</a><hr>' + div
  2703. div = '<a href="/record/' + url_pas(name) + '?what=move">(' + load_lang('move') + ')</a> ' + div
  2704. div = '<a href="/record/' + url_pas(name) + '?what=delete">(' + load_lang('delete') + ')</a> ' + div
  2705. curs.execute("select id, title, date, ip, send, leng from history where ip = ? order by date desc limit ?, '50'", [name, str(sql_num)])
  2706. else:
  2707. if what == 'delete':
  2708. sql = '%(' + load_lang('delete', 1) + ')'
  2709. elif what == 'move':
  2710. sql = '%' + load_lang('move', 1) + ')'
  2711. elif what == 'revert':
  2712. sql = '%' + load_lang('version', 1) + ')'
  2713. else:
  2714. return redirect('/')
  2715. curs.execute("select id, title, date, ip, send, leng from history where ip = ? and send like ? order by date desc limit ?, 50", [name, sql, str(sql_num)])
  2716. else:
  2717. num = int(flask.request.args.get('num', 1))
  2718. if num * 50 > 0:
  2719. sql_num = num * 50 - 50
  2720. else:
  2721. sql_num = 0
  2722. div += '<td style="width: 33.3%;">' + load_lang('document') + ' ' + load_lang('name') + '</td><td style="width: 33.3%;">' + load_lang('editor') + '</td><td style="width: 33.3%;">' + load_lang('time') + '</td></tr>'
  2723. if what == 'all':
  2724. div = '<a href="/recent_changes?what=revert">(' + load_lang('revert') + ')</a><hr>' + div
  2725. div = '<a href="/recent_changes?what=move">(' + load_lang('move') + ')</a> ' + div
  2726. div = '<a href="/recent_changes?what=delete">(' + load_lang('delete') + ')</a> ' + div
  2727. div = '<a href="/recent_discuss">(' + load_lang('discussion') + ')</a> <a href="/block_log">(' + load_lang('ban') + ')</a> <a href="/user_log">(' + load_lang('subscriber') + ')</a> <a href="/admin_log">(' + load_lang('authority') + ')</a><hr>' + div
  2728. curs.execute("select id, title, date, ip, send, leng from history order by date desc limit ?, 50", [str(sql_num)])
  2729. else:
  2730. if what == 'delete':
  2731. sql = '%(' + load_lang('delete', 1) + ')'
  2732. elif what == 'move':
  2733. sql = '%' + load_lang('move', 1) + ')'
  2734. elif what == 'revert':
  2735. sql = '%' + load_lang('version', 1) + ')'
  2736. else:
  2737. return redirect('/')
  2738. curs.execute("select id, title, date, ip, send, leng from history where send like ? order by date desc limit ?, 50", [sql, str(sql_num)])
  2739. data_list = curs.fetchall()
  2740. for data in data_list:
  2741. select += '<option value="' + data[0] + '">' + data[0] + '</option>'
  2742. send = '<br>'
  2743. if data[4]:
  2744. if not re.search("^(?: *)$", data[4]):
  2745. send = data[4]
  2746. if re.search("\+", data[5]):
  2747. leng = '<span style="color:green;">(' + data[5] + ')</span>'
  2748. elif re.search("\-", data[5]):
  2749. leng = '<span style="color:red;">(' + data[5] + ')</span>'
  2750. else:
  2751. leng = '<span style="color:gray;">(' + data[5] + ')</span>'
  2752. if one_admin == 1:
  2753. curs.execute("select * from ban where block = ?", [data[3]])
  2754. if curs.fetchall():
  2755. ban = ' <a href="/ban/' + url_pas(data[3]) + '">(' + load_lang('release') + ')</a>'
  2756. else:
  2757. ban = ' <a href="/ban/' + url_pas(data[3]) + '">(' + load_lang('ban') + ')</a>'
  2758. ip = ip_pas(data[3])
  2759. if int(data[0]) - 1 == 0:
  2760. revert = ''
  2761. else:
  2762. revert = '<a href="/diff/' + url_pas(data[1]) + '?first=' + str(int(data[0]) - 1) + '&second=' + data[0] + '">(' + load_lang('compare') + ')</a> <a href="/revert/' + url_pas(data[1]) + '?num=' + str(int(data[0]) - 1) + '">(' + load_lang('revert') + ')</a>'
  2763. style = ['', '']
  2764. date = data[2]
  2765. curs.execute("select title from history where title = ? and id = ? and hide = 'O'", [data[1], data[0]])
  2766. hide = curs.fetchall()
  2767. if six_admin == 1:
  2768. if hide:
  2769. hidden = ' <a href="/hidden/' + url_pas(data[1]) + '?num=' + data[0] + '">(' + load_lang('release') + ')'
  2770. style[0] = 'background: gainsboro;'
  2771. style[1] = 'background: gainsboro;'
  2772. if send == '<br>':
  2773. send = '(' + load_lang('hide') + ')'
  2774. else:
  2775. send += ' (' + load_lang('hide') + ')'
  2776. else:
  2777. hidden = ' <a href="/hidden/' + url_pas(data[1]) + '?num=' + data[0] + '">(' + load_lang('hide') + ')'
  2778. elif not hide:
  2779. hidden = ''
  2780. else:
  2781. ip = ''
  2782. hidden = ''
  2783. ban = ''
  2784. date = ''
  2785. send = '(' + load_lang('hide') + ')'
  2786. style[0] = 'display: none;'
  2787. style[1] = 'background: gainsboro;'
  2788. if tool == 'history':
  2789. title = '<a href="/w/' + url_pas(name) + '?num=' + data[0] + '">' + data[0] + load_lang('version') + '</a> <a href="/raw/' + url_pas(name) + '?num=' + data[0] + '">(' + load_lang('raw') + ')</a> '
  2790. else:
  2791. title = '<a href="/w/' + url_pas(data[1]) + '">' + html.escape(data[1]) + '</a> <a href="/history/' + url_pas(data[1]) + '">(' + data[0] + load_lang('version') + ')</a> '
  2792. div += '<tr style="' + style[0] + '"><td>' + title + revert + ' ' + leng + '</td>'
  2793. div += '<td>' + ip + ban + hidden + '</td><td>' + date + '</td></tr><tr style="' + style[1] + '"><td colspan="3">' + send_parser(send) + '</td></tr>'
  2794. div += '</tbody></table>'
  2795. sub = ''
  2796. if name:
  2797. if tool == 'history':
  2798. div = '<form method="post"><select name="a">' + select + '</select> <select name="b">' + select + '</select> <button type="submit">' + load_lang('compare') + '</button></form><hr>' + div
  2799. title = name
  2800. sub += ' (' + load_lang('history') + ')'
  2801. menu = [['w/' + url_pas(name), load_lang('document')], ['raw/' + url_pas(name), 'Raw'], ['move_data/' + url_pas(name), load_lang('move') + ' ' + load_lang('history')]]
  2802. div += next_fix('/history/' + url_pas(name) + '?num=', num, data_list)
  2803. else:
  2804. curs.execute("select end from ban where block = ?", [name])
  2805. if curs.fetchall():
  2806. sub += ' (' + load_lang('ban') + ')'
  2807. title = load_lang('edit') + ' ' + load_lang('record')
  2808. menu = [['other', load_lang('other')], ['user', load_lang('user')], ['count/' + url_pas(name), load_lang('count')], ['topic_record/' + url_pas(name), load_lang('discussion')]]
  2809. div += next_fix('/record/' + url_pas(name) + '/' + url_pas(what) + '?num=', num, data_list)
  2810. if what != 'all':
  2811. menu += [['record/' + url_pas(name), load_lang('normal')]]
  2812. else:
  2813. menu = 0
  2814. title = load_lang('recent') + ' ' + load_lang('change') + ''
  2815. if what != 'all':
  2816. menu = [['recent_changes', load_lang('normal')]]
  2817. div += next_fix('/recent_changes?num=', num, data_list)
  2818. if what == 'delete':
  2819. sub += ' (' + load_lang('delete') + ')'
  2820. elif what == 'move':
  2821. sub += ' (' + load_lang('move') + ')'
  2822. elif what == 'revert':
  2823. sub += ' (' + load_lang('revert') + ')'
  2824. if sub == '':
  2825. sub = 0
  2826. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2827. imp = [title, wiki_set(), custom(), other2([sub, 0])],
  2828. data = div,
  2829. menu = menu
  2830. ))
  2831. @app.route('/upload', methods=['GET', 'POST'])
  2832. def upload():
  2833. if ban_check() == 1:
  2834. return re_error('/ban')
  2835. if flask.request.method == 'POST':
  2836. if captcha_post(flask.request.form.get('g-recaptcha-response', None)) == 1:
  2837. return re_error('/error/13')
  2838. else:
  2839. captcha_post('', 0)
  2840. data = flask.request.files.get('f_data', None)
  2841. if not data:
  2842. return re_error('/error/9')
  2843. if int(wiki_set(3)) * 1024 * 1024 < flask.request.content_length:
  2844. return re_error('/error/17')
  2845. value = os.path.splitext(data.filename)[1]
  2846. if not value in ['.jpeg', '.jpg', '.gif', '.png', '.webp', '.JPEG', '.JPG', '.GIF', '.PNG', '.WEBP']:
  2847. return re_error('/error/14')
  2848. if flask.request.form.get('f_name', None):
  2849. name = flask.request.form.get('f_name', None) + value
  2850. else:
  2851. name = data.filename
  2852. piece = os.path.splitext(name)
  2853. if re.search('[^ㄱ-힣0-9a-zA-Z_\- ]', piece[0]):
  2854. return re_error('/error/22')
  2855. e_data = sha224(piece[0]) + piece[1]
  2856. curs.execute("select title from data where title = ?", ['file:' + name])
  2857. if curs.fetchall():
  2858. return re_error('/error/16')
  2859. ip = ip_check()
  2860. if flask.request.form.get('f_lice', None):
  2861. lice = flask.request.form.get('f_lice', None)
  2862. else:
  2863. if custom()[2] == 0:
  2864. lice = ip + ' Upload'
  2865. else:
  2866. lice = '[[user:' + ip + ']] Upload'
  2867. if os.path.exists(os.path.join('image', e_data)):
  2868. os.remove(os.path.join('image', e_data))
  2869. data.save(os.path.join('image', e_data))
  2870. else:
  2871. data.save(os.path.join('image', e_data))
  2872. curs.execute("select title from data where title = ?", ['file:' + name])
  2873. if curs.fetchall():
  2874. curs.execute("delete from data where title = ?", ['file:' + name])
  2875. curs.execute("insert into data (title, data) values (?, ?)", ['file:' + name, '[[file:' + name + ']][br][br]{{{[[file:' + name + ']]}}}[br][br]' + lice])
  2876. curs.execute("insert into acl (title, dec, dis, why) values (?, 'admin', '', '')", ['file:' + name])
  2877. history_plus('file:' + name, '[[file:' + name + ']][br][br]{{{[[file:' + name + ']]}}}[br][br]' + lice, get_time(), ip, '(Upload)', '0')
  2878. conn.commit()
  2879. return redirect('/w/file:' + name)
  2880. else:
  2881. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2882. imp = [load_lang('upload'), wiki_set(), custom(), other2([0, 0])],
  2883. data = '''
  2884. <form method="post" enctype="multipart/form-data" accept-charset="utf8">
  2885. <input type="file" name="f_data">
  2886. <hr>
  2887. <input placeholder="''' + load_lang('name') + '''" name="f_name" type="text">
  2888. <hr>
  2889. <input placeholder="''' + load_lang('license') + '''" name="f_lice" type="text">
  2890. <hr>
  2891. ''' + captcha_get() + '''
  2892. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  2893. </form>
  2894. ''',
  2895. menu = [['other', load_lang('other')]]
  2896. ))
  2897. @app.route('/user')
  2898. def user_info():
  2899. ip = ip_check()
  2900. curs.execute("select acl from user where id = ?", [ip])
  2901. data = curs.fetchall()
  2902. if ban_check() == 0:
  2903. if data:
  2904. if data[0][0] != 'user':
  2905. acl = data[0][0]
  2906. else:
  2907. acl = load_lang('subscriber')
  2908. else:
  2909. acl = load_lang('normal')
  2910. else:
  2911. acl = load_lang('ban')
  2912. match = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
  2913. if match:
  2914. match = match.groups()[0]
  2915. else:
  2916. match = 'Error'
  2917. curs.execute("select end, login, band from ban where block = ? or block = ?", [ip, match])
  2918. block_data = curs.fetchall()
  2919. if block_data:
  2920. if block_data[0][0] != '':
  2921. acl += ' (End : ' + block_data[0][0] + ')'
  2922. else:
  2923. acl += ' (End : ' + load_lang('limitless') + ')'
  2924. if block_data[0][1] != '':
  2925. acl += ' (' + load_lang('login') + ' ' + load_lang('able') + ')'
  2926. if block_data[0][2] == 'O':
  2927. acl += ' (' + load_lang('band') + ')'
  2928. if custom()[2] != 0:
  2929. ip_user = '<a href="/w/user:' + ip + '">' + ip + '</a>'
  2930. plus = '<li><a href="/logout">' + load_lang('logout') + '</a></li><li><a href="/change">' + load_lang('user') + ' ' + load_lang('setting') + ' ' + load_lang('edit') + '</a></li>'
  2931. curs.execute('select name from alarm where name = ? limit 1', [ip_check()])
  2932. if curs.fetchall():
  2933. plus2 = '<li><a href="/alarm">' + load_lang('alarm') + ' (O)</a></li>'
  2934. else:
  2935. plus2 = '<li><a href="/alarm">' + load_lang('alarm') + '</a></li>'
  2936. plus2 += '<li><a href="/watch_list">' + load_lang('watchlist') + '</a></li>'
  2937. else:
  2938. ip_user = ip
  2939. plus = '<li><a href="/login">' + load_lang('login') + '</a></li><li><a href="/register">' + load_lang('register') + '</a></li>'
  2940. plus2 = ''
  2941. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2942. imp = [load_lang('user') + ' ' + load_lang('tool'), wiki_set(), custom(), other2([0, 0])],
  2943. data = '''
  2944. <h2>''' + load_lang('state') + '''</h2>
  2945. <ul>
  2946. <li>''' + ip_user + ''' <a href="/record/''' + url_pas(ip) + '''">(''' + load_lang('record') + ''')</a></li><li>''' + load_lang('authority') + ''' : ''' + acl + '''</li>
  2947. </ul>
  2948. <br>
  2949. <h2>''' + load_lang('login') + '''</h2>
  2950. <ul>
  2951. ''' + plus + '''
  2952. </ul>
  2953. <br>
  2954. <h2>''' + load_lang('tool') + '''</h2>
  2955. <ul>
  2956. <li><a href="/acl/user:''' + url_pas(ip) + '">' + load_lang('user') + ' ' + load_lang('document') + ''' ACL</a></li>
  2957. <li><a href="/custom_head">''' + load_lang('user') + ''' HEAD</a></li></ul><br><h2>''' + load_lang('other') + '''</h2><ul>''' + plus2 + '''<li><a href="/count">''' + load_lang('count') + '''</a></li>
  2958. </ul>
  2959. ''',
  2960. menu = 0
  2961. ))
  2962. @app.route('/watch_list')
  2963. def watch_list():
  2964. div = 'Limit : 10<hr>'
  2965. if custom()[2] == 0:
  2966. return redirect('/login')
  2967. curs.execute("select title from scan where user = ?", [ip_check()])
  2968. data = curs.fetchall()
  2969. for data_list in data:
  2970. div += '<li><a href="/w/' + url_pas(data_list[0]) + '">' + data_list[0] + '</a> <a href="/watch_list/' + url_pas(data_list[0]) + '">(' + load_lang('delete') + ')</a></li>'
  2971. if data:
  2972. div = '<ul>' + div + '</ul><hr>'
  2973. div += '<a href="/manager/13">(' + load_lang('plus') + ')</a>'
  2974. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  2975. imp = [load_lang('watchlist') + ' ' + load_lang('list'), wiki_set(), custom(), other2([0, 0])],
  2976. data = div,
  2977. menu = [['manager', load_lang('admin')]]
  2978. ))
  2979. @app.route('/watch_list/<everything:name>')
  2980. def watch_list_name(name = None):
  2981. if custom()[2] == 0:
  2982. return redirect('/login')
  2983. ip = ip_check()
  2984. curs.execute("select count(title) from scan where user = ?", [ip])
  2985. count = curs.fetchall()
  2986. if count and count[0][0] > 9:
  2987. return redirect('/watch_list')
  2988. curs.execute("select title from scan where user = ? and title = ?", [ip, name])
  2989. if curs.fetchall():
  2990. curs.execute("delete from scan where user = ? and title = ?", [ip, name])
  2991. else:
  2992. curs.execute("insert into scan (user, title) values (?, ?)", [ip, name])
  2993. conn.commit()
  2994. return redirect('/watch_list')
  2995. @app.route('/custom_head', methods=['GET', 'POST'])
  2996. def custom_head_view():
  2997. ip = ip_check()
  2998. if flask.request.method == 'POST':
  2999. if custom()[2] != 0:
  3000. curs.execute("select user from custom where user = ?", [ip + ' (head)'])
  3001. if curs.fetchall():
  3002. curs.execute("update custom set css = ? where user = ?", [flask.request.form.get('content', None), ip + ' (head)'])
  3003. else:
  3004. curs.execute("insert into custom (user, css) values (?, ?)", [ip + ' (head)', flask.request.form.get('content', None)])
  3005. conn.commit()
  3006. flask.session['MyMaiToNight'] = flask.request.form.get('content', None)
  3007. return redirect('/user')
  3008. else:
  3009. if custom()[2] != 0:
  3010. start = ''
  3011. curs.execute("select css from custom where user = ?", [ip + ' (head)'])
  3012. head_data = curs.fetchall()
  3013. if head_data:
  3014. data = head_data[0][0]
  3015. else:
  3016. data = ''
  3017. else:
  3018. start = '<span>' + load_lang('user_head_warring') + '</span><hr>'
  3019. if 'MyMaiToNight' in flask.session:
  3020. data = flask.session['MyMaiToNight']
  3021. else:
  3022. data = ''
  3023. start += '<span>&lt;style&gt;CSS&lt;/style&gt;<br>&lt;script&gt;JS&lt;/script&gt;</span><hr>'
  3024. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  3025. imp = [load_lang('user') + ' HEAD', wiki_set(), custom(), other2([0, 0])],
  3026. data = start + '''
  3027. <form method="post">
  3028. <textarea rows="25" cols="100" name="content">''' + data + '''</textarea>
  3029. <hr>
  3030. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  3031. </form>
  3032. ''',
  3033. menu = [['user', load_lang('user')]]
  3034. ))
  3035. @app.route('/count')
  3036. @app.route('/count/<name>')
  3037. def count_edit(name = None):
  3038. if name == None:
  3039. that = ip_check()
  3040. else:
  3041. that = name
  3042. curs.execute("select count(title) from history where ip = ?", [that])
  3043. count = curs.fetchall()
  3044. if count:
  3045. data = count[0][0]
  3046. else:
  3047. data = 0
  3048. curs.execute("select count(title) from topic where ip = ?", [that])
  3049. count = curs.fetchall()
  3050. if count:
  3051. t_data = count[0][0]
  3052. else:
  3053. t_data = 0
  3054. return css_html_js_minify.html_minify(flask.render_template(skin_check(),
  3055. imp = [load_lang('count'), wiki_set(), custom(), other2([0, 0])],
  3056. data = '''
  3057. <ul>
  3058. <li><a href="/record/''' + url_pas(that) + '''">''' + load_lang('edit') + '''</a> : ''' + str(data) + '''</li>
  3059. <li><a href="/topic_record/''' + url_pas(that) + '''">''' + load_lang('discussion') + '''</a> : ''' + str(t_data) + '''</a></li>
  3060. </ul>
  3061. ''',
  3062. menu = [['user', load_lang('user')]]
  3063. ))
  3064. @app.route('/random')
  3065. def random():
  3066. curs.execute("select title from data order by random() limit 1")
  3067. data = curs.fetchall()
  3068. if data:
  3069. return redirect('/w/' + url_pas(data[0][0]))
  3070. else:
  3071. return redirect('/')
  3072. @app.route('/skin_set')
  3073. def skin_set():
  3074. return re_error('/error/5')
  3075. @app.route('/api/w/<everything:name>')
  3076. def api_w(name = None):
  3077. curs.execute("select data from data where title = ?", [name])
  3078. data = curs.fetchall()
  3079. if data:
  3080. json_data = { "title" : name, "data" : namumark(data = data[0][0]) }
  3081. return flask.jsonify(json_data)
  3082. else:
  3083. return redirect('/')
  3084. @app.route('/api/raw/<everything:name>')
  3085. def api_raw(name = None):
  3086. curs.execute("select data from data where title = ?", [name])
  3087. data = curs.fetchall()
  3088. if data:
  3089. json_data = { "title" : name, "data" : data[0][0] }
  3090. return flask.jsonify(json_data)
  3091. else:
  3092. return redirect('/')
  3093. @app.route('/views/<everything:name>')
  3094. def views(name = None):
  3095. if re.search('\/', name):
  3096. m = re.search('^(.*)\/(.*)$', name)
  3097. if m:
  3098. n = m.groups()
  3099. plus = '/' + n[0]
  3100. rename = n[1]
  3101. else:
  3102. plus = ''
  3103. rename = name
  3104. else:
  3105. plus = ''
  3106. rename = name
  3107. m = re.search('\.(.+)$', name)
  3108. if m:
  3109. g = m.groups()
  3110. else:
  3111. g = ['']
  3112. if g == 'css':
  3113. return css_html_js_minify.css_minify(flask.send_from_directory('./views' + plus, rename))
  3114. elif g == 'js':
  3115. return css_html_js_minify.js_minify(flask.send_from_directory('./views' + plus, rename))
  3116. elif g == 'html':
  3117. return css_html_js_minify.html_minify(flask.send_from_directory('./views' + plus, rename))
  3118. else:
  3119. return flask.send_from_directory('./views' + plus, rename)
  3120. @app.route('/<data>')
  3121. def main_file(data = None):
  3122. if re.search('\.(txt|html)$', data):
  3123. return flask.send_from_directory('./', data)
  3124. else:
  3125. return ''
  3126. @app.errorhandler(404)
  3127. def error_404(e):
  3128. return redirect('/w/' + url_pas(wiki_set(2)))
  3129. if __name__=="__main__":
  3130. app.secret_key = rep_key
  3131. http_server = tornado.httpserver.HTTPServer(tornado.wsgi.WSGIContainer(app))
  3132. http_server.listen(rep_port)
  3133. tornado.ioloop.IOLoop.instance().start()