简单加密

pull/350/head
midoks 2 years ago
parent a2298ade04
commit 58ec4c2c30
  1. 19
      class/core/mw.py
  2. 8
      class/core/ssh_terminal.py
  3. 6
      plugins/webssh/index.py

@ -579,28 +579,37 @@ def dePunycode(domain):
def enCrypt(key, strings):
# 加密字符串
try:
import base64
_key = md5(key).encode('utf-8')
_key = base64.urlsafe_b64encode(_key)
if type(strings) != bytes:
strings = strings.encode('utf-8')
import cryptography
from cryptography.fernet import Fernet
f = Fernet(key)
f = Fernet(_key)
result = f.encrypt(strings)
return result.decode('utf-8')
except:
# print(get_error_info())
print(getTracebackInfo())
return strings
def deCrypt(key, strings):
# 解密字符串
try:
import base64
_key = md5(key).encode('utf-8')
_key = base64.urlsafe_b64encode(_key)
if type(strings) != bytes:
strings = strings.decode('utf-8')
strings = strings.encode('utf-8')
from cryptography.fernet import Fernet
f = Fernet(key)
f = Fernet(_key)
result = f.decrypt(strings).decode('utf-8')
return result
except:
# print(get_error_info())
print(getTracebackInfo())
return strings

@ -318,6 +318,11 @@ class ssh_terminal:
self.debug('通道已构建')
return self.returnMsg(True, '连接成功.')
def getSshInfo(self, file):
rdata = mw.readFile(file)
destr = mw.deCrypt('mdserver-web', rdata)
return json.loads(destr)
def setAttr(self, sid, info):
self.__host = info['host'].strip()
@ -325,8 +330,7 @@ class ssh_terminal:
if not self.__host in ['127.0.0.1', 'localhost']:
dst_info = mw.getServerDir() + '/webssh/host/' + self.__host + '/info.json'
if os.path.exists(dst_info):
_t = mw.readFile(dst_info)
info = json.loads(_t)
info = self.getSshInfo(dst_info)
if 'type' in info:
self.__type = info['type']

@ -110,7 +110,8 @@ class App():
def getSshInfo(self, file):
rdata = mw.readFile(file)
return json.loads(rdata)
destr = mw.deCrypt('mdserver-web', rdata)
return json.loads(destr)
def get_server_by_host(self):
args = self.getArgs()
@ -198,7 +199,8 @@ class App():
if not os.path.exists(dst_host_dir):
os.makedirs(dst_host_dir)
mw.writeFile(dst_host_dir + '/info.json', json.dumps(info))
enstr = mw.enCrypt('mdserver-web', json.dumps(info))
mw.writeFile(dst_host_dir + '/info.json', enstr)
return mw.returnJson(True, '添加成功!')
if __name__ == "__main__":

Loading…
Cancel
Save