Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 Jul 2002 10:34:00 -0400 (EDT)
From:      "Gary D. Margiotta" <gary@tbe.net>
To:        Mark Johnston <mjohnston@skyweb.ca>
Cc:        'Odhiambo Washington' <wash@wananchi.com>, freebsd-isp@freebsd.org
Subject:   Re: Scripts to Manage Virtual Hosts
Message-ID:  <Pine.BSF.4.21.0207121029090.45401-300000@thud.tbe.net>
In-Reply-To: <001b01c229af$0a181040$3e0fa8c0@skycable.int>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
I started writing some perl scripts which I use to add virtualhosts and
redirects to separate config files.  I didn't like the idea of editing the
httpd.conf directly, so I made use of the ResourceConfig directive, and
created 2 files called virtualhosts.conf and redirects.conf which apache
pulls in when started.

The scripts are currently only able to add entries, and not remove them,
but should be able to be easily enough modified to include that, I just
haven't had the time to finish them up.  I want to eventually hook up the
scripts to keep the info in a database for much easier organization and
manipulation of domains, but again, lack of time.

You'll notice that it also makes a call to a shell script that gets run to
ifconfig the virtual IPs on the host interface.  I also run that before I
restart apache to make sure the new IP takes effect.

-Gary

Running Windows is kinda like playing blackjack:
User stays on success, reboots on failure


> -----Original Message-----
> From: owner-freebsd-isp@FreeBSD.ORG
> [mailto:owner-freebsd-isp@FreeBSD.ORG] On Behalf Of Odhiambo Washington
> Sent: Friday, July 12, 2002 8:51 AM
> To: FBSD-ISP
> Subject: Scripts to Manage Virtual Hosts
> 
> 
> [ I sent this to -questions but got no help ;) ]
> 
> 
> Hello Users,
> 
> I believe someone already had written a script that can be used to
> manipulate
> httpd.conf to add/remove virtual host entries.
> I sincerely believe that this is somewhere so I don't have to start
> agonizing
> about re-inventing the wheel.
> Could someone kindly point me to where one is located, better even share
> with me
> what they have ;-)
> 
> 
> -Wash
> 
> -- 
> Odhiambo Washington  <wash@wananchi.com>    "The box said 'Requires
> Wananchi Online Ltd.  www.wananchi.com      Windows 95, NT, or better,'
> Tel: 254 2 313985-9   Fax: 254 2 313922     so I installed FreeBSD."   
> GSM: 254 72 743 223   GSM: 254 733 744 121  This sig is McQ!  :-)
> 
> 
> The light at the end of the tunnel is the headlight of an approaching
> train.
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-isp" in the body of the message
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-isp" in the body of the message
> 

[-- Attachment #2 --]
#!/usr/local/bin/perl

use strict;
use warnings;
use CGI qw(:standard);

my $domain;
my $domain_ip;
my $servername;
my $serveradmin;
my $documentroot;
my $domaintype="virtualhost";

$domain=param("domain");
unless ($domain){
  print "Please enter the domain name you want to add:\n";
  $domain=<STDIN>;
  chomp $domain;
}

$domain_ip=param("ip");
unless ($domain_ip){
  print "Please enter the IP for this domain:\n";
  $domain_ip=<STDIN>;
  chomp $domain_ip;
}

$serveradmin=param("admin");
unless ($serveradmin){
  print "Please enter the e-mail address of the admin for this domain:\n";
  $serveradmin=<STDIN>;
  chomp $serveradmin;
}

$servername="www.$domain";
$documentroot="/web/$servername";

open (VHOST, ">>/usr/local/apache/conf/extras/virtualhosts.conf") or die "Couldn't open file: $!";

print VHOST <<"entry";

### $domain ###

<VirtualHost $domain_ip:80>
  ServerAdmin $serveradmin
  DocumentRoot $documentroot
  ServerName $servername
  ErrorLog /web/log/$servername-error.log
  CustomLog /web/log/$servername-access.log common
</VirtualHost>

entry

close (VHOST) or die "Couldn't close file: $!";

mkdir $documentroot;

open (NETCONFIG, ">>/usr/local/bin/netconfig.sh") or die "Couldn't open file: $!";

print NETCONFIG <<"addresses";

ifconfig fxp0 $domain_ip alias netmask 255.255.255.255
echo -n ' $servername'

addresses

close (NETCONFIG) or die "Couldn't close file: $!";

open (DOMAINLIST, ">>/usr/local/apache/htdocs/admin/domain_list") or die "Couldn't open file: 
$!";

print DOMAINLIST "$domain_ip,$servername,$domaintype\n";

close (DOMAINLIST) or die "Couldn't close file: $!";


print header();
print "$servername entered with an IP of $domain_ip\n";

[-- Attachment #3 --]
#!/usr/local/bin/perl

use strict;
use warnings;
use CGI qw(:standard);

my $domain_ip;
my $new_path;
my $servername;
my $domaintype="redirector";

$domain_ip=param("domain_ip");
unless ($domain_ip){
  print "Please enter the IP for the redirector:\n";
  $domain_ip=<STDIN>;
  chomp $domain_ip;
}

$servername=param("servername");
unless ($servername){
  print "Please enter the servername to redirect:\n";
  $servername=<STDIN>;
  chomp $servername;
}

$new_path=param("new_path");
unless ($new_path){
  print "Please enter the destination path:\n";
  $new_path=<STDIN>;
  chomp $new_path;
}

open (REDIRECT, ">>/usr/local/apache/conf/extras/redirects.conf") or die "Couldn't open file: $!";

print REDIRECT <<"stuff";

<VirtualHost $domain_ip:80>
    ServerName $servername
    ReDirect / http://$new_path
</VirtualHost>

stuff

close (REDIRECT) or die "Couldn't close file: $!";

open (NETCONFIG, ">>/usr/local/bin/netconfig.sh") or die "Couldn't open file: $!";

print NETCONFIG <<"addresses";

ifconfig fxp0 $domain_ip alias netmask 255.255.255.255
echo -n ' $servername'
  
addresses
  
close (NETCONFIG) or die "Couldn't close file: $!";

open (DOMAINLIST, ">>/usr/local/apache/htdocs/admin/domain_list") or die "Couldn't open file: 
$!";

print DOMAINLIST "$domain_ip,$servername,$domaintype\n";

close (DOMAINLIST) or die "Couldn't close file: $!";

print header();
print "$servername was redirected to $new_path";
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0207121029090.45401-300000>