Handle hostnames with upper-case letters
[webmin.git] / mysql / backup_form.cgi
1 #!/usr/local/bin/perl
2 # backup_form.cgi
3 # Display a form for backing up this database, or all databases
4
5 require './mysql-lib.pl';
6 &ReadParse();
7 if ($in{'all'}) {
8         @alldbs = &list_databases();
9         @dbs = grep { &can_edit_db($_) } @alldbs;
10         @alldbs == @dbs || &error($text{'dbase_ecannot'});
11         }
12 else {
13         &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
14         }
15 $access{'edonly'} && &error($text{'dbase_ecannot'});
16 $access{'buser'} || &error($text{'dbase_ecannot'});
17 &ui_print_header(undef, $in{'all'} ? $text{'backup_title2'}
18                                    : $text{'backup_title'}, "",
19         "backup_form");
20
21 if (!-x $config{'mysqldump'}) {
22         print &text('backup_edump', "<tt>$config{'mysqldump'}</tt>",
23                           "../config.cgi?$module_name"),"<p>\n";
24         &ui_print_footer("edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'});
25         exit;
26         }
27
28 $cron = !$module_info{'usermin'} && $access{'buser'} eq 'root' &&
29         !$access{'user'} && &foreign_installed("cron");
30 if ($in{'all'}) {
31         print "$text{'backup_desc3'}\n";
32         }
33 else {
34         print &text('backup_desc', "<tt>$in{'db'}</tt>"),"\n";
35         }
36 if ($cron) {
37         print "$text{'backup_desc2'}\n";
38         }
39 print "<p>\n";
40 %c = $module_info{'usermin'} ? %userconfig : %config;
41
42 print &ui_form_start("backup_db.cgi", "post");
43 print &ui_hidden("db", $in{'db'});
44 print &ui_hidden("all", $in{'all'});
45 print &ui_hidden_table_start($text{'backup_header1'}, "width=100%", 2, "main",
46                              1, [ "width=30%" ]);
47
48 # Destination file or directory
49 print &ui_table_row($in{'all'} ? $text{'backup_file2'}
50                                : $text{'backup_file'},
51         &ui_textbox("file", $c{'backup_'.$in{'db'}}, 60)." ".
52         &file_chooser_button("file"));
53
54 # Create destination dir
55 if ($in{'all'}) {
56         print &ui_table_row($text{'backup_mkdir'},
57                 &ui_yesno_radio("mkdir", int($c{'backup_mkdir_'.$in{'db'}})));
58         }
59
60 if (!$in{'all'}) {
61         # Show input to select tables
62         $t = $c{'backup_tables_'.$in{'db'}};
63         @tables = &list_tables($in{'db'});
64         print &ui_table_row($text{'backup_tables'},
65                 &ui_radio("tables_def", $t ? 0 : 1,
66                           [ [ 1, $text{'backup_alltables'} ],
67                             [ 0, $text{'backup_seltables'} ] ])."<br>".
68                 &ui_select("tables", [ split(/\s+/, $t) ],
69                            [ sort @tables ], 5, 1));
70         }
71
72 print &ui_hidden_table_end("main");
73 print &ui_hidden_table_start($text{'backup_header2'}, "width=100%", 2, "opts",
74                              0, [ "width=30%" ]);
75
76 # Show input for where clause
77 $w = $c{'backup_where_'.$in{'db'}};
78 print &ui_table_row($text{'backup_where'},
79         &ui_opt_textbox("where", $w, 30, $text{'backup_none'}));
80
81 # Show option to include drop statements in SQL
82 $d = $c{'backup_drop_'.$in{'db'}};
83 print &ui_table_row($text{'backup_drop'},
84         &ui_yesno_radio("drop", $d ? 1 : 0));
85
86 # Show input for character set
87 $s = $c{'backup_charset_'.$in{'db'}};
88 print &ui_table_row($text{'backup_charset'},
89         &ui_radio("charset_def", $s ? 0 : 1,
90                [ [ 1, $text{'default'} ],
91                  [ 0, &ui_select("charset", $s,
92                         [ &list_character_sets($in{'db'}) ]) ] ]));
93
94 if ($mysql_version >= 5.0) {
95         # Show compatability format option
96         $cf = $c{'backup_compatible_'.$in{'db'}};
97         print &ui_table_row($text{'backup_compatible'},
98                 &ui_radio("compatible_def", $cf ? 0 : 1,
99                        [ [ 1, $text{'default'} ],
100                          [ 0, &text('backup_compwith',
101                                 &ui_select("compatible", $cf,
102                                    [ &list_compatible_formats() ])) ] ]));
103
104         %co = map { $_, 1 } split(/\s+/, $c{'backup_options_'.$in{'db'}});
105         $opts = "";
106         foreach $o (&list_compatible_options()) {
107                 $opts .= &ui_checkbox("options", $o->[0], $o->[1] || $o->[0],
108                                    $co{$o->[0]})."<br>\n";
109                 }
110         print &ui_table_row($text{'backup_options'}, $opts);
111         }
112 else {
113         print &ui_hidden("compatible_def", 1),"\n";
114         }
115
116 # Show compression option
117 $cp = int($c{'backup_compress_'.$in{'db'}});
118 print &ui_table_row($text{'backup_compress'},
119         &ui_radio("compress", $cp,
120                 [ [ 0, $text{'backup_cnone'} ],
121                   [ 1, $text{'backup_gzip'} ],
122                   [ 2, $text{'backup_bzip2'} ] ]));
123
124 # Show single-transaction option
125 $s = $c{'backup_single_'.$in{'db'}};
126 print &ui_table_row($text{'backup_single'},
127         &ui_yesno_radio("single", $s ? 1 : 0));
128
129 if ($cron) {
130         # Show before/after commands
131         $b = $c{'backup_before_'.$in{'db'}};
132         print &ui_table_row($text{'backup_before'},
133                 &ui_textbox("before", $b, 60));
134
135         $a = $c{'backup_after_'.$in{'db'}};
136         print &ui_table_row($text{'backup_after'},
137                 &ui_textbox("after", $a, 60));
138
139         if ($in{'all'}) {
140                 # Command mode option
141                 $cmode = $c{'backup_cmode_'.$in{'db'}};
142                 print &ui_table_row($text{'backup_cmode'},
143                         &ui_radio("cmode", int($cmode),
144                                 [ [ 0, $text{'backup_cmode0'} ],
145                                   [ 1, $text{'backup_cmode1'} ] ]));
146                 }
147
148         print &ui_hidden_table_end("opts");
149         print &ui_hidden_table_start($text{'backup_header3'}, "width=100%", 2,
150                                      "sched", 1, [ "width=30%" ]);
151
152         # Show cron time
153         &foreign_require("cron", "cron-lib.pl");
154         @jobs = &cron::list_cron_jobs();
155         $cmd = $in{'all'} ? "$cron_cmd --all" : "$cron_cmd $in{'db'}";
156         ($job) = grep { $_->{'command'} eq $cmd } @jobs;
157
158         print &ui_table_row($text{'backup_sched'},
159                 &ui_radio("sched", $job ? 1 : 0,
160                   [ [ 0, $text{'no'} ], [ 1, $text{'backup_sched1'} ] ]));
161
162         $job ||= { 'mins' => 0,
163                    'hours' => 0,
164                    'days' => '*',
165                    'months' => '*',
166                    'weekdays' => '*' };
167         print &ui_table_row(undef,
168                 "<table border=2 width=100%>".
169                 &capture_function_output(\&cron::show_times_input, $job).
170                 "</table>", 2);
171
172         print &ui_hidden_table_end("sched");
173         }
174 else {
175         print &ui_hidden_table_end("opts");
176         }
177
178 if ($cron) {
179         print &ui_form_end([ [ "backup", $text{'backup_ok'} ],
180                              [ "save", $text{'backup_ok2'} ] ]);
181         }
182 else {
183         print &ui_form_end([ [ "backup", $text{'backup_ok'} ] ]);
184         }
185
186 if ($in{'all'}) {
187         &ui_print_footer("", $text{'index_return'});
188         }
189 else {
190         &ui_print_footer("edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'},
191                 "", $text{'index_return'});
192         }
193