func.py 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. from bottle import request, app
  2. from bottle.ext import beaker
  3. import json
  4. import sqlite3
  5. json_data = open('set.json').read()
  6. set_data = json.loads(json_data)
  7. conn = sqlite3.connect(set_data['db'] + '.db')
  8. curs = conn.cursor()
  9. session_opts = {
  10. 'session.type': 'file',
  11. 'session.data_dir': './app_session/',
  12. 'session.auto': 1
  13. }
  14. app = beaker.middleware.SessionMiddleware(app(), session_opts)
  15. from mark import *
  16. def other2(d):
  17. return(d)
  18. def wiki_set(num):
  19. if(num == 1):
  20. r = []
  21. curs.execute('select data from other where name = ?', ['name'])
  22. d = curs.fetchall()
  23. if(d):
  24. r += [d[0][0]]
  25. else:
  26. r += ['무명위키']
  27. curs.execute('select data from other where name = "license"')
  28. d = curs.fetchall()
  29. if(d):
  30. r += [d[0][0]]
  31. else:
  32. r += ['CC 0']
  33. return(r)
  34. if(num == 2):
  35. d = '위키:대문'
  36. curs.execute('select data from other where name = "frontpage"')
  37. elif(num == 3):
  38. d = '2'
  39. curs.execute('select data from other where name = "upload"')
  40. r = curs.fetchall()
  41. if(r):
  42. return(r[0][0])
  43. else:
  44. return(d)
  45. def diff(seqm, num):
  46. output= []
  47. for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
  48. if(opcode == 'equal' and num == 1):
  49. output.append(seqm.a[a0:a1])
  50. elif(opcode == 'insert' and num == 0):
  51. output.append("<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>")
  52. elif(opcode == 'delete' and num == 1):
  53. output.append("<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>")
  54. elif(opcode == 'replace'):
  55. if(num == 1):
  56. output.append("<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>")
  57. else:
  58. output.append("<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>")
  59. elif(num == 0):
  60. output.append(seqm.b[b0:b1])
  61. return(''.join(output))
  62. def admin_check(num, what):
  63. ip = ip_check()
  64. curs.execute("select acl from user where id = ?", [ip])
  65. user = curs.fetchall()
  66. if(user):
  67. reset = 0
  68. while(1):
  69. if(num == 1 and reset == 0):
  70. check = 'ban'
  71. elif(num == 2 and reset == 0):
  72. check = 'mdel'
  73. elif(num == 3 and reset == 0):
  74. check = 'toron'
  75. elif(num == 4 and reset == 0):
  76. check = 'check'
  77. elif(num == 5 and reset == 0):
  78. check = 'acl'
  79. elif(num == 6 and reset == 0):
  80. check = 'hidel'
  81. else:
  82. check = 'owner'
  83. curs.execute('select name from alist where name = ? and acl = ?', [user[0][0], check])
  84. acl_data = curs.fetchall()
  85. if(acl_data):
  86. if(what):
  87. curs.execute("insert into re_admin (who, what, time) values (?, ?, ?)", [ip, what, get_time()])
  88. conn.commit()
  89. return(1)
  90. else:
  91. if(reset == 0):
  92. reset = 1
  93. else:
  94. break
  95. def include_check(name, data):
  96. if(re.search('^틀:', name)):
  97. curs.execute("select link from back where title = ? and type = 'include'", [name])
  98. back = curs.fetchall()
  99. for back_p in back:
  100. curs.execute("select data from data where title = ?", [back_p[0]])
  101. data = curs.fetchall()
  102. if(data):
  103. curs.execute("delete from back where link = ?", [back_p[0]])
  104. curs.execute("delete from cat where cat = ?", [back_p[0]])
  105. namumark(back_p[0], data[0][0], 1, 0, 0)
  106. def ip_pas(raw_ip):
  107. if(re.search("(\.|:)", raw_ip)):
  108. ip = raw_ip
  109. else:
  110. curs.execute("select title from data where title = ?", ['사용자:' + raw_ip])
  111. data = curs.fetchall()
  112. if(data):
  113. ip = '<a href="/w/' + url_pas('사용자:' + raw_ip) + '">' + raw_ip + '</a>'
  114. else:
  115. ip = '<a class="not_thing" href="/w/' + url_pas('사용자:' + raw_ip) + '">' + raw_ip + '</a>'
  116. ip += ' <a href="/record/' + url_pas(raw_ip) + '">(기록)</a>'
  117. return(ip)
  118. def custom():
  119. session = request.environ.get('beaker.session')
  120. try:
  121. d1 = format(session['Daydream'])
  122. except:
  123. d1 = ''
  124. try:
  125. d2 = format(session['AQUARIUM'])
  126. except:
  127. d2 = ''
  128. if(session.get('Now') == 1):
  129. curs.execute('select name from alarm limit 1')
  130. if(curs.fetchall()):
  131. d3 = 2
  132. else:
  133. d3 = 1
  134. else:
  135. d3 = 0
  136. return([d1, d2, d3])
  137. def acl_check(name):
  138. ip = ip_check()
  139. band = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
  140. if(band):
  141. band_it = band.groups()
  142. else:
  143. band_it = ['Not']
  144. curs.execute("select block from ban where block = ? and band = 'O'", [band_it[0]])
  145. band_d = curs.fetchall()
  146. curs.execute("select block from ban where block = ?", [ip])
  147. ban_d = curs.fetchall()
  148. if(band_d or ban_d):
  149. return(1)
  150. acl_c = re.search("^사용자:([^/]*)", name)
  151. if(acl_c):
  152. acl_n = acl_c.groups()
  153. if(admin_check(5, None) == 1):
  154. return(0)
  155. curs.execute("select acl from data where title = ?", ['사용자:' + acl_n[0]])
  156. acl_d = curs.fetchall()
  157. if(acl_d):
  158. if(acl_d[0][0] == 'all'):
  159. return(0)
  160. if(acl_d[0][0] == 'user' and not re.search("(\.|:)", ip)):
  161. return(0)
  162. if(not ip == acl_n[0] or re.search("(\.|:)", ip)):
  163. return(1)
  164. if(ip == acl_n[0] and not re.search("(\.|:)", ip) and not re.search("(\.|:)", acl_n[0])):
  165. return(0)
  166. else:
  167. return(1)
  168. file_c = re.search("^파일:(.*)", name)
  169. if(file_c and admin_check(5, 'edit (' + name + ')') != 1):
  170. return(1)
  171. curs.execute("select acl from data where title = ?", [name])
  172. acl_d = curs.fetchall()
  173. if(not acl_d):
  174. return(0)
  175. curs.execute("select acl from user where id = ?", [ip])
  176. user_d = curs.fetchall()
  177. curs.execute('select data from other where name = "edit"')
  178. set_d = curs.fetchall()
  179. if(acl_d[0][0] == 'user'):
  180. if(not user_d):
  181. return(1)
  182. if(acl_d[0][0] == 'admin'):
  183. if(not user_d):
  184. return(1)
  185. if(not admin_check(5, 'edit (' + name + ')') == 1):
  186. return(1)
  187. if(set_d):
  188. if(set_d[0][0] == 'user'):
  189. if(not user_d):
  190. return(1)
  191. if(set_d[0][0] == 'admin'):
  192. if(not user_d):
  193. return(1)
  194. if(not admin_check(5, None) == 1):
  195. return(1)
  196. return(0)
  197. def ban_check():
  198. ip = ip_check()
  199. band = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
  200. if(band):
  201. band_it = band.groups()
  202. else:
  203. band_it = ['Not']
  204. curs.execute("select block from ban where block = ? and band = 'O'", [band_it[0]])
  205. band_d = curs.fetchall()
  206. curs.execute("select block from ban where block = ?", [ip])
  207. ban_d = curs.fetchall()
  208. if(band_d or ban_d):
  209. return(1)
  210. return(0)
  211. def topic_check(name, sub):
  212. ip = ip_check()
  213. band = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
  214. if(band):
  215. band_it = band.groups()
  216. else:
  217. band_it = ['Not']
  218. curs.execute("select block from ban where block = ? and band = 'O'", [band_it[0]])
  219. band_d = curs.fetchall()
  220. curs.execute("select block from ban where block = ?", [ip])
  221. ban_d = curs.fetchall()
  222. if(band_d or ban_d):
  223. return(1)
  224. curs.execute("select title from stop where title = ? and sub = ?", [name, sub])
  225. topic_s = curs.fetchall()
  226. if(topic_s):
  227. return(1)
  228. return(0)
  229. def rd_plus(title, sub, date):
  230. curs.execute("select title from rd where title = ? and sub = ?", [title, sub])
  231. rd = curs.fetchall()
  232. if(rd):
  233. curs.execute("update rd set date = ? where title = ? and sub = ?", [date, title, sub])
  234. else:
  235. curs.execute("insert into rd (title, sub, date) values (?, ?, ?)", [title, sub, date])
  236. conn.commit()
  237. def rb_plus(block, end, today, blocker, why):
  238. curs.execute("insert into rb (block, end, today, blocker, why) values (?, ?, ?, ?, ?)", [block, end, today, blocker, why])
  239. conn.commit()
  240. def history_plus(title, data, date, ip, send, leng):
  241. curs.execute("select id from history where title = ? order by id+0 desc limit 1", [title])
  242. rows = curs.fetchall()
  243. if(rows):
  244. curs.execute("insert into history (id, title, data, date, ip, send, leng) values (?, ?, ?, ?, ?, ?, ?)", [str(int(rows[0][0]) + 1), title, data, date, ip, send, leng])
  245. else:
  246. curs.execute("insert into history (id, title, data, date, ip, send, leng) values ('1', ?, ?, ?, ?, ?, ?)", [title, data, date, ip, send + ' (새 문서)', leng])
  247. conn.commit()
  248. def leng_check(a, b):
  249. if(a < b):
  250. c = b - a
  251. c = '+' + str(c)
  252. elif(b < a):
  253. c = a - b
  254. c = '-' + str(c)
  255. else:
  256. c = '0'
  257. return(c)