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
|
#!/usr/bin/env python
#
# ecryptui.py, Copyright 2008 Mike Rooney (https://launchpad.net/~mrooney)
# Date: 2008-12-12
# Version: 0.3
#
# This is a graphical GTK utility to manage an encrypted ~/Private
# directory, allowing the user to mount and unmount, as well as enable
# auto-mounting at login.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Lock icons courtesy of http://www.famfamfam.com/lab/icons/silk/, via the
# Creative Commons Attribution 2.5 License.
import gtk, os
from panelcontroller import PanelController
try:
from ecryptfs import ecryptapi
except ImportError:
ecryptapi = None
LOCKED_ICON = os.path.join(os.path.dirname(__file__), 'lock-secure.png')
UNLOCKED_ICON = os.path.join(os.path.dirname(__file__), 'lock-insecure.png')
LOCKED_STATUS = os.path.join(os.path.dirname(__file__), 'lock-secure-small.png')
UNLOCKED_STATUS = os.path.join(os.path.dirname(__file__), 'lock-insecure-small.png')
class Window(gtk.Window):
def __init__(self):
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
self.set_title("Encrypted Directories")
self.hbox = gtk.HBox()
self.add(self.hbox)
# Initialize some bindings.
self.connect("destroy", self.destroy)
self.Controller = PanelController(self.showInstall, self.showSetup, self.showManage)
self.Controller.showAppropriateStep()
self.show()
self.show_all()
def showInstall(self):
print "Step 1: Install"
ipanel = InstallFrame()
self.hbox.pack_start(ipanel, False, False, 0)
#ipanel.show()
def showSetup(self):
print "Step 2: Setup"
spanel = SetupFrame()
self.hbox.pack_start(spanel, False, False, 0)
#spanel.show()
def showManage(self):
print "Step 3: Manage"
mpanel = ManageFrame()
self.hbox.pack_start(mpanel, False, False, 0)
#mpanel.show()
def showError(self, title, msg):
"""Show an error dialog with the given title and message body."""
dialog = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg)
dialog.set_title(title)
dialog.run()
dialog.destroy()
def destroy(self, widget, data=None):
"""Destroy the main window and quit."""
gtk.main_quit()
def main(self):
"""All PyGTK applications need a main method (apparently)."""
gtk.main()
class InstallFrame(gtk.Frame):
def __init__(self):
gtk.Frame.__init__(self)
label = gtk.Label("ecryptfs-utils is not currently installed.")
self.add(label)
class SetupFrame(gtk.Frame):
def __init__(self):
gtk.Frame.__init__(self)
vbox = gtk.VBox(False, 5)
label = gtk.Label("Choose how your encrypted Private directory will be configured.")
label2 = gtk.Label("If you don't understand what a particular option does, leave it at its default value.")
self.encryptFilenamesCheckbox = gtk.CheckButton("Encrypt filenames")
self.encryptFilenamesCheckbox.set_active(True)
self.checkPasswordValidityCheckbox = gtk.CheckButton("Check the validity of the specified login password")
self.checkPasswordValidityCheckbox.set_active(True)
self.createPrivateButton = gtk.Button("Create Private directory")
vbox.pack_start(label, False, True, 5)
vbox.pack_start(label2, False, False, 5)
vbox.pack_start(self.encryptFilenamesCheckbox, False, False, 5)
vbox.pack_start(self.checkPasswordValidityCheckbox, False, False, 5)
vbox.pack_start(self.createPrivateButton, False, False, 5)
self.add(vbox)
self.createPrivateButton.connect("clicked", self.onCreatePrivate, None)
def generateCommand(self):
args = ["ecryptfs-setup-private"]
if not self.encryptFilenamesCheckbox.get_active():
args.append("--no-fnek")
if not self.checkPasswordValidityCheckbox.get_active():
args.append("--nopwcheck")
command = " ".join(args)
return command
def onCreatePrivate(self, widget, data=None):
print self.generateCommand()
class ManageFrame(gtk.Frame):
def __init__(self):
"""Create and layout the user interface."""
gtk.Frame.__init__(self)
# When this is True, ignore toggle events, such as when we manually set it.
# Initially True because we need to set the value.
self.autoMountFrozen = True
self.autoUnmountFrozen = True
# The state variable, later wrapped in a property.
self._MountedState = ecryptapi.get_mounted()
# The main, vertical sizer, for holding the controls.
hbox = gtk.HBox(False, 5)
vbox = gtk.VBox(False, 5)
hbox.pack_start(vbox, False, False, 5)
self.add(hbox)
# Create the label controls with explain the current status.
labelHbox = gtk.HBox()
label = gtk.Label("Your Private directory is currently: ")
self.statusImage = gtk.Image()
self.buttonImage = gtk.Image()
self.statusLabel = gtk.Label("")
self.statusLabel.set_use_markup(True)
labelHbox.pack_start(label, False, False, 2)
#labelHbox.pack_start(gtk.Label(""), True, True, 0) # Just a spacer.
labelHbox.pack_start(self.statusLabel, False, False, 0)
labelHbox.pack_start(self.statusImage, False, False, 2)
# Create the button allowing the user to toggle the state.
self.toggleButton = gtk.Button("")
# Create a checkbox for toggling automounting.
self.autoCheck = gtk.CheckButton("Automatically unlock Private directory at login")
self.autoCheck.set_active(ecryptapi.get_automount())
self.autoMountFrozen = False # Now we set, unfreeze.
# Create a checkbox for toggling autounmounting.
self.autoCheck2 = gtk.CheckButton("Automatically lock Private directory at logoff")
self.autoCheck2.set_active(ecryptapi.get_autounmount())
self.autoUnmountFrozen = False # Now we set, unfreeze.
# Add everything to the main sizer.
vbox.pack_start(labelHbox, False, False, 5)
vbox.pack_start(self.toggleButton, False, False, 0)
vbox.pack_start(self.autoCheck, False, False, 0)
vbox.pack_start(self.autoCheck2, False, False, 0)
# Update the UI state from the current state.
self.updateFromState()
# Initilize some bindings
self.toggleButton.connect("clicked", self.onStateToggled, None)
self.autoCheck.connect("toggled", self.onAutoMountToggled, None)
self.autoCheck2.connect("toggled", self.onAutoUnmountToggled, None)
# Show everything
#self.show()
self.show_all()
def SetMountedState(self, state):
"""Sets the internal mount state and triggers a UI update."""
self._MountedState = state
self.updateFromState()
def updateFromState(self):
"""
When the state of the mount changes, this is called to update the GUI.
"""
if self.MountedState:
status, action, actionIcon, statusIcon = "Unlocked", "Lock your Private directory", LOCKED_ICON, UNLOCKED_STATUS
else:
status, action, actionIcon, statusIcon = "Locked", "Unlock your Private directory", UNLOCKED_ICON, LOCKED_STATUS
self.statusLabel.set_label("<b>%s</b>"%status)
self.toggleButton.set_property("image-position", gtk.POS_TOP)
self.toggleButton.set_label(action)
self.buttonImage.set_from_file(actionIcon)
self.statusImage.set_from_file(statusIcon)
self.toggleButton.set_image(self.buttonImage) # Does this only need to be called once in init?
def onAutoMountToggled(self, widget, data=None):
"""The event handler for the automount checkbutton."""
if not self.autoMountFrozen:
desiredState = widget.get_active()
status, output = ecryptapi.set_automount(desiredState)
if status != 0:
# It failed, unset the checkbox and show the error.
self.autoMountFrozen = True
widget.set_active(not desiredState)
self.autoMountFrozen = False
self.showError("Error %s"%status, output)
def onAutoUnmountToggled(self, widget, data=None):
"""The event handler for the automount checkbutton."""
if not self.autoUnmountFrozen:
desiredState = widget.get_active()
status, output = ecryptapi.set_autounmount(desiredState)
if status != 0:
# It failed, unset the checkbox and show the error.
self.autoUnmountFrozen = True
widget.set_active(not desiredState)
self.autoUnmountFrozen = False
self.showError("Error %s"%status, output)
def onStateToggled(self, widget, data=None):
"""The event handler for the mount toggle button."""
desiredState = not self.MountedState
status, output = ecryptapi.set_mounted(desiredState)
if status == 0:
# The action was successful, update our state.
self.MountedState = desiredState
else:
# The action failed, report the error.
self.showError("Error %s"%status, output)
MountedState = property(fget=lambda self: self._MountedState, fset=SetMountedState)
def main():
base = Window()
base.main()
if __name__ == "__main__":
main()
|