#!/usr/bin/perl -w # # $Id: vhost.pl,v 1.9 2003/01/13 05:28:42 jmates Exp $ # # Copyright (c) 2000-2001, Jeremy Mates. This script is free # software; you can redistribute it and/or modify it under the same # terms as Perl itself. # # Run perldoc(1) on this file for additional documentation. # ###################################################################### # # REQUIREMENTS require 5; use strict; ###################################################################### # # MODULES use Carp; use Getopt::Std; ###################################################################### # # VARIABLES my $VERSION; ($VERSION = '$Revision: 1.9 $ ') =~ s/[^0-9.]//g; my (%opts); ###################################################################### # # MAIN # parse command-line options getopts('?i:p:h:n:a:e:', \%opts); help() if exists $opts{'?'}; my $ip = $opts{'i'} || die "no -i ip option\n"; my $port = $opts{'p'} || die "no -p port option\n"; my $host = $opts{'h'} || die "no -h host option\n"; my $server_name = $opts{'n'} || die "no -n server_name option\n"; my $server_alias = $opts{'a'} || die "no -a server_alias option\n"; my $server_admin = $opts{'e'} || die "no -e server_admin option\n"; print < ServerName $server_name Port $port ServerAlias $server_alias ServerAdmin $server_admin DocumentRoot /home/httpd/$host/html Options Indexes SymLinksIfOwnerMatch +Includes AllowOverride None Order allow,deny Allow from all ScriptAlias /cgi-bin/ /home/httpd/$host/cgi-bin/ CustomLog logs/${host}_access_log combined ErrorLog logs/${host}_error_log LogLevel warn TEXTCHUNK exit; ###################################################################### # # SUBROUTINES # a generic help blarb sub help { print <<"HELP"; Usage: $0 [opts] Simple Apache VirtualHost block generator. Options: -? Display this message -i xx VirtualHost IP address -p xx VirtualHost Port option (and Port) -h xx Short hostname to use (e.g. example) -n xx Full ServerName (e.g. www.example.org) -a xx ServerAlias directive (e.g. *.example.*) -e xx ServerAdmin (e.g. webmaster\@example.org) Run perldoc(1) on this script for additional documentation. HELP exit; } __END__ ###################################################################### # # DOCUMENTATION =head1 NAME vhost.pl - simple Apache VirtualHost block generator. =head1 SYNOPSIS $ vhost.pl -n foo \ -i 192.168.25.1 \ -p 80 \ -h foo \ -a "*.foo.*" \ -e "webmaster@foo.com" =head1 DESCRIPTION vhost.pl is a quick hack aimed at generating VirutalHost definitions for Apache, using the configuration defaults that a friend likes to use. To alter the form of the VirtualHost directive generated, alter the template insde the MAIN section of the script. Another means of generating VirtualHost definitions on the fly is to use mod_perl statements inside the httpd.conf to create VirtualHost blocks dynamically from an external source. Others have suggested using templates to create per-VirtualHost configuration files that httpd.conf includes in; dynamic data is fed into the configuration files via cron scripts or a Makefile, which avoids having to use mod_perl. =head1 USAGE Quite simple, run vhost.pl with a whole bunch of command line options that are all required. The options are explained below. =head1 OPTIONS vhost.pl supports the following options: -i xx VirtualHost IP address -p xx VirtualHost Port option (and Port) -h xx Short hostname to use (e.g. example) -n xx Full ServerName (e.g. www.example.org) -a xx ServerAlias directive (e.g. *.example.*) -e xx ServerAdmin (e.g. webmaster@example.org) =head1 BUGS =head2 Reporting Bugs Newer versions of this script may be available from: http://sial.org/code/perl/ If the bug is in the latest version, send a report to the author. Patches that fix problems or add new features are welcome. =head2 Known Issues No known bugs. =head1 SEE ALSO perl(1) =head1 AUTHOR Jeremy Mates, http://sial.org/contact/ =head1 COPYRIGHT Copyright (c) 2000-2001, Jeremy Mates. This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut