implement client::conf to fetch/set (with default) client configuration
[pxelator] / lib / PXElator / dhcpd.pm
index 2934aaf..83f1cd3 100644 (file)
@@ -40,7 +40,7 @@ my $addr = $server::ip_from;
 sub client_ip {
        my ( $mac ) = @_;
 
-       my $conf = "$server::base_dir/conf/$server::ip";
+       my $conf = $server::conf;
        mkdir $conf unless -e $conf;
 
        if ( -e "$conf/mac/$mac" ) {
@@ -54,6 +54,7 @@ sub client_ip {
        my $prefix = $server::ip;
        $prefix =~ s{\.\d+$}{.};
        my $ip = $prefix . $addr;
+
        while ( -e "$conf/ip/$ip" || $p->ping( $ip ) ) {
                $ip = $prefix . $addr++;
                die "all addresses allocated!" if $addr == $server::ip_to;
@@ -61,11 +62,14 @@ sub client_ip {
 
        write_file "$conf/mac/$mac", $ip;
 
-       if ( -l "$conf/ip/$ip" && readlink "$conf/ip/$ip" ne "$conf/mac/$mac" ) {
-               unlink     "$conf/ip/$ip";
-               warn "$mac IP changed from ", readlink "$conf/ip/$ip", " to $ip";
+       my $ip_path = "$conf/ip/$ip";
+       mkdir $ip_path unless -e $ip_path;
+
+       if ( -l "$ip_path/mac" && readlink "$ip_path/mac" ne "$conf/mac/$mac" ) {
+               warn "$mac IP changed from ", readlink "$ip_path/mac", " to $ip";
+               unlink "$ip_path/mac";
        };
-       symlink    "$conf/mac/$mac", "$conf/ip/$ip";
+       symlink "$conf/mac/$mac", "$ip_path/mac";
 
        print "$mac NEW $ip\n";