uspot: use static html files

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2024-08-05 09:12:47 +02:00
parent 51437a78c0
commit b5eef3e284
15 changed files with 198 additions and 137 deletions

View File

@@ -1,8 +0,0 @@
Status: 200 OK
Content-Type: text/html
{{ header }}
<h1> Connected </h1>
{{ footer }}

View File

@@ -1,11 +0,0 @@
Status: 200 OK
Content-Type: text/html
{{ header }}
{{ form_data.username }}
{{ form_data.password }}
<h1> Radius auth </h1>
{{ footer }}

View File

@@ -1,19 +0,0 @@
Status: 200 OK
Content-Type: text/html
{{ header }}
{% if (error): %}
<h1> {{ PO('accept_terms_error', 'Please accept the terms of use.') }} </h1>
{% endif %}
<h5 class="card-title">{{ PO('welcome', 'Welcome!') }}</h5>
<p class="card-text">{{ PO('accept_terms_header', 'To access the Internet you must Accept the Terms of Service.') }}</p>
<hr>
<form action="/hotspot" method="post">
<input type="hidden" name="action" value="click">
<input type="checkbox" name="accept_terms" value="clicked">{{ PO('accept_terms_checkbox', 'I accept the terms of use') }}
<input type="submit" value="{{ PO('accept_terms_button', 'Accept Terms of Service') }}" class="btn btn-primary btn-block">
{% if (query_string?.redir): %}
<input type="hidden" name="redir" value="{{ query_string.redir }}">
{% endif %}
</form>
{{ footer }}

View File

@@ -1,8 +0,0 @@
Status: 200 OK
Content-Type: text/html
{{ header }}
<h1> you are already Connected </h1>
{{ footer }}

View File

@@ -1,22 +0,0 @@
Status: 200 OK
Content-Type: text/html
{{ header }}
{% if (error): %}
<h2> Invalid credentials </h2>
{% endif %}
<form action="/hotspot" method="POST">
<table>
<tr><td><label for="fname">Username:</label></td>
<td><input type="text" name="username"></td>
</tr>
<tr><td><label for="fname">Password:</label></td>
<td><input type="password" name="password"></td>
</tr>
</table>
<input type="hidden" name="action" value="credentials">
<input type="submit" value="Login" class="btn btn-primary btn-block">
</form>
{{ footer }}

View File

@@ -1,9 +0,0 @@
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@@ -10,13 +10,13 @@ function request_start(ctx) {
portal.debug(ctx, 'start ' + (ctx.config.auth_mode || '') + ' flow');
switch (ctx.config.auth_mode) {
case 'click-to-continue':
include('click.uc', ctx);
include('serve.uc', { location: '/click.html' });
return;
case 'credentials':
include('credentials.uc', ctx);
include('serve.uc', { location: '/credentials.html' });
return;
case 'radius':
include('radius.uc', ctx);
include('serve.uc', { location: '/radius.html' });
return;
case 'uam':
// try mac-auth first if enabled

View File

@@ -6,29 +6,6 @@ let uci = require('uci').cursor();
let config = uci.get_all('uspot');
let nl = require("nl80211");
let file = fs.open('/usr/share/uspot/header', 'r');
let header = file.read('all');
file.close();
file = fs.open('/usr/share/uspot/footer', 'r');
let footer = file.read('all');
file.close();
let header_custom;
let footer_custom;
file = fs.open('/tmp/ucentral/www-uspot/header.html', 'r');
if (file) {
header_custom = file.read('all');
file.close();
}
file = fs.open('/tmp/ucentral/www-uspot/footer.html', 'r');
if (file) {
footer_custom = file.read('all');
file.close();
}
let devices = {};
uci.foreach('uspot', 'uspot', (d) => {
function adddev(ifname, sname) {
@@ -81,8 +58,6 @@ return {
uam: require('uam'),
uci,
config,
header,
footer,
// syslog helper
syslog: function(ctx, msg) {
@@ -163,16 +138,17 @@ return {
"connect": time(),
}
});
if (ctx.query_string.userurl)
include('redir.uc', { redir_location: ctx.query_string.userurl });
else
include('allow.uc', ctx);
// start accounting
ctx.ubus.call('uspot', 'client_add', {
interface: ctx.spotfilter,
address: ctx.mac,
});
if (ctx.query_string.userurl)
include('redir.uc', { redir_location: ctx.query_string.userurl });
else
include('serve.uc', { location: '/allow.html' });
},
// put a client back into pre-auth state
@@ -260,7 +236,7 @@ return {
let form_data = {};
let query_string = {};
let post_data = '';
let ctx = { env, header: this.header, footer: this.footer, mac, form_data, post_data, query_string, config: this.config, PO };
let ctx = { env, mac, form_data, post_data, query_string, config: this.config, PO };
// lookup the peers MAC
let macs = this.rtnl.request(this.rtnl.const.RTM_GETNEIGH, this.rtnl.const.NLM_F_DUMP, { });
@@ -277,10 +253,6 @@ return {
ctx.spotfilter = lookup_station(ctx.mac);
ctx.config = config[ctx.spotfilter] || {};
ctx.format_mac = this.format_mac(ctx.config.mac_format, ctx.mac);
if (+ctx.config.web_root) {
ctx.header = header_custom;
ctx.footer = footer_custom;
}
// check if a client is already connected
ctx.ubus = ubus.connect();
@@ -304,7 +276,7 @@ return {
this.logoff(ctx, false);
break;
default:
include('connected.uc', ctx);
include('serve.uc', { location: '/connected.html' });
break;
}
return;

View File

@@ -1,22 +0,0 @@
Status: 200 OK
Content-Type: text/html
{{ header }}
{% if (error): %}
<h2> Invalid credentials </h2>
{% endif %}
<form action="/hotspot" method="POST">
<table>
<tr><td><label for="fname">Username:</label></td>
<td><input type="text" name="username"></td>
</tr>
<tr><td><label for="fname">Password:</label></td>
<td><input type="password" name="password"></td>
</tr>
</table>
<input type="hidden" name="action" value="radius">
<input type="submit" value="Login" class="btn btn-primary btn-block">
</form>
{{ footer }}

View File

@@ -0,0 +1,5 @@
Status: 200 OK
Content-Type: text/html
{% let fs = require('fs'); %}
{{ fs.readfile('/tmp/ucentral/www-uspot/' + location) }}

View File

@@ -23,3 +23,13 @@
<div class="card">
<div class="card-header">uCentral - Captive Portal</div>
<div class="card-body">
<h1> Connected </h1>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/images/splash.jpg" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/captive-portal.css">
<title>uCentral - Captive Portal</title>
</head>
<body>
<div id="root">
<div class="portal flex-column align-items-center">
<div class="container">
<div class="justify-content-center row">
<div class="col-md-8">
<img class="c-sidebar-brand-full" src="/images/OpenWiFi_LogoLockup_DarkGreyColour.svg" alt="OpenWifi" style="padding-left: 17%; width: 85%;">
<div class="card">
<div class="card-header">uCentral - Captive Portal</div>
<div class="card-body">
<h5 class="card-title">Welcome!</h5>
<p class="card-text">To access the Internet you must Accept the Terms of Service.</p>
<hr>
<form action="/hotspot" method="post">
<input type="hidden" name="action" value="click">
<input type="checkbox" name="accept_terms" value="clicked">I accept the terms of use
<input type="submit" value="Accept Terms of Service" class="btn btn-primary btn-block">
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/images/splash.jpg" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/captive-portal.css">
<title>uCentral - Captive Portal</title>
</head>
<body>
<div id="root">
<div class="portal flex-column align-items-center">
<div class="container">
<div class="justify-content-center row">
<div class="col-md-8">
<img class="c-sidebar-brand-full" src="/images/OpenWiFi_LogoLockup_DarkGreyColour.svg" alt="OpenWifi" style="padding-left: 17%; width: 85%;">
<div class="card">
<div class="card-header">uCentral - Captive Portal</div>
<div class="card-body">
<h1> You are already Connected </h1>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/images/splash.jpg" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/captive-portal.css">
<title>uCentral - Captive Portal</title>
</head>
<body>
<div id="root">
<div class="portal flex-column align-items-center">
<div class="container">
<div class="justify-content-center row">
<div class="col-md-8">
<img class="c-sidebar-brand-full" src="/images/OpenWiFi_LogoLockup_DarkGreyColour.svg" alt="OpenWifi" style="padding-left: 17%; width: 85%;">
<div class="card">
<div class="card-header">uCentral - Captive Portal</div>
<div class="card-body">
<form action="/hotspot" method="POST">
<table>
<tr>
<td><label for="fname">Username:</label></td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td><label for="fname">Password:</label></td>
<td><input type="password" name="password"></td>
</tr>
</table>
<input type="hidden" name="action" value="credentials">
<input type="submit" value="Login" class="btn btn-primary btn-block">
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/images/splash.jpg" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/captive-portal.css">
<title>uCentral - Captive Portal</title>
</head>
<body>
<div id="root">
<div class="portal flex-column align-items-center">
<div class="container">
<div class="justify-content-center row">
<div class="col-md-8">
<img class="c-sidebar-brand-full" src="/images/OpenWiFi_LogoLockup_DarkGreyColour.svg" alt="OpenWifi" style="padding-left: 17%; width: 85%;">
<div class="card">
<div class="card-header">uCentral - Captive Portal</div>
<div class="card-body">
<form action="/hotspot" method="POST">
<table>
<tr>
<td><label for="fname">Username:</label></td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td><label for="fname">Password:</label></td>
<td><input type="password" name="password"></td>
</tr>
</table>
<input type="hidden" name="action" value="radius">
<input type="submit" value="Login" class="btn btn-primary btn-block">
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>