mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-07-29 01:52:51 +00:00
added application setting 'disable factory' Feature request->Button anti tampering mode
Fixes #3150
This commit is contained in:
@@ -134,6 +134,7 @@
|
||||
"modbus_max_clients": 10,
|
||||
"modbus_timeout": 300,
|
||||
"developer_mode": true,
|
||||
"disable_reset": false,
|
||||
"email_enabled": true,
|
||||
"email_security": 2,
|
||||
"email_server": "smtp.gmail.com",
|
||||
|
||||
@@ -54,6 +54,7 @@ export interface Settings {
|
||||
email_recp: string;
|
||||
email_subject: string;
|
||||
developer_mode: boolean;
|
||||
disable_reset: boolean;
|
||||
}
|
||||
|
||||
export enum busConnectionStatus {
|
||||
|
||||
@@ -903,6 +903,16 @@ const ApplicationSettings = () => {
|
||||
}
|
||||
label={LL.DEVELOPER_MODE()}
|
||||
/>
|
||||
<BlockFormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={data.disable_reset}
|
||||
onChange={updateFormValue}
|
||||
name="disable_reset"
|
||||
/>
|
||||
}
|
||||
label={LL.DISABLE_RESET()}
|
||||
/>
|
||||
<BlockFormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
|
||||
@@ -71,6 +71,7 @@ interface VersionData {
|
||||
partition: string;
|
||||
partitions: PartitionData[];
|
||||
developer_mode: boolean;
|
||||
disable_reset: boolean;
|
||||
}
|
||||
|
||||
// Memoized components for better performance
|
||||
@@ -923,7 +924,7 @@ const Version = () => {
|
||||
>
|
||||
{LL.RESTART()}
|
||||
</Button>
|
||||
{data.developer_mode && (
|
||||
{!data.disable_reset && (
|
||||
<Button
|
||||
startIcon={<SettingsBackupRestoreIcon />}
|
||||
variant="outlined"
|
||||
|
||||
@@ -340,6 +340,7 @@ const cs: Translation = {
|
||||
AUTO_SCROLL: 'Automatické rolování',
|
||||
DASHBOARD: 'Dashboard',
|
||||
DEVELOPER_MODE: 'Režim vývojáře',
|
||||
DISABLE_RESET: 'Zakázat obnovení továrního nastavení',
|
||||
BYTES: 'Bajty',
|
||||
BITMASK: 'Bit Mask',
|
||||
DUPLICATE: 'Duplikát',
|
||||
|
||||
@@ -340,6 +340,7 @@ const de: Translation = {
|
||||
AUTO_SCROLL: 'Automatisches Scrollen',
|
||||
DASHBOARD: 'Dashboard',
|
||||
DEVELOPER_MODE: 'Entwicklermodus',
|
||||
DISABLE_RESET: 'Werkseinstellungen deaktivieren',
|
||||
BYTES: 'Bytes',
|
||||
BITMASK: 'Bit Maske',
|
||||
DUPLICATE: 'Kopieren',
|
||||
|
||||
@@ -340,6 +340,7 @@ const en: Translation = {
|
||||
AUTO_SCROLL: 'Auto Scroll',
|
||||
DASHBOARD: 'Dashboard',
|
||||
DEVELOPER_MODE: 'Developer Mode',
|
||||
DISABLE_RESET: 'Disable Factory Reset',
|
||||
BYTES: 'Bytes',
|
||||
BITMASK: 'Bit Mask',
|
||||
DUPLICATE: 'Duplicate',
|
||||
|
||||
@@ -340,6 +340,7 @@ const fr: Translation = {
|
||||
AUTO_SCROLL: 'Défilement automatique',
|
||||
DASHBOARD: 'Tableau de bord',
|
||||
DEVELOPER_MODE: 'Mode développeur',
|
||||
DISABLE_RESET: 'Désactiver la réinitialisation de fabrique',
|
||||
BYTES: 'Octets',
|
||||
BITMASK: 'Masque de bits',
|
||||
DUPLICATE: 'Dupliquer',
|
||||
|
||||
@@ -340,6 +340,7 @@ const it: Translation = {
|
||||
AUTO_SCROLL: 'Scorrimento automatico',
|
||||
DASHBOARD: 'Pannello di controllo',
|
||||
DEVELOPER_MODE: 'Modalità sviluppatore',
|
||||
DISABLE_RESET: 'Disabilita la ripristino di fabbrica',
|
||||
BYTES: 'Byte',
|
||||
BITMASK: 'Bitmask',
|
||||
DUPLICATE: 'Duplicato',
|
||||
|
||||
@@ -340,6 +340,7 @@ const nl: Translation = {
|
||||
AUTO_SCROLL: 'Automatisch Scrollen',
|
||||
DASHBOARD: 'Dashboard',
|
||||
DEVELOPER_MODE: 'Ontwikkelaarsmodus',
|
||||
DISABLE_RESET: 'Fabrieksinstellingen uitschakelen',
|
||||
BYTES: 'Bytes',
|
||||
BITMASK: 'Bit Mask',
|
||||
DUPLICATE: 'Duplicaat',
|
||||
|
||||
@@ -340,6 +340,7 @@ const no: Translation = {
|
||||
AUTO_SCROLL: 'Automatisk rulling',
|
||||
DASHBOARD: 'Dashboard',
|
||||
DEVELOPER_MODE: 'Utvikler modus',
|
||||
DISABLE_RESET: 'Deaktiver fabrikkinnstillinger',
|
||||
BYTES: 'Bytes',
|
||||
BITMASK: 'Bitmask',
|
||||
DUPLICATE: 'Duplikat',
|
||||
|
||||
@@ -340,6 +340,7 @@ const pl: BaseTranslation = {
|
||||
AUTO_SCROLL: 'Auto Scroll',
|
||||
DASHBOARD: 'Pulpit',
|
||||
DEVELOPER_MODE: 'Tryb programisty',
|
||||
DISABLE_RESET: 'Wyłącz reset fabryczny',
|
||||
BYTES: 'Bajty',
|
||||
BITMASK: 'Bit Mask',
|
||||
DUPLICATE: 'Duplicate',
|
||||
|
||||
@@ -340,6 +340,7 @@ const sk: Translation = {
|
||||
AUTO_SCROLL: 'Automatické rolovanie',
|
||||
DASHBOARD: 'Panel',
|
||||
DEVELOPER_MODE: 'Režim vývojára',
|
||||
DISABLE_RESET: 'Zakázať továrenské nastavenia',
|
||||
BYTES: 'Bytov',
|
||||
BITMASK: 'Bitová maska',
|
||||
DUPLICATE: 'Duplicitné',
|
||||
|
||||
@@ -340,6 +340,7 @@ const sv: Translation = {
|
||||
AUTO_SCROLL: 'Autoskrolla',
|
||||
DASHBOARD: 'Kontrollpanel',
|
||||
DEVELOPER_MODE: 'Utvecklarläge',
|
||||
DISABLE_RESET: 'Inaktivera fabriksåterställning',
|
||||
BYTES: 'Bytes',
|
||||
BITMASK: 'Bitmask',
|
||||
DUPLICATE: 'Dublett',
|
||||
|
||||
@@ -340,6 +340,7 @@ const tr: Translation = {
|
||||
AUTO_SCROLL: 'Otomatik kaydırma',
|
||||
DASHBOARD: 'Kontrol Paneli',
|
||||
DEVELOPER_MODE: 'Geliştirici Modu',
|
||||
DISABLE_RESET: 'Fabrika ayarlarını devre dışı bırak',
|
||||
BYTES: 'Bayt',
|
||||
BITMASK: 'Bit Maskesi',
|
||||
DUPLICATE: 'Çift',
|
||||
|
||||
@@ -61,6 +61,7 @@ export interface SystemStatus {
|
||||
}[];
|
||||
status: number; // System Status Codes which matches SYSTEM_STATUS in System.h
|
||||
developer_mode: boolean;
|
||||
disable_reset: boolean;
|
||||
temperature?: number;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,8 @@ let settings = {
|
||||
modbus_port: 502,
|
||||
modbus_max_clients: 10,
|
||||
modbus_timeout: 10000,
|
||||
developer_mode: true
|
||||
developer_mode: true,
|
||||
disable_reset: false
|
||||
};
|
||||
|
||||
// EMS-ESP System Settings
|
||||
@@ -129,6 +130,7 @@ let system_status = {
|
||||
],
|
||||
// partitions: [],
|
||||
developer_mode: settings.developer_mode,
|
||||
disable_reset: settings.disable_reset,
|
||||
model: '',
|
||||
board: '',
|
||||
// model: 'BBQKees Electronics EMS Gateway E32 V2 (E32 V2.0 P3/2024011)',
|
||||
@@ -4721,6 +4723,7 @@ router
|
||||
settings = await request.json();
|
||||
console.log('application settings saved', settings);
|
||||
system_status.developer_mode = settings.developer_mode;
|
||||
system_status.disable_reset = settings.disable_reset;
|
||||
return status(200); // no restart needed
|
||||
// return status(205); // reboot required
|
||||
})
|
||||
|
||||
@@ -131,7 +131,7 @@ void LED::led_fast_flash() {
|
||||
set_led(led_flash_state_ ? Color::YELLOW : Color::OFF); // Yellow
|
||||
}
|
||||
|
||||
// after duration, turn off the LED
|
||||
// after duration, turn off the LED, and call the format command
|
||||
if (current_time - led_flash_start_time_ >= led_flash_duration_) {
|
||||
set_led(Color::OFF);
|
||||
led_fast_flash_timer_ = false;
|
||||
|
||||
@@ -677,6 +677,7 @@ void System::store_settings(WebSettings & settings) {
|
||||
locale_ = settings.locale;
|
||||
system_name_ = settings.system_name;
|
||||
developer_mode_ = settings.developer_mode;
|
||||
disable_reset_ = settings.disable_reset;
|
||||
}
|
||||
|
||||
// Starts up core services
|
||||
@@ -761,6 +762,10 @@ void System::button_OnLongPress(PButton & b) {
|
||||
|
||||
// button indefinite press
|
||||
void System::button_OnVLongPress(PButton & b) {
|
||||
if (EMSESP::system_.disable_reset()) {
|
||||
LOG_NOTICE("Factory reset disabled");
|
||||
return;
|
||||
}
|
||||
LOG_NOTICE("Button pressed - very long press - perform factory reset");
|
||||
EMSESP::led_.start_led_fast_flash(5); // Start LED flash timer for 5 seconds
|
||||
}
|
||||
@@ -2646,6 +2651,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
|
||||
node["modbusEnabled"] = settings.modbus_enabled;
|
||||
node["forceHeatingOff"] = settings.boiler_heatingoff;
|
||||
node["developerMode"] = settings.developer_mode;
|
||||
node["disableReset"] = settings.disable_reset;
|
||||
});
|
||||
|
||||
// Devices - show EMS devices if we have any
|
||||
@@ -2870,6 +2876,12 @@ bool System::command_txpause(const char * value, const int8_t id) {
|
||||
|
||||
// format command - factory reset, removing all config files
|
||||
bool System::command_format(const char * value, const int8_t id) {
|
||||
|
||||
if (EMSESP::system_.disable_reset()) {
|
||||
LOG_NOTICE("Factory reset disabled");
|
||||
return false;
|
||||
}
|
||||
|
||||
#if !defined(EMSESP_STANDALONE) && !defined(EMSESP_TEST)
|
||||
// don't really format the filesystem in test or standalone mode
|
||||
if (LittleFS.format()) {
|
||||
|
||||
@@ -199,6 +199,14 @@ class System {
|
||||
developer_mode_ = developer_mode;
|
||||
}
|
||||
|
||||
bool disable_reset() {
|
||||
return disable_reset_;
|
||||
}
|
||||
|
||||
void disable_reset(bool disable_reset) {
|
||||
disable_reset_ = disable_reset;
|
||||
}
|
||||
|
||||
// Boolean Format API/MQTT
|
||||
uint8_t bool_format() {
|
||||
return bool_format_;
|
||||
@@ -438,6 +446,7 @@ class System {
|
||||
uint8_t modbus_max_clients_;
|
||||
uint32_t modbus_timeout_;
|
||||
bool developer_mode_;
|
||||
bool disable_reset_;
|
||||
uint32_t fstotal_;
|
||||
uint32_t psram_;
|
||||
uint32_t appused_;
|
||||
|
||||
@@ -84,6 +84,7 @@ void WebSettings::read(WebSettings & settings, JsonObject root) {
|
||||
root["modbus_max_clients"] = settings.modbus_max_clients;
|
||||
root["modbus_timeout"] = settings.modbus_timeout;
|
||||
root["developer_mode"] = settings.developer_mode;
|
||||
root["disable_reset"] = settings.disable_reset;
|
||||
root["email_enabled"] = settings.email_enabled;
|
||||
root["email_security"] = settings.email_security;
|
||||
root["email_server"] = settings.email_server;
|
||||
@@ -306,6 +307,9 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
|
||||
settings.developer_mode = root["developer_mode"];
|
||||
EMSESP::system_.developer_mode(settings.developer_mode);
|
||||
|
||||
settings.disable_reset = root["disable_reset"];
|
||||
EMSESP::system_.disable_reset(settings.disable_reset);
|
||||
|
||||
settings.bool_dashboard = root["bool_dashboard"] | EMSESP_DEFAULT_BOOL_FORMAT;
|
||||
EMSESP::system_.bool_dashboard(settings.bool_dashboard);
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ class WebSettings {
|
||||
uint8_t eth_clock_mode;
|
||||
|
||||
bool developer_mode; // developer mode
|
||||
bool disable_reset; // disable reset
|
||||
|
||||
static void read(WebSettings & settings, JsonObject root);
|
||||
static StateUpdateResult update(JsonObject root, WebSettings & settings);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -131,6 +131,7 @@
|
||||
"modbus_max_clients": 10,
|
||||
"modbus_timeout": 300,
|
||||
"developer_mode": true,
|
||||
"disable_reset": false,
|
||||
"email_enabled": false,
|
||||
"email_security": 2,
|
||||
"email_server": "smtp.example.net",
|
||||
|
||||
@@ -132,7 +132,8 @@
|
||||
"modbus_port": 502,
|
||||
"modbus_max_clients": 10,
|
||||
"modbus_timeout": 300,
|
||||
"developer_mode": true
|
||||
"developer_mode": true,
|
||||
"disable_reset": false
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user