Skip to content

Commit 2c9face

Browse files
committed
Squashed commit of the following:
commit 0849e5b43eb8fdb0bb888a0c62b7b4281b1eadae Author: remi.pauchet <remi.pauchet@stormshield.eu> Date: Thu May 9 17:07:07 2019 +0200 fix cmd.complete new path commit 18303e74fc38ba6a517686083c7cdfcd4777c3e8 Author: remi.pauchet <remi.pauchet@stormshield.eu> Date: Thu May 9 15:43:44 2019 +0200 Fix socks install and version handling commit 5fb3610ab08685abf0cbd9b782a6172c43123d67 Author: remi.pauchet <remi.pauchet@stormshield.eu> Date: Tue Apr 30 17:44:57 2019 +0200 fix http proxy commit 73ea82b3f4490531215f727e048f9b04b31e25f6 Author: remi.pauchet <remi.pauchet@stormshield.eu> Date: Tue Apr 30 17:19:23 2019 +0200 fix commit 5b8e34dea77768f7614c2af5a431345c3b534bef Author: remi.pauchet <remi.pauchet@stormshield.eu> Date: Tue Apr 30 17:07:47 2019 +0200 Add socks/http proxy option, fix log file, use entry-points for windows snscli compatibility commit 07f485be81d952be99788a2849d08ca51da024c7 Author: remi.pauchet <remi.pauchet@stormshield.eu> Date: Mon Apr 29 14:35:47 2019 +0200 Add socks/http proxy support
1 parent 93ecedd commit 2c9face

File tree

9 files changed

+497
-245
lines changed

9 files changed

+497
-245
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# pySNSAPI
1+
# python-SNS-API
22

33
A Python client for the Stormshield Network Security appliance SSL API.
44

@@ -103,7 +103,11 @@ Concerning the SSL validation:
103103
* For the first connection to a new appliance, ssl host name verification can be bypassed with `--no-sslverifyhost` option.
104104
* To connect to a known appliance with the default certificate use `--host <serial> --ip <ip address>` to validate the peer certificate.
105105
* If a custom CA and certificate is installed, use `--host myfirewall.tld --cabundle <ca.pem>`.
106-
* For client certificate authentication, the expected format is a pem file with the certificate and the unencrypted key concatenated.
106+
* For client certificate authentication, the expected format is a PEM file with the certificate and the unencrypted key concatenated.
107+
108+
## Proxy
109+
110+
The library and `snscli` tool support HTTP and SOCKS proxies, use `--proxy scheme://user:password@host:port` option.
107111

108112

109113
## Build
@@ -125,7 +129,7 @@ Warning: some tests require a remote SNS appliance.
125129

126130
To run `snscli` from the source folder without install:
127131

128-
`$ PYTHONPATH=. python3 ./bin/snscli --help`
132+
`$ python3 stormshield/sns/cli.py --help`
129133

130134

131135
## Links

bin/snscli

Lines changed: 0 additions & 219 deletions
This file was deleted.

examples/addvlan.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Script to create a VLAN interface on a SNS appliance
5+
"""
6+
7+
import sys
8+
import getpass
9+
10+
from stormshield.sns.sslclient import SSLClient
11+
12+
# user input
13+
host = input("Appliance ip address: ")
14+
user = input("User:")
15+
password = getpass.getpass("Password: ")
16+
vlanname = input("VLAN name: ")
17+
vlanphy = input("Physical interface: ")
18+
vlantag = input("VLAN tag: ")
19+
vlanaddr = input("Address: ")
20+
vlanmask = input("Mask: ")
21+
22+
#host = "10.0.0.0.254"
23+
#user = "admin"
24+
#password = "mypassword"
25+
#vlanname = "myvlan3"
26+
#vlanphy = "Ethernet0"
27+
#vlantag = 103
28+
#vlanaddr = "192.168.103.1"
29+
#vlanmask = "255.255.255.0"
30+
31+
MAXVLAN=60
32+
33+
# connect to the appliance
34+
client = SSLClient(
35+
host=host, port=443,
36+
user=user, password=password,
37+
sslverifyhost=False)
38+
39+
def error(msg):
40+
global client
41+
42+
print("ERROR: {}".format(msg))
43+
client.disconnect()
44+
sys.exit(1)
45+
46+
def command(cmd):
47+
global client
48+
49+
response = client.send_command(cmd)
50+
if not response:
51+
error("command failed:\n{}".format(response.output))
52+
53+
return response
54+
55+
56+
# get vlan list & extract first available vlanX interface
57+
response = command("config network interface show filter=vlan")
58+
if len(response.data.keys()) == 0:
59+
vlanid = 0
60+
else:
61+
vlanid = -1
62+
for i in range(MAXVLAN):
63+
if "vlan{}".format(i) not in response.data:
64+
vlanid = i
65+
break
66+
if vlanid == -1:
67+
error("all available VLAN already created")
68+
69+
70+
response = command("CONFIG NETWORK INTERFACE CREATE state=1 protected=0 mtu=1500 physical={} name={} tag={} priority=0 keepVlanPriority=1 maxThroughput=0 ifname=vlan{} address={} mask={}".format(vlanphy, vlanname, vlantag, vlanid, vlanaddr, vlanmask))
71+
if response.code:
72+
print("VLAN vlan{} created".format(vlanid))
73+
else:
74+
error("VLAN vlan{} can't be created:\n{}".format(vlanid, response.output))
75+
76+
response = command("CONFIG NETWORK ACTIVATE")
77+
if response.code:
78+
print("Configuration activated")
79+
else:
80+
error("Can't activate network:\n{}".format(response.output))
81+
82+
client.disconnect()

setup.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#!/usr/bin/python
22

33
import setuptools
4+
import os
45

5-
import stormshield.sns
6-
6+
version = {}
7+
with open(os.path.join('stormshield', 'sns', 'sslclient', '__version__.py'), 'r') as fh:
8+
exec(fh.read(), version)
79

810
with open("README.md", "r") as fh:
911
long_description = fh.read()
1012

1113
setuptools.setup(
1214
name="stormshield.sns.sslclient",
13-
version=stormshield.sns.__version__,
15+
version=version['__version__'],
1416
author="Remi Pauchet",
1517
author_email="remi.pauchet@stormshield.eu",
1618
description="SSL API client for Stormshield Network Security appliances",
@@ -19,11 +21,12 @@
1921
url="https://github.com/stormshield/python-SNS-API",
2022
license='Apache License 2.0',
2123
packages=setuptools.find_packages(),
22-
scripts=['bin/snscli'],
24+
entry_points={
25+
'console_scripts': ['snscli=stormshield.sns.cli:main'],
26+
},
2327
install_requires=[
2428
'pygments',
25-
'begins',
26-
'requests',
29+
'requests[socks]',
2730
'requests_toolbelt',
2831
'colorlog',
2932
'defusedxml',
@@ -38,7 +41,7 @@
3841
"Programming Language :: Python :: 3",
3942
"License :: Apache License 2.0",
4043
"Operating System :: OS Independent",
41-
'Topic :: System :: Networking'
42-
'Environment :: Console'
44+
"Topic :: System :: Networking",
45+
"Environment :: Console"
4346
],
4447
)

stormshield/sns/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
__version__ = "1.0.0.beta1"
2-
3-
# major.minor.patch
4-
# major: breaking API change
5-
# minor: new functionality
6-
# patch: bugfix

0 commit comments

Comments
 (0)