| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- import time
- from route.tool.func import *
- # DB
- version_list = json.loads(open('version.json', encoding='utf8').read())
- app_var = json.loads(open('data/app_var.json', encoding='utf8').read())
- print('Version : ' + version_list['master']['r_ver'])
- print('DB set version : ' + version_list['master']['c_ver'])
- print('Skin set version : ' + version_list['master']['s_ver'])
- print('----')
- while 1:
- try:
- set_data = json.loads(open('data/set.json', encoding='utf8').read())
- if not 'db_type' in set_data:
- try:
- os.remove('data/set.json')
- except:
- print('Please delete set.json')
- print('----')
- raise
- else:
- print('DB name : ' + set_data['db'])
- print('DB type : ' + set_data['db_type'])
- break
- except:
- if os.getenv('NAMU_DB') != None or os.getenv('NAMU_DB_TYPE') != None:
- set_data = {
- "db" : os.getenv('NAMU_DB') if os.getenv('NAMU_DB') else 'data',
- "db_type" : os.getenv('NAMU_DB_TYPE') if os.getenv('NAMU_DB_TYPE') else 'sqlite'
- }
- print('DB name : ' + set_data['db'])
- print('DB type : ' + set_data['db_type'])
- break
- else:
- new_json = ['', '']
- normal_db_type = ['sqlite', 'mysql']
- print('DB type (sqlite) [sqlite, mysql] : ', end = '')
- new_json[0] = str(input())
- if new_json[0] == '' or not new_json[0] in normal_db_type:
- new_json[0] = 'sqlite'
- all_src = []
- for i_data in os.listdir("."):
- f_src = re.search(r"(.+)\.db$", i_data)
- if f_src:
- all_src += [f_src.group(1)]
- if all_src != [] and new_json[0] != 'mysql':
- print('DB name (data) [' + ', '.join(all_src) + '] : ', end = '')
- else:
- print('DB name (data) : ', end = '')
- new_json[1] = str(input())
- if new_json[1] == '':
- new_json[1] = 'data'
- with open('data/set.json', 'w', encoding='utf8') as f:
- f.write('{ "db" : "' + new_json[1] + '", "db_type" : "' + new_json[0] + '" }')
- set_data = json.loads(open('data/set.json', encoding='utf8').read())
- break
- db_data_get(set_data['db_type'])
- if set_data['db_type'] == 'mysql':
- try:
- set_data_mysql = json.loads(open('data/mysql.json', encoding='utf8').read())
- except:
- new_json = ['', '', '']
- while 1:
- print('DB user ID : ', end = '')
- new_json[0] = str(input())
- if new_json[0] != '':
- break
- while 1:
- print('DB password : ', end = '')
- new_json[1] = str(input())
- if new_json[1] != '':
- break
-
- print('DB host (localhost) : ', end = '')
- new_json[2] = str(input())
- if new_json[2] == '':
- new_json[2] == 'localhost'
- with open('data/mysql.json', 'w', encoding='utf8') as f:
- f.write('{ "user" : "' + new_json[0] + '", "password" : "' + new_json[1] + '", "host" : "' + new_json[2] + '" }')
- set_data_mysql = json.loads(open('data/mysql.json', encoding='utf8').read())
- conn = pymysql.connect(
- host = set_data_mysql['host'] if 'host' in set_data_mysql else 'localhost',
- user = set_data_mysql['user'],
- password = set_data_mysql['password'],
- charset = 'utf8mb4'
- )
- curs = conn.cursor()
- try:
- curs.execute(db_change('create database ? default character set utf8mb4;')%pymysql.escape_string(set_data['db']))
- except:
- pass
- curs.execute(db_change('use ?')%pymysql.escape_string(set_data['db']))
- else:
- conn = sqlite3.connect(set_data['db'] + '.db', check_same_thread = False)
- curs = conn.cursor()
- load_conn(conn)
- # Main
- print('----')
- print('1. Backlink reset')
- print('2. reCAPTCHA delete')
- print('3. Ban delete')
- print('4. Change host')
- print('5. Change port')
- print('6. Change skin')
- print('7. Change password')
- print('8. Change version')
- print('9. Delete set.json')
- print('10. Change name')
- print('11. Delete mysql.json')
- print('12. All title count reset')
- print('13. Cache data reset')
- print('14. Delete Main <HEAD>')
- print('----')
- print('Select : ', end = '')
- what_i_do = input()
- if what_i_do == '1':
- print('----')
- print('All delete (Y) [Y, N] : ', end = '')
- go_num = input()
- if not go_num == 'N':
- curs.execute(db_change("delete from back"))
- conn.commit()
- print('----')
- print('Count (100) : ', end = '')
- try:
- go_num = int(input())
- except:
- go_num = 100
- num = 0
- print('----')
- print('Load...')
- curs.execute(db_change("select title from data d where not exists (select title from back where link = d.title)"))
- title = curs.fetchall()
- print('----')
- print('Rest : ' + str(len(title)))
- time.sleep(1)
- print('----')
- for name in title:
- num += 1
- if num % go_num == 0:
- print(str(num) + ' : ' + name[0])
- if num % 100 == 0:
- conn.commit()
- curs.execute(db_change("select data from data where title = ?"), [name[0]])
- data = curs.fetchall()
- render_do(name[0], data[0][0], 3, None)
- elif what_i_do == '2':
- curs.execute(db_change("delete from other where name = 'recaptcha'"))
- curs.execute(db_change("delete from other where name = 'sec_re'"))
- elif what_i_do == '3':
- print('----')
- print('IP or Name : ', end = '')
- user_data = input()
- curs.execute(db_change("insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, ?)"),
- [user_data,
- 'release',
- get_time(),
- 'tool:emergency',
- '',
- ''
- ])
- curs.execute(db_change("update rb set ongoing = '' where block = ?"), [user_data])
- elif what_i_do == '4':
- print('----')
- print('Host : ', end = '')
- host = input()
- curs.execute(db_change("update other set data = ? where name = 'host'"), [host])
- elif what_i_do == '5':
- print('----')
- print('Port : ', end = '')
- port = int(input())
- curs.execute(db_change("update other set data = ? where name = 'port'"), [port])
- elif what_i_do == '6':
- print('----')
- print('Skin name : ', end = '')
- skin = input()
- curs.execute(db_change("update other set data = ? where name = 'skin'"), [skin])
- elif what_i_do == '7':
- print('----')
- print('1. sha256')
- print('2. sha3')
- print('----')
- print('Select : ', end = '')
- what_i_do = int(input())
- print('----')
- print('User name : ', end = '')
- user_name = input()
- print('----')
- print('User password : ', end = '')
- user_pw = input()
- if what_i_do == '1':
- hashed = hashlib.sha256(bytes(user_pw, 'utf-8')).hexdigest()
- else:
- if sys.version_info < (3, 6):
- hashed = sha3.sha3_256(bytes(user_pw, 'utf-8')).hexdigest()
- else:
- hashed = hashlib.sha3_256(bytes(user_pw, 'utf-8')).hexdigest()
- curs.execute(db_change("update user set pw = ? where id = ?"), [hashed, user_name])
- elif what_i_do == '8':
- print('----')
- print('Insert version (0000000) : ', end = '')
- new_ver = input()
-
- if new_ver == '':
- new_ver == '0000000'
- curs.execute(db_change("update other set data = ? where name = 'ver'"), [new_ver])
- elif what_i_do == '9':
- try:
- os.remove('data/set.json')
- except:
- pass
- elif what_i_do == '10':
- print('----')
- print('User name : ', end = '')
- user_name = input()
- print('----')
- print('New name : ', end = '')
- new_name = input()
- curs.execute(db_change("update user set id = ? where id = ?"), [new_name, user_name])
- elif what_i_do == '11':
- try:
- os.remove('data/mysql.json')
- except:
- pass
- elif what_i_do == '12':
- curs.execute(db_change("select count(*) from data"))
- count_data = curs.fetchall()
- if count_data:
- count_data = count_data[0][0]
- else:
- count_data = 0
- curs.execute(db_change('delete from other where name = "count_all_title"'))
- curs.execute(db_change('insert into other (name, data) values ("count_all_title", ?)'), [str(count_data)])
- elif what_i_do == '13':
- curs.execute(db_change('delete from cache_data'))
- else:
- curs.execute(db_change('delete from other where name = "head"'))
- conn.commit()
- print('----')
- print('OK')
|