Backup Config
This commit is contained in:
@@ -3,6 +3,8 @@ import QtQuick.Controls
|
|||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import QtQuick.Dialogs
|
import QtQuick.Dialogs
|
||||||
import QtCore
|
import QtCore
|
||||||
|
import "../js/qmldict.js" as JsLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GridLayout
|
GridLayout
|
||||||
@@ -57,7 +59,8 @@ GridLayout
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (configPwd.text === repeatConfigPwd.text)
|
if (configPwd.text === repeatConfigPwd.text)
|
||||||
{ console.log("true")
|
{
|
||||||
|
|
||||||
saveConfigFile.open()
|
saveConfigFile.open()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -67,12 +70,12 @@ GridLayout
|
|||||||
configPwd.placeholderTextColor = "red"
|
configPwd.placeholderTextColor = "red"
|
||||||
repeatConfigPwd.placeholderText = qsTr("")
|
repeatConfigPwd.placeholderText = qsTr("")
|
||||||
repeatConfigPwd.text = ""
|
repeatConfigPwd.text = ""
|
||||||
console.log("false")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onRejected: console.log("Cancel clicked")
|
onRejected: console.log("Cancel clicked")
|
||||||
GridLayout
|
GridLayout
|
||||||
{
|
{
|
||||||
|
id: gridPw
|
||||||
columns: 2
|
columns: 2
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
@@ -80,6 +83,7 @@ GridLayout
|
|||||||
}
|
}
|
||||||
TextField
|
TextField
|
||||||
{
|
{
|
||||||
|
|
||||||
id: configPwd
|
id: configPwd
|
||||||
placeholderText: qsTr("Sicherungspasswort festlegen")
|
placeholderText: qsTr("Sicherungspasswort festlegen")
|
||||||
}
|
}
|
||||||
@@ -89,6 +93,7 @@ GridLayout
|
|||||||
}
|
}
|
||||||
TextField
|
TextField
|
||||||
{
|
{
|
||||||
|
property string name: "password"
|
||||||
id: repeatConfigPwd
|
id: repeatConfigPwd
|
||||||
placeholderText: qsTr("Sicherungspasswort wiederholen")
|
placeholderText: qsTr("Sicherungspasswort wiederholen")
|
||||||
}
|
}
|
||||||
@@ -103,8 +108,8 @@ GridLayout
|
|||||||
currentFolder: StandardPaths.standardLocations(StandardPaths.DocumentsLocation)[0]
|
currentFolder: StandardPaths.standardLocations(StandardPaths.DocumentsLocation)[0]
|
||||||
onAccepted:
|
onAccepted:
|
||||||
{
|
{
|
||||||
var test = config.backupConfig(saveConfigFile.currentFile)
|
var pw = JsLib.parseForm(gridPw)
|
||||||
console.log()
|
config.backupConfig(saveConfigFile.currentFile, pw["password"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ ApplicationWindow
|
|||||||
title: qsTr("PYQCRM Einstellungen")
|
title: qsTr("PYQCRM Einstellungen")
|
||||||
currentFolder: StandardPaths.standardLocations(StandardPaths.DocumentsLocation)[0]
|
currentFolder: StandardPaths.standardLocations(StandardPaths.DocumentsLocation)[0]
|
||||||
modality: "ApplicationModal"
|
modality: "ApplicationModal"
|
||||||
nameFilters: [qsTr("PYQCRM Einstellungen (*.pyqcrm)")]
|
nameFilters: [qsTr("PYQCRM Einstellungen (*.pyqrec)")]
|
||||||
onAccepted:
|
onAccepted:
|
||||||
{
|
{
|
||||||
exportFilePassword.open()
|
exportFilePassword.open()
|
||||||
|
|||||||
@@ -110,6 +110,12 @@ class ConfigLoader(QObject):
|
|||||||
self.backupEncryptionKey.emit()
|
self.backupEncryptionKey.emit()
|
||||||
return admin
|
return admin
|
||||||
|
|
||||||
|
"""###################################################"""
|
||||||
|
""" """
|
||||||
|
""" TODO: Rename method and rename self.__encrypt_key """
|
||||||
|
""" """
|
||||||
|
"""###################################################"""
|
||||||
|
|
||||||
@Slot(str, str)
|
@Slot(str, str)
|
||||||
def saveRecoveryKey(self, recovery_file, recovery_password):
|
def saveRecoveryKey(self, recovery_file, recovery_password):
|
||||||
# print(f"In {__file__} file, saveRecoveryKey()")
|
# print(f"In {__file__} file, saveRecoveryKey()")
|
||||||
@@ -131,30 +137,39 @@ class ConfigLoader(QObject):
|
|||||||
|
|
||||||
@Slot(str, str)
|
@Slot(str, str)
|
||||||
def getRecoveryKey(self, recovery_file, recovery_password):
|
def getRecoveryKey(self, recovery_file, recovery_password):
|
||||||
# print(f"In {__file__} file, getRecoveryKey()")
|
|
||||||
local = False
|
|
||||||
rec_file = urlparse(recovery_file)
|
rec_file = urlparse(recovery_file)
|
||||||
rec_file = rec_file.path
|
rec_file = rec_file.path
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
rec_file = rec_file [1:]
|
rec_file = rec_file [1:]
|
||||||
try:
|
try:
|
||||||
with open(rec_file, "r") as f:
|
ek = self.__parseImport(rec_file, recovery_password)
|
||||||
rf = f.read()
|
|
||||||
rf = Vermasseln().entschluesseln(rf, local)
|
if ek:
|
||||||
ek = rf[128:]
|
self.__setEncryptionKey(ek)
|
||||||
ek = ek[:-32]
|
self.configurationReady.emit()
|
||||||
password = rf[:128]
|
else:
|
||||||
salt = rf[-32:]
|
self.__invalidateEncryptionKey()
|
||||||
ok = self.__checkRecoveryPassword(recovery_password, password, salt)
|
self.invalidEncryptionKey.emit()
|
||||||
if ok:
|
|
||||||
self.__setEncryptionKey(ek)
|
|
||||||
self.configurationReady.emit()
|
|
||||||
else:
|
|
||||||
self.__invalidateEncryptionKey()
|
|
||||||
self.invalidEncryptionKey.emit()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
|
||||||
|
def __parseImport(self, rec_file, recovery_password):
|
||||||
|
local = False
|
||||||
|
with open(rec_file, "r") as f:
|
||||||
|
|
||||||
|
rf = f.read()
|
||||||
|
rf = Vermasseln().entschluesseln(rf, local)
|
||||||
|
ek = rf[128:]
|
||||||
|
ek = ek[:-32]
|
||||||
|
password = rf[:128]
|
||||||
|
salt = rf[-32:]
|
||||||
|
ok = self.__checkRecoveryPassword(recovery_password, password, salt)
|
||||||
|
if ok:
|
||||||
|
return ek
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def __invalidateEncryptionKey(self):
|
def __invalidateEncryptionKey(self):
|
||||||
# print(f"In {__file__} file, __invalidateEncryptionKey()")
|
# print(f"In {__file__} file, __invalidateEncryptionKey()")
|
||||||
self.__config['pyqcrm']['ENCRYPTION_KEY_VALID'] = 'No'
|
self.__config['pyqcrm']['ENCRYPTION_KEY_VALID'] = 'No'
|
||||||
@@ -173,13 +188,25 @@ class ConfigLoader(QObject):
|
|||||||
|
|
||||||
@Slot(str, str) # todo: non local encryption
|
@Slot(str, str) # todo: non local encryption
|
||||||
def importConfig(self, confile, password):
|
def importConfig(self, confile, password):
|
||||||
# print(f"In {__file__} file, importConfig()")
|
|
||||||
confile = urlparse(confile)
|
confile = urlparse(confile)
|
||||||
confile = confile.path
|
confile = confile.path
|
||||||
|
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
confile = confile[1:]
|
confile = confile[1:]
|
||||||
shutil.copyfile(confile, self.config_dir+ '/pyqcrm.toml')
|
try:
|
||||||
|
ek = self.__parseImport(confile, password)
|
||||||
|
if ek:
|
||||||
|
self.__config = toml.loads(ek)
|
||||||
|
self.__saveConfig()
|
||||||
|
self.configurationReady.emit()
|
||||||
|
else:
|
||||||
|
self.invalidEncryptionKey.emit()
|
||||||
|
except Exception as e:
|
||||||
|
print(str(e))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __configLoad(self):
|
def __configLoad(self):
|
||||||
# print(f"In {__file__} file, __configLoad()")
|
# print(f"In {__file__} file, __configLoad()")
|
||||||
@@ -213,8 +240,8 @@ class ConfigLoader(QObject):
|
|||||||
self.__config['pyqcrm']['ENCRYPTION_KEY'] = enc_key
|
self.__config['pyqcrm']['ENCRYPTION_KEY'] = enc_key
|
||||||
self.__saveConfig()
|
self.__saveConfig()
|
||||||
|
|
||||||
@Slot(str)
|
@Slot(str, str)
|
||||||
def backupConfig(self, pw):
|
def backupConfig(self, filename, password):
|
||||||
print(pw)
|
self.__encrypt_key = toml.dumps(self.getConfig())
|
||||||
new_config = self.getConfig()
|
self.saveRecoveryKey(filename, password)
|
||||||
print(new_config)
|
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ class Vermasseln:
|
|||||||
hash_pw = (salt + password).encode("utf-8")
|
hash_pw = (salt + password).encode("utf-8")
|
||||||
h_obj = SHA3_512.new(hash_pw)
|
h_obj = SHA3_512.new(hash_pw)
|
||||||
password = salt + "$" + h_obj.hexdigest()
|
password = salt + "$" + h_obj.hexdigest()
|
||||||
|
|
||||||
return password
|
return password
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user