Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/web/www/routino/customrouter.cgi
Parent Directory
|
Revision Log
Revision 985 -
(show annotations)
(download)
Sat Mar 24 13:53:53 2012 UTC (13 years ago) by amb
File size: 2417 byte(s)
Sat Mar 24 13:53:53 2012 UTC (13 years ago) by amb
File size: 2417 byte(s)
Process the URL query string in the Javascript not in custom*.cgi. Refactor a lot of the code for coordinate handling. Simplify custom*.cgi so that they just redirect to the HTML page (will be removed in later versions - for existing link compatibility only).
1 | #!/usr/bin/perl |
2 | # |
3 | # Routino router custom link CGI |
4 | # |
5 | # Part of the Routino routing software. |
6 | # |
7 | # This file Copyright 2008-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 perl CGI module |
24 | use CGI ':cgi'; |
25 | |
26 | # Create the query and get the parameters |
27 | |
28 | $query=new CGI; |
29 | |
30 | @rawparams=$query->param; |
31 | |
32 | # Legal CGI parameters with regexp validity check |
33 | |
34 | %legalparams=( |
35 | "lon" => "[-0-9.]+", |
36 | "lat" => "[-0-9.]+", |
37 | "zoom" => "[0-9]+", |
38 | |
39 | "lon[1-9]+" => "[-0-9.]+", |
40 | "lat[1-9]+" => "[-0-9.]+", |
41 | "transport" => "[a-z]+", |
42 | "highway-[a-z]+" => "[0-9.]+", |
43 | "speed-[a-z]+" => "[0-9.]+", |
44 | "property-[a-z]+" => "[0-9.]+", |
45 | "oneway" => "(1|0|true|false|on|off)", |
46 | "turns" => "(1|0|true|false|on|off)", |
47 | "weight" => "[0-9.]+", |
48 | "height" => "[0-9.]+", |
49 | "width" => "[0-9.]+", |
50 | "length" => "[0-9.]+", |
51 | |
52 | "language" => "[-a-zA-Z]+" |
53 | ); |
54 | |
55 | # Validate the CGI parameters, ignore invalid ones |
56 | |
57 | foreach $key (@rawparams) |
58 | { |
59 | foreach $test (keys (%legalparams)) |
60 | { |
61 | if($key =~ m%^$test$%) |
62 | { |
63 | $value=$query->param($key); |
64 | |
65 | if($value =~ m%^$legalparams{$test}$%) |
66 | { |
67 | $cgiparams{$key}=$value; |
68 | last; |
69 | } |
70 | } |
71 | } |
72 | } |
73 | |
74 | # Redirect to the HTML page. |
75 | |
76 | $params=""; |
77 | |
78 | foreach $param (keys %cgiparams) |
79 | { |
80 | if($params eq "") |
81 | { |
82 | $params="?"; |
83 | } |
84 | else |
85 | { |
86 | $params.="&"; |
87 | } |
88 | |
89 | $params.="$param=$cgiparams{$param}"; |
90 | } |
91 | |
92 | print $query->redirect("router.html".$params); |
Properties
Name | Value |
---|---|
svn:executable | * |