Added get_file_path(vhost) to configurator, added check for mod_ssl in client

This commit is contained in:
James Kasten 2012-08-12 17:45:09 -04:00
parent 46799a963a
commit 6db2e9d6b3
2 changed files with 31 additions and 5 deletions

View file

@ -184,7 +184,6 @@ def save_key_csr(key, csr):
in the ssl and certs directories respectively
This function sets the appropriate permissions for the key and its
directory.
TODO: This file needs to be tested
"""
# Create directories if they do not exist
if not os.path.isdir(SERVER_ROOT + "certs"):
@ -240,6 +239,14 @@ def authenticate():
if curses:
shower = progress_shower()
# Check first if mod_ssl is loaded
if not config.check_ssl_loaded():
if curses:
shower.add("Loading mod_ssl into Apache Server")
else:
print "Loading mod_ssl into Apache Server"
config.enable_mod_ssl()
req_file = csr
key_file = privkey
if csr and privkey:
@ -248,7 +255,6 @@ def authenticate():
if not csr or not privkey:
# Generate new private key and corresponding csr!
key_pem, csr_pem = make_key_and_csr(names, 2048)
# TODO: IMPORTANT: NEED TO TEST
key_file, req_file = save_key_csr(key_pem, csr_pem)
if curses:
shower.add("Generating key: " + key_file + "\n")
@ -303,6 +309,7 @@ def authenticate():
if not curses: print sni_todo
# Find virtual hosts to deploy certificates too
vhost = set()
for name in dn:
host = config.choose_virtual_host(name)

View file

@ -5,7 +5,10 @@ import os
import sys
import socket
from trustify.client.CONFIG import SERVER_ROOT
#from trustify.client.CONFIG import SERVER_ROOT
SERVER_ROOT = "/etc/apache2/"
#TODO - Stop Augeas from loading up backup emacs files in sites-available
class VH(object):
def __init__(self, vh_path, vh_addrs):
@ -78,7 +81,7 @@ class Configurator(object):
return self.save("Virtual Server - deploying certificate")
def choose_virtual_host(self, name):
def choose_virtual_host(self, name, ssl=True):
"""
Chooses a virtual host based on the given domain name
@ -468,7 +471,22 @@ class Configurator(object):
if found == len(ssl_vhost.addrs):
return vh
return None
def get_file_path(self, vhost):
# Strip off /files
avail_fp = vhost.path[6:]
# This can be optimized...
while True:
find_if = avail_fp.find("/IfModule")
if find_if != -1:
avail_fp = avail_fp[:find_if]
continue
find_vh = avail_fp.find("/VirtualHost")
if find_vh != -1:
avail_fp = avail_fp[:find_vh]
continue
break
return avail_fp
def is_site_enabled(self, avail_fp):
"""
@ -580,6 +598,7 @@ class Configurator(object):
def main():
config = Configurator()
for v in config.vhosts:
print config.get_file_path(v)
print v.addrs
for name in v.names:
print name