managing the eeprom

This commit is contained in:
Matthew Frost 2024-04-15 21:07:26 +02:00
parent caf6846826
commit 9f483b89c4
4 changed files with 209 additions and 17 deletions

View file

@ -112,7 +112,7 @@ class MainWebServerClass{
});
#endif
_server->on("/settings/get/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,7 +122,7 @@ class MainWebServerClass{
request->send(response);
});
_server->on("/settings/set/DoorDisabled", HTTP_POST, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/DoorDisabled", HTTP_POST, [&] (AsyncWebServerRequest *request) {
String value;
if(_authRequired){
@ -155,7 +155,7 @@ class MainWebServerClass{
});
_server->on("/settings/get/tinanceCreds", HTTP_GET, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/tinanceCreds", 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/set/tinanceCreds", HTTP_POST, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/tinanceCreds", 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/validatecardurl", HTTP_POST, [&] (AsyncWebServerRequest *request) {
_server->on("/settings/tinanceurl", HTTP_POST, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
@ -211,14 +211,24 @@ class MainWebServerClass{
}
String url = String(request->arg("url"));
settings.tinance2_url_validatecard = url;
settings.saveSetting("t2", "vcurl", settings.tinance2_url_validatecard, "string");
settings.tinance2_url = url;
settings.saveSetting("t2", "rooturl", settings.tinance2_url, "string");
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"Tinance URL updated\"}");
request->send(response);
});
_server->on("/settings/tinanceurl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
}
}
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"value\":\""+settings.tinance2_url+"\"}");
request->send(response);
});
_server->on("/settings/validatecardurl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
@ -231,6 +241,189 @@ class MainWebServerClass{
});
_server->on("/settings/readerinfourl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
}
}
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"value\":\""+settings.tinance2_url_readerinfo+"\"}");
request->send(response);
});
_server->on("/settings/aclsurl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
}
}
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"value\":\""+settings.tinance2_url_acls+"\"}");
request->send(response);
});
_server->on("/settings/logurl", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
}
}
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"value\":\""+settings.tinance2_url_log+"\"}");
request->send(response);
});
_server->on("/settings/webhooklockenabled", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
}
}
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"value\":\""+String(settings.webhookLockEnabled)+"\"}");
request->send(response);
});
_server->on("/settings/webhooklockenabled", 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 (value == "0") {
settings.webhookLockEnabled = 0;
settings.saveSetting("wh", "lockena", String(settings.webhookLockEnabled), "bool");
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"value set to 0\"}");
request->send(response);
}
else if (value =="1") {
settings.webhookLockEnabled = 1;
settings.saveSetting("wh", "lockena", String(settings.webhookLockEnabled), "bool");
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"value set to 1\"}");
request->send(response);
} else {
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"value should be 0 or 1\"}");
request->send(response);
}
}
else {
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"Missing 'value' param.\"}");
request->send(response);
}
});
_server->on("/settings/webhooklockhook", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
}
}
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"value\":\""+settings.webhookLockHook+"\"}");
request->send(response);
});
_server->on("/settings/webhooklockhook", 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();
settings.webhookLockHook = value;
settings.saveSetting("wh", "lockurl", settings.webhookLockHook, "string");
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"value set to "+value+"\"}");
request->send(response);
}
else {
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"Missing 'value' param.\"}");
request->send(response);
}
});
_server->on("/settings/webhookunlockenabled", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
}
}
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"value\":\""+String(settings.webhookUnlockEnabled)+"\"}");
request->send(response);
});
_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 (value == "0") {
settings.webhookUnlockEnabled = 0;
settings.saveSetting("wh", "unlockena", String(settings.webhookUnlockEnabled), "bool");
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"value set to 0\"}");
request->send(response);
}
else if (value =="1") {
settings.webhookUnlockEnabled = 1;
settings.saveSetting("wh", "unlockena", String(settings.webhookUnlockEnabled), "bool");
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"value set to 1\"}");
request->send(response);
} else {
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"value should be 0 or 1\"}");
request->send(response);
}
}
else {
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"Missing 'value' param.\"}");
request->send(response);
}
});
_server->on("/settings/webhookunlockhook", HTTP_GET, [&] (AsyncWebServerRequest *request) {
if(_authRequired){
if(!request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
}
}
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"value\":\""+settings.webhookUnlockHook+"\"}");
request->send(response);
});
_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();
settings.webhookUnlockHook = value;
settings.saveSetting("wh", "unlockurl", settings.webhookUnlockHook, "string");
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"value set to "+value+"\"}");
request->send(response);
}
else {
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"Missing 'value' param.\"}");
request->send(response);
}
});
}

View file

@ -16,7 +16,7 @@ private:
String doorMode;
public:
Settings();
String tinance2_url;
String tinance2_url_validatecard;
String tinance2_url_readerinfo;
String tinance2_url_acls;

View file

@ -14,12 +14,11 @@ void Settings::loadFromEEPROM() {
settings_preferences.begin("t2", false);
tinance2ReaderIdentifier = settings_preferences.getString("ri", "default");
tinance2ReaderKey = settings_preferences.getString("rk", "default");
tinance2_url_validatecard = settings_preferences.getString("vcurl","https://tinance2.board.techinc.nl/accesscontrol/api/check-card-id");
tinance2_url_readerinfo = settings_preferences.getString("riurl","https://tinance2.board.techinc.nl/accesscontrol/api/readerinfo");
tinance2_url_acls = settings_preferences.getString("aclurl","https://tinance2.board.techinc.nl/accesscontrol/api/acls");
tinance2_url_log = settings_preferences.getString("rluri","https://tinance2.board.techinc.nl/accesscontrol/api/readerlog");
tinance2_url = settings_preferences.getString("rooturl","https://tinance2.board.techinc.nl");
tinance2_url_validatecard = settings_preferences.getString("vcurl",tinance2_url+"/accesscontrol/api/check-card-id");
tinance2_url_readerinfo = settings_preferences.getString("riurl",tinance2_url+"/accesscontrol/api/readerinfo");
tinance2_url_acls = settings_preferences.getString("aclurl",tinance2_url+"/accesscontrol/api/acls");
tinance2_url_log = settings_preferences.getString("rluri",tinance2_url+"/accesscontrol/api/readerlog");
settings_preferences.end();
settings_preferences.begin("wh", false);

View file

@ -85,7 +85,7 @@ HTTPClient tinance2_http;
String payload = "{\"message\":\"" + String(message) + "\"}";
// Send the HTTP request and get the response
Tinance2HttpClient httpClient;
std::pair<String, int> responsePair = httpClient.sendHttpRequest(tinance2_url_log, "POST", payload);
std::pair<String, int> responsePair = httpClient.sendHttpRequest(settings.tinance2_url_log, "POST", payload);
String response = responsePair.first;
int httpResponseCode = responsePair.second;
@ -119,7 +119,7 @@ HTTPClient tinance2_http;
String payload = "{\"full_card_id\":\"" + String(fullCardID) + "\"}";
// Send the HTTP request and get the response
Tinance2HttpClient httpClient;
std::pair<String, int> responsePair = httpClient.sendHttpRequest(tinance2_url_validatecard, "POST", payload);
std::pair<String, int> responsePair = httpClient.sendHttpRequest(settings.tinance2_url_validatecard, "POST", payload);
String response = responsePair.first;
int httpResponseCode = responsePair.second;
@ -184,7 +184,7 @@ while (true) {
if (WiFi.status() == WL_CONNECTED) {
Tinance2HttpClient httpClient;
std::pair<String, int> responsePair = httpClient.sendHttpRequest(tinance2_url_readerinfo, "GET", "");
std::pair<String, int> responsePair = httpClient.sendHttpRequest(settings.tinance2_url_readerinfo, "GET", "");
String response = responsePair.first;
int httpResponseCode = responsePair.second;