]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/captive/redirect.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2016 Alexander Marx alexander.marx@ipfire.org #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
24 use CGI
::Carp
qw(fatalsToBrowser);
26 require '/var/ipfire/general-functions.pl';
28 my $url = "http://$ENV{'SERVER_NAME'}$ENV{'REQUEST_URI'}";
29 my $safe_url = uri_escape
($url);
31 my %settingshash = ();
32 my %ethernethash = ();
36 &General
::readhash
("${General::swroot}/captive/settings", \
%settingshash);
37 &General
::readhash
("${General::swroot}/ethernet/settings", \
%ethernethash);
39 # Get the client's IP address
40 my $client_address = $ENV{X_FORWARDED_FOR
} || $ENV{REMOTE_ADDR
} || "";
42 if ($settingshash{'ENABLE_GREEN'} eq "on" && $ethernethash{'GREEN_ADDRESS'} ne '') {
43 if (&General
::IpInSubnet
($client_address, $ethernethash{'GREEN_ADDRESS'}, $ethernethash{'GREEN_NETMASK'})) {
44 $target = $ethernethash{'GREEN_ADDRESS'};
47 } elsif($settingshash{'ENABLE_BLUE'} eq "on" && $ethernethash{'BLUE_ADDRESS'} ne '') {
48 if (&General
::IpInSubnet
($client_address, $ethernethash{'BLUE_ADDRESS'}, $ethernethash{'BLUE_NETMASK'})) {
49 $target = $ethernethash{'BLUE_ADDRESS'};
56 print "Status: 302 Moved Temporarily\n";
57 print "Location: http://$target:1013/cgi-bin/index.cgi?redirect=$safe_url\n";
58 print "Connection: close\n\n";