changes suggested by netmindz

pull/4664/head
KrX3D 2025-07-07 15:40:32 +02:00 zatwierdzone przez GitHub
rodzic 51bd04ae91
commit a77b85a08d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
6 zmienionych plików z 34 dodań i 217 usunięć

Wyświetl plik

@ -37,42 +37,6 @@ SYSLOG_HTML = """
Enable Syslog: <input type="checkbox" name="SL_en"><br>
Host: <input type="text" name="SL_host" maxlength="32"><br>
Port: <input type="number" name="SL_port" min="1" max="65535" value="%SL_port%"><br>
<!-- These UI elements are commented out but preserved for potential future use -->
<!--
Protocol:
<select name="SL_proto">
<option value="0">BSD (RFC3164)</option>
<option value="1">RFC5424</option>
<option value="2">Raw</option>
</select><br>
Facility:
<select name="SL_fac">
<option value="0">KERN</option>
<option value="1">USER</option>
<option value="3">DAEMON</option>
<option value="5">SYSLOG</option>
<option value="16">LOCAL0</option>
<option value="17">LOCAL1</option>
<option value="18">LOCAL2</option>
<option value="19">LOCAL3</option>
<option value="20">LOCAL4</option>
<option value="21">LOCAL5</option>
<option value="22">LOCAL6</option>
<option value="23">LOCAL7</option>
</select><br>
Severity:
<select name="SL_sev">
<option value="0">EMERG</option>
<option value="1">ALERT</option>
<option value="2">CRIT</option>
<option value="3">ERR</option>
<option value="4">WARNING</option>
<option value="5">NOTICE</option>
<option value="6">INFO</option>
<option value="7">DEBUG</option>
</select><br>
-->
</div>
"""
@ -120,15 +84,9 @@ def inject_syslog_ui(source, target, env, retry_count=0):
original = f.read()
modified = original
# replace existing section if present
if '<!-- SYSLOG-START -->' in modified and '<!-- SYSLOG-END -->' in modified:
start = modified.index('<!-- SYSLOG-START -->')
end = modified.index('<!-- SYSLOG-END -->') + len('<!-- SYSLOG-END -->')
modified = (
modified[:start]
+ '<!-- SYSLOG-START -->\n' + SYSLOG_HTML + '\n<!-- SYSLOG-END -->'
+ modified[end:]
)
# replace the single comment with HTML
if '<!-- SYSLOG-INJECT -->' in modified:
modified = modified.replace('<!-- SYSLOG-INJECT -->', SYSLOG_HTML)
else:
# insert before last <hr>
idx = modified.rfind('<hr>')
@ -137,7 +95,7 @@ def inject_syslog_ui(source, target, env, retry_count=0):
return
modified = (
modified[:idx]
+ '<!-- SYSLOG-START -->\n' + SYSLOG_HTML + '\n<!-- SYSLOG-END -->\n'
+ SYSLOG_HTML + '\n'
+ modified[idx:]
)
@ -160,7 +118,7 @@ def inject_syslog_ui(source, target, env, retry_count=0):
# verify that SYSLOG markers really are in the file
with open(html_path, 'r', encoding='utf8') as f:
content = f.read()
if '<!-- SYSLOG-START -->' not in content or '<!-- SYSLOG-END -->' not in content:
if '<!-- SYSLOG-INJECT -->' not in content:
print("Backup exists but SYSLOG markers missing—forcing re-injection.")
os.remove(bak)
# only retry up to 3 times

Wyświetl plik

@ -541,9 +541,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
CJSON(syslogEnabled, if_syslog["en"]);
getStringFromJson(syslogHost, if_syslog[F("host")], 33);
CJSON(syslogPort, if_syslog["port"]);
// CJSON(syslogProtocol, if_syslog["proto"]);
// CJSON(syslogFacility, if_syslog["fac"]);
// CJSON(syslogSeverity, if_syslog["sev"]);
#endif
JsonObject if_ntp = interfaces[F("ntp")];
@ -1066,9 +1063,6 @@ void serializeConfig(JsonObject root) {
if_syslog["en"] = syslogEnabled;
if_syslog["host"] = syslogHost;
if_syslog["port"] = syslogPort;
// if_syslog["proto"] = syslogProtocol;
// if_syslog["fac"] = syslogFacility;
// if_syslog["sev"] = syslogSeverity;
#endif
JsonObject if_ntp = interfaces.createNestedObject("ntp");

Wyświetl plik

@ -237,7 +237,7 @@ Baud rate:
</select><br>
<i>Keep at 115200 to use Improv. Some boards may not support high rates.</i>
</div>
<!-- SYSLOG-START --><!-- SYSLOG-END -->
<!-- SYSLOG-INJECT -->
<hr>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button>
</form>

Wyświetl plik

@ -479,16 +479,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
t = request->arg(F("SL_port")).toInt();
if (t > 0) syslogPort = t;
// t = request->arg(F("SL_proto")).toInt();
// if (t >= SYSLOG_PROTO_BSD && t <= SYSLOG_PROTO_RAW) syslogProtocol = t;
// t = request->arg(F("SL_fac")).toInt();
// if (t >= SYSLOG_KERN && t <= SYSLOG_LOCAL7) syslogFacility = t;
// t = request->arg(F("SL_sev")).toInt();
// if (t >= SYSLOG_EMERG && t <= SYSLOG_DEBUG) syslogSeverity = t;
Syslog.begin(syslogHost, syslogPort,
syslogFacility, syslogSeverity, syslogProtocol);

Wyświetl plik

@ -3,42 +3,6 @@
#include "syslog.h"
// Comment out but preserve the protocol names
/*
static const char* const protoNames[] PROGMEM = {
PSTR("BSD"),
PSTR("RFC5424"),
PSTR("RAW"),
PSTR("UNKNOWN")
};
static const uint8_t protoCount = sizeof(protoNames)/sizeof(*protoNames);
*/
// Comment out but preserve facility names
/*
// We fill invalid entries with PSTR("UNKNOWN") so we can index 0..24 safely
static const char* const facilityNames[] PROGMEM = {
PSTR("KERN"), PSTR("USER"), PSTR("UNKNOWN"), PSTR("DAEMON"),
PSTR("UNKNOWN"),PSTR("SYSLOG"), PSTR("UNKNOWN"), PSTR("UNKNOWN"),
PSTR("UNKNOWN"),PSTR("UNKNOWN"),PSTR("UNKNOWN"), PSTR("UNKNOWN"),
PSTR("UNKNOWN"),PSTR("UNKNOWN"),PSTR("UNKNOWN"), PSTR("UNKNOWN"),
PSTR("LCL0"), PSTR("LCL1"), PSTR("LCL2"), PSTR("LCL3"),
PSTR("LCL4"), PSTR("LCL5"), PSTR("LCL6"), PSTR("LCL7"),
PSTR("UNKNOWN") // catch-all at index 24
};
static const uint8_t facCount = sizeof(facilityNames)/sizeof(*facilityNames);
*/
// Comment out but preserve severity names
/*
static const char* const severityNames[] PROGMEM = {
PSTR("EMERG"), PSTR("ALERT"), PSTR("CRIT"), PSTR("ERR"),
PSTR("WARN"), PSTR("NOTE"), PSTR("INFO"), PSTR("DEBUG"),
PSTR("UNKNOWN")
};
static const uint8_t sevCount = sizeof(severityNames) / sizeof(*severityNames);
*/
SyslogPrinter::SyslogPrinter() :
_lastOperationSucceeded(true),
_lastErrorMessage(""),
@ -55,24 +19,6 @@ void SyslogPrinter::begin(const char* host, uint16_t port,
DEBUG_PRINTF_P(PSTR(" Hostname: %s\n"), host);
DEBUG_PRINTF_P(PSTR(" Cached IP: %s\n"), syslogHostIP.toString().c_str());
DEBUG_PRINTF_P(PSTR(" Port: %u\n"), (unsigned)port);
/*
// Protocol
uint8_t pidx = protocol < (protoCount - 1) ? protocol : (protoCount - 1);
const char* pstr = (const char*)pgm_read_ptr(&protoNames[pidx]);
DEBUG_PRINTF_P(PSTR(" Protocol: %u (%s)\n"), (unsigned)protocol, pstr);
// — Facility
uint8_t fidx = facility < (facCount - 1) ? facility : (facCount - 1);
const char* fstr = (const char*)pgm_read_ptr(&facilityNames[fidx]);
DEBUG_PRINTF_P(PSTR(" Facility: %u (%s)\n"), (unsigned)facility, fstr);
// Severity
uint8_t idx = severity < sevCount-1 ? severity : sevCount-1;
const char* sevStr = (const char*)pgm_read_ptr(&severityNames[idx]);
DEBUG_PRINTF_P(PSTR(" Severity: %u (%s)\n"), (unsigned)severity, sevStr);
*/
DEBUG_PRINTF_P(PSTR("======================================\n"));
strlcpy(syslogHost, host, sizeof(syslogHost));
@ -211,76 +157,35 @@ size_t SyslogPrinter::write(const uint8_t *buf, size_t size, uint8_t severity) {
String cleanHostname = String(serverDescription);
cleanHostname.replace(' ', '_');
// Handle different syslog protocol formats
// Note: Only BSD protocol is currently implemented; RFC5424 and RAW are preserved for future use
// switch (_protocol) {
// case SYSLOG_PROTO_BSD:
// RFC 3164 format: <PRI>TIMESTAMP HOSTNAME APP-NAME: MESSAGE
syslogUdp.printf("<%d>", pri);
if (ntpEnabled && ntpConnected) {
// Month abbreviation
static const char* const months[] = {
"Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec"
};
// Note: Only BSD protocol is currently implemented
syslogUdp.printf("<%d>", pri);
if (ntpEnabled && ntpConnected) {
// Month abbreviation
static const char* const months[] = {
"Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec"
};
syslogUdp.printf("%s %2d %02d:%02d:%02d ",
months[month(localTime) - 1],
day(localTime),
hour(localTime),
minute(localTime),
second(localTime));
} else {
// No valid time available
syslogUdp.print(F("Jan 01 00:00:00 "));
}
// Add hostname and app name
syslogUdp.print(cleanHostname);
syslogUdp.print(" ");
syslogUdp.print(_appName);
syslogUdp.print(": ");
// Add message content
size = syslogUdp.write(buf, size);
/*
break;
case SYSLOG_PROTO_RFC5424:
// RFC 5424 format: <PRI>VERSION TIMESTAMP HOSTNAME APP-NAME PROCID MSGID STRUCTURED-DATA MSG
syslogUdp.printf("<%d>1 ", pri); // Version is always 1
if (ntpEnabled && ntpConnected) {
syslogUdp.printf("%04d-%02d-%02dT%02d:%02d:%02dZ ",
year(localTime),
month(localTime),
day(localTime),
hour(localTime),
minute(localTime),
second(localTime));
} else {
// No valid time available
syslogUdp.print(F("1970-01-01T00:00:00Z "));
}
// Add hostname, app name, and other fields (using - for empty fields)
syslogUdp.print(cleanHostname);
syslogUdp.print(" ");
syslogUdp.print(_appName);
syslogUdp.print(F(" - - - ")); // PROCID, MSGID, and STRUCTURED-DATA are empty
// Add message content
size = syslogUdp.write(buf, size);
break;
case SYSLOG_PROTO_RAW:
default:
// Just send the raw message (like original NetDebug)
size = syslogUdp.write(buf, size);
break;
syslogUdp.printf("%s %2d %02d:%02d:%02d ",
months[month(localTime) - 1],
day(localTime),
hour(localTime),
minute(localTime),
second(localTime));
} else {
// No valid time available
syslogUdp.print(F("Jan 01 00:00:00 "));
}
*/
// Add hostname and app name
syslogUdp.print(cleanHostname);
syslogUdp.print(" ");
syslogUdp.print(_appName);
syslogUdp.print(": ");
// Add message content
size = syslogUdp.write(buf, size);
syslogUdp.endPacket();
return size;

Wyświetl plik

@ -8,42 +8,11 @@
#define SYSLOG_BUFFER_SIZE 128
#endif
// Syslog facility codes - commented out but preserved
/*
#define SYSLOG_KERN 0 // kernel messages
#define SYSLOG_USER 1 // user-level messages
#define SYSLOG_DAEMON 3 // system daemons
#define SYSLOG_SYSLOG 5 // messages generated internally by syslogd
*/
#define SYSLOG_LOCAL0 16 // local use 0
/*
#define SYSLOG_LOCAL1 17 // local use 1
#define SYSLOG_LOCAL2 18 // local use 2
#define SYSLOG_LOCAL3 19 // local use 3
#define SYSLOG_LOCAL4 20 // local use 4
#define SYSLOG_LOCAL5 21 // local use 5
#define SYSLOG_LOCAL6 22 // local use 6
#define SYSLOG_LOCAL7 23 // local use 7
*/
// Syslog severity levels - commented out but preserved
/*
#define SYSLOG_EMERG 0 // Emergency: system is unusable
#define SYSLOG_ALERT 1 // Alert: action must be taken immediately
#define SYSLOG_CRIT 2 // Critical: critical conditions
#define SYSLOG_ERR 3 // Error: error conditions
#define SYSLOG_WARNING 4 // Warning: warning conditions
#define SYSLOG_NOTICE 5 // Notice: normal but significant condition
#define SYSLOG_INFO 6 // Informational: informational messages
*/
#define SYSLOG_DEBUG 7 // Debug: debug-level messages
// Syslog protocol formats - commented out but preserved
#define SYSLOG_PROTO_BSD 0 // Legacy BSD format (RFC 3164)
/*
#define SYSLOG_PROTO_RFC5424 1 // Modern syslog format (RFC 5424)
#define SYSLOG_PROTO_RAW 2 // Raw text (like original NetDebug)
*/
class SyslogPrinter : public Print {
private: