1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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";
|