--- lib/PXElator/client.pm 2009/08/06 15:15:53 156 +++ lib/PXElator/client.pm 2009/08/10 00:07:38 190 @@ -6,6 +6,7 @@ use server; use File::Slurp; +use Net::Ping; sub conf { my $ip = shift; @@ -28,10 +29,46 @@ write_file $path, $default; warn "default $path = $default"; $value = $default; - } else { - $value = read_file $path if -e $path; + } elsif ( -e $path ) { + if ( -l $path ) { + $value = readlink $path; + $value =~ s{.*/([^/]+)$}{$1}; + } else { + $value = read_file $path; + } } return $value; } +sub mac { + 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} && $op ne 'clean'; + return uc($mac); +} + +sub next_ip { + + my $p = Net::Ping->new; + + my $prefix = $server::ip; + $prefix =~ s{\.\d+$}{.}; + my $addr = $server::ip_from || die; + my $ip = $prefix . $addr; + + while ( -e "$server::conf/ip/$ip" || $p->ping( $ip, 0.7 ) ) { + $ip = $prefix . $addr++; + die "all addresses allocated!" if $addr == $server::ip_to; + warn "skip $ip\n"; + } + + warn "next_ip $ip\n"; + return $ip; + +} + 1;