| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# Routino data visualiser CGI |
| 4 |
# |
| 5 |
# Part of the Routino routing software. |
| 6 |
# |
| 7 |
# This file Copyright 2008-2014, 2016 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 strict; |
| 24 |
|
| 25 |
# Use the directory paths script |
| 26 |
require "./paths.pl"; |
| 27 |
|
| 28 |
# Use the perl CGI module |
| 29 |
use CGI ':cgi'; |
| 30 |
|
| 31 |
|
| 32 |
# Create the query and get the parameters |
| 33 |
|
| 34 |
my $query=new CGI; |
| 35 |
|
| 36 |
my @rawparams=$query->param; |
| 37 |
|
| 38 |
# Legal CGI parameters with regexp validity check |
| 39 |
|
| 40 |
my %legalparams=( |
| 41 |
"latmin" => "[-0-9.]+", |
| 42 |
"latmax" => "[-0-9.]+", |
| 43 |
"lonmin" => "[-0-9.]+", |
| 44 |
"lonmax" => "[-0-9.]+", |
| 45 |
"data" => "fixmes", |
| 46 |
"dump" => "fixme[0-9]+", |
| 47 |
"statistics" => "yes" |
| 48 |
); |
| 49 |
|
| 50 |
# Validate the CGI parameters, ignore invalid ones |
| 51 |
|
| 52 |
my %cgiparams=(); |
| 53 |
|
| 54 |
foreach my $key (@rawparams) |
| 55 |
{ |
| 56 |
foreach my $test (keys (%legalparams)) |
| 57 |
{ |
| 58 |
if($key =~ m%^$test$%) |
| 59 |
{ |
| 60 |
my $value=$query->param($key); |
| 61 |
|
| 62 |
if($value =~ m%^$legalparams{$test}$%) |
| 63 |
{ |
| 64 |
$cgiparams{$key}=$value; |
| 65 |
last; |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
# Data, dump or statistics? |
| 72 |
|
| 73 |
my $params=""; |
| 74 |
|
| 75 |
my $data =$cgiparams{"data"}; |
| 76 |
my $dump =$cgiparams{"dump"}; |
| 77 |
my $statistics=$cgiparams{"statistics"}; |
| 78 |
|
| 79 |
if(!defined $data && !defined $dump && !defined $statistics) |
| 80 |
{ |
| 81 |
print header(-status => '500 Invalid CGI parameters'); |
| 82 |
exit; |
| 83 |
} |
| 84 |
|
| 85 |
if(defined $statistics) |
| 86 |
{ |
| 87 |
# Print the output |
| 88 |
|
| 89 |
print header('text/plain'); |
| 90 |
|
| 91 |
# Set the parameters |
| 92 |
|
| 93 |
$params.=" --statistics"; |
| 94 |
} |
| 95 |
elsif(defined $data) |
| 96 |
{ |
| 97 |
# Parameters to limit range selected |
| 98 |
|
| 99 |
my $limits=0.5; |
| 100 |
|
| 101 |
# Check the parameters |
| 102 |
|
| 103 |
my $latmin=$cgiparams{"latmin"}; |
| 104 |
my $latmax=$cgiparams{"latmax"}; |
| 105 |
my $lonmin=$cgiparams{"lonmin"}; |
| 106 |
my $lonmax=$cgiparams{"lonmax"}; |
| 107 |
|
| 108 |
if($latmin eq "" || $latmax eq "" || $lonmin eq "" || $lonmax eq "" || $data eq "") |
| 109 |
{ |
| 110 |
print header(-status => '500 Invalid CGI parameters'); |
| 111 |
exit; |
| 112 |
} |
| 113 |
|
| 114 |
if(($latmax-$latmin)>$limits || ($lonmax-$lonmin)>$limits) |
| 115 |
{ |
| 116 |
print header(-status => '500 Selected area too large'); |
| 117 |
exit; |
| 118 |
} |
| 119 |
|
| 120 |
# Print the output |
| 121 |
|
| 122 |
print header('text/plain'); |
| 123 |
|
| 124 |
print "$latmin $lonmin $latmax $lonmax\n"; |
| 125 |
|
| 126 |
# Set the parameters |
| 127 |
|
| 128 |
$params.=" --visualiser --data=$data"; |
| 129 |
$params.=" --latmin=$latmin --latmax=$latmax --lonmin=$lonmin --lonmax=$lonmax"; |
| 130 |
} |
| 131 |
else |
| 132 |
{ |
| 133 |
# Print the output |
| 134 |
|
| 135 |
print header('text/plain'); |
| 136 |
|
| 137 |
# Set the parameters |
| 138 |
|
| 139 |
$params.=" --dump-visualiser --data=$dump"; |
| 140 |
} |
| 141 |
|
| 142 |
# Run the filedumper |
| 143 |
|
| 144 |
$params.=" --dir=$main::data_dir" if($main::data_dir); |
| 145 |
$params.=" --prefix=$main::data_prefix" if($main::data_prefix); |
| 146 |
|
| 147 |
system "$main::bin_dir/$main::fixme_dumper_exe $params 2>&1"; |