Einstellungsseite, Skoda-Seite und Karte
Sammelstand der offenen Arbeit im Dashboard. Einstellungen: eine Eingabemaske fuer die Energiepreise unter restricted/settings.php, dazu costs.php als Modell und ajax/settings.php als Endpunkt. Die Preise stehen jetzt in gridCosts, gasCosts und fuelCosts statt fest im Quelltext von getStats.php; die Jahresstatistik rechnet ueber LEAD() den jeweils gueltigen Zeitraum aus und schlaegt den anteiligen Grundpreis auf. Eingegeben wird in gewohnten Einheiten - l/100 km, kWh/100 km, Euro je Liter -, umgerechnet wird beim Speichern. solarLog_costs.sql beschreibt die Umstellung der Tabellen. Skoda: eigene Seite mit Live-Werten ueber MQTT und Historie ueber ajax/skoda.php, Kommandos ueber ajax/skodaCmd.php. Karte: Leaflet mit einem eigenen Kachel-Zwischenspeicher (ajax/tile.php), dessen Ablage unter tiles/ nicht ins Repository gehoert. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,132 +1,136 @@
|
||||
<?php
|
||||
require_once("helper.php");
|
||||
|
||||
if (isset($_GET["addUser"])) {
|
||||
if (checkAdduser($_GET["addUser"])) {
|
||||
echo <<<ENDE
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>Smarthome control</title>
|
||||
<link rel="icon" type="image/png" href="assets/img/favicon.png">
|
||||
<!--end::Accessibility Meta Tags-->
|
||||
|
||||
<!--begin::Primary Meta Tags-->
|
||||
<meta name="title" content="Smarthome control" />
|
||||
<meta name="author" content="ColorlibHQ" />
|
||||
<meta name="description" content="Smarthome control panel by m0." />
|
||||
<meta name="keywords" content="smarthome dashboard, admin panel" />
|
||||
<!--end::Primary Meta Tags-->
|
||||
|
||||
<!--begin::Fonts-->
|
||||
<link rel="stylesheet" href="assets/fonts/font_poppins.css" media="print" onload="this.media='all'" />
|
||||
<!--end::Fonts-->
|
||||
|
||||
<!--begin::Third Party Plugin(Bootstrap Icons)-->
|
||||
<link rel="stylesheet" href="css/bootstrap-icons.min.css" />
|
||||
<!--end::Third Party Plugin(Bootstrap Icons)-->
|
||||
|
||||
<!--begin::Required Plugin(AdminLTE)-->
|
||||
<link rel="stylesheet" href="./css/adminlte.min.css?v=2" />
|
||||
<!--end::Required Plugin(AdminLTE)-->
|
||||
|
||||
|
||||
</head>
|
||||
<body onload="createRegistration()">
|
||||
</body>
|
||||
<script src="js/auth.js"></script>
|
||||
<script>
|
||||
async function createRegistration() {
|
||||
try {
|
||||
// check browser support
|
||||
if (!window.fetch || !navigator.credentials || !navigator.credentials.create) {
|
||||
throw new Error('Browser not supported.');
|
||||
}
|
||||
let keyName = encodeURIComponent(prompt('Bitte Hier den Namen des Schlüssels eingeben:'));
|
||||
// get create args
|
||||
let rep = await window.fetch('authServer.php?fn=getCreateArgs', {method:'GET', cache:'no-cache'});
|
||||
//alert(await rep.text());
|
||||
const createArgs = await rep.json();
|
||||
// error handling
|
||||
if (createArgs.success === false) {
|
||||
throw new Error(createArgs.msg || 'unknown error occured');
|
||||
}
|
||||
|
||||
// replace binary base64 data with ArrayBuffer. a other way to do this
|
||||
// is the reviver function of JSON.parse()
|
||||
recursiveBase64StrToArrayBuffer(createArgs);
|
||||
|
||||
// create credentials
|
||||
const cred = await navigator.credentials.create(createArgs);
|
||||
|
||||
// create object
|
||||
const authenticatorAttestationResponse = {
|
||||
transports: cred.response.getTransports ? cred.response.getTransports() : null,
|
||||
clientDataJSON: cred.response.clientDataJSON ? arrayBufferToBase64(cred.response.clientDataJSON) : null,
|
||||
attestationObject: cred.response.attestationObject ? arrayBufferToBase64(cred.response.attestationObject) : null
|
||||
};
|
||||
|
||||
// check auth on server side
|
||||
rep = await window.fetch('authServer.php?fn=processCreate&name='+keyName, {
|
||||
method : 'POST',
|
||||
body : JSON.stringify(authenticatorAttestationResponse),
|
||||
cache : 'no-cache'
|
||||
});
|
||||
authenticatorAttestationServerResponse = await rep.json();
|
||||
// prompt server response
|
||||
if (authenticatorAttestationServerResponse.success) {
|
||||
window.alert(authenticatorAttestationServerResponse.msg || 'registration success');
|
||||
if(!authenticatorAttestationServerResponse.msg){
|
||||
window.location.href = "https://nas.el-wa.org/smart";
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new Error(authenticatorAttestationServerResponse.msg);
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
window.alert(err.message || 'unknown error occured');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
ENDE;
|
||||
}
|
||||
} else if (checkLogin()) {
|
||||
/*
|
||||
* Seitentabelle: Vorlage, Seitenskripte und welche Bibliotheken die Seite
|
||||
* ueberhaupt braucht. Frueher wurden Chart.js, MQTT & Co. auf jeder Seite
|
||||
* geladen - die Home-Seite etwa zeichnet gar keine Diagramme.
|
||||
*/
|
||||
$pages = [
|
||||
"solar" => ["template" => "solar.php", "mqtt" => true, "charts" => true, "meteogram" => true,
|
||||
"scripts" => ["js/solar/solarMQTT.js"]],
|
||||
"home" => ["template" => "home.php", "mqtt" => true, "charts" => false, "meteogram" => false,
|
||||
"scripts" => ["js/solar/autoActionFuncs.js", "js/solar/homeMQTT.js"]],
|
||||
"heat" => ["template" => "heat.php", "mqtt" => true, "charts" => true, "meteogram" => false,
|
||||
"scripts" => ["js/solar/heatMQTT.js"]],
|
||||
"history" => ["template" => "history.php", "mqtt" => false, "charts" => true, "meteogram" => false,
|
||||
"scripts" => ["js/solar/historyMQTT.js"]],
|
||||
"weather" => ["template" => "weather.php", "mqtt" => true, "charts" => false, "meteogram" => true,
|
||||
"scripts" => ["js/solar/weatherMQTT.js"]],
|
||||
];
|
||||
|
||||
// Unbekannte oder fehlende Aktion faellt auf die Solar-Seite zurueck.
|
||||
if (!isset($_GET["action"]) || !isset($pages[$_GET["action"]])) {
|
||||
$_GET["action"] = "solar";
|
||||
}
|
||||
$page = $pages[$_GET["action"]];
|
||||
|
||||
include "restricted/header.php";
|
||||
include "restricted/" . $page["template"];
|
||||
include "restricted/footer.php";
|
||||
} else {
|
||||
echo <<<ENDE
|
||||
<html>
|
||||
<head><link rel="icon" type="image/png" href="assets/img/favicon.png"></head>
|
||||
<body onload="checkRegistration()">
|
||||
<script src="js/auth.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
ENDE;
|
||||
}
|
||||
<?php
|
||||
require_once("helper.php");
|
||||
|
||||
if (isset($_GET["addUser"])) {
|
||||
if (checkAdduser($_GET["addUser"])) {
|
||||
echo <<<ENDE
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>Smarthome control</title>
|
||||
<link rel="icon" type="image/png" href="assets/img/favicon.png">
|
||||
<!--end::Accessibility Meta Tags-->
|
||||
|
||||
<!--begin::Primary Meta Tags-->
|
||||
<meta name="title" content="Smarthome control" />
|
||||
<meta name="author" content="ColorlibHQ" />
|
||||
<meta name="description" content="Smarthome control panel by m0." />
|
||||
<meta name="keywords" content="smarthome dashboard, admin panel" />
|
||||
<!--end::Primary Meta Tags-->
|
||||
|
||||
<!--begin::Fonts-->
|
||||
<link rel="stylesheet" href="assets/fonts/font_poppins.css" media="print" onload="this.media='all'" />
|
||||
<!--end::Fonts-->
|
||||
|
||||
<!--begin::Third Party Plugin(Bootstrap Icons)-->
|
||||
<link rel="stylesheet" href="css/bootstrap-icons.min.css" />
|
||||
<!--end::Third Party Plugin(Bootstrap Icons)-->
|
||||
|
||||
<!--begin::Required Plugin(AdminLTE)-->
|
||||
<link rel="stylesheet" href="./css/adminlte.min.css?v=2" />
|
||||
<!--end::Required Plugin(AdminLTE)-->
|
||||
|
||||
|
||||
</head>
|
||||
<body onload="createRegistration()">
|
||||
</body>
|
||||
<script src="js/auth.js"></script>
|
||||
<script>
|
||||
async function createRegistration() {
|
||||
try {
|
||||
// check browser support
|
||||
if (!window.fetch || !navigator.credentials || !navigator.credentials.create) {
|
||||
throw new Error('Browser not supported.');
|
||||
}
|
||||
let keyName = encodeURIComponent(prompt('Bitte Hier den Namen des Schlüssels eingeben:'));
|
||||
// get create args
|
||||
let rep = await window.fetch('authServer.php?fn=getCreateArgs', {method:'GET', cache:'no-cache'});
|
||||
//alert(await rep.text());
|
||||
const createArgs = await rep.json();
|
||||
// error handling
|
||||
if (createArgs.success === false) {
|
||||
throw new Error(createArgs.msg || 'unknown error occured');
|
||||
}
|
||||
|
||||
// replace binary base64 data with ArrayBuffer. a other way to do this
|
||||
// is the reviver function of JSON.parse()
|
||||
recursiveBase64StrToArrayBuffer(createArgs);
|
||||
|
||||
// create credentials
|
||||
const cred = await navigator.credentials.create(createArgs);
|
||||
|
||||
// create object
|
||||
const authenticatorAttestationResponse = {
|
||||
transports: cred.response.getTransports ? cred.response.getTransports() : null,
|
||||
clientDataJSON: cred.response.clientDataJSON ? arrayBufferToBase64(cred.response.clientDataJSON) : null,
|
||||
attestationObject: cred.response.attestationObject ? arrayBufferToBase64(cred.response.attestationObject) : null
|
||||
};
|
||||
|
||||
// check auth on server side
|
||||
rep = await window.fetch('authServer.php?fn=processCreate&name='+keyName, {
|
||||
method : 'POST',
|
||||
body : JSON.stringify(authenticatorAttestationResponse),
|
||||
cache : 'no-cache'
|
||||
});
|
||||
authenticatorAttestationServerResponse = await rep.json();
|
||||
// prompt server response
|
||||
if (authenticatorAttestationServerResponse.success) {
|
||||
window.alert(authenticatorAttestationServerResponse.msg || 'registration success');
|
||||
if(!authenticatorAttestationServerResponse.msg){
|
||||
window.location.href = "https://nas.el-wa.org/smart";
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new Error(authenticatorAttestationServerResponse.msg);
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
window.alert(err.message || 'unknown error occured');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
ENDE;
|
||||
}
|
||||
} else if (checkLogin()) {
|
||||
/*
|
||||
* Seitentabelle: Vorlage, Seitenskripte und welche Bibliotheken die Seite
|
||||
* ueberhaupt braucht. Frueher wurden Chart.js, MQTT & Co. auf jeder Seite
|
||||
* geladen - die Home-Seite etwa zeichnet gar keine Diagramme.
|
||||
*/
|
||||
$pages = [
|
||||
"solar" => ["template" => "solar.php", "mqtt" => true, "charts" => true, "meteogram" => true, "leaflet" => false,
|
||||
"scripts" => ["js/solar/solarMQTT.js"]],
|
||||
"home" => ["template" => "home.php", "mqtt" => true, "charts" => false, "meteogram" => false, "leaflet" => false,
|
||||
"scripts" => ["js/solar/autoActionFuncs.js", "js/solar/homeMQTT.js"]],
|
||||
"heat" => ["template" => "heat.php", "mqtt" => true, "charts" => true, "meteogram" => false, "leaflet" => false,
|
||||
"scripts" => ["js/solar/heatMQTT.js"]],
|
||||
"history" => ["template" => "history.php", "mqtt" => false, "charts" => true, "meteogram" => false, "leaflet" => false,
|
||||
"scripts" => ["js/solar/historyMQTT.js"]],
|
||||
"skoda" => ["template" => "skoda.php", "mqtt" => true, "charts" => true, "meteogram" => false, "leaflet" => true,
|
||||
"scripts" => ["js/solar/skodaMQTT.js"]],
|
||||
"weather" => ["template" => "weather.php", "mqtt" => true, "charts" => false, "meteogram" => true, "leaflet" => false,
|
||||
"scripts" => ["js/solar/weatherMQTT.js"]],
|
||||
"settings" => ["template" => "settings.php", "mqtt" => false, "charts" => false, "meteogram" => false, "leaflet" => false,
|
||||
"scripts" => ["js/solar/settings.js"]],
|
||||
];
|
||||
|
||||
// Unbekannte oder fehlende Aktion faellt auf die Solar-Seite zurueck.
|
||||
if (!isset($_GET["action"]) || !isset($pages[$_GET["action"]])) {
|
||||
$_GET["action"] = "solar";
|
||||
}
|
||||
$page = $pages[$_GET["action"]];
|
||||
|
||||
include "restricted/header.php";
|
||||
include "restricted/" . $page["template"];
|
||||
include "restricted/footer.php";
|
||||
} else {
|
||||
echo <<<ENDE
|
||||
<html>
|
||||
<head><link rel="icon" type="image/png" href="assets/img/favicon.png"></head>
|
||||
<body onload="checkRegistration()">
|
||||
<script src="js/auth.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
ENDE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user