#!/usr/bin/perl -w use strict; # a good idea; it brings into existence three strictures my $rawbuf; my $ipbuf; $rawbuf=`/sbin/ifconfig eth0`; if( $rawbuf =~ /(\d+\.\d+\.\d+\.\d+)/ ) { $ipbuf= $1; } else { print "You have no ip address you dazzle-duck! \n"; } vhost($ipbuf); globalip($ipbuf); #-----------------------Behold the function arena---------------------# #This function is the template for the apache vhost configuration file; listen to it sing sub vhost{ my $vfile = "/etc/httpd/conf/virtualhosts.conf"; open (VHOST, "> $vfile") or die "The virtual hosts configuration file is virtual all right! $!\n"; my $ipnum = "$_[0]"; my @bigbuf = ( "NameVirtualHost $ipnum\n\n", "\n", "User hg\n","Group hg\n", "DocumentRoot /www/hg\n", "ServerName 0tis.org\n", "ServerAlias www.0tis.org\n", "ScriptAlias /cgi-bin /www/hg/cgi-bin\n", "\n" ); while (@bigbuf){ my $printbuf = shift ( @bigbuf ); print VHOST $printbuf; } } #code for global ip template sub globalip{ my $ipnum = "$_[0]"; my $globalip = "/usr/share/global.ip"; open (GIP,"> $globalip") or die "You silly silly man, why must you insist on opening a non-existant configuration file $!\n"; print GIP "\$ipnum = $ipnum;\n1;"; close (GIP); }