Project

General

Profile

« Previous | Next » 

Revision 88479de6

Added by Jim Pingle about 4 years ago

Portal logout updates. Fixes #12138

  • Change "Connected" page to also include a logout button
  • Style page the same way as the login page for a more consistent user
    experience
  • Show the "Connected" page when a user navigates back to the portal
    URL no matter the setting of the logout popup option
  • Custom logout page still overrides the content as expected

View differences:

src/etc/inc/captiveportal.inc
42 42
define("CUSTOM_RADIUS_ACCT_OUTPUT_GIGAWORDS", "53");
43 43
define("GIGAWORDS_RIGHT_OPERAND", '4294967296'); // 2^32
44 44

  
45
function get_default_captive_portal_html() {
45
function get_captive_portal_logo() {
46 46
	global $config, $g, $cpzone;
47

  
48
	$translated_text1 = gettext("User");
49
	$translated_text2 = gettext("Password");
50
	$translated_text3 = gettext("First Authentication Method ");
51
	$translated_text4 = gettext("Second Authentication Method ");
52
	// default images to use.
53 47
	$logo_src = "captiveportal-default-logo.png";
54
	$bg_src = "linear-gradient(135deg, #1475CF, #2B40B5, #1C1275)";
55 48
	// Check if customlogo is set and if the element exists
56 49
	// Check if the image is in the directory
57 50
	if (isset($config['captiveportal'][$cpzone]['customlogo']) &&
......
66 59
			}
67 60
		}
68 61
	}
62
	return $logo_src;
63
}
64

  
65
function get_captive_portal_bg() {
66
	$bg_src = "linear-gradient(135deg, #1475CF, #2B40B5, #1C1275)";
67
	global $config, $g, $cpzone;
69 68
	// check if custombg is set and if the element exists
70 69
	if (isset($config['captiveportal'][$cpzone]['custombg']) &&
71 70
	    is_array($config['captiveportal'][$cpzone]['element']) &&
......
78 77
				}
79 78
			}
80 79
		}
81

  
82 80
	}
81
	return $bg_src;
82
}
83

  
84
function get_default_captive_portal_html() {
85
	global $config, $g, $cpzone;
86

  
87
	$translated_text1 = gettext("User");
88
	$translated_text2 = gettext("Password");
89
	$translated_text3 = gettext("First Authentication Method ");
90
	$translated_text4 = gettext("Second Authentication Method ");
91
	// default images to use.
92
	$logo_src = get_captive_portal_logo();
93
	$bg_src = get_captive_portal_bg();
83 94
	// bring in terms and conditions
84 95
	$termsconditions = base64_decode($config['captiveportal'][$cpzone]['termsconditions']);
85 96
	// if there is no terms and conditions do not require the checkbox to be selected.
src/usr/local/captiveportal/index.php
76 76
	return;
77 77
}
78 78

  
79
$cpsession = captiveportal_isip_logged($clientip);
80 79
$ourhostname = portal_hostname_from_client_ip($clientip);
80
$protocol = (isset($config['captiveportal'][$cpzone]['httpslogin'])) ? 'https://' : 'http://';
81
$logouturl = "{$protocol}{$ourhostname}/";
82

  
83
$cpsession = captiveportal_isip_logged($clientip);
84
if (!empty($cpsession)) {
85
	$sessionid = $cpsession['sessionid'];
86
}
87

  
81 88
/* Automatically switching to the logout page requires a custom logout page to be present. */
82 89
if ((!empty($cpsession)) && (! $_POST['logout_id']) && (!empty($cpcfg['page']['logouttext']))) {
83 90
	/* if client already connected and a custom logout page is set : show logout page */
84
	$protocol = (isset($config['captiveportal'][$cpzone]['httpslogin'])) ? 'https://' : 'http://';
85
	$logouturl = "{$protocol}{$ourhostname}/";
86

  
87
	$sessionid = $cpsession['sessionid'];
88 91
	$attributes = array();
89 92
	if (!empty($cpsession['session_timeout']))
90 93
		$attributes['session_timeout'] = $cpsession['session_timeout'];
......
94 97
	include("{$g['varetc_path']}/captiveportal-{$cpzone}-logout.html");
95 98
	ob_flush();
96 99
	return;
97
} elseif (!empty($cpsession) && (!isset($_POST['logout_id']) || !isset($config['captiveportal'][$cpzone]['logoutwin_enable']))) {
98
	/* If client try to access captive portal page while already connected, 
99
		but no custom logout page does exist and logout popup is disabled */	
100
	echo gettext("You are connected.<br/>");
101
	if (!empty($redirurl)) {
102
		$redirurl = htmlspecialchars($redirurl);
103
		echo ("You can proceed to: <a href='{$redirurl}'>{$redirurl}</a>");
104
	} 
100
} elseif (!empty($cpsession) && !isset($_POST['logout_id'])) {
101
	/* If the client tries to access the captive portal page while already connected,
102
		but no custom logout page exists */
103
	$logo_src = get_captive_portal_logo();
104
	$bg_src = get_captive_portal_bg();
105
?>
106
<!DOCTYPE html>
107
<html>
108
<head>
109
  <meta charset="UTF-8">
110
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
111
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
112
  <title>Captive Portal</title>
113
  <style>
114
	  #content,.login,.login-card a,.login-card h1,.login-help{text-align:center}body,html{margin:0;padding:0;width:100%;height:100%;display:table}#content{font-family:'Source Sans Pro',sans-serif;background-color:#1C1275;background:<?= $bg_src ?>;-webkit-background-size:cover;-moz-background-size:cover;-o-background-size:cover;background-size:cover;display:table-cell;vertical-align:middle}.login-card{padding:40px;width:280px;background-color:#F7F7F7;margin:100px auto 10px;border-radius:2px;box-shadow:0 2px 2px rgba(0,0,0,.3);overflow:hidden}.login-card h1{font-weight:400;font-size:2.3em;color:#1383c6}.login-card h1 span{color:#f26721}.login-card img{width:70%;height:70%}.login-card input[type=submit]{width:100%;display:block;margin-bottom:10px;position:relative}.login-card input[type=text],input[type=password]{height:44px;font-size:16px;width:100%;margin-bottom:10px;-webkit-appearance:none;background:#fff;border:1px solid #d9d9d9;border-top:1px solid silver;padding:0 8px;box-sizing:border-box;-moz-box-sizing:border-box}.login-card input[type=text]:hover,input[type=password]:hover{border:1px solid #b9b9b9;border-top:1px solid #a0a0a0;-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,.1);-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,.1);box-shadow:inset 0 1px 2px rgba(0,0,0,.1)}.login{font-size:14px;font-family:Arial,sans-serif;font-weight:700;height:36px;padding:0 8px}.login-submit{-webkit-appearance:none;-moz-appearance:none;appearance:none;border:0;color:#fff;text-shadow:0 1px rgba(0,0,0,.1);background-color:#4d90fe}.login-submit:disabled{opacity:.6}.login-submit:hover{border:0;text-shadow:0 1px rgba(0,0,0,.3);background-color:#357ae8}.login-card a{text-decoration:none;color:#222;font-weight:400;display:inline-block;opacity:.6;transition:opacity ease .5s}.login-card a:hover{opacity:1}.login-help{width:100%;font-size:12px}.list{list-style-type:none;padding:0}.list__item{margin:0 0 .7rem;padding:0}label{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;text-align:left;font-size:14px;}input[type=checkbox]{-webkit-box-flex:0;-webkit-flex:none;-ms-flex:none;flex:none;margin-right:10px;float:left}@media screen and (max-width:450px){.login-card{width:70%!important}.login-card img{width:30%;height:30%}}textarea{width:66%;margin:auto;height:120px;max-height:120px;background-color:#f7f7f7;padding:20px}#terms{display:none;padding-top:100px;padding-bottom:300px;}.auth_source{border: 1px solid lightgray; padding:20px 8px 0px 8px; margin-top: -2em; border-radius: 2px; }.auth_head{background-color:#f7f7f7;display:inline-block;}.auth_head_div{text-align:left;}#error-message{text-align:left;color:#ff3e3e;font-style:italic;}
115
  </style>
116
</head>
117

  
118
<body>
119
<div id="content">
120
	<div class="login-card">
121
		<img src="<?= $logo_src ?>"/><br>
122
		<h1></h1>
123
		<div class="login-help">
124
			<?= gettext("The portal session is connected.") ?>
125
<?php if (!empty($redirurl)):
126
		$redirurl = htmlspecialchars($redirurl); ?>
127
			<br/><br/>
128
			<?= gettext("Proceed to: ") ?>
129
			<a href="<?=$redirurl?>"><?=$redirurl?></a>
130
<?php endif; ?>
131
		</div>
132
<br/>
133
	<form method="POST" action="<?=$logouturl;?>">
134
		<input name="logout_id" type="hidden" value="<?=$sessionid;?>" />
135
		<input name="zone" type="hidden" value="<?=$cpzone;?>" />
136
		<input name="logout" type="submit" value="<?= gettext("Disconnect") ?>" />
137
	</form>
138
	<br  />
139
	<span> <i>Made with &hearts; by</i> <strong>Netgate</strong></span>
140
	</div>
141
</div>
142
</body>
143
</html>
144
<?php
105 145
	ob_flush();
106 146
	return;
107 147
} elseif ($orig_host != $ourhostname) {
......
135 175
	$safe_logout_id = SQLite3::escapeString($_POST['logout_id']);
136 176
	captiveportal_disconnect_client($safe_logout_id);
137 177
	header("Location: index.php?zone=".$cpzone);
178
	ob_flush();
179
	return;
138 180
} elseif (($_POST['accept'] || $cpcfg['auth_method'] === 'radmac' || !empty($cpcfg['blockedmacsurl'])) && $macfilter && $clientmac && captiveportal_blocked_mac($clientmac)) {
139 181
	captiveportal_logportalauth($clientmac, $clientmac, $clientip, "Blocked MAC address");
140 182
	if (!empty($cpcfg['blockedmacsurl'])) {

Also available in: Unified diff