3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
|
use Module::Refresh; |
|
6 |
|
|
7 |
our $ip = '172.16.10.1'; |
our $ip = '172.16.10.1'; |
8 |
our $netmask = '255.255.255.0'; |
our $netmask = '255.255.255.0'; |
9 |
|
our $bcast = '172.16.10.255'; |
10 |
|
|
11 |
|
if ( my $dev = $ENV{DEV} ) { |
12 |
|
my $ifconfig = `ifconfig $dev`; |
13 |
|
( $ip, $bcast, $netmask ) = ( $1, $2, $3 ) if $ifconfig =~ m{inet addr:(\S+)\s+Bcast:(\S+)\s+Mask:(\S+)}s; |
14 |
|
warn "DEV $dev $ip $bcast $netmask"; |
15 |
|
} |
16 |
|
|
17 |
our ( $ip_from, $ip_to ) = ( 10, 100 ); |
our ( $ip_from, $ip_to ) = ( 10, 100 ); |
18 |
|
|
19 |
our $base_dir = '/home/dpavlin/llin/pxelator'; |
our $domain_name = 'pxelator.lan'; |
20 |
|
|
21 |
|
our $base_dir = '/srv/pxelator'; |
22 |
|
|
23 |
|
our $conf = "$base_dir/conf/$ip"; |
24 |
|
mkdir $conf unless -e $conf; |
25 |
|
|
26 |
|
use Module::Refresh qw//; |
27 |
|
sub refresh { Module::Refresh->refresh }; |
28 |
|
|
|
use config; |
|
29 |
|
|
30 |
our $debug; |
mkdir $_ foreach grep { ! -d $_ } map { "$conf/$_" } ( 'ip', 'mac' ); |
|
sub debug { $debug = config::shared('debug', @_) || 0 } |
|
31 |
|
|
32 |
my $timestamp_interval = 3; |
use File::Slurp; |
33 |
my $stderr_tell = 0; |
sub shared { |
34 |
|
my ($name, $value) = @_; |
35 |
$SIG{ALRM} = sub { |
|
36 |
if ( tell(STDERR) != $stderr_tell ) { |
my $path ="$conf/$name"; |
37 |
warn "\nTIMESTAMP: " . localtime() . "\n\n"; |
if ( defined $value ) { |
38 |
$stderr_tell = tell(STDERR); |
write_file $path, $value; |
39 |
Module::Refresh->refresh; |
warn "update $path = $value"; |
40 |
} |
} else { |
41 |
alarm $timestamp_interval; |
$value = read_file $path if -e $path; |
42 |
}; |
} |
43 |
alarm $timestamp_interval; |
return $value; |
44 |
|
} |
45 |
|
|
46 |
|
sub debug { shared('debug', @_) || 0 } |
47 |
|
|
48 |
warn "loaded"; |
warn "loaded"; |
49 |
|
|
50 |
|
1; |