list_user_check.py 8.5 KB

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