|
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 create_port_list_command(self, name, port_range, kwargs): |
|
|
|
|
|
|
69
|
|
|
"""Generates xml string for create port list on gvmd.""" |
|
70
|
|
|
if not name: |
|
71
|
|
|
raise ValueError('create_port_list requires a name element') |
|
72
|
|
|
if not port_range: |
|
73
|
|
|
raise ValueError('create_port_list requires a port_range element') |
|
74
|
|
|
|
|
75
|
|
|
cmd = XmlCommand('create_port_list') |
|
76
|
|
|
cmd.add_element('name', name) |
|
77
|
|
|
cmd.add_element('port_range', port_range) |
|
78
|
|
|
|
|
79
|
|
|
comment = kwargs.get('comment', '') |
|
80
|
|
|
if comment: |
|
81
|
|
|
cmd.add_element('comment', comment) |
|
82
|
|
|
|
|
83
|
|
|
copy = kwargs.get('copy', '') |
|
84
|
|
|
if copy: |
|
85
|
|
|
cmd.add_element('copy', copy) |
|
86
|
|
|
|
|
87
|
|
|
return cmd.to_string() |
|
88
|
|
|
|
|
89
|
|
|
def create_port_range_command(self, port_list_id, start, end, type, |
|
|
|
|
|
|
90
|
|
|
comment=''): |
|
91
|
|
|
"""Generates xml string for create port range on gvmd.""" |
|
92
|
|
|
|
|
93
|
|
|
if not port_list_id: |
|
94
|
|
|
raise ValueError('create_port_range requires ' |
|
95
|
|
|
'a port_list_id element') |
|
96
|
|
|
if not type: |
|
97
|
|
|
raise ValueError('create_port_range requires a type element') |
|
98
|
|
|
|
|
99
|
|
|
cmd = XmlCommand('create_port_range') |
|
100
|
|
|
cmd.add_element('port_list', attrs={'id': port_list_id}) |
|
101
|
|
|
cmd.add_element('start', start) |
|
102
|
|
|
cmd.add_element('end', end) |
|
103
|
|
|
cmd.add_element('type', type) |
|
104
|
|
|
|
|
105
|
|
|
if comment: |
|
106
|
|
|
cmd.add_element('comment', comment) |
|
107
|
|
|
|
|
108
|
|
|
return cmd.to_string() |
|
109
|
|
|
|
|
110
|
|
|
def create_report_command(self, report_xml_string, kwargs): |
|
|
|
|
|
|
111
|
|
|
"""Generates xml string for create report on gvmd.""" |
|
112
|
|
|
|
|
113
|
|
|
if not report_xml_string: |
|
114
|
|
|
raise ValueError('create_report requires a report') |
|
115
|
|
|
|
|
116
|
|
|
task_id = kwargs.get('task_id', '') |
|
117
|
|
|
task_name = kwargs.get('task_name', '') |
|
118
|
|
|
|
|
119
|
|
|
cmd = XmlCommand('create_report') |
|
120
|
|
|
comment = kwargs.get('comment', '') |
|
121
|
|
|
if task_id: |
|
122
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
|
123
|
|
|
elif task_name: |
|
124
|
|
|
_xmltask = cmd.add_element('task') |
|
125
|
|
|
_xmltask.add_element('name', task_name) |
|
126
|
|
|
if comment: |
|
127
|
|
|
_xmltask.add_element('comment', comment) |
|
128
|
|
|
else: |
|
129
|
|
|
raise ValueError('create_report requires an id or name for a task') |
|
130
|
|
|
|
|
131
|
|
|
in_assets = kwargs.get('in_assets', '') |
|
132
|
|
|
if in_assets: |
|
133
|
|
|
cmd.add_element('in_assets', in_assets) |
|
134
|
|
|
|
|
135
|
|
|
cmd.append_xml_str(report_xml_string) |
|
136
|
|
|
|
|
137
|
|
|
return cmd.to_string() |
|
138
|
|
|
|
|
139
|
|
|
def create_role_command(self, name, kwargs): |
|
|
|
|
|
|
140
|
|
|
"""Generates xml string for create role on gvmd.""" |
|
141
|
|
|
|
|
142
|
|
|
if not name: |
|
143
|
|
|
raise ValueError('create_role requires a name element') |
|
144
|
|
|
|
|
145
|
|
|
cmd = XmlCommand('create_role') |
|
146
|
|
|
cmd.add_element('name', name) |
|
147
|
|
|
|
|
148
|
|
|
comment = kwargs.get('comment', '') |
|
149
|
|
|
if comment: |
|
150
|
|
|
cmd.add_element('comment', comment) |
|
151
|
|
|
|
|
152
|
|
|
copy = kwargs.get('copy', '') |
|
153
|
|
|
if copy: |
|
154
|
|
|
cmd.add_element('copy', copy) |
|
155
|
|
|
|
|
156
|
|
|
users = kwargs.get('users', '') |
|
157
|
|
|
if users: |
|
158
|
|
|
cmd.add_element('users', users) |
|
159
|
|
|
|
|
160
|
|
|
return cmd.to_string() |
|
161
|
|
|
|
|
162
|
|
|
def create_scanner_command(self, name, host, port, type, ca_pub, |
|
|
|
|
|
|
163
|
|
|
credential_id, kwargs): |
|
164
|
|
|
"""Generates xml string for create scanner on gvmd.""" |
|
165
|
|
|
if not name: |
|
166
|
|
|
raise ValueError('create_scanner requires a name element') |
|
167
|
|
|
if not host: |
|
168
|
|
|
raise ValueError('create_scanner requires a host element') |
|
169
|
|
|
if not port: |
|
170
|
|
|
raise ValueError('create_scanner requires a port element') |
|
171
|
|
|
if not type: |
|
172
|
|
|
raise ValueError('create_scanner requires a type element') |
|
173
|
|
|
if not ca_pub: |
|
174
|
|
|
raise ValueError('create_scanner requires a ca_pub element') |
|
175
|
|
|
if not credential_id: |
|
176
|
|
|
raise ValueError('create_scanner requires a credential_id element') |
|
177
|
|
|
|
|
178
|
|
|
cmd = XmlCommand('create_scanner') |
|
179
|
|
|
cmd.add_element('name', name) |
|
180
|
|
|
cmd.add_element('host', host) |
|
181
|
|
|
cmd.add_element('port', port) |
|
182
|
|
|
cmd.add_element('type', type) |
|
183
|
|
|
cmd.add_element('ca_pub', ca_pub) |
|
184
|
|
|
cmd.add_element('credential', attrs={'id': str(credential_id)}) |
|
185
|
|
|
|
|
186
|
|
|
comment = kwargs.get('comment', '') |
|
187
|
|
|
if comment: |
|
188
|
|
|
cmd.add_element('comment', comment) |
|
189
|
|
|
|
|
190
|
|
|
copy = kwargs.get('copy', '') |
|
191
|
|
|
if copy: |
|
192
|
|
|
cmd.add_element('copy', copy) |
|
193
|
|
|
|
|
194
|
|
|
return cmd.to_string() |
|
195
|
|
|
|
|
196
|
|
View Code Duplication |
def create_schedule_command(self, name, kwargs): |
|
|
|
|
|
|
197
|
|
|
"""Generates xml string for create schedule on gvmd.""" |
|
198
|
|
|
if not name: |
|
199
|
|
|
raise ValueError('create_schedule requires a name element') |
|
200
|
|
|
|
|
201
|
|
|
cmd = XmlCommand('create_schedule') |
|
202
|
|
|
cmd.add_element('name', name) |
|
203
|
|
|
|
|
204
|
|
|
comment = kwargs.get('comment', '') |
|
205
|
|
|
if comment: |
|
206
|
|
|
cmd.add_element('comment', comment) |
|
207
|
|
|
|
|
208
|
|
|
copy = kwargs.get('copy', '') |
|
209
|
|
|
if copy: |
|
210
|
|
|
cmd.add_element('copy', copy) |
|
211
|
|
|
|
|
212
|
|
|
first_time = kwargs.get('first_time', '') |
|
213
|
|
|
if first_time: |
|
214
|
|
|
first_time_minute = first_time['minute'] |
|
215
|
|
|
first_time_hour = first_time['hour'] |
|
216
|
|
|
first_time_day_of_month = first_time['day_of_month'] |
|
217
|
|
|
first_time_month = first_time['month'] |
|
218
|
|
|
first_time_year = first_time['year'] |
|
219
|
|
|
|
|
220
|
|
|
_xmlftime = cmd.add_element('first_time') |
|
221
|
|
|
_xmlftime.add_element('minute', first_time_minute) |
|
222
|
|
|
_xmlftime.add_element('hour', str(first_time_hour)) |
|
223
|
|
|
_xmlftime.add_element('day_of_month', str(first_time_day_of_month)) |
|
224
|
|
|
_xmlftime.add_element('month', str(first_time_month)) |
|
225
|
|
|
_xmlftime.add_element('year', str(first_time_year)) |
|
226
|
|
|
|
|
227
|
|
|
duration = kwargs.get('duration', '') |
|
228
|
|
|
if len(duration) > 1: |
|
229
|
|
|
_xmlduration = cmd.add_element('duration', str(duration[0])) |
|
230
|
|
|
_xmlduration.add_element('unit', str(duration[1])) |
|
231
|
|
|
|
|
232
|
|
|
period = kwargs.get('period', '') |
|
233
|
|
|
if len(period) > 1: |
|
234
|
|
|
_xmlperiod = cmd.add_element('period', str(period[0])) |
|
235
|
|
|
_xmlperiod.add_element('unit', str(period[1])) |
|
236
|
|
|
|
|
237
|
|
|
timezone = kwargs.get('timezone', '') |
|
238
|
|
|
if timezone: |
|
239
|
|
|
cmd.add_element('timezone', str(timezone)) |
|
240
|
|
|
|
|
241
|
|
|
return cmd.to_string() |
|
242
|
|
|
|
|
243
|
|
|
def create_tag_command(self, name, resource_id, resource_type, kwargs): |
|
|
|
|
|
|
244
|
|
|
"""Generates xml string for create tag on gvmd.""" |
|
245
|
|
|
|
|
246
|
|
|
cmd = XmlCommand('create_tag') |
|
247
|
|
|
cmd.add_element('name', name) |
|
248
|
|
|
_xmlresource = cmd.add_element('resource', |
|
249
|
|
|
attrs={'id': str(resource_id)}) |
|
250
|
|
|
_xmlresource.add_element('type', resource_type) |
|
251
|
|
|
|
|
252
|
|
|
comment = kwargs.get('comment', '') |
|
253
|
|
|
if comment: |
|
254
|
|
|
cmd.add_element('comment', comment) |
|
255
|
|
|
|
|
256
|
|
|
copy = kwargs.get('copy', '') |
|
257
|
|
|
if copy: |
|
258
|
|
|
cmd.add_element('copy', copy) |
|
259
|
|
|
|
|
260
|
|
|
value = kwargs.get('value', '') |
|
261
|
|
|
if value: |
|
262
|
|
|
cmd.add_element('value', value) |
|
263
|
|
|
|
|
264
|
|
|
active = kwargs.get('active', '') |
|
265
|
|
|
if active: |
|
266
|
|
|
cmd.add_element('active', active) |
|
267
|
|
|
|
|
268
|
|
|
return cmd.to_string() |
|
269
|
|
|
|
|
270
|
|
|
def create_task_command(self, name, config_id, target_id, scanner_id, |
|
|
|
|
|
|
271
|
|
|
alert_ids=None, comment=''): |
|
272
|
|
|
"""Generates xml string for create task on gvmd.""" |
|
273
|
|
|
|
|
274
|
|
|
if alert_ids is None: |
|
275
|
|
|
alert_ids = [] |
|
276
|
|
|
cmd = XmlCommand('create_task') |
|
277
|
|
|
cmd.add_element('name', name) |
|
278
|
|
|
cmd.add_element('comment', comment) |
|
279
|
|
|
cmd.add_element('config', attrs={'id': config_id}) |
|
280
|
|
|
cmd.add_element('target', attrs={'id': target_id}) |
|
281
|
|
|
cmd.add_element('scanner', attrs={'id': scanner_id}) |
|
282
|
|
|
|
|
283
|
|
|
#if given the alert_id is wrapped and integrated suitably as xml |
|
284
|
|
|
if len(alert_ids) > 0: |
|
285
|
|
|
if isinstance(alert_ids, str): |
|
286
|
|
|
#if a single id is given as a string wrap it into a list |
|
287
|
|
|
alert_ids = [alert_ids] |
|
288
|
|
|
if isinstance(alert_ids, list): |
|
289
|
|
|
#parse all given alert id's |
|
290
|
|
|
for alert in alert_ids: |
|
291
|
|
|
cmd.add_element('alert', attrs={'id': str(alert)}) |
|
292
|
|
|
|
|
293
|
|
|
return cmd.to_string() |
|
294
|
|
|
|
|
295
|
|
|
def create_user_command(self, name, password, copy='', hosts_allow='0', |
|
|
|
|
|
|
296
|
|
|
ifaces_allow='0', role_ids=(), hosts=None, |
|
297
|
|
|
ifaces=None): |
|
298
|
|
|
"""Generates xml string for create user on gvmd.""" |
|
299
|
|
|
cmd = XmlCommand('create_user') |
|
300
|
|
|
cmd.add_element('name', name) |
|
301
|
|
|
|
|
302
|
|
|
if copy: |
|
303
|
|
|
cmd.add_element('copy', copy) |
|
304
|
|
|
|
|
305
|
|
|
if password: |
|
306
|
|
|
cmd.add_element('password', password) |
|
307
|
|
|
|
|
308
|
|
|
if hosts is not None: |
|
309
|
|
|
cmd.add_element('hosts', hosts, attrs={'allow': str(hosts_allow)}) |
|
310
|
|
|
|
|
311
|
|
|
if ifaces is not None: |
|
312
|
|
|
cmd.add_element('ifaces', ifaces, |
|
313
|
|
|
attrs={'allow': str(ifaces_allow)}) |
|
314
|
|
|
|
|
315
|
|
|
if len(role_ids) > 0: |
|
316
|
|
|
for role in role_ids: |
|
317
|
|
|
cmd.add_element('role', attrs={'allow': str(role)}) |
|
318
|
|
|
|
|
319
|
|
|
return cmd.to_string() |
|
320
|
|
|
|
|
321
|
|
|
def modify_agent_command(self, agent_id, name='', comment=''): |
|
|
|
|
|
|
322
|
|
|
"""Generates xml string for modify agent on gvmd.""" |
|
323
|
|
|
if not agent_id: |
|
324
|
|
|
raise ValueError('modify_agent requires an agent_id element') |
|
325
|
|
|
|
|
326
|
|
|
cmd = XmlCommand('modify_agent') |
|
327
|
|
|
cmd.set_attribute('agent_id', str(agent_id)) |
|
328
|
|
|
if name: |
|
329
|
|
|
cmd.add_element('name', name) |
|
330
|
|
|
if comment: |
|
331
|
|
|
cmd.add_element('comment', comment) |
|
332
|
|
|
|
|
333
|
|
|
return cmd.to_string() |
|
334
|
|
|
|
|
335
|
|
|
def modify_alert_command(self, alert_id, kwargs): |
|
|
|
|
|
|
336
|
|
|
"""Generates xml string for modify alert on gvmd.""" |
|
337
|
|
|
|
|
338
|
|
|
if not alert_id: |
|
339
|
|
|
raise ValueError('modify_alert requires an agent_id element') |
|
340
|
|
|
|
|
341
|
|
|
cmd = XmlCommand('modify_alert') |
|
342
|
|
|
cmd.set_attribute('alert_id', str(alert_id)) |
|
343
|
|
|
|
|
344
|
|
|
name = kwargs.get('name', '') |
|
345
|
|
|
if name: |
|
346
|
|
|
cmd.add_element('name', name) |
|
347
|
|
|
|
|
348
|
|
|
comment = kwargs.get('comment', '') |
|
349
|
|
|
if comment: |
|
350
|
|
|
cmd.add_element('comment', comment) |
|
351
|
|
|
|
|
352
|
|
|
filter_id = kwargs.get('filter_id', '') |
|
353
|
|
|
if filter_id: |
|
354
|
|
|
cmd.add_element('filter', attrs={'id': filter_id}) |
|
355
|
|
|
|
|
356
|
|
|
event = kwargs.get('event', '') |
|
357
|
|
|
if len(event) > 1: |
|
358
|
|
|
_xmlevent = cmd.add_element('event', event[0]) |
|
359
|
|
|
for value, key in event[1].items(): |
|
360
|
|
|
_xmldata = _xmlevent.add_element('data', value) |
|
361
|
|
|
_xmldata.add_element('name', key) |
|
362
|
|
|
|
|
363
|
|
|
condition = kwargs.get('condition', '') |
|
364
|
|
|
if len(condition) > 1: |
|
365
|
|
|
_xmlcond = cmd.add_element('condition', condition[0]) |
|
366
|
|
|
for value, key in condition[1].items(): |
|
367
|
|
|
_xmldata = _xmlcond.add_element('data', value) |
|
368
|
|
|
_xmldata.add_element('name', key) |
|
369
|
|
|
|
|
370
|
|
|
method = kwargs.get('method', '') |
|
371
|
|
|
if len(method) > 1: |
|
372
|
|
|
_xmlmethod = cmd.add_element('method', method[0]) |
|
373
|
|
|
for value, key in method[1].items(): |
|
374
|
|
|
_xmldata = _xmlmethod.add_element('data', value) |
|
375
|
|
|
_xmldata.add_element('name', key) |
|
376
|
|
|
|
|
377
|
|
|
return cmd.to_string() |
|
378
|
|
|
|
|
379
|
|
|
def modify_asset_command(self, asset_id, comment): |
|
|
|
|
|
|
380
|
|
|
"""Generates xml string for modify asset on gvmd.""" |
|
381
|
|
|
cmd = XmlCommand('modify_asset') |
|
382
|
|
|
cmd.set_attribute('asset_id', asset_id) |
|
383
|
|
|
cmd.add_element('comment', comment) |
|
384
|
|
|
return cmd.to_string() |
|
385
|
|
|
|
|
386
|
|
|
def modify_auth_command(self, group_name, auth_conf_settings): |
|
|
|
|
|
|
387
|
|
|
"""Generates xml string for modify auth on gvmd.""" |
|
388
|
|
|
if not group_name: |
|
389
|
|
|
raise ValueError('modify_auth requires a group element ' |
|
390
|
|
|
'with a name attribute') |
|
391
|
|
|
if not auth_conf_settings: |
|
392
|
|
|
raise ValueError('modify_auth requires ' |
|
393
|
|
|
'an auth_conf_settings element') |
|
394
|
|
|
cmd = XmlCommand('modify_auth') |
|
395
|
|
|
_xmlgroup = cmd.add_element('group', attrs={'name': str(group_name)}) |
|
396
|
|
|
|
|
397
|
|
|
for key, value in auth_conf_settings.items(): |
|
398
|
|
|
_xmlauthconf = _xmlgroup.add_element('auth_conf_setting') |
|
399
|
|
|
_xmlauthconf.add_element('key', key) |
|
400
|
|
|
_xmlauthconf.add_element('value', value) |
|
401
|
|
|
|
|
402
|
|
|
return cmd.to_string() |
|
403
|
|
|
|
|
404
|
|
|
def modify_config_command(self, selection, kwargs): |
|
|
|
|
|
|
405
|
|
|
"""Generates xml string for modify config on gvmd.""" |
|
406
|
|
|
if selection not in ('nvt_pref', 'sca_pref', |
|
407
|
|
|
'family_selection', 'nvt_selection'): |
|
408
|
|
|
raise ValueError('selection must be one of nvt_pref, sca_pref, ' |
|
409
|
|
|
'family_selection or nvt_selection') |
|
410
|
|
|
config_id = kwargs.get('config_id') |
|
411
|
|
|
|
|
412
|
|
|
cmd = XmlCommand('modify_config') |
|
413
|
|
|
cmd.set_attribute('config_id', str(config_id)) |
|
414
|
|
|
|
|
415
|
|
|
if selection in 'nvt_pref': |
|
416
|
|
|
nvt_oid = kwargs.get('nvt_oid') |
|
417
|
|
|
name = kwargs.get('name') |
|
418
|
|
|
value = kwargs.get('value') |
|
419
|
|
|
_xmlpref = cmd.add_element('preference') |
|
420
|
|
|
_xmlpref.add_element('nvt', attrs={'oid': nvt_oid}) |
|
421
|
|
|
_xmlpref.add_element('name', name) |
|
422
|
|
|
_xmlpref.add_element('value', value) |
|
423
|
|
|
|
|
424
|
|
|
elif selection in 'nvt_selection': |
|
425
|
|
|
nvt_oid = kwargs.get('nvt_oid') |
|
426
|
|
|
family = kwargs.get('family') |
|
427
|
|
|
_xmlnvtsel = cmd.add_element('nvt_selection') |
|
428
|
|
|
_xmlnvtsel.add_element('family', family) |
|
429
|
|
|
|
|
430
|
|
|
if isinstance(nvt_oid, list): |
|
431
|
|
|
for nvt in nvt_oid: |
|
432
|
|
|
_xmlnvtsel.add_element('nvt', attrs={'oid': nvt}) |
|
433
|
|
|
else: |
|
434
|
|
|
_xmlnvtsel.add_element('nvt', attrs={'oid': nvt_oid}) |
|
435
|
|
|
|
|
436
|
|
|
elif selection in 'family_selection': |
|
437
|
|
|
family = kwargs.get('family') |
|
438
|
|
|
_xmlfamsel = cmd.add_element('family_selection') |
|
439
|
|
|
_xmlfamsel.add_element('growing', '1') |
|
440
|
|
|
_xmlfamily = _xmlfamsel.add_element('family') |
|
441
|
|
|
_xmlfamily.add_element('name', family) |
|
442
|
|
|
_xmlfamily.add_element('all', '1') |
|
443
|
|
|
_xmlfamily.add_element('growing', '1') |
|
444
|
|
|
else: |
|
445
|
|
|
raise NotImplementedError |
|
446
|
|
|
|
|
447
|
|
|
return cmd.to_string() |
|
448
|
|
|
|
|
449
|
|
|
def modify_credential_command(self, credential_id, kwargs): |
|
|
|
|
|
|
450
|
|
|
"""Generates xml string for modify credential on gvmd.""" |
|
451
|
|
|
if not credential_id: |
|
452
|
|
|
raise ValueError('modify_credential requires ' |
|
453
|
|
|
'a credential_id attribute') |
|
454
|
|
|
|
|
455
|
|
|
cmd = XmlCommand('modify_credential') |
|
456
|
|
|
cmd.set_attribute('credential_id', credential_id) |
|
457
|
|
|
|
|
458
|
|
|
comment = kwargs.get('comment', '') |
|
459
|
|
|
if comment: |
|
460
|
|
|
cmd.add_element('comment', comment) |
|
461
|
|
|
|
|
462
|
|
|
name = kwargs.get('name', '') |
|
463
|
|
|
if name: |
|
464
|
|
|
cmd.add_element('name', name) |
|
465
|
|
|
|
|
466
|
|
|
allow_insecure = kwargs.get('allow_insecure', '') |
|
467
|
|
|
if allow_insecure: |
|
468
|
|
|
cmd.add_element('allow_insecure', allow_insecure) |
|
469
|
|
|
|
|
470
|
|
|
certificate = kwargs.get('certificate', '') |
|
471
|
|
|
if certificate: |
|
472
|
|
|
cmd.add_element('certificate', certificate) |
|
473
|
|
|
|
|
474
|
|
|
key = kwargs.get('key', '') |
|
475
|
|
|
if key: |
|
476
|
|
|
phrase = key['phrase'] |
|
477
|
|
|
private = key['private'] |
|
478
|
|
|
if not phrase: |
|
479
|
|
|
raise ValueError('modify_credential requires a phrase element') |
|
480
|
|
|
if not private: |
|
481
|
|
|
raise ValueError('modify_credential requires ' |
|
482
|
|
|
'a private element') |
|
483
|
|
|
_xmlkey = cmd.add_element('key') |
|
484
|
|
|
_xmlkey.add_element('phrase', phrase) |
|
485
|
|
|
_xmlkey.add_element('private', private) |
|
486
|
|
|
|
|
487
|
|
|
login = kwargs.get('login', '') |
|
488
|
|
|
if login: |
|
489
|
|
|
cmd.add_element('login', login) |
|
490
|
|
|
|
|
491
|
|
|
password = kwargs.get('password', '') |
|
492
|
|
|
if password: |
|
493
|
|
|
cmd.add_element('password', password) |
|
494
|
|
|
|
|
495
|
|
|
auth_algorithm = kwargs.get('auth_algorithm', '') |
|
496
|
|
|
if auth_algorithm: |
|
497
|
|
|
if auth_algorithm not in ('md5', 'sha1'): |
|
498
|
|
|
raise ValueError('modify_credential requires auth_algorithm ' |
|
499
|
|
|
'to be either md5 or sha1') |
|
500
|
|
|
cmd.add_element('auth_algorithm', auth_algorithm) |
|
501
|
|
|
|
|
502
|
|
|
community = kwargs.get('community', '') |
|
503
|
|
|
if community: |
|
504
|
|
|
cmd.add_element('community', community) |
|
505
|
|
|
|
|
506
|
|
|
privacy = kwargs.get('privacy', '') |
|
507
|
|
|
if privacy: |
|
508
|
|
|
algorithm = privacy.algorithm |
|
509
|
|
|
if algorithm not in ('aes', 'des'): |
|
510
|
|
|
raise ValueError('modify_credential requires algorithm ' |
|
511
|
|
|
'to be either aes or des') |
|
512
|
|
|
p_password = privacy.password |
|
513
|
|
|
_xmlprivacy = cmd.add_element('privacy') |
|
514
|
|
|
_xmlprivacy.add_element('algorithm', algorithm) |
|
515
|
|
|
_xmlprivacy.add_element('password', p_password) |
|
516
|
|
|
|
|
517
|
|
|
cred_type = kwargs.get('type', '') |
|
518
|
|
|
if cred_type: |
|
519
|
|
|
if cred_type not in ('cc', 'snmp', 'up', 'usk'): |
|
520
|
|
|
raise ValueError('modify_credential requires type ' |
|
521
|
|
|
'to be either cc, snmp, up or usk') |
|
522
|
|
|
cmd.add_element('type', cred_type) |
|
523
|
|
|
|
|
524
|
|
|
return cmd.to_string() |
|
525
|
|
|
|
|
526
|
|
|
def modify_filter_command(self, filter_id, kwargs): |
|
|
|
|
|
|
527
|
|
|
"""Generates xml string for modify filter on gvmd.""" |
|
528
|
|
|
if not filter_id: |
|
529
|
|
|
raise ValueError('modify_filter requires a filter_id attribute') |
|
530
|
|
|
|
|
531
|
|
|
cmd = XmlCommand('modify_filter') |
|
532
|
|
|
cmd.set_attribute('filter_id', filter_id) |
|
533
|
|
|
|
|
534
|
|
|
comment = kwargs.get('comment', '') |
|
535
|
|
|
if comment: |
|
536
|
|
|
cmd.add_element('comment', comment) |
|
537
|
|
|
|
|
538
|
|
|
name = kwargs.get('name', '') |
|
539
|
|
|
if name: |
|
540
|
|
|
cmd.add_element('name', name) |
|
541
|
|
|
|
|
542
|
|
|
copy = kwargs.get('copy', '') |
|
543
|
|
|
if copy: |
|
544
|
|
|
cmd.add_element('copy', copy) |
|
545
|
|
|
|
|
546
|
|
|
term = kwargs.get('term', '') |
|
547
|
|
|
if term: |
|
548
|
|
|
cmd.add_element('term', term) |
|
549
|
|
|
|
|
550
|
|
|
filter_type = kwargs.get('type', '') |
|
551
|
|
|
if filter_type: |
|
552
|
|
|
if filter_type not in ('cc', 'snmp', 'up', 'usk'): |
|
553
|
|
|
raise ValueError('modify_filter requires type ' |
|
554
|
|
|
'to be either cc, snmp, up or usk') |
|
555
|
|
|
cmd.add_element('type', filter_type) |
|
556
|
|
|
|
|
557
|
|
|
return cmd.to_string() |
|
558
|
|
|
|
|
559
|
|
View Code Duplication |
def modify_group_command(self, group_id, kwargs): |
|
|
|
|
|
|
560
|
|
|
"""Generates xml string for modify group on gvmd.""" |
|
561
|
|
|
if not group_id: |
|
562
|
|
|
raise ValueError('modify_group requires a group_id attribute') |
|
563
|
|
|
|
|
564
|
|
|
cmd = XmlCommand('modify_group') |
|
565
|
|
|
cmd.set_attribute('group_id', group_id) |
|
566
|
|
|
|
|
567
|
|
|
comment = kwargs.get('comment', '') |
|
568
|
|
|
if comment: |
|
569
|
|
|
cmd.add_element('comment', comment) |
|
570
|
|
|
|
|
571
|
|
|
name = kwargs.get('name', '') |
|
572
|
|
|
if name: |
|
573
|
|
|
cmd.add_element('name', name) |
|
574
|
|
|
|
|
575
|
|
|
users = kwargs.get('users', '') |
|
576
|
|
|
if users: |
|
577
|
|
|
cmd.add_element('users', users) |
|
578
|
|
|
|
|
579
|
|
|
return cmd.to_string() |
|
580
|
|
|
|
|
581
|
|
|
def modify_note_command(self, note_id, text, kwargs): |
|
|
|
|
|
|
582
|
|
|
"""Generates xml string for modify note on gvmd.""" |
|
583
|
|
|
if not note_id: |
|
584
|
|
|
raise ValueError('modify_note requires a note_id attribute') |
|
585
|
|
|
if not text: |
|
586
|
|
|
raise ValueError('modify_note requires a text element') |
|
587
|
|
|
|
|
588
|
|
|
cmd = XmlCommand('modify_note') |
|
589
|
|
|
cmd.set_attribute('note_id', note_id) |
|
590
|
|
|
cmd.add_element('text', text) |
|
591
|
|
|
|
|
592
|
|
|
active = kwargs.get('active', '') |
|
593
|
|
|
if active: |
|
594
|
|
|
cmd.add_element('active', active) |
|
595
|
|
|
|
|
596
|
|
|
hosts = kwargs.get('hosts', '') |
|
597
|
|
|
if hosts: |
|
598
|
|
|
cmd.add_element('hosts', hosts) |
|
599
|
|
|
|
|
600
|
|
|
port = kwargs.get('port', '') |
|
601
|
|
|
if port: |
|
602
|
|
|
cmd.add_element('port', port) |
|
603
|
|
|
|
|
604
|
|
|
result_id = kwargs.get('result_id', '') |
|
605
|
|
|
if result_id: |
|
606
|
|
|
cmd.add_element('result', attrs={'id': result_id}) |
|
607
|
|
|
|
|
608
|
|
|
severity = kwargs.get('severity', '') |
|
609
|
|
|
if severity: |
|
610
|
|
|
cmd.add_element('severity', severity) |
|
611
|
|
|
|
|
612
|
|
|
task_id = kwargs.get('task_id', '') |
|
613
|
|
|
if task_id: |
|
614
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
|
615
|
|
|
|
|
616
|
|
|
threat = kwargs.get('threat', '') |
|
617
|
|
|
if threat: |
|
618
|
|
|
cmd.add_element('threat', threat) |
|
619
|
|
|
|
|
620
|
|
|
return cmd.to_string() |
|
621
|
|
|
|
|
622
|
|
|
def modify_override_command(self, override_id, text, kwargs): |
|
|
|
|
|
|
623
|
|
|
"""Generates xml string for modify override on gvmd.""" |
|
624
|
|
|
cmd = XmlCommand('modify_override') |
|
625
|
|
|
cmd.set_attribute('override_id', override_id) |
|
626
|
|
|
cmd.add_element('text', text) |
|
627
|
|
|
|
|
628
|
|
|
active = kwargs.get('active', '') |
|
629
|
|
|
if active: |
|
630
|
|
|
cmd.add_element('active', active) |
|
631
|
|
|
|
|
632
|
|
|
hosts = kwargs.get('hosts', '') |
|
633
|
|
|
if hosts: |
|
634
|
|
|
cmd.add_element('hosts', hosts) |
|
635
|
|
|
|
|
636
|
|
|
port = kwargs.get('port', '') |
|
637
|
|
|
if port: |
|
638
|
|
|
cmd.add_element('port', port) |
|
639
|
|
|
|
|
640
|
|
|
result_id = kwargs.get('result_id', '') |
|
641
|
|
|
if result_id: |
|
642
|
|
|
cmd.add_element('result', attrs={'id': result_id}) |
|
643
|
|
|
|
|
644
|
|
|
severity = kwargs.get('severity', '') |
|
645
|
|
|
if severity: |
|
646
|
|
|
cmd.add_element('severity', severity) |
|
647
|
|
|
|
|
648
|
|
|
new_severity = kwargs.get('new_severity', '') |
|
649
|
|
|
if new_severity: |
|
650
|
|
|
cmd.add_element('new_severity', new_severity) |
|
651
|
|
|
|
|
652
|
|
|
task_id = kwargs.get('task_id', '') |
|
653
|
|
|
if task_id: |
|
654
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
|
655
|
|
|
|
|
656
|
|
|
threat = kwargs.get('threat', '') |
|
657
|
|
|
if threat: |
|
658
|
|
|
cmd.add_element('threat', threat) |
|
659
|
|
|
|
|
660
|
|
|
new_threat = kwargs.get('new_threat', '') |
|
661
|
|
|
if new_threat: |
|
662
|
|
|
cmd.add_element('new_threat', new_threat) |
|
663
|
|
|
|
|
664
|
|
|
return cmd.to_string() |
|
665
|
|
|
|
|
666
|
|
|
def modify_permission_command(self, permission_id, kwargs): |
|
|
|
|
|
|
667
|
|
|
"""Generates xml string for modify permission on gvmd.""" |
|
668
|
|
|
if not permission_id: |
|
669
|
|
|
raise ValueError('modify_permission requires ' |
|
670
|
|
|
'a permission_id element') |
|
671
|
|
|
|
|
672
|
|
|
cmd = XmlCommand('modify_permission') |
|
673
|
|
|
cmd.set_attribute('permission_id', permission_id) |
|
674
|
|
|
|
|
675
|
|
|
comment = kwargs.get('comment', '') |
|
676
|
|
|
if comment: |
|
677
|
|
|
cmd.add_element('comment', comment) |
|
678
|
|
|
|
|
679
|
|
|
name = kwargs.get('name', '') |
|
680
|
|
|
if name: |
|
681
|
|
|
cmd.add_element('name', name) |
|
682
|
|
|
|
|
683
|
|
|
resource = kwargs.get('resource', '') |
|
684
|
|
|
if resource: |
|
685
|
|
|
resource_id = resource['id'] |
|
686
|
|
|
resource_type = resource['type'] |
|
687
|
|
|
_xmlresource = cmd.add_element('resource', |
|
688
|
|
|
attrs={'id': resource_id}) |
|
689
|
|
|
_xmlresource.add_element('type', resource_type) |
|
690
|
|
|
|
|
691
|
|
|
subject = kwargs.get('subject', '') |
|
692
|
|
|
if subject: |
|
693
|
|
|
subject_id = subject['id'] |
|
694
|
|
|
subject_type = subject['type'] |
|
695
|
|
|
_xmlsubject = cmd.add_element('subject', attrs={'id': subject_id}) |
|
696
|
|
|
_xmlsubject.add_element('type', subject_type) |
|
697
|
|
|
|
|
698
|
|
|
return cmd.to_string() |
|
699
|
|
|
|
|
700
|
|
|
def modify_port_list_command(self, port_list_id, kwargs): |
|
|
|
|
|
|
701
|
|
|
"""Generates xml string for modify port list on gvmd.""" |
|
702
|
|
|
if not port_list_id: |
|
703
|
|
|
raise ValueError('modify_port_list requires ' |
|
704
|
|
|
'a port_list_id attribute') |
|
705
|
|
|
cmd = XmlCommand('modify_port_list') |
|
706
|
|
|
cmd.set_attribute('port_list_id', port_list_id) |
|
707
|
|
|
|
|
708
|
|
|
comment = kwargs.get('comment', '') |
|
709
|
|
|
if comment: |
|
710
|
|
|
cmd.add_element('comment', comment) |
|
711
|
|
|
|
|
712
|
|
|
name = kwargs.get('name', '') |
|
713
|
|
|
if name: |
|
714
|
|
|
cmd.add_element('name', name) |
|
715
|
|
|
|
|
716
|
|
|
return cmd.to_string() |
|
717
|
|
|
|
|
718
|
|
|
def modify_report_command(self, report_id, comment): |
|
|
|
|
|
|
719
|
|
|
"""Generates xml string for modify report on gvmd.""" |
|
720
|
|
|
cmd = XmlCommand('modify_report') |
|
721
|
|
|
cmd.set_attribute('report_id', report_id) |
|
722
|
|
|
cmd.add_element('comment', comment) |
|
723
|
|
|
return cmd.to_string() |
|
724
|
|
|
|
|
725
|
|
|
def modify_report_format_command(self, report_format_id, kwargs): |
|
|
|
|
|
|
726
|
|
|
"""Generates xml string for modify report format on gvmd.""" |
|
727
|
|
|
if len(kwargs) < 1: |
|
728
|
|
|
raise Exception('modify_report_format: Missing parameter') |
|
729
|
|
|
|
|
730
|
|
|
cmd = XmlCommand('modify_report_format') |
|
731
|
|
|
cmd.set_attribute('report_format_id', report_format_id) |
|
732
|
|
|
|
|
733
|
|
|
active = kwargs.get('active', '') |
|
734
|
|
|
if active: |
|
735
|
|
|
cmd.add_element('active', active) |
|
736
|
|
|
|
|
737
|
|
|
name = kwargs.get('name', '') |
|
738
|
|
|
if name: |
|
739
|
|
|
cmd.add_element('name', name) |
|
740
|
|
|
|
|
741
|
|
|
summary = kwargs.get('summary', '') |
|
742
|
|
|
if summary: |
|
743
|
|
|
cmd.add_element('summary', summary) |
|
744
|
|
|
|
|
745
|
|
|
param = kwargs.get('param', '') |
|
746
|
|
|
if param: |
|
747
|
|
|
p_name = param[0] |
|
748
|
|
|
p_value = param[1] |
|
749
|
|
|
_xmlparam = cmd.add_element('param') |
|
750
|
|
|
_xmlparam.add_element('name', p_name) |
|
751
|
|
|
_xmlparam.add_element('value', p_value) |
|
752
|
|
|
|
|
753
|
|
|
return cmd.to_string() |
|
754
|
|
|
|
|
755
|
|
View Code Duplication |
def modify_role_command(self, role_id, kwargs): |
|
|
|
|
|
|
756
|
|
|
"""Generates xml string for modify role on gvmd.""" |
|
757
|
|
|
if not role_id: |
|
758
|
|
|
raise ValueError('modify_role requires a role_id element') |
|
759
|
|
|
|
|
760
|
|
|
cmd = XmlCommand('modify_role') |
|
761
|
|
|
cmd.set_attribute('role_id', role_id) |
|
762
|
|
|
|
|
763
|
|
|
comment = kwargs.get('comment', '') |
|
764
|
|
|
if comment: |
|
765
|
|
|
cmd.add_element('comment', comment) |
|
766
|
|
|
|
|
767
|
|
|
name = kwargs.get('name', '') |
|
768
|
|
|
if name: |
|
769
|
|
|
cmd.add_element('name', name) |
|
770
|
|
|
|
|
771
|
|
|
users = kwargs.get('users', '') |
|
772
|
|
|
if users: |
|
773
|
|
|
cmd.add_element('users', users) |
|
774
|
|
|
|
|
775
|
|
|
return cmd.to_string() |
|
776
|
|
|
|
|
777
|
|
|
def modify_scanner_command(self, scanner_id, host, port, scanner_type, |
|
|
|
|
|
|
778
|
|
|
kwargs): |
|
779
|
|
|
"""Generates xml string for modify scanner on gvmd.""" |
|
780
|
|
|
if not scanner_id: |
|
781
|
|
|
raise ValueError('modify_scanner requires a scanner_id element') |
|
782
|
|
|
if not host: |
|
783
|
|
|
raise ValueError('modify_scanner requires a host element') |
|
784
|
|
|
if not port: |
|
785
|
|
|
raise ValueError('modify_scanner requires a port element') |
|
786
|
|
|
if not scanner_type: |
|
787
|
|
|
raise ValueError('modify_scanner requires a type element') |
|
788
|
|
|
|
|
789
|
|
|
cmd = XmlCommand('modify_scanner') |
|
790
|
|
|
cmd.set_attribute('scanner_id', scanner_id) |
|
791
|
|
|
cmd.add_element('host', host) |
|
792
|
|
|
cmd.add_element('port', port) |
|
793
|
|
|
cmd.add_element('type', scanner_type) |
|
794
|
|
|
|
|
795
|
|
|
comment = kwargs.get('comment', '') |
|
796
|
|
|
if comment: |
|
797
|
|
|
cmd.add_element('comment', comment) |
|
798
|
|
|
|
|
799
|
|
|
name = kwargs.get('name', '') |
|
800
|
|
|
if name: |
|
801
|
|
|
cmd.add_element('name', name) |
|
802
|
|
|
|
|
803
|
|
|
ca_pub = kwargs.get('ca_pub', '') |
|
804
|
|
|
if ca_pub: |
|
805
|
|
|
cmd.add_element('ca_pub', ca_pub) |
|
806
|
|
|
|
|
807
|
|
|
credential_id = kwargs.get('credential_id', '') |
|
808
|
|
|
if credential_id: |
|
809
|
|
|
cmd.add_element('credential', attrs={'id': str(credential_id)}) |
|
810
|
|
|
|
|
811
|
|
|
return cmd.to_string() |
|
812
|
|
|
|
|
813
|
|
View Code Duplication |
def modify_schedule_command(self, schedule_id, kwargs): |
|
|
|
|
|
|
814
|
|
|
"""Generates xml string for modify schedule on gvmd.""" |
|
815
|
|
|
if not schedule_id: |
|
816
|
|
|
raise ValueError('modify_schedule requires a schedule_id element') |
|
817
|
|
|
|
|
818
|
|
|
cmd = XmlCommand('modify_schedule') |
|
819
|
|
|
cmd.set_attribute('schedule_id', schedule_id) |
|
820
|
|
|
comment = kwargs.get('comment', '') |
|
821
|
|
|
if comment: |
|
822
|
|
|
cmd.add_element('comment', comment) |
|
823
|
|
|
|
|
824
|
|
|
name = kwargs.get('name', '') |
|
825
|
|
|
if name: |
|
826
|
|
|
cmd.add_element('name', name) |
|
827
|
|
|
|
|
828
|
|
|
first_time = kwargs.get('first_time', '') |
|
829
|
|
|
if first_time: |
|
830
|
|
|
first_time_minute = first_time['minute'] |
|
831
|
|
|
first_time_hour = first_time['hour'] |
|
832
|
|
|
first_time_day_of_month = first_time['day_of_month'] |
|
833
|
|
|
first_time_month = first_time['month'] |
|
834
|
|
|
first_time_year = first_time['year'] |
|
835
|
|
|
|
|
836
|
|
|
_xmlftime = cmd.add_element('first_time') |
|
837
|
|
|
_xmlftime.add_element('minute', str(first_time_minute)) |
|
838
|
|
|
_xmlftime.add_element('hour', str(first_time_hour)) |
|
839
|
|
|
_xmlftime.add_element('day_of_month', str(first_time_day_of_month)) |
|
840
|
|
|
_xmlftime.add_element('month', str(first_time_month)) |
|
841
|
|
|
_xmlftime.add_element('year', str(first_time_year)) |
|
842
|
|
|
|
|
843
|
|
|
duration = kwargs.get('duration', '') |
|
844
|
|
|
if len(duration) > 1: |
|
845
|
|
|
_xmlduration = cmd.add_element('duration', str(duration[0])) |
|
846
|
|
|
_xmlduration.add_element('unit', str(duration[1])) |
|
847
|
|
|
|
|
848
|
|
|
period = kwargs.get('period', '') |
|
849
|
|
|
if len(period) > 1: |
|
850
|
|
|
_xmlperiod = cmd.add_element('period', str(period[0])) |
|
851
|
|
|
_xmlperiod.add_element('unit', str(period[1])) |
|
852
|
|
|
|
|
853
|
|
|
timezone = kwargs.get('timezone', '') |
|
854
|
|
|
if timezone: |
|
855
|
|
|
cmd.add_element('timezone', str(timezone)) |
|
856
|
|
|
|
|
857
|
|
|
return cmd.to_string() |
|
858
|
|
|
|
|
859
|
|
|
def modify_setting_command(self, setting_id, name, value): |
|
|
|
|
|
|
860
|
|
|
"""Generates xml string for modify setting format on gvmd.""" |
|
861
|
|
|
cmd = XmlCommand('modify_setting') |
|
862
|
|
|
cmd.set_attribute('setting_id', setting_id) |
|
863
|
|
|
cmd.add_element('name', name) |
|
864
|
|
|
cmd.add_element('value', value) |
|
865
|
|
|
|
|
866
|
|
|
return cmd.to_string() |
|
867
|
|
|
|
|
868
|
|
|
def modify_tag_command(self, tag_id, kwargs): |
|
|
|
|
|
|
869
|
|
|
"""Generates xml string for modify tag on gvmd.""" |
|
870
|
|
|
if not tag_id: |
|
871
|
|
|
raise ValueError('modify_tag requires a tag_id element') |
|
872
|
|
|
|
|
873
|
|
|
cmd = XmlCommand('modify_tag') |
|
874
|
|
|
cmd.set_attribute('tag_id', str(tag_id)) |
|
875
|
|
|
|
|
876
|
|
|
comment = kwargs.get('comment', '') |
|
877
|
|
|
if comment: |
|
878
|
|
|
cmd.add_element('comment', comment) |
|
879
|
|
|
|
|
880
|
|
|
name = kwargs.get('name', '') |
|
881
|
|
|
if name: |
|
882
|
|
|
cmd.add_element('name', name) |
|
883
|
|
|
|
|
884
|
|
|
value = kwargs.get('value', '') |
|
885
|
|
|
if value: |
|
886
|
|
|
cmd.add_element('value', value) |
|
887
|
|
|
|
|
888
|
|
|
active = kwargs.get('active', '') |
|
889
|
|
|
if active: |
|
890
|
|
|
cmd.add_element('active', value) |
|
891
|
|
|
|
|
892
|
|
|
resource = kwargs.get('resource', '') |
|
893
|
|
|
if resource: |
|
894
|
|
|
resource_id = resource['id'] |
|
895
|
|
|
resource_type = resource['type'] |
|
896
|
|
|
_xmlresource = cmd.add_element('resource', |
|
897
|
|
|
attrs={'resource_id': resource_id}) |
|
898
|
|
|
_xmlresource.add_element('type', resource_type) |
|
899
|
|
|
|
|
900
|
|
|
return cmd.to_string() |
|
901
|
|
|
|
|
902
|
|
|
def modify_target_command(self, target_id, kwargs): |
|
|
|
|
|
|
903
|
|
|
"""Generates xml string for modify target on gvmd.""" |
|
904
|
|
|
if not target_id: |
|
905
|
|
|
raise ValueError('modify_target requires a target_id element') |
|
906
|
|
|
|
|
907
|
|
|
cmd = XmlCommand('modify_target') |
|
908
|
|
|
cmd.set_attribute('target_id', target_id) |
|
909
|
|
|
|
|
910
|
|
|
comment = kwargs.get('comment', '') |
|
911
|
|
|
if comment: |
|
912
|
|
|
cmd.add_element('comment', comment) |
|
913
|
|
|
|
|
914
|
|
|
name = kwargs.get('name', '') |
|
915
|
|
|
if name: |
|
916
|
|
|
cmd.add_element('name', name) |
|
917
|
|
|
|
|
918
|
|
|
hosts = kwargs.get('hosts', '') |
|
919
|
|
|
if hosts: |
|
920
|
|
|
cmd.add_element('hosts', hosts) |
|
921
|
|
|
|
|
922
|
|
|
copy = kwargs.get('copy', '') |
|
923
|
|
|
if copy: |
|
924
|
|
|
cmd.add_element('copy', copy) |
|
925
|
|
|
|
|
926
|
|
|
exclude_hosts = kwargs.get('exclude_hosts', '') |
|
927
|
|
|
if exclude_hosts: |
|
928
|
|
|
cmd.add_element('exclude_hosts', exclude_hosts) |
|
929
|
|
|
|
|
930
|
|
|
alive_tests = kwargs.get('alive_tests', '') |
|
931
|
|
|
if alive_tests: |
|
932
|
|
|
cmd.add_element('alive_tests', alive_tests) |
|
933
|
|
|
|
|
934
|
|
|
reverse_lookup_only = kwargs.get('reverse_lookup_only', '') |
|
935
|
|
|
if reverse_lookup_only: |
|
936
|
|
|
cmd.add_element('reverse_lookup_only', reverse_lookup_only) |
|
937
|
|
|
|
|
938
|
|
|
reverse_lookup_unify = kwargs.get('reverse_lookup_unify', '') |
|
939
|
|
|
if reverse_lookup_unify: |
|
940
|
|
|
cmd.add_element('reverse_lookup_unify', reverse_lookup_unify) |
|
941
|
|
|
|
|
942
|
|
|
port_range = kwargs.get('port_range', '') |
|
943
|
|
|
if port_range: |
|
944
|
|
|
cmd.add_element('port_range', port_range) |
|
945
|
|
|
|
|
946
|
|
|
port_list = kwargs.get('port_list', '') |
|
947
|
|
|
if port_list: |
|
948
|
|
|
cmd.add_element('port_list', attrs={'id': str(port_list)}) |
|
949
|
|
|
|
|
950
|
|
|
return cmd.to_string() |
|
951
|
|
|
|
|
952
|
|
|
def modify_task_command(self, task_id, kwargs): |
|
|
|
|
|
|
953
|
|
|
"""Generates xml string for modify task on gvmd.""" |
|
954
|
|
|
if not task_id: |
|
955
|
|
|
raise ValueError('modify_task requires a task_id element') |
|
956
|
|
|
|
|
957
|
|
|
cmd = XmlCommand('modify_task') |
|
958
|
|
|
cmd.set_attribute('task_id', task_id) |
|
959
|
|
|
|
|
960
|
|
|
name = kwargs.get('name', '') |
|
961
|
|
|
if name: |
|
962
|
|
|
cmd.add_element('name', name) |
|
963
|
|
|
|
|
964
|
|
|
comment = kwargs.get('comment', '') |
|
965
|
|
|
if comment: |
|
966
|
|
|
cmd.add_element('comment', comment) |
|
967
|
|
|
|
|
968
|
|
|
target_id = kwargs.get('target_id', '') |
|
969
|
|
|
if target_id: |
|
970
|
|
|
cmd.add_element('target', attrs={'id': target_id}) |
|
971
|
|
|
|
|
972
|
|
|
scanner = kwargs.get('scanner', '') |
|
973
|
|
|
if scanner: |
|
974
|
|
|
cmd.add_element('scanner', attrs={'id': scanner}) |
|
975
|
|
|
|
|
976
|
|
|
schedule_periods = kwargs.get('schedule_periods', '') |
|
977
|
|
|
if schedule_periods: |
|
978
|
|
|
cmd.add_element('schedule_periods', str(schedule_periods)) |
|
979
|
|
|
|
|
980
|
|
|
schedule = kwargs.get('schedule', '') |
|
981
|
|
|
if schedule: |
|
982
|
|
|
cmd.add_element('schedule', attrs={'id': str(schedule)}) |
|
983
|
|
|
|
|
984
|
|
|
alert = kwargs.get('alert', '') |
|
985
|
|
|
if alert: |
|
986
|
|
|
cmd.add_element('alert', attrs={'id': str(alert)}) |
|
987
|
|
|
|
|
988
|
|
|
observers = kwargs.get('observers', '') |
|
989
|
|
|
if observers: |
|
990
|
|
|
cmd.add_element('observers', str(observers)) |
|
991
|
|
|
|
|
992
|
|
|
preferences = kwargs.get('preferences', '') |
|
993
|
|
|
if preferences: |
|
994
|
|
|
_xmlprefs = cmd.add_element('preferences') |
|
995
|
|
|
for n in range(len(preferences["scanner_name"])): |
|
|
|
|
|
|
996
|
|
|
preferences_scanner_name = preferences["scanner_name"][n] |
|
997
|
|
|
preferences_value = preferences["value"][n] |
|
998
|
|
|
_xmlpref = _xmlprefs.add_element('preference') |
|
999
|
|
|
_xmlpref.add_element('scanner_name', preferences_scanner_name) |
|
1000
|
|
|
_xmlpref.add_element('value', preferences_value) |
|
1001
|
|
|
|
|
1002
|
|
|
file = kwargs.get('file', '') |
|
1003
|
|
|
if file: |
|
1004
|
|
|
file_name = file['name'] |
|
1005
|
|
|
file_action = file['action'] |
|
1006
|
|
|
if file_action != "update" and file_action != "remove": |
|
|
|
|
|
|
1007
|
|
|
raise ValueError('action can only be "update" or "remove"!') |
|
1008
|
|
|
cmd.add_element('file', attrs={'name': file_name, |
|
1009
|
|
|
'action': file_action}) |
|
1010
|
|
|
|
|
1011
|
|
|
return cmd.to_string() |
|
1012
|
|
|
|
|
1013
|
|
|
def modify_user_command(self, kwargs): |
|
|
|
|
|
|
1014
|
|
|
"""Generates xml string for modify user on gvmd.""" |
|
1015
|
|
|
user_id = kwargs.get('user_id', '') |
|
1016
|
|
|
name = kwargs.get('name', '') |
|
1017
|
|
|
|
|
1018
|
|
|
if not user_id and not name: |
|
1019
|
|
|
raise ValueError('modify_user requires ' |
|
1020
|
|
|
'either a user_id or a name element') |
|
1021
|
|
|
|
|
1022
|
|
|
cmd = XmlCommand('modify_user') |
|
1023
|
|
|
cmd.set_attribute('user_id', str(user_id)) |
|
1024
|
|
|
|
|
1025
|
|
|
new_name = kwargs.get('new_name', '') |
|
1026
|
|
|
if new_name: |
|
1027
|
|
|
cmd.add_element('new_name', new_name) |
|
1028
|
|
|
|
|
1029
|
|
|
password = kwargs.get('password', '') |
|
1030
|
|
|
if password: |
|
1031
|
|
|
cmd.add_element('password', password) |
|
1032
|
|
|
|
|
1033
|
|
|
role_ids = kwargs.get('role_ids', '') |
|
1034
|
|
|
if len(role_ids) > 0: |
|
1035
|
|
|
for role in role_ids: |
|
1036
|
|
|
cmd.add_element('role', attrs={'id': str(role)}) |
|
1037
|
|
|
|
|
1038
|
|
|
hosts = kwargs.get('hosts', '') |
|
1039
|
|
|
hosts_allow = kwargs.get('hosts_allow', '') |
|
1040
|
|
|
if hosts or hosts_allow: |
|
1041
|
|
|
cmd.add_element('hosts', hosts, attrs={'allow': str(hosts_allow)}) |
|
1042
|
|
|
|
|
1043
|
|
|
ifaces = kwargs.get('ifaces', '') |
|
1044
|
|
|
ifaces_allow = kwargs.get('ifaces_allow', '') |
|
1045
|
|
|
if ifaces or ifaces_allow: |
|
1046
|
|
|
cmd.add_element('ifaces', ifaces, |
|
1047
|
|
|
attrs={'allow': str(ifaces_allow)}) |
|
1048
|
|
|
|
|
1049
|
|
|
sources = kwargs.get('sources', '') |
|
1050
|
|
|
if sources: |
|
1051
|
|
|
cmd.add_element('sources', sources) |
|
1052
|
|
|
|
|
1053
|
|
|
return cmd.to_string() |
|
1054
|
|
|
|
|
1055
|
|
|
def delete_agent_command(self, kwargs): |
|
|
|
|
|
|
1056
|
|
|
"""Generates xml string for delete agent on gvmd""" |
|
1057
|
|
|
cmd = XmlCommand('delete_agent') |
|
1058
|
|
|
for key, value in kwargs.items(): |
|
1059
|
|
|
cmd.set_attribute(key, value) |
|
1060
|
|
|
|
|
1061
|
|
|
return cmd.to_string() |
|
1062
|
|
|
|
|
1063
|
|
|
def delete_alert_command(self, kwargs): |
|
|
|
|
|
|
1064
|
|
|
"""Generates xml string for delete alert on gvmd""" |
|
1065
|
|
|
cmd = XmlCommand('delete_alert') |
|
1066
|
|
|
for key, value in kwargs.items(): |
|
1067
|
|
|
cmd.set_attribute(key, value) |
|
1068
|
|
|
|
|
1069
|
|
|
return cmd.to_string() |
|
1070
|
|
|
|
|
1071
|
|
|
def delete_asset_command(self, asset_id, ultimate=0): |
|
|
|
|
|
|
1072
|
|
|
"""Generates xml string for delete asset on gvmd""" |
|
1073
|
|
|
cmd = XmlCommand('delete_asset') |
|
1074
|
|
|
cmd.set_attribute('asset_id', asset_id) |
|
1075
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1076
|
|
|
|
|
1077
|
|
|
return cmd.to_string() |
|
1078
|
|
|
|
|
1079
|
|
|
def delete_config_command(self, config_id, ultimate=0): |
|
|
|
|
|
|
1080
|
|
|
"""Generates xml string for delete config on gvmd""" |
|
1081
|
|
|
cmd = XmlCommand('delete_config') |
|
1082
|
|
|
cmd.set_attribute('config_id', config_id) |
|
1083
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1084
|
|
|
|
|
1085
|
|
|
return cmd.to_string() |
|
1086
|
|
|
|
|
1087
|
|
|
def delete_credential_command(self, credential_id, ultimate=0): |
|
|
|
|
|
|
1088
|
|
|
"""Generates xml string for delete credential on gvmd""" |
|
1089
|
|
|
cmd = XmlCommand('delete_credential') |
|
1090
|
|
|
cmd.set_attribute('credential_id', credential_id) |
|
1091
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1092
|
|
|
return cmd.to_string() |
|
1093
|
|
|
|
|
1094
|
|
|
def delete_filter_command(self, filter_id, ultimate=0): |
|
|
|
|
|
|
1095
|
|
|
"""Generates xml string for delete filter on gvmd""" |
|
1096
|
|
|
cmd = XmlCommand('delete_filter') |
|
1097
|
|
|
cmd.set_attribute('filter_id', filter_id) |
|
1098
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1099
|
|
|
|
|
1100
|
|
|
return cmd.to_string() |
|
1101
|
|
|
|
|
1102
|
|
|
def delete_group_command(self, group_id, ultimate=0): |
|
|
|
|
|
|
1103
|
|
|
"""Generates xml string for delete group on gvmd""" |
|
1104
|
|
|
cmd = XmlCommand('delete_group') |
|
1105
|
|
|
cmd.set_attribute('group_id', group_id) |
|
1106
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1107
|
|
|
|
|
1108
|
|
|
return cmd.to_string() |
|
1109
|
|
|
|
|
1110
|
|
|
def delete_note_command(self, note_id, ultimate=0): |
|
|
|
|
|
|
1111
|
|
|
"""Generates xml string for delete note on gvmd""" |
|
1112
|
|
|
cmd = XmlCommand('delete_note') |
|
1113
|
|
|
cmd.set_attribute('note_id', note_id) |
|
1114
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1115
|
|
|
|
|
1116
|
|
|
return cmd.to_string() |
|
1117
|
|
|
|
|
1118
|
|
|
def delete_override_command(self, override_id, ultimate=0): |
|
|
|
|
|
|
1119
|
|
|
"""Generates xml string for delete override on gvmd""" |
|
1120
|
|
|
cmd = XmlCommand('delete_override') |
|
1121
|
|
|
cmd.set_attribute('override_id', override_id) |
|
1122
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1123
|
|
|
|
|
1124
|
|
|
return cmd.to_string() |
|
1125
|
|
|
|
|
1126
|
|
|
def delete_permission_command(self, permission_id, ultimate=0): |
|
|
|
|
|
|
1127
|
|
|
"""Generates xml string for delete permission on gvmd""" |
|
1128
|
|
|
cmd = XmlCommand('delete_permission') |
|
1129
|
|
|
cmd.set_attribute('permission_id', permission_id) |
|
1130
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1131
|
|
|
|
|
1132
|
|
|
return cmd.to_string() |
|
1133
|
|
|
|
|
1134
|
|
|
def delete_port_list_command(self, port_list_id, ultimate=0): |
|
|
|
|
|
|
1135
|
|
|
"""Generates xml string for delete port on gvmd""" |
|
1136
|
|
|
cmd = XmlCommand('delete_port_list') |
|
1137
|
|
|
cmd.set_attribute('port_list_id', port_list_id) |
|
1138
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1139
|
|
|
|
|
1140
|
|
|
return cmd.to_string() |
|
1141
|
|
|
|
|
1142
|
|
|
def delete_port_range_command(self, port_range_id): |
|
|
|
|
|
|
1143
|
|
|
"""Generates xml string for delete port on gvmd""" |
|
1144
|
|
|
cmd = XmlCommand('delete_port_range') |
|
1145
|
|
|
cmd.set_attribute('port_range_id', port_range_id) |
|
1146
|
|
|
|
|
1147
|
|
|
return cmd.to_string() |
|
1148
|
|
|
|
|
1149
|
|
|
def delete_report_command(self, report_id): |
|
|
|
|
|
|
1150
|
|
|
"""Generates xml string for delete report on gvmd""" |
|
1151
|
|
|
cmd = XmlCommand('delete_report') |
|
1152
|
|
|
cmd.set_attribute('report_id', report_id) |
|
1153
|
|
|
|
|
1154
|
|
|
return cmd.to_string() |
|
1155
|
|
|
|
|
1156
|
|
|
def delete_report_format_command(self, report_format_id, ultimate=0): |
|
|
|
|
|
|
1157
|
|
|
"""Generates xml string for delete report on gvmd""" |
|
1158
|
|
|
cmd = XmlCommand('delete_report_format') |
|
1159
|
|
|
cmd.set_attribute('report_format_id', report_format_id) |
|
1160
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1161
|
|
|
|
|
1162
|
|
|
return cmd.to_string() |
|
1163
|
|
|
|
|
1164
|
|
|
def delete_role_command(self, role_id, ultimate=0): |
|
|
|
|
|
|
1165
|
|
|
"""Generates xml string for delete role on gvmd""" |
|
1166
|
|
|
cmd = XmlCommand('delete_role') |
|
1167
|
|
|
cmd.set_attribute('role_id', role_id) |
|
1168
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1169
|
|
|
|
|
1170
|
|
|
return cmd.to_string() |
|
1171
|
|
|
|
|
1172
|
|
|
def delete_scanner_command(self, scanner_id, ultimate=0): |
|
|
|
|
|
|
1173
|
|
|
"""Generates xml string for delete scanner on gvmd""" |
|
1174
|
|
|
cmd = XmlCommand('delete_scanner') |
|
1175
|
|
|
cmd.set_attribute('scanner_id', scanner_id) |
|
1176
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1177
|
|
|
|
|
1178
|
|
|
return cmd.to_string() |
|
1179
|
|
|
|
|
1180
|
|
|
def delete_schedule_command(self, schedule_id, ultimate=0): |
|
|
|
|
|
|
1181
|
|
|
"""Generates xml string for delete schedule on gvmd""" |
|
1182
|
|
|
# if self.ask_yes_or_no('Are you sure to delete this schedule? '): |
|
1183
|
|
|
cmd = XmlCommand('delete_schedule') |
|
1184
|
|
|
cmd.set_attribute('schedule_id', schedule_id) |
|
1185
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1186
|
|
|
|
|
1187
|
|
|
return cmd.to_string() |
|
1188
|
|
|
|
|
1189
|
|
|
def delete_tag_command(self, tag_id, ultimate=0): |
|
|
|
|
|
|
1190
|
|
|
"""Generates xml string for delete tag on gvmd""" |
|
1191
|
|
|
cmd = XmlCommand('delete_tag') |
|
1192
|
|
|
cmd.set_attribute('tag_id', tag_id) |
|
1193
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1194
|
|
|
|
|
1195
|
|
|
return cmd.to_string() |
|
1196
|
|
|
|
|
1197
|
|
|
def delete_target_command(self, target_id, ultimate=0): |
|
|
|
|
|
|
1198
|
|
|
"""Generates xml string for delete target on gvmd""" |
|
1199
|
|
|
cmd = XmlCommand('delete_target') |
|
1200
|
|
|
cmd.set_attribute('target_id', target_id) |
|
1201
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1202
|
|
|
|
|
1203
|
|
|
return cmd.to_string() |
|
1204
|
|
|
|
|
1205
|
|
|
def delete_task_command(self, task_id, ultimate=0): |
|
|
|
|
|
|
1206
|
|
|
"""Generates xml string for delete task on gvmd""" |
|
1207
|
|
|
cmd = XmlCommand('delete_task') |
|
1208
|
|
|
cmd.set_attribute('task_id', task_id) |
|
1209
|
|
|
cmd.set_attribute('ultimate', ultimate) |
|
1210
|
|
|
|
|
1211
|
|
|
return cmd.to_string() |
|
1212
|
|
|
|
|
1213
|
|
|
def delete_user_command(self, kwargs): |
|
|
|
|
|
|
1214
|
|
|
"""Generates xml string for delete user on gvmd""" |
|
1215
|
|
|
cmd = XmlCommand('delete_user') |
|
1216
|
|
|
|
|
1217
|
|
|
user_id = kwargs.get('user_id', '') |
|
1218
|
|
|
if user_id: |
|
1219
|
|
|
cmd.set_attribute('user_id', user_id) |
|
1220
|
|
|
|
|
1221
|
|
|
name = kwargs.get('name', '') |
|
1222
|
|
|
if name: |
|
1223
|
|
|
cmd.set_attribute('name', name) |
|
1224
|
|
|
|
|
1225
|
|
|
inheritor_id = kwargs.get('inheritor_id', '') |
|
1226
|
|
|
if inheritor_id: |
|
1227
|
|
|
cmd.set_attribute('inheritor_id', inheritor_id) |
|
1228
|
|
|
|
|
1229
|
|
|
inheritor_name = kwargs.get('inheritor_name', '') |
|
1230
|
|
|
if inheritor_name: |
|
1231
|
|
|
cmd.set_attribute('inheritor_name', inheritor_name) |
|
1232
|
|
|
|
|
1233
|
|
|
return cmd.to_string() |
|
1234
|
|
|
|
|
1235
|
|
|
def describe_auth_command(self): |
|
|
|
|
|
|
1236
|
|
|
"""Generates xml string for describe auth on gvmd""" |
|
1237
|
|
|
cmd = XmlCommand('describe_auth') |
|
1238
|
|
|
return cmd.to_string() |
|
1239
|
|
|
|
|
1240
|
|
|
def empty_trashcan_command(self): |
|
|
|
|
|
|
1241
|
|
|
"""Generates xml string for empty trashcan on gvmd""" |
|
1242
|
|
|
cmd = XmlCommand('empty_trashcan') |
|
1243
|
|
|
return cmd.to_string() |
|
1244
|
|
|
|
|
1245
|
|
|
def get_agents_command(self, kwargs): |
|
|
|
|
|
|
1246
|
|
|
"""Generates xml string for get agents on gvmd.""" |
|
1247
|
|
|
cmd = XmlCommand('get_agents') |
|
1248
|
|
|
cmd.set_attributes(kwargs) |
|
1249
|
|
|
return cmd.to_string() |
|
1250
|
|
|
|
|
1251
|
|
|
def get_aggregates_command(self, kwargs): |
|
|
|
|
|
|
1252
|
|
|
"""Generates xml string for get aggregates on gvmd.""" |
|
1253
|
|
|
cmd = XmlCommand('get_aggregates') |
|
1254
|
|
|
cmd.set_attributes(kwargs) |
|
1255
|
|
|
return cmd.to_string() |
|
1256
|
|
|
|
|
1257
|
|
|
def get_alerts_command(self, kwargs): |
|
|
|
|
|
|
1258
|
|
|
"""Generates xml string for get alerts on gvmd.""" |
|
1259
|
|
|
cmd = XmlCommand('get_alerts') |
|
1260
|
|
|
cmd.set_attributes(kwargs) |
|
1261
|
|
|
return cmd.to_string() |
|
1262
|
|
|
|
|
1263
|
|
|
def get_assets_command(self, kwargs): |
|
|
|
|
|
|
1264
|
|
|
"""Generates xml string for get assets on gvmd.""" |
|
1265
|
|
|
cmd = XmlCommand('get_assets') |
|
1266
|
|
|
cmd.set_attributes(kwargs) |
|
1267
|
|
|
return cmd.to_string() |
|
1268
|
|
|
|
|
1269
|
|
|
def get_credentials_command(self, kwargs): |
|
|
|
|
|
|
1270
|
|
|
"""Generates xml string for get credentials on gvmd.""" |
|
1271
|
|
|
cmd = XmlCommand('get_credentials') |
|
1272
|
|
|
cmd.set_attributes(kwargs) |
|
1273
|
|
|
return cmd.to_string() |
|
1274
|
|
|
|
|
1275
|
|
|
def get_configs_command(self, kwargs): |
|
|
|
|
|
|
1276
|
|
|
"""Generates xml string for get configs on gvmd.""" |
|
1277
|
|
|
cmd = XmlCommand('get_configs') |
|
1278
|
|
|
cmd.set_attributes(kwargs) |
|
1279
|
|
|
return cmd.to_string() |
|
1280
|
|
|
|
|
1281
|
|
|
def get_feeds_command(self, kwargs): |
|
|
|
|
|
|
1282
|
|
|
"""Generates xml string for get feeds on gvmd.""" |
|
1283
|
|
|
cmd = XmlCommand('get_feeds') |
|
1284
|
|
|
cmd.set_attributes(kwargs) |
|
1285
|
|
|
return cmd.to_string() |
|
1286
|
|
|
|
|
1287
|
|
|
def get_filters_command(self, kwargs): |
|
|
|
|
|
|
1288
|
|
|
"""Generates xml string for get filters on gvmd.""" |
|
1289
|
|
|
cmd = XmlCommand('get_filters') |
|
1290
|
|
|
cmd.set_attributes(kwargs) |
|
1291
|
|
|
return cmd.to_string() |
|
1292
|
|
|
|
|
1293
|
|
|
def get_groups_command(self, kwargs): |
|
|
|
|
|
|
1294
|
|
|
"""Generates xml string for get groups on gvmd.""" |
|
1295
|
|
|
cmd = XmlCommand('get_groups') |
|
1296
|
|
|
cmd.set_attributes(kwargs) |
|
1297
|
|
|
return cmd.to_string() |
|
1298
|
|
|
|
|
1299
|
|
|
def get_info_command(self, kwargs): |
|
|
|
|
|
|
1300
|
|
|
"""Generates xml string for get info on gvmd.""" |
|
1301
|
|
|
cmd = XmlCommand('get_info') |
|
1302
|
|
|
cmd.set_attributes(kwargs) |
|
1303
|
|
|
return cmd.to_string() |
|
1304
|
|
|
|
|
1305
|
|
|
def get_notes_command(self, kwargs): |
|
|
|
|
|
|
1306
|
|
|
"""Generates xml string for get notes on gvmd.""" |
|
1307
|
|
|
cmd = XmlCommand('get_notes') |
|
1308
|
|
|
cmd.set_attributes(kwargs) |
|
1309
|
|
|
return cmd.to_string() |
|
1310
|
|
|
|
|
1311
|
|
|
def get_nvts_command(self, kwargs): |
|
|
|
|
|
|
1312
|
|
|
"""Generates xml string for get nvts on gvmd.""" |
|
1313
|
|
|
cmd = XmlCommand('get_nvts') |
|
1314
|
|
|
cmd.set_attributes(kwargs) |
|
1315
|
|
|
return cmd.to_string() |
|
1316
|
|
|
|
|
1317
|
|
|
def get_nvt_families_command(self, kwargs): |
|
|
|
|
|
|
1318
|
|
|
"""Generates xml string for get nvt on gvmd.""" |
|
1319
|
|
|
cmd = XmlCommand('get_nvt_families') |
|
1320
|
|
|
cmd.set_attributes(kwargs) |
|
1321
|
|
|
return cmd.to_string() |
|
1322
|
|
|
|
|
1323
|
|
|
def get_overrides_command(self, kwargs): |
|
|
|
|
|
|
1324
|
|
|
"""Generates xml string for get overrides on gvmd.""" |
|
1325
|
|
|
cmd = XmlCommand('get_overrides') |
|
1326
|
|
|
cmd.set_attributes(kwargs) |
|
1327
|
|
|
return cmd.to_string() |
|
1328
|
|
|
|
|
1329
|
|
|
def get_permissions_command(self, kwargs): |
|
|
|
|
|
|
1330
|
|
|
"""Generates xml string for get permissions on gvmd.""" |
|
1331
|
|
|
cmd = XmlCommand('get_permissions') |
|
1332
|
|
|
cmd.set_attributes(kwargs) |
|
1333
|
|
|
return cmd.to_string() |
|
1334
|
|
|
|
|
1335
|
|
|
def get_port_lists_command(self, kwargs): |
|
|
|
|
|
|
1336
|
|
|
"""Generates xml string for get port on gvmd.""" |
|
1337
|
|
|
cmd = XmlCommand('get_port_lists') |
|
1338
|
|
|
cmd.set_attributes(kwargs) |
|
1339
|
|
|
return cmd.to_string() |
|
1340
|
|
|
|
|
1341
|
|
|
def get_preferences_command(self, kwargs): |
|
|
|
|
|
|
1342
|
|
|
"""Generates xml string for get preferences on gvmd.""" |
|
1343
|
|
|
cmd = XmlCommand('get_preferences') |
|
1344
|
|
|
cmd.set_attributes(kwargs) |
|
1345
|
|
|
return cmd.to_string() |
|
1346
|
|
|
|
|
1347
|
|
|
def get_reports_command(self, kwargs): |
|
|
|
|
|
|
1348
|
|
|
"""Generates xml string for get reports on gvmd.""" |
|
1349
|
|
|
cmd = XmlCommand('get_reports') |
|
1350
|
|
|
cmd.set_attributes(kwargs) |
|
1351
|
|
|
return cmd.to_string() |
|
1352
|
|
|
|
|
1353
|
|
|
def get_report_formats_command(self, kwargs): |
|
|
|
|
|
|
1354
|
|
|
"""Generates xml string for get report on gvmd.""" |
|
1355
|
|
|
cmd = XmlCommand('get_report_formats') |
|
1356
|
|
|
cmd.set_attributes(kwargs) |
|
1357
|
|
|
return cmd.to_string() |
|
1358
|
|
|
|
|
1359
|
|
|
def get_results_command(self, kwargs): |
|
|
|
|
|
|
1360
|
|
|
"""Generates xml string for get results on gvmd.""" |
|
1361
|
|
|
cmd = XmlCommand('get_results') |
|
1362
|
|
|
cmd.set_attributes(kwargs) |
|
1363
|
|
|
return cmd.to_string() |
|
1364
|
|
|
|
|
1365
|
|
|
def get_roles_command(self, kwargs): |
|
|
|
|
|
|
1366
|
|
|
"""Generates xml string for get roles on gvmd.""" |
|
1367
|
|
|
cmd = XmlCommand('get_roles') |
|
1368
|
|
|
cmd.set_attributes(kwargs) |
|
1369
|
|
|
return cmd.to_string() |
|
1370
|
|
|
|
|
1371
|
|
|
def get_scanners_command(self, kwargs): |
|
|
|
|
|
|
1372
|
|
|
"""Generates xml string for get scanners on gvmd.""" |
|
1373
|
|
|
cmd = XmlCommand('get_scanners') |
|
1374
|
|
|
cmd.set_attributes(kwargs) |
|
1375
|
|
|
return cmd.to_string() |
|
1376
|
|
|
|
|
1377
|
|
|
def get_schedules_command(self, kwargs): |
|
|
|
|
|
|
1378
|
|
|
"""Generates xml string for get schedules on gvmd.""" |
|
1379
|
|
|
cmd = XmlCommand('get_schedules') |
|
1380
|
|
|
cmd.set_attributes(kwargs) |
|
1381
|
|
|
return cmd.to_string() |
|
1382
|
|
|
|
|
1383
|
|
|
def get_settings_command(self, kwargs): |
|
|
|
|
|
|
1384
|
|
|
"""Generates xml string for get settings on gvmd.""" |
|
1385
|
|
|
cmd = XmlCommand('get_settings') |
|
1386
|
|
|
cmd.set_attributes(kwargs) |
|
1387
|
|
|
return cmd.to_string() |
|
1388
|
|
|
|
|
1389
|
|
|
def get_system_reports_command(self, kwargs): |
|
|
|
|
|
|
1390
|
|
|
"""Generates xml string for get system on gvmd.""" |
|
1391
|
|
|
cmd = XmlCommand('get_system') |
|
1392
|
|
|
cmd.set_attributes(kwargs) |
|
1393
|
|
|
return cmd.to_string() |
|
1394
|
|
|
|
|
1395
|
|
|
def get_tags_command(self, kwargs): |
|
|
|
|
|
|
1396
|
|
|
"""Generates xml string for get tags on gvmd.""" |
|
1397
|
|
|
cmd = XmlCommand('get_tags') |
|
1398
|
|
|
cmd.set_attributes(kwargs) |
|
1399
|
|
|
return cmd.to_string() |
|
1400
|
|
|
|
|
1401
|
|
|
def get_targets_command(self, kwargs): |
|
|
|
|
|
|
1402
|
|
|
"""Generates xml string for get targets on gvmd.""" |
|
1403
|
|
|
cmd = XmlCommand('get_targets') |
|
1404
|
|
|
cmd.set_attributes(kwargs) |
|
1405
|
|
|
return cmd.to_string() |
|
1406
|
|
|
|
|
1407
|
|
|
def get_tasks_command(self, kwargs): |
|
|
|
|
|
|
1408
|
|
|
"""Generates xml string for get tasks on gvmd.""" |
|
1409
|
|
|
cmd = XmlCommand('get_tasks') |
|
1410
|
|
|
cmd.set_attributes(kwargs) |
|
1411
|
|
|
return cmd.to_string() |
|
1412
|
|
|
|
|
1413
|
|
|
def get_users_command(self, kwargs): |
|
|
|
|
|
|
1414
|
|
|
"""Generates xml string for get users on gvmd.""" |
|
1415
|
|
|
cmd = XmlCommand('get_users') |
|
1416
|
|
|
cmd.set_attributes(kwargs) |
|
1417
|
|
|
return cmd.to_string() |
|
1418
|
|
|
|
|
1419
|
|
|
def get_version_command(self): |
|
|
|
|
|
|
1420
|
|
|
"""Generates xml string for get version on gvmd.""" |
|
1421
|
|
|
cmd = XmlCommand('get_version') |
|
1422
|
|
|
return cmd.to_string() |
|
1423
|
|
|
|
|
1424
|
|
|
def help_command(self, kwargs): |
|
|
|
|
|
|
1425
|
|
|
"""Generates xml string for help on gvmd.""" |
|
1426
|
|
|
cmd = XmlCommand('help') |
|
1427
|
|
|
cmd.set_attributes(kwargs) |
|
1428
|
|
|
return cmd.to_string() |
|
1429
|
|
|
|
|
1430
|
|
|
def move_task_command(self, task_id, slave_id): |
|
|
|
|
|
|
1431
|
|
|
"""Generates xml string for move task on gvmd.""" |
|
1432
|
|
|
cmd = XmlCommand('move_task') |
|
1433
|
|
|
cmd.set_attribute('task_id', task_id) |
|
1434
|
|
|
cmd.set_attribute('slave_id', slave_id) |
|
1435
|
|
|
return cmd.to_string() |
|
1436
|
|
|
|
|
1437
|
|
|
def restore_command(self, entity_id): |
|
|
|
|
|
|
1438
|
|
|
"""Generates xml string for restore on gvmd.""" |
|
1439
|
|
|
cmd = XmlCommand('restore') |
|
1440
|
|
|
cmd.set_attribute('id', entity_id) |
|
1441
|
|
|
return cmd.to_string() |
|
1442
|
|
|
|
|
1443
|
|
|
def resume_task_command(self, task_id): |
|
|
|
|
|
|
1444
|
|
|
"""Generates xml string for resume task on gvmd.""" |
|
1445
|
|
|
cmd = XmlCommand('resume_task') |
|
1446
|
|
|
cmd.set_attribute('task_id', task_id) |
|
1447
|
|
|
return cmd.to_string() |
|
1448
|
|
|
|
|
1449
|
|
|
def start_task_command(self, task_id): |
|
|
|
|
|
|
1450
|
|
|
"""Generates xml string for start task on gvmd.""" |
|
1451
|
|
|
cmd = XmlCommand('start_task') |
|
1452
|
|
|
cmd.set_attribute('task_id', task_id) |
|
1453
|
|
|
return cmd.to_string() |
|
1454
|
|
|
|
|
1455
|
|
|
def stop_task_command(self, task_id): |
|
|
|
|
|
|
1456
|
|
|
"""Generates xml string for stop task on gvmd.""" |
|
1457
|
|
|
cmd = XmlCommand('stop_task') |
|
1458
|
|
|
cmd.set_attribute('task_id', task_id) |
|
1459
|
|
|
return cmd.to_string() |
|
1460
|
|
|
|
|
1461
|
|
|
def sync_cert_command(self): |
|
|
|
|
|
|
1462
|
|
|
"""Generates xml string for sync cert on gvmd.""" |
|
1463
|
|
|
cmd = XmlCommand('sync_cert') |
|
1464
|
|
|
return cmd.to_string() |
|
1465
|
|
|
|
|
1466
|
|
|
def sync_config_command(self): |
|
|
|
|
|
|
1467
|
|
|
"""Generates xml string for sync config on gvmd.""" |
|
1468
|
|
|
cmd = XmlCommand('sync_config') |
|
1469
|
|
|
return cmd.to_string() |
|
1470
|
|
|
|
|
1471
|
|
|
def sync_feed_command(self): |
|
|
|
|
|
|
1472
|
|
|
"""Generates xml string for sync feed on gvmd.""" |
|
1473
|
|
|
cmd = XmlCommand('sync_feed') |
|
1474
|
|
|
return cmd.to_string() |
|
1475
|
|
|
|
|
1476
|
|
|
def sync_scap_command(self): |
|
|
|
|
|
|
1477
|
|
|
"""Generates xml string for sync scap on gvmd.""" |
|
1478
|
|
|
cmd = XmlCommand('sync_scap') |
|
1479
|
|
|
return cmd.to_string() |
|
1480
|
|
|
|
|
1481
|
|
|
def test_alert_command(self, alert_id): |
|
|
|
|
|
|
1482
|
|
|
"""Generates xml string for test alert on gvmd.""" |
|
1483
|
|
|
cmd = XmlCommand('test_alert') |
|
1484
|
|
|
cmd.set_attribute('alert_id', alert_id) |
|
1485
|
|
|
return cmd.to_string() |
|
1486
|
|
|
|
|
1487
|
|
|
def verify_agent_command(self, agent_id): |
|
|
|
|
|
|
1488
|
|
|
"""Generates xml string for verify agent on gvmd.""" |
|
1489
|
|
|
cmd = XmlCommand('verify_agent') |
|
1490
|
|
|
cmd.set_attribute('agent_id', agent_id) |
|
1491
|
|
|
return cmd.to_string() |
|
1492
|
|
|
|
|
1493
|
|
|
def verify_report_format_command(self, report_format_id): |
|
|
|
|
|
|
1494
|
|
|
"""Generates xml string for verify report format on gvmd.""" |
|
1495
|
|
|
cmd = XmlCommand('verify_report_format') |
|
1496
|
|
|
cmd.set_attribute('report_format_id', report_format_id) |
|
1497
|
|
|
return cmd.to_string() |
|
1498
|
|
|
|
|
1499
|
|
|
def verify_scanner_command(self, scanner_id): |
|
|
|
|
|
|
1500
|
|
|
"""Generates xml string for verify scanner on gvmd.""" |
|
1501
|
|
|
cmd = XmlCommand('verify_scanner') |
|
1502
|
|
|
cmd.set_attribute('scanner_id', scanner_id) |
|
1503
|
|
|
return cmd.to_string() |
|
1504
|
|
|
|
|
1505
|
|
|
|
|
1506
|
|
|
def pretty_print(xml): |
|
1507
|
|
|
"""Prints beautiful XML-Code |
|
1508
|
|
|
|
|
1509
|
|
|
This function gets an object of list<lxml.etree._Element> |
|
1510
|
|
|
or directly a lxml element. |
|
1511
|
|
|
Print it with good readable format. |
|
1512
|
|
|
|
|
1513
|
|
|
Arguments: |
|
1514
|
|
|
xml: List<lxml.etree.Element> or directly a lxml element |
|
1515
|
|
|
""" |
|
1516
|
|
|
if isinstance(xml, list): |
|
1517
|
|
|
for item in xml: |
|
1518
|
|
|
if etree.iselement(item): |
|
1519
|
|
|
print(etree.tostring(item, pretty_print=True).decode('utf-8')) |
|
1520
|
|
|
else: |
|
1521
|
|
|
print(item) |
|
1522
|
|
|
elif etree.iselement(xml): |
|
1523
|
|
|
print(etree.tostring(xml, pretty_print=True).decode('utf-8')) |
|
1524
|
|
|
|