Skip to content

Commit a77b85a

Browse files
authored
changes suggested by netmindz
1 parent 51bd04a commit a77b85a

File tree

6 files changed

+35
-218
lines changed

6 files changed

+35
-218
lines changed

pio-scripts/inject_syslog_ui.py

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -37,42 +37,6 @@ def set_syslog_state(project_dir, enabled):
3737
Enable Syslog: <input type="checkbox" name="SL_en"><br>
3838
Host: <input type="text" name="SL_host" maxlength="32"><br>
3939
Port: <input type="number" name="SL_port" min="1" max="65535" value="%SL_port%"><br>
40-
41-
<!-- These UI elements are commented out but preserved for potential future use -->
42-
<!--
43-
Protocol:
44-
<select name="SL_proto">
45-
<option value="0">BSD (RFC3164)</option>
46-
<option value="1">RFC5424</option>
47-
<option value="2">Raw</option>
48-
</select><br>
49-
Facility:
50-
<select name="SL_fac">
51-
<option value="0">KERN</option>
52-
<option value="1">USER</option>
53-
<option value="3">DAEMON</option>
54-
<option value="5">SYSLOG</option>
55-
<option value="16">LOCAL0</option>
56-
<option value="17">LOCAL1</option>
57-
<option value="18">LOCAL2</option>
58-
<option value="19">LOCAL3</option>
59-
<option value="20">LOCAL4</option>
60-
<option value="21">LOCAL5</option>
61-
<option value="22">LOCAL6</option>
62-
<option value="23">LOCAL7</option>
63-
</select><br>
64-
Severity:
65-
<select name="SL_sev">
66-
<option value="0">EMERG</option>
67-
<option value="1">ALERT</option>
68-
<option value="2">CRIT</option>
69-
<option value="3">ERR</option>
70-
<option value="4">WARNING</option>
71-
<option value="5">NOTICE</option>
72-
<option value="6">INFO</option>
73-
<option value="7">DEBUG</option>
74-
</select><br>
75-
-->
7640
</div>
7741
"""
7842

@@ -120,15 +84,9 @@ def inject_syslog_ui(source, target, env, retry_count=0):
12084
original = f.read()
12185
modified = original
12286

123-
# replace existing section if present
124-
if '<!-- SYSLOG-START -->' in modified and '<!-- SYSLOG-END -->' in modified:
125-
start = modified.index('<!-- SYSLOG-START -->')
126-
end = modified.index('<!-- SYSLOG-END -->') + len('<!-- SYSLOG-END -->')
127-
modified = (
128-
modified[:start]
129-
+ '<!-- SYSLOG-START -->\n' + SYSLOG_HTML + '\n<!-- SYSLOG-END -->'
130-
+ modified[end:]
131-
)
87+
# replace the single comment with HTML
88+
if '<!-- SYSLOG-INJECT -->' in modified:
89+
modified = modified.replace('<!-- SYSLOG-INJECT -->', SYSLOG_HTML)
13290
else:
13391
# insert before last <hr>
13492
idx = modified.rfind('<hr>')
@@ -137,7 +95,7 @@ def inject_syslog_ui(source, target, env, retry_count=0):
13795
return
13896
modified = (
13997
modified[:idx]
140-
+ '<!-- SYSLOG-START -->\n' + SYSLOG_HTML + '\n<!-- SYSLOG-END -->\n'
98+
+ SYSLOG_HTML + '\n'
14199
+ modified[idx:]
142100
)
143101

@@ -160,7 +118,7 @@ def inject_syslog_ui(source, target, env, retry_count=0):
160118
# verify that SYSLOG markers really are in the file
161119
with open(html_path, 'r', encoding='utf8') as f:
162120
content = f.read()
163-
if '<!-- SYSLOG-START -->' not in content or '<!-- SYSLOG-END -->' not in content:
121+
if '<!-- SYSLOG-INJECT -->' not in content:
164122
print("Backup exists but SYSLOG markers missing—forcing re-injection.")
165123
os.remove(bak)
166124
# only retry up to 3 times

wled00/cfg.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
541541
CJSON(syslogEnabled, if_syslog["en"]);
542542
getStringFromJson(syslogHost, if_syslog[F("host")], 33);
543543
CJSON(syslogPort, if_syslog["port"]);
544-
// CJSON(syslogProtocol, if_syslog["proto"]);
545-
// CJSON(syslogFacility, if_syslog["fac"]);
546-
// CJSON(syslogSeverity, if_syslog["sev"]);
547544
#endif
548545

549546
JsonObject if_ntp = interfaces[F("ntp")];
@@ -1066,9 +1063,6 @@ void serializeConfig(JsonObject root) {
10661063
if_syslog["en"] = syslogEnabled;
10671064
if_syslog["host"] = syslogHost;
10681065
if_syslog["port"] = syslogPort;
1069-
// if_syslog["proto"] = syslogProtocol;
1070-
// if_syslog["fac"] = syslogFacility;
1071-
// if_syslog["sev"] = syslogSeverity;
10721066
#endif
10731067

10741068
JsonObject if_ntp = interfaces.createNestedObject("ntp");

wled00/data/settings_sync.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ <h3>Serial</h3>
237237
</select><br>
238238
<i>Keep at 115200 to use Improv. Some boards may not support high rates.</i>
239239
</div>
240-
<!-- SYSLOG-START --><!-- SYSLOG-END -->
240+
<!-- SYSLOG-INJECT -->
241241
<hr>
242242
<button type="button" onclick="B()">Back</button><button type="submit">Save</button>
243243
</form>

wled00/set.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -479,16 +479,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
479479

480480
t = request->arg(F("SL_port")).toInt();
481481
if (t > 0) syslogPort = t;
482-
483-
// t = request->arg(F("SL_proto")).toInt();
484-
// if (t >= SYSLOG_PROTO_BSD && t <= SYSLOG_PROTO_RAW) syslogProtocol = t;
485-
486-
// t = request->arg(F("SL_fac")).toInt();
487-
// if (t >= SYSLOG_KERN && t <= SYSLOG_LOCAL7) syslogFacility = t;
488-
489-
// t = request->arg(F("SL_sev")).toInt();
490-
// if (t >= SYSLOG_EMERG && t <= SYSLOG_DEBUG) syslogSeverity = t;
491-
482+
492483
Syslog.begin(syslogHost, syslogPort,
493484
syslogFacility, syslogSeverity, syslogProtocol);
494485

wled00/syslog.cpp

Lines changed: 28 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,6 @@
33

44
#include "syslog.h"
55

6-
// Comment out but preserve the protocol names
7-
/*
8-
static const char* const protoNames[] PROGMEM = {
9-
PSTR("BSD"),
10-
PSTR("RFC5424"),
11-
PSTR("RAW"),
12-
PSTR("UNKNOWN")
13-
};
14-
static const uint8_t protoCount = sizeof(protoNames)/sizeof(*protoNames);
15-
*/
16-
17-
// Comment out but preserve facility names
18-
/*
19-
// We fill invalid entries with PSTR("UNKNOWN") so we can index 0..24 safely
20-
static const char* const facilityNames[] PROGMEM = {
21-
PSTR("KERN"), PSTR("USER"), PSTR("UNKNOWN"), PSTR("DAEMON"),
22-
PSTR("UNKNOWN"),PSTR("SYSLOG"), PSTR("UNKNOWN"), PSTR("UNKNOWN"),
23-
PSTR("UNKNOWN"),PSTR("UNKNOWN"),PSTR("UNKNOWN"), PSTR("UNKNOWN"),
24-
PSTR("UNKNOWN"),PSTR("UNKNOWN"),PSTR("UNKNOWN"), PSTR("UNKNOWN"),
25-
PSTR("LCL0"), PSTR("LCL1"), PSTR("LCL2"), PSTR("LCL3"),
26-
PSTR("LCL4"), PSTR("LCL5"), PSTR("LCL6"), PSTR("LCL7"),
27-
PSTR("UNKNOWN") // catch-all at index 24
28-
};
29-
static const uint8_t facCount = sizeof(facilityNames)/sizeof(*facilityNames);
30-
*/
31-
32-
// Comment out but preserve severity names
33-
/*
34-
static const char* const severityNames[] PROGMEM = {
35-
PSTR("EMERG"), PSTR("ALERT"), PSTR("CRIT"), PSTR("ERR"),
36-
PSTR("WARN"), PSTR("NOTE"), PSTR("INFO"), PSTR("DEBUG"),
37-
PSTR("UNKNOWN")
38-
};
39-
static const uint8_t sevCount = sizeof(severityNames) / sizeof(*severityNames);
40-
*/
41-
426
SyslogPrinter::SyslogPrinter() :
437
_lastOperationSucceeded(true),
448
_lastErrorMessage(""),
@@ -55,24 +19,6 @@ void SyslogPrinter::begin(const char* host, uint16_t port,
5519
DEBUG_PRINTF_P(PSTR(" Hostname: %s\n"), host);
5620
DEBUG_PRINTF_P(PSTR(" Cached IP: %s\n"), syslogHostIP.toString().c_str());
5721
DEBUG_PRINTF_P(PSTR(" Port: %u\n"), (unsigned)port);
58-
59-
/*
60-
// Protocol
61-
uint8_t pidx = protocol < (protoCount - 1) ? protocol : (protoCount - 1);
62-
const char* pstr = (const char*)pgm_read_ptr(&protoNames[pidx]);
63-
DEBUG_PRINTF_P(PSTR(" Protocol: %u (%s)\n"), (unsigned)protocol, pstr);
64-
65-
// — Facility
66-
uint8_t fidx = facility < (facCount - 1) ? facility : (facCount - 1);
67-
const char* fstr = (const char*)pgm_read_ptr(&facilityNames[fidx]);
68-
DEBUG_PRINTF_P(PSTR(" Facility: %u (%s)\n"), (unsigned)facility, fstr);
69-
70-
// Severity
71-
uint8_t idx = severity < sevCount-1 ? severity : sevCount-1;
72-
const char* sevStr = (const char*)pgm_read_ptr(&severityNames[idx]);
73-
DEBUG_PRINTF_P(PSTR(" Severity: %u (%s)\n"), (unsigned)severity, sevStr);
74-
*/
75-
7622
DEBUG_PRINTF_P(PSTR("======================================\n"));
7723

7824
strlcpy(syslogHost, host, sizeof(syslogHost));
@@ -211,76 +157,35 @@ size_t SyslogPrinter::write(const uint8_t *buf, size_t size, uint8_t severity) {
211157
String cleanHostname = String(serverDescription);
212158
cleanHostname.replace(' ', '_');
213159

214-
// Handle different syslog protocol formats
215-
// Note: Only BSD protocol is currently implemented; RFC5424 and RAW are preserved for future use
216-
// switch (_protocol) {
217-
// case SYSLOG_PROTO_BSD:
218-
// RFC 3164 format: <PRI>TIMESTAMP HOSTNAME APP-NAME: MESSAGE
219-
syslogUdp.printf("<%d>", pri);
220-
221-
if (ntpEnabled && ntpConnected) {
222-
// Month abbreviation
223-
static const char* const months[] = {
224-
"Jan","Feb","Mar","Apr","May","Jun",
225-
"Jul","Aug","Sep","Oct","Nov","Dec"
226-
};
227-
228-
syslogUdp.printf("%s %2d %02d:%02d:%02d ",
229-
months[month(localTime) - 1],
230-
day(localTime),
231-
hour(localTime),
232-
minute(localTime),
233-
second(localTime));
234-
} else {
235-
// No valid time available
236-
syslogUdp.print(F("Jan 01 00:00:00 "));
237-
}
238-
239-
// Add hostname and app name
240-
syslogUdp.print(cleanHostname);
241-
syslogUdp.print(" ");
242-
syslogUdp.print(_appName);
243-
syslogUdp.print(": ");
244-
245-
// Add message content
246-
size = syslogUdp.write(buf, size);
247-
/*
248-
break;
249-
250-
case SYSLOG_PROTO_RFC5424:
251-
// RFC 5424 format: <PRI>VERSION TIMESTAMP HOSTNAME APP-NAME PROCID MSGID STRUCTURED-DATA MSG
252-
syslogUdp.printf("<%d>1 ", pri); // Version is always 1
253-
254-
if (ntpEnabled && ntpConnected) {
255-
syslogUdp.printf("%04d-%02d-%02dT%02d:%02d:%02dZ ",
256-
year(localTime),
257-
month(localTime),
258-
day(localTime),
259-
hour(localTime),
260-
minute(localTime),
261-
second(localTime));
262-
} else {
263-
// No valid time available
264-
syslogUdp.print(F("1970-01-01T00:00:00Z "));
265-
}
266-
267-
// Add hostname, app name, and other fields (using - for empty fields)
268-
syslogUdp.print(cleanHostname);
269-
syslogUdp.print(" ");
270-
syslogUdp.print(_appName);
271-
syslogUdp.print(F(" - - - ")); // PROCID, MSGID, and STRUCTURED-DATA are empty
272-
273-
// Add message content
274-
size = syslogUdp.write(buf, size);
275-
break;
276-
277-
case SYSLOG_PROTO_RAW:
278-
default:
279-
// Just send the raw message (like original NetDebug)
280-
size = syslogUdp.write(buf, size);
281-
break;
160+
// Note: Only BSD protocol is currently implemented
161+
syslogUdp.printf("<%d>", pri);
162+
163+
if (ntpEnabled && ntpConnected) {
164+
// Month abbreviation
165+
static const char* const months[] = {
166+
"Jan","Feb","Mar","Apr","May","Jun",
167+
"Jul","Aug","Sep","Oct","Nov","Dec"
168+
};
169+
170+
syslogUdp.printf("%s %2d %02d:%02d:%02d ",
171+
months[month(localTime) - 1],
172+
day(localTime),
173+
hour(localTime),
174+
minute(localTime),
175+
second(localTime));
176+
} else {
177+
// No valid time available
178+
syslogUdp.print(F("Jan 01 00:00:00 "));
282179
}
283-
*/
180+
181+
// Add hostname and app name
182+
syslogUdp.print(cleanHostname);
183+
syslogUdp.print(" ");
184+
syslogUdp.print(_appName);
185+
syslogUdp.print(": ");
186+
187+
// Add message content
188+
size = syslogUdp.write(buf, size);
284189

285190
syslogUdp.endPacket();
286191
return size;

wled00/syslog.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,11 @@
88
#define SYSLOG_BUFFER_SIZE 128
99
#endif
1010

11-
// Syslog facility codes - commented out but preserved
12-
/*
13-
#define SYSLOG_KERN 0 // kernel messages
14-
#define SYSLOG_USER 1 // user-level messages
15-
#define SYSLOG_DAEMON 3 // system daemons
16-
#define SYSLOG_SYSLOG 5 // messages generated internally by syslogd
17-
*/
1811
#define SYSLOG_LOCAL0 16 // local use 0
19-
/*
20-
#define SYSLOG_LOCAL1 17 // local use 1
21-
#define SYSLOG_LOCAL2 18 // local use 2
22-
#define SYSLOG_LOCAL3 19 // local use 3
23-
#define SYSLOG_LOCAL4 20 // local use 4
24-
#define SYSLOG_LOCAL5 21 // local use 5
25-
#define SYSLOG_LOCAL6 22 // local use 6
26-
#define SYSLOG_LOCAL7 23 // local use 7
27-
*/
28-
29-
// Syslog severity levels - commented out but preserved
30-
/*
31-
#define SYSLOG_EMERG 0 // Emergency: system is unusable
32-
#define SYSLOG_ALERT 1 // Alert: action must be taken immediately
33-
#define SYSLOG_CRIT 2 // Critical: critical conditions
34-
#define SYSLOG_ERR 3 // Error: error conditions
35-
#define SYSLOG_WARNING 4 // Warning: warning conditions
36-
#define SYSLOG_NOTICE 5 // Notice: normal but significant condition
37-
#define SYSLOG_INFO 6 // Informational: informational messages
38-
*/
3912
#define SYSLOG_DEBUG 7 // Debug: debug-level messages
4013

4114
// Syslog protocol formats - commented out but preserved
4215
#define SYSLOG_PROTO_BSD 0 // Legacy BSD format (RFC 3164)
43-
/*
44-
#define SYSLOG_PROTO_RFC5424 1 // Modern syslog format (RFC 5424)
45-
#define SYSLOG_PROTO_RAW 2 // Raw text (like original NetDebug)
46-
*/
4716

4817
class SyslogPrinter : public Print {
4918
private:

0 commit comments

Comments
 (0)