Backup Config

This commit is contained in:
2025-02-27 14:45:27 +01:00
parent 4c62834369
commit 73542e8089
4 changed files with 61 additions and 30 deletions

View File

@@ -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"])
} }
} }
} }

View File

@@ -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()

View File

@@ -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,14 +137,26 @@ 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:
ek = self.__parseImport(rec_file, recovery_password)
if ek:
self.__setEncryptionKey(ek)
self.configurationReady.emit()
else:
self.__invalidateEncryptionKey()
self.invalidEncryptionKey.emit()
except Exception as e:
print(str(e))
def __parseImport(self, rec_file, recovery_password):
local = False
with open(rec_file, "r") as f: with open(rec_file, "r") as f:
rf = f.read() rf = f.read()
rf = Vermasseln().entschluesseln(rf, local) rf = Vermasseln().entschluesseln(rf, local)
ek = rf[128:] ek = rf[128:]
@@ -147,13 +165,10 @@ class ConfigLoader(QObject):
salt = rf[-32:] salt = rf[-32:]
ok = self.__checkRecoveryPassword(recovery_password, password, salt) ok = self.__checkRecoveryPassword(recovery_password, password, salt)
if ok: if ok:
self.__setEncryptionKey(ek) return ek
self.configurationReady.emit()
else: else:
self.__invalidateEncryptionKey() return None
self.invalidEncryptionKey.emit()
except Exception as e:
print(str(e))
def __invalidateEncryptionKey(self): def __invalidateEncryptionKey(self):
# print(f"In {__file__} file, __invalidateEncryptionKey()") # print(f"In {__file__} file, __invalidateEncryptionKey()")
@@ -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)

View File

@@ -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