|
@@ -5,6 +5,8 @@ import platform
|
|
|
import json
|
|
import json
|
|
|
import smtplib
|
|
import smtplib
|
|
|
import random
|
|
import random
|
|
|
|
|
+import shutil
|
|
|
|
|
+import datetime
|
|
|
import ipaddress
|
|
import ipaddress
|
|
|
import subprocess
|
|
import subprocess
|
|
|
|
|
|
|
@@ -97,12 +99,13 @@ if sys.version_info < (3, 6):
|
|
|
global_lang = {}
|
|
global_lang = {}
|
|
|
global_wiki_set = {}
|
|
global_wiki_set = {}
|
|
|
|
|
|
|
|
-global_db_set = ''
|
|
|
|
|
|
|
+global_db_set = {}
|
|
|
|
|
|
|
|
# Func
|
|
# Func
|
|
|
# Func-main
|
|
# Func-main
|
|
|
def do_db_set(db_set):
|
|
def do_db_set(db_set):
|
|
|
global global_db_set
|
|
global global_db_set
|
|
|
|
|
+
|
|
|
global_db_set = db_set
|
|
global_db_set = db_set
|
|
|
|
|
|
|
|
# Func-init
|
|
# Func-init
|
|
@@ -142,6 +145,7 @@ def get_init_set_list(need = 'all'):
|
|
|
class get_db_connect:
|
|
class get_db_connect:
|
|
|
def __init__(self, db_type = ''):
|
|
def __init__(self, db_type = ''):
|
|
|
global global_db_set
|
|
global global_db_set
|
|
|
|
|
+
|
|
|
self.db_set = global_db_set
|
|
self.db_set = global_db_set
|
|
|
if db_type != '':
|
|
if db_type != '':
|
|
|
self.db_set['type'] = db_type
|
|
self.db_set['type'] = db_type
|
|
@@ -346,6 +350,68 @@ def get_db_table_list():
|
|
|
|
|
|
|
|
return create_data
|
|
return create_data
|
|
|
|
|
|
|
|
|
|
+def auto_do_something(data_db_set):
|
|
|
|
|
+ with get_db_connect() as conn:
|
|
|
|
|
+ curs = conn.cursor()
|
|
|
|
|
+
|
|
|
|
|
+ if data_db_set['type'] == 'sqlite':
|
|
|
|
|
+ def back_up(back_time, back_up_where, back_up_count = 0):
|
|
|
|
|
+ try:
|
|
|
|
|
+ if back_up_count != 0:
|
|
|
|
|
+ file_dir = os.path.split(back_up_where)[0]
|
|
|
|
|
+ file_dir = '.' if file_dir == '' else file_dir
|
|
|
|
|
+
|
|
|
|
|
+ file_name = os.path.split(back_up_where)[1]
|
|
|
|
|
+ file_name = re.sub(r'\.db$', '_[0-9]{14}.db', file_name)
|
|
|
|
|
+
|
|
|
|
|
+ backup_file = [for_a for for_a in os.listdir(file_dir) if re.search('^' + file_name + '$', for_a)]
|
|
|
|
|
+ backup_file = sorted(backup_file)
|
|
|
|
|
+
|
|
|
|
|
+ if len(backup_file) >= back_up_count:
|
|
|
|
|
+ remove_dir = os.path.join(file_dir, backup_file[0])
|
|
|
|
|
+ os.remove(remove_dir)
|
|
|
|
|
+ print('Back up : Remove (' + remove_dir + ')')
|
|
|
|
|
+
|
|
|
|
|
+ now_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
|
|
|
|
|
+ new_file_name = re.sub(r'\.db$', '_' + now_time + '.db', back_up_where)
|
|
|
|
|
+ shutil.copyfile(
|
|
|
|
|
+ data_db_set['name'] + '.db',
|
|
|
|
|
+ new_file_name
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ print('Back up : OK (' + new_file_name + ')')
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ print('Back up : Error')
|
|
|
|
|
+ print(e)
|
|
|
|
|
+
|
|
|
|
|
+ threading.Timer(
|
|
|
|
|
+ 60 * 60 * back_time,
|
|
|
|
|
+ back_up,
|
|
|
|
|
+ [back_time, back_up_where, back_up_count]
|
|
|
|
|
+ ).start()
|
|
|
|
|
+
|
|
|
|
|
+ curs.execute(db_change('select data from other where name = "back_up"'))
|
|
|
|
|
+ back_time = curs.fetchall()
|
|
|
|
|
+ back_time = float(number_check(back_time[0][0], True)) if back_time and back_time[0][0] != '' else 0
|
|
|
|
|
+
|
|
|
|
|
+ curs.execute(db_change('select data from other where name = "backup_count"'))
|
|
|
|
|
+ back_up_count = curs.fetchall()
|
|
|
|
|
+ back_up_count = int(number_check(back_up_count[0][0])) if back_up_count and back_up_count[0][0] != '' else 0
|
|
|
|
|
+
|
|
|
|
|
+ if back_time != 0:
|
|
|
|
|
+ curs.execute(db_change('select data from other where name = "backup_where"'))
|
|
|
|
|
+ back_up_where = curs.fetchall()
|
|
|
|
|
+ back_up_where = back_up_where[0][0] if back_up_where and back_up_where[0][0] != '' else data_db_set['name'] + '.db'
|
|
|
|
|
+
|
|
|
|
|
+ print('Back up state : ' + str(back_time) + ' hours')
|
|
|
|
|
+ print('Back up directory : ' + back_up_where)
|
|
|
|
|
+ if back_up_count != 0:
|
|
|
|
|
+ print('Back up max number : ' + str(back_up_count))
|
|
|
|
|
+
|
|
|
|
|
+ back_up(back_time, back_up_where, back_up_count)
|
|
|
|
|
+ else:
|
|
|
|
|
+ print('Back up state : Turn off')
|
|
|
|
|
+
|
|
|
def update(ver_num, set_data):
|
|
def update(ver_num, set_data):
|
|
|
with get_db_connect() as conn:
|
|
with get_db_connect() as conn:
|
|
|
curs = conn.cursor()
|
|
curs = conn.cursor()
|
|
@@ -2251,9 +2317,7 @@ def do_edit_filter(data):
|
|
|
curs = conn.cursor()
|
|
curs = conn.cursor()
|
|
|
|
|
|
|
|
if admin_check(1) != 1:
|
|
if admin_check(1) != 1:
|
|
|
- curs.execute(db_change(
|
|
|
|
|
- "select plus, plus_t from html_filter where kind = 'regex_filter' and plus != ''"
|
|
|
|
|
- ))
|
|
|
|
|
|
|
+ curs.execute(db_change("select plus, plus_t from html_filter where kind = 'regex_filter' and plus != ''"))
|
|
|
for data_list in curs.fetchall():
|
|
for data_list in curs.fetchall():
|
|
|
match = re.compile(data_list[0], re.I)
|
|
match = re.compile(data_list[0], re.I)
|
|
|
if match.search(data):
|
|
if match.search(data):
|