Routino SVN Repository Browser

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

ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 585 - (hide annotations) (download)
Wed Dec 29 10:54:11 2010 UTC (14 years, 2 months ago) by amb
File size: 4669 byte(s)
Added the uncontrolled (not auto-generated) files from routino-1.5.

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

Properties

Name Value
svn:executable *