3 # Routino router custom link 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
42 "lon[1-9]" => "[-0-9.]+",
43 "lat[1-9]" => "[-0-9.]+",
44 "transport" => "[a-z]+",
45 "highway-[a-z]+" => "[0-9.]+",
46 "speed-[a-z]+" => "[0-9.]+",
47 "property-[a-z]+" => "[0-9.]+",
48 "oneway" => "(1|0|true|false|on|off)",
49 "weight" => "[0-9.]+",
50 "height" => "[0-9.]+",
52 "length" => "[0-9.]+",
54 "language" => "[-a-zA-Z]+"
57 # Validate the CGI parameters, ignore invalid ones
59 foreach $key (@rawparams)
61 foreach $test (keys (%legalparams))
63 if($key =~ m%^$test$%)
65 $value=$query->param($key);
67 if($value =~ m%^$legalparams{$test}$%)
69 $cgiparams{$key}=$value;
76 # Fill in the default parameters
78 %fullparams=FillInDefaults(%cgiparams);
80 # Open template file and output it
82 $lang=$cgiparams{'language'};
84 if( -f "router.html.$lang")
86 open(TEMPLATE,"<router.html.$lang");
90 open(TEMPLATE,"<router.html");
93 # Parse the template and fill in the parameters
95 print header('text/html');
101 s/'lat'/$cgiparams{'lat'}/ if(defined $cgiparams{'lat'});
102 s/'lon'/$cgiparams{'lon'}/ if(defined $cgiparams{'lon'});
103 s/'zoom'/$cgiparams{'zoom'}/ if(defined $cgiparams{'zoom'});
106 elsif(m%<input% && m%<!-- ([^ ]+) *-->%)
119 $checked="checked" if($fullparams{$key} eq $value);
121 s%><!-- .+? *-->% $checked>%;
123 elsif($type eq "checkbox")
126 $checked="checked" if($fullparams{$key});
128 s%><!-- .+? *-->% $checked>%;
130 elsif($type eq "text")
132 s%><!-- .+? *-->% value="$fullparams{$key}">%;