#!/var/local/bin/perl # See the COPYING.txt file in this directory for Copyright information # and usage restrictions # Build a FreeRADIUS "users" file based on information in the inventory # database. require DB_File; use Fcntl; require '/var/local/etc/invdb5/invstuff.pl'; &initSNinfo; # learn subnet information (list of subnets, masks, VLAN IDs, # routers, DNS servers, NTP servers, etc) tie(%INVDB, DB_File, $INVDBFILE, O_RDONLY, 0); while (($key, $entry)=each %INVDB) { &ParseInvEntry(*array,$entry); if (defined($array{hostname})) { next if ($array{citType} =~ /INACTIVE/); foreach (split(/\|/, $array{interface})) { ($macaddr,$ipaddr,$ipv6addr,$remainder) = split(/,/, $_, 4); if ($macaddr) { next if ($macaddr!~/[0-9a-fA-F:]{11,17}/); $RADmac = &enet_to_rad($macaddr); print "$RADmac\tAuth-Type := Local, User-Password == \"$RADmac\"\n"; if ($ipaddr) { $SNname = &getSNname($ipaddr); $SNvlan = &getSNvlan($SNname); if (($SNvlan) && ($SNdpv{$SNname})) { print "\tTunnel-Type = VLAN,\n", "\tTunnel-Medium-type = IEEE-802,\n", "\tTunnel-Private-group-ID = $SNvlan,\n"; } } print "\tFall-Through = No\n#\n" } } } } untie(%INVDB); sub enet_to_rad($) { my($enet_colon) = shift; my(@hexBytes,$byte,@decimalBytes); @hexBytes = split(/:/,$enet_colon); foreach $byte (@hexBytes) { push(@decimalBytes,hex($byte)); } return(sprintf("%02x%02x%02x%02x%02x%02x", @decimalBytes)); }