Handle hostnames with upper-case letters
[webmin.git] / bacula-backup / backup.cgi
1 #!/usr/local/bin/perl
2 # Actually execute a backup
3
4 require './bacula-backup-lib.pl';
5 &ui_print_unbuffered_header(undef,  $text{'backup_title'}, "");
6 &ReadParse();
7
8 print "<b>",&text('backup_run', "<tt>$in{'job'}</tt>"),"</b>\n";
9 print "<pre>";
10 $h = &open_console();
11
12 # Clear messages
13 &console_cmd($h, "messages");
14
15 # Select the job to run
16 &sysprint($h->{'infh'}, "run\n");
17 &wait_for($h->{'outfh'}, 'run\\n');
18 $rv = &wait_for($h->{'outfh'}, 'Select Job.*:');
19 print $wait_for_input;
20 if ($rv == 0 && $wait_for_input =~ /(\d+):\s+\Q$in{'job'}\E/) {
21         &sysprint($h->{'infh'}, "$1\n");
22         }
23 else {
24         &job_error($text{'backup_ejob'});
25         }
26
27 # Say that it is OK
28 $rv = &wait_for($h->{'outfh'}, 'OK to run.*:');
29 print $wait_for_input;
30 if ($rv == 0) {
31         &sysprint($h->{'infh'}, "yes\n");
32         }
33 else {
34         &job_error($text{'backup_eok'});
35         }
36
37 print "</pre>";
38
39 if ($in{'wait'}) {
40         # Wait till we have a status
41         print "</pre>\n";
42         print "<b>",$text{'backup_running'},"</b>\n";
43         print "<pre>";
44         while(1) {
45                 $out = &console_cmd($h, "messages");
46                 if ($out !~ /You\s+have\s+no\s+messages/i) {
47                         print $out;
48                         }
49                 if ($out =~ /Termination:\s+(.*)/) {
50                         $status = $1;
51                         last;
52                         }
53                 sleep(1);
54                 }
55         print "</pre>\n";
56         if ($status =~ /Backup\s+OK/i && $status !~ /warning/i) {
57                 print "<b>",$text{'backup_done'},"</b><p>\n";
58                 }
59         else {
60                 print "<b>",$text{'backup_failed'},"</b><p>\n";
61                 }
62         }
63 else {
64         # Let it fly
65         print "<b>",$text{'backup_running2'},"</b><p>\n";
66         }
67
68 &close_console($h);
69 &webmin_log("backup", $in{'job'});
70
71 &ui_print_footer("backup_form.cgi", $text{'backup_return'});
72
73 sub job_error
74 {
75 &close_console($h);
76 print "</pre>\n";
77 print "<b>",@_,"</b><p>\n";
78 &ui_print_footer("backup_form.cgi", $text{'backup_return'});
79 exit;
80 }
81