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