Password protection for firmware update API
This commit is contained in:
parent
d63476c70e
commit
233efe3a50
@ -7,6 +7,7 @@
|
|||||||
#include "AsyncJson.h"
|
#include "AsyncJson.h"
|
||||||
#include "Configuration.h"
|
#include "Configuration.h"
|
||||||
#include "Update.h"
|
#include "Update.h"
|
||||||
|
#include "WebApi.h"
|
||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
|
|
||||||
void WebApiFirmwareClass::init(AsyncWebServer* server)
|
void WebApiFirmwareClass::init(AsyncWebServer* server)
|
||||||
@ -31,6 +32,10 @@ void WebApiFirmwareClass::loop()
|
|||||||
|
|
||||||
void WebApiFirmwareClass::onFirmwareUpdateFinish(AsyncWebServerRequest* request)
|
void WebApiFirmwareClass::onFirmwareUpdateFinish(AsyncWebServerRequest* request)
|
||||||
{
|
{
|
||||||
|
if (!WebApi.checkCredentials(request)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// the request handler is triggered after the upload has finished...
|
// the request handler is triggered after the upload has finished...
|
||||||
// create the response, add header, and send response
|
// create the response, add header, and send response
|
||||||
|
|
||||||
@ -46,6 +51,10 @@ void WebApiFirmwareClass::onFirmwareUpdateFinish(AsyncWebServerRequest* request)
|
|||||||
|
|
||||||
void WebApiFirmwareClass::onFirmwareUpdateUpload(AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final)
|
void WebApiFirmwareClass::onFirmwareUpdateUpload(AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final)
|
||||||
{
|
{
|
||||||
|
if (!WebApi.checkCredentials(request)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Upload handler chunks in data
|
// Upload handler chunks in data
|
||||||
if (!index) {
|
if (!index) {
|
||||||
if (!request->hasParam("MD5", true)) {
|
if (!request->hasParam("MD5", true)) {
|
||||||
|
|||||||
@ -99,8 +99,7 @@ const router = createRouter({
|
|||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
// redirect to login page if not logged in and trying to access a restricted page
|
// 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', ];
|
||||||
'/firmware/upgrade', ];
|
|
||||||
const authRequired = !publicPages.includes(to.path);
|
const authRequired = !publicPages.includes(to.path);
|
||||||
const loggedIn = localStorage.getItem('user');
|
const loggedIn = localStorage.getItem('user');
|
||||||
|
|
||||||
|
|||||||
@ -77,6 +77,7 @@ import {
|
|||||||
BIconArrowRepeat,
|
BIconArrowRepeat,
|
||||||
BIconCheckCircle
|
BIconCheckCircle
|
||||||
} from 'bootstrap-icons-vue';
|
} from 'bootstrap-icons-vue';
|
||||||
|
import { authHeader } from '@/utils/authentication';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
@ -160,6 +161,9 @@ export default defineComponent({
|
|||||||
formData.append("MD5", (md5 as string));
|
formData.append("MD5", (md5 as string));
|
||||||
formData.append("firmware", this.file, "firmware");
|
formData.append("firmware", this.file, "firmware");
|
||||||
request.open("post", "/api/firmware/update");
|
request.open("post", "/api/firmware/update");
|
||||||
|
authHeader().forEach((value, key) => {
|
||||||
|
request.setRequestHeader(key, value);
|
||||||
|
});
|
||||||
request.send(formData);
|
request.send(formData);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user