#!/usr/bin/perl # # SmoothWall CGIs # # This code is distributed under the terms of the GPL # # (c) The SmoothWall Team # # $Id: ddns.cgi,v 1.7.2.15 2004/10/03 21:33:12 alanh Exp $ # require '/var/efw/header.pl'; require '/home/httpd/cgi-bin/endianinc.pl'; my @errormessages = (); my (%cgiparams,%selected,%checked); my $filename = "${swroot}/ddns/config"; &showhttpheaders(); $cgiparams{'ENABLED'} = 'off'; $cgiparams{'PROXY'} = 'off'; $cgiparams{'WILDCARDS'} = 'off'; &getcgihash(\%cgiparams); my @service = (); open(FILE, "$filename") or die 'Unable to open config file.'; my @current = ; close(FILE); if ($cgiparams{'ACTION'} eq 'add') { toggle_file("${swroot}/ddns/behindnat","$cgiparams{'BEHINDNAT'}"); unless ($cgiparams{'SERVICE'} =~ /^(DynAccess|dhs\.org|dyndns\.org|dyndns-custom|dyndns-static|dyns\.cx|easydns\.com|freedns-afraid\.org|hn\.org|no-ip\.com|nsupdate|ovh\.com|regfish\.com|selfhost\.de|tzo\.com|zoneedit\.com)$/) { push(@errormessages, _('Invalid input')); } unless ($cgiparams{'LOGIN'} ne '') { push(@errormessages, _('Username not set.')); } # for free-dns.afraid.org, only 'connect string' is mandatory if ($cgiparams{'SERVICE'} ne 'freedns-afraid.org') { unless ($cgiparams{'SERVICE'} eq 'regfish.com' || $cgiparams{'PASSWORD'} ne '') { push(@errormessages, _('Password not set.')); } # Permit an empty HOSTNAME for the nsupdate, regfish, dyndns, ovh, zoneedit unless ($cgiparams{'SERVICE'} eq 'zoneedit.com' || $cgiparams{'SERVICE'} eq 'nsupdate' || $cgiparams{'SERVICE'} eq 'dyndns-custom'|| $cgiparams{'SERVICE'} eq 'regfish.com' || $cgiparams{'SERVICE'} eq 'ovh.com' || $cgiparams{'HOSTNAME'} ne '') { push(@errormessages, _('Hostname not set.')); } unless ($cgiparams{'HOSTNAME'} eq '' || $cgiparams{'HOSTNAME'} =~ /^[a-zA-Z_0-9-]+$/) { push(@errormessages, _('Invalid hostname.')); } if ($cgiparams{'DOMAIN'} eq '') { push(@errormessages, _('Domain not set.')); } else { unless ($cgiparams{'DOMAIN'} =~ /^[a-zA-Z_0-9.-]+$/ || $cgiparams{'DOMAIN'} =~ /[.]/) { push(@errormessages, _('Invalid domain name.')); } } } my $id = 0; foreach my $line (@current) { $id++; my @temp = split(/\,/,$line); if($cgiparams{'HOSTNAME'} eq $temp[1] && $cgiparams{'DOMAIN'} eq $temp[2] && $cgiparams{'EDITING'} ne $id) { push(@errormessages, _('Hostname and domain already in use.')); } } if (scalar(@errormessages) eq 0) { if ($cgiparams{'EDITING'} eq 'no') { open(FILE,">>$filename") or die 'Unable to open config file.'; flock FILE, 2; print FILE "$cgiparams{'SERVICE'},$cgiparams{'HOSTNAME'},$cgiparams{'DOMAIN'},$cgiparams{'PROXY'},$cgiparams{'WILDCARDS'},$cgiparams{'LOGIN'},$cgiparams{'PASSWORD'},$cgiparams{'ENABLED'}\n"; &log(_('Dynamic DNS hostname added')); } else { open(FILE,">$filename") or die 'Unable to open config file.'; flock FILE, 2; my $id = 0; foreach my $line (@current) { $id++; chomp($line); my @temp = split(/\,/,$line); if ($cgiparams{'EDITING'} eq $id) { print FILE "$cgiparams{'SERVICE'},$cgiparams{'HOSTNAME'},$cgiparams{'DOMAIN'},$cgiparams{'PROXY'},$cgiparams{'WILDCARDS'},$cgiparams{'LOGIN'},$cgiparams{'PASSWORD'},$cgiparams{'ENABLED'}\n"; } else { print FILE "$line\n"; } } } close(FILE); undef %cgiparams; } } if ($cgiparams{'ACTION'} eq 'edit' ) { my $id = 0; foreach my $line (@current) { $id++; chomp($line); my @temp = split(/\,/,$line); if ($cgiparams{'ID'} eq $id) { $cgiparams{'SERVICE'} = $temp[0]; $cgiparams{'HOSTNAME'} = $temp[1]; $cgiparams{'DOMAIN'} = $temp[2]; $cgiparams{'PROXY'} = $temp[3]; $cgiparams{'WILDCARDS'} = $temp[4]; $cgiparams{'LOGIN'} = $temp[5]; $cgiparams{'PASSWORD'} = $temp[6]; $cgiparams{'ENABLED'} = $temp[7]; } } } if ($cgiparams{'ACTION'} eq 'remove') { open(FILE, ">$filename") or die 'Unable to open config file.'; flock FILE, 2; my $id = 0; foreach my $line (@current) { $id++; unless ($cgiparams{"ID"} eq $id) { print FILE "$line"; } } close(FILE); &log(_('Dynamic DNS hostname removed')); } if ($cgiparams{'ACTION'} eq 'toggle') { open(FILE, ">$filename") or die 'Unable to open config file.'; flock FILE, 2; my $id = 0; foreach my $line (@current) { $id++; unless ($cgiparams{'ID'} eq $id) { print FILE "$line"; } else { my $pos = 7; if ($cgiparams{'KEY1'} eq 'wildcard') { $pos = 4; } elsif ($cgiparams{'KEY1'} eq 'proxy') { $pos = 3; } chomp($line); my @temp = split(/\,/,$line); if ($temp[$pos] eq "on") { $temp[$pos] = "off"; } else { $temp[$pos] = "on"; } print FILE join(',',@temp) . "\n"; } } close(FILE); } if ($cgiparams{'ACTION'} eq 'forceupdate') { system('/usr/local/bin/setddns.pl', '-f'); } if ($cgiparams{'ACTION'} eq '') { $cgiparams{'ENABLED'} = 'on'; } $selected{'SERVICE'}{'DynAccess'} = ''; $selected{'SERVICE'}{'dhs.org'} = ''; $selected{'SERVICE'}{'dyndns.org'} = ''; $selected{'SERVICE'}{'dyndns-custom'} = ''; $selected{'SERVICE'}{'dyndns-static'} = ''; $selected{'SERVICE'}{'dyns.cx'} = ''; $selected{'SERVICE'}{'easydns.com'} = ''; $selected{'SERVICE'}{'freedns-afraid.org'} = ''; $selected{'SERVICE'}{'hn.org'} = ''; $selected{'SERVICE'}{'no-ip.com'} = ''; $selected{'SERVICE'}{'nsupdate'} = ''; $selected{'SERVICE'}{'ovh.com'} = ''; $selected{'SERVICE'}{'regfish.com'} = ''; $selected{'SERVICE'}{'selfhost.de'} = ''; $selected{'SERVICE'}{'tzo.com'} = ''; $selected{'SERVICE'}{'zoneedit.com'} = ''; $selected{'SERVICE'}{$cgiparams{'SERVICE'}} = "selected='selected'"; $checked{'PROXY'}{'off'} = ''; $checked{'PROXY'}{'on'} = ''; $checked{'PROXY'}{$cgiparams{'PROXY'}} = "checked='checked'"; $checked{'WILDCARDS'}{'off'} = ''; $checked{'WILDCARDS'}{'on'} = ''; $checked{'WILDCARDS'}{$cgiparams{'WILDCARDS'}} = "checked='checked'"; $checked{'ENABLED'}{'off'} = ''; $checked{'ENABLED'}{'on'} = ''; $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'"; if( -e "${swroot}/ddns/behindnat" ) { $checked{'BEHINDNAT'}{'on'} = "checked='checked'"; } &openpage(_('Dynamic DNS'), 1, ''); &openbigbox($errormessage, $warnmessage, $notemessage); if (scalar(@errormessages) > 0) { #Stay in edit mode if we are in it if ($cgiparams{'EDITING'} ne 'no') { $cgiparams{'ACTION'} = 'edit'; $cgiparams{'ID'} = $cgiparams{'EDITING'}; } } &openbox('100%', 'left', _('Current hosts')); # if ($cgiparams{'ACTION'} eq "edit") { # $action = "edit"; # } # else { # $action = "add"; # } openeditorbox(_("Add a host"), _("Add a host"), ($cgiparams{'ACTION'} eq 'edit' || scalar(@errormessages) > 0 ? "showeditor" : ""), "hosts", @errormessages); printf < %s * %s %s %s * %s * %s * %s * %s %s END , _('Service'), _('Behind a proxy'), _('Enable wildcards'), _('Hostname'), _('Domain'), _('Username'), _('Password'), _('behind Router(NAT)'), _('Enabled'), ; if ($cgiparams{'ACTION'} eq 'edit') { print "\n"; } else { print "\n"; } &closeeditorbox(($cgiparams{'ACTION'} eq 'add' || $cgiparams{'ACTION'} eq 'edit' || scalar(@errormessages) > 0 ? _("Update Host") : _("Add Host")), _("Cancel"), "hostsbutton", "hosts", $ENV{'SCRIPT_NAME'}); printf < %s %s %s %s %s %s %s END , _('Service'), _('Hostname'), _('Domain'), _('Anonymous web proxies'), _('Wildcards'), _('Enabled'), _('Actions') ; my $id = 0; open(SETTINGS, "$filename") or die 'Unable to open config file.'; while () { my ($gifproxy,$descproxy,$gifwildcards,$descwildcard,$gifenabled,$descenabled); $id++; chomp($_); my @temp = split(/\,/,$_); if ($cgiparams{'ACTION'} eq 'edit' && $cgiparams{'ID'} eq $id) { print "\n"; } elsif ($id % 2) { print "\n"; } else { print "\n"; } if ($temp[3] eq 'on') { $gifproxy = 'on.png'; $descproxy = _('Enabled (click to disable)'); } else { $gifproxy = 'off.png'; $descproxy = _('Disabled (click to enable)'); } if ($temp[4] eq 'on') { $gifwildcards = 'on.png'; $descwildcard = _('Enabled (click to disable)'); } else { $gifwildcards = 'off.png'; $descwildcard = _('Disabled (click to enable)'); } if ($temp[7] eq 'on') { $gifenabled = 'on.png'; $descenabled = _('Enabled (click to disable)'); } else { $gifenabled = 'off.png'; $descenabled = _('Disabled (click to enable)'); } printf <$temp[0] $temp[1] $temp[2]
END , _('Edit'), _('Edit'), _('Edit'), _('Remove'), _('Remove'), _('Remove') ; } close(SETTINGS); printf <
END , _('Force update') ; # If the file contains entries, print Key to action icons if ( ! -z "$filename") { printf < %s:   %s %s     %s %s     %s %s     %s %s END , _('Legend'), _('Enabled (click to disable)'), _('Enabled (click to disable)'), _('Disabled (click to enable)'), _('Disabled (click to enable)'), _('Edit'), _('Edit'), _('Remove'), _('Remove') ; } &closebox(); &closebigbox(); &closepage();