Handle hostnames with upper-case letters
[webmin.git] / ipfw / cluster_add.cgi
1 #!/usr/local/bin/perl
2 # Add or update a server or group from the webmin servers module
3
4 require './ipfw-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, "ipfw");
40         if ($add_error_msg) {
41                 print "$add_error_msg<p>\n";
42                 next;
43                 }
44         if (!$firewall) {
45                 print &text('add_echeck', $s),"<p>\n";
46                 next;
47                 }
48         &remote_foreign_require($s, "ipfw", "ipfw-lib.pl");
49
50         local $ok = &remote_foreign_call($s, "ipfw",
51                                          "foreign_installed", "ipfw");
52         if (!$ok) {
53                 print &text('add_eok'),"<p>\n";
54                 next;
55                 }
56
57         $iconfig = &remote_foreign_config($s, "ipfw");
58         $live = &remote_foreign_call($s, "ipfw",
59                                    "get_config", "$iconfig->{'ipfw'} show |");
60         print &text('add_ok', $s->{'host'}, scalar(@$live)),"<p>\n";
61         &add_cluster_server($s);
62         }
63 &remote_finished();
64 if ($in{'add'}) {
65         &webmin_log("add", "host", $add[0]->{'host'});
66         }
67 else {
68         &webmin_log("add", "group", $in{'group'});
69         }
70
71 &ui_print_footer("cluster.cgi", $text{'cluster_return'});
72