/[pxelator]/lib/PXElator/server.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/PXElator/server.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 288 - (show annotations)
Tue Aug 25 17:09:52 2009 UTC (14 years, 7 months ago) by dpavlin
File size: 1249 byte(s)
server::setup_from_dev will take configuration from existing device

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

  ViewVC Help
Powered by ViewVC 1.1.26