From: Andres S. <di...@us...> - 2005-02-16 19:34:14
|
Update of /cvsroot/tuxaator/tuxaator/Plugins/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19639/Plugins/Core Modified Files: Plugin.pm Log Message: implemented the extra_hosts_files configuration parameter Index: Plugin.pm =================================================================== RCS file: /cvsroot/tuxaator/tuxaator/Plugins/Core/Plugin.pm,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Plugin.pm 11 Feb 2005 20:17:05 -0000 1.5 --- Plugin.pm 16 Feb 2005 19:33:58 -0000 1.6 *************** *** 83,87 **** my($self,$event) = @_; my $basedir = $self->{'Core'}->{'basedir'}; ! my %users = &load_hosts($basedir); $self->{'Core'}->{'users'} = \%users; } --- 83,87 ---- my($self,$event) = @_; my $basedir = $self->{'Core'}->{'basedir'}; ! my %users = &load_hosts($basedir, $self->{'Core'}->{'config'}); $self->{'Core'}->{'users'} = \%users; } *************** *** 159,163 **** my $event = pop @_; my $basedir = $self->{'core'}->{'basedir'}; ! my %users = &load_hosts($basedir); print "rehashing hosts\n"; $self->{'core'}->{'users'} = \%users; --- 159,163 ---- my $event = pop @_; my $basedir = $self->{'core'}->{'basedir'}; ! my %users = &load_hosts($basedir, $self->{'core'}->{'config'}); print "rehashing hosts\n"; $self->{'core'}->{'users'} = \%users; *************** *** 171,214 **** sub load_hosts { my $basedir = shift; my %users; ! my $hostsfile = "$basedir/config/hosts"; ! my ($key,$value); ! print STDERR "DEBUG: loading $hostsfile\n"; ! open HOSTS, "<" . $hostsfile or die "$hostsfile: cannot open: $!\n"; ! ! while (<HOSTS>) { ! chomp; ! next if m/^#/ or m/^\s*$/; ! if (m/^\s*(.+?)\s*([|=])\s*(\d+?)\s*$/) { ! my ($hostmask, $delim, $level) = ($1, $2, $3); ! if ($delim eq '=') # glob ? { ! $hostmask =~ s/([^\w*])/\\$1/g; ! $hostmask =~ s/\*/.*/g; } ! $users{$hostmask} = $level; ! } ! else ! { ! warn "$hostsfile:$.: unable to parse host file line\n" ! } ! }; ! close HOSTS; ! # open HOSTS,"</home/kaups/.tux" or die "cannot open hosts file\n"; ! # while(<HOSTS>) ! # { ! # unless (/^#/) ! # { ! # my ($hostmask,$level) = $_ =~ /^\s*(.+?)\s*\|\s*(.+?)$/; ! # if ($hostmask && $level) ! # { ! # $users{$hostmask} = 2; ! # }; ! # }; ! # }; ! # close HOSTS; return %users; } --- 171,208 ---- sub load_hosts { + my ($basedir, $config) = @_; + my $extra_hosts_files; + $extra_hosts_files = $config->{'extra_hosts_files'} if $config; my $basedir = shift; my %users; ! for my $hostsfile ("$basedir/config/hosts", ! split /\s*,\s*/, $extra_hosts_files) { ! print STDERR "DEBUG: loading $hostsfile\n"; ! unless (open HOSTS, $hostsfile) { ! warn "$hostsfile: cannot open: $!\n"; ! next; ! } ! while (<HOSTS>) { ! chomp; ! next if m/^#/ or m/^\s*$/; ! if (m/^\s*(.+?)\s*([|=])\s*(\d+?)\s*$/) { ! my ($hostmask, $delim, $level) = ($1, $2, $3); ! if ($delim eq '=') # glob ? ! { ! $hostmask =~ s/([^\w*])/\\$1/g; ! $hostmask =~ s/\*/.*/g; ! } ! $users{$hostmask} = $level; } ! else ! { ! warn "$hostsfile:$.: unable to parse host file line\n" ! } ! }; ! close HOSTS; ! } return %users; } |