|
1 | | -#!/usr/bin/python |
| 1 | +#!/usr/bin/env python |
2 | 2 |
|
3 | 3 | """ cli to connect to Stormshield Network Security appliances""" |
4 | 4 |
|
| 5 | +from __future__ import unicode_literals |
5 | 6 | import sys |
6 | 7 | import os |
7 | 8 | import re |
8 | 9 | import logging |
9 | 10 | import readline |
10 | 11 | import getpass |
11 | 12 | import atexit |
12 | | -import xml.dom.minidom |
| 13 | +import defusedxml.minidom |
13 | 14 | import begin |
14 | 15 | from pygments import highlight |
15 | 16 | from pygments.lexers import XmlLexer |
@@ -47,20 +48,18 @@ def make_completer(): |
47 | 48 | return results[state] |
48 | 49 | return custom_complete |
49 | 50 |
|
50 | | -@begin.start(auto_convert=True, short_args=False, lexical_order=True) |
51 | | -@begin.logging |
52 | | -def main(host: 'Remote UTM' = None, |
53 | | - ip: 'Remote UTM ip' = None, |
54 | | - usercert: 'User certificate file' = None, |
55 | | - cabundle: 'CA bundle file' = None, |
56 | | - password: 'Password' = None, |
57 | | - port: 'Remote port' = 443, |
58 | | - user: 'User name' = 'admin', |
59 | | - sslverifypeer: 'Strict SSL CA check' = True, |
60 | | - sslverifyhost: 'Strict SSL host name check' = True, |
61 | | - credentials: 'Privilege list' = None, |
62 | | - script: 'Command script' = None, |
63 | | - outputformat: 'Output format (ini|xml)' = 'ini'): |
| 51 | +def main(host = None, |
| 52 | + ip = None, |
| 53 | + usercert = None, |
| 54 | + cabundle = None, |
| 55 | + password = None, |
| 56 | + port = 443, |
| 57 | + user = 'admin', |
| 58 | + sslverifypeer = True, |
| 59 | + sslverifyhost = True, |
| 60 | + credentials = None, |
| 61 | + script = None, |
| 62 | + outputformat = 'ini'): |
64 | 63 |
|
65 | 64 | for handler in logging.getLogger().handlers: |
66 | 65 | if handler.__class__ == logging.StreamHandler: |
@@ -123,7 +122,7 @@ def main(host: 'Remote UTM' = None, |
123 | 122 | logging.error(str(exception)) |
124 | 123 | sys.exit(1) |
125 | 124 | if outputformat == 'xml': |
126 | | - print(highlight(xml.dom.minidom.parseString(response.xml).toprettyxml(), |
| 125 | + print(highlight(defusedxml.minidom.parseString(response.xml).toprettyxml(), |
127 | 126 | XmlLexer(), TerminalFormatter())) |
128 | 127 | else: |
129 | 128 | print(response.output) |
@@ -191,7 +190,30 @@ def main(host: 'Remote UTM' = None, |
191 | 190 | logging.error(str(exception)) |
192 | 191 | else: |
193 | 192 | if outputformat == 'xml': |
194 | | - print(highlight(xml.dom.minidom.parseString(response.xml).toprettyxml(), |
| 193 | + print(highlight(defusedxml.minidom.parseString(response.xml).toprettyxml(), |
195 | 194 | XmlLexer(), TerminalFormatter())) |
196 | 195 | else: |
197 | 196 | print(response.output) |
| 197 | + |
| 198 | +# set function parameter annotations manually for compatibility with python2 |
| 199 | +main.__annotations__ = { |
| 200 | + 'host': 'Remote UTM', |
| 201 | + 'ip': 'Remote UTM ip', |
| 202 | + 'usercert': 'User certificate file', |
| 203 | + 'cabundle': 'CA bundle file', |
| 204 | + 'password': 'Password', |
| 205 | + 'port': 'Remote port', |
| 206 | + 'user': 'User name', |
| 207 | + 'sslverifypeer': 'Strict SSL CA check', |
| 208 | + 'sslverifyhost': 'Strict SSL host name check', |
| 209 | + 'credentials': 'Privilege list', |
| 210 | + 'script': 'Command script', |
| 211 | + 'outputformat': 'Output format (ini|xml)' |
| 212 | + } |
| 213 | +# use correct input function with python2 |
| 214 | +try: |
| 215 | + input = raw_input |
| 216 | +except NameError: |
| 217 | + pass |
| 218 | + |
| 219 | +begin.start(begin.logging(main)) |
0 commit comments