--- lib/PXElator/client.pm 2009/08/06 21:31:10 168 +++ lib/PXElator/client.pm 2009/08/10 17:30:01 194 @@ -41,11 +41,13 @@ } sub mac { - my $ip = shift; + my ( $ip, $op ) = @_; + $op ||= 'html'; my $mac = client::conf( $ip, 'mac' ); + return '' unless $mac; $mac =~ s{(..)}{$1:}g; $mac =~ s{:$}{}; - $mac = qq|$mac| if (caller(1))[3] =~ m{^httpd}; + $mac = qq|$mac| if (caller(1))[3] =~ m{^httpd} && $op ne 'clean'; return uc($mac); } @@ -69,4 +71,30 @@ } +sub ip_from_mac { + my $mac = shift; + + $mac = lc $mac; + $mac =~ s{:}{}g; + + my $mac_path = "$server::conf/mac/$mac"; + return unless -e $mac_path; + + my $ip; + + if ( -f $mac_path ) { + $ip = read_file $mac_path; + unlink $mac_path; + symlink "$server::conf/ip/$ip", $mac_path; + warn "I: upgrade to mac symlink $mac_path\n"; + } elsif ( -l $mac_path ) { + $ip = readlink $mac_path; + $ip =~ s{^.+/([^/]+)$}{$1}; + } else { + die "$mac_path not file or symlink"; + } + + return $ip; +} + 1;