Total Complexity | 327 |
Total Lines | 1600 |
Duplicated Lines | 2.81 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like gmp.xml often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
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 | FILTER_NAMES = [ |
||
24 | 'Agent', |
||
25 | 'Alert', |
||
26 | 'Asset', |
||
27 | 'Config', |
||
28 | 'Credential', |
||
29 | 'Filter', |
||
30 | 'Group', |
||
31 | 'Note', |
||
32 | 'Override', |
||
33 | 'Permission', |
||
34 | 'Port List', |
||
35 | 'Report', |
||
36 | 'Report Format', |
||
37 | 'Result', |
||
38 | 'Role', |
||
39 | 'Schedule', |
||
40 | 'SecInfo', |
||
41 | 'Tag', |
||
42 | 'Target', |
||
43 | 'Task', |
||
44 | 'User', |
||
45 | ] |
||
46 | |||
47 | class XmlCommandElement: |
||
48 | |||
49 | def __init__(self, element): |
||
50 | self._element = element |
||
51 | |||
52 | def add_element(self, name, text=None, attrs=None): |
||
53 | node = etree.SubElement(self._element, name, attrib=attrs) |
||
54 | node.text = text |
||
55 | return XmlCommandElement(node) |
||
56 | |||
57 | def set_attribute(self, name, value): |
||
58 | self._element.set(name, value) |
||
59 | |||
60 | def append_xml_str(self, xml_text): |
||
61 | node = secET.fromstring(xml_text) |
||
62 | self._element.append(node) |
||
63 | |||
64 | def to_string(self): |
||
65 | return etree.tostring(self._element).decode('utf-8') |
||
66 | |||
67 | def __str__(self): |
||
68 | return self.to_string() |
||
69 | |||
70 | |||
71 | class XmlCommand(XmlCommandElement): |
||
72 | |||
73 | def __init__(self, name): |
||
74 | super().__init__(etree.Element(name)) |
||
75 | |||
76 | |||
77 | class _GmpCommandFactory: |
||
78 | |||
79 | """Factory to create gmp - Greenbone Manangement Protocol - commands |
||
80 | """ |
||
81 | |||
82 | def create_agent_command(self, installer, signature, name, comment='', |
||
83 | copy='', howto_install='', howto_use=''): |
||
84 | |||
85 | cmd = XmlCommand('create_agent') |
||
86 | cmd.add_element('installer', installer) |
||
87 | cmd.add_element('signature', signature) |
||
88 | cmd.add_element('name', name) |
||
89 | |||
90 | if comment: |
||
91 | cmd.add_element('comment', comment) |
||
92 | |||
93 | if copy: |
||
94 | cmd.add_element('copy', copy) |
||
95 | |||
96 | if howto_install: |
||
97 | cmd.add_element('howto_install', howto_install) |
||
98 | |||
99 | if howto_use: |
||
100 | cmd.add_element('howto_use', howto_use) |
||
101 | |||
102 | return cmd.to_string() |
||
103 | |||
104 | def create_alert_command(self, name, condition, event, method, filter_id='', |
||
105 | copy='', comment=''): |
||
106 | |||
107 | cmd = XmlCommand('create_alert') |
||
108 | cmd.add_element('name', name) |
||
109 | |||
110 | if len(condition) > 1: |
||
111 | conditions = cmd.add_element('condition', condition[0]) |
||
112 | for value, key in condition[1].items(): |
||
113 | _data = conditions.add_element('data', value) |
||
114 | _data.add_element('name', key) |
||
115 | |||
116 | elif condition[0] == "Always": |
||
117 | conditions = cmd.add_element('condition', condition[0]) |
||
118 | |||
119 | if len(event) > 1: |
||
120 | events = cmd.add_element('event', event[0]) |
||
121 | for value, key in event[1].items(): |
||
122 | _data = events.add_element('data', value) |
||
123 | _data.add_element('name', key) |
||
124 | |||
125 | if len(method) > 1: |
||
126 | methods = cmd.add_element('method', method[0]) |
||
127 | for value, key in method[1].items(): |
||
128 | _data = methods.add_element('data', value) |
||
129 | _data.add_element('name', key) |
||
130 | |||
131 | if filter_id: |
||
132 | cmd.add_element('filter', attrs={'id': filter_id}) |
||
133 | |||
134 | if copy: |
||
135 | cmd.add_element('copy', copy) |
||
136 | |||
137 | if comment: |
||
138 | cmd.add_element('comment', comment) |
||
139 | |||
140 | return cmd.to_string() |
||
141 | |||
142 | def create_asset_command(self, name, asset_type, comment=''): |
||
143 | if asset_type not in ('host', 'os'): |
||
144 | raise ValueError('create_asset requires asset_type to be either ' |
||
145 | 'host or os') |
||
146 | cmd = XmlCommand('create_asset') |
||
147 | asset = cmd.add_element('asset') |
||
148 | asset.add_element('type', asset_type) |
||
149 | asset.add_element('name', name) |
||
150 | |||
151 | if comment: |
||
152 | asset.add_element('comment', comment) |
||
153 | |||
154 | return cmd.to_string() |
||
155 | |||
156 | def create_authenticate_command(self, username, password): |
||
157 | """Generates string for authentification on gvmd |
||
158 | |||
159 | Creates the gmp authentication xml string. |
||
160 | Inserts the username and password into it. |
||
161 | |||
162 | Keyword Arguments: |
||
163 | username {str} -- Username for GVM User |
||
164 | password {str} -- Password for GVM User |
||
165 | """ |
||
166 | cmd = XmlCommand('authenticate') |
||
167 | |||
168 | credentials = cmd.add_element('credentials') |
||
169 | credentials.add_element('username', username) |
||
170 | credentials.add_element('password', password) |
||
171 | |||
172 | return cmd.to_string() |
||
173 | |||
174 | def create_config_command(self, copy_id, name): |
||
175 | """Generates xml string for create config on gvmd.""" |
||
176 | cmd = XmlCommand('create_config') |
||
177 | cmd.add_element('copy', copy_id) |
||
178 | cmd.add_element('name', name) |
||
179 | |||
180 | return cmd.to_string() |
||
181 | |||
182 | def create_credential_command(self, name, kwargs): |
||
183 | """Generates xml string for create credential on gvmd.""" |
||
184 | cmd = XmlCommand('create_credential') |
||
185 | cmd.add_element('name', name) |
||
186 | |||
187 | comment = kwargs.get('comment', '') |
||
188 | if comment: |
||
189 | cmd.add_element('comment', comment) |
||
190 | |||
191 | copy = kwargs.get('copy', '') |
||
192 | if copy: |
||
193 | cmd.add_element('copy', copy) |
||
194 | |||
195 | allow_insecure = kwargs.get('allow_insecure', '') |
||
196 | if allow_insecure: |
||
197 | cmd.add_element('allow_insecure', allow_insecure) |
||
198 | |||
199 | certificate = kwargs.get('certificate', '') |
||
200 | if certificate: |
||
201 | cmd.add_element('certificate', certificate) |
||
202 | |||
203 | key = kwargs.get('key', '') |
||
204 | if key: |
||
205 | phrase = key['phrase'] |
||
206 | private = key['private'] |
||
207 | if not phrase: |
||
208 | raise ValueError('create_credential requires a phrase element') |
||
209 | if not private: |
||
210 | raise ValueError('create_credential requires a ' |
||
211 | 'private element') |
||
212 | |||
213 | _xmlKey = cmd.add_element('key') |
||
214 | _xmlKey.add_element('phrase', phrase) |
||
215 | _xmlKey.add_element('private', private) |
||
216 | |||
217 | login = kwargs.get('login', '') |
||
218 | if login: |
||
219 | cmd.add_element('login', login) |
||
220 | |||
221 | password = kwargs.get('password', '') |
||
222 | if password: |
||
223 | cmd.add_element('password', password) |
||
224 | |||
225 | auth_algorithm = kwargs.get('auth_algorithm', '') |
||
226 | if auth_algorithm: |
||
227 | if auth_algorithm not in ('md5', 'sha1'): |
||
228 | raise ValueError('create_credential requires auth_algorithm ' |
||
229 | 'to be either md5 or sha1') |
||
230 | cmd.add_element('auth_algorithm', auth_algorithm) |
||
231 | |||
232 | community = kwargs.get('community', '') |
||
233 | if community: |
||
234 | cmd.add_element('community', community) |
||
235 | |||
236 | privacy = kwargs.get('privacy', '') |
||
237 | if privacy: |
||
238 | algorithm = privacy.algorithm |
||
239 | if algorithm not in ('aes', 'des'): |
||
240 | raise ValueError('create_credential requires algorithm ' |
||
241 | 'to be either aes or des') |
||
242 | p_password = privacy.password |
||
243 | _xmlPrivacy = cmd.add_element('privacy') |
||
244 | _xmlPrivacy.add_element('algorithm', algorithm) |
||
245 | _xmlPrivacy.add_element('password', p_password) |
||
246 | |||
247 | cred_type = kwargs.get('type', '') |
||
248 | if cred_type: |
||
249 | if cred_type not in ('cc', 'snmp', 'up', 'usk'): |
||
250 | raise ValueError('create_credential requires type ' |
||
251 | 'to be either cc, snmp, up or usk') |
||
252 | cmd.add_element('type', cred_type) |
||
253 | |||
254 | return cmd.to_string() |
||
255 | |||
256 | def create_filter_command(self, name, make_unique, kwargs): |
||
257 | """Generates xml string for create filter on gvmd.""" |
||
258 | |||
259 | cmd = XmlCommand('create_filter') |
||
260 | _xmlName = cmd.add_element('name', name) |
||
261 | if make_unique: |
||
262 | _xmlName.add_element('make_unique', '1') |
||
263 | else: |
||
264 | _xmlName.add_element('make_unique', '0') |
||
265 | |||
266 | comment = kwargs.get('comment', '') |
||
267 | if comment: |
||
268 | cmd.add_element('comment', comment) |
||
269 | |||
270 | copy = kwargs.get('copy', '') |
||
271 | if copy: |
||
272 | cmd.add_element('copy', copy) |
||
273 | |||
274 | term = kwargs.get('term', '') |
||
275 | if term: |
||
276 | cmd.add_element('term', term) |
||
277 | |||
278 | filter_type = kwargs.get('type', '') |
||
279 | if filter_type: |
||
280 | if filter_type not in FILTER_NAMES: |
||
281 | raise ValueError('create_filter requires type ' |
||
282 | 'to be either cc, snmp, up or usk') |
||
283 | cmd.add_element('type', filter_type) |
||
284 | |||
285 | return cmd.to_string() |
||
286 | |||
287 | def create_group_command(self, name, kwargs): |
||
288 | """Generates xml string for create group on gvmd.""" |
||
289 | |||
290 | cmd = XmlCommand('create_group') |
||
291 | cmd.add_element('name', name) |
||
292 | |||
293 | comment = kwargs.get('comment', '') |
||
294 | if comment: |
||
295 | cmd.add_element('comment', comment) |
||
296 | |||
297 | copy = kwargs.get('copy', '') |
||
298 | if copy: |
||
299 | cmd.add_element('copy', copy) |
||
300 | |||
301 | special = kwargs.get('special', '') |
||
302 | if special: |
||
303 | _xmlSpecial = cmd.add_element('specials') |
||
304 | _xmlSpecial.add_element('full') |
||
305 | |||
306 | users = kwargs.get('users', '') |
||
307 | if users: |
||
308 | cmd.add_element('users', users) |
||
309 | |||
310 | return cmd.to_string() |
||
311 | |||
312 | def create_note_command(self, text, nvt_oid, kwargs): |
||
313 | """Generates xml string for create note on gvmd.""" |
||
314 | |||
315 | cmd = XmlCommand('create_note') |
||
316 | cmd.add_element('text', text) |
||
317 | cmd.add_element('nvt', attrs={"oid": nvt_oid}) |
||
318 | |||
319 | active = kwargs.get('active', '') |
||
320 | if active: |
||
321 | cmd.add_element('active', active) |
||
322 | |||
323 | comment = kwargs.get('comment', '') |
||
324 | if comment: |
||
325 | cmd.add_element('comment', comment) |
||
326 | |||
327 | copy = kwargs.get('copy', '') |
||
328 | if copy: |
||
329 | cmd.add_element('copy', copy) |
||
330 | |||
331 | hosts = kwargs.get('hosts', '') |
||
332 | if hosts: |
||
333 | cmd.add_element('hosts', hosts) |
||
334 | |||
335 | port = kwargs.get('port', '') |
||
336 | if port: |
||
337 | cmd.add_element('port', port) |
||
338 | |||
339 | result_id = kwargs.get('result_id', '') |
||
340 | if result_id: |
||
341 | cmd.add_element('result', attrs={'id': result_id}) |
||
342 | |||
343 | severity = kwargs.get('severity', '') |
||
344 | if severity: |
||
345 | cmd.add_element('severity', severity) |
||
346 | |||
347 | task_id = kwargs.get('task_id', '') |
||
348 | if task_id: |
||
349 | cmd.add_element('task', attrs={'id': task_id}) |
||
350 | |||
351 | threat = kwargs.get('threat', '') |
||
352 | if threat: |
||
353 | cmd.add_element('threat', threat) |
||
354 | |||
355 | return cmd.to_string() |
||
356 | |||
357 | def create_override_command(self, text, nvt_oid, kwargs): |
||
358 | """Generates xml string for create override on gvmd.""" |
||
359 | |||
360 | cmd = XmlCommand('create_override') |
||
361 | cmd.add_element('text', text) |
||
362 | cmd.add_element('nvt', attrs={'oid': nvt_oid}) |
||
363 | |||
364 | active = kwargs.get('active', '') |
||
365 | if active: |
||
366 | cmd.add_element('active', active) |
||
367 | |||
368 | comment = kwargs.get('comment', '') |
||
369 | if comment: |
||
370 | cmd.add_element('comment', comment) |
||
371 | |||
372 | copy = kwargs.get('copy', '') |
||
373 | if copy: |
||
374 | cmd.add_element('copy', copy) |
||
375 | |||
376 | hosts = kwargs.get('hosts', '') |
||
377 | if hosts: |
||
378 | cmd.add_element('hosts', hosts) |
||
379 | |||
380 | port = kwargs.get('port', '') |
||
381 | if port: |
||
382 | cmd.add_element('port', port) |
||
383 | |||
384 | result_id = kwargs.get('result_id', '') |
||
385 | if result_id: |
||
386 | cmd.add_element('result', attrs={'id': result_id}) |
||
387 | |||
388 | severity = kwargs.get('severity', '') |
||
389 | if severity: |
||
390 | cmd.add_element('severity', severity) |
||
391 | |||
392 | new_severity = kwargs.get('new_severity', '') |
||
393 | if new_severity: |
||
394 | cmd.add_element('new_severity', new_severity) |
||
395 | |||
396 | task_id = kwargs.get('task_id', '') |
||
397 | if task_id: |
||
398 | cmd.add_element('task', attrs={'id': task_id}) |
||
399 | |||
400 | threat = kwargs.get('threat', '') |
||
401 | if threat: |
||
402 | cmd.add_element('threat', threat) |
||
403 | |||
404 | new_threat = kwargs.get('new_threat', '') |
||
405 | if new_threat: |
||
406 | cmd.add_element('new_threat', new_threat) |
||
407 | |||
408 | return cmd.to_string() |
||
409 | |||
410 | def create_permission_command(self, name, subject_id, type, kwargs): |
||
411 | # pretty(gmp.create_permission('get_version', |
||
412 | # 'cc9cac5e-39a3-11e4-abae-406186ea4fc5', 'role')) |
||
413 | # libs.gvm_connection.GMPError: Error in NAME |
||
414 | # TODO: Research why!! |
||
415 | |||
416 | if not name: |
||
417 | raise ValueError('create_permission requires a name element') |
||
418 | if not subject_id: |
||
419 | raise ValueError('create_permission requires a subject_id element') |
||
420 | if type not in ('user', 'group', 'role'): |
||
421 | raise ValueError('create_permission requires type ' |
||
422 | 'to be either user, group or role') |
||
423 | |||
424 | cmd = XmlCommand('create_permission') |
||
425 | cmd.add_element('name', name) |
||
426 | _xmlSubject = cmd.add_element('subject', attrs={'id': subject_id}) |
||
427 | _xmlSubject.add_element('type', type) |
||
428 | |||
429 | comment = kwargs.get('comment', '') |
||
430 | if comment: |
||
431 | cmd.add_element('comment', comment) |
||
432 | |||
433 | copy = kwargs.get('copy', '') |
||
434 | if copy: |
||
435 | cmd.add_element('copy', copy) |
||
436 | |||
437 | resource = kwargs.get('resource', '') |
||
438 | if resource: |
||
439 | resource_id = resource.id |
||
440 | resource_type = resource.type |
||
441 | _xmlResource = cmd.add_element('resource', |
||
442 | attrs={'id': resource_id}) |
||
443 | _xmlResource.add_element('type', resource_type) |
||
444 | |||
445 | return cmd.to_string() |
||
446 | |||
447 | def create_port_list_command(self, name, port_range, kwargs): |
||
448 | """Generates xml string for create port list on gvmd.""" |
||
449 | if not name: |
||
450 | raise ValueError('create_port_list requires a name element') |
||
451 | if not port_range: |
||
452 | raise ValueError('create_port_list requires a port_range element') |
||
453 | |||
454 | cmd = XmlCommand('create_port_list') |
||
455 | cmd.add_element('name', name) |
||
456 | cmd.add_element('port_range', port_range) |
||
457 | |||
458 | comment = kwargs.get('comment', '') |
||
459 | if comment: |
||
460 | cmd.add_element('comment', comment) |
||
461 | |||
462 | copy = kwargs.get('copy', '') |
||
463 | if copy: |
||
464 | cmd.add_element('copy', copy) |
||
465 | |||
466 | return cmd.to_string() |
||
467 | |||
468 | def create_port_range_command(self, port_list_id, start, end, type, |
||
469 | comment=''): |
||
470 | """Generates xml string for create port range on gvmd.""" |
||
471 | |||
472 | if not port_list_id: |
||
473 | raise ValueError('create_port_range requires ' |
||
474 | 'a port_list_id element') |
||
475 | if not type: |
||
476 | raise ValueError('create_port_range requires a type element') |
||
477 | |||
478 | cmd.add_element('create_port_range') |
||
479 | cmd.add_element('port_list', attrs={'id': port_list_id}) |
||
480 | cmd.add_element('start', start) |
||
481 | cmd.add_element('end', end) |
||
482 | cmd.add_element('type', type) |
||
483 | |||
484 | if len(comment): |
||
485 | cmd.add_element('comment', comment) |
||
486 | |||
487 | return cmd.to_string() |
||
488 | |||
489 | def create_report_command(self, report_xml_string, kwargs): |
||
490 | """Generates xml string for create report on gvmd.""" |
||
491 | |||
492 | if not report_xml_string: |
||
493 | raise ValueError('create_report requires a report') |
||
494 | |||
495 | task_id = kwargs.get('task_id', '') |
||
496 | task_name = kwargs.get('task_name', '') |
||
497 | |||
498 | cmd = XmlCommand('create_report') |
||
499 | comment = kwargs.get('comment', '') |
||
500 | if task_id: |
||
501 | cmd.add_element('task', attrs={'id': task_id}) |
||
502 | elif task_name: |
||
503 | _xmlTask = cmd.add_element('task') |
||
504 | _xmlTask.add_element('name', task_name) |
||
505 | if comment: |
||
506 | _xmlTask.add_element('comment', comment) |
||
507 | else: |
||
508 | raise ValueError('create_report requires an id or name for a task') |
||
509 | |||
510 | in_assets = kwargs.get('in_assets', '') |
||
511 | if in_assets: |
||
512 | cmd.add_element('in_assets', in_assets) |
||
513 | |||
514 | cmd.append_xml_str(report_xml_string) |
||
515 | |||
516 | return cmd.to_string() |
||
517 | |||
518 | def create_role_command(self, name, kwargs): |
||
519 | """Generates xml string for create role on gvmd.""" |
||
520 | |||
521 | if not name: |
||
522 | raise ValueError('create_role requires a name element') |
||
523 | |||
524 | cmd = XmlCommand('create_role') |
||
525 | cmd.add_element('name', name) |
||
526 | |||
527 | comment = kwargs.get('comment', '') |
||
528 | if comment: |
||
529 | cmd.add_element('comment', comment) |
||
530 | |||
531 | copy = kwargs.get('copy', '') |
||
532 | if copy: |
||
533 | cmd.add_element('copy', copy) |
||
534 | |||
535 | users = kwargs.get('users', '') |
||
536 | if users: |
||
537 | cmd.add_element('users', users) |
||
538 | |||
539 | return cmd.to_string() |
||
540 | |||
541 | def create_scanner_command(self, name, host, port, type, ca_pub, |
||
542 | credential_id, kwargs): |
||
543 | """Generates xml string for create scanner on gvmd.""" |
||
544 | if not name: |
||
545 | raise ValueError('create_scanner requires a name element') |
||
546 | if not host: |
||
547 | raise ValueError('create_scanner requires a host element') |
||
548 | if not port: |
||
549 | raise ValueError('create_scanner requires a port element') |
||
550 | if not type: |
||
551 | raise ValueError('create_scanner requires a type element') |
||
552 | if not ca_pub: |
||
553 | raise ValueError('create_scanner requires a ca_pub element') |
||
554 | if not credential_id: |
||
555 | raise ValueError('create_scanner requires a credential_id element') |
||
556 | |||
557 | cmd = XmlCommand('create_scanner') |
||
558 | cmd.add_element('name', name) |
||
559 | cmd.add_element('host', host) |
||
560 | cmd.add_element('port', port) |
||
561 | cmd.add_element('type', type) |
||
562 | cmd.add_element('ca_pub', ca_pub) |
||
563 | cmd.add_element('credential', attrs={'id': str(credential_id)}) |
||
564 | |||
565 | comment = kwargs.get('comment', '') |
||
566 | if comment: |
||
567 | cmd.add_element('comment', comment) |
||
568 | |||
569 | copy = kwargs.get('copy', '') |
||
570 | if copy: |
||
571 | cmd.add_element('copy', copy) |
||
572 | |||
573 | return cmd.to_string() |
||
574 | |||
575 | def create_schedule_command(self, name, kwargs): |
||
576 | """Generates xml string for create schedule on gvmd.""" |
||
577 | if not name: |
||
578 | raise ValueError('create_schedule requires a name element') |
||
579 | |||
580 | cmd = XmlCommand('create_schedule') |
||
581 | cmd.add_element('name', name) |
||
582 | |||
583 | comment = kwargs.get('comment', '') |
||
584 | if comment: |
||
585 | cmd.add_element('comment', comment) |
||
586 | |||
587 | copy = kwargs.get('copy', '') |
||
588 | if copy: |
||
589 | cmd.add_element('copy', copy) |
||
590 | |||
591 | first_time = kwargs.get('first_time', '') |
||
592 | if first_time: |
||
593 | first_time_minute = first_time['minute'] |
||
594 | first_time_hour = first_time['hour'] |
||
595 | first_time_day_of_month = first_time['day_of_month'] |
||
596 | first_time_month = first_time['month'] |
||
597 | first_time_year = first_time['year'] |
||
598 | |||
599 | _xmlFtime = cmd.add_element('first_time') |
||
600 | _xmlFtime.add_element('minute', first_time_minute) |
||
601 | _xmlFtime.add_element('hour', str(first_time_hour)) |
||
602 | _xmlFtime.add_element('day_of_month', str(first_time_day_of_month)) |
||
603 | _xmlFtime.add_element('month', str(first_time_month)) |
||
604 | _xmlFtime.add_element('year', str(first_time_year)) |
||
605 | |||
606 | duration = kwargs.get('duration', '') |
||
607 | if len(duration) > 1: |
||
608 | _xmlDuration = cmd.add_element('duration', str(duration[0])) |
||
609 | _xmlDuration.add_element('unit', str(duration[1])) |
||
610 | |||
611 | period = kwargs.get('period', '') |
||
612 | if len(period) > 1: |
||
613 | _xmlPeriod = cmd.add_element('period', str(period[0])) |
||
614 | _xmlPeriod.add_element('unit', str(period[1])) |
||
615 | |||
616 | timezone = kwargs.get('timezone', '') |
||
617 | if timezone: |
||
618 | cmd.add_element('timezone', str(timezone)) |
||
619 | |||
620 | return cmd.to_string() |
||
621 | |||
622 | def create_tag_command(self, name, resource_id, resource_type, kwargs): |
||
623 | """Generates xml string for create tag on gvmd.""" |
||
624 | |||
625 | cmd = XmlCommand('create_tag') |
||
626 | _cmd.add_element('name', name) |
||
627 | _xmlResource = cmd.add_element('resource', |
||
628 | attrs={'id': str(resource_id)}) |
||
629 | _xmlResource.add_element('type', resource_type) |
||
630 | |||
631 | comment = kwargs.get('comment', '') |
||
632 | if comment: |
||
633 | cmd.add_element('comment', comment) |
||
634 | |||
635 | copy = kwargs.get('copy', '') |
||
636 | if copy: |
||
637 | cmd.add_element('copy', copy) |
||
638 | |||
639 | value = kwargs.get('value', '') |
||
640 | if value: |
||
641 | cmd.add_element('value', value) |
||
642 | |||
643 | active = kwargs.get('active', '') |
||
644 | if active: |
||
645 | cmd.add_element('active', active) |
||
646 | |||
647 | return cmd.to_string() |
||
648 | |||
649 | def create_target_command(self, name, make_unique, kwargs): |
||
650 | """Generates xml string for create target on gvmd.""" |
||
651 | if not name: |
||
652 | raise ValueError('create_target requires a name element') |
||
653 | |||
654 | cmd = XmlCommand('create_target') |
||
655 | _xmlName = cmd.add_element('name', name) |
||
656 | if make_unique: |
||
657 | _xmlName.add_element('make_unique', '1') |
||
658 | else: |
||
659 | _xmlName.add_element('make_unique', '0') |
||
660 | |||
661 | if 'asset_hosts' in kwargs: |
||
662 | hosts = kwargs.get('asset_hosts') |
||
663 | filter = hosts['filter'] |
||
664 | cmd.add_element('asset_hosts', attrs={'filter': str(filter)}) |
||
665 | elif 'hosts' in kwargs: |
||
666 | hosts = kwargs.get('hosts') |
||
667 | cmd.add_element('hosts', hosts) |
||
668 | else: |
||
669 | raise ValueError('create_target requires either a hosts or ' |
||
670 | 'an asset_hosts element') |
||
671 | |||
672 | if 'comment' in kwargs: |
||
673 | cmd.add_element('comment', kwargs.get('comment')) |
||
674 | |||
675 | if 'copy' in kwargs: |
||
676 | # NOTE: It seems that hosts/asset_hosts is silently ignored by the |
||
677 | # server when copy is supplied. But for specification conformance |
||
678 | # we raise the ValueError above and consider copy optional. |
||
679 | cmd.add_element('copy', kwargs.get('copy')) |
||
680 | |||
681 | if 'exclude_hosts' in kwargs: |
||
682 | cmd.add_element('exclude_hosts', kwargs.get('exclude_hosts')) |
||
683 | |||
684 | if 'ssh_credential' in kwargs: |
||
685 | ssh_credential = kwargs.get('ssh_credential') |
||
686 | if 'id' in ssh_credential: |
||
687 | _xmlSSH = cmd.add_element('ssh_credential', '', |
||
688 | attrs={'id': ssh_credential['id']}) |
||
689 | if 'port' in ssh_credential: |
||
690 | _xmlSSH.add_element('port', ssh_credential['port']) |
||
691 | else: |
||
692 | raise ValueError('ssh_credential requires an id attribute') |
||
693 | |||
694 | if 'smb_credential' in kwargs: |
||
695 | smb_credential = kwargs.get('smb_credential') |
||
696 | if 'id' in smb_credential: |
||
697 | cmd.add_element('smb_credential', |
||
698 | attrs={'id': smb_credential['id']}) |
||
699 | else: |
||
700 | raise ValueError('smb_credential requires an id attribute') |
||
701 | |||
702 | if 'esxi_credential' in kwargs: |
||
703 | esxi_credential = kwargs.get('esxi_credential') |
||
704 | if 'id' in esxi_credential: |
||
705 | cmd.add_element('esxi_credential', |
||
706 | attrs={'id': esxi_credential['id']}) |
||
707 | else: |
||
708 | raise ValueError('esxi_credential requires an id attribute') |
||
709 | |||
710 | if 'snmp_credential' in kwargs: |
||
711 | snmp_credential = kwargs.get('snmp_credential') |
||
712 | if 'id' in snmp_credential: |
||
713 | cmd.add_element('snmp_credential', |
||
714 | attrs={'id': snmp_credential['id']}) |
||
715 | else: |
||
716 | raise ValueError('snmp_credential requires an id attribute') |
||
717 | |||
718 | if 'alive_tests' in kwargs: |
||
719 | # NOTE: As the alive_tests are referenced by their name and some |
||
720 | # names contain ampersand ('&') characters it should be considered |
||
721 | # replacing any characters special to XML in the variable with |
||
722 | # their corresponding entities. |
||
723 | cmd.add_element('alive_tests', kwargs.get('alive_tests')) |
||
724 | |||
725 | if 'reverse_lookup_only' in kwargs: |
||
726 | reverse_lookup_only = kwargs.get('reverse_lookup_only') |
||
727 | if reverse_lookup_only: |
||
728 | cmd.add_element('reverse_lookup_only', '1') |
||
729 | else: |
||
730 | cmd.add_element('reverse_lookup_only', '0') |
||
731 | |||
732 | if 'reverse_lookup_unify' in kwargs: |
||
733 | reverse_lookup_unify = kwargs.get('reverse_lookup_unify') |
||
734 | if reverse_lookup_unify: |
||
735 | cmd.add_element('reverse_lookup_unify', '1') |
||
736 | else: |
||
737 | cmd.add_element('reverse_lookup_unify', '0') |
||
738 | |||
739 | if 'port_range' in kwargs: |
||
740 | cmd.add_element('port_range', kwargs.get('port_range')) |
||
741 | |||
742 | if 'port_list' in kwargs: |
||
743 | port_list = kwargs.get('port_list') |
||
744 | if 'id' in port_list: |
||
745 | cmd.add_element('port_list', |
||
746 | attrs={'id': str(port_list['id'])}) |
||
747 | else: |
||
748 | raise ValueError('port_list requires an id attribute') |
||
749 | |||
750 | return cmd.to_string() |
||
751 | |||
752 | def create_task_command(self, name, config_id, target_id, scanner_id, |
||
753 | alert_ids=None, comment=''): |
||
754 | """Generates xml string for create task on gvmd.""" |
||
755 | |||
756 | if alert_ids is None: |
||
757 | alert_ids = [] |
||
758 | cmd = XmlCommand('create_task') |
||
759 | cmd.add_element('name', name) |
||
760 | cmd.add_element('comment', comment) |
||
761 | cmd.add_element('config', attrs={'id': config_id}) |
||
762 | cmd.add_element('target', attrs={'id': target_id}) |
||
763 | cmd.add_element('scanner', attrs={'id': scanner_id}) |
||
764 | |||
765 | #if given the alert_id is wrapped and integrated suitably as xml |
||
766 | if len(alert_ids) > 0: |
||
767 | if isinstance(alert_ids, str): |
||
768 | #if a single id is given as a string wrap it into a list |
||
769 | alert_ids = [alert_ids] |
||
770 | if isinstance(alert_ids, list): |
||
771 | #parse all given alert id's |
||
772 | for alert in alert_ids: |
||
773 | cmd.add_element('alert', attrs={'id': str(alert)}) |
||
774 | |||
775 | return cmd.to_string() |
||
776 | |||
777 | def create_user_command(self, name, password, copy='', hosts_allow='0', |
||
778 | ifaces_allow='0', role_ids=(), hosts=None, |
||
779 | ifaces=None): |
||
780 | """Generates xml string for create user on gvmd.""" |
||
781 | cmd = XmlCommand('create_user') |
||
782 | cmd.add_element('name', name) |
||
783 | |||
784 | if copy: |
||
785 | cmd.add_element('copy', copy) |
||
786 | |||
787 | if password: |
||
788 | cmd.add_element('password', password) |
||
789 | |||
790 | if hosts is not None: |
||
791 | cmd.add_element('hosts', hosts, attrs={'allow': str(hosts_allow)}) |
||
792 | |||
793 | if ifaces is not None: |
||
794 | cmd.add_element('ifaces', ifaces, |
||
795 | attrs={'allow': str(ifaces_allow)}) |
||
796 | |||
797 | if len(role_ids) > 0: |
||
798 | for role in role_ids: |
||
799 | cmd.add_element('role', attrs={'allow': str(role)}) |
||
800 | |||
801 | return cmd.to_string() |
||
802 | |||
803 | def modify_agent_command(self, agent_id, name='', comment=''): |
||
804 | if not agent_id: |
||
805 | raise ValueError('modify_agent requires an agent_id element') |
||
806 | |||
807 | xmlRoot = etree.Element('modify_agent', agent_id=str(agent_id)) |
||
808 | if name: |
||
809 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
810 | _xmlName.text = name |
||
811 | |||
812 | if comment: |
||
813 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
814 | _xmlComment.text = comment |
||
815 | |||
816 | return etree.tostring(xmlRoot).decode('utf-8') |
||
817 | |||
818 | def modify_alert_command(self, alert_id, kwargs): |
||
819 | if not alert_id: |
||
820 | raise ValueError('modify_alert requires an agent_id element') |
||
821 | |||
822 | xmlRoot = etree.Element('modify_alert', alert_id=str(alert_id)) |
||
823 | |||
824 | name = kwargs.get('name', '') |
||
825 | if name: |
||
826 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
827 | _xmlName.text = name |
||
828 | |||
829 | comment = kwargs.get('comment', '') |
||
830 | if comment: |
||
831 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
832 | _xmlComment.text = comment |
||
833 | |||
834 | filter_id = kwargs.get('filter_id', '') |
||
835 | if filter_id: |
||
836 | _xmlFilter = etree.SubElement(xmlRoot, 'filter', id=filter_id) |
||
837 | |||
838 | event = kwargs.get('event', '') |
||
839 | if len(event) > 1: |
||
840 | _xmlEvent = etree.SubElement(xmlRoot, 'event') |
||
841 | _xmlEvent.text = event[0] |
||
842 | for value, key in event[1].items(): |
||
843 | _xmlData = etree.SubElement(_xmlEvent, 'data') |
||
844 | _xmlData.text = value |
||
845 | _xmlDName = etree.SubElement(_xmlData, 'name') |
||
846 | _xmlDName.text = key |
||
847 | |||
848 | condition = kwargs.get('condition', '') |
||
849 | if len(condition) > 1: |
||
850 | _xmlCond = etree.SubElement(xmlRoot, 'condition') |
||
851 | _xmlCond.text = condition[0] |
||
852 | for value, key in condition[1].items(): |
||
853 | _xmlData = etree.SubElement(_xmlCond, 'data') |
||
854 | _xmlData.text = value |
||
855 | _xmlDName = etree.SubElement(_xmlData, 'name') |
||
856 | _xmlDName.text = key |
||
857 | |||
858 | method = kwargs.get('method', '') |
||
859 | if len(method) > 1: |
||
860 | _xmlMethod = etree.SubElement(xmlRoot, 'method') |
||
861 | _xmlMethod.text = method[0] |
||
862 | for value, key in method[1].items(): |
||
863 | _xmlData = etree.SubElement(_xmlMethod, 'data') |
||
864 | _xmlData.text = value |
||
865 | _xmlDName = etree.SubElement(_xmlData, 'name') |
||
866 | _xmlDName.text = key |
||
867 | |||
868 | return etree.tostring(xmlRoot).decode('utf-8') |
||
869 | |||
870 | def modify_auth_command(self, group_name, auth_conf_settings): |
||
871 | if not group_name: |
||
872 | raise ValueError('modify_auth requires a group element ' |
||
873 | 'with a name attribute') |
||
874 | if not auth_conf_settings: |
||
875 | raise ValueError('modify_auth requires ' |
||
876 | 'an auth_conf_settings element') |
||
877 | |||
878 | xmlRoot = etree.Element('modify_auth') |
||
879 | _xmlGroup = etree.SubElement(xmlRoot, 'group', name=str(group_name)) |
||
880 | |||
881 | for key, value in auth_conf_settings.items(): |
||
882 | _xmlAuthConf = etree.SubElement(_xmlGroup, 'auth_conf_setting') |
||
883 | _xmlKey = etree.SubElement(_xmlAuthConf, 'key') |
||
884 | _xmlKey.text = key |
||
885 | _xmlValue = etree.SubElement(_xmlAuthConf, 'value') |
||
886 | _xmlValue.text = value |
||
887 | |||
888 | return etree.tostring(xmlRoot).decode('utf-8') |
||
889 | |||
890 | def modify_config_command(self, selection, kwargs): |
||
891 | if selection not in ('nvt_pref', 'sca_pref', |
||
892 | 'family_selection', 'nvt_selection'): |
||
893 | raise ValueError('selection must be one of nvt_pref, sca_pref, ' |
||
894 | 'family_selection or nvt_selection') |
||
895 | config_id = kwargs.get('config_id') |
||
896 | |||
897 | xmlRoot = etree.Element('modify_config', config_id=str(config_id)) |
||
898 | |||
899 | if selection in 'nvt_pref': |
||
900 | nvt_oid = kwargs.get('nvt_oid') |
||
901 | name = kwargs.get('name') |
||
902 | value = kwargs.get('value') |
||
903 | _xmlPref = etree.SubElement(xmlRoot, 'preference') |
||
904 | _xmlNvt = etree.SubElement(_xmlPref, 'nvt', oid=nvt_oid) |
||
905 | _xmlName = etree.SubElement(_xmlPref, 'name') |
||
906 | _xmlName.text = name |
||
907 | _xmlValue = etree.SubElement(_xmlPref, 'value') |
||
908 | _xmlValue.text = value |
||
909 | |||
910 | elif selection in 'nvt_selection': |
||
911 | nvt_oid = kwargs.get('nvt_oid') |
||
912 | family = kwargs.get('family') |
||
913 | _xmlNvtSel = etree.SubElement(xmlRoot, 'nvt_selection') |
||
914 | _xmlFamily = etree.SubElement(_xmlNvtSel, 'family') |
||
915 | _xmlFamily.text = family |
||
916 | |||
917 | if isinstance(nvt_oid, list): |
||
918 | for nvt in nvt_oid: |
||
919 | _xmlNvt = etree.SubElement(_xmlNvtSel, 'nvt', oid=nvt) |
||
920 | else: |
||
921 | _xmlNvt = etree.SubElement(_xmlNvtSel, 'nvt', oid=nvt) |
||
922 | |||
923 | elif selection in 'family_selection': |
||
924 | family = kwargs.get('family') |
||
925 | _xmlFamSel = etree.SubElement(xmlRoot, 'family_selection') |
||
926 | _xmlGrow = etree.SubElement(_xmlFamSel, 'growing') |
||
927 | _xmlGrow.text = '1' |
||
928 | _xmlFamily = etree.SubElement(_xmlFamSel, 'family') |
||
929 | _xmlName = etree.SubElement(_xmlFamily, 'name') |
||
930 | _xmlName.text = family |
||
931 | _xmlAll = etree.SubElement(_xmlFamily, 'all') |
||
932 | _xmlAll.text = '1' |
||
933 | _xmlGrowI = etree.SubElement(_xmlFamily, 'growing') |
||
934 | _xmlGrowI.text = '1' |
||
935 | else: |
||
936 | raise NotImplementedError |
||
937 | |||
938 | return etree.tostring(xmlRoot).decode('utf-8') |
||
939 | |||
940 | def modify_credential_command(self, credential_id, kwargs): |
||
941 | if not credential_id: |
||
942 | raise ValueError('modify_credential requires ' |
||
943 | 'a credential_id attribute') |
||
944 | |||
945 | xmlRoot = etree.Element('modify_credential', |
||
946 | credential_id=credential_id) |
||
947 | |||
948 | comment = kwargs.get('comment', '') |
||
949 | if comment: |
||
950 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
951 | _xmlComment.text = comment |
||
952 | |||
953 | name = kwargs.get('name', '') |
||
954 | if name: |
||
955 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
956 | _xmlName.text = name |
||
957 | |||
958 | allow_insecure = kwargs.get('allow_insecure', '') |
||
959 | if allow_insecure: |
||
960 | _xmlAllowinsecure = etree.SubElement(xmlRoot, 'allow_insecure') |
||
961 | _xmlAllowinsecure.text = allow_insecure |
||
962 | |||
963 | certificate = kwargs.get('certificate', '') |
||
964 | if certificate: |
||
965 | _xmlCertificate = etree.SubElement(xmlRoot, 'certificate') |
||
966 | _xmlCertificate.text = certificate |
||
967 | |||
968 | key = kwargs.get('key', '') |
||
969 | if key: |
||
970 | phrase = key['phrase'] |
||
971 | private = key['private'] |
||
972 | if not phrase: |
||
973 | raise ValueError('modify_credential requires a phrase element') |
||
974 | if not private: |
||
975 | raise ValueError('modify_credential requires ' |
||
976 | 'a private element') |
||
977 | _xmlKey = etree.SubElement(xmlRoot, 'key') |
||
978 | _xmlKeyphrase = etree.SubElement(_xmlKey, 'phrase') |
||
979 | _xmlKeyphrase.text = phrase |
||
980 | _xmlKeyprivate = etree.SubElement(_xmlKey, 'private') |
||
981 | _xmlKeyprivate.text = private |
||
982 | |||
983 | login = kwargs.get('login', '') |
||
984 | if login: |
||
985 | _xmlLogin = etree.SubElement(xmlRoot, 'login') |
||
986 | _xmlLogin.text = login |
||
987 | |||
988 | password = kwargs.get('password', '') |
||
989 | if password: |
||
990 | _xmlPass = etree.SubElement(xmlRoot, 'password') |
||
991 | _xmlPass.text = password |
||
992 | |||
993 | auth_algorithm = kwargs.get('auth_algorithm', '') |
||
994 | if auth_algorithm: |
||
995 | if auth_algorithm not in ('md5', 'sha1'): |
||
996 | raise ValueError('modify_credential requires auth_algorithm ' |
||
997 | 'to be either md5 or sha1') |
||
998 | _xmlAuthalg = etree.SubElement(xmlRoot, 'auth_algorithm') |
||
999 | _xmlAuthalg.text = auth_algorithm |
||
1000 | |||
1001 | community = kwargs.get('community', '') |
||
1002 | if community: |
||
1003 | _xmlCommunity = etree.SubElement(xmlRoot, 'community') |
||
1004 | _xmlCommunity.text = community |
||
1005 | |||
1006 | privacy = kwargs.get('privacy', '') |
||
1007 | if privacy: |
||
1008 | algorithm = privacy.algorithm |
||
1009 | if algorithm not in ('aes', 'des'): |
||
1010 | raise ValueError('modify_credential requires algorithm ' |
||
1011 | 'to be either aes or des') |
||
1012 | p_password = privacy.password |
||
1013 | _xmlPrivacy = etree.SubElement(xmlRoot, 'privacy') |
||
1014 | _xmlAlgorithm = etree.SubElement(_xmlPrivacy, 'algorithm') |
||
1015 | _xmlAlgorithm.text = algorithm |
||
1016 | _xmlPpass = etree.SubElement(_xmlPrivacy, 'password') |
||
1017 | _xmlPpass.text = p_password |
||
1018 | |||
1019 | cred_type = kwargs.get('type', '') |
||
1020 | if cred_type: |
||
1021 | if cred_type not in ('cc', 'snmp', 'up', 'usk'): |
||
1022 | raise ValueError('modify_credential requires type ' |
||
1023 | 'to be either cc, snmp, up or usk') |
||
1024 | _xmlCredtype = etree.SubElement(xmlRoot, 'type') |
||
1025 | _xmlCredtype.text = cred_type |
||
1026 | |||
1027 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1028 | |||
1029 | def modify_filter_command(self, filter_id, kwargs): |
||
1030 | if not filter_id: |
||
1031 | raise ValueError('modify_filter requires a filter_id attribute') |
||
1032 | |||
1033 | xmlRoot = etree.Element('modify_filter', filter_id=filter_id) |
||
1034 | |||
1035 | comment = kwargs.get('comment', '') |
||
1036 | if comment: |
||
1037 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
1038 | _xmlComment.text = comment |
||
1039 | |||
1040 | name = kwargs.get('name', '') |
||
1041 | if name: |
||
1042 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
1043 | _xmlName.text = name |
||
1044 | |||
1045 | copy = kwargs.get('copy', '') |
||
1046 | if copy: |
||
1047 | _xmlCopy = etree.SubElement(xmlRoot, 'copy') |
||
1048 | _xmlCopy.text = copy |
||
1049 | |||
1050 | term = kwargs.get('term', '') |
||
1051 | if term: |
||
1052 | _xmlTerm = etree.SubElement(xmlRoot, 'term') |
||
1053 | _xmlTerm.text = term |
||
1054 | |||
1055 | filter_type = kwargs.get('type', '') |
||
1056 | if filter_type: |
||
1057 | if filter_type not in ('cc', 'snmp', 'up', 'usk'): |
||
1058 | raise ValueError('modify_filter requires type ' |
||
1059 | 'to be either cc, snmp, up or usk') |
||
1060 | _xmlFiltertype = etree.SubElement(xmlRoot, 'type') |
||
1061 | _xmlFiltertype.text = filter_type |
||
1062 | |||
1063 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1064 | |||
1065 | View Code Duplication | def modify_group_command(self, group_id, kwargs): |
|
1066 | if not group_id: |
||
1067 | raise ValueError('modify_group requires a group_id attribute') |
||
1068 | |||
1069 | xmlRoot = etree.Element('modify_group', group_id=group_id) |
||
1070 | |||
1071 | comment = kwargs.get('comment', '') |
||
1072 | if comment: |
||
1073 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
1074 | _xmlComment.text = comment |
||
1075 | |||
1076 | name = kwargs.get('name', '') |
||
1077 | if name: |
||
1078 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
1079 | _xmlName.text = name |
||
1080 | |||
1081 | users = kwargs.get('users', '') |
||
1082 | if users: |
||
1083 | _xmlUser = etree.SubElement(xmlRoot, 'users') |
||
1084 | _xmlUser.text = users |
||
1085 | |||
1086 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1087 | |||
1088 | def modify_note_command(self, note_id, text, kwargs): |
||
1089 | if not note_id: |
||
1090 | raise ValueError('modify_note requires a note_id attribute') |
||
1091 | if not text: |
||
1092 | raise ValueError('modify_note requires a text element') |
||
1093 | |||
1094 | xmlRoot = etree.Element('modify_note', note_id=note_id) |
||
1095 | _xmlText = etree.SubElement(xmlRoot, 'text') |
||
1096 | _xmlText.text = text |
||
1097 | |||
1098 | active = kwargs.get('active', '') |
||
1099 | if active: |
||
1100 | _xmlActive = etree.SubElement(xmlRoot, 'active') |
||
1101 | _xmlActive.text = active |
||
1102 | |||
1103 | hosts = kwargs.get('hosts', '') |
||
1104 | if hosts: |
||
1105 | _xmlHosts = etree.SubElement(xmlRoot, 'hosts') |
||
1106 | _xmlHosts.text = hosts |
||
1107 | |||
1108 | port = kwargs.get('port', '') |
||
1109 | if port: |
||
1110 | _xmlPort = etree.SubElement(xmlRoot, 'port') |
||
1111 | _xmlPort.text = port |
||
1112 | |||
1113 | result_id = kwargs.get('result_id', '') |
||
1114 | if result_id: |
||
1115 | _xmlResultid = etree.SubElement(xmlRoot, 'result', id=result_id) |
||
1116 | |||
1117 | severity = kwargs.get('severity', '') |
||
1118 | if severity: |
||
1119 | _xmlSeverity = etree.SubElement(xmlRoot, 'severity') |
||
1120 | _xmlSeverity.text = severity |
||
1121 | |||
1122 | task_id = kwargs.get('task_id', '') |
||
1123 | if task_id: |
||
1124 | _xmlTaskid = etree.SubElement(xmlRoot, 'task', id=task_id) |
||
1125 | |||
1126 | threat = kwargs.get('threat', '') |
||
1127 | if threat: |
||
1128 | _xmlThreat = etree.SubElement(xmlRoot, 'threat') |
||
1129 | _xmlThreat.text = threat |
||
1130 | |||
1131 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1132 | |||
1133 | def modify_override_command(self, override_id, text, kwargs): |
||
1134 | xmlRoot = etree.Element('modify_override', |
||
1135 | override_id=override_id) |
||
1136 | _xmlText = etree.SubElement(xmlRoot, 'text') |
||
1137 | _xmlText.text = text |
||
1138 | |||
1139 | active = kwargs.get('active', '') |
||
1140 | if active: |
||
1141 | _xmlActive = etree.SubElement(xmlRoot, 'active') |
||
1142 | _xmlActive.text = active |
||
1143 | |||
1144 | hosts = kwargs.get('hosts', '') |
||
1145 | if hosts: |
||
1146 | _xmlHosts = etree.SubElement(xmlRoot, 'hosts') |
||
1147 | _xmlHosts.text = hosts |
||
1148 | |||
1149 | port = kwargs.get('port', '') |
||
1150 | if port: |
||
1151 | _xmlPort = etree.SubElement(xmlRoot, 'port') |
||
1152 | _xmlPort.text = port |
||
1153 | |||
1154 | result_id = kwargs.get('result_id', '') |
||
1155 | if result_id: |
||
1156 | _xmlResultid = etree.SubElement(xmlRoot, 'result', id=result_id) |
||
1157 | |||
1158 | severity = kwargs.get('severity', '') |
||
1159 | if severity: |
||
1160 | _xmlSeverity = etree.SubElement(xmlRoot, 'severity') |
||
1161 | _xmlSeverity.text = severity |
||
1162 | |||
1163 | new_severity = kwargs.get('new_severity', '') |
||
1164 | if new_severity: |
||
1165 | _xmlNSeverity = etree.SubElement(xmlRoot, 'new_severity') |
||
1166 | _xmlNSeverity.text = new_severity |
||
1167 | |||
1168 | task_id = kwargs.get('task_id', '') |
||
1169 | if task_id: |
||
1170 | _xmlTaskid = etree.SubElement(xmlRoot, 'task', id=task_id) |
||
1171 | |||
1172 | threat = kwargs.get('threat', '') |
||
1173 | if threat: |
||
1174 | _xmlThreat = etree.SubElement(xmlRoot, 'threat') |
||
1175 | _xmlThreat.text = threat |
||
1176 | |||
1177 | new_threat = kwargs.get('new_threat', '') |
||
1178 | if new_threat: |
||
1179 | _xmlNThreat = etree.SubElement(xmlRoot, 'new_threat') |
||
1180 | _xmlNThreat.text = new_threat |
||
1181 | |||
1182 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1183 | |||
1184 | def modify_permission_command(self, permission_id, kwargs): |
||
1185 | if not permission_id: |
||
1186 | raise ValueError('modify_permission requires ' |
||
1187 | 'a permission_id element') |
||
1188 | |||
1189 | xmlRoot = etree.Element('modify_permission', |
||
1190 | permission_id=permission_id) |
||
1191 | |||
1192 | comment = kwargs.get('comment', '') |
||
1193 | if comment: |
||
1194 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
1195 | _xmlComment.text = comment |
||
1196 | |||
1197 | name = kwargs.get('name', '') |
||
1198 | if name: |
||
1199 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
1200 | _xmlName.text = name |
||
1201 | |||
1202 | resource = kwargs.get('resource', '') |
||
1203 | if resource: |
||
1204 | resource_id = resource['id'] |
||
1205 | resource_type = resource['type'] |
||
1206 | _xmlResource = etree.SubElement(xmlRoot, 'resource', |
||
1207 | id=resource_id) |
||
1208 | _xmlRType = etree.SubElement(_xmlResource, 'type') |
||
1209 | _xmlRType.text = resource_type |
||
1210 | |||
1211 | subject = kwargs.get('subject', '') |
||
1212 | if subject: |
||
1213 | subject_id = subject['id'] |
||
1214 | subject_type = subject['type'] |
||
1215 | _xmlSubject = etree.SubElement(xmlRoot, 'subject', id=subject_id) |
||
1216 | _xmlType = etree.SubElement(_xmlSubject, 'type') |
||
1217 | _xmlType.text = subject_type |
||
1218 | |||
1219 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1220 | |||
1221 | def modify_port_list_command(self, port_list_id, kwargs): |
||
1222 | if not port_list_id: |
||
1223 | raise ValueError('modify_port_list requires ' |
||
1224 | 'a port_list_id attribute') |
||
1225 | xmlRoot = etree.Element('modify_port_list', |
||
1226 | port_list_id=port_list_id) |
||
1227 | |||
1228 | comment = kwargs.get('comment', '') |
||
1229 | if comment: |
||
1230 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
1231 | _xmlComment.text = comment |
||
1232 | |||
1233 | name = kwargs.get('name', '') |
||
1234 | if name: |
||
1235 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
1236 | _xmlName.text = name |
||
1237 | |||
1238 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1239 | |||
1240 | def modify_report_format_command(self, report_format_id, kwargs): |
||
1241 | if len(kwargs) < 1: |
||
1242 | raise Exception('modify_report_format: Missing parameter') |
||
1243 | |||
1244 | xmlRoot = etree.Element('modify_report_format', |
||
1245 | report_format_id=report_format_id) |
||
1246 | |||
1247 | active = kwargs.get('active', '') |
||
1248 | if active: |
||
1249 | _xmlActive = etree.SubElement(xmlRoot, 'active') |
||
1250 | _xmlActive.text = active |
||
1251 | |||
1252 | name = kwargs.get('name', '') |
||
1253 | if name: |
||
1254 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
1255 | _xmlName.text = name |
||
1256 | |||
1257 | summary = kwargs.get('summary', '') |
||
1258 | if summary: |
||
1259 | _xmlSummary = etree.SubElement(xmlRoot, 'summary') |
||
1260 | _xmlSummary.text = summary |
||
1261 | |||
1262 | param = kwargs.get('param', '') |
||
1263 | if param: |
||
1264 | p_name = param[0] |
||
1265 | p_value = param[1] |
||
1266 | _xmlParam = etree.SubElement(xmlRoot, 'param') |
||
1267 | _xmlPname = etree.SubElement(_xmlParam, 'name') |
||
1268 | _xmlPname.text = p_name |
||
1269 | _xmlValue = etree.SubElement(_xmlParam, 'value') |
||
1270 | _xmlValue.text = p_value |
||
1271 | |||
1272 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1273 | |||
1274 | View Code Duplication | def modify_role_command(self, role_id, kwargs): |
|
1275 | if not role_id: |
||
1276 | raise ValueError('modify_role requires a role_id element') |
||
1277 | |||
1278 | xmlRoot = etree.Element('modify_role', |
||
1279 | role_id=role_id) |
||
1280 | |||
1281 | comment = kwargs.get('comment', '') |
||
1282 | if comment: |
||
1283 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
1284 | _xmlComment.text = comment |
||
1285 | |||
1286 | name = kwargs.get('name', '') |
||
1287 | if name: |
||
1288 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
1289 | _xmlName.text = name |
||
1290 | |||
1291 | users = kwargs.get('users', '') |
||
1292 | if users: |
||
1293 | _xmlUser = etree.SubElement(xmlRoot, 'users') |
||
1294 | _xmlUser.text = users |
||
1295 | |||
1296 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1297 | |||
1298 | def modify_scanner_command(self, scanner_id, host, port, scanner_type, |
||
1299 | kwargs): |
||
1300 | if not scanner_id: |
||
1301 | raise ValueError('modify_scanner requires a scanner_id element') |
||
1302 | if not host: |
||
1303 | raise ValueError('modify_scanner requires a host element') |
||
1304 | if not port: |
||
1305 | raise ValueError('modify_scanner requires a port element') |
||
1306 | if not scanner_type: |
||
1307 | raise ValueError('modify_scanner requires a type element') |
||
1308 | |||
1309 | xmlRoot = etree.Element('modify_scanner', scanner_id=scanner_id) |
||
1310 | _xmlHost = etree.SubElement(xmlRoot, 'host') |
||
1311 | _xmlHost.text = host |
||
1312 | _xmlPort = etree.SubElement(xmlRoot, 'port') |
||
1313 | _xmlPort.text = port |
||
1314 | _xmlType = etree.SubElement(xmlRoot, 'type') |
||
1315 | _xmlType.text = scanner_type |
||
1316 | |||
1317 | comment = kwargs.get('comment', '') |
||
1318 | if comment: |
||
1319 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
1320 | _xmlComment.text = comment |
||
1321 | |||
1322 | name = kwargs.get('name', '') |
||
1323 | if name: |
||
1324 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
1325 | _xmlName.text = name |
||
1326 | |||
1327 | ca_pub = kwargs.get('ca_pub', '') |
||
1328 | if ca_pub: |
||
1329 | _xmlCAPub = etree.SubElement(xmlRoot, 'ca_pub') |
||
1330 | _xmlCAPub.text = ca_pub |
||
1331 | |||
1332 | credential_id = kwargs.get('credential_id', '') |
||
1333 | if credential_id: |
||
1334 | _xmlCred = etree.SubElement(xmlRoot, 'credential', |
||
1335 | id=str(credential_id)) |
||
1336 | |||
1337 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1338 | |||
1339 | def modify_schedule_command(self, schedule_id, kwargs): |
||
1340 | if not schedule_id: |
||
1341 | raise ValueError('modify_schedule requires a schedule_id element') |
||
1342 | |||
1343 | xmlRoot = etree.Element('modify_schedule', schedule_id=schedule_id) |
||
1344 | comment = kwargs.get('comment', '') |
||
1345 | if comment: |
||
1346 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
1347 | _xmlComment.text = comment |
||
1348 | |||
1349 | name = kwargs.get('name', '') |
||
1350 | if name: |
||
1351 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
1352 | _xmlName.text = name |
||
1353 | |||
1354 | first_time = kwargs.get('first_time', '') |
||
1355 | if first_time: |
||
1356 | first_time_minute = first_time['minute'] |
||
1357 | first_time_hour = first_time['hour'] |
||
1358 | first_time_day_of_month = first_time['day_of_month'] |
||
1359 | first_time_month = first_time['month'] |
||
1360 | first_time_year = first_time['year'] |
||
1361 | |||
1362 | _xmlFtime = etree.SubElement(xmlRoot, 'first_time') |
||
1363 | _xmlMinute = etree.SubElement(_xmlFtime, 'minute') |
||
1364 | _xmlMinute.text = str(first_time_minute) |
||
1365 | _xmlHour = etree.SubElement(_xmlFtime, 'hour') |
||
1366 | _xmlHour.text = str(first_time_hour) |
||
1367 | _xmlDay = etree.SubElement(_xmlFtime, 'day_of_month') |
||
1368 | _xmlDay.text = str(first_time_day_of_month) |
||
1369 | _xmlMonth = etree.SubElement(_xmlFtime, 'month') |
||
1370 | _xmlMonth.text = str(first_time_month) |
||
1371 | _xmlYear = etree.SubElement(_xmlFtime, 'year') |
||
1372 | _xmlYear.text = str(first_time_year) |
||
1373 | |||
1374 | duration = kwargs.get('duration', '') |
||
1375 | if len(duration) > 1: |
||
1376 | _xmlDuration = etree.SubElement(xmlRoot, 'duration') |
||
1377 | _xmlDuration.text = str(duration[0]) |
||
1378 | _xmlUnit = etree.SubElement(_xmlDuration, 'unit') |
||
1379 | _xmlUnit.text = str(duration[1]) |
||
1380 | |||
1381 | period = kwargs.get('period', '') |
||
1382 | if len(period) > 1: |
||
1383 | _xmlPeriod = etree.SubElement(xmlRoot, 'period') |
||
1384 | _xmlPeriod.text = str(period[0]) |
||
1385 | _xmlPUnit = etree.SubElement(_xmlPeriod, 'unit') |
||
1386 | _xmlPUnit.text = str(period[1]) |
||
1387 | |||
1388 | timezone = kwargs.get('timezone', '') |
||
1389 | if timezone: |
||
1390 | _xmlTimezone = etree.SubElement(xmlRoot, 'timezone') |
||
1391 | _xmlTimezone.text = str(timezone) |
||
1392 | |||
1393 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1394 | |||
1395 | def modify_tag_command(self, tag_id, kwargs): |
||
1396 | if not tag_id: |
||
1397 | raise ValueError('modify_tag requires a tag_id element') |
||
1398 | |||
1399 | xmlRoot = etree.Element('modify_tag', tag_id=str(tag_id)) |
||
1400 | |||
1401 | comment = kwargs.get('comment', '') |
||
1402 | if comment: |
||
1403 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
1404 | _xmlComment.text = comment |
||
1405 | |||
1406 | name = kwargs.get('name', '') |
||
1407 | if name: |
||
1408 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
1409 | _xmlName.text = name |
||
1410 | |||
1411 | value = kwargs.get('value', '') |
||
1412 | if value: |
||
1413 | _xmlValue = etree.SubElement(xmlRoot, 'value') |
||
1414 | _xmlValue.text = value |
||
1415 | |||
1416 | active = kwargs.get('active', '') |
||
1417 | if active: |
||
1418 | _xmlActive = etree.SubElement(xmlRoot, 'active') |
||
1419 | _xmlActive.text = value |
||
1420 | |||
1421 | resource = kwargs.get('resource', '') |
||
1422 | if resource: |
||
1423 | resource_id = resource['id'] |
||
1424 | resource_type = resource['type'] |
||
1425 | _xmlResource = etree.SubElement(xmlRoot, 'resource', |
||
1426 | resource_id=resource_id) |
||
1427 | _xmlRType = etree.SubElement(_xmlResource, 'type') |
||
1428 | _xmlRType.text = resource_type |
||
1429 | |||
1430 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1431 | |||
1432 | def modify_target_command(self, target_id, kwargs): |
||
1433 | if not target_id: |
||
1434 | raise ValueError('modify_target requires a target_id element') |
||
1435 | |||
1436 | xmlRoot = etree.Element('modify_target', target_id=target_id) |
||
1437 | |||
1438 | comment = kwargs.get('comment', '') |
||
1439 | if comment: |
||
1440 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
1441 | _xmlComment.text = comment |
||
1442 | |||
1443 | name = kwargs.get('name', '') |
||
1444 | if name: |
||
1445 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
1446 | _xmlName.text = name |
||
1447 | |||
1448 | hosts = kwargs.get('hosts', '') |
||
1449 | if hosts: |
||
1450 | _xmlHosts = etree.SubElement(xmlRoot, 'hosts') |
||
1451 | _xmlHosts.text = hosts |
||
1452 | |||
1453 | copy = kwargs.get('copy', '') |
||
1454 | if copy: |
||
1455 | _xmlCopy = etree.SubElement(xmlRoot, 'copy') |
||
1456 | _xmlCopy.text = kwargs.get('copy') |
||
1457 | |||
1458 | exclude_hosts = kwargs.get('exclude_hosts', '') |
||
1459 | if exclude_hosts: |
||
1460 | _xmlExHosts = etree.SubElement(xmlRoot, 'exclude_hosts') |
||
1461 | _xmlExHosts.text = kwargs.get('exclude_hosts') |
||
1462 | |||
1463 | alive_tests = kwargs.get('alive_tests', '') |
||
1464 | if alive_tests: |
||
1465 | _xmlAlive = etree.SubElement(xmlRoot, 'alive_tests') |
||
1466 | _xmlAlive.text = kwargs.get('alive_tests') |
||
1467 | |||
1468 | reverse_lookup_only = kwargs.get('reverse_lookup_only', '') |
||
1469 | if reverse_lookup_only: |
||
1470 | _xmlLookup = etree.SubElement(xmlRoot, 'reverse_lookup_only') |
||
1471 | _xmlLookup.text = reverse_lookup_only |
||
1472 | |||
1473 | reverse_lookup_unify = kwargs.get('reverse_lookup_unify', '') |
||
1474 | if reverse_lookup_unify: |
||
1475 | _xmlLookupU = etree.SubElement(xmlRoot, 'reverse_lookup_unify') |
||
1476 | _xmlLookupU.text = reverse_lookup_unify |
||
1477 | |||
1478 | port_range = kwargs.get('port_range', '') |
||
1479 | if port_range: |
||
1480 | _xmlPortR = etree.SubElement(xmlRoot, 'port_range') |
||
1481 | _xmlPortR.text = kwargs.get('port_range') |
||
1482 | |||
1483 | port_list = kwargs.get('port_list', '') |
||
1484 | if port_list: |
||
1485 | _xmlPortL = etree.SubElement(xmlRoot, 'port_list', |
||
1486 | id=str(port_list)) |
||
1487 | |||
1488 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1489 | |||
1490 | def modify_task_command(self, task_id, kwargs): |
||
1491 | if not task_id: |
||
1492 | raise ValueError('modify_task requires a task_id element') |
||
1493 | |||
1494 | xmlRoot = etree.Element('modify_task', task_id=task_id) |
||
1495 | |||
1496 | name = kwargs.get('name', '') |
||
1497 | if name: |
||
1498 | _xmlName = etree.SubElement(xmlRoot, 'name') |
||
1499 | _xmlName.text = name |
||
1500 | |||
1501 | comment = kwargs.get('comment', '') |
||
1502 | if comment: |
||
1503 | _xmlComment = etree.SubElement(xmlRoot, 'comment') |
||
1504 | _xmlComment.text = comment |
||
1505 | |||
1506 | target_id = kwargs.get('target_id', '') |
||
1507 | if target_id: |
||
1508 | _xmlTarget = etree.SubElement(xmlRoot, 'target', id=target_id) |
||
1509 | |||
1510 | scanner = kwargs.get('scanner', '') |
||
1511 | if scanner: |
||
1512 | _xmlScanner = etree.SubElement(xmlRoot, 'scanner', id=scanner) |
||
1513 | |||
1514 | schedule_periods = kwargs.get('schedule_periods', '') |
||
1515 | if schedule_periods: |
||
1516 | _xmlPeriod = etree.SubElement(xmlRoot, 'schedule_periods') |
||
1517 | _xmlPeriod.text = str(schedule_periods) |
||
1518 | |||
1519 | schedule = kwargs.get('schedule', '') |
||
1520 | if schedule: |
||
1521 | _xmlSched = etree.SubElement(xmlRoot, 'schedule', id=str(schedule)) |
||
1522 | |||
1523 | alert = kwargs.get('alert', '') |
||
1524 | if alert: |
||
1525 | _xmlAlert = etree.SubElement(xmlRoot, 'alert', id=str(alert)) |
||
1526 | |||
1527 | observers = kwargs.get('observers', '') |
||
1528 | if observers: |
||
1529 | _xmlObserver = etree.SubElement(xmlRoot, 'observers') |
||
1530 | _xmlObserver.text = str(observers) |
||
1531 | |||
1532 | preferences = kwargs.get('preferences', '') |
||
1533 | if preferences: |
||
1534 | _xmlPrefs = etree.SubElement(xmlRoot, 'preferences') |
||
1535 | for n in range(len(preferences["scanner_name"])): |
||
1536 | preferences_scanner_name = preferences["scanner_name"][n] |
||
1537 | preferences_value = preferences["value"][n] |
||
1538 | _xmlPref = etree.SubElement(_xmlPrefs, 'preference') |
||
1539 | _xmlScan = etree.SubElement(_xmlPref, 'scanner_name') |
||
1540 | _xmlScan.text = preferences_scanner_name |
||
1541 | _xmlVal = etree.SubElement(_xmlPref, 'value') |
||
1542 | _xmlVal.text = preferences_value |
||
1543 | |||
1544 | file = kwargs.get('file', '') |
||
1545 | if file: |
||
1546 | file_name = file['name'] |
||
1547 | file_action = file['action'] |
||
1548 | if file_action != "update" and file_action != "remove": |
||
1549 | raise ValueError('action can only be "update" or "remove"!') |
||
1550 | _xmlFile = etree.SubElement(xmlRoot, 'file', name=file_name, |
||
1551 | action=file_action) |
||
1552 | |||
1553 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1554 | |||
1555 | def modify_user_command(self, kwargs): |
||
1556 | user_id = kwargs.get('user_id', '') |
||
1557 | name = kwargs.get('name', '') |
||
1558 | |||
1559 | if not user_id and not name: |
||
1560 | raise ValueError('modify_user requires ' |
||
1561 | 'either a user_id or a name element') |
||
1562 | |||
1563 | xmlRoot = etree.Element('modify_user', user_id=str(user_id)) |
||
1564 | |||
1565 | new_name = kwargs.get('new_name', '') |
||
1566 | if new_name: |
||
1567 | _xmlName = etree.SubElement(xmlRoot, 'new_name') |
||
1568 | _xmlName.text = new_name |
||
1569 | |||
1570 | password = kwargs.get('password', '') |
||
1571 | if password: |
||
1572 | _xmlPass = etree.SubElement(xmlRoot, 'password') |
||
1573 | _xmlPass.text = password |
||
1574 | |||
1575 | role_ids = kwargs.get('role_ids', '') |
||
1576 | if len(role_ids) > 0: |
||
1577 | for role in role_ids: |
||
1578 | _xmlRole = etree.SubElement(xmlRoot, 'role', |
||
1579 | id=str(role)) |
||
1580 | hosts = kwargs.get('hosts', '') |
||
1581 | hosts_allow = kwargs.get('hosts_allow', '') |
||
1582 | if hosts or hosts_allow: |
||
1583 | _xmlHosts = etree.SubElement(xmlRoot, 'hosts', |
||
1584 | allow=str(hosts_allow)) |
||
1585 | _xmlHosts.text = hosts |
||
1586 | |||
1587 | ifaces = kwargs.get('ifaces', '') |
||
1588 | ifaces_allow = kwargs.get('ifaces_allow', '') |
||
1589 | if ifaces or ifaces_allow: |
||
1590 | _xmlIFaces = etree.SubElement(xmlRoot, 'ifaces', |
||
1591 | allow=str(ifaces_allow)) |
||
1592 | _xmlIFaces.text = ifaces |
||
1593 | |||
1594 | sources = kwargs.get('sources', '') |
||
1595 | if sources: |
||
1596 | _xmlSource = etree.SubElement(xmlRoot, 'sources') |
||
1597 | _xmlSource.text = sources |
||
1598 | |||
1599 | return etree.tostring(xmlRoot).decode('utf-8') |
||
1600 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.