1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# Copyright (C) 2018 Greenbone Networks GmbH |
3
|
|
|
# |
4
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later |
5
|
|
|
# |
6
|
|
|
# This program is free software: you can redistribute it and/or modify |
7
|
|
|
# it under the terms of the GNU General Public License as published by |
8
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
# (at your option) any later version. |
10
|
|
|
# |
11
|
|
|
# This program is distributed in the hope that it will be useful, |
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
# GNU General Public License for more details. |
15
|
|
|
# |
16
|
|
|
# You should have received a copy of the GNU General Public License |
17
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
|
19
|
|
|
import defusedxml.lxml as secET |
20
|
|
|
|
21
|
|
|
from lxml import etree |
22
|
|
|
|
23
|
|
|
class XmlCommandElement: |
24
|
|
|
|
25
|
|
|
def __init__(self, element): |
26
|
|
|
self._element = element |
27
|
|
|
|
28
|
|
|
def add_element(self, name, text=None, attrs=None): |
29
|
|
|
node = etree.SubElement(self._element, name, attrib=attrs) |
30
|
|
|
node.text = text |
31
|
|
|
return XmlCommandElement(node) |
32
|
|
|
|
33
|
|
|
def set_attribute(self, name, value): |
34
|
|
|
self._element.set(name, value) |
35
|
|
|
|
36
|
|
|
def set_attributes(self, attrs): |
37
|
|
|
"""Set several attributes at once. |
38
|
|
|
|
39
|
|
|
Arguments: |
40
|
|
|
attrs (dict): Attributes to be set on the element |
41
|
|
|
""" |
42
|
|
|
for key, value in attrs.items(): |
43
|
|
|
self._element.set(key, value) |
44
|
|
|
|
45
|
|
|
def append_xml_str(self, xml_text): |
46
|
|
|
"""Append a xml element in string format.""" |
47
|
|
|
node = secET.fromstring(xml_text) |
48
|
|
|
self._element.append(node) |
49
|
|
|
|
50
|
|
|
def to_string(self): |
51
|
|
|
return etree.tostring(self._element).decode('utf-8') |
52
|
|
|
|
53
|
|
|
def __str__(self): |
54
|
|
|
return self.to_string() |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
class XmlCommand(XmlCommandElement): |
58
|
|
|
|
59
|
|
|
def __init__(self, name): |
60
|
|
|
super().__init__(etree.Element(name)) |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
class _GmpCommandFactory: |
|
|
|
|
64
|
|
|
|
65
|
|
|
"""Factory to create gmp - Greenbone Management Protocol - commands |
66
|
|
|
""" |
67
|
|
|
|
68
|
|
|
def delete_agent_command(self, kwargs): |
|
|
|
|
69
|
|
|
"""Generates xml string for delete agent on gvmd""" |
70
|
|
|
cmd = XmlCommand('delete_agent') |
71
|
|
|
for key, value in kwargs.items(): |
72
|
|
|
cmd.set_attribute(key, value) |
73
|
|
|
|
74
|
|
|
return cmd.to_string() |
75
|
|
|
|
76
|
|
|
def delete_alert_command(self, kwargs): |
|
|
|
|
77
|
|
|
"""Generates xml string for delete alert on gvmd""" |
78
|
|
|
cmd = XmlCommand('delete_alert') |
79
|
|
|
for key, value in kwargs.items(): |
80
|
|
|
cmd.set_attribute(key, value) |
81
|
|
|
|
82
|
|
|
return cmd.to_string() |
83
|
|
|
|
84
|
|
|
def delete_asset_command(self, asset_id, ultimate=0): |
|
|
|
|
85
|
|
|
"""Generates xml string for delete asset on gvmd""" |
86
|
|
|
cmd = XmlCommand('delete_asset') |
87
|
|
|
cmd.set_attribute('asset_id', asset_id) |
88
|
|
|
cmd.set_attribute('ultimate', ultimate) |
89
|
|
|
|
90
|
|
|
return cmd.to_string() |
91
|
|
|
|
92
|
|
|
def delete_config_command(self, config_id, ultimate=0): |
|
|
|
|
93
|
|
|
"""Generates xml string for delete config on gvmd""" |
94
|
|
|
cmd = XmlCommand('delete_config') |
95
|
|
|
cmd.set_attribute('config_id', config_id) |
96
|
|
|
cmd.set_attribute('ultimate', ultimate) |
97
|
|
|
|
98
|
|
|
return cmd.to_string() |
99
|
|
|
|
100
|
|
|
def delete_credential_command(self, credential_id, ultimate=0): |
|
|
|
|
101
|
|
|
"""Generates xml string for delete credential on gvmd""" |
102
|
|
|
cmd = XmlCommand('delete_credential') |
103
|
|
|
cmd.set_attribute('credential_id', credential_id) |
104
|
|
|
cmd.set_attribute('ultimate', ultimate) |
105
|
|
|
return cmd.to_string() |
106
|
|
|
|
107
|
|
|
def delete_filter_command(self, filter_id, ultimate=0): |
|
|
|
|
108
|
|
|
"""Generates xml string for delete filter on gvmd""" |
109
|
|
|
cmd = XmlCommand('delete_filter') |
110
|
|
|
cmd.set_attribute('filter_id', filter_id) |
111
|
|
|
cmd.set_attribute('ultimate', ultimate) |
112
|
|
|
|
113
|
|
|
return cmd.to_string() |
114
|
|
|
|
115
|
|
|
def delete_group_command(self, group_id, ultimate=0): |
|
|
|
|
116
|
|
|
"""Generates xml string for delete group on gvmd""" |
117
|
|
|
cmd = XmlCommand('delete_group') |
118
|
|
|
cmd.set_attribute('group_id', group_id) |
119
|
|
|
cmd.set_attribute('ultimate', ultimate) |
120
|
|
|
|
121
|
|
|
return cmd.to_string() |
122
|
|
|
|
123
|
|
|
def delete_note_command(self, note_id, ultimate=0): |
|
|
|
|
124
|
|
|
"""Generates xml string for delete note on gvmd""" |
125
|
|
|
cmd = XmlCommand('delete_note') |
126
|
|
|
cmd.set_attribute('note_id', note_id) |
127
|
|
|
cmd.set_attribute('ultimate', ultimate) |
128
|
|
|
|
129
|
|
|
return cmd.to_string() |
130
|
|
|
|
131
|
|
|
def delete_override_command(self, override_id, ultimate=0): |
|
|
|
|
132
|
|
|
"""Generates xml string for delete override on gvmd""" |
133
|
|
|
cmd = XmlCommand('delete_override') |
134
|
|
|
cmd.set_attribute('override_id', override_id) |
135
|
|
|
cmd.set_attribute('ultimate', ultimate) |
136
|
|
|
|
137
|
|
|
return cmd.to_string() |
138
|
|
|
|
139
|
|
|
def delete_permission_command(self, permission_id, ultimate=0): |
|
|
|
|
140
|
|
|
"""Generates xml string for delete permission on gvmd""" |
141
|
|
|
cmd = XmlCommand('delete_permission') |
142
|
|
|
cmd.set_attribute('permission_id', permission_id) |
143
|
|
|
cmd.set_attribute('ultimate', ultimate) |
144
|
|
|
|
145
|
|
|
return cmd.to_string() |
146
|
|
|
|
147
|
|
|
def delete_port_list_command(self, port_list_id, ultimate=0): |
|
|
|
|
148
|
|
|
"""Generates xml string for delete port on gvmd""" |
149
|
|
|
cmd = XmlCommand('delete_port_list') |
150
|
|
|
cmd.set_attribute('port_list_id', port_list_id) |
151
|
|
|
cmd.set_attribute('ultimate', ultimate) |
152
|
|
|
|
153
|
|
|
return cmd.to_string() |
154
|
|
|
|
155
|
|
|
def delete_port_range_command(self, port_range_id): |
|
|
|
|
156
|
|
|
"""Generates xml string for delete port on gvmd""" |
157
|
|
|
cmd = XmlCommand('delete_port_range') |
158
|
|
|
cmd.set_attribute('port_range_id', port_range_id) |
159
|
|
|
|
160
|
|
|
return cmd.to_string() |
161
|
|
|
|
162
|
|
|
def delete_report_command(self, report_id): |
|
|
|
|
163
|
|
|
"""Generates xml string for delete report on gvmd""" |
164
|
|
|
cmd = XmlCommand('delete_report') |
165
|
|
|
cmd.set_attribute('report_id', report_id) |
166
|
|
|
|
167
|
|
|
return cmd.to_string() |
168
|
|
|
|
169
|
|
|
def delete_report_format_command(self, report_format_id, ultimate=0): |
|
|
|
|
170
|
|
|
"""Generates xml string for delete report on gvmd""" |
171
|
|
|
cmd = XmlCommand('delete_report_format') |
172
|
|
|
cmd.set_attribute('report_format_id', report_format_id) |
173
|
|
|
cmd.set_attribute('ultimate', ultimate) |
174
|
|
|
|
175
|
|
|
return cmd.to_string() |
176
|
|
|
|
177
|
|
|
def delete_role_command(self, role_id, ultimate=0): |
|
|
|
|
178
|
|
|
"""Generates xml string for delete role on gvmd""" |
179
|
|
|
cmd = XmlCommand('delete_role') |
180
|
|
|
cmd.set_attribute('role_id', role_id) |
181
|
|
|
cmd.set_attribute('ultimate', ultimate) |
182
|
|
|
|
183
|
|
|
return cmd.to_string() |
184
|
|
|
|
185
|
|
|
def delete_scanner_command(self, scanner_id, ultimate=0): |
|
|
|
|
186
|
|
|
"""Generates xml string for delete scanner on gvmd""" |
187
|
|
|
cmd = XmlCommand('delete_scanner') |
188
|
|
|
cmd.set_attribute('scanner_id', scanner_id) |
189
|
|
|
cmd.set_attribute('ultimate', ultimate) |
190
|
|
|
|
191
|
|
|
return cmd.to_string() |
192
|
|
|
|
193
|
|
|
def delete_schedule_command(self, schedule_id, ultimate=0): |
|
|
|
|
194
|
|
|
"""Generates xml string for delete schedule on gvmd""" |
195
|
|
|
# if self.ask_yes_or_no('Are you sure to delete this schedule? '): |
196
|
|
|
cmd = XmlCommand('delete_schedule') |
197
|
|
|
cmd.set_attribute('schedule_id', schedule_id) |
198
|
|
|
cmd.set_attribute('ultimate', ultimate) |
199
|
|
|
|
200
|
|
|
return cmd.to_string() |
201
|
|
|
|
202
|
|
|
def delete_tag_command(self, tag_id, ultimate=0): |
|
|
|
|
203
|
|
|
"""Generates xml string for delete tag on gvmd""" |
204
|
|
|
cmd = XmlCommand('delete_tag') |
205
|
|
|
cmd.set_attribute('tag_id', tag_id) |
206
|
|
|
cmd.set_attribute('ultimate', ultimate) |
207
|
|
|
|
208
|
|
|
return cmd.to_string() |
209
|
|
|
|
210
|
|
|
def delete_target_command(self, target_id, ultimate=0): |
|
|
|
|
211
|
|
|
"""Generates xml string for delete target on gvmd""" |
212
|
|
|
cmd = XmlCommand('delete_target') |
213
|
|
|
cmd.set_attribute('target_id', target_id) |
214
|
|
|
cmd.set_attribute('ultimate', ultimate) |
215
|
|
|
|
216
|
|
|
return cmd.to_string() |
217
|
|
|
|
218
|
|
|
def delete_task_command(self, task_id, ultimate=0): |
|
|
|
|
219
|
|
|
"""Generates xml string for delete task on gvmd""" |
220
|
|
|
cmd = XmlCommand('delete_task') |
221
|
|
|
cmd.set_attribute('task_id', task_id) |
222
|
|
|
cmd.set_attribute('ultimate', ultimate) |
223
|
|
|
|
224
|
|
|
return cmd.to_string() |
225
|
|
|
|
226
|
|
|
def delete_user_command(self, kwargs): |
|
|
|
|
227
|
|
|
"""Generates xml string for delete user on gvmd""" |
228
|
|
|
cmd = XmlCommand('delete_user') |
229
|
|
|
|
230
|
|
|
user_id = kwargs.get('user_id', '') |
231
|
|
|
if user_id: |
232
|
|
|
cmd.set_attribute('user_id', user_id) |
233
|
|
|
|
234
|
|
|
name = kwargs.get('name', '') |
235
|
|
|
if name: |
236
|
|
|
cmd.set_attribute('name', name) |
237
|
|
|
|
238
|
|
|
inheritor_id = kwargs.get('inheritor_id', '') |
239
|
|
|
if inheritor_id: |
240
|
|
|
cmd.set_attribute('inheritor_id', inheritor_id) |
241
|
|
|
|
242
|
|
|
inheritor_name = kwargs.get('inheritor_name', '') |
243
|
|
|
if inheritor_name: |
244
|
|
|
cmd.set_attribute('inheritor_name', inheritor_name) |
245
|
|
|
|
246
|
|
|
return cmd.to_string() |
247
|
|
|
|
248
|
|
|
def get_assets_command(self, kwargs): |
|
|
|
|
249
|
|
|
"""Generates xml string for get assets on gvmd.""" |
250
|
|
|
cmd = XmlCommand('get_assets') |
251
|
|
|
cmd.set_attributes(kwargs) |
252
|
|
|
return cmd.to_string() |
253
|
|
|
|
254
|
|
|
def get_credentials_command(self, kwargs): |
|
|
|
|
255
|
|
|
"""Generates xml string for get credentials on gvmd.""" |
256
|
|
|
cmd = XmlCommand('get_credentials') |
257
|
|
|
cmd.set_attributes(kwargs) |
258
|
|
|
return cmd.to_string() |
259
|
|
|
|
260
|
|
|
def get_configs_command(self, kwargs): |
|
|
|
|
261
|
|
|
"""Generates xml string for get configs on gvmd.""" |
262
|
|
|
cmd = XmlCommand('get_configs') |
263
|
|
|
cmd.set_attributes(kwargs) |
264
|
|
|
return cmd.to_string() |
265
|
|
|
|
266
|
|
|
def get_feeds_command(self, kwargs): |
|
|
|
|
267
|
|
|
"""Generates xml string for get feeds on gvmd.""" |
268
|
|
|
cmd = XmlCommand('get_feeds') |
269
|
|
|
cmd.set_attributes(kwargs) |
270
|
|
|
return cmd.to_string() |
271
|
|
|
|
272
|
|
|
def get_filters_command(self, kwargs): |
|
|
|
|
273
|
|
|
"""Generates xml string for get filters on gvmd.""" |
274
|
|
|
cmd = XmlCommand('get_filters') |
275
|
|
|
cmd.set_attributes(kwargs) |
276
|
|
|
return cmd.to_string() |
277
|
|
|
|
278
|
|
|
def get_groups_command(self, kwargs): |
|
|
|
|
279
|
|
|
"""Generates xml string for get groups on gvmd.""" |
280
|
|
|
cmd = XmlCommand('get_groups') |
281
|
|
|
cmd.set_attributes(kwargs) |
282
|
|
|
return cmd.to_string() |
283
|
|
|
|
284
|
|
|
def get_info_command(self, kwargs): |
|
|
|
|
285
|
|
|
"""Generates xml string for get info on gvmd.""" |
286
|
|
|
cmd = XmlCommand('get_info') |
287
|
|
|
cmd.set_attributes(kwargs) |
288
|
|
|
return cmd.to_string() |
289
|
|
|
|
290
|
|
|
def get_notes_command(self, kwargs): |
|
|
|
|
291
|
|
|
"""Generates xml string for get notes on gvmd.""" |
292
|
|
|
cmd = XmlCommand('get_notes') |
293
|
|
|
cmd.set_attributes(kwargs) |
294
|
|
|
return cmd.to_string() |
295
|
|
|
|
296
|
|
|
def get_nvts_command(self, kwargs): |
|
|
|
|
297
|
|
|
"""Generates xml string for get nvts on gvmd.""" |
298
|
|
|
cmd = XmlCommand('get_nvts') |
299
|
|
|
cmd.set_attributes(kwargs) |
300
|
|
|
return cmd.to_string() |
301
|
|
|
|
302
|
|
|
def get_nvt_families_command(self, kwargs): |
|
|
|
|
303
|
|
|
"""Generates xml string for get nvt on gvmd.""" |
304
|
|
|
cmd = XmlCommand('get_nvt_families') |
305
|
|
|
cmd.set_attributes(kwargs) |
306
|
|
|
return cmd.to_string() |
307
|
|
|
|
308
|
|
|
def get_overrides_command(self, kwargs): |
|
|
|
|
309
|
|
|
"""Generates xml string for get overrides on gvmd.""" |
310
|
|
|
cmd = XmlCommand('get_overrides') |
311
|
|
|
cmd.set_attributes(kwargs) |
312
|
|
|
return cmd.to_string() |
313
|
|
|
|
314
|
|
|
def get_permissions_command(self, kwargs): |
|
|
|
|
315
|
|
|
"""Generates xml string for get permissions on gvmd.""" |
316
|
|
|
cmd = XmlCommand('get_permissions') |
317
|
|
|
cmd.set_attributes(kwargs) |
318
|
|
|
return cmd.to_string() |
319
|
|
|
|
320
|
|
|
def get_port_lists_command(self, kwargs): |
|
|
|
|
321
|
|
|
"""Generates xml string for get port on gvmd.""" |
322
|
|
|
cmd = XmlCommand('get_port_lists') |
323
|
|
|
cmd.set_attributes(kwargs) |
324
|
|
|
return cmd.to_string() |
325
|
|
|
|
326
|
|
|
def get_preferences_command(self, kwargs): |
|
|
|
|
327
|
|
|
"""Generates xml string for get preferences on gvmd.""" |
328
|
|
|
cmd = XmlCommand('get_preferences') |
329
|
|
|
cmd.set_attributes(kwargs) |
330
|
|
|
return cmd.to_string() |
331
|
|
|
|
332
|
|
|
def get_reports_command(self, kwargs): |
|
|
|
|
333
|
|
|
"""Generates xml string for get reports on gvmd.""" |
334
|
|
|
cmd = XmlCommand('get_reports') |
335
|
|
|
cmd.set_attributes(kwargs) |
336
|
|
|
return cmd.to_string() |
337
|
|
|
|
338
|
|
|
def get_report_formats_command(self, kwargs): |
|
|
|
|
339
|
|
|
"""Generates xml string for get report on gvmd.""" |
340
|
|
|
cmd = XmlCommand('get_report_formats') |
341
|
|
|
cmd.set_attributes(kwargs) |
342
|
|
|
return cmd.to_string() |
343
|
|
|
|
344
|
|
|
def get_results_command(self, kwargs): |
|
|
|
|
345
|
|
|
"""Generates xml string for get results on gvmd.""" |
346
|
|
|
cmd = XmlCommand('get_results') |
347
|
|
|
cmd.set_attributes(kwargs) |
348
|
|
|
return cmd.to_string() |
349
|
|
|
|
350
|
|
|
def get_roles_command(self, kwargs): |
|
|
|
|
351
|
|
|
"""Generates xml string for get roles on gvmd.""" |
352
|
|
|
cmd = XmlCommand('get_roles') |
353
|
|
|
cmd.set_attributes(kwargs) |
354
|
|
|
return cmd.to_string() |
355
|
|
|
|
356
|
|
|
def get_scanners_command(self, kwargs): |
|
|
|
|
357
|
|
|
"""Generates xml string for get scanners on gvmd.""" |
358
|
|
|
cmd = XmlCommand('get_scanners') |
359
|
|
|
cmd.set_attributes(kwargs) |
360
|
|
|
return cmd.to_string() |
361
|
|
|
|
362
|
|
|
def get_schedules_command(self, kwargs): |
|
|
|
|
363
|
|
|
"""Generates xml string for get schedules on gvmd.""" |
364
|
|
|
cmd = XmlCommand('get_schedules') |
365
|
|
|
cmd.set_attributes(kwargs) |
366
|
|
|
return cmd.to_string() |
367
|
|
|
|
368
|
|
|
def get_settings_command(self, kwargs): |
|
|
|
|
369
|
|
|
"""Generates xml string for get settings on gvmd.""" |
370
|
|
|
cmd = XmlCommand('get_settings') |
371
|
|
|
cmd.set_attributes(kwargs) |
372
|
|
|
return cmd.to_string() |
373
|
|
|
|
374
|
|
|
def get_system_reports_command(self, kwargs): |
|
|
|
|
375
|
|
|
"""Generates xml string for get system on gvmd.""" |
376
|
|
|
cmd = XmlCommand('get_system') |
377
|
|
|
cmd.set_attributes(kwargs) |
378
|
|
|
return cmd.to_string() |
379
|
|
|
|
380
|
|
|
def get_tags_command(self, kwargs): |
|
|
|
|
381
|
|
|
"""Generates xml string for get tags on gvmd.""" |
382
|
|
|
cmd = XmlCommand('get_tags') |
383
|
|
|
cmd.set_attributes(kwargs) |
384
|
|
|
return cmd.to_string() |
385
|
|
|
|
386
|
|
|
def get_targets_command(self, kwargs): |
|
|
|
|
387
|
|
|
"""Generates xml string for get targets on gvmd.""" |
388
|
|
|
cmd = XmlCommand('get_targets') |
389
|
|
|
cmd.set_attributes(kwargs) |
390
|
|
|
return cmd.to_string() |
391
|
|
|
|
392
|
|
|
def get_tasks_command(self, kwargs): |
|
|
|
|
393
|
|
|
"""Generates xml string for get tasks on gvmd.""" |
394
|
|
|
cmd = XmlCommand('get_tasks') |
395
|
|
|
cmd.set_attributes(kwargs) |
396
|
|
|
return cmd.to_string() |
397
|
|
|
|
398
|
|
|
def get_users_command(self, kwargs): |
|
|
|
|
399
|
|
|
"""Generates xml string for get users on gvmd.""" |
400
|
|
|
cmd = XmlCommand('get_users') |
401
|
|
|
cmd.set_attributes(kwargs) |
402
|
|
|
return cmd.to_string() |
403
|
|
|
|
404
|
|
|
def move_task_command(self, task_id, slave_id): |
|
|
|
|
405
|
|
|
"""Generates xml string for move task on gvmd.""" |
406
|
|
|
cmd = XmlCommand('move_task') |
407
|
|
|
cmd.set_attribute('task_id', task_id) |
408
|
|
|
cmd.set_attribute('slave_id', slave_id) |
409
|
|
|
return cmd.to_string() |
410
|
|
|
|
411
|
|
|
def restore_command(self, entity_id): |
|
|
|
|
412
|
|
|
"""Generates xml string for restore on gvmd.""" |
413
|
|
|
cmd = XmlCommand('restore') |
414
|
|
|
cmd.set_attribute('id', entity_id) |
415
|
|
|
return cmd.to_string() |
416
|
|
|
|
417
|
|
|
def resume_task_command(self, task_id): |
|
|
|
|
418
|
|
|
"""Generates xml string for resume task on gvmd.""" |
419
|
|
|
cmd = XmlCommand('resume_task') |
420
|
|
|
cmd.set_attribute('task_id', task_id) |
421
|
|
|
return cmd.to_string() |
422
|
|
|
|
423
|
|
|
def start_task_command(self, task_id): |
|
|
|
|
424
|
|
|
"""Generates xml string for start task on gvmd.""" |
425
|
|
|
cmd = XmlCommand('start_task') |
426
|
|
|
cmd.set_attribute('task_id', task_id) |
427
|
|
|
return cmd.to_string() |
428
|
|
|
|
429
|
|
|
def stop_task_command(self, task_id): |
|
|
|
|
430
|
|
|
"""Generates xml string for stop task on gvmd.""" |
431
|
|
|
cmd = XmlCommand('stop_task') |
432
|
|
|
cmd.set_attribute('task_id', task_id) |
433
|
|
|
return cmd.to_string() |
434
|
|
|
|
435
|
|
|
def test_alert_command(self, alert_id): |
|
|
|
|
436
|
|
|
"""Generates xml string for test alert on gvmd.""" |
437
|
|
|
cmd = XmlCommand('test_alert') |
438
|
|
|
cmd.set_attribute('alert_id', alert_id) |
439
|
|
|
return cmd.to_string() |
440
|
|
|
|
441
|
|
|
def verify_agent_command(self, agent_id): |
|
|
|
|
442
|
|
|
"""Generates xml string for verify agent on gvmd.""" |
443
|
|
|
cmd = XmlCommand('verify_agent') |
444
|
|
|
cmd.set_attribute('agent_id', agent_id) |
445
|
|
|
return cmd.to_string() |
446
|
|
|
|
447
|
|
|
def verify_report_format_command(self, report_format_id): |
|
|
|
|
448
|
|
|
"""Generates xml string for verify report format on gvmd.""" |
449
|
|
|
cmd = XmlCommand('verify_report_format') |
450
|
|
|
cmd.set_attribute('report_format_id', report_format_id) |
451
|
|
|
return cmd.to_string() |
452
|
|
|
|
453
|
|
|
def verify_scanner_command(self, scanner_id): |
|
|
|
|
454
|
|
|
"""Generates xml string for verify scanner on gvmd.""" |
455
|
|
|
cmd = XmlCommand('verify_scanner') |
456
|
|
|
cmd.set_attribute('scanner_id', scanner_id) |
457
|
|
|
return cmd.to_string() |
458
|
|
|
|
459
|
|
|
|
460
|
|
|
def pretty_print(xml): |
461
|
|
|
"""Prints beautiful XML-Code |
462
|
|
|
|
463
|
|
|
This function gets an object of list<lxml.etree._Element> |
464
|
|
|
or directly a lxml element. |
465
|
|
|
Print it with good readable format. |
466
|
|
|
|
467
|
|
|
Arguments: |
468
|
|
|
xml: List<lxml.etree.Element> or directly a lxml element |
469
|
|
|
""" |
470
|
|
|
if isinstance(xml, list): |
471
|
|
|
for item in xml: |
472
|
|
|
if etree.iselement(item): |
473
|
|
|
print(etree.tostring(item, pretty_print=True).decode('utf-8')) |
474
|
|
|
else: |
475
|
|
|
print(item) |
476
|
|
|
elif etree.iselement(xml): |
477
|
|
|
print(etree.tostring(xml, pretty_print=True).decode('utf-8')) |
478
|
|
|
|