1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
--- /home/eric/Téléchargements/proxy.pl
+++ /home/eric/Téléchargements/proxy_new.pl
@@ -9,7 +9,7 @@
# modules
use CGI qw/:cgi/;# pour dialoguer sur http
-$CGI::POST_MAX=1024 * 1000; # max 1000Kb posts
+$CGI::POST_MAX=1024 * 1000; # max 1000Kb posts (was 1000)
use LWP::UserAgent;
use HTTP::Headers;
use HTTP::Message;
@@ -22,9 +22,11 @@
# variables globales
our $VERSION= '0.0.1';
-# TODO : fichier de configuration par défaut
-# il peut être écrasé par la directive SetPerlVar
+# TODO : fichier de configuration par defaut
+# il peut etre ecrase par la directive SetPerlVar
my $configfile= '';
+my @urllocking=("urlduservice");#liste des URL autorisées ("url1","url2") par exemple http://services.sandre.eaufrance.fr/geo/zon_FXX?
+my $domain='domainedusiteweb'; #domaine des pages utilisant l'API geoportail
#
# Sortie en erreur
@@ -225,7 +227,7 @@
#
# Programme principal :
#
-# On récupère la GlobalRequest en premier
+# On recupere la GlobalRequest en premier
my $gr= undef;
my $cgi= undef;
if ($ENV{MOD_PERL}) {
@@ -246,6 +248,11 @@
if (!defined($url) || length($url)==0) {
notify_proxy_failure($cgi,400,'no url parameter');#RC_BAD_REQUEST
}
+# is url in @urlocking // check url and referer domain
+notify_proxy_failure($cgi,403,'Not an authorized url') unless grep {$_ eq $url} @urllocking;#RC_BAD_URL
+#check if referer domain is empty or bad domain
+notify_proxy_failure($cgi,403,'Not authorized') if ($cgi->referer() !~ m|^https?://$domain/|);#RC_BAD_REFERER
+# else continue and proxyfy
if ($url=~m/^https?:\/\//) {
proxyfy_remote($cgi,$url);
} else { |
Partager