-
Notifications
You must be signed in to change notification settings - Fork 4
/
tails-greeter.py
executable file
·159 lines (136 loc) · 5.58 KB
/
tails-greeter.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
#!/usr/bin/python
#
# Copyright 2012-2013 Tails developers <tails@boum.org>
# Copyright 2011 Max <govnototalitarizm@gmail.com>
# Copyright 2011 Martin Owens
#
# 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/>
#
"""
GDM greeter for Tails project using gtk
"""
import logging, logging.config
from gi.repository import Gtk
import sys, os
import tailsgreeter.gdmclient
def print_log_record_on_error(func):
"""Wrapper to determine failed logging instance"""
def wrap(self, *args, **kwargs):
"""internal logging wrapper"""
try:
return func(self, *args, **kwargs)
except:
print >> sys.stderr, "Failed log message=%r with args=%r " % (getattr(self, 'msg', '?'), getattr(self, 'args', '?'))
raise
return wrap
logging.config.fileConfig('tails-logging.conf')
logging.LogRecord.getMessage = print_log_record_on_error(logging.LogRecord.getMessage)
from pipes import quote
import tailsgreeter.config
import tailsgreeter.rootaccess
import tailsgreeter.camouflage
import tailsgreeter.persistence
import tailsgreeter.physicalsecurity
from tailsgreeter.language import TranslatableWindow
from tailsgreeter.langpanel import LangPanel
from tailsgreeter.persistencewindow import PersistenceWindow
from tailsgreeter.optionswindow import OptionsWindow
from tailsgreeter import GLADE_DIR, __appname__
class CommunityGreeterApp():
"""Tails greeter main controller
This class is the greeter dbus service"""
app_name = __appname__
glade_dir = GLADE_DIR
def __init__(self, *args, **kwargs):
self.language = 'en_US.UTF-8'
self.session = None
self.forced = False
self.postponed = False
self.postponed_text = None
self._usermanager_ready = False
self._gdmserver_ready = False
self.ready = False
self.translated = False
self._loaded_windows = []
# Load models
self.gdmclient = tailsgreeter.gdmclient.GdmClient(
server_ready_cb=self.server_ready,
session_opened_cb = self.close_app
)
self.persistence = tailsgreeter.persistence.PersistenceSettings()
self.localisationsettings = tailsgreeter.language.LocalisationSettings(
usermanager_loaded_cb = self.usermanager_loaded,
locale_selected_cb = self.locale_selected
)
self.rootaccess = tailsgreeter.rootaccess.RootAccessSettings()
self.camouflage = tailsgreeter.camouflage.CamouflageSettings()
self.physical_security = tailsgreeter.physicalsecurity.PhysicalSecuritySettings()
# Load views
self.langpanel = self.load_window(LangPanel, self)
self.persistencewindow = self.load_window(PersistenceWindow, self)
self.optionswindow = self.load_window(OptionsWindow, self)
logging.debug("loaded windows: %s" % self._loaded_windows)
def load_window(self, window_class, *args, **kwargs):
"""When loading a window, also translate it"""
logging.debug("loading window %s" % window_class)
window = window_class(*args, **kwargs)
self._loaded_windows.append(window)
if isinstance(window, TranslatableWindow) and self.language:
logging.debug("found translatable window")
window.translate_to(self.language.split('_')[0])
return window
def translate_to(self, lang):
"""Translate all windows to target language"""
logging.debug("translating to %s" % lang)
if self.ready:
self.language = lang
for window in self._loaded_windows:
if isinstance(window, TranslatableWindow):
logging.debug("translating %s to %s" % (window, lang))
window.translate_to(lang)
def login(self):
"""Login GDM to the server"""
self.gdmclient.do_login(tailsgreeter.config.LUSER)
def server_ready(self):
"""Server is ready"""
logging.debug("Entering server_ready")
self._gdmserver_ready = True
self.localisationsettings.set_layout('us')
self.maybe_show_ui()
def usermanager_loaded(self):
"""UserManager is ready"""
logging.debug("Entering usermanager_loaded")
self._usermanager_ready = True
self.localisationsettings.set_locale('en_US')
self.maybe_show_ui()
def locale_selected(self, locale):
self.translate_to(locale)
def maybe_show_ui(self):
"""Show UI if server and usermanager are both ready"""
logging.debug("Entering maybe_show_ui")
if self._gdmserver_ready and self._usermanager_ready:
self.ready = True
logging.info("tails-greeter is ready.")
self.langpanel.window.show()
self.persistencewindow.window.show()
else:
logging.debug("Something is not ready; not showing UI yet")
def close_app(self):
"""We're done, quit gtk app"""
logging.info("Finished.")
Gtk.main_quit()
if __name__ == "__main__":
logging.info("Started.")
app = CommunityGreeterApp()
Gtk.main()