2
2
# -*- mode: python; coding: utf-8 -*-
4
# Mandos Monitor - Control and monitor the Mandos server
6
# Copyright © 2009,2010 Teddy Hogeborn
7
# Copyright © 2009,2010 Björn Påhlsson
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 3 of the License, or
12
# (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
# Contact the authors at <mandos@fukt.bsnet.se>.
4
25
from __future__ import division, absolute_import, with_statement
115
137
self.opened = False
139
last_checked_ok = isoformat_to_datetime(self.properties
141
if last_checked_ok is None:
142
self.last_checker_failed = True
144
self.last_checker_failed = ((datetime.datetime.utcnow()
151
if self.last_checker_failed:
152
self.using_timer(True)
154
if self.need_approval:
155
self.using_timer(True)
116
157
self.proxy.connect_to_signal(u"CheckerCompleted",
117
158
self.checker_completed,
118
159
client_interface,
134
175
client_interface,
135
176
byte_arrays=True)
136
last_checked_ok = isoformat_to_datetime(self.properties
138
if last_checked_ok is None:
139
self.last_checker_failed = True
178
def property_changed(self, property=None, value=None):
179
super(self, MandosClientWidget).property_changed(property,
181
if property == u"ApprovalPending":
182
using_timer(bool(value))
184
def using_timer(self, flag):
185
"""Call this method with True or False when timer should be
186
activated or deactivated.
188
old = self._update_timer_callback_lock
190
self._update_timer_callback_lock += 1
141
self.last_checker_failed = ((datetime.datetime.utcnow()
147
if self.last_checker_failed:
192
self._update_timer_callback_lock -= 1
193
if old == 0 and self._update_timer_callback_lock:
148
194
self._update_timer_callback_tag = (gobject.timeout_add
150
196
self.update_timer))
197
elif old and self._update_timer_callback_lock == 0:
198
gobject.source_remove(self._update_timer_callback_tag)
199
self._update_timer_callback_tag = None
152
201
def checker_completed(self, exitstatus, condition, command):
153
202
if exitstatus == 0:
154
203
if self.last_checker_failed:
155
204
self.last_checker_failed = False
156
gobject.source_remove(self._update_timer_callback_tag)
157
self._update_timer_callback_tag = None
205
self.using_timer(False)
158
206
#self.logger(u'Checker for client %s (command "%s")'
159
207
# u' was successful'
160
208
# % (self.properties[u"Name"], command))
164
212
if not self.last_checker_failed:
165
213
self.last_checker_failed = True
166
self._update_timer_callback_tag = (gobject.timeout_add
214
self.using_timer(True)
169
215
if os.WIFEXITED(condition):
170
216
self.logger(u'Checker for client %s (command "%s")'
171
217
u' failed with exit code %s'
202
248
message = u'Client %s will get its secret in %s seconds'
203
249
self.logger(message
204
250
% (self.properties[u"Name"], timeout/1000))
251
self.using_timer(True)
206
253
def rejected(self, reason):
207
254
self.logger(u'Client %s was rejected; reason: %s'
242
289
if not self.properties[u"Enabled"]:
243
290
message = u"DISABLED"
244
291
elif self.properties[u"ApprovalPending"]:
292
timeout = datetime.timedelta(milliseconds
295
last_approval_request = isoformat_to_datetime(
296
self.properties[u"LastApprovalRequest"])
297
if last_approval_request is not None:
298
timer = timeout - (datetime.datetime.utcnow()
299
- last_approval_request)
301
timer = datetime.timedelta()
245
302
if self.properties[u"ApprovedByDefault"]:
246
message = u"Connection established to client. (d)eny?"
303
message = u"Approval in %s. (d)eny?"
248
message = u"Seeks approval to send secret. (a)pprove?"
305
message = u"Denial in %s. (a)pprove?"
306
message = message % unicode(timer).rsplit(".", 1)[0]
249
307
elif self.last_checker_failed:
250
308
timeout = datetime.timedelta(milliseconds
251
309
= self.properties
309
367
elif key == u"d":
310
368
self.proxy.Approve(dbus.Boolean(False, variant_level=1),
311
369
dbus_interface = client_interface)
312
elif key == u"r" or key == u"_" or key == u"ctrl k":
370
elif key == u"R" or key == u"_" or key == u"ctrl k":
313
371
self.server_proxy_object.RemoveClient(self.proxy
315
373
elif key == u"s":