|
|
@@ -78,7 +78,7 @@ import pymysql
|
|
|
|
|
|
if sys.version_info < (3, 6):
|
|
|
import sha3
|
|
|
-
|
|
|
+
|
|
|
# Init-Global
|
|
|
global_lang = {}
|
|
|
global_wiki_set = {}
|
|
|
@@ -196,6 +196,130 @@ class get_db_connect:
|
|
|
load_conn(self.conn_sub)
|
|
|
self.conn.close()
|
|
|
|
|
|
+class class_check_json:
|
|
|
+ def do_check_set_json():
|
|
|
+ if os.getenv('NAMU_DB') or os.getenv('NAMU_DB_TYPE'):
|
|
|
+ set_data = {}
|
|
|
+ set_data['db'] = os.getenv('NAMU_DB') if os.getenv('NAMU_DB') else 'data'
|
|
|
+ set_data['db'] = os.getenv('NAMU_DB_TYPE') if os.getenv('NAMU_DB_TYPE') else 'sqlite'
|
|
|
+ else:
|
|
|
+ if os.path.exists(os.path.join('data', 'set.json')):
|
|
|
+ db_set_list = ['db', 'db_type']
|
|
|
+ set_data = json.loads(open(
|
|
|
+ os.path.join('data', 'set.json'),
|
|
|
+ encoding = 'utf8'
|
|
|
+ ).read())
|
|
|
+ for i in db_set_list:
|
|
|
+ if not i in set_data:
|
|
|
+ os.remove(os.path.join('data', 'set.json'))
|
|
|
+
|
|
|
+ break
|
|
|
+
|
|
|
+ if not os.path.exists(os.path.join('data', 'set.json')):
|
|
|
+ set_data = {}
|
|
|
+ normal_db_type = ['sqlite', 'mysql']
|
|
|
+
|
|
|
+ print('DB type (' + normal_db_type[0] + ') [' + ', '.join(normal_db_type) + '] : ', end = '')
|
|
|
+ data_get = str(input())
|
|
|
+ if data_get == '' or not data_get in normal_db_type:
|
|
|
+ set_data['db_type'] = 'sqlite'
|
|
|
+ else:
|
|
|
+ set_data['db_type'] = data_get
|
|
|
+
|
|
|
+ all_src = []
|
|
|
+ if set_data['db_type'] == 'sqlite':
|
|
|
+ for i_data in os.listdir("."):
|
|
|
+ f_src = re.search(r"(.+)\.db$", i_data)
|
|
|
+ if f_src:
|
|
|
+ all_src += [f_src.group(1)]
|
|
|
+
|
|
|
+ print('DB name (data) [' + ', '.join(all_src) + '] : ', end = '')
|
|
|
+
|
|
|
+ data_get = str(input())
|
|
|
+ if data_get == '':
|
|
|
+ set_data['db'] = 'data'
|
|
|
+ else:
|
|
|
+ set_data['db'] = data_get
|
|
|
+
|
|
|
+ with open(os.path.join('data', 'set.json'), 'w', encoding = 'utf8') as f:
|
|
|
+ f.write(json.dumps(set_data))
|
|
|
+
|
|
|
+ print('DB name : ' + set_data['db'])
|
|
|
+ print('DB type : ' + set_data['db_type'])
|
|
|
+
|
|
|
+ data_db_set = {}
|
|
|
+ data_db_set['name'] = set_data['db']
|
|
|
+ data_db_set['type'] = set_data['db_type']
|
|
|
+
|
|
|
+ return data_db_set
|
|
|
+
|
|
|
+ def do_check_mysql_json(data_db_set):
|
|
|
+ if os.path.exists(os.path.join('data', 'mysql.json')):
|
|
|
+ db_set_list = ['user', 'password', 'host', 'port']
|
|
|
+ set_data = json.loads(
|
|
|
+ open(
|
|
|
+ os.path.join('data', 'mysql.json'),
|
|
|
+ encoding = 'utf8'
|
|
|
+ ).read()
|
|
|
+ )
|
|
|
+ for i in db_set_list:
|
|
|
+ if not i in set_data:
|
|
|
+ os.remove(os.path.join('data', 'mysql.json'))
|
|
|
+
|
|
|
+ break
|
|
|
+
|
|
|
+ set_data_mysql = set_data
|
|
|
+
|
|
|
+ if not os.path.exists(os.path.join('data', 'mysql.json')):
|
|
|
+ set_data_mysql = {}
|
|
|
+
|
|
|
+ print('DB user ID : ', end = '')
|
|
|
+ set_data_mysql['user'] = str(input())
|
|
|
+
|
|
|
+ print('DB password : ', end = '')
|
|
|
+ set_data_mysql['password'] = str(input())
|
|
|
+
|
|
|
+ print('DB host (localhost) : ', end = '')
|
|
|
+ set_data_mysql['host'] = str(input())
|
|
|
+ if set_data_mysql['host'] == '':
|
|
|
+ set_data_mysql['host'] = 'localhost'
|
|
|
+
|
|
|
+ print('DB port (3306) : ', end = '')
|
|
|
+ set_data_mysql['port'] = str(input())
|
|
|
+ if set_data_mysql['port'] == '':
|
|
|
+ set_data_mysql['port'] = '3306'
|
|
|
+
|
|
|
+ with open(
|
|
|
+ os.path.join('data', 'mysql.json'),
|
|
|
+ 'w',
|
|
|
+ encoding = 'utf8'
|
|
|
+ ) as f:
|
|
|
+ f.write(json.dumps(set_data_mysql))
|
|
|
+
|
|
|
+ data_db_set['mysql_user'] = set_data_mysql['user']
|
|
|
+ data_db_set['mysql_pw'] = set_data_mysql['password']
|
|
|
+ if 'host' in set_data_mysql:
|
|
|
+ data_db_set['mysql_host'] = set_data_mysql['host']
|
|
|
+ else:
|
|
|
+ data_db_set['mysql_host'] = 'localhost'
|
|
|
+
|
|
|
+ if 'port' in set_data_mysql:
|
|
|
+ data_db_set['mysql_port'] = set_data_mysql['port']
|
|
|
+ else:
|
|
|
+ data_db_set['mysql_port'] = '3306'
|
|
|
+
|
|
|
+ return data_db_set
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ self.data_db_set = {}
|
|
|
+
|
|
|
+ def __new__(self):
|
|
|
+ self.data_db_set = self.do_check_set_json()
|
|
|
+ if self.data_db_set['type'] == 'mysql':
|
|
|
+ self.data_db_set = self.do_check_mysql_json(self.data_db_set)
|
|
|
+
|
|
|
+ return self.data_db_set
|
|
|
+
|
|
|
def update(ver_num, set_data):
|
|
|
curs = conn.cursor()
|
|
|
|
|
|
@@ -1040,15 +1164,14 @@ def captcha_get():
|
|
|
|
|
|
curs.execute(db_change('select data from other where name = "recaptcha_ver"'))
|
|
|
rec_ver = curs.fetchall()
|
|
|
- if recaptcha and recaptcha[0][0] != '' and \
|
|
|
- sec_re and sec_re[0][0] != '':
|
|
|
+ if recaptcha and recaptcha[0][0] != '' and sec_re and sec_re[0][0] != '':
|
|
|
if not rec_ver or rec_ver[0][0] == '':
|
|
|
data += '' + \
|
|
|
'<script src="https://www.google.com/recaptcha/api.js" async defer></script>' + \
|
|
|
'<div class="g-recaptcha" data-sitekey="' + recaptcha[0][0] + '"></div>' + \
|
|
|
'<hr class="main_hr">' + \
|
|
|
''
|
|
|
- else:
|
|
|
+ elif rec_ver[0][0] == 'v3':
|
|
|
data += '' + \
|
|
|
'<script src="https://www.google.com/recaptcha/api.js?render=' + recaptcha[0][0] + '"></script>' + \
|
|
|
'<input type="hidden" id="g-recaptcha" name="g-recaptcha">' + \
|
|
|
@@ -1060,25 +1183,43 @@ def captcha_get():
|
|
|
'});' + \
|
|
|
'</script>' + \
|
|
|
''
|
|
|
+ else:
|
|
|
+ data += '''
|
|
|
+ <script src="https://js.hcaptcha.com/1/api.js" async defer></script>
|
|
|
+ <div class="h-captcha" data-sitekey="''' + recaptcha[0][0] + '''"></div>
|
|
|
+ <hr class="main_hr">
|
|
|
+ '''
|
|
|
|
|
|
return data
|
|
|
|
|
|
def captcha_post(re_data, num = 1):
|
|
|
curs = conn.cursor()
|
|
|
|
|
|
- if num == 1:
|
|
|
+ if num == 1 and ip_or_user() != 0:
|
|
|
curs.execute(db_change('select data from other where name = "sec_re"'))
|
|
|
sec_re = curs.fetchall()
|
|
|
- if sec_re and sec_re[0][0] != '' and \
|
|
|
- ip_or_user() != 0 and captcha_get() != '':
|
|
|
- data = requests.get(
|
|
|
- 'https://www.google.com/recaptcha/api/siteverify' + \
|
|
|
- '?secret=' + sec_re[0][0] + '&response=' + re_data
|
|
|
- )
|
|
|
- if data.status_code == 200:
|
|
|
- json_data = json.loads(data.text)
|
|
|
- if json_data['success'] != True:
|
|
|
- return 1
|
|
|
+
|
|
|
+ curs.execute(db_change('select data from other where name = "recaptcha_ver"'))
|
|
|
+ rec_ver = curs.fetchall()
|
|
|
+ if captcha_get() != '':
|
|
|
+ if not rec_ver or rec_ver[0][0] in ('', 'v3'):
|
|
|
+ data = requests.get(
|
|
|
+ 'https://www.google.com/recaptcha/api/siteverify' + \
|
|
|
+ '?secret=' + sec_re[0][0] + '&response=' + re_data
|
|
|
+ )
|
|
|
+ if data.status_code == 200:
|
|
|
+ json_data = json.loads(data.text)
|
|
|
+ if json_data['success'] != True:
|
|
|
+ return 1
|
|
|
+ else:
|
|
|
+ data = requests.get(
|
|
|
+ 'https://hcaptcha.com/siteverify' + \
|
|
|
+ '?secret=' + sec_re[0][0] + '&response=' + re_data
|
|
|
+ )
|
|
|
+ if data.status_code == 200:
|
|
|
+ json_data = json.loads(data.text)
|
|
|
+ if json_data['success'] != True:
|
|
|
+ return 1
|
|
|
|
|
|
return 0
|
|
|
|