34
locale.setlocale(locale.LC_ALL, u"")
13
locale.setlocale(locale.LC_ALL, u'')
38
u"Enabled": u"Enabled",
39
u"Timeout": u"Timeout",
40
u"LastCheckedOK": u"Last Successful Check",
41
u"LastApprovalRequest": u"Last Approval Request",
42
u"Created": u"Created",
43
u"Interval": u"Interval",
45
u"Fingerprint": u"Fingerprint",
46
u"CheckerRunning": u"Check Is Running",
47
u"LastEnabled": u"Last Enabled",
48
u"ApprovalPending": u"Approval Is Pending",
49
u"ApprovedByDefault": u"Approved By Default",
50
u"ApprovalDelay": u"Approval Delay",
51
u"ApprovalDuration": u"Approval Duration",
52
u"Checker": u"Checker",
17
'Enabled': u'Enabled',
18
'Timeout': u'Timeout',
19
'LastCheckedOK': u'Last Successful Check',
20
'LastApprovalRequest': u'Last Approval Request',
21
'Created': u'Created',
22
'Interval': u'Interval',
24
'Fingerprint': u'Fingerprint',
25
'CheckerRunning': u'Check Is Running',
26
'LastEnabled': u'Last Enabled',
27
'ApprovalPending': u'Approval Is Pending',
28
'ApprovedByDefault': u'Approved By Default',
29
'ApprovalDelay': u"Approval Delay",
30
'ApprovalDuration': u"Approval Duration",
31
'Checker': u'Checker',
54
defaultkeywords = (u"Name", u"Enabled", u"Timeout", u"LastCheckedOK")
55
domain = u"se.bsnet.fukt"
56
busname = domain + u".Mandos"
58
server_interface = domain + u".Mandos"
59
client_interface = domain + u".Mandos.Client"
33
defaultkeywords = ('Name', 'Enabled', 'Timeout', 'LastCheckedOK')
34
domain = 'se.bsnet.fukt'
35
busname = domain + '.Mandos'
37
server_interface = domain + '.Mandos'
38
client_interface = domain + '.Mandos.Client'
62
41
def timedelta_to_milliseconds(td):
63
"""Convert a datetime.timedelta object to milliseconds"""
42
"Convert a datetime.timedelta object to milliseconds"
64
43
return ((td.days * 24 * 60 * 60 * 1000)
65
44
+ (td.seconds * 1000)
66
45
+ (td.microseconds // 1000))
68
47
def milliseconds_to_string(ms):
69
48
td = datetime.timedelta(0, 0, 0, ms)
70
49
return (u"%(days)s%(hours)02d:%(minutes)02d:%(seconds)02d"
71
% { u"days": u"%dT" % td.days if td.days else u"",
72
u"hours": td.seconds // 3600,
73
u"minutes": (td.seconds % 3600) // 60,
74
u"seconds": td.seconds % 60,
50
% { "days": "%dT" % td.days if td.days else "",
51
"hours": td.seconds // 3600,
52
"minutes": (td.seconds % 3600) // 60,
53
"seconds": td.seconds % 60,
78
57
def string_to_delta(interval):
79
58
"""Parse a string and return a datetime.timedelta
81
>>> string_to_delta("7d")
60
>>> string_to_delta('7d')
82
61
datetime.timedelta(7)
83
>>> string_to_delta("60s")
62
>>> string_to_delta('60s')
84
63
datetime.timedelta(0, 60)
85
>>> string_to_delta("60m")
64
>>> string_to_delta('60m')
86
65
datetime.timedelta(0, 3600)
87
>>> string_to_delta("24h")
66
>>> string_to_delta('24h')
88
67
datetime.timedelta(1)
89
>>> string_to_delta(u"1w")
68
>>> string_to_delta(u'1w')
90
69
datetime.timedelta(7)
91
>>> string_to_delta("5m 30s")
70
>>> string_to_delta('5m 30s')
92
71
datetime.timedelta(0, 330)
94
73
timevalue = datetime.timedelta(0)
95
regexp = re.compile(u"\d+[dsmhw]")
74
regexp = re.compile("\d+[dsmhw]")
97
76
for s in regexp.findall(interval):
161
parser = OptionParser(version = u"%%prog %s" % version)
162
parser.add_option(u"-a", u"--all", action=u"store_true",
163
help=u"Select all clients")
164
parser.add_option(u"-v", u"--verbose", action=u"store_true",
165
help=u"Print all fields")
166
parser.add_option(u"-e", u"--enable", action=u"store_true",
167
help=u"Enable client")
168
parser.add_option(u"-d", u"--disable", action=u"store_true",
169
help=u"disable client")
170
parser.add_option(u"-b", u"--bump-timeout", action=u"store_true",
171
help=u"Bump timeout for client")
172
parser.add_option(u"--start-checker", action=u"store_true",
173
help=u"Start checker for client")
174
parser.add_option(u"--stop-checker", action=u"store_true",
175
help=u"Stop checker for client")
176
parser.add_option(u"-V", u"--is-enabled", action=u"store_true",
177
help=u"Check if client is enabled")
178
parser.add_option(u"-r", u"--remove", action=u"store_true",
179
help=u"Remove client")
180
parser.add_option(u"-c", u"--checker", type=u"string",
181
help=u"Set checker command for client")
182
parser.add_option(u"-t", u"--timeout", type=u"string",
183
help=u"Set timeout for client")
184
parser.add_option(u"-i", u"--interval", type=u"string",
185
help=u"Set checker interval for client")
186
parser.add_option(u"--approve-by-default", action=u"store_true",
187
dest=u"approved_by_default",
188
help=u"Set client to be approved by default")
189
parser.add_option(u"--deny-by-default", action=u"store_false",
190
dest=u"approved_by_default",
191
help=u"Set client to be denied by default")
192
parser.add_option(u"--approval-delay", type=u"string",
193
help=u"Set delay before client approve/deny")
194
parser.add_option(u"--approval-duration", type=u"string",
195
help=u"Set duration of one client approval")
196
parser.add_option(u"-H", u"--host", type=u"string",
197
help=u"Set host for client")
198
parser.add_option(u"-s", u"--secret", type=u"string",
199
help=u"Set password blob (file) for client")
200
parser.add_option(u"-A", u"--approve", action=u"store_true",
201
help=u"Approve any current client request")
202
parser.add_option(u"-D", u"--deny", action=u"store_true",
203
help=u"Deny any current client request")
140
parser = OptionParser(version = "%%prog %s" % version)
141
parser.add_option("-a", "--all", action="store_true",
142
help="Select all clients")
143
parser.add_option("-v", "--verbose", action="store_true",
144
help="Print all fields")
145
parser.add_option("-e", "--enable", action="store_true",
146
help="Enable client")
147
parser.add_option("-d", "--disable", action="store_true",
148
help="disable client")
149
parser.add_option("-b", "--bump-timeout", action="store_true",
150
help="Bump timeout for client")
151
parser.add_option("--start-checker", action="store_true",
152
help="Start checker for client")
153
parser.add_option("--stop-checker", action="store_true",
154
help="Stop checker for client")
155
parser.add_option("-V", "--is-enabled", action="store_true",
156
help="Check if client is enabled")
157
parser.add_option("-r", "--remove", action="store_true",
158
help="Remove client")
159
parser.add_option("-c", "--checker", type="string",
160
help="Set checker command for client")
161
parser.add_option("-t", "--timeout", type="string",
162
help="Set timeout for client")
163
parser.add_option("-i", "--interval", type="string",
164
help="Set checker interval for client")
165
parser.add_option("--approve-by-default", action="store_true",
166
dest=u"approved_by_default",
167
help="Set client to be approved by default")
168
parser.add_option("--deny-by-default", action="store_false",
169
dest=u"approved_by_default",
170
help="Set client to be denied by default")
171
parser.add_option("--approval-delay", type="string",
172
help="Set delay before client approve/deny")
173
parser.add_option("--approval-duration", type="string",
174
help="Set duration of one client approval")
175
parser.add_option("-H", "--host", type="string",
176
help="Set host for client")
177
parser.add_option("-s", "--secret", type="string",
178
help="Set password blob (file) for client")
179
parser.add_option("-A", "--approve", action="store_true",
180
help="Approve any current client request")
181
parser.add_option("-D", "--deny", action="store_true",
182
help="Deny any current client request")
204
183
options, client_names = parser.parse_args()
206
185
if has_actions(options) and not client_names and not options.all:
207
parser.error(u"Options require clients names or --all.")
186
parser.error('Options require clients names or --all.')
208
187
if options.verbose and has_actions(options):
209
parser.error(u"--verbose can only be used alone or with"
188
parser.error('--verbose can only be used alone or with'
211
190
if options.all and not has_actions(options):
212
parser.error(u"--all requires an action.")
191
parser.error('--all requires an action.')
215
194
bus = dbus.SystemBus()
216
195
mandos_dbus_objc = bus.get_object(busname, server_path)
217
196
except dbus.exceptions.DBusException:
218
print >> sys.stderr, u"Could not connect to Mandos server"
197
print >> sys.stderr, "Could not connect to Mandos server"
221
200
mandos_serv = dbus.Interface(mandos_dbus_objc,
248
227
for name in client_names:
249
228
for path, client in mandos_clients.iteritems():
250
if client[u"Name"] == name:
229
if client['Name'] == name:
251
230
client_objc = bus.get_object(busname, path)
252
231
clients[client_objc] = client
255
print >> sys.stderr, u"Client not found on server: %r" % name
234
print >> sys.stderr, "Client not found on server: %r" % name
258
237
if not has_actions(options) and clients:
259
238
if options.verbose:
260
keywords = (u"Name", u"Enabled", u"Timeout",
261
u"LastCheckedOK", u"Created", u"Interval",
262
u"Host", u"Fingerprint", u"CheckerRunning",
263
u"LastEnabled", u"ApprovalPending",
264
u"ApprovedByDefault",
265
u"LastApprovalRequest", u"ApprovalDelay",
266
u"ApprovalDuration", u"Checker")
239
keywords = ('Name', 'Enabled', 'Timeout',
240
'LastCheckedOK', 'Created', 'Interval',
241
'Host', 'Fingerprint', 'CheckerRunning',
242
'LastEnabled', 'ApprovalPending',
244
'LastApprovalRequest', 'ApprovalDelay',
245
'ApprovalDuration', 'Checker')
268
247
keywords = defaultkeywords