2 |
|
|
3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
|
use File::Slurp; |
|
5 |
|
|
6 |
our $ip = '172.16.10.1'; |
our $base_dir = '/srv/pxelator'; |
7 |
our $netmask = '255.255.255.0'; |
|
8 |
|
use ties; |
9 |
|
|
10 |
our ( $ip_from, $ip_to ) = ( 10, 100 ); |
tie our $ip, 'ties', 'server_ip' => '172.16.10.1'; |
11 |
|
tie our $netmask, 'ties', 'netmask' => '255.255.255.0'; |
12 |
|
tie our $bcast, 'ties', 'bcast' => '172.16.10.254'; |
13 |
|
tie our $ip_from, 'ties', 'ip_from' => 10; |
14 |
|
tie our $ip_to, 'ties', 'ip_to' => 100; |
15 |
|
tie our $domain, 'ties', 'domain' => 'pxelator.lan'; |
16 |
|
tie our $new_clients, 'ties', 'new_clients' => $ip_to - $ip_from; |
17 |
|
|
18 |
|
warn "DEV $ip $bcast $netmask"; |
19 |
|
|
20 |
|
our $conf = "$base_dir/conf"; |
21 |
|
mkdir $conf unless -e $conf; |
22 |
|
|
23 |
|
sub conf { |
24 |
|
warn "## conf $conf"; |
25 |
|
$conf; |
26 |
|
} |
27 |
|
|
28 |
our $base_dir = '/home/dpavlin/llin/pxelator'; |
use Module::Refresh qw//; |
29 |
|
sub refresh { |
30 |
|
Module::Refresh->refresh; |
31 |
|
my $from = (caller(1))[3]; |
32 |
|
$from =~ s{^(\w+)::.+$}{$1}; |
33 |
|
my $eval = '$' . $from . '::debug = server::debug();'; |
34 |
|
warn "refresh $eval\n"; |
35 |
|
eval $eval; |
36 |
|
warn $@ if $@; |
37 |
|
}; |
38 |
|
|
39 |
our $debug = 0; |
mkdir $_ foreach grep { ! -d $_ } map { "$conf/$_" } ( 'ip', 'mac' ); |
40 |
sub debug { |
|
41 |
my $new = shift; |
use File::Slurp; |
42 |
my $path ="$base_dir/conf/debug"; |
sub shared { |
43 |
if ( defined $new ) { |
my ($name, $value) = @_; |
44 |
write_file $path, $debug = $new; |
|
45 |
|
my $path ="$conf/$name"; |
46 |
|
if ( defined $value ) { |
47 |
|
write_file $path, $value; |
48 |
|
warn "update $path = $value"; |
49 |
} else { |
} else { |
50 |
$debug = read_file $path if -e $path; |
$value = read_file $path if -e $path; |
51 |
} |
} |
52 |
return $debug; |
return $value; |
53 |
} |
} |
54 |
|
|
55 |
|
sub conf_default { shared($_[0]) || $_[1] } |
56 |
|
|
57 |
|
sub debug { shared('debug', @_) || 0 } |
58 |
|
|
59 |
warn "loaded"; |
warn "loaded"; |
60 |
|
|
61 |
|
1; |