Skip to content

Commit

Permalink
Allow load config from file
Browse files Browse the repository at this point in the history
  • Loading branch information
sorz committed Jan 11, 2017
1 parent 628fa23 commit 1c368a3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
url='https://github.com/sorz/sstp-server',
packages=['sstpd'],
ext_modules = [fcsmodule],
data_files=[('', ['README.rst'])],
entry_points="""
[console_scripts]
sstpd = sstpd:main
Expand Down
38 changes: 38 additions & 0 deletions sstp-server.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[DEAFULT]
# 1 to 50. Default 20, debug 10, verbose 5
;log_level = 20

# OpenSSL cipher suite. See ciphers(1).
;cipher = EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH

# Path to pppd
;pppd = /usr/bin/pppd

[site1]
# To start with [site1] config, execute:
# sstpd -f /path/to/config.ini -s site1
# Config here will override items on [DEFAULT],
# and cmdline args override the config file.

listen = 0.0.0.0
port = 443

# PEM-format certificate with key.
pem_cert = /path/to/cert.pem

# Address of server side on ppp.
local = 192.168.20.1

# If RADIUS is used to mangle IP pool, comment it out.
remote = 192.168.20.0/24

# pppd config file path
;pppd_config = /etc/ppp/options.sstpd

[no-ssl]
# Use plain HTTP instead of HTTPS. Useful when running behind proxy.
no_ssl = yes

listen = 127.0.0.1
port = 4433

29 changes: 26 additions & 3 deletions sstpd/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import logging
import argparse
from ConfigParser import SafeConfigParser, NoSectionError
from twisted.internet.endpoints import SSL4ServerEndpoint
from twisted.internet import reactor, ssl

Expand All @@ -10,9 +11,31 @@


def _getArgs():
parser = argparse.ArgumentParser(description='A Secure Socket Tunneling '
'Protocol (SSTP) server.',
epilog='Author: Sorz <[email protected]>.')
conf_parser = argparse.ArgumentParser(
description='A Secure Socket Tunneling Protocol (SSTP) server.',
epilog='Author: Sorz <[email protected]>.',
add_help=False)
conf_parser.add_argument("-f", "--conf-file",
help="Specify config file.", metavar="FILE")
conf_parser.add_argument("-s", "--conf-section",
help="Specify section name on config file.",
metavar="SITE", default="DEFAULT")

args, remaining_argv = conf_parser.parse_known_args()
defaults = {}
if args.conf_file:
config = SafeConfigParser()
config.read(args.conf_file)
try:
defaults = dict(config.items(args.conf_section))
except NoSectionError as e:
print('Error: section [%s] not found in config file.' % \
args.conf_section)
sys.exit(1)
return

parser = argparse.ArgumentParser(parents=[conf_parser])
parser.set_defaults(**defaults)
parser.add_argument('-l', '--listen',
default='',
metavar='ADDRESS',
Expand Down

0 comments on commit 1c368a3

Please sign in to comment.