-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgettemplocxml.cgi
More file actions
executable file
·80 lines (72 loc) · 2.21 KB
/
Copy pathgettemplocxml.cgi
File metadata and controls
executable file
·80 lines (72 loc) · 2.21 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl -w
# FILE: gettemplocxml.cgi
# DATE: 03/01/2012
# AUTH: CUMMINGS
# DESC: Responds to url in the having the following structure
# http://gwdroid.wrlc.org/cgi-bin/gettemplocxml.cgi?itemid=5434377
# Returns the full name of the temporary item location for the item
# in XML format
use CGI;
$CGI::POST_MAX=1024*100; # MAX 100k POSTS
$CGI::DISABLE_UPLOADS=1; # no uploads
# trim spaces and return NULL if field is empty
sub trim
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
if ( length($string) > 0 ){
return $string;
} else {
return "NULL";
}
}
#
# This line sets the method that this script was accessed (GET or POST)
my $method = $ENV{'REQUEST_METHOD'};
# The following if else structure will use the appropriate
# processing for grabbing the form data
if ($method eq "GET") {
$rawdata = $ENV{'QUERY_STRING'};
} else {
# if not "GET" then it will default "POST"
read(STDIN, $rawdata, $ENV{'CONTENT_LENGTH'});
}
# Split the data pairs into sections
my @value_pairs = split (/&/,$rawdata);
my %formdata = ();
# Cycle through each pair to grab the values of the fields
foreach $pair (@value_pairs) {
($field, $value) = split (/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
$formdata{$field} = $value;
# store the field data in the results hash
}
# next line sets the MIME type for the output
#print "Content-type: application/json\n\n";
print "Content-type: text/xml\n\n";
# query output is a pipe delimited file. eg /tmp/locdata300000.txt
`sh templocquery.sh $formdata{itemid}`;
my $Fname="/tmp/locdata".$formdata{itemid}.".txt";
if (-s $Fname) {
open FILE, $Fname or dienice("Unable to open output file");
$document='';
while (<FILE>)
{
$document .= $_;
}
close (FILE);
@tokens = split(/\|/, $document);
# Note: No trim required.
print "<TEMPLOC TL.ITEMID='".trim($tokens[1])."'>\n";
#
print "<TL.TEMPLOCDESC>";
print $tokens[3];
print "</TL.TEMPLOCDESC>\n";
print "</TEMPLOC>";
`rm $Fname`;
} else {
print "<TEMPLOC STATUS='NA'>\n";
print "</TEMPLOC>";
}