Browse Source

DB 가져오는 부분 수정, MySQL 호스트 지원

Surplus_Up (2DU) 6 years ago
parent
commit
ed8436c36e
4 changed files with 60 additions and 29 deletions
  1. 17 13
      app.py
  2. 34 12
      emergency_tool.py
  3. 7 2
      route/tool/func.py
  4. 2 2
      version.json

+ 17 - 13
app.py

@@ -8,19 +8,18 @@ for i_data in os.listdir("route"):
 
         exec("from route." + f_src + " import *")
 
-version_list = json.loads(open('version.json').read())
+# 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('----')
 
-app_var = json.loads(open('data/app_var.json').read())
-
-# DB
 while 1:
     try:
-        set_data = json.loads(open('data/set.json').read())
+        set_data = json.loads(open('data/set.json', encoding='utf8').read())
         if not 'db_type' in set_data:
             try:
                 os.remove('data/set.json')
@@ -68,10 +67,10 @@ while 1:
             if new_json[1] == '':
                 new_json[1] = 'data'
 
-            with open('data/set.json', 'w') as f:
+            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').read())
+            set_data = json.loads(open('data/set.json', encoding='utf8').read())
 
             break
 
@@ -79,7 +78,7 @@ db_data_get(set_data['db_type'])
 
 if set_data['db_type'] == 'mysql':
     try:
-        set_data_mysql = json.loads(open('data/mysql.json').read())
+        set_data_mysql = json.loads(open('data/mysql.json', encoding='utf8').read())
     except:
         new_json = ['', '']
 
@@ -94,14 +93,19 @@ if set_data['db_type'] == 'mysql':
             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') as f:
-            f.write('{ "user" : "' + new_json[0] + '", "password" : "' + new_json[1] + '" }')
+        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').read())
+        set_data_mysql = json.loads(open('data/mysql.json', encoding='utf8').read())
 
     conn = pymysql.connect(
-        host = 'localhost',
+        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'
@@ -205,7 +209,7 @@ if setup_tool != 0:
                 pass
 
     if setup_tool == 1:
-        update(int(ver_set_data[0][0]))
+        update(int(ver_set_data[0][0]), set_data)
     else:
         set_init()
 

+ 34 - 12
emergency_tool.py

@@ -1,9 +1,16 @@
 import time
 from route.tool.func import *
 
-version_list = json.loads(open('version.json', encoding='utf8').read())
 
 # 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())
@@ -70,7 +77,7 @@ if set_data['db_type'] == 'mysql':
         new_json = ['', '']
 
         while 1:
-            print('DB user id : ', end = '')
+            print('DB user ID : ', end = '')
             new_json[0] = str(input())
             if new_json[0] != '':
                 break
@@ -80,14 +87,19 @@ if set_data['db_type'] == 'mysql':
             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] + '" }')
+            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 = 'localhost',
+        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'
@@ -146,23 +158,23 @@ try:
     curs.execute(db_change('select data from other where name = "ver"'))
     ver_set_data = curs.fetchall()
     if not ver_set_data:
-        setup_tool = 1
+        setup_tool = 2
     else:
         if int(version_list['master']['c_ver']) > int(ver_set_data[0][0]):
             setup_tool = 1
 except:
-    setup_tool = 1
+    setup_tool = 2
 
 if setup_tool != 0:
     create_data['data'] = ['title', 'data']
-    create_data['cache_data'] = ['title', 'data']
+    create_data['cache_data'] = ['title', 'data', 'id']
     create_data['history'] = ['id', 'title', 'data', 'date', 'ip', 'send', 'leng', 'hide', 'type']
-    create_data['rd'] = ['title', 'sub', 'date', 'band', 'stop', 'agree']
+    create_data['rd'] = ['title', 'sub', 'code', 'date', 'band', 'stop', 'agree', 'acl']
     create_data['user'] = ['id', 'pw', 'acl', 'date', 'encode']
     create_data['user_set'] = ['name', 'id', 'data']
     create_data['user_application'] = ['id', 'pw', 'date', 'encode', 'question', 'answer', 'ip', 'ua', 'token', 'email']
     create_data['ban'] = ['block', 'end', 'why', 'band', 'login']
-    create_data['topic'] = ['id', 'title', 'sub', 'data', 'date', 'ip', 'block', 'top', 'code']
+    create_data['topic'] = ['id', 'data', 'date', 'ip', 'block', 'top', 'code']
     create_data['rb'] = ['block', 'end', 'today', 'blocker', 'why', 'band']
     create_data['back'] = ['title', 'link', 'type']
     create_data['custom'] = ['user', 'css']
@@ -190,7 +202,10 @@ if setup_tool != 0:
             except:
                 pass
 
-    update()
+    if setup_tool == 1:
+        update(int(ver_set_data[0][0]), set_data)
+    else:
+        set_init()
 
 curs.execute(db_change('delete from other where name = "ver"'))
 curs.execute(db_change('insert into other (name, data) values ("ver", ?)'), [version_list['master']['c_ver']])
@@ -205,7 +220,7 @@ print('4. Change host')
 print('5. Change port')
 print('6. Change skin')
 print('7. Change password')
-print('8. Reset version')
+print('8. Change version')
 print('9. Delete set.json')
 print('10. Change name')
 print('11. Delete mysql.json')
@@ -322,7 +337,14 @@ elif what_i_do == '7':
 
     curs.execute(db_change("update user set pw = ? where id = ?"), [hashed, user_name])
 elif what_i_do == '8':
-    curs.execute(db_change("update other set data = '00000' where name = 'ver'"))
+    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')

+ 7 - 2
route/tool/func.py

@@ -166,7 +166,7 @@ def render_set(title = '', data = '', num = 0, s_data = 0, include = None):
         else:
             return 'HTTP Request 404'
 
-def update(ver_num):
+def update(ver_num, set_data):
     print('----')
     # 업데이트 하위 호환 유지 함수
 
@@ -200,10 +200,15 @@ def update(ver_num):
             else:
                 curs.execute(db_change("update other set data = '' where name = 'recaptcha'"))
                 curs.execute(db_change("update other set data = '' where name = 'sec_re'"))
+    
+    if ver_num < 3172800 and set_data['db_type'] == 'mysql':
+        get_data_mysql = json.loads(open('data/mysql.json').read())
+        
+        with open('data/mysql.json', 'w') as f:
+            f.write('{ "user" : "' + get_data_mysql['user'] + '", "password" : "' + get_data_mysql['password'] + '", "host" : "localhost" }')
 
     conn.commit()
     print('Update pass')
-    print('----')
 
 def set_init():
     # 초기값 설정 함수    

+ 2 - 2
version.json

@@ -1,7 +1,7 @@
 {
     "master" : {
-        "r_ver" : "v3.1.7-master-27",
-        "c_ver" : "3171800",
+        "r_ver" : "v3.1.7-master-28",
+        "c_ver" : "3172800",
         "s_ver" : "7"
     }, "stable" : {
         "r_ver" : "v3.1.6-stable-05",