Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/web/www/routino/noscript.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 574 - (show annotations) (download)
Wed Dec 29 10:11:08 2010 UTC (14 years, 3 months ago) by amb
File size: 6194 byte(s)
Added the uncontrolled (not auto-generated) files from routino-1.3.

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 "property-[a-z]+" => "[0-9.]+",
44 "oneway" => "(1|0|true|false|on|off)",
45 "weight" => "[0-9.]+",
46 "height" => "[0-9.]+",
47 "width" => "[0-9.]+",
48 "length" => "[0-9.]+",
49 "length" => "[0-9.]+",
50
51 "submit" => "(shortest|quickest|link)",
52 "output" => "(gpx-route|gpx-track|txt|txt-all|html)"
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 # Possible file formats
75
76 %formats=(
77 "gpx-route" => "-route.gpx",
78 "gpx-track" => "-track.gpx",
79 "txt" => ".txt",
80 "txt-all" => "-all.txt"
81 );
82
83 # Possible MIME types
84
85 %mimetypes=(
86 "gpx-route" => "text/xml",
87 "gpx-track" => "text/xml",
88 "txt" => "text/plain",
89 "txt-all" => "text/plain"
90 );
91
92 # Get the important parameters
93
94 $submit=$cgiparams{submit};
95 delete $cgiparams{submit};
96
97 $output=$cgiparams{output};
98 delete $cgiparams{output};
99
100 $output="html" if(!$output || !$formats{$output} ||
101 ($submit ne "shortest" && $submit ne "quickest"));
102
103 # Generate a custom URL
104
105 $customurl="";
106
107 if($submit)
108 {
109 $customurl="noscript.cgi?";
110
111 foreach $key (sort (keys %cgiparams))
112 {
113 $customurl.="$key=$cgiparams{$key};";
114 }
115
116 $customurl.="submit=custom";
117 }
118
119 # Fill in the default parameters using the ones in router.pl (don't use compiled in defaults)
120
121 $cgiparams{transport}='motorcar' if(!defined $cgiparams{transport});
122
123 $transport=$cgiparams{transport};
124
125 foreach $highway (@router_highways)
126 {
127 $key="highway-$highway";
128 $value=$router_profile_highway{$highway}->{$transport};
129 $cgiparams{$key}=$value if(!defined $cgiparams{$key});
130
131 $key="speed-$highway";
132 $value=$router_profile_speed{$highway}->{$transport};
133 $cgiparams{$key}=$value if(!defined $cgiparams{$key});
134 }
135
136 foreach $property (@router_properties)
137 {
138 $key="property-$property";
139 $value=$router_profile_property{$property}->{$transport};
140 $cgiparams{$key}=$value if(!defined $cgiparams{$key});
141 }
142
143 $cgiparams{oneway} =~ s/(true|on)/1/;
144 $cgiparams{oneway} =~ s/(false|off)/0/;
145
146 foreach $restriction (@router_restrictions)
147 {
148 $key="$restriction";
149 $value=$router_profile_restrictions{$restriction}->{$transport};
150 $cgiparams{$key}=$value if(!defined $cgiparams{$key});
151 }
152
153 # Open template file before running the router (including changing directory)
154
155 open(TEMPLATE,"<noscript.template.html");
156
157 # Run the router
158
159 if($submit eq "shortest" || $submit eq "quickest")
160 {
161 ($router_uuid,$router_time,$router_result,$router_message)=&RunRouter($submit,%cgiparams);
162
163 $router_type=$submit;
164 $router_Type="Shortest" if($submit eq "shortest");
165 $router_Type="Quickest" if($submit eq "quickest");
166 }
167
168 # Generate the output
169
170 if($output eq "html" || $router_message)
171 {
172 # Parse the template and fill in the parameters
173
174 print header('text/html');
175
176 while(<TEMPLATE>)
177 {
178 if(m%<input% && m%<!-- ([^ ]+) *-->%)
179 {
180 $key=$1;
181
182 m%type="([a-z]+)"%;
183 $type=$1;
184
185 m%value="([a-z]+)"%;
186 $value=$1;
187
188 if($type eq "radio")
189 {
190 $checked="";
191 $checked="checked" if($cgiparams{$key} eq $value);
192
193 s%><!-- .+? *-->% $checked>%;
194 }
195 elsif($type eq "checkbox")
196 {
197 $checked="";
198 $checked="checked" if($cgiparams{$key});
199
200 s%><!-- .+? *-->% $checked>%;
201 }
202 elsif($type eq "text")
203 {
204 s%><!-- .+? *-->% value="$cgiparams{$key}">%;
205 }
206
207 print;
208 }
209 elsif(m%<!-- custom-url -->%)
210 {
211 s%<!-- custom-url -->%$customurl%;
212
213 print if($submit);
214 }
215 elsif(m%<!-- result-start -->%)
216 {
217 $results_section=1;
218 }
219 elsif(m%<!-- result-finish -->%)
220 {
221 $results_section=0;
222 }
223 elsif($results_section)
224 {
225 s%<!-- result-Type -->%$router_Type%;
226 s%<!-- result-type -->%$router_type%;
227 s%<!-- result-uuid -->%$router_uuid%;
228 s%<!-- result-time -->%$router_time%;
229 s%<!-- result-result -->%$router_result%;
230 s%<!-- result-message -->%$router_message%;
231
232 print if($router_uuid);
233 }
234 else
235 {
236 print;
237 }
238 }
239
240 close(TEMPLATE);
241 }
242 else
243 {
244 print header($mimetypes{$output});
245
246 system "cat $submit$formats{$output}";
247 }

Properties

Name Value
svn:executable *