Handle hostnames with upper-case letters
[webmin.git] / usermin / export_mod.cgi
1 #!/usr/local/bin/perl
2 # Create and output a wbm.gz file of selected modules
3
4 require './usermin-lib.pl';
5 &ReadParse();
6 &error_setup($text{'export_err'});
7 @mods = split(/\0/, $in{'mod'});
8 @mods || &error($text{'delete_enone'});
9
10 # Make sure we have the needed commands
11 &has_command("tar") || &error(&text('export_ecmd', "<tt>tar</tt>"));
12 &has_command("gzip") || &error(&twebmin::ext('export_ecmd', "<tt>gzip</tt>"));
13 $in{'to'} == 0 || $in{'file'} =~ /^\// || &error($text{'export_efile'});
14
15 # Make the tar.gz file
16 $temp = $in{'to'} ? $in{'file'} : &transname();
17 local %miniserv;
18 &get_usermin_miniserv_config(\%miniserv);
19 chdir($miniserv{'root'});
20 $cmd = "tar chf -";
21 foreach $m (@mods) {
22         $cmd .= " $m";
23         }
24 $cmd .= " | gzip -c >".quotemeta($temp);
25 $out = &backquote_logged("($cmd) 2>&1 </dev/null");
26 $? && &error("<pre>$out</pre>");
27
28 if ($in{'to'} == 0) {
29         # Output the file
30         print "Content-type: application/octet-stream\n\n";
31         open(TEMP, $temp);
32         while(<TEMP>) {
33                 print $_;
34                 }
35         close(TEMP);
36         unlink($temp);
37         }
38 else {
39         # Tell the user
40         &ui_print_header(undef, $text{'export_title'}, "");
41
42         print &text('export_done', "<tt>$in{'file'}</tt>"),"<p>\n";
43
44         &ui_print_footer("/$module_name/edit_mods.cgi", $text{'mods_return'},
45                          "", $text{'index_return'});
46         }
47
48