mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
remove feature as its not used, and speed up web loading slightly
This commit is contained in:
@@ -4,7 +4,6 @@ import { ToastContainer, Slide } from 'react-toastify';
|
||||
import 'react-toastify/dist/ReactToastify.min.css';
|
||||
|
||||
import { localStorageDetector } from 'typesafe-i18n/detectors';
|
||||
import { FeaturesLoader } from './contexts/features';
|
||||
import type { FC } from 'react';
|
||||
import AppRouting from 'AppRouting';
|
||||
import CustomTheme from 'CustomTheme';
|
||||
@@ -27,9 +26,7 @@ const App: FC = () => {
|
||||
return (
|
||||
<TypesafeI18n locale={detectedLocale}>
|
||||
<CustomTheme>
|
||||
<FeaturesLoader>
|
||||
<AppRouting />
|
||||
</FeaturesLoader>
|
||||
<ToastContainer
|
||||
position="bottom-left"
|
||||
autoClose={3000}
|
||||
|
||||
@@ -3,7 +3,6 @@ import { Box, Paper, Typography, MenuItem, TextField, Button } from '@mui/materi
|
||||
import { useRequest } from 'alova';
|
||||
import { useContext, useState } from 'react';
|
||||
import { toast } from 'react-toastify';
|
||||
import { FeaturesContext } from './contexts/features';
|
||||
import type { ValidateFieldsError } from 'async-validator';
|
||||
|
||||
import type { Locales } from 'i18n/i18n-types';
|
||||
@@ -35,8 +34,6 @@ const SignIn: FC = () => {
|
||||
|
||||
const { LL, setLocale, locale } = useContext(I18nContext);
|
||||
|
||||
const { features } = useContext(FeaturesContext);
|
||||
|
||||
const [signInRequest, setSignInRequest] = useState<SignInRequest>({
|
||||
username: '',
|
||||
password: ''
|
||||
@@ -112,7 +109,6 @@ const SignIn: FC = () => {
|
||||
})}
|
||||
>
|
||||
<Typography variant="h4">{PROJECT_NAME}</Typography>
|
||||
<Typography variant="subtitle2">{features.version}</Typography>
|
||||
|
||||
<TextField name="locale" variant="outlined" value={locale} onChange={onLocaleSelected} size="small" select>
|
||||
<MenuItem key="de" value="de">
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { alovaInstance } from './endpoints';
|
||||
|
||||
import type { Features } from 'types';
|
||||
|
||||
export const readFeatures = () => alovaInstance.Get<Features>('/rest/features');
|
||||
@@ -1,25 +0,0 @@
|
||||
import { useRequest } from 'alova';
|
||||
|
||||
import { FeaturesContext } from '.';
|
||||
import type { FC } from 'react';
|
||||
|
||||
import type { RequiredChildrenProps } from 'utils';
|
||||
import * as FeaturesApi from 'api/features';
|
||||
|
||||
const FeaturesLoader: FC<RequiredChildrenProps> = (props) => {
|
||||
const { data: features } = useRequest(FeaturesApi.readFeatures);
|
||||
|
||||
if (features) {
|
||||
return (
|
||||
<FeaturesContext.Provider
|
||||
value={{
|
||||
features
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</FeaturesContext.Provider>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default FeaturesLoader;
|
||||
@@ -1,10 +0,0 @@
|
||||
import { createContext } from 'react';
|
||||
|
||||
import type { Features } from 'types';
|
||||
|
||||
export interface FeaturesContextValue {
|
||||
features: Features;
|
||||
}
|
||||
|
||||
const FeaturesContextDefaultValue = {} as FeaturesContextValue;
|
||||
export const FeaturesContext = createContext(FeaturesContextDefaultValue);
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './context';
|
||||
export { default as FeaturesLoader } from './FeaturesLoader';
|
||||
@@ -29,7 +29,6 @@ import {
|
||||
import { useRequest } from 'alova';
|
||||
import { useContext, useState } from 'react';
|
||||
import { toast } from 'react-toastify';
|
||||
import { FeaturesContext } from '../../contexts/features';
|
||||
import RestartMonitor from './RestartMonitor';
|
||||
import SystemStatusVersionDialog from './SystemStatusVersionDialog';
|
||||
import type { FC } from 'react';
|
||||
@@ -54,8 +53,6 @@ const SystemStatusForm: FC = () => {
|
||||
const [restarting, setRestarting] = useState<boolean>();
|
||||
const [versionDialogOpen, setVersionDialogOpen] = useState<boolean>(false);
|
||||
|
||||
const { features } = useContext(FeaturesContext);
|
||||
|
||||
const { send: restartCommand } = useRequest(SystemApi.restart(), {
|
||||
immediate: false
|
||||
});
|
||||
@@ -355,7 +352,7 @@ const SystemStatusForm: FC = () => {
|
||||
open={versionDialogOpen}
|
||||
onClose={() => setVersionDialogOpen(false)}
|
||||
version={data.emsesp_version}
|
||||
platform={features.platform}
|
||||
platform={data.esp_platform}
|
||||
/>
|
||||
)}
|
||||
</SectionContent>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from './ap';
|
||||
export * from './features';
|
||||
export * from './me';
|
||||
export * from './mqtt';
|
||||
export * from './ntp';
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
using namespace std::placeholders; // for `_1` etc
|
||||
|
||||
#if FT_ENABLED(FT_SECURITY)
|
||||
|
||||
AuthenticationService::AuthenticationService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||
: _securityManager(securityManager)
|
||||
, _signInHandler(SIGN_IN_PATH, std::bind(&AuthenticationService::signIn, this, _1, _2)) {
|
||||
@@ -43,5 +41,3 @@ void AuthenticationService::signIn(AsyncWebServerRequest * request, JsonVariant
|
||||
AsyncWebServerResponse * response = request->beginResponse(401);
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
|
||||
#define MAX_AUTHENTICATION_SIZE 256
|
||||
|
||||
#if FT_ENABLED(FT_SECURITY)
|
||||
|
||||
class AuthenticationService {
|
||||
public:
|
||||
AuthenticationService(AsyncWebServer * server, SecurityManager * securityManager);
|
||||
@@ -26,5 +24,3 @@ class AuthenticationService {
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
#include <WWWData.h>
|
||||
|
||||
ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
|
||||
: _featureService(server)
|
||||
, _securitySettingsService(server, fs)
|
||||
: _securitySettingsService(server, fs)
|
||||
, _networkSettingsService(server, fs, &_securitySettingsService)
|
||||
, _wifiScanner(server, &_securitySettingsService)
|
||||
, _networkStatus(server, &_securitySettingsService)
|
||||
@@ -20,12 +19,12 @@ ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
|
||||
, _restartService(server, &_securitySettingsService)
|
||||
, _factoryResetService(server, fs, &_securitySettingsService)
|
||||
, _systemStatus(server, &_securitySettingsService) {
|
||||
// Serve static resources from PROGMEM
|
||||
// Serve static resources
|
||||
WWWData::registerRoutes([server, this](const String & uri, const String & contentType, const uint8_t * content, size_t len) {
|
||||
ArRequestHandlerFunction requestHandler = [contentType, content, len](AsyncWebServerRequest * request) {
|
||||
AsyncWebServerResponse * response = request->beginResponse_P(200, contentType, content, len);
|
||||
response->addHeader("Content-Encoding", "gzip");
|
||||
// response->addHeader("Cache-Control", "public, immutable, max-age=31536000");
|
||||
response->addHeader("Cache-Control", "public, immutable, max-age=31536000");
|
||||
// response->addHeader("Content-Encoding", "br"); // only works over HTTPS
|
||||
request->send(response);
|
||||
};
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <AsyncTCP.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
#include <FeaturesService.h>
|
||||
#include <APSettingsService.h>
|
||||
#include <APStatus.h>
|
||||
#include <AuthenticationService.h>
|
||||
@@ -72,7 +71,6 @@ class ESP8266React {
|
||||
}
|
||||
|
||||
private:
|
||||
FeaturesService _featureService;
|
||||
SecuritySettingsService _securitySettingsService;
|
||||
NetworkSettingsService _networkSettingsService;
|
||||
WiFiScanner _wifiScanner;
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
#ifndef Features_h
|
||||
#define Features_h
|
||||
|
||||
// modified by Proddy
|
||||
|
||||
#define FT_ENABLED(feature) feature
|
||||
|
||||
// project feature on by default
|
||||
#ifndef FT_PROJECT
|
||||
#define FT_PROJECT 1
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#include <FeaturesService.h>
|
||||
#include "../../src/emsesp_stub.hpp"
|
||||
|
||||
using namespace std::placeholders; // for `_1` etc
|
||||
|
||||
FeaturesService::FeaturesService(AsyncWebServer * server) {
|
||||
server->on(FEATURES_SERVICE_PATH, HTTP_GET, std::bind(&FeaturesService::features, this, _1));
|
||||
}
|
||||
|
||||
void FeaturesService::features(AsyncWebServerRequest * request) {
|
||||
AsyncJsonResponse * response = new AsyncJsonResponse(false);
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
root["version"] = EMSESP_APP_VERSION;
|
||||
root["platform"] = EMSESP_PLATFORM;
|
||||
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
#ifndef FeaturesService_h
|
||||
#define FeaturesService_h
|
||||
|
||||
#include <Features.h>
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <AsyncJson.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
// #define MAX_FEATURES_SIZE 256
|
||||
#define FEATURES_SERVICE_PATH "/rest/features"
|
||||
|
||||
class FeaturesService {
|
||||
public:
|
||||
FeaturesService(AsyncWebServer * server);
|
||||
|
||||
private:
|
||||
void features(AsyncWebServerRequest * request);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,5 @@
|
||||
#include <SecuritySettingsService.h>
|
||||
|
||||
#if FT_ENABLED(FT_SECURITY)
|
||||
|
||||
#include "../../src/emsesp_stub.hpp"
|
||||
|
||||
SecuritySettingsService::SecuritySettingsService(AsyncWebServer * server, FS * fs)
|
||||
@@ -125,33 +123,3 @@ void SecuritySettingsService::generateToken(AsyncWebServerRequest * request) {
|
||||
}
|
||||
request->send(401);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
User ADMIN_USER = User(FACTORY_ADMIN_USERNAME, FACTORY_ADMIN_PASSWORD, true);
|
||||
|
||||
SecuritySettingsService::SecuritySettingsService(AsyncWebServer * server, FS * fs)
|
||||
: SecurityManager() {
|
||||
}
|
||||
SecuritySettingsService::~SecuritySettingsService() {
|
||||
}
|
||||
|
||||
ArRequestFilterFunction SecuritySettingsService::filterRequest(AuthenticationPredicate predicate) {
|
||||
return [this, predicate](AsyncWebServerRequest * request) { return true; };
|
||||
}
|
||||
|
||||
// Return the admin user on all request - disabling security features
|
||||
Authentication SecuritySettingsService::authenticateRequest(AsyncWebServerRequest * request) {
|
||||
return Authentication(ADMIN_USER);
|
||||
}
|
||||
|
||||
// Return the function unwrapped
|
||||
ArRequestHandlerFunction SecuritySettingsService::wrapRequest(ArRequestHandlerFunction onRequest, AuthenticationPredicate predicate) {
|
||||
return onRequest;
|
||||
}
|
||||
|
||||
ArJsonRequestHandlerFunction SecuritySettingsService::wrapCallback(ArJsonRequestHandlerFunction onRequest, AuthenticationPredicate predicate) {
|
||||
return onRequest;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#define GENERATE_TOKEN_SIZE 512
|
||||
#define GENERATE_TOKEN_PATH "/rest/generateToken"
|
||||
|
||||
#if FT_ENABLED(FT_SECURITY)
|
||||
|
||||
class SecuritySettings {
|
||||
public:
|
||||
String jwtSecret;
|
||||
@@ -102,19 +100,4 @@ class SecuritySettingsService : public StatefulService<SecuritySettings>, public
|
||||
boolean validatePayload(JsonObject parsedPayload, User * user);
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
class SecuritySettingsService : public SecurityManager {
|
||||
public:
|
||||
SecuritySettingsService(AsyncWebServer * server, FS * fs);
|
||||
~SecuritySettingsService();
|
||||
|
||||
// minimal set of functions to support framework with security settings disabled
|
||||
Authentication authenticateRequest(AsyncWebServerRequest * request);
|
||||
ArRequestFilterFunction filterRequest(AuthenticationPredicate predicate);
|
||||
ArRequestHandlerFunction wrapRequest(ArRequestHandlerFunction onRequest, AuthenticationPredicate predicate);
|
||||
ArJsonRequestHandlerFunction wrapCallback(ArJsonRequestHandlerFunction onRequest, AuthenticationPredicate predicate);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef Features_h
|
||||
#define Features_h
|
||||
|
||||
#define FT_ENABLED(feature) feature
|
||||
|
||||
// project feature off by default
|
||||
#ifndef FT_PROJECT
|
||||
#define FT_PROJECT 0
|
||||
|
||||
@@ -69,10 +69,8 @@ class AuthenticationPredicates {
|
||||
|
||||
class SecurityManager {
|
||||
public:
|
||||
#if FT_ENABLED(FT_SECURITY)
|
||||
virtual Authentication authenticate(const String & username, const String & password) = 0;
|
||||
virtual String generateJWT(User * user) = 0;
|
||||
#endif
|
||||
|
||||
virtual Authentication authenticateRequest(AsyncWebServerRequest * request) = 0;
|
||||
virtual ArRequestFilterFunction filterRequest(AuthenticationPredicate predicate) = 0;
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include <SecuritySettingsService.h>
|
||||
|
||||
#if FT_ENABLED(FT_SECURITY)
|
||||
|
||||
#include "../../src/emsesp_stub.h" // proddy added
|
||||
|
||||
SecuritySettingsService::SecuritySettingsService(AsyncWebServer * server, FS * fs)
|
||||
@@ -110,34 +108,4 @@ ArJsonRequestHandlerFunction SecuritySettingsService::wrapCallback(ArJsonRequest
|
||||
};
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
User ADMIN_USER = User(FACTORY_ADMIN_USERNAME, FACTORY_ADMIN_PASSWORD, true);
|
||||
|
||||
SecuritySettingsService::SecuritySettingsService(AsyncWebServer * server, FS * fs)
|
||||
: SecurityManager() {
|
||||
}
|
||||
SecuritySettingsService::~SecuritySettingsService() {
|
||||
}
|
||||
|
||||
ArRequestFilterFunction SecuritySettingsService::filterRequest(AuthenticationPredicate predicate) {
|
||||
return [this, predicate](AsyncWebServerRequest * request) { return true; };
|
||||
}
|
||||
|
||||
// Return the admin user on all request - disabling security features
|
||||
Authentication SecuritySettingsService::authenticateRequest(AsyncWebServerRequest * request) {
|
||||
return Authentication(ADMIN_USER);
|
||||
}
|
||||
|
||||
// Return the function unwrapped
|
||||
ArRequestHandlerFunction SecuritySettingsService::wrapRequest(ArRequestHandlerFunction onRequest, AuthenticationPredicate predicate) {
|
||||
return onRequest;
|
||||
}
|
||||
|
||||
ArJsonRequestHandlerFunction SecuritySettingsService::wrapCallback(ArJsonRequestHandlerFunction onRequest, AuthenticationPredicate predicate) {
|
||||
return onRequest;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -25,8 +25,6 @@
|
||||
#define SECURITY_SETTINGS_FILE "/config/securitySettings.json"
|
||||
#define SECURITY_SETTINGS_PATH "/rest/securitySettings"
|
||||
|
||||
#if FT_ENABLED(FT_SECURITY)
|
||||
|
||||
class SecuritySettings {
|
||||
public:
|
||||
String jwtSecret;
|
||||
@@ -103,4 +101,3 @@ class SecuritySettingsService : public SecurityManager {
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user