3 # Routino non-Javascript router CGI
5 # Part of the Routino routing software.
7 # This file Copyright 2008-2010 Andrew M. Bishop
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.
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.
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/>.
23 # Use the generic router script
26 # Use the perl CGI module
29 # Create the query and get the parameters
33 @rawparams=$query->param;
35 # Legal CGI parameters with regexp validity check
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.]+",
48 "length" => "[0-9.]+",
49 "length" => "[0-9.]+",
51 "language" => "[-a-zA-Z]+",
52 "submit" => "(shortest|quickest|link)",
53 "format" => "(html|gpx-route|gpx-track|text|text-all|form)"
56 # Validate the CGI parameters, ignore invalid ones
58 foreach $key (@rawparams)
60 foreach $test (keys (%legalparams))
62 if($key =~ m%^$test$%)
64 $value=$query->param($key);
66 if($value =~ m%^$legalparams{$test}$%)
68 $cgiparams{$key}=$value;
75 # Get the important parameters
77 $submit=$cgiparams{submit};
78 delete $cgiparams{submit};
80 $format=$cgiparams{format};
81 delete $cgiparams{format};
83 $format="form" if(!$format || ($submit ne "shortest" && $submit ne "quickest"));
85 # Generate a custom URL
91 $customurl="noscript.cgi?";
93 foreach $key (sort (keys %cgiparams))
95 $customurl.="$key=$cgiparams{$key};";
98 $customurl.="submit=custom";
101 # Fill in the default parameters
103 %fullparams=FillInDefaults(%cgiparams);
105 # Open template file before running the router (including changing directory)
107 open(TEMPLATE,"<noscript.template.html");
111 if($submit eq "shortest" || $submit eq "quickest")
113 ($router_uuid,$router_time,$router_result,$router_message)=RunRouter($submit,%fullparams);
115 $router_type=$submit;
116 $router_Type="Shortest" if($submit eq "shortest");
117 $router_Type="Quickest" if($submit eq "quickest");
119 if($format ne "form")
121 ReturnOutput($router_uuid,$submit,$format);
126 # Generate the form output
128 print header('text/html');
130 # Parse the template and fill in the parameters
134 if (m%<input% && m%<!-- ([^ ]+) *-->%)
144 if ($type eq "radio")
147 $checked="checked" if($fullparams{$key} eq $value);
149 s%><!-- .+? *-->% $checked>%;
151 elsif ($type eq "checkbox")
154 $checked="checked" if($fullparams{$key});
156 s%><!-- .+? *-->% $checked>%;
158 elsif ($type eq "text")
160 s%><!-- .+? *-->% value="$fullparams{$key}">%;
165 elsif (m%<!-- custom-url -->%)
167 s%<!-- custom-url -->%$customurl%;
171 elsif (m%<!-- result-start -->%)
175 elsif (m%<!-- result-finish -->%)
179 elsif ($results_section)
181 s%<!-- result-Type -->%$router_Type%;
182 s%<!-- result-type -->%$router_type%;
183 s%<!-- result-uuid -->%$router_uuid%;
184 s%<!-- result-time -->%$router_time%;
185 s%<!-- result-result -->%$router_result%;
186 s%<!-- result-message -->%$router_message%;
188 print if($router_uuid);