Skip to content

Commit 7a17b0d

Browse files
authored
Merge branch 'master' into issue-3302
2 parents 97eb3b1 + cc72213 commit 7a17b0d

32 files changed

+916
-220
lines changed

NEWS.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ https://github.com/networkupstools/nut/milestone/12
113113
operations. (Re-)registration of the "Network UPS Tools" service should
114114
now populate a nice description of it. The `-U` (uninstall) action should
115115
now also try to stop the service first. [PR #3235]
116+
* Using `nut.exe -N` for testing and pressing 'Ctrl+C' should now cause the
117+
started daemons to be killed off. Previously they would linger and e.g.
118+
preclude subsequent experiments with the service wrapper. Console close
119+
events are ignored, so there is a way to indefinitely keep the daemons
120+
started by test-mode wrapper running (kill via Task Manager). [#3312]
116121
* Revised WIN32 `WSAStartup()` and registration of `atexit(WSACleanup)` to
117122
only be done once per program (and cleanups to be always registered); this
118123
impacts the C `libupsclient` and C++ `libnutclient` libraries (and so most
@@ -276,6 +281,10 @@ https://github.com/networkupstools/nut/milestone/12
276281
built-in NUT configuration path on all platforms, but to also consider
277282
`NUT_CONFPATH` and other fallback locations, like other code does.
278283
[PR #3249]
284+
* Enhance debug-logging of dynamic library loading with information about
285+
any missing method in the library discovered at run-time, if lack of such
286+
prevents us from using that library, and blocks scanning of corresponding
287+
protocol and/or media to discover possibly supported devices. [PR #3310]
279288
* Introduced `nut-scanner` support for new `nut-upower` driver. [PR #3293]
280289

281290
- `upsd` data server updates:
@@ -342,6 +351,9 @@ several `FSD` notifications into one executed action. [PR #3097]
342351
* Introduced a `@NUT_UPSSTATS_TEMPLATE@` command which the HTML template
343352
files now MUST start with (safety check that we are reading a template).
344353
[issue #3252, PR #3249]
354+
* (Experimental) Custom templates other than `upsstats{,-single}.html` can
355+
now be specified as CGI parameters, if locally permitted via `hosts.conf`.
356+
[issue #2524, PR #3304]
345357

346358
- `upssched` tool updates:
347359
* Previously in PR #2896 (NUT releases v2.8.3 and v2.8.4) the `UPSNAME` and

clients/cgilib.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,15 @@ void extractcgiargs(void)
8787
while (ptr) {
8888
varname = ptr;
8989
eq = strchr(varname, '=');
90-
if (!eq) {
91-
ptr = strchr(varname, '&');
90+
amp = strchr(varname, '&');
91+
if (!eq
92+
|| (eq && amp && amp < eq)
93+
) {
94+
/* Last token is a flag (without assignment in sight),
95+
* OR we've got a flag token in the middle of a query
96+
* string, followed by another key=value pair later on.
97+
*/
98+
ptr = amp;
9299
if (ptr)
93100
*ptr++ = '\0';
94101

@@ -99,6 +106,8 @@ void extractcgiargs(void)
99106
continue;
100107
}
101108

109+
/* The nearest point of interest is a key=value pair,
110+
* maybe followed by another amp and flag or assignment... */
102111
*eq = '\0';
103112
value = eq + 1;
104113
amp = strchr(value, '&');
@@ -111,6 +120,8 @@ void extractcgiargs(void)
111120

112121
cleanvar = unescape(varname);
113122
cleanval = unescape(value);
123+
upsdebugx(3, "%s: parsearg('%s', '%s')<br/>",
124+
__func__, NUT_STRARG(cleanvar), NUT_STRARG(cleanval));
114125
parsearg(cleanvar, cleanval);
115126
free(cleanvar);
116127
free(cleanval);

clients/upsclient.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ int upscli_init(int certverify, const char *certpath,
501501
void upscli_add_host_cert(const char* hostname, const char* certname, int certverify, int forcessl)
502502
{
503503
#ifdef WITH_NSS
504-
HOST_CERT_t* cert = xmalloc(sizeof(HOST_CERT_t));
504+
HOST_CERT_t* cert = (HOST_CERT_t *)xmalloc(sizeof(HOST_CERT_t));
505505
cert->next = first_host_cert;
506506
cert->host = xstrdup(hostname);
507507
cert->certname = xstrdup(certname);

clients/upsimage.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
Copyrights:
2121
(C) 1998 Russell Kroll <rkroll@exploits.org>
2222
(C) 2002 Simon Rozman <simon@rozman.net>
23+
(C) 2020-2026 Jim Klimov <jimklimov+nut@gmail.com>
2324
2425
This program is free software; you can redistribute it and/or modify
2526
it under the terms of the GNU General Public License as published by
@@ -619,14 +620,14 @@ int main(int argc, char **argv)
619620
double var = 0;
620621

621622
#ifdef WIN32
622-
/* Required ritual before calling any socket functions */
623-
static WSADATA WSAdata;
624-
static int WSA_Started = 0;
625-
if (!WSA_Started) {
626-
WSAStartup(2, &WSAdata);
627-
atexit((void(*)(void))WSACleanup);
628-
WSA_Started = 1;
629-
}
623+
/* Required ritual before calling any socket functions */
624+
static WSADATA WSAdata;
625+
static int WSA_Started = 0;
626+
if (!WSA_Started) {
627+
WSAStartup(2, &WSAdata);
628+
atexit((void(*)(void))WSACleanup);
629+
WSA_Started = 1;
630+
}
630631

631632
/* Avoid binary output conversions, e.g.
632633
* mangling what looks like CRLF on WIN32 */
@@ -646,6 +647,23 @@ int main(int argc, char **argv)
646647
nut_debug_level = i;
647648
}
648649

650+
#ifdef NUT_CGI_DEBUG_UPSIMAGE
651+
# if (NUT_CGI_DEBUG_UPSIMAGE - 0 < 1)
652+
# undef NUT_CGI_DEBUG_UPSIMAGE
653+
# define NUT_CGI_DEBUG_UPSIMAGE 6
654+
# endif
655+
/* Un-comment via make flags when developer-troubleshooting: */
656+
nut_debug_level = NUT_CGI_DEBUG_UPSIMAGE;
657+
#endif
658+
659+
if (nut_debug_level > 0) {
660+
cgilogbit_set();
661+
printf("Content-type: text/html\n");
662+
printf("Pragma: no-cache\n");
663+
printf("\n");
664+
printf("<p>NUT CGI Debugging enabled, level: %d</p>\n\n", nut_debug_level);
665+
}
666+
649667
extractcgiargs();
650668

651669
upscli_init_default_connect_timeout(NULL, NULL, UPSCLI_DEFAULT_CONNECT_TIMEOUT);

clients/upsset.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* upsset - CGI program to manage read/write variables
22
33
Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
4+
Copyright (C) 2020-2026 Jim Klimov <jimklimov+nut@gmail.com>
45
56
This program is free software; you can redistribute it and/or modify
67
it under the terms of the GNU General Public License as published by
@@ -1116,14 +1117,14 @@ int main(int argc, char **argv)
11161117
int i;
11171118

11181119
#ifdef WIN32
1119-
/* Required ritual before calling any socket functions */
1120-
static WSADATA WSAdata;
1121-
static int WSA_Started = 0;
1122-
if (!WSA_Started) {
1123-
WSAStartup(2, &WSAdata);
1124-
atexit((void(*)(void))WSACleanup);
1125-
WSA_Started = 1;
1126-
}
1120+
/* Required ritual before calling any socket functions */
1121+
static WSADATA WSAdata;
1122+
static int WSA_Started = 0;
1123+
if (!WSA_Started) {
1124+
WSAStartup(2, &WSAdata);
1125+
atexit((void(*)(void))WSACleanup);
1126+
WSA_Started = 1;
1127+
}
11271128

11281129
/* Avoid binary output conversions, e.g.
11291130
* mangling what looks like CRLF on WIN32 */
@@ -1136,7 +1137,9 @@ int main(int argc, char **argv)
11361137
NUT_UNUSED_VARIABLE(argv);
11371138
username = password = function = monups = NULL;
11381139

1139-
printf("Content-type: text/html\n\n");
1140+
printf("Content-type: text/html\n");
1141+
printf("Pragma: no-cache\n");
1142+
printf("\n");
11401143

11411144
/* NOTE: Caller must `export NUT_DEBUG_LEVEL` to see debugs for upsc
11421145
* and NUT methods called from it. This line aims to just initialize
@@ -1148,6 +1151,20 @@ int main(int argc, char **argv)
11481151
nut_debug_level = i;
11491152
}
11501153

1154+
#ifdef NUT_CGI_DEBUG_UPSSET
1155+
# if (NUT_CGI_DEBUG_UPSSET - 0 < 1)
1156+
# undef NUT_CGI_DEBUG_UPSSET
1157+
# define NUT_CGI_DEBUG_UPSSET 6
1158+
# endif
1159+
/* Un-comment via make flags when developer-troubleshooting: */
1160+
nut_debug_level = NUT_CGI_DEBUG_UPSSET;
1161+
#endif
1162+
1163+
if (nut_debug_level > 0) {
1164+
cgilogbit_set();
1165+
printf("<p>NUT CGI Debugging enabled, level: %d</p>\n\n", nut_debug_level);
1166+
}
1167+
11511168
/* see if the magic string is present in the config file */
11521169
check_conf();
11531170

0 commit comments

Comments
 (0)