Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/web/www/routino/customrouter.cgi
Parent Directory
|
Revision Log
Revision 622 -
(show annotations)
(download)
Sat Feb 5 15:41:48 2011 UTC (14 years, 1 month ago) by amb
File size: 3486 byte(s)
Sat Feb 5 15:41:48 2011 UTC (14 years, 1 month ago) by amb
File size: 3486 byte(s)
Include the option to obey turn restrictions in the profile for each transport type.
1 | #!/usr/bin/perl |
2 | # |
3 | # Routino router custom link 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" => "[-0-9.]+", |
39 | "lat" => "[-0-9.]+", |
40 | "zoom" => "[0-9]+", |
41 | |
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 | "turns" => "(1|0|true|false|on|off)", |
50 | "weight" => "[0-9.]+", |
51 | "height" => "[0-9.]+", |
52 | "width" => "[0-9.]+", |
53 | "length" => "[0-9.]+", |
54 | |
55 | "language" => "[-a-zA-Z]+" |
56 | ); |
57 | |
58 | # Validate the CGI parameters, ignore invalid ones |
59 | |
60 | foreach $key (@rawparams) |
61 | { |
62 | foreach $test (keys (%legalparams)) |
63 | { |
64 | if($key =~ m%^$test$%) |
65 | { |
66 | $value=$query->param($key); |
67 | |
68 | if($value =~ m%^$legalparams{$test}$%) |
69 | { |
70 | $cgiparams{$key}=$value; |
71 | last; |
72 | } |
73 | } |
74 | } |
75 | } |
76 | |
77 | # Fill in the default parameters |
78 | |
79 | %fullparams=FillInDefaults(%cgiparams); |
80 | |
81 | # Open template file and output it |
82 | |
83 | $lang=$cgiparams{'language'}; |
84 | |
85 | if( -f "router.html.$lang") |
86 | { |
87 | open(TEMPLATE,"<router.html.$lang"); |
88 | } |
89 | else |
90 | { |
91 | open(TEMPLATE,"<router.html"); |
92 | } |
93 | |
94 | # Parse the template and fill in the parameters |
95 | |
96 | print header('text/html'); |
97 | |
98 | while(<TEMPLATE>) |
99 | { |
100 | if(m%^<BODY.+>%) |
101 | { |
102 | s/'lat'/$cgiparams{'lat'}/ if(defined $cgiparams{'lat'}); |
103 | s/'lon'/$cgiparams{'lon'}/ if(defined $cgiparams{'lon'}); |
104 | s/'zoom'/$cgiparams{'zoom'}/ if(defined $cgiparams{'zoom'}); |
105 | print; |
106 | } |
107 | elsif(m%<input% && m%<!-- ([^ ]+) *-->%) |
108 | { |
109 | $key=$1; |
110 | |
111 | m%type="([a-z]+)"%; |
112 | $type=$1; |
113 | |
114 | m%value="([a-z]+)"%; |
115 | $value=$1; |
116 | |
117 | if($type eq "radio") |
118 | { |
119 | $checked=""; |
120 | $checked="checked" if($fullparams{$key} eq $value); |
121 | |
122 | s%><!-- .+? *-->% $checked>%; |
123 | } |
124 | elsif($type eq "checkbox") |
125 | { |
126 | $checked=""; |
127 | $checked="checked" if($fullparams{$key}); |
128 | |
129 | s%><!-- .+? *-->% $checked>%; |
130 | } |
131 | elsif($type eq "text") |
132 | { |
133 | s%><!-- .+? *-->% value="$fullparams{$key}">%; |
134 | } |
135 | |
136 | print; |
137 | } |
138 | else |
139 | { |
140 | print; |
141 | } |
142 | } |
143 | |
144 | close(TEMPLATE); |
Properties
Name | Value |
---|---|
svn:executable | * |