Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/web/www/routino/customrouter.cgi
Parent Directory
|
Revision Log
Revision 622 -
(hide annotations)
(download)
Sat Feb 5 15:41:48 2011 UTC (14 years, 2 months ago) by amb
File size: 3486 byte(s)
Sat Feb 5 15:41:48 2011 UTC (14 years, 2 months ago) by amb
File size: 3486 byte(s)
Include the option to obey turn restrictions in the profile for each transport type.
1 | amb | 569 | #!/usr/bin/perl |
2 | # | ||
3 | # Routino router custom link CGI | ||
4 | # | ||
5 | # Part of the Routino routing software. | ||
6 | # | ||
7 | amb | 622 | # This file Copyright 2008-2011 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" => "[-0-9.]+", |
39 | "lat" => "[-0-9.]+", | ||
40 | "zoom" => "[0-9]+", | ||
41 | amb | 569 | |
42 | amb | 574 | "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 | amb | 622 | "turns" => "(1|0|true|false|on|off)", |
50 | amb | 574 | "weight" => "[0-9.]+", |
51 | "height" => "[0-9.]+", | ||
52 | "width" => "[0-9.]+", | ||
53 | amb | 577 | "length" => "[0-9.]+", |
54 | |||
55 | "language" => "[-a-zA-Z]+" | ||
56 | amb | 569 | ); |
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 | amb | 577 | # Fill in the default parameters |
78 | amb | 569 | |
79 | amb | 577 | %fullparams=FillInDefaults(%cgiparams); |
80 | amb | 569 | |
81 | amb | 577 | # Open template file and output it |
82 | amb | 569 | |
83 | amb | 577 | $lang=$cgiparams{'language'}; |
84 | |||
85 | if( -f "router.html.$lang") | ||
86 | amb | 569 | { |
87 | amb | 577 | open(TEMPLATE,"<router.html.$lang"); |
88 | amb | 569 | } |
89 | amb | 577 | else |
90 | amb | 569 | { |
91 | amb | 577 | open(TEMPLATE,"<router.html"); |
92 | amb | 569 | } |
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 | amb | 574 | 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 | amb | 569 | 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 | amb | 577 | $checked="checked" if($fullparams{$key} eq $value); |
121 | amb | 569 | |
122 | s%><!-- .+? *-->% $checked>%; | ||
123 | } | ||
124 | elsif($type eq "checkbox") | ||
125 | { | ||
126 | $checked=""; | ||
127 | amb | 577 | $checked="checked" if($fullparams{$key}); |
128 | amb | 569 | |
129 | s%><!-- .+? *-->% $checked>%; | ||
130 | } | ||
131 | elsif($type eq "text") | ||
132 | { | ||
133 | amb | 577 | s%><!-- .+? *-->% value="$fullparams{$key}">%; |
134 | amb | 569 | } |
135 | |||
136 | print; | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | print; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | close(TEMPLATE); |
Properties
Name | Value |
---|---|
svn:executable | * |