2
0

list_user_check.py 8.7 KB

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