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