Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/web/www/routino/noscript.cgi
Parent Directory
|
Revision Log
Revision 569 -
(show annotations)
(download)
Wed Dec 29 09:50:50 2010 UTC (14 years, 3 months ago) by amb
File size: 5938 byte(s)
Wed Dec 29 09:50:50 2010 UTC (14 years, 3 months ago) by amb
File size: 5938 byte(s)
Added the uncontrolled (not auto-generated) files from routino-1.1.
1 | #!/usr/bin/perl |
2 | # |
3 | # Routino non-Javascript router CGI |
4 | # |
5 | # Part of the Routino routing software. |
6 | # |
7 | # This file Copyright 2008,2009 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 router script |
24 | require "router.pl"; |
25 | |
26 | # Use the perl CGI module |
27 | use CGI ':cgi'; |
28 | |
29 | # Create the query and get the parameters |
30 | |
31 | $query=new CGI; |
32 | |
33 | @rawparams=$query->param; |
34 | |
35 | # Legal CGI parameters with regexp validity check |
36 | |
37 | %legalparams=( |
38 | "lon[1-9]" => "[-0-9.]+", |
39 | "lat[1-9]" => "[-0-9.]+", |
40 | "transport" => "[a-z]+", |
41 | "highway-[a-z]+" => "[0-9.]+", |
42 | "speed-[a-z]+" => "[0-9.]+", |
43 | "oneway" => "(1|0|true|false|on|off)", |
44 | "weight" => "[0-9.]+", |
45 | "height" => "[0-9.]+", |
46 | "width" => "[0-9.]+", |
47 | "length" => "[0-9.]+", |
48 | "length" => "[0-9.]+", |
49 | |
50 | "submit" => "(shortest|quickest|link)", |
51 | "output" => "(gpx-route|gpx-track|txt|txt-all|html)" |
52 | ); |
53 | |
54 | # Validate the CGI parameters, ignore invalid ones |
55 | |
56 | foreach $key (@rawparams) |
57 | { |
58 | foreach $test (keys (%legalparams)) |
59 | { |
60 | if($key =~ m%^$test$%) |
61 | { |
62 | $value=$query->param($key); |
63 | |
64 | if($value =~ m%^$legalparams{$test}$%) |
65 | { |
66 | $cgiparams{$key}=$value; |
67 | last; |
68 | } |
69 | } |
70 | } |
71 | } |
72 | |
73 | # Possible file formats |
74 | |
75 | %formats=( |
76 | "gpx-route" => "-route.gpx", |
77 | "gpx-track" => "-track.gpx", |
78 | "txt" => ".txt", |
79 | "txt-all" => "-all.txt" |
80 | ); |
81 | |
82 | # Possible MIME types |
83 | |
84 | %mimetypes=( |
85 | "gpx-route" => "text/xml", |
86 | "gpx-track" => "text/xml", |
87 | "txt" => "text/plain", |
88 | "txt-all" => "text/plain" |
89 | ); |
90 | |
91 | # Get the important parameters |
92 | |
93 | $submit=$cgiparams{submit}; |
94 | delete $cgiparams{submit}; |
95 | |
96 | $output=$cgiparams{output}; |
97 | delete $cgiparams{output}; |
98 | |
99 | $output="html" if(!$output || !$formats{$output} || |
100 | ($submit ne "shortest" && $submit ne "quickest")); |
101 | |
102 | # Generate a custom URL |
103 | |
104 | $customurl=""; |
105 | |
106 | if($submit) |
107 | { |
108 | $customurl="noscript.cgi?"; |
109 | |
110 | foreach $key (sort (keys %cgiparams)) |
111 | { |
112 | $customurl.="$key=$cgiparams{$key};"; |
113 | } |
114 | |
115 | $customurl.="submit=custom"; |
116 | } |
117 | |
118 | # Fill in the default parameters using the ones in router.pl (don't use compiled in defaults) |
119 | |
120 | $cgiparams{transport}='motorcar' if(!defined $cgiparams{transport}); |
121 | |
122 | $transport=$cgiparams{transport}; |
123 | |
124 | foreach $highway (@router_highways) |
125 | { |
126 | $key="highway-$highway"; |
127 | $value=$router_profile_highway{$highway}->{$transport}; |
128 | $cgiparams{$key}=$value if(!defined $cgiparams{$key}); |
129 | |
130 | $key="speed-$highway"; |
131 | $value=$router_profile_speed{$highway}->{$transport}; |
132 | $cgiparams{$key}=$value if(!defined $cgiparams{$key}); |
133 | } |
134 | |
135 | $cgiparams{oneway} =~ s/(true|on)/1/; |
136 | $cgiparams{oneway} =~ s/(false|off)/0/; |
137 | |
138 | foreach $restriction (@router_restrictions) |
139 | { |
140 | $key="$restriction"; |
141 | $value=$router_profile_restrictions{$restriction}->{$transport}; |
142 | $cgiparams{$key}=$value if(!defined $cgiparams{$key}); |
143 | } |
144 | |
145 | # Open template file before running the router (including changing directory) |
146 | |
147 | open(TEMPLATE,"<noscript.template.html"); |
148 | |
149 | # Run the router |
150 | |
151 | if($submit eq "shortest" || $submit eq "quickest") |
152 | { |
153 | ($router_uuid,$router_time,$router_result,$router_message)=&RunRouter($submit,%cgiparams); |
154 | |
155 | $router_type=$submit; |
156 | $router_Type="Shortest" if($submit eq "shortest"); |
157 | $router_Type="Quickest" if($submit eq "quickest"); |
158 | } |
159 | |
160 | # Generate the output |
161 | |
162 | if($output eq "html" || $router_message) |
163 | { |
164 | # Parse the template and fill in the parameters |
165 | |
166 | print header('text/html'); |
167 | |
168 | while(<TEMPLATE>) |
169 | { |
170 | if(m%<input% && m%<!-- ([^ ]+) *-->%) |
171 | { |
172 | $key=$1; |
173 | |
174 | m%type="([a-z]+)"%; |
175 | $type=$1; |
176 | |
177 | m%value="([a-z]+)"%; |
178 | $value=$1; |
179 | |
180 | if($type eq "radio") |
181 | { |
182 | $checked=""; |
183 | $checked="checked" if($cgiparams{$key} eq $value); |
184 | |
185 | s%><!-- .+? *-->% $checked>%; |
186 | } |
187 | elsif($type eq "checkbox") |
188 | { |
189 | $checked=""; |
190 | $checked="checked" if($cgiparams{$key}); |
191 | |
192 | s%><!-- .+? *-->% $checked>%; |
193 | } |
194 | elsif($type eq "text") |
195 | { |
196 | s%><!-- .+? *-->% value="$cgiparams{$key}">%; |
197 | } |
198 | |
199 | print; |
200 | } |
201 | elsif(m%<!-- custom-url -->%) |
202 | { |
203 | s%<!-- custom-url -->%$customurl%; |
204 | |
205 | print if($submit); |
206 | } |
207 | elsif(m%<!-- result-start -->%) |
208 | { |
209 | $results_section=1; |
210 | } |
211 | elsif(m%<!-- result-finish -->%) |
212 | { |
213 | $results_section=0; |
214 | } |
215 | elsif($results_section) |
216 | { |
217 | s%<!-- result-Type -->%$router_Type%; |
218 | s%<!-- result-type -->%$router_type%; |
219 | s%<!-- result-uuid -->%$router_uuid%; |
220 | s%<!-- result-time -->%$router_time%; |
221 | s%<!-- result-result -->%$router_result%; |
222 | s%<!-- result-message -->%$router_message%; |
223 | |
224 | print if($router_uuid); |
225 | } |
226 | else |
227 | { |
228 | print; |
229 | } |
230 | } |
231 | |
232 | close(TEMPLATE); |
233 | } |
234 | else |
235 | { |
236 | print header($mimetypes{$output}); |
237 | |
238 | system "cat $submit$formats{$output}"; |
239 | } |
Properties
Name | Value |
---|---|
svn:executable | * |