Handle hostnames with upper-case letters
[webmin.git] / postgresql / backup_form.cgi
1 #!/usr/local/bin/perl
2 # backup_form.cgi
3 # Display a form for backup the database
4
5 require './postgresql-lib.pl' ;
6 &ReadParse();
7 &error_setup ( $text{'backup_err'} ) ;
8 if ($in{'all'}) {
9         @alldbs = &list_databases();
10         @dbs = grep { &can_edit_db($_) } @alldbs;
11         @alldbs == @dbs || &error($text{'dbase_ecannot'});
12         }
13 else {
14         &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
15         }
16 $access{'backup'} || &error($text{'backup_ecannot'});
17
18 &has_command($config{'dump_cmd'}) ||
19         &error(&text('backup_ecmd', "<tt>$config{'dump_cmd'}</tt>"));
20
21 $desc = "<tt>$in{'db'}</tt>";
22 &ui_print_header($desc, $in{'all'} ? $text{'backup_title2'}
23                    : $text{'backup_title'}, "", "backup_form" ) ;
24
25 $cron = !$module_info{'usermin'} &&
26         !$access{'user'} && &foreign_installed("cron");
27 if ($in{'all'}) {
28         print "$text{'backup_desc3'}\n";
29         }
30 else {
31         print &text('backup_desc', "<tt>$in{'db'}</tt>"),"\n";
32         }
33 if ($cron) {
34         print "$text{'backup_desc2'}\n";
35         }
36 print "<p>\n";
37 %c = $module_info{'usermin'} ? %userconfig : %config;
38
39 print &ui_form_start("backup.cgi", "post");
40 print &ui_hidden("db", $in{'db'});
41 print &ui_hidden("all", $in{'all'});
42 print &ui_hidden_table_start($text{'backup_header1'}, "width=100%", 2, "main",
43                              1, [ "width=30%" ]);
44
45 # Destination file or directory
46 $p = $c{'backup_'.$in{'db'}} || "$config{'repository'}/";
47 print &ui_table_row($in{'all'} ? $text{'backup_path2'}
48                                : $text{'backup_path'},
49         &ui_textbox("path", $p, 60)." ".
50         &file_chooser_button("path"));
51
52 # Create destination dir
53 if ($in{'all'}) {
54         print &ui_table_row($text{'backup_mkdir'},
55                 &ui_yesno_radio("mkdir", int($c{'backup_mkdir_'.$in{'db'}})));
56         }
57
58 # Show backup format input
59 $f = $c{'backup_format_'.$in{'db'}};
60 print &ui_table_row($text{'backup_format'},
61         &ui_select("format", $f,
62                 [ [ 'p', $text{'backup_format_p'} ],
63                   [ 't', $text{'backup_format_t'} ],
64                   [ 'c', $text{'backup_format_c'} ] ]));
65
66 if (!$in{'all'}) {
67         # Show input to select tables
68         $t = $c{'backup_tables_'.$in{'db'}};
69         @tables = &list_tables($in{'db'});
70         if (@tables) {
71                 print &ui_table_row($text{'backup_tables'},
72                         &ui_radio("tables_def", $t ? 0 : 1,
73                                   [ [ 1, $text{'backup_alltables'} ],
74                                     [ 0, $text{'backup_seltables'} ] ])."<br>".
75                         &ui_select("tables", [ split(/\s+/, $t) ],
76                                    [ sort @tables ], 5, 1));
77                 }
78         else {
79                 print &ui_hidden("tables_def", 1);
80                 }
81         }
82
83 print &ui_hidden_table_end("main");
84
85 if ($cron) {
86         if ($access{'cmds'}) {
87                 print &ui_hidden_table_start($text{'backup_header2'},
88                                              "width=100%", 2,
89                                              "opts", 0, [ "width=30%" ]);
90
91                 $b = $c{'backup_before_'.$in{'db'}};
92                 print &ui_table_row($text{'backup_before'},
93                         &ui_textbox("before", $b, 50));
94
95                 $a = $c{'backup_after_'.$in{'db'}};
96                 print &ui_table_row($text{'backup_after'},
97                         &ui_textbox("after", $a, 50));
98
99                 if ($in{'all'}) {
100                         # Command mode option
101                         $cmode = $c{'backup_cmode_'.$in{'db'}};
102                         print &ui_table_row($text{'backup_cmode'},
103                                 &ui_radio("cmode", int($cmode),
104                                         [ [ 0, $text{'backup_cmode0'} ],
105                                           [ 1, $text{'backup_cmode1'} ] ]));
106                         }
107
108                 print &ui_hidden_table_end("opts");
109                 }
110
111         print &ui_hidden_table_start($text{'backup_header3'}, "width=100%",
112                                      2, "sched", 1, [ "width=30%" ]);
113
114         &foreign_require("cron", "cron-lib.pl");
115         @jobs = &cron::list_cron_jobs();
116         $cmd = $in{'all'} ? "$cron_cmd --all" : "$cron_cmd $in{'db'}";
117         ($job) = grep { $_->{'command'} eq $cmd } @jobs;
118
119         print &ui_table_row($text{'backup_sched'},
120                 &ui_radio("sched", $job ? 1 : 0,
121                   [ [ 0, $text{'no'} ], [ 1, $text{'backup_sched1'} ] ]));
122
123         if (!$config{'simple_sched'} || ($dump && !$dump->{'special'})) {
124                 # Complex Cron time input
125                 $job ||= { 'mins' => 0,
126                            'hours' => 0,
127                            'days' => '*',
128                            'months' => '*',
129                            'weekdays' => '*' };
130                 print &ui_table_row(undef,
131                         "<table border=2 width=100%>".
132                         &capture_function_output(\&cron::show_times_input,$job).
133                         "</table>", 2);
134                 }
135         else {
136                 # Simple Cron time input
137                 $job ||= { 'special' => 'daily' };
138                 print &ui_hidden("special_def", 1),"\n";
139                 print &ui_table_row($text{'backup_special'},
140                     &ui_select("special", $job->{'special'},
141                         [ map { [ $_, $cron::text{'edit_special_'.$_} ] }
142                           ('hourly', 'daily', 'weekly', 'monthly', 'yearly')]));
143                 }
144         print &ui_hidden_table_end("sched");
145         }
146
147 if ($cron) {
148         print &ui_form_end([ [ "backup", $text{'backup_ok'} ],
149                              [ "save", $text{'backup_ok2'} ] ]);
150         }
151 else {
152         print &ui_form_end([ [ "backup", $text{'backup_ok'} ] ]);
153         }
154
155 if ($in{'all'}) {
156         &ui_print_footer("", $text{'index_return'});
157         }
158 else {
159         &ui_print_footer("edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'},
160                 "", $text{'index_return'});
161         }
162
163