11 sub mac_path { $server::conf . '/mac/' . $_[0] }
12 sub ip_path { $server::conf . '/ip/' . join('/', @_) }
17 my ( $default, $value );
20 } elsif ( $#_ == 1 && $_[0] eq 'default' ) {
24 my $path = ip_path $ip;
25 mkdir $path unless -d $path;
28 if ( defined $value ) {
29 write_file $path, $value;
30 warn "update $path = $value";
31 } elsif ( ! -e $path && defined $default ) {
32 write_file $path, $default;
33 warn "default $path = $default";
35 } elsif ( -e $path ) {
37 $value = readlink $path;
38 $value =~ s{.*/([^/]+)$}{$1};
40 $value = read_file $path;
49 my $mac = client::conf( $ip, 'mac' );
50 return '' unless $mac;
51 $mac =~ s{(..)}{$1:}g;
53 $mac = qq|<tt>$mac</tt>| if (caller(1))[3] =~ m{^httpd} && $op ne 'clean';
60 my $p = Net::Ping->new;
62 my $prefix = $server::ip;
63 $prefix =~ s{\.\d+$}{.};
64 my $addr = $server::ip_from || die;
65 my $ip = $prefix . $addr;
67 while ( -e ip_path($ip) || $p->ping( $ip, 0.7 ) ) {
68 $ip = $prefix . $addr++;
69 die "all addresses allocated!" if $addr == $server::ip_to;
77 symlink ip_path($ip), mac_path($mac);
78 write_file ip_path($ip,'mac'), $mac;
90 my $mac_path = mac_path $mac;
91 return unless -e $mac_path;
96 $ip = read_file $mac_path;
98 symlink ip_path($ip), $mac_path;
99 warn "I: upgrade to mac symlink $mac_path\n";
100 } elsif ( -l $mac_path ) {
101 $ip = readlink $mac_path;
102 $ip =~ s{^.+/([^/]+)$}{$1};
104 die "$mac_path not file or symlink";
112 return read_file ip_path($ip, 'mac');
116 my ($old, $new) = @_;
117 my $mac = mac_from_ip($old);
118 rename ip_path($old), ip_path($new);
119 unlink mac_path($mac);
120 symlink ip_path($new), mac_path($mac);