2 # Automatically discover new servers
7 require './servers-lib.pl';
8 our (%config, %text, @cluster_modules);
9 &foreign_require("mailboxes", "mailboxes-lib.pl");
10 &foreign_require("net", "net-lib.pl");
13 if ($ARGV[0] eq "--debug" || $ARGV[0] eq "-debug") {
18 if (!$config{'auto_net'}) {
19 $nets = &get_my_address();
21 elsif (&check_ipaddress($config{'auto_net'})) {
22 $nets = $config{'auto_net'};
25 my ($iface) = grep { $_->{'fullname'} eq $config{'auto_net'} }
26 &net::active_interfaces();
27 $iface && $iface->{'address'} || die $text{'find_eiface'};
28 $nets = $iface->{'address'};
31 foreach my $net (split(/\s+/, $nets)) {
32 $net =~ s/\.\d+$/\.0/;
33 $net =~ /^(\d+\.\d+\.\d+)\.0$/ || die $text{'find_escan'};
34 for(my $i=0; $i<256; $i++) {
35 push(@broad, "$1.$i");
38 my $limit = $config{'scan_time'};
39 my @cluster = grep { $config{'auto_'.$_} } @cluster_modules;
41 print "Checking on ",join(" ", @broad),"\n";
42 print "User = $config{'auto_user'}\n";
43 print "Pass = $config{'auto_pass'}\n";
45 my ($found, $already, $foundme, $addmods) =
46 &find_servers(\@broad, $config{'scan_time'}, !$debug,
48 $config{'auto_pass'}, $config{'auto_type'}, \@cluster,
49 $config{'auto_self'});
51 foreach my $f (@$found) {
52 my $added = $addmods->{$f->{'id'}};
53 print "On $f->{'host'} added $added->[0]->{'host'} ",
54 ($added->[1] ? "OK" : "FAILED")," ",
59 # Send an email for each new system found
60 my @servers = &list_servers();
61 if ($config{'auto_email'}) {
62 foreach my $f (@$found) {
63 &send_auto_email(&text('email_regsubject', $f->{'host'}),
64 &text('email_reg', $f->{'host'}));
68 # See if there were any systems that are registered and on the same net, but
69 # were not found 3 times in a row.
70 if ($config{'auto_remove'}) {
71 my @net = split(/\./, $nets);
72 foreach my $s (@servers) {
73 my $ip = &to_ipaddress($s->{'host'});
74 my @ip = split(/\./, $ip);
75 if ($ip[0] == $net[0] && $ip[1] == $net[1] &&
77 # On scanned net, so should have been found
78 my ($f) = grep { &to_ipaddress($_->{'host'}) eq $ip }
80 if (!$f && $s->{'notfound'}++ >= 3) {
81 # Not found too many times Delete it ..
82 &delete_server($s->{'id'});
83 if ($config{'auto_email'}) {
85 &text('email_unregsubject',
92 # Found, or only not found once
104 my ($subject, $body) = @_;
105 &mailboxes::send_text_mail(&mailboxes::get_from_address(),
106 $config{'auto_email'},
110 $config{'auto_smtp'});