give_user_check.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. from .tool.func import *
  2. def give_user_check_2(name):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. plus_id = flask.request.args.get('plus', None)
  6. if admin_check('all', None, name) == 1 or (plus_id and admin_check('all', None, plus_id) == 1):
  7. if admin_check() != 1:
  8. return re_error('/error/4')
  9. num = int(number_check(flask.request.args.get('num', '1')))
  10. sql_num = (num * 50 - 50) if num * 50 > 0 else 0
  11. div = ''
  12. check_type = flask.request.args.get('type', '')
  13. if admin_check(4, (check_type + ' ' if check_type != '' else '') + 'check (' + name + ')') != 1:
  14. return re_error('/error/3')
  15. if check_type == '':
  16. if ip_or_user(name) == 0:
  17. curs.execute(db_change("select data from user_set where name = \"approval_question\" and id = ?"), [name])
  18. approval_question = curs.fetchall()
  19. if approval_question and approval_question[0][0]:
  20. curs.execute(db_change("select data from user_set where name = \"approval_question_answer\" and id = ?"), [name])
  21. approval_question_answer = curs.fetchall()
  22. if approval_question_answer and approval_question_answer[0]:
  23. div += '''
  24. <table id="main_table_set">
  25. <tbody>
  26. <tr id="main_table_top_tr">
  27. <td>Q</td>
  28. <td>''' + approval_question[0][0] + '''</td>
  29. <td>A</td>
  30. <td>''' + approval_question_answer[0][0] + '''</td>
  31. </tr>
  32. </tbody>
  33. </table>
  34. <hr class="main_hr">
  35. '''
  36. if plus_id:
  37. plus = "or " + ('ip' if ip_or_user(plus_id) == 1 else 'name') + " = ? "
  38. set_list = [name, plus_id, sql_num]
  39. if num == 1:
  40. curs.execute(db_change("" + \
  41. "select distinct ip from ua_d " + \
  42. "where " + ('ip' if ip_or_user(name) == 1 else 'name') + " = ? or " + ('ip' if ip_or_user(plus_id) == 1 else 'name') + " = ? "
  43. ""), [name, plus_id])
  44. all_ip_count = len(curs.fetchall())
  45. curs.execute(db_change("" + \
  46. "select distinct ip from ua_d " + \
  47. "where " + ('ip' if ip_or_user(name) == 1 else 'name') + " = ?" + \
  48. ""), [name])
  49. a_ip_count = len(curs.fetchall())
  50. curs.execute(db_change("" + \
  51. "select distinct ip from ua_d " + \
  52. "where " + ('ip' if ip_or_user(plus_id) == 1 else 'name') + " = ? "
  53. ""), [plus_id])
  54. b_ip_count = len(curs.fetchall())
  55. if a_ip_count + b_ip_count != all_ip_count:
  56. div += load_lang('same_ip_exist') + '<hr class="main_hr">'
  57. else:
  58. plus = ''
  59. set_list = [name, sql_num]
  60. curs.execute(db_change("" + \
  61. "select name, ip, ua, today from ua_d " + \
  62. "where " + ('ip' if ip_or_user(name) == 1 else 'name') + " = ? " + \
  63. plus + \
  64. "order by today desc limit ?, 50" + \
  65. ""), set_list)
  66. record = curs.fetchall()
  67. if record:
  68. if not plus_id:
  69. div = '' + \
  70. '<a href="/manager/14?plus=' + url_pas(name) + '">(' + load_lang('compare') + ')</a> ' + \
  71. '<a href="/check/' + url_pas(name) + '?type=simple">(' + load_lang('simple_check') + ')</a>' + \
  72. '<hr class="main_hr">' + \
  73. '' + div
  74. else:
  75. div = '' + \
  76. '<a href="/check/' + url_pas(name) + '">(' + name + ')</a> ' + \
  77. '<a href="/check/' + url_pas(plus_id) + '">(' + plus_id + ')</a>' + \
  78. '<hr class="main_hr">' + \
  79. '' + div
  80. div += '''
  81. <table id="main_table_set">
  82. <tbody>
  83. <tr id="main_table_top_tr">
  84. <td id="main_table_width">''' + load_lang('name') + '''</td>
  85. <td id="main_table_width">''' + load_lang('ip') + '''</td>
  86. <td id="main_table_width">''' + load_lang('time') + '''</td>
  87. </tr>
  88. '''
  89. set_n = 0
  90. for data in record:
  91. if data[2]:
  92. if len(data[2]) > 300:
  93. ua = '' + \
  94. '<a href="javascript:void();" onclick="document.getElementById(\'check_' + str(set_n) + '\').style.display=\'block\';">(300+)</a>' + \
  95. '<div id="check_' + str(set_n) + '" style="display:none;">' + html.escape(data[2]) + '</div>' + \
  96. ''
  97. set_n += 1
  98. else:
  99. ua = html.escape(data[2])
  100. else:
  101. ua = '<br>'
  102. div += '''
  103. <tr>
  104. <td>
  105. <a href="/check/''' + url_pas(data[0]) + '''">''' + data[0] + '''</a>
  106. <a href="/check_delete''' + \
  107. '''?name=''' + url_pas(data[0]) + \
  108. '''&ip=''' + url_pas(data[1]) + \
  109. '''&time=''' + url_pas(data[3].replace(' ', '').replace(':', '').replace('-', '')) + \
  110. '''&return_type=''' + ('0' if ip_or_user(name) == 0 else '1') + '''">
  111. (''' + load_lang('delete') + ''')
  112. </a>
  113. </td>
  114. <td><a href="/check/''' + url_pas(data[1]) + '''">''' + data[1] + '''</a></td>
  115. <td>''' + data[3] + '''</td>
  116. </tr>
  117. <tr>
  118. <td colspan="3">''' + ua + '''</td>
  119. </tr>
  120. '''
  121. div += '''
  122. </tbody>
  123. </table>
  124. '''
  125. div += next_fix(
  126. '/check/' + url_pas(name) + ('?plus=' + plus_id + '&num=' if plus_id else '?num='),
  127. num,
  128. record
  129. )
  130. return easy_minify(flask.render_template(skin_check(),
  131. imp = [load_lang('check'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  132. data = div,
  133. menu = [['manager', load_lang('return')]]
  134. ))
  135. else:
  136. curs.execute(db_change("" + \
  137. "select distinct " + ('name' if ip_or_user(name) == 1 else 'ip') + " from ua_d " + \
  138. "where " + ('ip' if ip_or_user(name) == 1 else 'name') + " = ? "
  139. "order by today desc limit ?, 50" + \
  140. ""), [name, sql_num])
  141. record = curs.fetchall()
  142. div = ''
  143. for i in record:
  144. div += '<li><a href="/check/' + url_pas(i[0]) + '?type=simple">' + i[0] + '</a></li>'
  145. if div != '':
  146. div = '<ul class="opennamu_ul">' + div + '</ul>'
  147. div += next_fix(
  148. '/check/' + url_pas(name) + '?type=' + check_type + '&num=',
  149. num,
  150. record
  151. )
  152. return easy_minify(flask.render_template(skin_check(),
  153. imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('simple_check') + ')', 0])],
  154. data = div,
  155. menu = [['check/' + url_pas(name), load_lang('return')]]
  156. ))