]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/captive/redirect.cgi
ddns: Import latest upstream patches for ddns-013
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / captive / redirect.cgi
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);
30
31 my %settingshash = ();
32 my %ethernethash = ();
33 my $target;
34
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 }
51
52 } else {
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";