#!/usr/bin/perl # # Description: # Take tab delimited or comma delimited text file of networks and create basic # network Firewall-1 objects. # Options exist to: # --csv Comma seperated data # --tab Tab delimited data # # Additional features # --routes Create static routing statements # use Getopt::Long; # Subroutines relevant to this system sub Usage { print "usage: $ARGV[0] [--csv | --tab] [--routes] --file \n"; exit 0; } sub fwlNetworkObjs ($$$) { # Passes $name, $ip, $mask my ($name, $ip, $mask) = @_; # Format of network object in objects.C is something like: # : (net-192.39.1.0 # :color ("dark green") # :type (network) # :location (internal) # :broadcast (allow) # :comments () # :ipaddr (192.39.1.0) # :netmask (255.255.255.0) # :"#oldname" ( # :type (refobj) # :refname ("#_net-192.39.1") # ) # ) # # Notes: White space is a tab (\t) # : requires opening and closing brackets to 'close' the defintion, but # can further expand to contain nested definitions. print "\t\t: (net-$ip\n"; print "\t\t\t:color (\"dark green\")\n"; print "\t\t\t:type (network)\n"; print "\t\t\t:location (internal)\n"; print "\t\t\t:broadcast (internal)\n"; print "\t\t\t:comments ($name)\n"; print "\t\t\t:ipaddr ($ip)\n"; print "\t\t\t:netmask ($mask)\n"; print "\t\t\t:\"#oldname\" (\n"; print "\t\t\t\t:type (refobj)\n"; print "\t\t\t\t:refname (\"#_net-$ip\")\n"; print "\t\t\t)\n"; print "\t\t)\n"; } # Globals ;) $csvfile = 0; $tabfile = 0; # process cmd line arguments %cmdopts = (); GetOptions(\%cmdopts,'csv','tab','routes','file:s'); # Process options, and check for sanity if ($cmdopts{'csv'} ne "") { # Use Comma seperated Value file of network names, ip address and subnet $csvfile = 1; if ($cmdopts{'tab'} ne "") { Usage; } } elsif ($cmdopts{'tab'} ne "" ) { # Use tab delimited file $tabfile = 1; } else { Usage; } if ($cmdopts{'routes'} ne "" ) { # Print out routing commands } if ($cmdopts{'file'} eq "") { # No filename specified Usage; } # Format of file should be: # NetnameNetworkIPNetmask open(NETFILE,$cmdopts{'file'}) or die "ERROR: Can't open file $cmdopts{'file'}\n"; chomp; while () { # Split data into parts based on delimitor if ($tabfile == 1) { ($netname,$netip,$netmask) = split(/\t/); } else { ($netname,$netip,$netmask) = split(/,/); } # Remove trailing UNIX and MSDOC carriage return and newlines $netmask =~ s/\r//; $netmask =~ s/\n//; fwlNetworkObjs($netname,$netip,$netmask); chomp; }