#!/usr/bin/perl # _____ ___ ____ _ _ # | ___| __ ___ ___|_ _| _ \ __| | |__ # | |_ | '__/ _ \/ _ \| || |_) / _` | '_ \ # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # # index.cgi-$Name: $-$Revision: 1.24 $ $Date: 2002/04/29 18:59:02 $ <$Author: bapril $@freeipdb.org> ###################################################################### use strict; use warnings; require 'ipdb_httpcgi.pl'; use config; use CGI qw( :standard :cgi-lib ); use DBI; $config::config{'_REMOTE_USER'} = $ENV{'REMOTE_USER'}; $config::config{'_REMOTE_ADDR'} = $ENV{'REMOTE_ADDR'}; $config::config{'debug'} = 1; $| = 1; my $css = < meta({ -http_equiv => 'PRAGMA', -content => 'NO-CACHE' }), -title => $config::config{ver}, -style => { -code => [ $css ] }, ); my $conn = DBI->connect("DBI:Pg:dbname=$config::config{dbname};host=$config::config{dbhost};port=$config::config{dbport}", $config::config{dbuser}, $config::config{dbpass}); my $script = get_cgi($0); our %FORM = Vars; if( $FORM{BLOCK} && $FORM{BLOCK} =~ /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\/([0-9]{1,2})/ ) { $FORM{BLOCK} = $1; $FORM{BITS} = $2; } if( ! $FORM{ACTION} ) { goto MAIN; } elsif( $FORM{ACTION} eq 'RECLAIM' ) { if($config::config{confirm_reclaim}){ if( $FORM{CONFIRM} ) { if( $FORM{CONFIRM} eq $FORM{CONFIRM2} ){ print "CONFIRM:\n"; unless(&ClearRevDNS($conn,$FORM{RECLAIM})){ unless(&ReclaimBlock($conn,$FORM{RECLAIM})){ print "Reclaim Block ".$FORM{RECLAIM}." CONFIRMED\n
"; } } } else { print "Confirm Failed\n"; &ReclaimConfirm($conn,$FORM{RECLAIM}); &printTail(); $conn->disconnect; exit(); } } else { &ReclaimConfirm($conn,$FORM{RECLAIM}); &printTail(); $conn->disconnect; exit(); } } else { #procede to reclaim unless(&ClearRevDNS($conn,$FORM{RECLAIM})){ unless(&ReclaimBlock($conn,$FORM{RECLAIM})){ print "Reclaim Block ".$FORM{RECLAIM}."\n
"; } } } goto MAIN; } elsif( $FORM{ACTION} eq 'UPDATE' ) { &UpdateBlock($conn,$FORM{UPDATE},$FORM{REGION},$FORM{CUSTOMER},$FORM{CUSTDESC}); print "Block Updated\n"; $FORM{ACTION} = 'EDIT'; # Show edit form with new values. $FORM{EDIT} = $FORM{UPDATE}; goto MAIN; } elsif( $FORM{ACTION} eq 'DNSEDIT' ) { if($FORM{'SUB'} =~ /Add A\+PTR/){ print "Creating Forward and Reverse DNS Record for $FORM{'HOSTNAME'}
\n"; my $host = &CleanDNSText($FORM{'HOSTNAME'}); $host =~ s/^([a-zA-Z0-9-]+)\.//; my $zone = &GetZone($conn,$host); $host = $1; &SetFwdDNS($conn,$FORM{'BLOCK'},$zone,$FORM{'INDEX'},$host); &SetRevDNS($conn,$FORM{'BLOCK'},$zone,$FORM{'INDEX'},$host); } elsif($FORM{'SUB'} =~ /Add A/){ #Add A Record print "Creating Forward DNS Record for $FORM{'HOSTNAME'}
\n"; my $host = &CleanDNSText($FORM{'HOSTNAME'}); $host =~ s/^([a-zA-Z0-9-]+)\.//; my $zone = &GetZone($conn,$host); $host = $1; &SetFwdDNS($conn,$FORM{'BLOCK'},$zone,$FORM{'INDEX'},$host); } elsif($FORM{'SUB'} =~ /Add CNAME/){ #Add CNAME } elsif($FORM{'SUB'} =~ /Add MX/){ #Add MX record } elsif($FORM{'SUB'} =~ /Add NS/){ #Add NS Record } elsif($FORM{'SUB'} =~ /Add PTR/){ #Add PTR record. print "Creating Reverse DNS Record for $FORM{'HOSTNAME'}
\n"; my $host = &CleanDNSText($FORM{'HOSTNAME'}); $host =~ s/^([a-zA-Z0-9-]+)\.//; my $zone = &GetZone($conn,$host); $host = $1; &SetRevDNS($conn,$FORM{'BLOCK'},$zone,$FORM{'INDEX'},$host); } elsif($FORM{'SUB'} =~ /Delegate Block/){ my $host = &CleanDNSText($FORM{'HOSTNAME'}); if($host ne $FORM{'HOSTNAME'}){&IPDBError(-1,"Hostname supplied for Delegation is illegal");} #Delegate full block. &DelegateBlock($conn,$FORM{'BLOCK'},$FORM{'HOSTNAME'}); print "Delegating block to:$FORM{'HOSTNAME'}\n"; } $FORM{'ACTION'} = "EDIT"; # Show edit form with new values. $FORM{'EDIT'} = $FORM{'BLOCK'}; goto MAIN; } elsif( $FORM{ACTION} eq 'DELETEDNS' ) { &DeleteDNSRecord($conn,$FORM{'ID'}); print "DNS Record Deleted."; $FORM{'ACTION'} = "EDIT"; # Show edit form with new values. goto MAIN; } elsif( $FORM{ACTION} eq 'EDIT' ) { &EditForm($conn,$FORM{'EDIT'},$script); if($config::config{allowDNS}){ &DNSTable($conn,$FORM{'EDIT'},$script); &DNSForm($conn,$FORM{'EDIT'},$script); } &printTail(); $conn->disconnect; exit(); } elsif( $FORM{ACTION} eq 'CLEARHOLD' ) { print "Clear holdtime on block $FORM{'EDIT'}
\n"; &ClearHoldtime($conn,$FORM{'EDIT'}); print "Success!\n"; &printTail(); $conn->disconnect; exit(); } elsif( $FORM{ACTION} eq 'ASSIGN' ) { my @block = &GetBlockFromID($conn,$FORM{'UPDATE'}); print "Here $FORM{'UPDATE'} $block[0]/$block[1]"; my $ver = &VersionFromRegion($conn,$FORM{'REGION'}); my $ip = deci2ip($block[0],$ver); my $id = &SetBlockP($conn,$ip,$FORM{'REGION'},$block[1],$FORM{'CUSTDESC'},$FORM{'CUSTOMER'},$ver); print "Assigned\n"; goto MAIN; } elsif( $FORM{ACTION} eq 'SUBMIT6' ) { print "Reclaim?"; if($FORM{'ACCEPT'}){ print "Done!\n"; } if($FORM{'DENY'}){ &ReclaimBlock($conn,$FORM{'BLOCK'}); } goto MAIN; } elsif( $FORM{ACTION} eq 'ZONEED' ) { if($FORM{'OPER'} =~ /Toggle State/){ &ToggleZone($conn,$FORM{'ZONE'}); } elsif($FORM{'OPER'} =~ /Edit Zone/){ print "Edit Zone $FORM{'ZONE'}\n"; &SOAEdit($conn,$FORM{'ZONE'}); if(&IsReverse($conn,$FORM{'ZONE'})){ &EditRevZone($conn,$FORM{'ZONE'}); } else { &EditFwdZone($conn,$FORM{'ZONE'}); } } elsif($FORM{'OPER'} =~ /View Zone/){ print "Zone: $FORM{'ZONE'}\n"; print "
\n";
		&DNSHead($conn,$FORM{'ZONE'},0);
		if(&IsReverse($conn,$FORM{'ZONE'})){
			my $block = &GetBlockFromZone($conn,$FORM{'ZONE'});
			&WalkReverseBlocks($conn,$block);
		} else {
			&WalkZone($conn,$FORM{'ZONE'});
		}
		print "
\n"; &printTail(); $conn->disconnect; exit(); } else{ print "\n"; &ZoneTable($conn,$script,$FORM{'ZONEPARENT'}); print "
\n"; &printTail(); $conn->disconnect; exit(); } } elsif( $FORM{ACTION} eq 'DATADUMP' ) { my $exit = 0; if($FORM{'REGION'} =~ /---/){ print "

Must Select Region \n"; $exit = 1; } if($FORM{'BLOCK'}){ if($FORM{'BLOCK'} =~ m/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\/([0-9]{1,2})/){ $FORM{'BLOCK'} = $1; $FORM{'BITS'} = $2; } elsif ($FORM{'BLOCK'} =~ m/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/ && $FORM{'BITS'}){ $FORM{'BLOCK'} = $1; } elsif ($FORM{'BLOCK'} =~ m/([0-9A-F]{4}:[0-9A-F]{4}:[0-9A-F]{4}:[0-9A-F]{4}:[0-9A-F]{4}:[0-9A-F]{4}:[0-9A-F]{4}:[0-9A-F]{4})\/([0-9]{1,3})/){ $FORM{'BLOCK'} = $1; $FORM{'BITS'} = $2; } else { print "

Bad IP block format.\n"; #exit = 1; } if($exit){ print ""; &printTail(); $conn->disconnect;exit(); } # Bail Missing some info. &DataDump($conn,$FORM{BLOCK},$FORM{BITS},$FORM{'REGION'}); } else { my @List = &RegionAllocations($conn,$FORM{'REGION'}); my $i = 0; my $ver = &Version($conn,$FORM{'REGION'}); while($List[$i]){ my @block = &GetBlockFromID($conn,$List[$i]); my $ip = &deci2ip($block[0],$ver); &DataDump($conn,$ip,$block[1],$FORM{'REGION'}); $i++; } } &printTail; exit(); } elsif( $FORM{ACTION} eq 'SEARCHLOG' ) { &LogHead(); &LogSearch($conn,$FORM{'REGION'}); &printTail; exit(); } elsif( $FORM{ACTION} eq 'REQ' ) { print "\n"; my $exit = ""; if($FORM{'REGION'} =~ /---/){ print "\n"; $exit = 1; } if($FORM{'BITS'} =~ /---/){ print "\n"; $exit = 1; } if($FORM{'HOSTNAME'}){ print "\n"; $exit = 1; } if($config::config{'custname_r'} && $config::config{'custname'}){ if(!$FORM{'CUSTDESC'}){ print "\n"; $exit = 1; } } if($config::config{'custnum_r'} && $config::config{'custnum'}){ if(!$FORM{'CUSTOMER'}){ print "\n"; $exit = 1; } } if($config::config{'allowRwhois'}){ if($FORM{'ADMINC'} =~ /---/){ print "\n"; $exit = 1; } if($FORM{'TECHC'} =~ /---/){ print "\n"; } if($config::config{'requireRwhois'}){ if(!$FORM{'NETNAME'}){ print "\n"; $exit = 1; } elsif (!$FORM{'ORG'}) { print "Rwhois Form"; #&RwhoisForm($conn,,$FORM{'NETNAME'}); $exit = 1; } } } if($exit){ print "

Please go back and choose a REGION

Please go back and choose a Block Size

Can't Sethostname and request a block at the same time

No $config::config{'custname_f'}

No $config::config{'custnum_f'}

Please Choose an Admin Contact

Please Choose an Tech Contact

No NetName

"; &printTail(); $conn->disconnect; exit(); } # Bail Missing some info. print "\n"; print ""; print "
Confirm New IP Block Assignment
\n"; print "\n"; print ""; my $newblock = &GetNewBlock($conn,$FORM{'REGION'},$FORM{'BITS'},$FORM{'CUSTDESC'},$FORM{'CUSTOMER'}); print "\n"; print "
"; print ""; print ""; print ""; print ""; print ""; print "
"; &printTail(); $conn->disconnect; exit(); } elsif( $FORM{ACTION} eq 'SEARCH' ) { my $block = ""; if($FORM{'BLOCK'}){ $block = &IP2Deci($FORM{'BLOCK'}); } my $region = $FORM{'REGION'}; my $bits = $FORM{'BITS'}; my $cust = $FORM{'CUSTOMER'}; my $custdesc = $FORM{'CUSTDESC'}; my $hostname = $FORM{'HOSTNAME'}; my $id = $FORM{'BLOCKID'}; print "\n"; &AllocatedSearch_Head(); &AllocatedSearch($conn,$script,1,$id,$block,$bits,$region,$cust,$custdesc,$hostname,1); print ""; &printTail(); $conn->disconnect; exit(); } elsif( $FORM{ACTION} eq 'RECURSE' ) { my $id1 = $FORM{'CHILDL'}; my $id2 = $FORM{'CHILDR'}; &AllocatedSearch_Head(); &AllocatedSearch($conn,$script,1,$id1); &AllocatedSearch($conn,$script,1,$id2); print ""; &printTail(); $conn->disconnect; exit(); } elsif( $FORM{ACTION} eq 'LISTFREE' ) { print ""; print "\n"; &FreeList($conn); print "
REGIONBlockReclaimIDHoldtime
"; &printTail(); $conn->disconnect; exit(); } elsif( $FORM{ACTION} eq 'SETDNS' ) { # Check for hostname and an IP address. my $exit = 0; if($FORM{'HOSTNAME'} =~ m/[^A-Za-z0-9\.-]/){ print "

Hostname contains invalid symbols.\n"; $exit = 1; } if($exit){ print ""; &printTail(); $conn->disconnect; exit(); } # Bail Missing some info. if($FORM{'BLOCK'} && $FORM{'HOSTNAME'} && ($FORM{'REGION'} !~ m/---/)){ print ""; my $fqdn = $FORM{'HOSTNAME'}; $fqdn =~ m/^([0-9A-Za-z-]*)\.(.*)$/; my $hostname = $1; $hostname =~ s/[\/:_]/-/g; $hostname =~ s/[ ]//g; $hostname =~ s/--//g; $hostname =~ s/^-//g; $hostname =~ s/\.\././g; $hostname =~ s/-\././g; my $zone = $2; $zone =~ s/[\/:_]/-/g; $zone =~ s/[ ]//g; $zone =~ s/--//g; $zone =~ s/^-//g; $zone =~ s/\.\././g; $zone =~ s/-\././g; my $ForZone = &GetZone($conn,$zone); #Get Block ID and Offset. my $BLK = ip2deci($FORM{'BLOCK'}); my @blk = &GetBlockIdNM($conn,$BLK,$FORM{'REGION'}); my $block = $blk[0]; my $index = $blk[1]; unless($block){ print "Block not allocated.(Can't assign DNS)"; } else { #Set the reverse enrty. if($FORM{'DNSTYPE'} eq "REV" || $FORM{'DNSTYPE'} eq "BOTH"){ print "Set Reverse DNS for $FORM{'BLOCK'} to $fqdn { $index }
\n"; &SetRevDNS($conn,$block,$ForZone,$index,$hostname); &SetRevZone($conn,$FORM{'BLOCK'},$FORM{'REGION'}); } #Get/Create the Forward Block ID #Set the forward entry. if($FORM{'DNSTYPE'} eq "FWD" || $FORM{'DNSTYPE'} eq "BOTH"){ print "Set Forward DNS for $FORM{'BLOCK'} to $fqdn
\n"; &SetFwdDNS($conn,$block,$ForZone,$index,$hostname); } } print "
"; } else { print "

No IP address ,region or hostname set

\n"; &printTail(); $conn->disconnect; exit(); } } exit; MAIN: print < EOF if($config::config{'custname'}){ print < EOF } if($config::config{'custnum'}){ print < EOF } if($config::config{'allowDNS'}){ print < EOF } if($config::config{'allowRwhois'}){ print < EOF } print <
$config::config{'ver'}
Block:
Subnet Mask:
Region:
$config::config{'custname_f'}:
$config::config{'custnum_f'}:
Hostname: Set :
Rhowis: Net-Name: Admin-c: Tech-c:
Action:
EOF &printTail; $conn->disconnect;