diff options
-rwxr-xr-x | cgi-bin/mat.cgi | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/cgi-bin/mat.cgi b/cgi-bin/mat.cgi new file mode 100755 index 0000000..7b31e87 --- /dev/null +++ b/cgi-bin/mat.cgi @@ -0,0 +1,46 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Config::Simple; +use CGI::Simple; +use DBI; + +tie my %Config, "Config::Simple", '/etc/mat.conf'; + +my $q = new CGI::Simple; +my $id = $q->param('id'); +my $action = $q->param('action'); + +sub misconfigured +{ + print "Content-Type: text/plain; charset=utf-8\n\r\n\r"; + print "This system is misconfigured.\n"; + exit 1; +} + +sub invalid_input() +{ + print "Content-Type: text/plain; charset=utf-8\n\r\n\r"; + print "Invalid input.\n"; + exit 1; +} + +### MAIN PROGRAM ############################################################## + +misconfigured unless ($Config{'database'}); +invalid_input unless ($id and $action); + +invalid_input unless (($id =~ m/^[0-9]+$/) and ($action =~ m/^view$/)); + +my $db = DBI->connect($Config{'database'}, "", "", + {HandleError => \&misconfigured, AutoCommit => 1}); + +my $recipe_row = $db->selectrow_arrayref("SELECT name, storage, uri FROM ". + "recipes AS r JOIN inventory AS i ON i.recipe_id=r.id WHERE i.id=".$id. + ";"); + +print "Content-Type: text/plain; charset=utf-8\n\r\n\r"; +print $id, "\n", $$recipe_row[0], "\n", $$recipe_row[1], "\n", + $$recipe_row[2], "\n"; |