Handle hostnames with upper-case letters
[webmin.git] / postgresql / restore.cgi
1 #!/usr/local/bin/perl
2 # restore.cgi
3 # Restore a database from a local file, or from an uploaded file
4
5 require './postgresql-lib.pl' ;
6 &ReadParseMime();
7
8 &error_setup ( $text{'restore_err'} ) ;
9 $access{'restore'} || &error($text{'restore_ecannot'});
10 &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
11
12 # Work out where to restore from
13 if ($in{'src'} == 0) {
14         -r $in{'path'} || &error(&text('restore_pe2', $in{'path'}));
15         $path = $in{'path'};
16         $need_unlink = 0;
17         }
18 else {
19         $in{'data'} || &error($text{'restore_edata'});
20         $path = &transname();
21         &open_tempfile(DATA, ">$path");
22         &print_tempfile(DATA, $in{'data'});
23         &close_tempfile(DATA);
24         }
25
26 # Validate tables list
27 if ($in{'tables_def'}) {
28         $tables = undef;
29         }
30 else {
31         $in{'tables'} =~ /\S/ || &error($text{'restore_etables'});
32         $tables = [ split(/\s+/, $in{'tables'}) ];
33         }
34
35 # Validate database
36 &indexof($in{'db'}, &list_databases()) >= 0 ||
37         &error(&text('restore_edb'));
38
39 $err = &restore_database($in{'db'}, $path, $in{'only'}, $in{'clean'}, $tables);
40 if ($err) {
41         &error(&text('restore_failed', "<pre>$err</pre>"));
42         }
43 else {
44         &redirect ("edit_dbase.cgi?db=$in{'db'}") ;
45         }
46