Handle hostnames with upper-case letters
[webmin.git] / postgresql / backup.cgi.bak
1 #!/usr/local/bin/perl
2 # backup.cgi
3 # Backup a database to a local file
4
5 require './postgresql-lib.pl' ;
6
7 &ReadParse ( ) ;
8
9 &error_setup ( $text{'backup_err'} ) ;
10
11 $access{'backup'} || &error($text{'backup_ecannot'});
12 &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
13 $in{'format'} =~ /^[a-z]$/ || &redirect ( "" );
14 $in{'path'} =~ /^\S+$/ || &error(&text('backup_pe3', $in{'path'})) ;
15 if ( -e $in{'path'} ) {
16         &error ( &text ( 'backup_pe2', $in{'path'} ) ) ;
17         }
18
19 $db_find_f = 0 ;
20
21 if ( $in{'db'} ) {
22
23     foreach ( &list_databases() ) {
24
25         if ( $_ eq $in{'db'} ) { $db_find_f = 1 ; }
26     }
27 }
28
29 if ( $db_find_f == 0 ) { &error ( &text ( 'backup_edb' ) ) ; }
30
31 $bkup_command = $config{'dump_cmd'}.
32                 ($config{'login'} ? " -U $config{'login'}" : "").
33                 ($config{'host'} ? " -h $config{'host'}" : "").
34                 ($in{'format'} eq 'p' ? "" : " -b").
35                 " -F$in{'format'} -f $in{'path'} $in{'db'}" ;
36
37 if ( $config{'sameunix'} && defined(getpwnam($config{'login'})) ) {
38     $bkup_command =~ s/"/\\"/g ;
39     $bkup_command =  "su $config{'login'} -c ".quotemeta($bkup_command);
40 }
41
42 $temp = &tempname();
43 open(TEMP, ">$temp");
44 print TEMP "$config{'pass'}\n";
45 close(TEMP);
46 $out = &backquote_logged("$bkup_command 2>&1 <$temp");
47 unlink($temp);
48
49 if ( $? == 0 ) {
50     &redirect ("edit_dbase.cgi?db=$in{'db'}") ;
51 } else {
52      &error ( &text ( 'backup_exe', $bkup_command )."<pre>$out</pre>" ) ;
53 }