emergency_tool.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. # Load
  2. import time
  3. from route.tool.func import *
  4. while True:
  5. data_db_load = input('Load DB (Y) [Y, N] : ')
  6. if data_db_load in ('Y', 'N'):
  7. break
  8. if data_db_load == 'Y':
  9. data_db_set = class_check_json()
  10. db_data_get(data_db_set['type'])
  11. do_db_set(data_db_set)
  12. load_db = get_db_connect_old(data_db_set)
  13. conn = load_db.db_load()
  14. curs = conn.cursor()
  15. else:
  16. print('----')
  17. print('You can use [9, 11]')
  18. # Main
  19. print('----')
  20. print('1. Backlink reset')
  21. print('2. reCAPTCHA delete')
  22. print('3. Ban delete')
  23. print('4. Change host')
  24. print('5. Change port')
  25. print('6. Change skin')
  26. print('7. Change password')
  27. print('8. Change version')
  28. print('9. Delete set.json')
  29. print('10. Change name')
  30. print('11. Delete mysql.json')
  31. print('12. All title count reset')
  32. print('13. Cache data reset')
  33. print('14. Delete Main <HEAD>')
  34. print('15. Give owner')
  35. print('16. Delete 2FA password')
  36. print('17. Change markup')
  37. print('----')
  38. what_i_do = input('Select : ')
  39. if what_i_do == '1':
  40. print('----')
  41. go_num = input('All delete (Y) [Y, N] : ')
  42. if not go_num == 'N':
  43. curs.execute(db_change("delete from back"))
  44. conn.commit()
  45. print('----')
  46. try:
  47. go_num = int(input('Count (100) : '))
  48. except ValueError:
  49. go_num = 100
  50. num = 0
  51. print('----')
  52. print('Load...')
  53. curs.execute(
  54. db_change(
  55. "select title from data d "
  56. "where not exists ("
  57. "select title from back where link = d.title limit 1"
  58. ")"
  59. ""
  60. )
  61. )
  62. title = curs.fetchall()
  63. print('----')
  64. print('Rest : ' + str(len(title)))
  65. print('Start : ' + title[0][0])
  66. time.sleep(1)
  67. print('----')
  68. for name in title:
  69. num += 1
  70. if num % go_num == 0:
  71. print(str(num) + ' : ' + name[0])
  72. if num % 100 == 0:
  73. conn.commit()
  74. curs.execute(db_change("select data from data where title = ?"), [name[0]])
  75. data = curs.fetchall()
  76. get_class_render = class_do_render(conn)
  77. get_class_render.do_render(name[0], data[0][0], 'backlink', '')
  78. elif what_i_do == '2':
  79. curs.execute(db_change("delete from other where name = 'recaptcha'"))
  80. curs.execute(db_change("delete from other where name = 'sec_re'"))
  81. elif what_i_do == '3':
  82. print('----')
  83. user_data = input('IP or Name : ')
  84. curs.execute(
  85. db_change(
  86. "insert into rb (block, end, today, blocker, why, band) "
  87. "values (?, ?, ?, ?, ?, ?)"
  88. ),
  89. [
  90. user_data,
  91. 'release',
  92. get_time(),
  93. 'tool:emergency',
  94. '',
  95. '',
  96. ]
  97. )
  98. curs.execute(db_change("update rb set ongoing = '' where block = ?"), [user_data])
  99. elif what_i_do == '4':
  100. print('----')
  101. host = input('Host : ')
  102. curs.execute(db_change("update other set data = ? where name = 'host'"), [host])
  103. elif what_i_do == '5':
  104. print('----')
  105. port = int(input('Port : '))
  106. curs.execute(db_change("update other set data = ? where name = 'port'"), [port])
  107. elif what_i_do == '6':
  108. print('----')
  109. skin = input('Skin name : ')
  110. curs.execute(db_change("update other set data = ? where name = 'skin'"), [skin])
  111. elif what_i_do == '7':
  112. print('----')
  113. print('1. sha256')
  114. print('2. sha3')
  115. print('----')
  116. what_i_do = input('Select : ')
  117. print('----')
  118. user_name = input('User name : ')
  119. print('----')
  120. user_pw = input('User password : ')
  121. if what_i_do == '1':
  122. hashed = hashlib.sha256(bytes(user_pw, 'utf-8')).hexdigest()
  123. elif what_i_do == '2':
  124. if sys.version_info < (3, 6):
  125. hashed = sha3.sha3_256(bytes(user_pw, 'utf-8')).hexdigest()
  126. else:
  127. hashed = hashlib.sha3_256(bytes(user_pw, 'utf-8')).hexdigest()
  128. else:
  129. raise ValueError(what_i_do)
  130. curs.execute(db_change("update user_set set data = ? where id = ? and name = 'pw'"), [
  131. hashed,
  132. user_name
  133. ])
  134. elif what_i_do == '8':
  135. print('----')
  136. new_ver = input('Insert version (0000000) : ')
  137. if new_ver == '':
  138. new_ver = '0000000'
  139. curs.execute(db_change("update other set data = ? where name = 'ver'"), [new_ver])
  140. elif what_i_do == '9':
  141. if os.path.exists(os.path.join('data', 'set.json')):
  142. os.remove(os.path.join('data', 'set.json'))
  143. elif what_i_do == '10':
  144. print('----')
  145. user_name = input('User name : ')
  146. print('----')
  147. new_name = input('New name : ')
  148. curs.execute(
  149. db_change("update user_set set id = ? where id = ?"),
  150. [new_name, user_name]
  151. )
  152. elif what_i_do == '11':
  153. if os.path.exists(os.path.join('data', 'mysql.json')):
  154. os.remove(os.path.join('data', 'mysql.json'))
  155. elif what_i_do == '12':
  156. curs.execute(db_change("select count(*) from data"))
  157. count_data = curs.fetchall()
  158. if count_data:
  159. count_data = count_data[0][0]
  160. else:
  161. count_data = 0
  162. curs.execute(db_change('delete from other where name = "count_all_title"'))
  163. curs.execute(
  164. db_change(
  165. 'insert into other (name, data) values ("count_all_title", ?)'
  166. ),
  167. [str(count_data)]
  168. )
  169. elif what_i_do == '13':
  170. curs.execute(db_change('delete from cache_data'))
  171. elif what_i_do == '14':
  172. curs.execute(db_change('delete from other where name = "head"'))
  173. elif what_i_do == '15':
  174. print('----')
  175. user_name = input('User name : ')
  176. curs.execute(db_change("update user_set set data = 'owner' where id = ? and name = 'acl'"), [user_name])
  177. elif what_i_do == '16':
  178. print('----')
  179. user_name = input('User name : ')
  180. curs.execute(db_change('select data from user_set where name = "2fa" and id = ?'), [user_name])
  181. if curs.fetchall():
  182. curs.execute(db_change("update user_set set data = '' where name = '2fa' and id = ?"), [user_name])
  183. elif what_i_do == '17':
  184. print('----')
  185. markup = input('Markup name : ')
  186. curs.execute(db_change("update other set data = ? where name = 'markup'"), [markup])
  187. else:
  188. raise ValueError(what_i_do)
  189. if data_db_load == 'Y':
  190. conn.commit()
  191. print('----')
  192. print('OK')