Handle hostnames with upper-case letters
[webmin.git] / fsdump / newtape.pl
1 #!/usr/local/bin/perl
2 # newtape.pl
3 # Called when a new tape is needed for some backup, to update its status
4 # file. Only exits when the user has actually clicked the 'new tape' button
5
6 $no_acl_check++;
7 delete($ENV{'SCRIPT_NAME'});    # force use of $0 to determine module
8 delete($ENV{'FOREIGN_MODULE_NAME'});
9 require './fsdump-lib.pl';
10 $dump = &get_dump($ARGV[0]);
11 $dump->{'id'} || die "Dump $ARGV[0] does not exist!";
12
13 # Find the status file
14 opendir(DIR, $module_config_directory);
15 foreach $f (readdir(DIR)) {
16         if ($f =~ /^(\d+)\.(\d+)\.status$/ && $1 eq $dump->{'id'}) {
17                 # Got it!
18                 $sfile = "$module_config_directory/$f";
19                 }
20         }
21 closedir(DIR);
22 $sfile || die "Failed to find status file for dump $ARGV[0]";
23
24 # Update it to indicate that a new tape is needed
25 &read_file($sfile, \%status);
26 $status{'status'} = 'tape';
27 $status{'tapepid'} = $$;
28 $status{'tapecount'}++;
29 &write_file($sfile, \%status);
30
31 # Email the backup address
32 if ($dump->{'email'} && &foreign_check("mailboxes")) {
33         &foreign_require("mailboxes", "mailboxes-lib.pl");
34         $host = &get_system_hostname();
35         $c = $status{'tapecount'};
36         @dirs = &dump_directories($dump);
37         $dirs = join(", ", @dirs);
38         $subject = &text('newtape_subject', $c, $dirs, $host);
39         $data = &text('newtape_body', $c, $dirs, $host)."\n";
40         &mailboxes::send_text_mail(&mailboxes::get_from_address(),
41                                    $dump->{'email'},
42                                    undef,
43                                    $subject,
44                                    $data,
45                                    $config{'smtp_server'});
46         }
47
48 # Wait until signalled with a HUP
49 $SIG{'HUP'} = \&got_hup;
50 while(1) {
51         sleep(1000000);
52         }
53 exit(2);
54
55 sub got_hup
56 {
57 $status{'status'} = 'running';
58 &write_file($sfile, \%status);
59 exit(0);
60 }
61