func.py 8.8 KB

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