diff options
author | Tarik Gasmi | 2007-07-31 09:29:53 +0200 |
---|---|---|
committer | Tarik Gasmi | 2007-07-31 09:29:53 +0200 |
commit | c7b4e4a81d7f38c0f1f927f6804ef281c4f67dcd (patch) | |
tree | 974eb0c95d0ff2678439b161246433cde972564d /ldap-site-mngmt/generation-scripts/dhcp_generate.pl | |
parent | * more work towards Debian & Ubuntu support, Debian-4.0, Ubuntu-6.10 (diff) | |
download | core-c7b4e4a81d7f38c0f1f927f6804ef281c4f67dcd.tar.gz core-c7b4e4a81d7f38c0f1f927f6804ef281c4f67dcd.tar.xz core-c7b4e4a81d7f38c0f1f927f6804ef281c4f67dcd.zip |
Actualized LDAP SiteManagement Code - Web Interface, DHCP Generationscript
git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1284 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'ldap-site-mngmt/generation-scripts/dhcp_generate.pl')
-rw-r--r-- | ldap-site-mngmt/generation-scripts/dhcp_generate.pl | 73 |
1 files changed, 53 insertions, 20 deletions
diff --git a/ldap-site-mngmt/generation-scripts/dhcp_generate.pl b/ldap-site-mngmt/generation-scripts/dhcp_generate.pl index 13969f34..f8c2cfb6 100644 --- a/ldap-site-mngmt/generation-scripts/dhcp_generate.pl +++ b/ldap-site-mngmt/generation-scripts/dhcp_generate.pl @@ -2,12 +2,12 @@ # Generate ISC DHCP Configuration File # -# generates an include file "dhcp.master.inc" included in dhcpd.conf -# with: +# Reads DHCP Config Data form LDAP Directory and generates an +# include file "dhcp.master.inc" included in dhcpd.conf with: # - Definitions of User-defined DHCP Options # - DHCP Service Global Options -# - DHCP Subnet Deklarations and Options -# - DHCP Host Deklarations and Options +# - DHCP Subnet Declarations, Options and Dynamic Pools +# - DHCP Host Declarations and Options use strict; @@ -17,13 +17,13 @@ use warnings; use Net::LDAP; use Net::LDAP::LDIF; +# Configuration Variables for Perl-Script our ( $ldaphost, $basedn, $userdn, $passwd, $dhcpdn, $dhcpdconfpath, $dhcpdconffile ); -my ( $ldap, $mesg ); - -# Read Configuration Variables for LDAP/ +# Read Configuration Variables ... require "dhcpgen.conf.pl"; #use dhcpgenconfig; +my ( $ldap, $mesg, $mesg2 ); # Bind with LDAP Server $ldap = Net::LDAP->new( $ldaphost ) or die "$@"; @@ -67,10 +67,17 @@ if ($dhcpsrventry->exists( 'OptionDefinition' )) { printf DATEI "%s\n", $optdef; } } +# Failover Information of DHCP Service +my $failoverpeer; +if ($dhcpsrventry->exists( 'dhcpFailoverPeer' )) { + $failoverpeer = $dhcpsrventry->get_value( 'dhcpFailoverPeer' ); +} + +my $indent = ""; printf DATEI "\n\n######################\n# Global Options\n######################\n\n"; # write DHCP Options in global Scope -dhcpoptions( $dhcpsrventry ); +dhcpoptions( $dhcpsrventry, $indent ); printf DATEI "\n"; @@ -95,13 +102,36 @@ foreach my $subnetentry ( @subnets ) { my $netmask = $subnetentry->get_value( 'dhcpoptnetmask' ); printf DATEI "subnet %s netmask %s {\n", $subnet, $netmask; # write DHCP Options in Subnet Scope - dhcpoptions($subnetentry); - # Range - if ($subnetentry->exists( 'dhcpRange' )) { - my @range = split /_/,$subnetentry->get_value( 'dhcpRange' ); - printf DATEI " range %s %s;\n", $range[0], $range[1]; + my $optindent = " "; + dhcpoptions($subnetentry,$optindent); + + # write Pool Declarations in Subnet Declaration + # ldapsearch on Pool Objects referencing to DHCP Subnet Object + $mesg2 = $ldap->search(base=>$basedn, + scope => 'sub', + filter => '(&(objectclass=dhcpPool)(dhcphlpcont:dn:='.$subnetdn.'))'); + #Net::LDAP::LDIF->new( \*STDOUT,"w" )->write( $mesg->entries ); + $mesg2->code && die $mesg2->error; + my @pools = $mesg2->sorted('cn'); + + foreach my $poolentry ( @pools ) { + printf DATEI "%spool {\n", $optindent; + # write DHCP Options in Pool Scope + my $poolindent = " "; + if ( $failoverpeer ){ + printf DATEI "%sfailover peer \"%s\";\n", $poolindent, $failoverpeer; + printf DATEI "%sdeny dynamic bootp clients;\n", $poolindent; + } + if ($poolentry->exists( 'dhcpRange' )) { + #foreach my $ranges ( @) { + my @range = split /_/,$poolentry->get_value( 'dhcpRange' ); + printf DATEI "%srange %s %s;\n", $poolindent, $range[0], $range[1]; + } + dhcpoptions($poolentry,$poolindent); + printf DATEI "%s}\n", $optindent; } - + + # close Subnet Declaration printf DATEI "}\n\n"; } @@ -130,7 +160,7 @@ foreach my $hostentry ( @hosts ) { my @auarray = split /=/,$dnarray[2]; my $hostauactual = $auarray[1]; if ( $hostau ne $hostauactual) { - # hier neues handle und pfad falls eigene includedatei ... + # hier neues Datei Handle und neuer Pfad falls eigene includedatei ... printf DATEI "\n################################################\n# AU: %s \n", $hostauactual; $hostau = $hostauactual; } @@ -138,6 +168,7 @@ foreach my $hostentry ( @hosts ) { dhcphost($hostentry); } + close DATEI; # LDAP unbind @@ -153,6 +184,7 @@ exit (0); # write DHCP Options, Parameter: DHCP Object LDAP Entry sub dhcpoptions { my $entry = shift; + my $indent = shift; my @atts = $entry->attributes; # DHCP Optionen mit 'option' vorne dran @@ -163,9 +195,9 @@ sub dhcpoptions { my $value = $entry->get_value( $option ); $option =~ s/dhcpopt//; if ( $option eq "Domain-name"){ - printf DATEI " option %s \"%s\";\n", lc($option), $value; + printf DATEI "%soption %s \"%s\";\n", $indent, lc($option), $value; }else{ - printf DATEI " option %s %s;\n", lc($option), $value; + printf DATEI "%soption %s %s;\n", $indent, lc($option), $value; } } } @@ -177,9 +209,9 @@ sub dhcpoptions { my $value = $entry->get_value( $option ); $option =~ s/dhcpOpt//; if ( $option eq "Filename"){ - printf DATEI " %s \"%s\";\n", lc($option), $value; + printf DATEI "%s%s \"%s\";\n", $indent, lc($option), $value; }else{ - printf DATEI " %s %s;\n", lc($option), $value; + printf DATEI "%s%s %s;\n", $indent, lc($option), $value; } } } @@ -210,6 +242,7 @@ sub dhcphost { printf DATEI " option %s \"%s\";\n", lc($hwoption), $entry->get_value($hwoption); } # remaining DHCP Options - dhcpoptions ($entry); + my $optindent = " "; + dhcpoptions ($entry, $optindent); printf DATEI "}\n"; }
\ No newline at end of file |