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 622 - (show annotations) (download)
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 #!/usr/bin/perl
2 #
3 # Routino non-Javascript router CGI
4 #
5 # Part of the Routino routing software.
6 #
7 # This file Copyright 2008-2011 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 "turns" => "(1|0|true|false|on|off)",
46 "weight" => "[0-9.]+",
47 "height" => "[0-9.]+",
48 "width" => "[0-9.]+",
49 "length" => "[0-9.]+",
50 "length" => "[0-9.]+",
51
52 "language" => "[-a-zA-Z]+",
53 "submit" => "(shortest|quickest|link)",
54 "format" => "(html|gpx-route|gpx-track|text|text-all|form)"
55 );
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 $format=$cgiparams{format};
82 delete $cgiparams{format};
83
84 $format="form" if(!$format || ($submit ne "shortest" && $submit ne "quickest"));
85
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 # Fill in the default parameters
103
104 %fullparams=FillInDefaults(%cgiparams);
105
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 ($router_uuid,$router_time,$router_result,$router_message)=RunRouter($submit,%fullparams);
115
116 $router_type=$submit;
117 $router_Type="Shortest" if($submit eq "shortest");
118 $router_Type="Quickest" if($submit eq "quickest");
119
120 if($format ne "form")
121 {
122 ReturnOutput($router_uuid,$submit,$format);
123 exit;
124 }
125 }
126
127 # Generate the form output
128
129 print header('text/html');
130
131 # Parse the template and fill in the parameters
132
133 while(<TEMPLATE>)
134 {
135 if (m%<input% && m%<!-- ([^ ]+) *-->%)
136 {
137 $key=$1;
138
139 m%type="([a-z]+)"%;
140 $type=$1;
141
142 m%value="([a-z]+)"%;
143 $value=$1;
144
145 if ($type eq "radio")
146 {
147 $checked="";
148 $checked="checked" if($fullparams{$key} eq $value);
149
150 s%><!-- .+? *-->% $checked>%;
151 }
152 elsif ($type eq "checkbox")
153 {
154 $checked="";
155 $checked="checked" if($fullparams{$key});
156
157 s%><!-- .+? *-->% $checked>%;
158 }
159 elsif ($type eq "text")
160 {
161 s%><!-- .+? *-->% value="$fullparams{$key}">%;
162 }
163
164 print;
165 }
166 elsif (m%<!-- custom-url -->%)
167 {
168 s%<!-- custom-url -->%$customurl%;
169
170 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 }
196
197 close(TEMPLATE);

Properties

Name Value
svn:executable *