Gheek.net

January 27, 2008

dnsdhcpgen_cgi

Filed under: cgi, dhcp, dns, perl — Tags: , , , — lancevermilion @ 11:15 pm
#!/usr/local/bin/perl
#Written By: Lance Vermilion
#Purpose: Provided the site size,iata,facility type, number of router,
#         number of switches, and the network address at the remote site
#         this script will generate the required format that SOG needs to
#         bulk load entires.
###########################################################################

#Sample output need for SOG
#iata,facilitytype,networkaddress,gateway,subnetnetmask,staticdevicerange(#-#),dhcprange(#-#),statics(host, ip)....

use CGI qw(:standard);

sub usage () {
print
  "Content-type: text/html\n\n" .
  "\n\n" .
  "DNS & DHCP Results\n" .
  "\n" .
  "\n" .
  "

ERROR

\n" . "

\n" . "\n"; print "\nYOU MUST FILL OUT EVERY FIELD\n"; print "\n" . "\n\n"; exit 0; } #### # Question for the user #### $size = param('size'); $iata = param('iata'); $factype = param('ou'); $numrtr = param('routers'); $numsw = param('switches'); $networkaddress = param('network'); if ( $size eq "" ) { &usage; } elsif ( $iata eq "" ) { &usage; } elsif ( $factype eq "" ) { &usage; } elsif ( $numrtr eq "" ) { &usage; } elsif ( $numsw eq "" ) { &usage; } elsif ( $networkaddress ne "") { ######################################## #### DO NOT CHANGE BELOW THIS POINT #### ######################################## if ( $size eq '/24' ) { #### # SMALL SITES #### my (@ips) = split(/\./, $networkaddress); $ip3octets = "$ips[0].$ips[1].$ips[2]"; @staticdevices; @staticdevicesDHL; @staticdevicesTOOLS; ## ##SWITCH ## $ip4thoctet = "4"; for ( $count = 1; $count <= $numsw; $count++ ) { chomp ($val = "us-$iata-$factype-ice-sw0$count,$ips[0].$ips[1].$ips[2].$ip4thoctet"); chomp ($valDHL = "us-$iata-$factype-ice-sw0$count 86400 IN CNAME us-$iata-$factype-ice-sw0$count.us.dhl.com."); chomp ($valTOOLS = "us-$iata-$factype-ice-sw0$count.dhl.com,$ips[0].$ips[1].$ips[2].$ip4thoctet"); push @staticdevices, $val; push @staticdevicesDHL, $valDHL; push @staticdevicesTOOLS, $valTOOLS; $ip4thoctet++; } ## ##ROUTER ## $rtrip4thoctet = "254"; for ( $count = 1; $count <= $numrtr; $count++ ) { chomp ($val = "us-$iata-$factype-ice-rt0$count,$ips[0].$ips[1].$ips[2].$rtrip4thoctet"); chomp ($valDHL = "us-$iata-$factype-ice-rt0$count 86400 IN CNAME us-$iata-$factype-ice-rt0$count.us.dhl.com."); chomp ($valTOOLS = "us-$iata-$factype-ice-rt0$count.dhl.com,$ips[0].$ips[1].$ips[2].$rtrip4thoctet"); push @staticdevices, $val; push @staticdevicesDHL, $valDHL; push @staticdevicesTOOLS, $valTOOLS; $rtrip4thoctet--; } ## ##DO NOT CHANGE VARIABLES BELOW ## $staticdevices = join(",", @staticdevices); $staticdevicesDHL = join("\n", @staticdevicesDHL); $staticdevicesTOOLS = join("\n", @staticdevicesTOOLS); $subnet = "255.255.255.192"; $gw = $ip3octets . ".1"; $network = $ip3octets . ".0"; $staticrange = "1-15"; $dhcprange = "16-62"; } elsif ( $size eq '/23' ) { #### # MEDIUM SITES #### my (@ips) = split(/\./, $networkaddress); $ip3octets = "$ips[0].$ips[1].$ips[2]"; @staticdevices; @staticdevicesDHL; @staticdevicesTOOLS; ## ##SWITCH ## $ip4thoctet = "4"; for ( $count = 1; $count <= $numsw; $count++ ) { chomp ($val = "us-$iata-$factype-ice-sw0$count,$ips[0].$ips[1].$ips[2].$ip4thoctet"); chomp ($valDHL = "us-$iata-$factype-ice-sw0$count 86400 IN CNAME us-$iata-$factype-ice-sw0$count.us.dhl.com."); chomp ($valTOOLS = "us-$iata-$factype-ice-sw0$count.dhl.com,$ips[0].$ips[1].$ips[2].$ip4thoctet"); push @staticdevices, $val; push @staticdevicesDHL, $valDHL; push @staticdevicesTOOLS, $valTOOLS; $ip4thoctet++; } ## ##ROUTER ## $rtrip3rdoctet = $ips[2] += 1; $rtrip4thoctet = "254"; for ( $count = 1; $count <= $numrtr; $count++ ) { chomp ($val = "us-$iata-$factype-ice-rt0$count,$ips[0].$ips[1].$rtrip3rdoctet.$rtrip4thoctet"); chomp ($valDHL = "us-$iata-$factype-ice-rt0$count 86400 IN CNAME us-$iata-$factype-ice-rt0$count.us.dhl.com."); chomp ($valTOOLS = "us-$iata-$factype-ice-rt0$count.dhl.com,$ips[0].$ips[1].$rtrip3rdoctet.$rtrip4thoctet"); push @staticdevices, $val; push @staticdevicesDHL, $valDHL; push @staticdevicesTOOLS, $valTOOLS; $rtrip4thoctet--; } ## ##DO NOT CHANGE VARIABLES BELOW ## $staticdevices = join(",", @staticdevices); $staticdevicesDHL = join("\n", @staticdevicesDHL); $staticdevicesTOOLS = join("\n", @staticdevicesTOOLS); $subnet = "255.255.255.128"; $gw = $ip3octets . ".1"; $network = $ip3octets . ".0"; $staticrange = "1-31"; $dhcprange = "32-126"; } elsif ( $size eq '/22' ) { #### # LARGE SITES #### my (@ips) = split(/\./, $networkaddress); $ip3octets = "$ips[0].$ips[1].$ips[2]"; @staticdevices; @staticdevicesDHL; @staticdevicesTOOLS; ## ##SWITCH ## $ip4thoctet = "4"; for ( $count = 1; $count <= $numsw; $count++ ) { chomp ($val = "us-$iata-$factype-ice-sw0$count,$ips[0].$ips[1].$ips[2].$ip4thoctet"); chomp ($valDHL = "us-$iata-$factype-ice-sw0$count 86400 IN CNAME us-$iata-$factype-ice-sw0$count.us.dhl.com."); chomp ($valTOOLS = "us-$iata-$factype-ice-sw0$count.dhl.com,$ips[0].$ips[1].$ips[2].$ip4thoctet"); push @staticdevices, $val; push @staticdevicesDHL, $valDHL; push @staticdevicesTOOLS, $valTOOLS; $ip4thoctet++; } ## ##ROUTER ## $rtrip3rdoctet = $ips[2] += 3; $rtrip4thoctet = "254"; for ( $count = 1; $count <= $numrtr; $count++ ) { chomp ($val = "us-$iata-$factype-ice-rt0$count,$ips[0].$ips[1].$rtrip3rdoctet.$rtrip4thoctet"); chomp ($valDHL = "us-$iata-$factype-ice-rt0$count 86400 IN CNAME us-$iata-$factype-ice-rt0$count.us.dhl.com."); chomp ($valTOOLS = "us-$iata-$factype-ice-rt0$count.dhl.com,$ips[0].$ips[1].$rtrip3rdoctet.$rtrip4thoctet"); push @staticdevices, $val; push @staticdevicesDHL, $valDHL; push @staticdevicesTOOLS, $valTOOLS; $rtrip4thoctet--; } ## ##DO NOT CHANGE VARIABLES BELOW ## $staticdevices = join(",", @staticdevices); $staticdevicesDHL = join("\n", @staticdevicesDHL); $staticdevicesTOOLS = join("\n", @staticdevicesTOOLS); $subnet = "255.255.255.0"; $gw = $ip3octets . ".1"; $network = $ip3octets . ".0"; $staticrange = "1-31"; $dhcprange = "32-254"; } else { print "Content-type: text/html\n\n" . "\n\n" . "ERROR\n" . "\n" . "\n" . "

ERROR

\n" . "

\n" . "\n"; print "YOU MUST TYPE: /22 or /23 or /24 NOT $size"; print "

“;

print “\n” .
“\n\n”;
exit 0;
}

print
“Content-type: text/html\n\n” .
“\n\n” .
“DNS & DHCP Results\n” .
“\n” .
“\n” .

DNS & DHCP Results

\n” .
Copy the output to the work order that goes to SOG” .

\n” .
“\n”;
print “\n$iata,$factype,$network,$gw,$subnet,$staticrange,$dhcprange,$staticdevices\n\n”;
print “

“;
print “SOG please notify \”AM Secure Access\” when you are done. So they can complete their work order.“;
print “

“;
print “\n\nCopy the output to the work order that goes to Secure Access\n\n“;
print “

“;
print “

";
  print "\n$staticdevicesDHL\n";
  print "

“;
print “\nCopy the output to the work order that goes to Network Management Tool\n\n“;
print “

“;
print “

";
  print "$staticdevicesTOOLS\n";
  print "

“;
print “\n” .
“\n\n”;

exit 0;

} else {
&usage;
}

Advertisements

Blog at WordPress.com.