My situation is this:
I have cable internet service provided through rcn. Recently they started frowning upon my staticly set ip number, and kept disconnecting my service for doing so. Hence, I decided to do as they wished and use a dynamic ip. The problem then arose that my apache vhost configuration file, and several cgi configuration files needed to be updated every time my ip changed so that they would work. Thus I wrote this script to update my /etc/httpd/conf/virtualhosts.conf file. I also made this script write the file /usr/share/global.ip so that if I had any other scripts that needed my ip i could just put in require "/usr/share/global.ip"; and the put $ipnum everywhere I needed my ip. This all worked.
The problem is this: Some of the configuration files aren't executable so I can't use the global.ip file with them, and also I can't/don't want to imbed long files into the script as I did with the vhost configuration file. Does anyone have any suggestions/comments on how I could improve my system, and more importantly get these text configuration files updated. The following is the code for my script:
#!/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",
"<VirtualHost $ipnum>\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",
"</VirtualHost>\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 ins
+ist on opening a non-existant configuration file $!\n";
print GIP "\$ipnum = $ipnum;\n1;";
close (GIP);
}
~heise2k~