Permalink
Browse files

Added script entrypoints for certificate generation and starting sirious

  • Loading branch information...
1 parent 1457e42 commit e9942cfd642826d2835f9e78de939b8eaf67ed7f @wrboyce committed Nov 28, 2011
Showing with 79 additions and 56 deletions.
  1. +1 −0 MANIFEST.in
  2. +0 −52 main.py
  3. +9 −1 setup.py
  4. +66 −0 sirious/scripts.py
  5. +3 −3 { → sirious/scripts}/gen_certs.zsh
View
@@ -0,0 +1 @@
+include sirious/scripts/gen_certs.zsh
View
52 main.py
@@ -1,52 +0,0 @@
-import ConfigParser
-import logging
-import os
-
-from twisted.internet import reactor, ssl
-
-from sirious import SiriProxyFactory
-
-
-## Find & Parse the config files
-## Cfg files are parsed in the order /etc/sirious/sirious.cfg, ~/.sirious/sirious.cfg, ${VIRTUAL_ENV}/.sirious/sirious.cfg
-config = ConfigParser.RawConfigParser()
-cfg_dirs = [os.path.expanduser('~/.sirious/'), '/etc/sirious']
-if os.getenv('VIRTUAL_ENV'):
- cfg_dirs.insert(0, os.path.expandvars('${VIRTUAL_ENV}/.sirious/'))
-for dir in cfg_dirs[::-1]:
- config.read('sirious.cfg')
-## Grab core settings
-try:
- core_settings = config.items('core')
-except ConfigParser.NoSectionError:
- core_settings = {}
-settings = {}
-settings['root'] = root = cfg_dirs[0] # ${VIRTUAL_ENV}/.sirious or ~/.sirious
-## Configure logging
-try:
- loglevel_name = core_settings['loglevel']
- loglevel = getattr(logging, loglevel_name.upper())
-except (KeyError, AttributeError):
- loglevel = logging.INFO
-finally:
- logging.basicConfig(
- format="%(asctime)s %(levelname)s [%(name)s] %(message)s",
- level=loglevel)
-## Configure plugins
-plugins = []
-for plugin, cls in config.items('plugins'):
- try:
- kwargs = dict(config.items(cls))
- except ConfigParser.NoSectionError:
- kwargs = {}
- plugins.append((plugin, cls, kwargs))
-settings['plugins'] = plugins
-## Start the Proxy
-logging.getLogger('sirious').info('Starting up...')
-reactor.listenSSL(443, SiriProxyFactory(**settings),
- ssl.DefaultOpenSSLContextFactory(
- os.path.join(root, 'ssl', 'server.key'),
- os.path.join(root, 'ssl', 'server.crt')
- )
-)
-reactor.run()
View
@@ -10,4 +10,12 @@
license="BSD",
url='https://github.com/wrboyce/sirious',
install_requires=['biplist', 'pydispatcher', 'twisted'],
- packages=['sirious', 'sirious.plugins'])
+ packages=['sirious', 'sirious.plugins'],
+ package_data={
+ 'sirious': ['scripts/gen_certs.zsh'],
+ },
+ entry_points={
+ 'console_scripts': [
+ 'sirious = sirious.scripts:start_proxy',
+ 'sirious-gencerts = sirious.scripts:gen_certs']
+ })
View
@@ -0,0 +1,66 @@
+import ConfigParser
+import logging
+import os
+from pkg_resources import resource_filename
+
+from twisted.internet import reactor, ssl
+
+from sirious import SiriProxyFactory
+
+
+def get_paths():
+ cfg_dirs = [os.path.expanduser('~/.sirious/'), '/etc/sirious']
+ if os.getenv('VIRTUAL_ENV'):
+ cfg_dirs.insert(0, os.path.expandvars('${VIRTUAL_ENV}/.sirious/'))
+ return cfg_dirs
+
+def gen_certs():
+ path = get_paths()[0]
+ os.system('mkdir -p %s/ssl' % path)
+ os.chdir(path)
+ filename = resource_filename(__name__, "scripts/gen_certs.zsh")
+ print "You will shortly be asked four questions. The correct answers are 1234, 1234, y, y."
+ os.system(filename)
+
+def start_proxy():
+ ## Find & Parse the config files
+ config = ConfigParser.RawConfigParser()
+ cfg_dirs = get_paths()
+ for dir in cfg_dirs[::-1]: # Cfg files are parsed in the order /etc/sirious/sirious.cfg, ~/.sirious/sirious.cfg, ${VIRTUAL_ENV}/.sirious/sirious.cfg
+ config.read('sirious.cfg')
+ ## Grab core settings
+ try:
+ core_settings = config.items('core')
+ except ConfigParser.NoSectionError:
+ core_settings = {}
+ settings = {}
+ settings['root'] = root = cfg_dirs[0] # ${VIRTUAL_ENV}/.sirious or ~/.sirious
+ ## Configure logging
+ try:
+ loglevel_name = core_settings['loglevel']
+ loglevel = getattr(logging, loglevel_name.upper())
+ except (KeyError, AttributeError):
+ loglevel = logging.INFO
+ finally:
+ logging.basicConfig(
+ format="%(asctime)s %(levelname)s [%(name)s] %(message)s",
+ level=loglevel)
+ ## Configure plugins
+ plugins = []
+ for plugin, cls in config.items('plugins'):
+ logging.getLogger('sirious').info('Registering plugin %s.%s...' % (plugin, cls))
+ try:
+ kwargs = dict(config.items(cls))
+ except ConfigParser.NoSectionError:
+ kwargs = {}
+ plugins.append((plugin, cls, kwargs))
+ settings['plugins'] = plugins
+ ## Start the Proxy
+ logging.getLogger('sirious').info('Starting up...')
+ reactor.listenSSL(443, SiriProxyFactory(**settings),
+ ssl.DefaultOpenSSLContextFactory(
+ os.path.join(root, 'ssl', 'server.key'),
+ os.path.join(root, 'ssl', 'server.crt')
+ )
+ )
+ reactor.run()
@@ -12,7 +12,7 @@ emailAddress=""
## Do not edit below here!
-mkdir keys
+mkdir -p ssl
mkdir -p demoCA/{certs,crl,newcerts,private}
touch demoCA/index.txt
echo 01 > demoCA/crtnumber
@@ -27,6 +27,6 @@ openssl ca -policy policy_anything -out newcert.pem -infiles newreq.pem
openssl rsa -in newkey.pem -out server.key -passin pass:1234
mv newcert.pem server.crt
-mv demoCA/cacert.pem keys/ca.pem
-mv server.{crt,key} keys/
+mv demoCA/cacert.pem ssl/ca.pem
+mv server.{crt,key} ssl/
rm -rf new{key,req}.pem demoCA

0 comments on commit e9942cf

Please sign in to comment.