Project

General

Profile

Feature #15904 » RFC8910-w-allowed-MAC-IP-fix.php

RFC8910 implementation CE 2.7.2 and later. - Dale Harron, 12/05/2024 10:48 PM

 
1
<?php
2

    
3
require_once("auth.inc");
4
require_once("util.inc");
5
require_once("functions.inc");
6
require_once("captiveportal.inc");
7

    
8
header("Expires: 0");
9
header("Cache-Control: no-cache, no-store, must-revalidate");
10
header("Pragma: no-cache");
11
header("Connection: close");
12

    
13
global $g, $config, $cpzone, $cpzoneid, $cpzoneprefix;
14

    
15
$cpzone = strtolower($_REQUEST['zone']);
16
$cpcfg = config_get_path("captiveportal/{$cpzone}");
17

    
18
if (empty($cpcfg)) {
19
	log_error("rfc8910.php - Submission to captiveportal with unknown parameter zone: " . htmlspecialchars($cpzone));
20
	portal_reply_page($redirurl, "error", gettext("Internal error"));
21
	ob_flush();
22
	return;
23
}
24

    
25
$cpzoneid = $cpcfg['zoneid'];
26
$clientip = $_SERVER['REMOTE_ADDR'];
27

    
28
if (is_array($cpcfg['allowedip'])) {
29
	foreach ($cpcfg['allowedip'] as $ipent) {
30
		if ($ipent['ip'] == $clientip) {
31
			if ($ipent['dir'] != 'to') {
32
				// 'clientip' is part of the 'allowedip' list
33
				ob_flush();
34
				return;
35
			}
36
		}
37
	}
38
}
39

    
40
$clientmac = pfSense_ip_to_mac($clientip);
41
if (!is_array($clientmac)) {
42
	if (!isset($cpcfg['nomacfilter']) || isset($cpcfg['passthrumacadd'])) {
43
		/* unable to find MAC address - shouldn't happen! - bail out */
44
		captiveportal_logportalauth("unauthenticated", "noclientmac", $clientip, "ERROR");
45
		echo "An error occurred.  Please check the system logs for more information.";
46
		log_error("Zone: {$cpzone} - Captive portal could not determine client's MAC address.  Disable MAC address filtering in captive portal if you do not need this functionality.");
47
		ob_flush();
48
		return;
49
	}
50
}
51
else if (is_array($cpcfg['passthrumac'])) {
52
	foreach ($cpcfg['passthrumac'] as $macent) {
53
		if ($macent['mac'] == $clientmac['macaddr']) {
54
			if ($macent['action'] == 'pass') {
55
				// 'clientmac' is part of the 'allowed MAC' list
56
				ob_flush();
57
				return;
58
			}
59
		}
60
	}
61
}
62

    
63
$cpsession = captiveportal_isip_logged($clientip);
64
$sessionid = $cpsession['sessionid'];
65
$rfc8910_url = 'https://' . $_SERVER['HTTP_HOST'] . '/index.php?zone=' . $cpzone;
66

    
67
ob_flush();
68
if (empty($cpsession)) {
69
/*	captiveportal_logportalauth("rfc8910", "EMPTY SESSION", $clientip, $cpzone); */
70
/*	$seconds_remaining = $cpcfg['timeout'] * 60; */
71
	$json_post  = array (
72
		"captive" => true,
73
		"user-portal-url" => "$rfc8910_url",
74
		"venue-info-url" => "$rfc8910_url"
75
);
76

    
77
echo json_encode($json_post, JSON_PRETTY_PRINT);
78

    
79
} else {
80
/*	captiveportal_logportalauth("rfc8910", "EXISTING SESSION", $clientip, $cpzone); */
81
/*	$seconds_remaining = (time()-$cpsession['allow_time'])+($cpcfg['timeout']*60); */
82
	$json_post  = array (
83
		"captive" => false,
84
		"user-portal-url" => "$rfc8910_url",
85
		"venue-info-url" => "$rfc8910_url"
86
);
87
echo json_encode($json_post, JSON_PRETTY_PRINT);
88

    
89
}
90
ob_flush();
91

    
92
return;
93
?>
(1-1/7)