/[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

Diff of /lib/PXElator/server.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 75 by dpavlin, Fri Jul 31 13:22:45 2009 UTC revision 288 by dpavlin, Tue Aug 25 17:09:52 2009 UTC
# Line 3  package server; Line 3  package server;
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
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    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 );  our ( $ip_from, $ip_to ) = ( 10, 100 );
21    
22  our $base_dir = '/home/dpavlin/llin/pxelator';  our $domain_name = 'pxelator.lan';
23    
24    our $base_dir = '/srv/pxelator';
25    
26  use config;  our $conf = "$base_dir/conf/$ip";
27    mkdir $conf unless -e $conf;
28    
29  our $debug;  use Module::Refresh qw//;
30  sub debug { $debug = config::shared('debug', @_) || 0 }  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";  warn "loaded";
61    
62    1;

Legend:
Removed from v.75  
changed lines
  Added in v.288

  ViewVC Help
Powered by ViewVC 1.1.26