Add UI for syslog configuration to network view
This commit is contained in:
parent
4cd5d79c73
commit
dc588dce07
@ -11,6 +11,8 @@
|
|||||||
#define WIFI_MAX_PASSWORD_STRLEN 64
|
#define WIFI_MAX_PASSWORD_STRLEN 64
|
||||||
#define WIFI_MAX_HOSTNAME_STRLEN 31
|
#define WIFI_MAX_HOSTNAME_STRLEN 31
|
||||||
|
|
||||||
|
#define SYSLOG_MAX_HOSTNAME_STRLEN 128
|
||||||
|
|
||||||
#define NTP_MAX_SERVER_STRLEN 31
|
#define NTP_MAX_SERVER_STRLEN 31
|
||||||
#define NTP_MAX_TIMEZONE_STRLEN 50
|
#define NTP_MAX_TIMEZONE_STRLEN 50
|
||||||
#define NTP_MAX_TIMEZONEDESCR_STRLEN 50
|
#define NTP_MAX_TIMEZONEDESCR_STRLEN 50
|
||||||
@ -76,6 +78,12 @@ struct CONFIG_T {
|
|||||||
bool Enabled;
|
bool Enabled;
|
||||||
} Mdns;
|
} Mdns;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
bool Enabled;
|
||||||
|
char Hostname[SYSLOG_MAX_HOSTNAME_STRLEN + 1];
|
||||||
|
uint32_t Port;
|
||||||
|
} Syslog;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
char Server[NTP_MAX_SERVER_STRLEN + 1];
|
char Server[NTP_MAX_SERVER_STRLEN + 1];
|
||||||
char Timezone[NTP_MAX_TIMEZONE_STRLEN + 1];
|
char Timezone[NTP_MAX_TIMEZONE_STRLEN + 1];
|
||||||
|
|||||||
@ -70,6 +70,8 @@ enum WebApiError {
|
|||||||
NetworkDns1Invalid,
|
NetworkDns1Invalid,
|
||||||
NetworkDns2Invalid,
|
NetworkDns2Invalid,
|
||||||
NetworkApTimeoutInvalid,
|
NetworkApTimeoutInvalid,
|
||||||
|
NetworkSyslogHostnameLength,
|
||||||
|
NetworkSyslogPort,
|
||||||
|
|
||||||
NtpBase = 9000,
|
NtpBase = 9000,
|
||||||
NtpServerLength,
|
NtpServerLength,
|
||||||
|
|||||||
@ -22,6 +22,9 @@
|
|||||||
|
|
||||||
#define MDNS_ENABLED false
|
#define MDNS_ENABLED false
|
||||||
|
|
||||||
|
#define SYSLOG_ENABLED false
|
||||||
|
#define SYSLOG_PORT 514
|
||||||
|
|
||||||
#define NTP_SERVER_OLD "pool.ntp.org"
|
#define NTP_SERVER_OLD "pool.ntp.org"
|
||||||
#define NTP_SERVER "opendtu.pool.ntp.org"
|
#define NTP_SERVER "opendtu.pool.ntp.org"
|
||||||
#define NTP_TIMEZONE "CET-1CEST,M3.5.0,M10.5.0/3"
|
#define NTP_TIMEZONE "CET-1CEST,M3.5.0,M10.5.0/3"
|
||||||
|
|||||||
@ -47,6 +47,11 @@ bool ConfigurationClass::write()
|
|||||||
JsonObject mdns = doc["mdns"].to<JsonObject>();
|
JsonObject mdns = doc["mdns"].to<JsonObject>();
|
||||||
mdns["enabled"] = config.Mdns.Enabled;
|
mdns["enabled"] = config.Mdns.Enabled;
|
||||||
|
|
||||||
|
JsonObject syslog = doc["syslog"].to<JsonObject>();
|
||||||
|
syslog["enabled"] = config.Syslog.Enabled;
|
||||||
|
syslog["hostname"] = config.Syslog.Hostname;
|
||||||
|
syslog["port"] = config.Syslog.Port;
|
||||||
|
|
||||||
JsonObject ntp = doc["ntp"].to<JsonObject>();
|
JsonObject ntp = doc["ntp"].to<JsonObject>();
|
||||||
ntp["server"] = config.Ntp.Server;
|
ntp["server"] = config.Ntp.Server;
|
||||||
ntp["timezone"] = config.Ntp.Timezone;
|
ntp["timezone"] = config.Ntp.Timezone;
|
||||||
@ -222,6 +227,11 @@ bool ConfigurationClass::read()
|
|||||||
JsonObject mdns = doc["mdns"];
|
JsonObject mdns = doc["mdns"];
|
||||||
config.Mdns.Enabled = mdns["enabled"] | MDNS_ENABLED;
|
config.Mdns.Enabled = mdns["enabled"] | MDNS_ENABLED;
|
||||||
|
|
||||||
|
JsonObject syslog = doc["syslog"];
|
||||||
|
config.Syslog.Enabled = syslog["enabled"] | SYSLOG_ENABLED;
|
||||||
|
strlcpy(config.Syslog.Hostname, syslog["hostname"] | "", sizeof(config.Syslog.Hostname));
|
||||||
|
config.Syslog.Port = syslog["port"] | SYSLOG_PORT;
|
||||||
|
|
||||||
JsonObject ntp = doc["ntp"];
|
JsonObject ntp = doc["ntp"];
|
||||||
strlcpy(config.Ntp.Server, ntp["server"] | NTP_SERVER, sizeof(config.Ntp.Server));
|
strlcpy(config.Ntp.Server, ntp["server"] | NTP_SERVER, sizeof(config.Ntp.Server));
|
||||||
strlcpy(config.Ntp.Timezone, ntp["timezone"] | NTP_TIMEZONE, sizeof(config.Ntp.Timezone));
|
strlcpy(config.Ntp.Timezone, ntp["timezone"] | NTP_TIMEZONE, sizeof(config.Ntp.Timezone));
|
||||||
|
|||||||
@ -70,6 +70,9 @@ void WebApiNetworkClass::onNetworkAdminGet(AsyncWebServerRequest* request)
|
|||||||
root["password"] = config.WiFi.Password;
|
root["password"] = config.WiFi.Password;
|
||||||
root["aptimeout"] = config.WiFi.ApTimeout;
|
root["aptimeout"] = config.WiFi.ApTimeout;
|
||||||
root["mdnsenabled"] = config.Mdns.Enabled;
|
root["mdnsenabled"] = config.Mdns.Enabled;
|
||||||
|
root["syslogenabled"] = config.Syslog.Enabled;
|
||||||
|
root["sysloghostname"] = config.Syslog.Hostname;
|
||||||
|
root["syslogport"] = config.Syslog.Port;
|
||||||
|
|
||||||
WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
|
WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
|
||||||
}
|
}
|
||||||
@ -163,6 +166,23 @@ void WebApiNetworkClass::onNetworkAdminPost(AsyncWebServerRequest* request)
|
|||||||
WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
|
WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (root["syslogenabled"].as<bool>()) {
|
||||||
|
if (root["sysloghostname"].as<String>().length() == 0 || root["sysloghostname"].as<String>().length() > SYSLOG_MAX_HOSTNAME_STRLEN) {
|
||||||
|
retMsg["message"] = "Syslog Server must between 1 and " STR(SYSLOG_MAX_HOSTNAME_STRLEN) " characters long!";
|
||||||
|
retMsg["code"] = WebApiError::NetworkSyslogHostnameLength;
|
||||||
|
retMsg["param"]["max"] = SYSLOG_MAX_HOSTNAME_STRLEN;
|
||||||
|
WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root["syslogport"].as<uint>() == 0 || root["syslogport"].as<uint>() > 65535) {
|
||||||
|
retMsg["message"] = "Port must be a number between 1 and 65535!";
|
||||||
|
retMsg["code"] = WebApiError::NetworkSyslogPort;
|
||||||
|
WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
CONFIG_T& config = Configuration.get();
|
CONFIG_T& config = Configuration.get();
|
||||||
config.WiFi.Ip[0] = ipaddress[0];
|
config.WiFi.Ip[0] = ipaddress[0];
|
||||||
@ -195,6 +215,9 @@ void WebApiNetworkClass::onNetworkAdminPost(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
config.WiFi.ApTimeout = root["aptimeout"].as<uint>();
|
config.WiFi.ApTimeout = root["aptimeout"].as<uint>();
|
||||||
config.Mdns.Enabled = root["mdnsenabled"].as<bool>();
|
config.Mdns.Enabled = root["mdnsenabled"].as<bool>();
|
||||||
|
config.Syslog.Enabled = root["syslogenabled"].as<bool>();
|
||||||
|
strlcpy(config.Syslog.Hostname, root["sysloghostname"].as<String>().c_str(), sizeof(config.Syslog.Hostname));
|
||||||
|
config.Syslog.Port = root["syslogport"].as<uint>();
|
||||||
|
|
||||||
WebApi.writeConfig(retMsg);
|
WebApi.writeConfig(retMsg);
|
||||||
|
|
||||||
|
|||||||
@ -444,7 +444,10 @@
|
|||||||
"ApTimeoutHint": "Zeit die der AccessPoint offen gehalten wird. Ein Wert von 0 bedeutet unendlich.",
|
"ApTimeoutHint": "Zeit die der AccessPoint offen gehalten wird. Ein Wert von 0 bedeutet unendlich.",
|
||||||
"Minutes": "Minuten",
|
"Minutes": "Minuten",
|
||||||
"EnableMdns": "mDNS aktivieren",
|
"EnableMdns": "mDNS aktivieren",
|
||||||
"MdnsSettings": "mDNS-Einstellungen"
|
"MdnsSettings": "mDNS-Einstellungen",
|
||||||
|
"EnableSyslog": "Syslog aktivieren",
|
||||||
|
"SyslogSettings": "Syslog-Einstellungen",
|
||||||
|
"Port": "Port:"
|
||||||
},
|
},
|
||||||
"mqttadmin": {
|
"mqttadmin": {
|
||||||
"MqttSettings": "MQTT-Einstellungen",
|
"MqttSettings": "MQTT-Einstellungen",
|
||||||
|
|||||||
@ -444,7 +444,10 @@
|
|||||||
"ApTimeoutHint": "Time which the AccessPoint is kept open. A value of 0 means infinite.",
|
"ApTimeoutHint": "Time which the AccessPoint is kept open. A value of 0 means infinite.",
|
||||||
"Minutes": "minutes",
|
"Minutes": "minutes",
|
||||||
"EnableMdns": "Enable mDNS",
|
"EnableMdns": "Enable mDNS",
|
||||||
"MdnsSettings": "mDNS Settings"
|
"MdnsSettings": "mDNS Settings",
|
||||||
|
"EnableSyslog": "Enable Syslog",
|
||||||
|
"SyslogSettings": "Syslog Settings",
|
||||||
|
"Port": "Port:"
|
||||||
},
|
},
|
||||||
"mqttadmin": {
|
"mqttadmin": {
|
||||||
"MqttSettings": "MQTT Settings",
|
"MqttSettings": "MQTT Settings",
|
||||||
|
|||||||
@ -10,4 +10,7 @@ export interface NetworkConfig {
|
|||||||
dns2: string;
|
dns2: string;
|
||||||
aptimeout: number;
|
aptimeout: number;
|
||||||
mdnsenabled: boolean;
|
mdnsenabled: boolean;
|
||||||
|
syslogenabled: boolean;
|
||||||
|
sysloghostname: string;
|
||||||
|
syslogport: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,6 +82,29 @@
|
|||||||
/>
|
/>
|
||||||
</CardElement>
|
</CardElement>
|
||||||
|
|
||||||
|
<CardElement :text="$t('networkadmin.SyslogSettings')" textVariant="text-bg-primary" add-space>
|
||||||
|
<InputElement
|
||||||
|
:label="$t('networkadmin.EnableSyslog')"
|
||||||
|
v-model="networkConfigList.syslogenabled"
|
||||||
|
type="checkbox"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<InputElement
|
||||||
|
:label="$t('networkadmin.Hostname', { num: 1 })"
|
||||||
|
v-model="networkConfigList.sysloghostname"
|
||||||
|
type="text"
|
||||||
|
maxlength="128"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<InputElement
|
||||||
|
:label="$t('networkadmin.Port')"
|
||||||
|
v-model="networkConfigList.syslogport"
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="65535"
|
||||||
|
/>
|
||||||
|
</CardElement>
|
||||||
|
|
||||||
<CardElement :text="$t('networkadmin.AdminAp')" textVariant="text-bg-primary" add-space>
|
<CardElement :text="$t('networkadmin.AdminAp')" textVariant="text-bg-primary" add-space>
|
||||||
<InputElement
|
<InputElement
|
||||||
:label="$t('networkadmin.ApTimeout')"
|
:label="$t('networkadmin.ApTimeout')"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user