func.py 9.7 KB

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