Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/web/www/routino/search.cgi
Parent Directory
|
Revision Log
Revision 1008 -
(show annotations)
(download)
Fri Jun 29 18:01:57 2012 UTC (12 years, 8 months ago) by amb
File size: 2131 byte(s)
Fri Jun 29 18:01:57 2012 UTC (12 years, 8 months ago) by amb
File size: 2131 byte(s)
Pass bounding box to search to help find local places. Properly URI encode search strings. Properly check CGI parameters.
1 | #!/usr/bin/perl |
2 | # |
3 | # Routino search results retrieval CGI |
4 | # |
5 | # Part of the Routino routing software. |
6 | # |
7 | # This file Copyright 2012 Andrew M. Bishop |
8 | # |
9 | # This program is free software: you can redistribute it and/or modify |
10 | # it under the terms of the GNU Affero General Public License as published by |
11 | # the Free Software Foundation, either version 3 of the License, or |
12 | # (at your option) any later version. |
13 | # |
14 | # This program is distributed in the hope that it will be useful, |
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | # GNU Affero General Public License for more details. |
18 | # |
19 | # You should have received a copy of the GNU Affero General Public License |
20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | # |
22 | |
23 | # Use the generic search script |
24 | require "search.pl"; |
25 | |
26 | # Use the perl CGI module |
27 | use CGI ':cgi'; |
28 | |
29 | |
30 | # Create the query and get the parameters |
31 | |
32 | $query=new CGI; |
33 | |
34 | @rawparams=$query->param; |
35 | |
36 | # Legal CGI parameters with regexp validity check |
37 | |
38 | %legalparams=( |
39 | "marker" => "[0-9]+", |
40 | |
41 | "left" => "[-0-9.]+", |
42 | "right" => "[-0-9.]+", |
43 | "top" => "[-0-9.]+", |
44 | "bottom" => "[-0-9.]+", |
45 | |
46 | "search" => ".+" |
47 | ); |
48 | |
49 | # Validate the CGI parameters, ignore invalid ones |
50 | |
51 | foreach my $key (@rawparams) |
52 | { |
53 | foreach my $test (keys (%legalparams)) |
54 | { |
55 | if($key =~ m%^$test$%) |
56 | { |
57 | my $value=$query->param($key); |
58 | |
59 | if($value =~ m%^$legalparams{$test}$%) |
60 | { |
61 | $cgiparams{$key}=$value; |
62 | last; |
63 | } |
64 | } |
65 | } |
66 | } |
67 | |
68 | # Parse the parameters |
69 | |
70 | $marker=$cgiparams{marker}; |
71 | $search=$cgiparams{search}; |
72 | |
73 | $left =$cgiparams{left}; |
74 | $right =$cgiparams{right}; |
75 | $top =$cgiparams{top}; |
76 | $bottom=$cgiparams{bottom}; |
77 | |
78 | # Run the search |
79 | |
80 | ($search_time,$search_message,@places)=RunSearch($search,$left,$right,$top,$bottom); |
81 | |
82 | # Return the output |
83 | |
84 | print header('text/plain'); |
85 | |
86 | print "$marker\n"; |
87 | print "$search_time\n"; |
88 | print "$search_message\n"; |
89 | foreach $place (@places) |
90 | { |
91 | print "$place\n"; |
92 | } |
Properties
Name | Value |
---|---|
svn:executable | * |