Handle hostnames with upper-case letters
[webmin.git] / ipfilter / cluster_add.cgi
1 #!/usr/local/bin/perl
2 # Add or update a server or group from the webmin servers module
3
4 require './ipfilter-lib.pl';
5 &ReadParse();
6 &foreign_require("servers", "servers-lib.pl");
7 @allservers = grep { $_->{'user'} } &servers::list_servers();
8
9 if ($in{'add'}) {
10         # Add a single host
11         @add = grep { $_->{'id'} eq $in{'server'} } @allservers;
12         &error_setup($text{'add_err'});
13         $msg = &text('add_msg', &server_name($add[0]));
14         }
15 else {
16         # Add all from a group
17         ($group) = grep { $_->{'name'} eq $in{'group'} }
18                         &servers::list_all_groups(\@allservers);
19         foreach $m (@{$group->{'members'}}) {
20                 push(@add, grep { $_->{'host'} eq $m } @allservers);
21                 }
22         &error_setup($text{'add_gerr'});
23         $msg = &text('add_gmsg', $in{'group'});
24         }
25
26 &ui_print_header(undef, $text{'add_title'}, "");
27 print "<b>$msg</b><p>\n";
28
29 # Setup error handler for down hosts
30 sub add_error
31 {
32 $add_error_msg = join("", @_);
33 }
34 &remote_error_setup(\&add_error);
35
36 # Make sure each host is set up for firewalling
37 foreach $s (@add) {
38         $add_error_msg = undef;
39         local $firewall = &remote_foreign_check($s, "ipfilter");
40         if ($add_error_msg) {
41                 print "$add_error_msg<p>\n";
42                 next;
43                 }
44         if (!$firewall) {
45                 print &text('add_echeck', $s->{'host'}),"<p>\n";
46                 next;
47                 }
48         &remote_foreign_require($s, "ipfilter", "ipfilter-lib.pl");
49
50         local $missing = &remote_foreign_call($s, "ipfilter",
51                                               "missing_firewall_commands");
52         if ($missing) {
53                 print &text('add_emissing', "<tt>$missing</tt>"),"<p>\n";
54                 next;
55                 }
56
57         $live = &remote_foreign_call($s, "ipfilter", "get_live_config");
58         print &text('add_ok', $s->{'host'}, scalar(@$live)),"<p>\n";
59         &add_cluster_server($s);
60         }
61 &remote_finished();
62 if ($in{'add'}) {
63         &webmin_log("add", "host", $add[0]->{'host'});
64         }
65 else {
66         &webmin_log("add", "group", $in{'group'});
67         }
68
69 &ui_print_footer("cluster.cgi", $text{'cluster_return'});
70