Handle hostnames with upper-case letters
[webmin.git] / backup-config / backup.cgi
1 #!/usr/local/bin/perl
2 # Do an immediate backup
3
4 use strict;
5 use warnings;
6 require './backup-config-lib.pl';
7 our (%in, %text, %config, $module_config_file);
8 &ReadParse();
9
10 # Validate inputs
11 &error_setup($text{'backup_err'});
12 my $dest = &parse_backup_destination("dest", \%in);
13 my ($configfile, $nofiles, $others) = &parse_backup_what("what", \%in);
14 my @mods = split(/\0/, $in{'mods'});
15 @mods || ($nofiles && !$configfile) || &error($text{'backup_emods'});
16
17 # Go for it
18 my ($mode, $user, $pass, $server, $path, $port) = &parse_backup_url($dest);
19 my $err;
20 if ($mode != 4) {
21         # Save somewhere, and tell the user
22         &ui_print_header(undef, $text{'backup_title'}, "");
23         print &text('backup_doing', &nice_dest($dest, 1)),"<p>\n";
24         my $size;
25         my @files;
26         $err = &execute_backup(\@mods, $dest, \$size, \@files,
27                                $configfile, $nofiles,
28                                [ split(/\t+/, $others) ]);
29         if ($err) {
30                 print &text('backup_failed', $err),"<p>\n";
31                 }
32         else {
33                 print &text('backup_done', &nice_size($size),
34                             scalar(@files)),"<p>\n";
35                 }
36         &ui_print_footer("", $text{'index_return2'});
37         }
38 else {
39         # Output file in browser
40         my $temp = &transname();
41         my $size;
42         $err = &execute_backup(\@mods, $temp, \$size, undef,
43                                $configfile, $nofiles);
44         if ($err) {
45                 &unlink_file($temp);
46                 &error($err);
47                 }
48         print "Content-type: application/octet-stream\n\n";
49         my $buf;
50         open(TEMP, $temp);
51         while(read(TEMP, $buf, 1024)) {
52                 print $buf;
53                 }
54         close(TEMP);
55         &unlink_file($temp);
56         }
57
58 if (!$err) {
59         # Save config
60         $config{'dest'} = $dest;
61         $config{'mods'} = join(" ", @mods);
62         $config{'configfile'} = $in{'configfile'};
63         $config{'nofiles'} = $in{'nofiles'};
64         &lock_file($module_config_file);
65         &save_module_config();
66         &unlock_file($module_config_file);
67         &webmin_log("backup", undef, $dest, { 'mods' => \@mods });
68         }
69