128 lines
3.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WiFi Credentials</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
}
h1 {
margin: 30px 0 20px;
text-align: center;
}
form {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
margin: auto;
max-width: 500px;
}
input[type="text"], input[type="password"] {
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: none;
border-radius: 4px;
background-color: #f2f2f2;
font-size: 16px;
width: 100%;
}
button {
background-color: #2d2dfa;
color: #fff;
padding: 12px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
width: 100%;
}
button:hover {
background-color: #45a049;
}
img{
display: block;
margin-left: auto;
margin-right:auto;
height: auto;
width: auto;
max-width: 150px;
filter: drop-shadow(2px 2px 2px #666666);
}
</style>
</head>
<body>
<h1>Enter WiFi Credentials</h1>
<form id="wifi-credentials-form">
<label for="ssid">SSID:</label>
<input type="text" id="ssid" name="ssid" placeholder="SSID" required>
<label for="password">Password:</label>
<input type="text" id="password" name="password" placeholder="Password" required>
<button type="button" onclick="postCredentials(event)">Submit & ReStart</button>
<img src="img/atalogo.png" alt="Image not found" >
</form>
<script>
const form = document.querySelector('#wifi-credentials-form');
window.onload = getSSID();
function getSSID(){
const params = new URLSearchParams();
params.append('type', 'wifi');
const url = '/get?' + params.toString();
fetch(url, { method: 'GET'})
.then(response => {
if (response.ok) {
console.log('Request successful');
return response.json();
}
else { throw new Error('Request failed'); }
})
.then(data => {
console.log(data);
form.ssid.value = data.ssid;
form.password.placeholder = '*'.repeat(data.pass);
})
.catch(error => { console.error(error); });
}
function postCredentials(event){
event.preventDefault();
if(!inputValidationOk()){ return; }
var creds = {
ssid : form.ssid.value,
pass : form.password.value
};
const params = new URLSearchParams();
params.append('type', 'wifi');
const url = '/post?' + params.toString();
fetch(url, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(creds)
})
.then(response => {
if (response.ok) { console.log('Request successful'); }
else { throw new Error('Request failed'); }
})
.catch(error => { console.error(error); });
}
function inputValidationOk(){
return true;
}
</script>
</body>
</html>