Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/web/www/routino/noscript.cgi
Parent Directory
|
Revision Log
Revision 622 -
(hide annotations)
(download)
Sat Feb 5 15:41:48 2011 UTC (14 years, 1 month ago) by amb
File size: 4731 byte(s)
Sat Feb 5 15:41:48 2011 UTC (14 years, 1 month ago) by amb
File size: 4731 byte(s)
Include the option to obey turn restrictions in the profile for each transport type.
1 | amb | 569 | #!/usr/bin/perl |
2 | # | ||
3 | # Routino non-Javascript router CGI | ||
4 | # | ||
5 | # Part of the Routino routing software. | ||
6 | # | ||
7 | amb | 622 | # This file Copyright 2008-2011 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 | # 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 | amb | 574 | "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 | amb | 622 | "turns" => "(1|0|true|false|on|off)", |
46 | amb | 574 | "weight" => "[0-9.]+", |
47 | "height" => "[0-9.]+", | ||
48 | "width" => "[0-9.]+", | ||
49 | "length" => "[0-9.]+", | ||
50 | "length" => "[0-9.]+", | ||
51 | amb | 569 | |
52 | amb | 585 | "language" => "[-a-zA-Z]+", |
53 | amb | 574 | "submit" => "(shortest|quickest|link)", |
54 | amb | 577 | "format" => "(html|gpx-route|gpx-track|text|text-all|form)" |
55 | amb | 569 | ); |
56 | |||
57 | # Validate the CGI parameters, ignore invalid ones | ||
58 | |||
59 | foreach $key (@rawparams) | ||
60 | { | ||
61 | foreach $test (keys (%legalparams)) | ||
62 | { | ||
63 | if($key =~ m%^$test$%) | ||
64 | { | ||
65 | $value=$query->param($key); | ||
66 | |||
67 | if($value =~ m%^$legalparams{$test}$%) | ||
68 | { | ||
69 | $cgiparams{$key}=$value; | ||
70 | last; | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | |||
76 | # Get the important parameters | ||
77 | |||
78 | $submit=$cgiparams{submit}; | ||
79 | delete $cgiparams{submit}; | ||
80 | |||
81 | amb | 577 | $format=$cgiparams{format}; |
82 | delete $cgiparams{format}; | ||
83 | amb | 569 | |
84 | amb | 577 | $format="form" if(!$format || ($submit ne "shortest" && $submit ne "quickest")); |
85 | amb | 569 | |
86 | # Generate a custom URL | ||
87 | |||
88 | $customurl=""; | ||
89 | |||
90 | if($submit) | ||
91 | { | ||
92 | $customurl="noscript.cgi?"; | ||
93 | |||
94 | foreach $key (sort (keys %cgiparams)) | ||
95 | { | ||
96 | $customurl.="$key=$cgiparams{$key};"; | ||
97 | } | ||
98 | |||
99 | $customurl.="submit=custom"; | ||
100 | } | ||
101 | |||
102 | amb | 577 | # Fill in the default parameters |
103 | amb | 569 | |
104 | amb | 577 | %fullparams=FillInDefaults(%cgiparams); |
105 | amb | 569 | |
106 | # Open template file before running the router (including changing directory) | ||
107 | |||
108 | open(TEMPLATE,"<noscript.template.html"); | ||
109 | |||
110 | # Run the router | ||
111 | |||
112 | if($submit eq "shortest" || $submit eq "quickest") | ||
113 | { | ||
114 | amb | 577 | ($router_uuid,$router_time,$router_result,$router_message)=RunRouter($submit,%fullparams); |
115 | amb | 569 | |
116 | $router_type=$submit; | ||
117 | $router_Type="Shortest" if($submit eq "shortest"); | ||
118 | $router_Type="Quickest" if($submit eq "quickest"); | ||
119 | amb | 577 | |
120 | if($format ne "form") | ||
121 | { | ||
122 | ReturnOutput($router_uuid,$submit,$format); | ||
123 | exit; | ||
124 | } | ||
125 | amb | 569 | } |
126 | |||
127 | amb | 577 | # Generate the form output |
128 | amb | 569 | |
129 | amb | 577 | print header('text/html'); |
130 | amb | 569 | |
131 | amb | 577 | # Parse the template and fill in the parameters |
132 | amb | 569 | |
133 | amb | 577 | while(<TEMPLATE>) |
134 | { | ||
135 | if (m%<input% && m%<!-- ([^ ]+) *-->%) | ||
136 | amb | 569 | { |
137 | amb | 577 | $key=$1; |
138 | amb | 569 | |
139 | amb | 577 | m%type="([a-z]+)"%; |
140 | $type=$1; | ||
141 | amb | 569 | |
142 | amb | 577 | m%value="([a-z]+)"%; |
143 | $value=$1; | ||
144 | amb | 569 | |
145 | amb | 577 | if ($type eq "radio") |
146 | { | ||
147 | $checked=""; | ||
148 | $checked="checked" if($fullparams{$key} eq $value); | ||
149 | amb | 569 | |
150 | amb | 577 | s%><!-- .+? *-->% $checked>%; |
151 | amb | 569 | } |
152 | amb | 577 | elsif ($type eq "checkbox") |
153 | amb | 569 | { |
154 | amb | 577 | $checked=""; |
155 | $checked="checked" if($fullparams{$key}); | ||
156 | amb | 569 | |
157 | amb | 577 | s%><!-- .+? *-->% $checked>%; |
158 | amb | 569 | } |
159 | amb | 577 | elsif ($type eq "text") |
160 | amb | 569 | { |
161 | amb | 577 | s%><!-- .+? *-->% value="$fullparams{$key}">%; |
162 | amb | 569 | } |
163 | |||
164 | amb | 577 | print; |
165 | amb | 569 | } |
166 | amb | 577 | elsif (m%<!-- custom-url -->%) |
167 | { | ||
168 | s%<!-- custom-url -->%$customurl%; | ||
169 | amb | 569 | |
170 | amb | 577 | print if($submit); |
171 | } | ||
172 | elsif (m%<!-- result-start -->%) | ||
173 | { | ||
174 | $results_section=1; | ||
175 | } | ||
176 | elsif (m%<!-- result-finish -->%) | ||
177 | { | ||
178 | $results_section=0; | ||
179 | } | ||
180 | elsif ($results_section) | ||
181 | { | ||
182 | s%<!-- result-Type -->%$router_Type%; | ||
183 | s%<!-- result-type -->%$router_type%; | ||
184 | s%<!-- result-uuid -->%$router_uuid%; | ||
185 | s%<!-- result-time -->%$router_time%; | ||
186 | s%<!-- result-result -->%$router_result%; | ||
187 | s%<!-- result-message -->%$router_message%; | ||
188 | |||
189 | print if($router_uuid); | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | print; | ||
194 | } | ||
195 | amb | 569 | } |
196 | |||
197 | amb | 577 | close(TEMPLATE); |
Properties
Name | Value |
---|---|
svn:executable | * |