-
Notifications
You must be signed in to change notification settings - Fork 5
/
csettings.py
283 lines (236 loc) · 14.5 KB
/
csettings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# encfsgui Settings
#
#
import os
import sys
import time
import datetime
import string
import configparser
from PyQt5 import uic
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
from PyQt5 import QtCore
import encfsgui_globals
from encfsgui_globals import *
import encfsgui_helper
from encfsgui_helper import *
import cconfig
from cconfig import CConfig
import cnewmasterkey
from cnewmasterkey import CNewMasterKeyWindow
class CSettingsWindow(QtWidgets.QDialog):
def __init__(self):
encfsgui_helper.print_debug("Start CSettingsWindow %s" % inspect.stack()[0][3])
super(CSettingsWindow, self).__init__()
uic.loadUi('encfsgui_settings.ui', self)
# disable/remove buttons
self.setWindowFlags(self.windowFlags() | QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowStaysOnTopHint)
self.setWindowFlag(QtCore.Qt.WindowMaximizeButtonHint, False)
self.setWindowFlag(QtCore.Qt.WindowCloseButtonHint, False)
# assign methods to buttons
self.okbutton = self.findChild(QtWidgets.QPushButton, 'btn_OK')
self.okbutton.clicked.connect(self.OKButtonClicked)
self.cancelbutton = self.findChild(QtWidgets.QPushButton, 'btn_cancel')
self.cancelbutton.clicked.connect(self.CancelButtonClicked)
self.selectencfsbutton = self.findChild(QtWidgets.QPushButton, 'btn_selectencfs')
self.selectencfsbutton.clicked.connect(self.SelectEncfsButtonClicked)
self.selectgocryptfsbutton = self.findChild(QtWidgets.QPushButton, 'btn_selectgocryptfs')
self.selectgocryptfsbutton.clicked.connect(self.SelectGocryptfsButtonClicked)
self.selectmountbutton = self.findChild(QtWidgets.QPushButton, 'btn_selectmount')
self.selectmountbutton.clicked.connect(self.SelectMountButtonClicked)
self.selectumountbutton = self.findChild(QtWidgets.QPushButton, 'btn_selectumount')
self.selectumountbutton.clicked.connect(self.SelectUmountButtonClicked)
self.selectworkingfolderbutton = self.findChild(QtWidgets.QPushButton, 'btn_selectworkingfolder')
self.selectworkingfolderbutton.clicked.connect(self.SelectWorkingFolderClicked)
self.settingsfile = encfsgui_globals.settingsfile
def SelectEncfsButtonClicked(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.txt_enfcsbinary = self.findChild(QtWidgets.QLineEdit, 'txt_encfsbinary')
options = QtWidgets.QFileDialog.Options()
options |= QtWidgets.QFileDialog.DontUseNativeDialog
fileName, _ = QtWidgets.QFileDialog.getOpenFileName(self,"Select 'encfs' binary", self.txt_enfcsbinary.displayText(),"All Files (*)", options=options)
if fileName:
self.txt_encfsbinary.setText("%s" % fileName)
return
def SelectGocryptfsButtonClicked(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.txt_gocryptfsbinary = self.findChild(QtWidgets.QLineEdit, 'txt_gocryptfsbinary')
options = QtWidgets.QFileDialog.Options()
options |= QtWidgets.QFileDialog.DontUseNativeDialog
fileName, _ = QtWidgets.QFileDialog.getOpenFileName(self,"Select 'gocryptfs' binary", self.txt_gocryptfsbinary.displayText(),"All Files (*)", options=options)
if fileName:
self.txt_gocryptfsbinary.setText("%s" % fileName)
return
def SelectMountButtonClicked(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.txt_mountbinary = self.findChild(QtWidgets.QLineEdit, 'txt_mountbinary')
options = QtWidgets.QFileDialog.Options()
options |= QtWidgets.QFileDialog.DontUseNativeDialog
fileName, _ = QtWidgets.QFileDialog.getOpenFileName(self,"Select 'mount' binary", self.txt_mountbinary.displayText(),"All Files (*)", options=options)
if fileName:
self.txt_mountbinary.setText("%s" % fileName)
return
def SelectUmountButtonClicked(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.txt_umountbinary = self.findChild(QtWidgets.QLineEdit, 'txt_umountbinary')
options = QtWidgets.QFileDialog.Options()
options |= QtWidgets.QFileDialog.DontUseNativeDialog
fileName, _ = QtWidgets.QFileDialog.getOpenFileName(self,"Select 'umount' binary", self.txt_umountbinary.displayText(),"All Files (*)", options=options)
if fileName:
self.txt_umountbinary.setText("%s" % fileName)
return
def SelectWorkingFolderClicked(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.txt_workingfolder = self.findChild(QtWidgets.QLineEdit, 'txt_workingfolder')
options = QtWidgets.QFileDialog.Options()
options |= QtWidgets.QFileDialog.DontUseNativeDialog
folderName = str(QtWidgets.QFileDialog.getExistingDirectory(self, "Select Directory"))
if folderName:
self.txt_workingfolder.setText("%s" % folderName)
return
def OKButtonClicked(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.saveSettings()
self.close()
return
def CancelButtonClicked(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.close()
return
def loadSettings(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
# populate fields
self.txt_enfcsbinary = self.findChild(QtWidgets.QLineEdit, 'txt_encfsbinary')
self.txt_enfcsbinary.setText("%s" % encfsgui_globals.g_Settings["encfspath"])
self.txt_gocryptfsbinary = self.findChild(QtWidgets.QLineEdit, 'txt_gocryptfsbinary')
self.txt_gocryptfsbinary.setText("%s" % encfsgui_globals.g_Settings["gocryptfspath"])
self.txt_mountbinary = self.findChild(QtWidgets.QLineEdit, 'txt_mountbinary')
self.txt_mountbinary.setText("%s" % encfsgui_globals.g_Settings["mountpath"])
self.txt_umountbinary = self.findChild(QtWidgets.QLineEdit, 'txt_umountbinary')
self.txt_umountbinary.setText("%s" % encfsgui_globals.g_Settings["umountpath"])
self.txt_workingfolder = self.findChild(QtWidgets.QLineEdit, 'txt_workingfolder')
self.txt_workingfolder.setText("%s" % encfsgui_globals.g_Settings["workingfolder"])
self.chk_starthidden = self.findChild(QtWidgets.QCheckBox, 'chk_starthidden')
self.chk_autounmount = self.findChild(QtWidgets.QCheckBox, 'chk_autounmount')
self.chk_autoupdate = self.findChild(QtWidgets.QCheckBox, 'chk_autoupdate')
self.chk_noconfirmationunmount = self.findChild(QtWidgets.QCheckBox, 'chk_noconfirmationunmount')
self.chk_noconfirmationexit = self.findChild(QtWidgets.QCheckBox, 'chk_noconfirmationexit')
self.chk_debugmode = self.findChild(QtWidgets.QCheckBox, 'chk_debugmode')
self.chk_confirmforceunmountall = self.findChild(QtWidgets.QCheckBox, 'chk_confirmforceunmountall')
self.chk_doubleclickmount = self.findChild(QtWidgets.QCheckBox, 'chk_doubleclickmount')
self.chk_encrypt = self.findChild(QtWidgets.QCheckBox, 'chk_encrypt')
self.chk_clearkeywhenhidden = self.findChild(QtWidgets.QCheckBox, 'chk_clearkeywhenhidden')
self.chk_hidevolumenotfound = self.findChild(QtWidgets.QCheckBox, 'chk_hidevolumenotfound')
if (encfsgui_globals.g_Settings["autounmount"].lower() == "true"):
self.chk_autounmount.setChecked(True)
if (encfsgui_globals.g_Settings["starthidden"].lower() == "true"):
self.chk_starthidden.setChecked(True)
if (encfsgui_globals.g_Settings["noconfirmationunmount"].lower() == "true"):
self.chk_noconfirmationunmount.setChecked(True)
else:
self.chk_noconfirmationunmount.setChecked(False)
if (encfsgui_globals.g_Settings["noconfirmationexit"].lower() == "true"):
self.chk_noconfirmationexit.setChecked(True)
if (encfsgui_globals.g_Settings["debugmode"].lower() == "true"):
self.chk_debugmode.setChecked(True)
if (encfsgui_globals.g_Settings["autoupdate"].lower() == "true"):
self.chk_autoupdate.setChecked(True)
if (encfsgui_globals.g_Settings["confirmforceunmountall"].lower() == "true"):
self.chk_confirmforceunmountall.setChecked(True)
if (encfsgui_globals.g_Settings["doubleclickmount"].lower() == "true"):
self.chk_doubleclickmount.setChecked(True)
if (encfsgui_globals.g_Settings["encrypt"].lower() == "true"):
self.chk_encrypt.setChecked(True)
if (encfsgui_globals.g_Settings["clearkeywhenhidden"].lower() == "true"):
self.chk_clearkeywhenhidden.setChecked(True)
if (encfsgui_globals.g_Settings["hidevolumenotfound"].lower() == "true"):
self.chk_hidevolumenotfound.setChecked(True)
return
def saveSettings(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
# update global settings
encfsgui_globals.g_Settings["encfspath"] = str(self.txt_enfcsbinary.displayText().strip())
encfsgui_globals.g_Settings["gocryptfspath"] = str(self.txt_gocryptfsbinary.displayText().strip())
encfsgui_globals.g_Settings["mountpath"] = str(self.txt_mountbinary.displayText().strip())
encfsgui_globals.g_Settings["umountpath"] = str(self.txt_umountbinary.displayText().strip())
if (self.txt_workingfolder.displayText().strip().replace(" ","") == ""):
self.txt_workingfolder.setText(".")
encfsgui_globals.g_Settings["workingfolder"] = str(self.txt_workingfolder.displayText().strip())
encfsgui_globals.g_Settings["autounmount"] = str(self.chk_autounmount.isChecked()).lower()
encfsgui_globals.g_Settings["noconfirmationunmount"] = str(self.chk_noconfirmationunmount.isChecked()).lower()
encfsgui_globals.g_Settings["noconfirmationexit"] = str(self.chk_noconfirmationexit.isChecked()).lower()
encfsgui_globals.g_Settings["starthidden"] = str(self.chk_starthidden.isChecked()).lower()
encfsgui_globals.g_Settings["debugmode"] = str(self.chk_debugmode.isChecked()).lower()
encfsgui_globals.g_Settings["autoupdate"] = str(self.chk_autoupdate.isChecked()).lower()
encfsgui_globals.g_Settings["confirmforceunmountall"] = str(self.chk_confirmforceunmountall.isChecked()).lower()
encfsgui_globals.g_Settings["doubleclickmount"] = str(self.chk_doubleclickmount.isChecked()).lower()
encfsgui_globals.g_Settings["clearkeywhenhidden"] = str(self.chk_clearkeywhenhidden.isChecked()).lower()
encfsgui_globals.g_Settings["hidevolumenotfound"] = str(self.chk_hidevolumenotfound.isChecked()).lower()
if self.chk_debugmode.isChecked():
encfsgui_globals.debugmode = True
encfsgui_helper.print_debug("Enable debug mode")
else:
encfsgui_helper.print_debug("Disable debug mode")
encfsgui_globals.debugmode = False
# encryption?
if (self.chk_encrypt.isChecked() and str(encfsgui_globals.g_Settings["encrypt"]).lower() == "false"):
# ask for master password
encryptionpassword = ""
msgBox = QtWidgets.QMessageBox()
msgBox.setWindowTitle("Enable encryption/master password?")
msgBox.setText("You are about to enable encryption of the encfsgui.volumes file.\n\nYour 'masterkey' password will NOT be stored and cannot be recovered.\nIf you forget the master password, you will not be able to recover/decrypt the contents of the encfsgui.volumes file.\n\nAre you sure?")
msgBox.setIcon(QMessageBox.Question)
msgBox.setStandardButtons(QtWidgets.QMessageBox.Yes)
msgBox.addButton(QtWidgets.QMessageBox.No)
msgBox.show()
if (msgBox.exec_() == QtWidgets.QMessageBox.Yes):
# ask for the password
masterpwwindow = CNewMasterKeyWindow()
masterpwwindow.setWindowTitle("Please enter master password")
masterpwwindow.show()
masterpwwindow.exec_()
encryptionpassword = masterpwwindow.getPassword()
# no password = no encryption
if encryptionpassword != "":
encfsgui_globals.masterkey = encryptionpassword
encfsgui_globals.g_Settings["encrypt"] = "true"
# make sure to encrypt the volumes file - simply request volumes file to be written to disk
# encryption is handled by the saveVolumes method
encfsgui_globals.appconfig.saveVolumes()
QtWidgets.QMessageBox.information(None,"Encryption enabled","Encryption enabled.")
else:
encfsgui_globals.g_Settings["encrypt"] = "false"
removeencryption = False
if (not self.chk_encrypt.isChecked()) and str(encfsgui_globals.g_Settings["encrypt"]).lower() == "true":
# ask to confirm to remove encryption?
msgBox = QtWidgets.QMessageBox()
msgBox.setWindowTitle("Disable encryption/master password?")
msgBox.setText("You are about to disable encryption of the encfsgui.volumes file.\n\nThis will decrypt the contents of the file and remove the need to use a master password.\n\nAre you sure?")
msgBox.setIcon(QMessageBox.Question)
msgBox.setStandardButtons(QtWidgets.QMessageBox.No)
msgBox.addButton(QtWidgets.QMessageBox.Yes)
msgBox.show()
if (msgBox.exec_() == QtWidgets.QMessageBox.Yes):
removeencryption = True
if removeencryption:
encfsgui_globals.g_Settings["encrypt"] = "false"
encfsgui_globals.masterkey = ""
else:
# leave encryption active
encfsgui_globals.g_Settings["encrypt"] = "true"
# and write to file
config = configparser.RawConfigParser()
config.add_section('config')
for settingkey in encfsgui_globals.g_Settings:
config.set('config', settingkey, encfsgui_globals.g_Settings[settingkey])
config.add_section('encodings')
config.set('encodings','filenameencodings', ",".join(encfsgui_globals.g_Encodings))
# save file to disk
with open(encfsgui_globals.settingsfile, 'w') as configfile:
config.write(configfile)
# save volumes (to make sure it gets encrypted or decrypted)
encfsgui_globals.appconfig.saveVolumes()
if removeencryption:
QtWidgets.QMessageBox.information(None,"Encryption disabled","Encryption disabled.")
return