Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
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
  • Loading branch information
remip2 committed Jun 20, 2019
1 parent 93ecedd commit 2c9face
Show file tree
Hide file tree
Showing 9 changed files with 497 additions and 245 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pySNSAPI
# python-SNS-API

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

Expand Down Expand Up @@ -103,7 +103,11 @@ Concerning the SSL validation:
* For the first connection to a new appliance, ssl host name verification can be bypassed with `--no-sslverifyhost` option.
* To connect to a known appliance with the default certificate use `--host <serial> --ip <ip address>` to validate the peer certificate.
* If a custom CA and certificate is installed, use `--host myfirewall.tld --cabundle <ca.pem>`.
* For client certificate authentication, the expected format is a pem file with the certificate and the unencrypted key concatenated.
* For client certificate authentication, the expected format is a PEM file with the certificate and the unencrypted key concatenated.

## Proxy

The library and `snscli` tool support HTTP and SOCKS proxies, use `--proxy scheme://user:password@host:port` option.


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

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

`$ PYTHONPATH=. python3 ./bin/snscli --help`
`$ python3 stormshield/sns/cli.py --help`


## Links
Expand Down
219 changes: 0 additions & 219 deletions bin/snscli

This file was deleted.

82 changes: 82 additions & 0 deletions examples/addvlan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python3

"""
Script to create a VLAN interface on a SNS appliance
"""

import sys
import getpass

from stormshield.sns.sslclient import SSLClient

# user input
host = input("Appliance ip address: ")
user = input("User:")
password = getpass.getpass("Password: ")
vlanname = input("VLAN name: ")
vlanphy = input("Physical interface: ")
vlantag = input("VLAN tag: ")
vlanaddr = input("Address: ")
vlanmask = input("Mask: ")

#host = "10.0.0.0.254"
#user = "admin"
#password = "mypassword"
#vlanname = "myvlan3"
#vlanphy = "Ethernet0"
#vlantag = 103
#vlanaddr = "192.168.103.1"
#vlanmask = "255.255.255.0"

MAXVLAN=60

# connect to the appliance
client = SSLClient(
host=host, port=443,
user=user, password=password,
sslverifyhost=False)

def error(msg):
global client

print("ERROR: {}".format(msg))
client.disconnect()
sys.exit(1)

def command(cmd):
global client

response = client.send_command(cmd)
if not response:
error("command failed:\n{}".format(response.output))

return response


# get vlan list & extract first available vlanX interface
response = command("config network interface show filter=vlan")
if len(response.data.keys()) == 0:
vlanid = 0
else:
vlanid = -1
for i in range(MAXVLAN):
if "vlan{}".format(i) not in response.data:
vlanid = i
break
if vlanid == -1:
error("all available VLAN already created")


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))
if response.code:
print("VLAN vlan{} created".format(vlanid))
else:
error("VLAN vlan{} can't be created:\n{}".format(vlanid, response.output))

response = command("CONFIG NETWORK ACTIVATE")
if response.code:
print("Configuration activated")
else:
error("Can't activate network:\n{}".format(response.output))

client.disconnect()
19 changes: 11 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/usr/bin/python

import setuptools
import os

import stormshield.sns

version = {}
with open(os.path.join('stormshield', 'sns', 'sslclient', '__version__.py'), 'r') as fh:
exec(fh.read(), version)

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

setuptools.setup(
name="stormshield.sns.sslclient",
version=stormshield.sns.__version__,
version=version['__version__'],
author="Remi Pauchet",
author_email="remi.pauchet@stormshield.eu",
description="SSL API client for Stormshield Network Security appliances",
Expand All @@ -19,11 +21,12 @@
url="https://github.com/stormshield/python-SNS-API",
license='Apache License 2.0',
packages=setuptools.find_packages(),
scripts=['bin/snscli'],
entry_points={
'console_scripts': ['snscli=stormshield.sns.cli:main'],
},
install_requires=[
'pygments',
'begins',
'requests',
'requests[socks]',
'requests_toolbelt',
'colorlog',
'defusedxml',
Expand All @@ -38,7 +41,7 @@
"Programming Language :: Python :: 3",
"License :: Apache License 2.0",
"Operating System :: OS Independent",
'Topic :: System :: Networking'
'Environment :: Console'
"Topic :: System :: Networking",
"Environment :: Console"
],
)
6 changes: 0 additions & 6 deletions stormshield/sns/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
__version__ = "1.0.0.beta1"

# major.minor.patch
# major: breaking API change
# minor: new functionality
# patch: bugfix
Loading

0 comments on commit 2c9face

Please sign in to comment.