Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/web/www/routino/router.cgi
Parent Directory
|
Revision Log
Revision 1520 -
(hide annotations)
(download)
Sat Mar 8 19:36:35 2014 UTC (11 years ago) by amb
File size: 3006 byte(s)
Sat Mar 8 19:36:35 2014 UTC (11 years ago) by amb
File size: 3006 byte(s)
Update all Perl scripts to "use strict".
1 | amb | 569 | #!/usr/bin/perl |
2 | # | ||
3 | # Routino interactive router CGI | ||
4 | # | ||
5 | # Part of the Routino routing software. | ||
6 | # | ||
7 | amb | 1520 | # This file Copyright 2008-2014 Andrew M. Bishop |
8 | amb | 569 | # |
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 | amb | 1520 | use strict; |
24 | |||
25 | amb | 569 | # Use the generic router script |
26 | require "router.pl"; | ||
27 | |||
28 | # Use the perl CGI module | ||
29 | use CGI ':cgi'; | ||
30 | |||
31 | amb | 1004 | |
32 | amb | 569 | # Create the query and get the parameters |
33 | |||
34 | amb | 1520 | my $query=new CGI; |
35 | amb | 569 | |
36 | amb | 1520 | my @rawparams=$query->param; |
37 | amb | 569 | |
38 | # Legal CGI parameters with regexp validity check | ||
39 | |||
40 | amb | 1520 | my %legalparams=( |
41 | amb | 1468 | "lon[1-9][0-9]*" => "[-0-9.]+", |
42 | "lat[1-9][0-9]*" => "[-0-9.]+", | ||
43 | amb | 675 | "heading" => "[-0-9.]+", |
44 | amb | 574 | "transport" => "[a-z]+", |
45 | "highway-[a-z]+" => "[0-9.]+", | ||
46 | "speed-[a-z]+" => "[0-9.]+", | ||
47 | "property-[a-z]+" => "[0-9.]+", | ||
48 | "oneway" => "(1|0|true|false|on|off)", | ||
49 | amb | 622 | "turns" => "(1|0|true|false|on|off)", |
50 | amb | 574 | "weight" => "[0-9.]+", |
51 | "height" => "[0-9.]+", | ||
52 | "width" => "[0-9.]+", | ||
53 | "length" => "[0-9.]+", | ||
54 | "length" => "[0-9.]+", | ||
55 | amb | 577 | |
56 | "language" => "[-a-zA-Z]+", | ||
57 | "type" => "(shortest|quickest)", | ||
58 | amb | 1520 | "format" => "(html|gpx-route|gpx-track|text|text-all)", |
59 | |||
60 | "reverse" => "(1|0|true|false|on|off)", | ||
61 | "loop" => "(1|0|true|false|on|off)" | ||
62 | amb | 569 | ); |
63 | |||
64 | # Validate the CGI parameters, ignore invalid ones | ||
65 | |||
66 | amb | 1520 | my %cgiparams=(); |
67 | |||
68 | amb | 1004 | foreach my $key (@rawparams) |
69 | amb | 569 | { |
70 | amb | 1004 | foreach my $test (keys (%legalparams)) |
71 | amb | 569 | { |
72 | if($key =~ m%^$test$%) | ||
73 | { | ||
74 | amb | 1004 | my $value=$query->param($key); |
75 | amb | 569 | |
76 | if($value =~ m%^$legalparams{$test}$%) | ||
77 | { | ||
78 | $cgiparams{$key}=$value; | ||
79 | last; | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | |||
85 | # Get the important parameters | ||
86 | |||
87 | amb | 1520 | my $type; |
88 | my $format; | ||
89 | |||
90 | amb | 569 | $type=$cgiparams{type}; |
91 | delete $cgiparams{type}; | ||
92 | |||
93 | amb | 852 | $type="shortest" if(!$type); |
94 | |||
95 | amb | 577 | $format=$cgiparams{format}; |
96 | delete $cgiparams{format}; | ||
97 | amb | 569 | |
98 | amb | 577 | # Fill in the default parameters |
99 | amb | 569 | |
100 | amb | 1520 | my %fullparams=FillInDefaults(%cgiparams); |
101 | amb | 569 | |
102 | amb | 577 | # Run the router |
103 | amb | 569 | |
104 | amb | 1043 | my($router_uuid,$router_success)=RunRouter($type,%fullparams); |
105 | amb | 569 | |
106 | amb | 577 | # Return the output |
107 | amb | 569 | |
108 | amb | 577 | if($format) |
109 | amb | 569 | { |
110 | amb | 577 | ReturnOutput($router_uuid,$type,$format); |
111 | amb | 569 | } |
112 | amb | 577 | else |
113 | { | ||
114 | print header('text/plain'); | ||
115 | amb | 569 | |
116 | amb | 577 | print "$router_uuid\n"; |
117 | amb | 1043 | print "$router_success\n"; |
118 | amb | 577 | } |
Properties
Name | Value |
---|---|
svn:executable | * |