report error without nmap output
[pxelator] / lib / PXElator / server.pm
index 62928e1..951a48a 100644 (file)
@@ -18,6 +18,15 @@ tie our $ip_to,   'ties', 'ip_to'     => 100;
 tie our $domain,  'ties', 'domain'    => 'pxelator.lan';
 tie our $new_clients, 'ties', 'new_clients' => $ip_to - $ip_from;
 
+if ( my $dev = $ENV{DEV} ) {
+       my $ifconfig = `ifconfig $dev`;
+       die "can't ifconfig $dev" unless $ifconfig;
+       die "device $dev not up: ifconfig $dev\n$ifconfig" unless $ifconfig =~ m/UP/;
+       $ip      = $1 if $ifconfig =~ m/inet addr:(\S+)/s;
+       $netmask = $1 if $ifconfig =~ m/Mask:(\S+)/s;
+       $bcast   = $1 if $ifconfig =~ m/Bcast:(\S+)/s;
+}
+
 warn "DEV $ip $bcast $netmask";
 
 our $conf = "$base_dir/conf";
@@ -66,7 +75,10 @@ sub as_hash_for {
        map { $server->{ $_ } = eval '$server::' . $_ } ( 'ip', 'netmask', 'bcast', 'domain', 'ip_from', 'ip_to', 'new_clients' );
 
        my $server_path = "$server::conf/ip/$ip/server.yaml";
-       $server =  YAML::LoadFile $server_path if -e $server_path;
+       if ( -e $server_path ) {
+               my $overlay = YAML::LoadFile $server_path;
+               $server->{$_} = $overlay->{$_} foreach keys %$overlay;
+       }
 
        return $server;
 }