diff options
Diffstat (limited to 'bootstrap/make-dhcpd.pl')
-rwxr-xr-x | bootstrap/make-dhcpd.pl | 85 |
1 files changed, 53 insertions, 32 deletions
diff --git a/bootstrap/make-dhcpd.pl b/bootstrap/make-dhcpd.pl index 7bd1a5c..ad39704 100755 --- a/bootstrap/make-dhcpd.pl +++ b/bootstrap/make-dhcpd.pl @@ -4,10 +4,10 @@ use Net::IP; use NetAddr::IP; BEGIN { - require "include/config.pm"; - eval { - require "include/config.local.pm"; - }; + require "include/config.pm"; + eval { + require "include/config.local.pm"; + }; } my $base = "/etc"; @@ -39,10 +39,10 @@ my $sec_n = $sec_num - int($sec_num / 4); # don't use more than 1/4 of the net f # Create main configuration file for DHCP if ( not -f $dhcpd_conf ) { - print STDERR "Creating file " . $dhcpd_conf . "\n"; - open DHCPDFILE, ">" . $dhcpd_conf or die ( $! . " " . $dhcpd_conf); + print STDERR "Creating file " . $dhcpd_conf . "\n"; + open DHCPDFILE, ">" . $dhcpd_conf or die ( $! . " " . $dhcpd_conf); - print DHCPDFILE <<"EOF"; + print DHCPDFILE <<"EOF"; # GENERATED BY make-dhcpd.pl # 60 min leasetime, 120 min max @@ -105,16 +105,16 @@ include "$dhcpd_voip_conf"; include "$dhcpd_fap_conf"; EOF - close DHCPDFILE; + close DHCPDFILE; } # Create PXE-boot configuration file for DHCP if ( not -f $dhcpd_pxeconf ) { - print STDERR "Creating file " . $dhcpd_pxeconf . "\n"; - open PXEFILE, ">" . $dhcpd_pxeconf or die ( $! . " " . $dhcpd_pxeconf); + print STDERR "Creating file " . $dhcpd_pxeconf . "\n"; + open PXEFILE, ">" . $dhcpd_pxeconf or die ( $! . " " . $dhcpd_pxeconf); - print PXEFILE <<"EOF"; + print PXEFILE <<"EOF"; option arch code 93 = unsigned integer 16; if option arch = 00:07 { @@ -127,16 +127,16 @@ next-server $nms::config::pxe_server_v4; EOF - close PXEFILE; + close PXEFILE; } # Create WLC configuration file if ( not -f $dhcpd_wlc_conf ) { - print STDERR "Creating file " . $dhcpd_wlc_conf . "\n"; - open WLCFILE, ">" . $dhcpd_wlc_conf or die ( $! . " " . $dhcpd_wlc_conf); + print STDERR "Creating file " . $dhcpd_wlc_conf . "\n"; + open WLCFILE, ">" . $dhcpd_wlc_conf or die ( $! . " " . $dhcpd_wlc_conf); - print WLCFILE <<"EOF"; + print WLCFILE <<"EOF"; option space WLC; option WLC.controller-address code 43 = text; set vendor-string = option vendor-class-identifier; @@ -149,16 +149,16 @@ class "access-points" { option WLC.controller-address "$nms::config::wlc1_v4"; } EOF - close WLCFILE; + close WLCFILE; } # Create VoIP config if ( not -f $dhcpd_voip_conf ) { - print STDERR "Creating file " . $dhcpd_voip_conf . "\n"; - open VOIPFILE, ">" . $dhcpd_voip_conf or die ( $! . " " . $dhcpd_voip_conf); + print STDERR "Creating file " . $dhcpd_voip_conf . "\n"; + open VOIPFILE, ">" . $dhcpd_voip_conf or die ( $! . " " . $dhcpd_voip_conf); - print VOIPFILE <<"EOF"; + print VOIPFILE <<"EOF"; option space CiscoVOIP; option CiscoVOIP.cm-tftp-server code 150 = array of ip-address; @@ -178,16 +178,18 @@ class "cisco-voip-wlan" { next-server $nms::config::voip1_v4; } EOF - close VOIPFILE; + close VOIPFILE; } # Create FAP/Gondul config if ( not -f $dhcpd_fap_conf ) { - print STDERR "Creating file " . $dhcpd_fap_conf . "\n"; - open FAPFILE, ">" . $dhcpd_fap_conf or die ( $! . " " . $dhcpd_fap_conf); + print STDERR "Creating file " . $dhcpd_fap_conf . "\n"; + open FAPFILE, ">" . $dhcpd_fap_conf or die ( $! . " " . $dhcpd_fap_conf); + + print FAPFILE <<"EOF"; +# FAP DHCP-configuration - print FAPFILE <<"EOF"; # Define structure of option 43 ( Zero Touch Protocol options) option space ztp; #option ztp.image-file-name code 0 = text; @@ -203,21 +205,20 @@ option option-150 code 150 = { ip-address }; # define option 60 - used for classifying ZTP clients ("vendor class identifier") option vendor-class-identifier code 60 = text; -# set short leasetime, so that it times out at reboot -default-lease-time 120; -max-lease-time 120; - -# define ranges group { # No DDNS ddns-updates off; ddns-hostname = none; ddns-domainname = none; - + # supershort leasetime default-lease-time 120; max-lease-time 120; + # set short leasetime, so that it times out at reboot + default-lease-time 120; + max-lease-time 120; + # ZTP Settings option option-150 $nms::config::fap_server_v4; option tftp-server-name "$nms::config::fap_server_v4"; @@ -225,12 +226,32 @@ group { option ztp.config-file-name = concat("api/config/", (option agent.circuit-id)); #option ztp.image-file-name "files/jinstall-ex-2200-14.1X53-D15.2-domestic-signed.tgz"; - -} + ### define ranges EOF - close FAPFILE; + + foreach my $fap_net (@nms::config::fap_networks){ + my $fap_subnet = Net::IP->new($fap_net)->ip(); + my $fap_mask = Net::IP->new($fap_net)->mask(); + (my $fap_last = NetAddr::IP->new($fap_net)->last()) =~ s/\/[0-9]{1,2}//; + (my $fap_gw = NetAddr::IP->new($fap_net)->first()) =~ s/\/[0-9]{1,2}//; + my $fap_num = NetAddr::IP->new($fap_net)->num(); + my $fap_n = $fap_num - int($fap_num / 2); # don't use more than 1/2 of the net for DHCP + (my $fap_first = NetAddr::IP->new($fap_net)->nth($fap_n)) =~ s/\/[0-9]{1,2}//; + + print FAPFILE <<"EOF"; + subnet $fap_subnet netmask $fap_mask { + range $fap_first $fap_last; + option subnet-mask $fap_mask; + option routers $fap_gw; + } +EOF + + } + + print FAPFILE "}\n"; + close FAPFILE; } |