[mod_python] creating httpd.conf on the file with python

Matthew Nuzum mattnuzum at gmail.com
Wed Jun 29 20:44:05 EDT 2005


I'd like to add some brain power to my apache httpd.conf file. You can
do this with mod_perl (see attached below), but since python is better
than perl, I'd prefer to do it in python. Is this possible?

I've searched and looked through the archives, but I'm not having
luck. I likely don't know what terms to search for. An example or link
to some documentation would be greatly appreciated.

I'm using apache 1.3, libapach-mod-python2.3 version 2.7

I tried the obvious and added <Python></Python> and received an
Invalid Command error message.

Here is a snippet from mod_perl (old cobalt Raq server, I think):

<Perl>
use Apache::PerlSections();
use lib qw(/usr/sausalito/perl);
use CCE;
use Base::Httpd qw(httpd_get_vhost_conf_file);

my $cce = new CCE;
$cce->connectuds();

my @ssl_sites = $cce->find('Vsite', { 'SSL.enabled' => 1 }, {
'SSL.expires' => '^.+' });

# Only a temp variable until we go the whole hog.
my (@ssl_conf, $ip, $rewrite_rules, $proto, $ret);

# O.K. What we bassically want to do is build up new section in the conf file
# for SSL sections.
for my $oid (@ssl_sites)
{
my ($ok, $vsite) = $cce->get($oid);
my $conf_file = httpd_get_vhost_conf_file($vsite->{name});

open HTTPD_CONF, "<$conf_file" or die "Can't open $conf_file: $!\n";

# reset
@ssl_conf = ();

while(<HTTPD_CONF>)
{
if ( /^<VirtualHost ([\d\.]+)>/o )
{
$ip = $1;
# skip everything before the VirtualHost entry since it doesn't need
to be duplicated
last;
}
}

# read the rest
while(<HTTPD_CONF>)
{
# These two are for the rewrite options
s/http/https/go if (/^Rewrite/);
s/80/443/go if (/^Rewrite/);
s#https://$vsite->{fqdn}/#https://$vsite->{fqdn}:443/# if (/^RewriteRule/);
push @ssl_conf, $_;

# Hardcoded, issues with mod_perl and cobalt modules.
if (/^<\/Virtual/ && (-f "$vsite->{basedir}/certs/certificate") && (-f
"$vsite->{basedir}/certs/key"))
{
$PerlConfig .= "Listen $ip:443\n";
$PerlConfig .= "<VirtualHost $ip:443>\n";
$PerlConfig .= "SSLengine on\n";
if (-f "$vsite->{basedir}/certs/ca-certs")
{
$PerlConfig .= "SSLCACertificateFile $vsite->{basedir}/certs/ca-certs\n";
}
$PerlConfig .= "SSLCertificateFile $vsite->{basedir}/certs/certificate\n";
$PerlConfig .= "SSLCertificateKeyFile $vsite->{basedir}/certs/key\n";
$PerlConfig .= join('', @ssl_conf);
}
}
close HTTPD_CONF;
}

$cce->bye('SUCCESS');

if (-f '/etc/DEBUG')
{
print STDERR Apache::PerlSections->dump();
}
</Perl>
-- 
Matthew Nuzum
www.bearfruit.org



More information about the Mod_python mailing list