func.py 9.4 KB

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