Imported Upstream version 1.4.1
[routino] / web / www / routino / customvisualiser.cgi
1 #!/usr/bin/perl
2 #
3 # Routino data visualiser custom link CGI
4 #
5 # Part of the Routino routing software.
6 #
7 # This file Copyright 2008,2009 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 perl CGI module
24 use CGI ':cgi';
25
26 # Create the query and get the parameters
27
28 $query=new CGI;
29
30 @rawparams=$query->param;
31
32 # Legal CGI parameters with regexp validity check
33
34 %legalparams=(
35               "lon"  => "[-0-9.]+",
36               "lat"  => "[-0-9.]+",
37               "zoom" => "[0-9]+"
38              );
39
40 # Validate the CGI parameters, ignore invalid ones
41
42 foreach $key (@rawparams)
43   {
44    foreach $test (keys (%legalparams))
45      {
46       if($key =~ m%^$test$%)
47         {
48          $value=$query->param($key);
49
50          if($value =~ m%^$legalparams{$test}$%)
51            {
52             $cgiparams{$key}=$value;
53             last;
54            }
55         }
56      }
57   }
58
59 # Open template file and output it
60
61 open(TEMPLATE,"<visualiser.html");
62
63 # Parse the template and fill in the parameters
64
65 print header('text/html');
66
67 while(<TEMPLATE>)
68   {
69    if(m%^<BODY.+>%)
70      {
71       s/'lat'/$cgiparams{'lat'}/   if(defined $cgiparams{'lat'});
72       s/'lon'/$cgiparams{'lon'}/   if(defined $cgiparams{'lon'});
73       s/'zoom'/$cgiparams{'zoom'}/ if(defined $cgiparams{'zoom'});
74       print;
75      }
76    else
77      {
78       print;
79      }
80   }
81
82 close(TEMPLATE);