#!/usr/bin/perl use CGI; $dnsdir = "/var/named/"; $dnsdaemon = "/usr/sbin/in.named"; $dnspidfile = "/var/run/named.pid"; $rndc = "/usr/local/sbin/rndc"; $comment = "Added_by_web_update"; $ENV{PATH} = '/bin:/usr/bin'; $query = new CGI; $entryname = $query->param('entryname'); $domain = $query->param('domain'); $destination = $query->param('destination'); $todo = $query->param('todo'); print "Content-type: text/html\n\n"; print $query->start_html(); #print "VALUES: $entryname $domain $destination $todo

"; if ($todo eq "add") { #print "ADD!
"; $isitthere = `grep -w $entryname $dnsdir$domain`; #print "
ISITTHEREADD = $isitthere"; if ($isitthere eq "") { #print "
OK TO ADD ENTRY
"; $addcommand = "echo \"$entryname\t\t\t7200\tIN\tA\t$destination\t;$comment\" >> $dnsdir$domain"; #print "
ADDCOMMAND:
$addcommand
"; system("$addcommand"); } else { print "
ERROR:Entry already exists!
"; exit; } } if ($todo eq "delete") { #print "
DELETE!
"; #verify that we're deleteing a addition by this program $isitthere = `grep -w $entryname $dnsdir$domain`; #print "
ISITTHERE: $isitthere
"; @split = split /;/,$isitthere; $addbyme = @split[1]; chop $addbyme; #print "ADBYME: $addbyme
"; #print "
COMMENT: $comment ADBYME: $addbyme
"; if ($addbyme eq $comment) { #print "
OK TO DELETE
"; $delcommand = "grep -v -w $entryname $dnsdir$domain > $dnsdir$domain.temp ; rm $dnsdir$domain; mv $dnsdir$domain.temp $dnsdir$domain"; #print "
DELECOMMD:$delcommand
"; system("$delcommand"); } else { print "
ERROR:Entry not added by webadmin!
"; exit; } } #update the serial $oldsline = `grep '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' $dnsdir$domain`; @split = split /;/,$oldsline; $oldserial = @split[0]; $year = (localtime)[5] + 1900; $mnth = ((localtime)[4] + 1); $day = (localtime)[3]; if ($day <=9 ) { $day = "0".$day }; if ($mnth <=9 ) { $mnth = "0".$mnth }; $newserial = "$year$mnth$day"."00"; while ($newserial <= $oldserial) { $newserial = $newserial + 1; }; #print "
NEW NEW SN=$newserial
"; $replacesncommand = "cat $dnsdir$domain | sed '/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/s//$newserial/' > $dnsdir$domain.temp ; rm $dnsdir$domain; mv $dnsdir$domain.temp $dnsdir$domain"; #print "
$replacesncommand
"; system("$replacesncommand"); #restart the name server $output = system("$rndc reload"); print "
OK
";