aboutsummaryrefslogtreecommitdiffstats
path: root/bootstrap/make-dhcpd.pl
blob: d734c1dae6dc8ac4b61b268a054bc1852a127593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/perl -I /root/tgmanage
use strict;

use Net::IP;

BEGIN {
        require "include/config.pm";
        eval {
                require "include/config.local.pm";
        };
}

my $base = "/etc";
$base = $ARGV[0] if $#ARGV > -1;
$base .= "/" if not $base =~ m/\/$/ and not $base eq "";

my $dhcpd_base = $base . "dhcp/";
my $dhcpd_conf =  $dhcpd_base . "dhcpd.conf";
my $dhcpd_pxeconf =  $dhcpd_base . "pxe-boot.conf";
my $dhcpd_wlc_conf=  $dhcpd_base . "wlc-conf.conf";

# primary
my $pri_range = Net::IP->new($nms::config::pri_net) or die ("oopxos");
my $pri_mask = $pri_range->mask();
my $pri_net = $pri_range->ip();

# secondary
my $sec_range = Net::IP->new($nms::config::sec_net) or die ("oopxos");
my $sec_mask = $sec_range->mask();
my $sec_net = $sec_range->ip();

# Create PXE-boot configuration file for DHCP on master.
if ( not -f $dhcpd_conf )
{
		print STDERR "Creating file " . $dhcpd_conf . "\n";
		open DHCPDFILE, ">" . $dhcpd_conf or die ( $! . " " . $dhcpd_conf);

		print DHCPDFILE <<"EOF";
# GENERATED BY make-dhcpd.pl
#
# Central concept: as little config in the main .conf,
# include almost everything from separate files..
#
# log-facility local7;
option domain-name "$nms::config::tgname.gathering.org";
option domain-name-servers $nms::config::pri_v4, $nms::config::sec_v4;
default-lease-time 3600;
max-lease-time 7200;
authoritative;

ddns-update-style interim;
key DHCP_UPDATER {
        algorithm HMAC-MD5.SIG-ALG.REG.INT;
        secret $nms::config::ddns_key;
}

subnet $pri_net netmask $pri_mask {}
subnet $sec_net netmask $sec_mask {}

include "/etc/dhcp/revzones.conf";
include "/etc/dhcp/generated-include.conf";
include "$dhcpd_pxeconf";
include "$dhcpd_wlc_conf";

EOF
		close DHCPDFILE;
}

# Create PXE-boot configuration file for DHCP on master.
if ( not -f $dhcpd_pxeconf )
{
		print STDERR "Creating file " . $dhcpd_pxeconf . "\n";
		open PXEFILE, ">" . $dhcpd_pxeconf or die ( $! . " " . $dhcpd_pxeconf);

		print PXEFILE "next-server " . $nms::config::pxe_server . ";\n";
		print PXEFILE "filename \"pxelinux.0\";\n";

		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 WLCFILE <<"EOF";
option space CiscoAP;
option CiscoAP.server-address code 241 = array of ip-address;
set vendor-string = option vendor-class-identifier;

class "cisco-aps" {
       match if substring (option vendor-class-identifier, 0, 8) = "Cisco AP";
       vendor-option-space CiscoAP;
       option CiscoAP.server-address $nms::config::wlc1;
}
EOF
		close WLCFILE;
}