implement psql plain-text output
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 8 Jul 2011 23:20:22 +0000 (01:20 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 8 Jul 2011 23:20:22 +0000 (01:20 +0200)
web_ui.pl

index 52ad371..76d2132 100755 (executable)
--- a/web_ui.pl
+++ b/web_ui.pl
@@ -193,6 +193,16 @@ get '/user' => sub {
        $self->render('user');
 };
 
        $self->render('user');
 };
 
+get '/psql/:command' => sub {
+       my $self = shift;
+       my $command = $self->param('command');
+       $command =~ s/^_/\\/ && warn "internal psql command $command";
+       $command = sprintf "psql -c '%s' apkpm", $command;
+       my $output = `$command`; # FIXME unsecure
+       $self->render_text( "\$ <b><tt>$command</tt></b>\n\n<pre>$output</pre>" );
+};
+
+# create pid file
 open(my $pid, '>', '/tmp/apkpm.web_ui.pid');
 print $pid "$$\n";
 close $pid;
 open(my $pid, '>', '/tmp/apkpm.web_ui.pid');
 print $pid "$$\n";
 close $pid;