summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2014-10-21 18:14:02 +0200
committercos <cos>2014-11-21 21:55:18 +0100
commit368cdce25f35f31320d2f26d7683fa35a27e18f6 (patch)
tree784e4f0013be910db22902da469173fbbd7ad2fe
parent957c73087d6b090de5dc8953adc7086cac6641ec (diff)
downloadmat-368cdce25f35f31320d2f26d7683fa35a27e18f6.zip
Initial commit of mat.cgi
-rwxr-xr-xcgi-bin/mat.cgi46
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";