emergency_tool.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. # Load
  2. import time
  3. import os
  4. import platform
  5. import urllib
  6. import zipfile
  7. import urllib.request
  8. from route.tool.func import *
  9. while True:
  10. data_db_load = input('Load DB (Y) [Y, N] : ')
  11. data_db_load = data_db_load.upper()
  12. if data_db_load in ('Y', 'N'):
  13. break
  14. if data_db_load == 'Y':
  15. data_db_set = class_check_json()
  16. db_data_get(data_db_set['type'])
  17. do_db_set(data_db_set)
  18. load_db = get_db_connect()
  19. conn = load_db.__enter__()
  20. curs = conn.cursor()
  21. else:
  22. print('----')
  23. print('You can use [9, 11, 19]')
  24. # Main
  25. print('----')
  26. print('1. Backlink reset')
  27. print('2. reCAPTCHA delete')
  28. print('3. Ban delete')
  29. print('4. Change host')
  30. print('5. Change port')
  31. print('6. Change skin')
  32. print('7. Change password')
  33. print('8. Change version')
  34. print('9. Delete set.json')
  35. print('10. Change name')
  36. print('11. Delete mysql.json')
  37. print('12. All title count reset')
  38. print('14. Delete Main <HEAD>')
  39. print('15. Give owner')
  40. print('16. Delete 2FA password')
  41. print('17. Change markup')
  42. print('18. Change wiki access password')
  43. print('19. Forced update')
  44. print('20. Change domain')
  45. print('21. Change TLS')
  46. print('22. Delete body top')
  47. print('23. Delete body bottom')
  48. print('24. SQLite to MySQL')
  49. print('----')
  50. what_i_do = input('Select : ')
  51. if what_i_do == '1':
  52. print('----')
  53. go_num = input('All delete (Y) [Y, N] : ')
  54. if not go_num == 'N':
  55. curs.execute(db_change("delete from back"))
  56. conn.commit()
  57. print('----')
  58. try:
  59. go_num = int(input('Count (100) : '))
  60. except ValueError:
  61. go_num = 100
  62. num = 0
  63. print('----')
  64. print('Load...')
  65. curs.execute(
  66. db_change(
  67. "select title from data d "
  68. "where not exists ("
  69. "select title from back where link = d.title limit 1"
  70. ")"
  71. ""
  72. )
  73. )
  74. title = curs.fetchall()
  75. print('----')
  76. print('Rest : ' + str(len(title)))
  77. print('Start : ' + title[0][0])
  78. time.sleep(1)
  79. print('----')
  80. for name in title:
  81. num += 1
  82. if num % go_num == 0:
  83. print(str(num) + ' : ' + name[0])
  84. if num % 100 == 0:
  85. conn.commit()
  86. curs.execute(db_change("select data from data where title = ?"), [name[0]])
  87. data = curs.fetchall()
  88. class_do_render(conn).do_render(name[0], data[0][0], 'backlink', '')
  89. elif what_i_do == '2':
  90. curs.execute(db_change("delete from other where name = 'recaptcha'"))
  91. curs.execute(db_change("delete from other where name = 'sec_re'"))
  92. elif what_i_do == '3':
  93. print('----')
  94. user_data = input('IP or Name : ')
  95. curs.execute(
  96. db_change(
  97. "insert into rb (block, end, today, blocker, why, band) "
  98. "values (?, ?, ?, ?, ?, ?)"
  99. ),
  100. [
  101. user_data,
  102. 'release',
  103. get_time(),
  104. 'tool:emergency',
  105. '',
  106. '',
  107. ]
  108. )
  109. curs.execute(db_change("update rb set ongoing = '' where block = ?"), [user_data])
  110. elif what_i_do == '4':
  111. print('----')
  112. host = input('Host : ')
  113. curs.execute(db_change("update other set data = ? where name = 'host'"), [host])
  114. elif what_i_do == '5':
  115. print('----')
  116. port = int(input('Port : '))
  117. curs.execute(db_change("update other set data = ? where name = 'port'"), [port])
  118. elif what_i_do == '6':
  119. print('----')
  120. skin = input('Skin name : ')
  121. curs.execute(db_change("update other set data = ? where name = 'skin'"), [skin])
  122. elif what_i_do == '7':
  123. print('----')
  124. user_name = input('User name : ')
  125. print('----')
  126. user_pw = input('User password : ')
  127. hashed = pw_encode(user_pw)
  128. curs.execute(db_change("update user_set set data = ? where id = ? and name = 'pw'"), [
  129. hashed,
  130. user_name
  131. ])
  132. elif what_i_do == '8':
  133. print('----')
  134. new_ver = input('Insert version (0000000) : ')
  135. if new_ver == '':
  136. new_ver = '0000000'
  137. curs.execute(db_change("update other set data = ? where name = 'ver'"), [new_ver])
  138. elif what_i_do == '9':
  139. if os.path.exists(os.path.join('data', 'set.json')):
  140. os.remove(os.path.join('data', 'set.json'))
  141. elif what_i_do == '10':
  142. print('----')
  143. user_name = input('User name : ')
  144. print('----')
  145. new_name = input('New name : ')
  146. curs.execute(
  147. db_change("update user_set set id = ? where id = ?"),
  148. [new_name, user_name]
  149. )
  150. elif what_i_do == '11':
  151. if os.path.exists(os.path.join('data', 'mysql.json')):
  152. os.remove(os.path.join('data', 'mysql.json'))
  153. elif what_i_do == '12':
  154. curs.execute(db_change("select count(*) from data"))
  155. count_data = curs.fetchall()
  156. if count_data:
  157. count_data = count_data[0][0]
  158. else:
  159. count_data = 0
  160. curs.execute(db_change('delete from other where name = "count_all_title"'))
  161. curs.execute(db_change('insert into other (name, data, coverage) values ("count_all_title", ?, "")'), [str(count_data)])
  162. elif what_i_do == '14':
  163. curs.execute(db_change('delete from other where name = "head"'))
  164. elif what_i_do == '15':
  165. print('----')
  166. user_name = input('User name : ')
  167. curs.execute(db_change("update user_set set data = 'owner' where id = ? and name = 'acl'"), [user_name])
  168. elif what_i_do == '16':
  169. print('----')
  170. user_name = input('User name : ')
  171. curs.execute(db_change('select data from user_set where name = "2fa" and id = ?'), [user_name])
  172. if curs.fetchall():
  173. curs.execute(db_change("update user_set set data = '' where name = '2fa' and id = ?"), [user_name])
  174. elif what_i_do == '17':
  175. print('----')
  176. markup = input('Markup name : ')
  177. curs.execute(db_change("update other set data = ? where name = 'markup'"), [markup])
  178. elif what_i_do == '18':
  179. print('----')
  180. wiki_access_password = input('Password : ')
  181. curs.execute(db_change("update other set data = ? where name = 'wiki_access_password'"), [wiki_access_password])
  182. elif what_i_do == '19':
  183. print('----')
  184. up_data = input('Insert branch (beta) [stable, beta, dev] : ')
  185. if not up_data in ['stable', 'beta', 'dev']:
  186. up_data = 'beta'
  187. if platform.system() == 'Linux':
  188. ok = []
  189. ok += [os.system('git remote rm origin')]
  190. ok += [os.system('git remote add origin https://github.com/opennamu/opennamu.git')]
  191. ok += [os.system('git fetch origin ' + up_data)]
  192. ok += [os.system('git reset --hard origin/' + up_data)]
  193. if (ok[0] and ok[1] and ok[2] and ok[3]) != 0:
  194. print('Error : update failed')
  195. elif platform.system() == 'Windows':
  196. os.system('rd /s /q route')
  197. urllib.request.urlretrieve('https://github.com/opennamu/opennamu/archive/' + up_data + '.zip', 'update.zip')
  198. zipfile.ZipFile('update.zip').extractall('')
  199. ok = os.system('xcopy /y /s /r opennamu-' + up_data + ' .')
  200. if ok == 0:
  201. os.system('rd /s /q opennamu-' + up_data)
  202. os.system('del update.zip')
  203. else:
  204. print('Error : update failed')
  205. elif what_i_do == '20':
  206. print('----')
  207. domain = input('Domain (EX : 2du.pythonanywhere.com) : ')
  208. curs.execute(db_change('delete from other where name = "domain"'))
  209. curs.execute(db_change('insert into other (name, data, coverage) values ("domain", ?, "")'), [domain])
  210. elif what_i_do == '21':
  211. print('----')
  212. tls_v = input('TLS (http) [http, https] : ')
  213. if not tls_v in ['http', 'https']:
  214. tls_v = 'http'
  215. curs.execute(db_change('delete from other where name = "http_select"'))
  216. curs.execute(db_change('insert into other (name, data, coverage) values ("http_select", ?, "")'), [tls_v])
  217. elif what_i_do == '22':
  218. curs.execute(db_change('delete from other where name = "body"'))
  219. elif what_i_do == '23':
  220. curs.execute(db_change('delete from other where name = "bottom_body"'))
  221. elif what_i_do == '24':
  222. load_db = get_db_connect('mysql')
  223. mysql_conn = load_db.__enter__()
  224. mysql_curs = mysql_conn.cursor()
  225. load_db = get_db_connect('sqlite')
  226. sqlite_conn = load_db.__enter__()
  227. sqlite_curs = sqlite_conn.cursor()
  228. create_data = get_db_table_list()
  229. for create_table in create_data:
  230. create = ['test'] + create_data[create_table]
  231. create_r = ', '.join(['%s' for _ in create])
  232. create = ', '.join(create)
  233. print('select ' + create + ' from ' + create_table)
  234. mysql_curs.execute(db_change('delete from ' + create_table))
  235. sqlite_curs.execute(db_change('select ' + create + ' from ' + create_table))
  236. db_data = sqlite_curs.fetchall()
  237. mysql_curs.executemany(db_change("insert into " + create_table + " (" + create + ") values (" + create_r + ")"), db_data)
  238. else:
  239. raise ValueError(what_i_do)
  240. if data_db_load == 'Y':
  241. try:
  242. conn.commit()
  243. except:
  244. pass
  245. print('----')
  246. print('OK')