Handle hostnames with upper-case letters
[webmin.git] / mysql / exec.cgi
1 #!/usr/local/bin/perl
2 # exec.cgi
3 # Execute some SQL command and display output
4
5 require './mysql-lib.pl';
6 &ReadParseMime();
7 &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
8 $access{'edonly'} && &error($text{'dbase_ecannot'});
9 &error_setup($text{'exec_err'});
10
11 if ($in{'clear'}) {
12         # Delete the history file
13         &unlink_file($commands_file.".".$in{'db'});
14         &redirect("exec_form.cgi?db=$in{'db'}");
15         }
16 else {
17         # Run some SQL
18         $in{'cmd'} = join(" ", split(/[\r\n]+/, $in{'cmd'}));
19         $cmd = $in{'cmd'} ? $in{'cmd'} : $in{'old'};
20         $d = &execute_sql_logged($in{'db'}, $cmd);
21
22         &ui_print_header(undef, $text{'exec_title'}, "");
23         print &text('exec_out', "<tt>".&html_escape($cmd)."</tt>"),"<p>\n";
24         @data = @{$d->{'data'}};
25         if (@data) {
26                 print &ui_columns_start($d->{'titles'});
27                 foreach $r (@data) {
28                         print &ui_columns_row($r);
29                         }
30                 print &ui_columns_end();
31                 }
32         else {
33                 print "<b>$text{'exec_none'}</b> <p>\n";
34                 }
35
36         &open_readfile(OLD, "$commands_file.$in{'db'}");
37         while(<OLD>) {
38                 s/\r|\n//g;
39                 $already++ if ($_ eq $in{'cmd'});
40                 }
41         close(OLD);
42         if (!$already && $in{'cmd'} =~ /\S/) {
43                 &open_lock_tempfile(OLD, ">>$commands_file.$in{'db'}");
44                 &print_tempfile(OLD, "$in{'cmd'}\n");
45                 &close_tempfile(OLD);
46                 chmod(0700, "$commands_file.$in{'db'}");
47                 }
48         &webmin_log("exec", undef, $in{'db'}, \%in);
49
50         &ui_print_footer("exec_form.cgi?db=$in{'db'}", $text{'exec_return'},
51                 "edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'},
52                 "", $text{'index_return'});
53         }
54