This commit is contained in:
Matthew Frost 2024-04-15 22:09:24 +02:00
parent 9f483b89c4
commit 7ebf25d586
5 changed files with 153 additions and 187 deletions

View file

@ -111,7 +111,6 @@
<body>
<div class="navbar">
<a class="active" href="/">Home</a>
<a href="docs">API Docs</a>
<a href="update">Update</a>
<span class="version" id="version">Version: <span id="versionNumber"></span></span>
</div>
@ -121,7 +120,109 @@
<h3>Latest News</h3>
<p>Added API docs and Serial Interface docs. To access the API docs, click on "docs" in the navbar. For the Serial docs, just type "help" on the serial CLI.</p>
</div>
<hr>
<div>
<table>
<tr>
<th style="text-align: left;">Endpoint</th>
<th>HTTP Method</th>
<th>Parameters</th>
<th>Description</th>
</tr>
<tr>
<td style="text-align: left;">/</td>
<td>GET</td>
<td>N/A</td>
<td>Serves the index.html file</td>
</tr>
<tr>
<td style="text-align: left;">/version</td>
<td>GET</td>
<td>N/A</td>
<td>Returns the version number</td>
</tr>
<tr>
<td style="text-align: left;">/gpio</td>
<td>POST</td>
<td>output, state</td>
<td>Controls the GPIO pin</td>
</tr>
<tr>
<td style="text-align: left;">/state/relay1</td>
<td>GET</td>
<td>N/A</td>
<td>Returns the state of relay1</td>
</tr>
<tr>
<td style="text-align: left;">/settings/doordisabled</td>
<td>GET, POST</td>
<td>value</td>
<td>Gets or sets the door disabled value</td>
</tr>
<tr>
<td style="text-align: left;">/settings/tinance2creds</td>
<td>GET, POST</td>
<td>identifier, key</td>
<td>Gets or sets the Tinance credentials</td>
</tr>
<tr>
<td style="text-align: left;">/settings/tinance2url</td>
<td>GET, POST</td>
<td>url</td>
<td>Gets or sets the Tinance URL</td>
</tr>
<tr>
<td style="text-align: left;">/settings/tinance2validatecardurl</td>
<td>GET</td>
<td>N/A</td>
<td>Returns the validate card URL</td>
</tr>
<tr>
<td style="text-align: left;">/settings/tinance2readerinfourl</td>
<td>GET</td>
<td>N/A</td>
<td>Returns the reader info URL</td>
</tr>
<tr>
<td style="text-align: left;">/settings/tinance2aclsurl</td>
<td>GET</td>
<td>N/A</td>
<td>Returns the ACLs URL</td>
</tr>
<tr>
<td style="text-align: left;">/settings/tinance2logurl</td>
<td>GET</td>
<td>N/A</td>
<td>Returns the reader log URL</td>
</tr>
<tr>
<td style="text-align: left;">/settings/webhooklockenabled</td>
<td>GET, POST</td>
<td>value</td>
<td>Gets or sets the webhook lock enabled value</td>
</tr>
<tr>
<td style="text-align: left;">/settings/webhooklockhook</td>
<td>GET, POST</td>
<td>value</td>
<td>Gets or sets the webhook lock hook</td>
</tr>
<tr>
<td style="text-align: left;">/settings/webhookunlockenabled</td>
<td>GET, POST</td>
<td>value</td>
<td>Gets or sets the webhook unlock enabled value</td>
</tr>
<tr>
<td style="text-align: left;">/settings/webhookunlockhook</td>
<td>GET, POST</td>
<td>value</td>
<td>Gets or sets the webhook unlock hook</td>
</tr>
</table>
</div>
</div>
<script>
var xhr = new XMLHttpRequest();
xhr.open("GET", "/version", true);
@ -135,16 +236,5 @@
xhr.send();
</script>
<script>
function toggleCheckbox(element) {
var xhr = new XMLHttpRequest();
if (element.checked) {
xhr.open("GET", "/gpio?output=" + element.id + "&state=1", true);
} else {
xhr.open("GET", "/gpio?output=" + element.id + "&state=0", true);
}
xhr.send();
}
</script>
</body>
</html>

View file

@ -2,10 +2,9 @@
#define HARDWARE_H
#include <Arduino.h>
#ifdef WIFI
#ifdef WEBHOOKS
#include "webhooks.h"
#include "secrets.h"
#endif
#include "webhooks.h"
#ifdef TINANCE2_BACKEND
#include "tinance2.h"
#include "secrets.h"

View file

@ -46,7 +46,7 @@ class MainWebServerClass{
return request->requestAuthentication();
}
}
request->send(200, "application/json", "{\"version\":\"3.2.5\"}");
request->send(200, "application/json", "{\"version\":\"3.5.6\"}");
});
_server->onNotFound([&](AsyncWebServerRequest *request){
@ -69,7 +69,7 @@ class MainWebServerClass{
}
// GET input1 value on <ESP_IP>/gpio?output=<paramOutput>&state=<paramState>
if (request->hasParam("output") && request->hasParam("state")) {
if (request->hasParam("output", true) && request->hasParam("state", true)) {
paramOutput = request->getParam("output")->value();
paramState = request->getParam("state")->value();
@ -112,7 +112,7 @@ class MainWebServerClass{
});
#endif
_server->on("/settings/DoorDisabled", HTTP_GET, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/doordisabled", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
@ -122,8 +122,7 @@ class MainWebServerClass{
request->send(response);
});
_server->on("/settings/DoorDisabled", HTTP_POST, [&] (AsyncWebServerRequest *request) {
String value;
_server->on("/settings/doordisabled", HTTP_POST, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
@ -131,8 +130,9 @@ class MainWebServerClass{
}
}
if (request->hasParam("value")) {
value = request->getParam("value")->value();
if (request->hasParam("value", true)) {
String value = String(request->arg("value"));
if (value == "0") {
settings.setDisableDoor(0);
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"value set to 0\"}");
@ -155,7 +155,7 @@ class MainWebServerClass{
});
_server->on("/settings/tinanceCreds", HTTP_GET, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/tinance2creds", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
@ -165,7 +165,7 @@ class MainWebServerClass{
request->send(response);
});
_server->on("/settings/tinanceCreds", HTTP_POST, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/tinance2creds", HTTP_POST, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
@ -198,7 +198,7 @@ class MainWebServerClass{
});
_server->on("/settings/tinanceurl", HTTP_POST, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/tinance2url", HTTP_POST, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
@ -212,14 +212,25 @@ class MainWebServerClass{
String url = String(request->arg("url"));
settings.tinance2_url = url;
settings.tinance2_url_validatecard = settings.tinance2_url+"/accesscontrol/api/check-card-id";
settings.tinance2_url_readerinfo = settings.tinance2_url+"/accesscontrol/api/readerinfo";
settings.tinance2_url_acls = settings.tinance2_url+"/accesscontrol/api/acls";
settings.tinance2_url_log = settings.tinance2_url+"/accesscontrol/api/readerlog";
settings.saveSetting("t2", "rooturl", settings.tinance2_url, "string");
settings.saveSetting("t2", "vcurl", settings.tinance2_url_validatecard, "string");
settings.saveSetting("t2", "riurl", settings.tinance2_url_readerinfo, "string");
settings.saveSetting("t2", "aclurl", settings.tinance2_url_acls, "string");
settings.saveSetting("t2", "rluri", settings.tinance2_url_log, "string");
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"Tinance URL updated\"}");
request->send(response);
});
_server->on("/settings/tinanceurl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/tinance2url", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
@ -230,7 +241,7 @@ class MainWebServerClass{
});
_server->on("/settings/validatecardurl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/tinance2validatecardurl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
@ -241,7 +252,7 @@ class MainWebServerClass{
});
_server->on("/settings/readerinfourl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/tinance2readerinfourl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
@ -251,7 +262,7 @@ class MainWebServerClass{
request->send(response);
});
_server->on("/settings/aclsurl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/tinance2aclsurl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
@ -262,7 +273,7 @@ class MainWebServerClass{
});
_server->on("/settings/logurl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/tinance2logurl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
@ -283,7 +294,6 @@ class MainWebServerClass{
});
_server->on("/settings/webhooklockenabled", HTTP_POST, [&] (AsyncWebServerRequest *request) {
String value;
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
@ -291,8 +301,8 @@ class MainWebServerClass{
}
}
if (request->hasParam("value")) {
value = request->getParam("value")->value();
if (request->hasParam("value", true)) {
String value = String(request->arg("value"));
if (value == "0") {
settings.webhookLockEnabled = 0;
settings.saveSetting("wh", "lockena", String(settings.webhookLockEnabled), "bool");
@ -328,7 +338,6 @@ class MainWebServerClass{
});
_server->on("/settings/webhooklockhook", HTTP_POST, [&] (AsyncWebServerRequest *request) {
String value;
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
@ -336,8 +345,8 @@ class MainWebServerClass{
}
}
if (request->hasParam("value")) {
value = request->getParam("value")->value();
if (request->hasParam("value", true)) {
String value = String(request->arg("value"));
settings.webhookLockHook = value;
settings.saveSetting("wh", "lockurl", settings.webhookLockHook, "string");
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"value set to "+value+"\"}");
@ -360,16 +369,15 @@ class MainWebServerClass{
});
_server->on("/settings/webhookunlockenabled", HTTP_POST, [&] (AsyncWebServerRequest *request) {
String value;
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
}
}
if (request->hasParam("value")) {
value = request->getParam("value")->value();
if (request->hasParam("value", true)) {
String value = String(request->arg("value"));
if (value == "0") {
settings.webhookUnlockEnabled = 0;
settings.saveSetting("wh", "unlockena", String(settings.webhookUnlockEnabled), "bool");
@ -404,16 +412,15 @@ class MainWebServerClass{
});
_server->on("/settings/webhookunlockhook", HTTP_POST, [&] (AsyncWebServerRequest *request) {
String value;
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
}
}
if (request->hasParam("value")) {
value = request->getParam("value")->value();
if (request->hasParam("value", true)) {
String value = String(request->arg("value"));
settings.webhookUnlockHook = value;
settings.saveSetting("wh", "unlockurl", settings.webhookUnlockHook, "string");
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"value set to "+value+"\"}");

View file

@ -26,12 +26,11 @@ void unlockDoor(bool silent) {
#endif
#ifdef WIFI
#ifdef WEBHOOKS
#ifdef WEBHOOK_UNLOCK
ExecuteHTTPRequest(String(webhook_unlock_url));
#endif
#endif
if (settings.webhookUnlockEnabled) {
if (settings.webhookUnlockHook != "") {
ExecuteHTTPRequest(settings.webhookUnlockHook);
}
}
#ifdef TINANCE2_BACKEND
tinance2logrequest("Door Unlocked");
#endif
@ -60,11 +59,12 @@ void lockDoor(bool silent) {
#endif
#ifdef WIFI
#ifdef WEBHOOKS
#ifdef WEBHOOK_LOCK
ExecuteHTTPRequest(String(webhook_lock_url));
#endif
#endif
if (settings.webhookLockEnabled) {
if (settings.webhookLockHook != "") {
ExecuteHTTPRequest(settings.webhookLockHook);
}
}
#ifdef TINANCE2_BACKEND
tinance2logrequest("Door Locked");
#endif

View file

@ -160,7 +160,7 @@ void setup() {
#ifdef TINANCE2_BACKEND
#endif
#ifdef WEBHOOKS
#ifdef WIFI
webhooks_http.setReuse(true);
#endif
@ -328,10 +328,6 @@ void setup() {
String prefix = wordList[0];
if (prefix.equals("help")) {
Serial.println("Available prefixes:");
Serial.println("tinance2.identifier.get - No arguments");
Serial.println("tinance2.identifier.set - 1 argument: new identifier");
Serial.println("tinance2.key.get - No arguments");
Serial.println("tinance2.key.set - 1 argument: new key");
Serial.println("acl.local.validate - 1 argument: card ID");
Serial.println("acl.local.add - 2 arguments: card ID, description");
Serial.println("acl.local.update - 3 arguments: card ID, new card ID, new description");
@ -339,132 +335,6 @@ void setup() {
Serial.println("acl.local.list - No arguments");
}
if (prefix.equals("tinance2.identifier.get")) {
// Retrieves the Tinance2 reader identifier from the settings
Serial.println("Tinance2 Identifier: " + settings.tinance2ReaderIdentifier);
}
if (prefix.equals("tinance2.identifier.set")) {
if (wordCount == 2) {
// Sets the Tinance2 reader identifier in the settings
settings.tinance2ReaderIdentifier = wordList[1];
settings.saveSetting("t2", "ri", wordList[1], "string");
}
}
if (prefix.equals("tinance2.key.get")) {
// Retrieves the Tinance2 reader key from the settings
Serial.println("Tinance2 Key: " + settings.tinance2ReaderKey);
}
if (prefix.equals("tinance2.key.set")) {
if (wordCount == 2) {
// Sets the Tinance2 reader key in the settings
settings.tinance2ReaderKey = wordList[1];
settings.saveSetting("t2", "rk", wordList[1], "string");
}
}
if (prefix.equals("tinance2.validatecardurl.get")) {
// Retrieves the Tinance2 reader key from the settings
Serial.println("Tinance2 Key: " + settings.tinance2_url_validatecard);
}
if (prefix.equals("tinance2.validatecardurl.set")) {
if (wordCount == 2) {
// Sets the Tinance2 reader key in the settings
settings.saveSetting("t2", "vcurl", wordList[1], "string");
Serial.println("Tinance2 Key: " + settings.tinance2_url_validatecard);
}
}
if (prefix.equals("tinance2.readerinfourl.get")) {
// Retrieves the Tinance2 reader key from the settings
Serial.println("Tinance2 Key: " + settings.tinance2_url_readerinfo);
}
if (prefix.equals("tinance2.readerinfourl.set")) {
if (wordCount == 2) {
// Sets the Tinance2 reader key in the settings
settings.saveSetting("t2", "riurl", wordList[1], "string");
Serial.println("Tinance2 Key: " + settings.tinance2_url_readerinfo);
}
}
if (prefix.equals("tinance2.aclsurl.get")) {
// Retrieves the Tinance2 reader key from the settings
Serial.println("Tinance2 Key: " + settings.tinance2_url_acls);
}
if (prefix.equals("tinance2.aclsurl.set")) {
if (wordCount == 2) {
// Sets the Tinance2 reader key in the settings
settings.saveSetting("t2", "aclurl", wordList[1], "string");
Serial.println("Tinance2 Key: " + settings.tinance2_url_acls);
}
}
if (prefix.equals("tinance2.readerlogurl.get")) {
// Retrieves the Tinance2 reader key from the settings
Serial.println("Tinance2 Key: " + settings.tinance2_url_log);
}
if (prefix.equals("tinance2.readerlogurl.set")) {
if (wordCount == 2) {
// Sets the Tinance2 reader key in the settings
settings.saveSetting("t2", "rluri", wordList[1], "string");
Serial.println("Tinance2 Key: " + settings.tinance2_url_log);
}
}
if(prefix.equals("webhook.lock.url.get")) {
Serial.println("Webhook Lock URL: " + settings.webhookLockHook);
}
if(prefix.equals("webhook.lock.url.set")) {
if (wordCount == 2) {
settings.saveSetting("wh", "lockurl", wordList[1], "string");
Serial.println("Webhook Lock URL: " + settings.webhookLockHook);
}
}
if(prefix.equals("webhook.lock.enable.get")) {
Serial.println("Webhook Lock Enabled: " + settings.webhookLockEnabled);
}
if(prefix.equals("webhook.lock.enable.set")) {
if (wordCount == 2) {
settings.saveSetting("wh", "lockena", wordList[1], "bool");
Serial.println("Webhook Lock Enabled: " + settings.webhookLockEnabled);
}
}
if(prefix.equals("webhook.unlock.url.get")) {
Serial.println("Webhook Unlock URL: " + settings.webhookUnlockHook);
}
if(prefix.equals("webhook.unlock.url.set")) {
if (wordCount == 2) {
settings.saveSetting("wh", "unlockurl", wordList[1], "string");
Serial.println("Webhook Unlock URL: " + settings.webhookUnlockHook);
}
}
if(prefix.equals("webhook.unlock.enable.get")) {
Serial.println("Webhook Unlock Enabled: " + settings.webhookUnlockEnabled);
}
if(prefix.equals("webhook.unlock.enable.set")) {
if (wordCount == 2) {
settings.saveSetting("wh", "unlockena", wordList[1], "bool");
Serial.println("Webhook Unlock Enabled: " + settings.webhookUnlockEnabled);
}
}
// Command Validate Access
if (prefix.equals("acl.local.validate")) {