]>
Commit | Line | Data |
---|---|---|
8b920789 AM |
1 | #!/usr/bin/perl |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2016 Alexander Marx alexander.marx@ipfire.org # | |
6 | # # | |
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. # | |
11 | # # | |
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. # | |
16 | # # | |
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/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
22 | use strict; | |
23 | use URI::Escape; | |
24 | use CGI::Carp qw(fatalsToBrowser); | |
25 | ||
26 | require '/var/ipfire/general-functions.pl'; | |
27 | ||
28 | my $url = "http://$ENV{'SERVER_NAME'}$ENV{'REQUEST_URI'}"; | |
29 | my $safe_url = uri_escape($url); | |
d57e8c67 MT |
30 | |
31 | my %settingshash = (); | |
32 | my %ethernethash = (); | |
8b920789 | 33 | my $target; |
8b920789 | 34 | |
d57e8c67 MT |
35 | # Read settings |
36 | &General::readhash("${General::swroot}/captive/settings", \%settingshash); | |
37 | &General::readhash("${General::swroot}/ethernet/settings", \%ethernethash); | |
38 | ||
39 | # Get the client's IP address | |
40 | my $client_address = $ENV{X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} || ""; | |
41 | ||
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'}; | |
45 | } | |
46 | ||
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'}; | |
50 | } | |
8b920789 | 51 | |
d57e8c67 | 52 | } else { |
8b920789 AM |
53 | exit 0; |
54 | } | |
55 | ||
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"; |