]> git.ipfire.org Git - ipfire-2.x.git/blob - html/html/captive/index.cgi
Captive-Portal: add web-part
[ipfire-2.x.git] / html / html / captive / index.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 my $settings="${General::swroot}/captive/settings";
31 my $ethernet="${General::swroot}/ethernet/settings";
32 my %settingshash=();
33 my %ethernethash=();
34 my $green_ip;
35 my $green_mask;
36 my $blue_ip;
37 my $blue_mask;
38 my $target;
39 #Read settings
40 &General::readhash("$settings", \%settingshash) if(-f $settings);
41 &General::readhash("$ethernet", \%ethernethash) if(-f $ethernet);
42
43 #Get Clients IP-Address
44 my $ip_address = $ENV{X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} ||"";
45
46 if($settingshash{'ENABLE_GREEN'} eq "on" && $ethernethash{'GREEN_ADDRESS'} ne ''){
47 $green_ip=$ethernethash{'GREEN_ADDRESS'};
48 $green_mask=$ethernethash{'GREEN_NETMASK'};
49
50 if (&General::IpInSubnet($ip_address,$ethernethash{'GREEN_ADDRESS'},$ethernethash{'GREEN_NETMASK'})){
51 $target = $green_ip;
52 }
53 }elsif($settingshash{'ENABLE_BLUE'} eq "on" &&$ethernethash{'BLUE_ADDRESS'} ne '' ){
54 $blue_ip=$ethernethash{'BLUE_ADDRESS'};
55 $blue_mask=$ethernethash{'BLUE_NETMASK'};
56
57 if (&General::IpInSubnet($ip_address,$ethernethash{'BLUE_ADDRESS'},$ethernethash{'BLUE_NETMASK'})){
58 $target = $blue_ip;
59 }
60 }else{
61 exit 0;
62 }
63
64 print "Status: 302 Moved Temporarily\n";
65 print "Location: http://$target:1013/cgi-bin/index.cgi?redirect=$safe_url\n";
66 print "Connection: close\n\n";