Handle hostnames with upper-case letters
[webmin.git] / cluster-copy / exec.cgi
1 #!/usr/local/bin/perl
2 # exec.cgi
3 # Run the cron job on all configured servers
4
5 require './cluster-copy-lib.pl';
6 &ReadParse();
7 &ui_print_unbuffered_header(undef, $text{'exec_title'}, "");
8
9 # Run on all servers and show output
10 $copy = &get_copy($in{'id'});
11 @files = split(/\t+/, $copy->{'files'});
12 $under = $copy->{'dest'} eq "/" ? "" :
13                 &text('exec_under', "<tt>$copy->{'dest'}</tt>");
14 if (@files > 3) {
15         print &text('exec_files1', scalar(@files), $under),"<p>\n";
16         }
17 else {
18         print &text('exec_files2',
19                     join(", ", map { "<tt>$_</tt>" } @files), $under),"<p>\n";
20         }
21 @run = &run_cluster_job($copy, \&callback);
22 if (!@run) {
23         print "$text{'exec_nohosts'}<p>\n";
24         }
25
26 &webmin_log("exec", "copy", undef, $copy);
27
28 &ui_print_footer("edit.cgi?id=$in{'id'}", $text{'edit_return'},
29         "", $text{'index_return'});
30
31 # callback(error, &server, message, dirs, command-output, before-output)
32 sub callback
33 {
34 local $d = $_[1]->{'desc'} || $_[1]->{'host'};
35 if (!$_[0]) {
36         # Failed - show error
37         print "<b>",&text('exec_failed', $d, $_[2]),"</b><p>\n";
38         }
39 else {
40         if ($_[6]) {
41                 # Show before command output
42                 print "<b>",&text('exec_before', $d),"</b><br>\n";
43                 print "<tt>",join("<br>", &mailboxes::wrap_lines($_[6], 80)),
44                       "</tt><p>\n";
45                 }
46         if (@{$_[4]}) {
47                 # Show created directories
48                 print "<b>",&text('exec_made', $d),"</b><br><ul>\n";
49                 foreach $f (@{$_[4]}) {
50                         print "<tt>$f</tt><br>\n";
51                         }
52                 print "</ul><p>\n";
53                 }
54         if (!@{$_[2]}) {
55                 # Nothing copied
56                 print "<b>",&text('exec_nothing', $d),"</b><p>\n";
57                 }
58         else {
59                 # Show copied files
60                 print "<b>",&text('exec_success', $d),"</b><br><ul>\n";
61                 foreach $f (@{$_[2]}) {
62                         print "<tt>$f</tt><br>\n";
63                         }
64                 print "</ul><p>\n";
65                 }
66         if (@{$_[3]}) {
67                 # Show failed files
68                 print "<b>",&text('exec_not', $d),"</b><br><ul>\n";
69                 foreach $f (@{$_[3]}) {
70                         print "<tt>$f->[0]</tt> : $f->[1]<br>\n";
71                         }
72                 print "</ul><p>\n";
73                 }
74         if ($_[5]) {
75                 # Show after command output
76                 print "<b>",&text('exec_cmd', $d),"</b><br>\n";
77                 print "<tt>",join("<br>", &mailboxes::wrap_lines($_[5], 80)),
78                       "</tt><p>\n";
79                 }
80         }
81 }
82