/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos-monitor

  • Committer: Teddy Hogeborn
  • Date: 2012-05-05 10:52:11 UTC
  • Revision ID: teddy@recompile.se-20120505105211-58z3hyjfzep3z2q9
* mandos: White space and other misc. format fixes only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#     GNU General Public License for more details.
18
18
19
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/>.
 
20
# along with this program.  If not, see
 
21
# <http://www.gnu.org/licenses/>.
21
22
22
23
# Contact the authors at <mandos@recompile.se>.
23
24
172
173
                                         self.rejected,
173
174
                                         client_interface,
174
175
                                         byte_arrays=True))
175
 
        #self.logger('Created client %s' % (self.properties["Name"]))
 
176
        #self.logger('Created client {0}'
 
177
        #            .format(self.properties["Name"]))
176
178
    
177
179
    def property_changed(self, property=None, value=None):
178
180
        super(self, MandosClientWidget).property_changed(property,
181
183
            using_timer(bool(value))
182
184
        if property == "LastCheckerStatus":
183
185
            using_timer(value != 0)
184
 
            #self.logger('Checker for client %s (command "%s")'
185
 
            #            ' was successful'
186
 
            #            % (self.properties["Name"], command))
 
186
            #self.logger('Checker for client {0} (command "{1}") was '
 
187
            #            ' successful'.format(self.properties["Name"],
 
188
            #                                 command))
187
189
    
188
190
    def using_timer(self, flag):
189
191
        """Call this method with True or False when timer should be
209
211
            return
210
212
        # Checker failed
211
213
        if os.WIFEXITED(condition):
212
 
            self.logger('Checker for client %s (command "%s")'
213
 
                        ' failed with exit code %s'
214
 
                        % (self.properties["Name"], command,
215
 
                           os.WEXITSTATUS(condition)))
 
214
            self.logger('Checker for client {0} (command "{1}")'
 
215
                        ' failed with exit code {2}'
 
216
                        .format(self.properties["Name"], command,
 
217
                                os.WEXITSTATUS(condition)))
216
218
        elif os.WIFSIGNALED(condition):
217
 
            self.logger('Checker for client %s (command "%s")'
218
 
                        ' was killed by signal %s'
219
 
                        % (self.properties["Name"], command,
220
 
                           os.WTERMSIG(condition)))
 
219
            self.logger('Checker for client {0} (command "{1}") was'
 
220
                        ' killed by signal {2}'
 
221
                        .format(self.properties["Name"], command,
 
222
                                os.WTERMSIG(condition)))
221
223
        elif os.WCOREDUMP(condition):
222
 
            self.logger('Checker for client %s (command "%s")'
 
224
            self.logger('Checker for client {0} (command "{1}")'
223
225
                        ' dumped core'
224
 
                        % (self.properties["Name"], command))
 
226
                        .format(self.properties["Name"], command))
225
227
        else:
226
 
            self.logger('Checker for client %s completed'
227
 
                        ' mysteriously')
 
228
            self.logger('Checker for client {0} completed'
 
229
                        ' mysteriously'
 
230
                        .format(self.properties["Name"]))
228
231
        self.update()
229
232
    
230
233
    def checker_started(self, command):
231
234
        """Server signals that a checker started. This could be useful
232
235
           to log in the future. """
233
 
        #self.logger('Client %s started checker "%s"'
234
 
        #            % (self.properties["Name"], unicode(command)))
 
236
        #self.logger('Client {0} started checker "{1}"'
 
237
        #            .format(self.properties["Name"],
 
238
        #                    unicode(command)))
235
239
        pass
236
240
    
237
241
    def got_secret(self):
238
 
        self.logger('Client %s received its secret'
239
 
                    % self.properties["Name"])
 
242
        self.logger('Client {0} received its secret'
 
243
                    .format(self.properties["Name"]))
240
244
    
241
245
    def need_approval(self, timeout, default):
242
246
        if not default:
243
 
            message = 'Client %s needs approval within %s seconds'
 
247
            message = 'Client {0} needs approval within {1} seconds'
244
248
        else:
245
 
            message = 'Client %s will get its secret in %s seconds'
246
 
        self.logger(message
247
 
                    % (self.properties["Name"], timeout/1000))
 
249
            message = 'Client {0} will get its secret in {1} seconds'
 
250
        self.logger(message.format(self.properties["Name"],
 
251
                                   timeout/1000))
248
252
        self.using_timer(True)
249
253
    
250
254
    def rejected(self, reason):
251
 
        self.logger('Client %s was rejected; reason: %s'
252
 
                    % (self.properties["Name"], reason))
 
255
        self.logger('Client {0} was rejected; reason: {1}'
 
256
                    .format(self.properties["Name"], reason))
253
257
    
254
258
    def selectable(self):
255
259
        """Make this a "selectable" widget.
281
285
        # Rebuild focus and non-focus widgets using current properties
282
286
 
283
287
        # Base part of a client. Name!
284
 
        base = ('%(name)s: '
285
 
                      % {"name": self.properties["Name"]})
 
288
        base = '{name}: '.format(name=self.properties["Name"])
286
289
        if not self.properties["Enabled"]:
287
290
            message = "DISABLED"
288
291
        elif self.properties["ApprovalPending"]:
297
300
            else:
298
301
                timer = datetime.timedelta()
299
302
            if self.properties["ApprovedByDefault"]:
300
 
                message = "Approval in %s. (d)eny?"
 
303
                message = "Approval in {0}. (d)eny?"
301
304
            else:
302
 
                message = "Denial in %s. (a)pprove?"
303
 
            message = message % unicode(timer).rsplit(".", 1)[0]
 
305
                message = "Denial in {0}. (a)pprove?"
 
306
            message = message.format(unicode(timer).rsplit(".", 1)[0])
304
307
        elif self.properties["LastCheckerStatus"] != 0:
305
 
            # When checker has failed, print a timer until client expires
 
308
            # When checker has failed, show timer until client expires
306
309
            expires = self.properties["Expires"]
307
310
            if expires == "":
308
311
                timer = datetime.timedelta(0)
309
312
            else:
310
 
                expires = datetime.datetime.strptime(expires,
311
 
                                                     '%Y-%m-%dT%H:%M:%S.%f')
 
313
                expires = (datetime.datetime.strptime
 
314
                           (expires, '%Y-%m-%dT%H:%M:%S.%f'))
312
315
                timer = expires - datetime.datetime.utcnow()
313
316
            message = ('A checker has failed! Time until client'
314
 
                       ' gets disabled: %s'
315
 
                           % unicode(timer).rsplit(".", 1)[0])
 
317
                       ' gets disabled: {0}'
 
318
                       .format(unicode(timer).rsplit(".", 1)[0]))
316
319
        else:
317
320
            message = "enabled"
318
 
        self._text = "%s%s" % (base, message)
 
321
        self._text = "{0}{1}".format(base, message)
319
322
            
320
323
        if not urwid.supports_unicode():
321
324
            self._text = self._text.encode("ascii", "replace")
486
489
        self.main_loop = gobject.MainLoop()
487
490
    
488
491
    def client_not_found(self, fingerprint, address):
489
 
        self.log_message(("Client with address %s and fingerprint %s"
490
 
                          " could not be found" % (address,
491
 
                                                    fingerprint)))
 
492
        self.log_message("Client with address {0} and fingerprint"
 
493
                         " {1} could not be found"
 
494
                         .format(address, fingerprint))
492
495
    
493
496
    def rebuild(self):
494
497
        """This rebuilds the User Interface.
547
550
            client = self.clients_dict[path]
548
551
        except KeyError:
549
552
            # not found?
550
 
            self.log_message("Unknown client %r (%r) removed", name,
551
 
                             path)
 
553
            self.log_message("Unknown client {0!r} ({1!r}) removed"
 
554
                             .format(name, path))
552
555
            return
553
556
        client.delete()
554
557