Howell
Storage? I am Storage!
I think I have a syntax error.
Mercutio said:I know perl.
I also know that debugging someone else's perl program is next to "sliding down a razor blade into a bucket of iodine" on my list of favorite things to do.
What's wrong?
dyndns,cliptin,dyndns.org,off,on,userid,password,on
dyndns-custom,home,whstrain.us,off,on,userid,password,on
#!/usr/bin/perl
#
# SmoothWall CGIs
#
# This code is distributed under the terms of the GPL
#
# (c) The SmoothWall Team
close(STDIN);
close(STDOUT);
close(STDERR);
require '/var/smoothwall/header.pl';
my %settings;
my %noipsettings;
my $filename = "${swroot}/ddns/config";
my $cachefile = "${swroot}/ddns/ipcache";
my $ipcache = 0;
open(FILE, "$filename") or die 'Unable to open config file.';
my @current = <FILE>;
close(FILE);
my $lines = $#current + 1;
unless($lines) { exit 0; }
open(IP, "${swroot}/red/local-ipaddress") or die 'Unable to open local-ipaddress
file.';
my $ip = <IP>;
close(IP);
chomp $ip;
if ($ARGV[0] ne '-f')
{
open(IPCACHE, "$cachefile");
$ipcache = <IPCACHE>;
close(IPCACHE);
chomp $ipcache;
}
if ($ip ne $ipcache)
{
my $id = 0;
my $success = 0;
my $line;
foreach $line (@current)
{
$id++;
chomp($line);
my @temp = split(/\,/,$line);
unless ($temp[7] eq "off")
{
$settings{'SERVICE'} = $temp[0];
$settings{'HOSTNAME'} = $temp[1];
$settings{'DOMAIN'} = $temp[2];
$settings{'PROXY'} = $temp[3];
$settings{'WILDCARDS'} = $temp[4];
$settings{'LOGIN'} = $temp[5];
$settings{'PASSWORD'} = $temp[6];
$settings{'ENABLED'} = $temp[7];
my @service = split(/\./, "$settings{'SERVICE'}");
$settings{'SERVICE'} = "$service[0]";
if ($settings{'SERVICE'} eq 'no-ip')
{
$noipsettings{'LOGIN'} = $settings{'LOGIN'};
$noipsettings{'PASSWORD'} = $settings{'PASSWORD'
};
$noipsettings{'HOSTNAME'} = $settings{'HOSTNAME'
};
$noipsettings{'DOMAIN'} = $settings{'DOMAIN'};
$noipsettings{'DAEMON'} = 'N';
$noipsettings{'DEVICE'} = '';
$noipsettings{'INTERVAL'} = '1';
$noipsettings{'NAT'} = 'N';
if ($settings{'PROXY'} eq 'on') { $noipsettings{
'PROXY'} = 'Y'; }
else { $noipsettings{'PROXY'} = 'N'; }
&writehash("${swroot}/ddns/noipsettings", \%noip
settings);
open(F, "${swroot}/ddns/noipsettings");
my @unsorted = <F>;
close(F);
my @sorted = sort { $b cmp $a } @unsorted;
open(F, ">${swroot}/ddns/noipsettings");
flock F, 2;
print F @sorted;
close(F);
my @ddnscommand = ('/usr/local/bin/noip_for_libc
6','-c',"${swroot}/ddns/noipsettings",'-i',"$ip");
my $result = system(@ddnscommand);
if ( $result != 0) { &log("Dynamic DNS ip-update
for $settings{'HOSTNAME'}.$settings{'DOMAIN'}: failure"); }
else
{
&log("Dynamic DNS ip-update for $setting
s{'HOSTNAME'}.$settings{'DOMAIN'}: success");
$success++;
}
}
else
{
if ($settings{'WILDCARDS'} eq 'on') {$settings{'
WILDCARDS'} = '-w';}
else {$settings{'WILDCARDS'} = '';}
if ($settings{'SERVICE'} eq 'dyndns-custom')
{
&log("Service=$settings{'SERVICE'}");
my @ddnscommand = ('/usr/local/bin/ez-ip
update', '-a', "$ip", '-S', "$settings{'SERVICE'}", '-u', "$settings{'LOGIN'}:$s
ettings{'PASSWORD'}", '-h', "$settings{'DOMAIN'}", "$settings{'WILDCARDS'}", '-q
');
&log("Modified command on $settings{'HOS
TNAME'}.$settings{'DOMAIN'}");
}
else
{
&log("Service=$settings{'SERVICE'}");
my @ddnscommand = ('/usr/local/bin/ez-ip
update', '-a', "$ip", '-S', "$settings{'SERVICE'}", '-u', "$settings{'LOGIN'}:$s
ettings{'PASSWORD'}", '-h', "$settings{'HOSTNAME'}.$settings{'DOMAIN'}", "$setti
ngs{'WILDCARDS'}", '-q');
&log("Standard command on $settings{'HOS
TNAME'}.$settings{'DOMAIN'}");
}
my $result = system(@ddnscommand);
if ( $result != 0) { &log("Dynamic DNS ip-update
for $settings{'HOSTNAME'}.$settings{'DOMAIN'}: failure"); }
else
{
&log("Dynamic DNS ip-update for $setting
s{'HOSTNAME'}.$settings{'DOMAIN'}: success");
$success++;
}
}
}
}
if ($lines == $success)
{
open(IPCACHE, ">$cachefile");
flock IPCACHE, 2;
print IPCACHE $ip;
close(IPCACHE);
}
}
else { &log('Dyanmic DNS ip-update: your IP is already up-to-date'); }
22:40:07 smoothwall Service=dyndns
22:40:07 smoothwall Standard command on cliptin.dyndns.org
22:40:07 smoothwall Dynamic DNS ip-update for cliptin.dyndns.org: failure
22:40:07 smoothwall Service=dyndns-custom
22:40:07 smoothwall Modified command on home.whstrain.us
22:40:07 smoothwall Dynamic DNS ip-update for home.whstrain.us: failure
ez-ipupdate -a 67.34.156.150 -S dyndns-custom -u userid:password -h whstrain.us
if ($cgiparams{'ACTION'} eq $tr{'add'})
{
unless ($cgiparams{'HOSTNAME'} =~ /^[a-zA-Z_0-9-]+$/) { $errormessage = $tr{'invalid hostname'}; }
}
Handruin said:Wouldn't $tr{'add'} be the associated value of add in the array?
That's my guess. Funny construct, "unless not".Howell said:Newtun, You think =~ means "not".
Mercutio said:Nope. =~ is used for regexp string comparison.
Regular Expression. Pattern-matching for strings.Howell said:regexp?
if ($cgiparams{'ACTION'} eq $tr{'add'})
{
unless ($cgiparams{'HOSTNAME'} =~ /^[a-zA-Z_0-9-]+$/) { $errormessage = $tr{'invalid hostname'}; }
}
if ($cgiparams{'ACTION'} eq $tr{'add'})
{
unless
(
($cgiparams{'HOSTNAME'} =~ /^[a-zA-Z_0-9-]+$/)
OR ($cgiparams{'SERVICE'} eq {'dyndns-custom'}
)
{ $errormessage = $tr{'invalid hostname'}; }
}