Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ several `FSD` notifications into one executed action. [PR #3097]
* Introduced a `@NUT_UPSSTATS_TEMPLATE@` command which the HTML template
files now MUST start with (safety check that we are reading a template).
[issue #3252, PR #3249]
* (Experimental) Custom templates other than `upsstats{,-single}.html` can
now be specified as CGI parameters, if locally permitted via `hosts.conf`.
[issue #2524, PR #3304]

- `upssched` tool updates:
* Previously in PR #2896 (NUT releases v2.8.3 and v2.8.4) the `UPSNAME` and
Expand Down
15 changes: 13 additions & 2 deletions clients/cgilib.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,15 @@ void extractcgiargs(void)
while (ptr) {
varname = ptr;
eq = strchr(varname, '=');
if (!eq) {
ptr = strchr(varname, '&');
amp = strchr(varname, '&');
if (!eq
|| (eq && amp && amp < eq)
) {
/* Last token is a flag (without assignment in sight),
* OR we've got a flag token in the middle of a query
* string, followed by another key=value pair later on.
*/
ptr = amp;
if (ptr)
*ptr++ = '\0';

Expand All @@ -99,6 +106,8 @@ void extractcgiargs(void)
continue;
}

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

cleanvar = unescape(varname);
cleanval = unescape(value);
upsdebugx(3, "%s: parsearg('%s', '%s')<br/>",
__func__, NUT_STRARG(cleanvar), NUT_STRARG(cleanval));
parsearg(cleanvar, cleanval);
free(cleanvar);
free(cleanval);
Expand Down
34 changes: 26 additions & 8 deletions clients/upsimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Copyrights:
(C) 1998 Russell Kroll <rkroll@exploits.org>
(C) 2002 Simon Rozman <simon@rozman.net>
(C) 2020-2026 Jim Klimov <jimklimov+nut@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -619,14 +620,14 @@ int main(int argc, char **argv)
double var = 0;

#ifdef WIN32
/* Required ritual before calling any socket functions */
static WSADATA WSAdata;
static int WSA_Started = 0;
if (!WSA_Started) {
WSAStartup(2, &WSAdata);
atexit((void(*)(void))WSACleanup);
WSA_Started = 1;
}
/* Required ritual before calling any socket functions */
static WSADATA WSAdata;
static int WSA_Started = 0;
if (!WSA_Started) {
WSAStartup(2, &WSAdata);
atexit((void(*)(void))WSACleanup);
WSA_Started = 1;
}

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

#ifdef NUT_CGI_DEBUG_UPSIMAGE
# if (NUT_CGI_DEBUG_UPSIMAGE - 0 < 1)
# undef NUT_CGI_DEBUG_UPSIMAGE
# define NUT_CGI_DEBUG_UPSIMAGE 6
# endif
/* Un-comment via make flags when developer-troubleshooting: */
nut_debug_level = NUT_CGI_DEBUG_UPSIMAGE;
#endif

if (nut_debug_level > 0) {
cgilogbit_set();
printf("Content-type: text/html\n");
printf("Pragma: no-cache\n");
printf("\n");
printf("<p>NUT CGI Debugging enabled, level: %d</p>\n\n", nut_debug_level);
}

extractcgiargs();

upscli_init_default_connect_timeout(NULL, NULL, UPSCLI_DEFAULT_CONNECT_TIMEOUT);
Expand Down
35 changes: 26 additions & 9 deletions clients/upsset.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* upsset - CGI program to manage read/write variables

Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
Copyright (C) 2020-2026 Jim Klimov <jimklimov+nut@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1116,14 +1117,14 @@ int main(int argc, char **argv)
int i;

#ifdef WIN32
/* Required ritual before calling any socket functions */
static WSADATA WSAdata;
static int WSA_Started = 0;
if (!WSA_Started) {
WSAStartup(2, &WSAdata);
atexit((void(*)(void))WSACleanup);
WSA_Started = 1;
}
/* Required ritual before calling any socket functions */
static WSADATA WSAdata;
static int WSA_Started = 0;
if (!WSA_Started) {
WSAStartup(2, &WSAdata);
atexit((void(*)(void))WSACleanup);
WSA_Started = 1;
}

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

printf("Content-type: text/html\n\n");
printf("Content-type: text/html\n");
printf("Pragma: no-cache\n");
printf("\n");

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

#ifdef NUT_CGI_DEBUG_UPSSET
# if (NUT_CGI_DEBUG_UPSSET - 0 < 1)
# undef NUT_CGI_DEBUG_UPSSET
# define NUT_CGI_DEBUG_UPSSET 6
# endif
/* Un-comment via make flags when developer-troubleshooting: */
nut_debug_level = NUT_CGI_DEBUG_UPSSET;
#endif

if (nut_debug_level > 0) {
cgilogbit_set();
printf("<p>NUT CGI Debugging enabled, level: %d</p>\n\n", nut_debug_level);
}

/* see if the magic string is present in the config file */
check_conf();

Expand Down
Loading
Loading