#!/usr/bin/env python
# $Id$
#
# Copyright (C) 2015-2016 Parsons Government Services ("PARSONS")
# Portions copyright (C) 2014 Dragon Research Labs ("DRL")
# Portions copyright (C) 2013 Internet Systems Consortium ("ISC")
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notices and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND PARSONS, DRL, AND ISC DISCLAIM
# ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# PARSONS, DRL, OR ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import os
import sys
import socket
import urllib2
import argparse
import platform
import textwrap
import subprocess
import rpki.autoconf
fqdn = socket.getfqdn()
vhost_template = """\
#
# Stuff that should be visible with both HTTP and HTTPS is (now)
# outside the vhost block (see if this works properly...).
#
#
# Allow access to the directory where rcynic-html writes
# its output files.
#
%(allow)s
#
# Add alias pointing to rcynic-html's output files.
#
# If for some reason you need to change this, be careful to leave
# the trailing slash off the URL, otherwise /rcynic will be
# swallowed by the WSGIScriptAlias
#
Alias /rcynic %(RCYNIC_HTML_DIR)s/
#
# Allow access to the directory where pubd writes RRDP files.
#
%(allow)s
#
# Add alias pointing to pubd's RRD output files.
#
Alias /rrdp %(datarootdir)s/rpki/rrdp-publication/
#
# RRDP "notification" file needs a short expiration: this is
# a critical part of how RRDP interacts with HTTP caching.
# Timeout is per current RRDP I-D, this will need to track
# any changes as the specification evolves.
#
ExpiresActive on
ExpiresDefault "access plus 1 minute"
#
# By default, this configuration assumes that you use name-based
# virtual hosting. If that's not what you want, you may need
# to change this.
#
#
# By default, we enable an HTTPS virtual host on this machine's
# fully qualified domain name. This works for simple
# configurations, but if you're running a more complex Apache
# configuration or want to run the GUI on a different hostname,
# you may need to change this.
#
ServerName %(fqdn)s
#
# Configure the WSGI application to run as a separate process from
# the Apache daemon itself.
#
%(WSGI_DAEMON_PROCESS)s
%(WSGI_PROCESS_GROUP)s
#
# Allow access to our WSGI directory.
#
%(allow)s
#
# Define the URL to the RPKI GUI
#
WSGIScriptAlias / %(datarootdir)s/rpki/wsgi/rpki.wsgi
#
# Allow access to static content (icons, etc).
#
%(allow)s
#
# Add the aliases Django expects for static content.
#
Alias /media/
<?xml version="1.0" encoding="US-ASCII"?><!--Automatically generated, do not edit.--><msgxmlns="http://www.hactrn.net/uris/rpki/left-right-spec/"version="1"><route_originaction="set"type="reply"self_id="42"route_origin_id="88"/></msg>