Skip to content

Commit

Permalink
Password protection for vedirect settings API
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Nov 19, 2022
1 parent f35395e commit 2c6dff3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"C_Cpp.clang_format_style": "WebKit"
"C_Cpp.clang_format_style": "WebKit",
"files.associations": {
"*.tcc": "cpp",
"algorithm": "cpp"
}
}
1 change: 1 addition & 0 deletions include/WebApi_vedirect.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <ESPAsyncWebServer.h>


class WebApiVedirectClass {
public:
void init(AsyncWebServer* server);
Expand Down
13 changes: 11 additions & 2 deletions src/WebApi_vedirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ArduinoJson.h"
#include "AsyncJson.h"
#include "Configuration.h"
#include "WebApi.h"
#include "helper.h"

void WebApiVedirectClass::init(AsyncWebServer* server)
Expand All @@ -28,7 +29,7 @@ void WebApiVedirectClass::onVedirectStatus(AsyncWebServerRequest* request)
{
AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject root = response->getRoot();
CONFIG_T& config = Configuration.get();
const CONFIG_T& config = Configuration.get();

root[F("vedirect_enabled")] = config.Vedirect_Enabled;
root[F("vedirect_pollinterval")] = config.Vedirect_PollInterval;
Expand All @@ -40,9 +41,13 @@ void WebApiVedirectClass::onVedirectStatus(AsyncWebServerRequest* request)

void WebApiVedirectClass::onVedirectAdminGet(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentials(request)) {
return;
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject root = response->getRoot();
CONFIG_T& config = Configuration.get();
const CONFIG_T& config = Configuration.get();

root[F("vedirect_enabled")] = config.Vedirect_Enabled;
root[F("vedirect_pollinterval")] = config.Vedirect_PollInterval;
Expand All @@ -54,6 +59,10 @@ void WebApiVedirectClass::onVedirectAdminGet(AsyncWebServerRequest* request)

void WebApiVedirectClass::onVedirectAdminPost(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentials(request)) {
return;
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject retMsg = response->getRoot();
retMsg[F("type")] = F("warning");
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const router = createRouter({

router.beforeEach((to, from, next) => {
// redirect to login page if not logged in and trying to access a restricted page
const publicPages = ['/', '/login', '/about', '/info/network', '/info/system', '/info/ntp', '/info/mqtt', ];
const publicPages = ['/', '/login', '/about', '/info/network', '/info/system', '/info/ntp', '/info/mqtt', '/info/vedirect', ];
const authRequired = !publicPages.includes(to.path);
const loggedIn = localStorage.getItem('user');

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/views/VedirectAdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default defineComponent({
methods: {
getVedirectConfig() {
this.dataLoading = true;
fetch("api/vedirect/config", { headers: authHeader() })
fetch("/api/vedirect/config", { headers: authHeader() })
.then((response) => handleResponse(response, this.$emitter))
.then((data) => {
this.vedirectConfigList = data;
Expand Down
Binary file modified webapp_dist/js/app.js.gz
Binary file not shown.

0 comments on commit 2c6dff3

Please sign in to comment.