#!/usr/local/bin/perl -w use Text::Template qw(fill_in_string); use User::pwent; our ($vhost, $owner, $email, $pw, $logdir); print "Name of virtual host:"; chomp($vhost = ); print "Who owns this virtual host:"; chomp($owner = ); print "What is the administrator's address:"; chomp($email = ); $logdir = '/disk2/logs'; $pw = getpwnam($owner) || die "No such user $owner"; $file = '/usr/local/etc/apache/httpd.conf'; open FILE, $file or die "Cannot open $file"; { local $/; $conf = ; } close FILE; # Find the comment lines that begin with 'VirtualHostTemplate' ($template) = $conf =~ /^#VirtualHostTemplate\n(.*?)^$/ms; # Strip off the hashes $template =~ s/^#//mg; # Expand the template $new_section = fill_in_string($template); # Put the new section in the file $conf =~ s/(?=^\#VirtualHostTemplate)/$new_section\n/m; rename $file, "$file.bak" || die "Cannot move $file"; open OUTFILE, ">$file" || die "Cannot open new file"; print OUTFILE $conf; close OUTFILE; print "Don't forget to restart apache\n";