emergency_tool.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. from route.tool.func import *
  2. from route.tool.mark import load_conn2, namumark
  3. try:
  4. set_data = json.loads(open('data/set.json').read())
  5. except:
  6. if os.getenv('NAMU_DB') != None:
  7. set_data = { "db" : os.getenv('NAMU_DB') }
  8. else:
  9. print('DB name (data) : ', end = '')
  10. new_json = str(input())
  11. if new_json == '':
  12. new_json = 'data'
  13. with open('data/set.json', 'w') as f:
  14. f.write('{ "db" : "' + new_json + '" }')
  15. set_data = json.loads(open('data/set.json').read())
  16. print('DB name : ' + set_data['db'])
  17. db_name = set_data['db']
  18. conn = sqlite3.connect(db_name + '.db', check_same_thread = False)
  19. curs = conn.cursor()
  20. load_conn(conn)
  21. print('----')
  22. print('1. Backlink reset')
  23. print('2. reCAPTCHA delete')
  24. print('3. Ban delete')
  25. print('4. Change host')
  26. print('5. Change port')
  27. print('6. Change skin')
  28. print('7. Change password')
  29. print('8. Reset version')
  30. print('9. Delete set.json')
  31. print('10. Change name')
  32. print('----')
  33. print('Select : ', end = '')
  34. what_i_do = input()
  35. if what_i_do == '1':
  36. def parser(data):
  37. namumark(data[0], data[1], 1)
  38. curs.execute(db_change("delete from back"))
  39. conn.commit()
  40. curs.execute(db_change("select title, data from data"))
  41. data = curs.fetchall()
  42. num = 0
  43. for test in data:
  44. num += 1
  45. t = threading.Thread(target = parser, args = [test])
  46. t.start()
  47. t.join()
  48. if num % 10 == 0:
  49. print(num)
  50. elif what_i_do == '2':
  51. curs.execute(db_change("delete from other where name = 'recaptcha'"))
  52. curs.execute(db_change("delete from other where name = 'sec_re'"))
  53. elif what_i_do == '3':
  54. print('----')
  55. print('IP or Name : ', end = '')
  56. user_data = input()
  57. if re.search("^([0-9]{1,3}\.[0-9]{1,3})$", user_data):
  58. band = 'O'
  59. else:
  60. band = ''
  61. curs.execute(db_change("insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, ?)"),
  62. [user_data,
  63. 'release',
  64. get_time(),
  65. 'tool:emergency',
  66. '',
  67. band
  68. ])
  69. curs.execute(db_change("delete from ban where block = ?"), [user_data])
  70. elif what_i_do == '4':
  71. print('----')
  72. print('Host : ', end = '')
  73. host = input()
  74. curs.execute(db_change("update other set data = ? where name = 'host'"), [host])
  75. elif what_i_do == '5':
  76. print('----')
  77. print('Port : ', end = '')
  78. port = int(input())
  79. curs.execute(db_change("update other set data = ? where name = 'port'"), [port])
  80. elif what_i_do == '6':
  81. print('----')
  82. print('Skin name : ', end = '')
  83. skin = input()
  84. curs.execute(db_change("update other set data = ? where name = 'skin'"), [skin])
  85. elif what_i_do == '7':
  86. print('----')
  87. print('1. sha256')
  88. print('2. sha3')
  89. print('----')
  90. print('Select : ', end = '')
  91. what_i_do = int(input())
  92. print('----')
  93. print('User name : ', end = '')
  94. user_name = input()
  95. print('----')
  96. print('User password : ', end = '')
  97. user_pw = input()
  98. if what_i_do == '1':
  99. hashed = hashlib.sha256(bytes(user_pw, 'utf-8')).hexdigest()
  100. else:
  101. if sys.version_info < (3, 6):
  102. hashed = sha3.sha3_256(bytes(user_pw, 'utf-8')).hexdigest()
  103. else:
  104. hashed = hashlib.sha3_256(bytes(user_pw, 'utf-8')).hexdigest()
  105. curs.execute(db_change("update user set pw = ? where id = ?"), [hashed, user_name])
  106. elif what_i_do == '8':
  107. curs.execute(db_change("update other set data = '00000' where name = 'ver'"))
  108. elif what_i_do == '9':
  109. try:
  110. os.remove('data/set.json')
  111. except:
  112. pass
  113. else:
  114. print('----')
  115. print('User name : ', end = '')
  116. user_name = input()
  117. print('----')
  118. print('New name : ', end = '')
  119. new_name = input()
  120. curs.execute(db_change("update user set id = ? where id = ?"), [new_name, user_name])
  121. conn.commit()
  122. print('----')
  123. print('OK')