diff --git a/NEWS.adoc b/NEWS.adoc index e18dc2bc09..23b9f8f38d 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -344,7 +344,7 @@ several `FSD` notifications into one executed action. [PR #3097] - `upsset` should now recognize `RANGE NUMBER` and `NUMBER` types. [#3164] - - `upsstats` tool updates: + - `upsstats` CGI tool updates: * Now has JSON output mode via `?json` (or `&json`) CGI query parameter. New `@TREELINK_JSON@` keyword added and HTML templates updated to expose these JSON documents when browsing. [issue #2524, PRs #3171, #3249] @@ -357,7 +357,7 @@ several `FSD` notifications into one executed action. [PR #3097] [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] + Modern-looking templates were provided. [issues #2524, #3316, PR #3304] - `upssched` tool updates: * Previously in PR #2896 (NUT releases v2.8.3 and v2.8.4) the `UPSNAME` and diff --git a/clients/upsstats.c b/clients/upsstats.c index 04c74c70e5..d630769c8c 100644 --- a/clients/upsstats.c +++ b/clients/upsstats.c @@ -67,6 +67,9 @@ static char *upsimgpath = "upsimage.cgi" EXEEXT, *upsstatpath = "upsstats.cgi" E *template_single = NULL, *template_list = NULL; static UPSCONN_t ups; +#define DEFAULT_TEMPLATE_SINGLE "upsstats-single.html" +#define DEFAULT_TEMPLATE_LIST "upsstats.html" + static FILE *tf; static long forofs = 0; @@ -546,11 +549,11 @@ static void do_hostlink(void) printf("sys); - if (template_single && strcmp(template_single, "upsstats-single.html")) { + if (template_single && strcmp(template_single, DEFAULT_TEMPLATE_SINGLE)) { printf("&template_single=%s", template_single); } - if (template_list && strcmp(template_list, "upsstats.html")) { + if (template_list && strcmp(template_list, DEFAULT_TEMPLATE_LIST)) { printf("&template_list=%s", template_list); } @@ -574,11 +577,11 @@ static void do_treelink_json(const char *text) printf("sys); - if (template_single && strcmp(template_single, "upsstats-single.html")) { + if (template_single && strcmp(template_single, DEFAULT_TEMPLATE_SINGLE)) { printf("&template_single=%s", template_single); } - if (template_list && strcmp(template_list, "upsstats.html")) { + if (template_list && strcmp(template_list, DEFAULT_TEMPLATE_LIST)) { printf("&template_list=%s", template_list); } @@ -604,11 +607,11 @@ static void do_treelink(const char *text) printf("sys); - if (template_single && strcmp(template_single, "upsstats-single.html")) { + if (template_single && strcmp(template_single, DEFAULT_TEMPLATE_SINGLE)) { printf("&template_single=%s", template_single); } - if (template_list && strcmp(template_list, "upsstats.html")) { + if (template_list && strcmp(template_list, DEFAULT_TEMPLATE_LIST)) { printf("&template_list=%s", template_list); } @@ -630,6 +633,13 @@ static void do_ifsupp(const char *var, const char *val) upsdebug_call_starting3("for '%s' ( =? '%s')", NUT_STRARG(var), NUT_STRARG(val)); + if (!strcmp(var, "upsstats.use_celsius")) { + snprintf(dummy, sizeof(dummy), "%d", use_celsius); + skip_clause = 1; + upsdebug_call_finished1(": get_var() returned unexpected val"); + return; + } + /* if not connected, act like it's not supported and skip the rest */ if (!check_ups_fd(0)) { skip_clause = 1; @@ -1720,8 +1730,8 @@ int main(int argc, char **argv) } /* Built-in defaults */ - template_single = xstrdup("upsstats-single.html"); - template_list = xstrdup("upsstats.html"); + template_single = xstrdup(DEFAULT_TEMPLATE_SINGLE); + template_list = xstrdup(DEFAULT_TEMPLATE_LIST); extractcgiargs(); @@ -1762,8 +1772,8 @@ int main(int argc, char **argv) /* if a host is specified, use upsstats-single.html instead * of listing whatever we know about with upsstats.html */ - add_allowed_template_single("upsstats-single.html"); - add_allowed_template_list("upsstats.html"); + add_allowed_template_single(DEFAULT_TEMPLATE_SINGLE); + add_allowed_template_list(DEFAULT_TEMPLATE_LIST); if (monhost) { load_hosts_conf(0); display_single(); diff --git a/conf/.gitignore b/conf/.gitignore index b65c1e01a2..fb8a2fe90d 100644 --- a/conf/.gitignore +++ b/conf/.gitignore @@ -2,3 +2,5 @@ /upssched.conf.sample /upsstats-single.html.sample /upsstats.html.sample +/upsstats-modern-single.html.sample +/upsstats-modern-list.html.sample diff --git a/conf/Makefile.am b/conf/Makefile.am index 0bd66744b7..a3f49f9a6a 100644 --- a/conf/Makefile.am +++ b/conf/Makefile.am @@ -11,7 +11,8 @@ SECFILES_GENERATED = upsmon.conf.sample PUBFILES_STATIC = nut.conf.sample PUBFILES_GENERATED = upssched.conf.sample CGIPUB_STATIC = hosts.conf.sample upsset.conf.sample -CGIPUB_GENERATED = upsstats.html.sample upsstats-single.html.sample +CGIPUB_GENERATED = upsstats.html.sample upsstats-single.html.sample \ + upsstats-modern-list.html.sample upsstats-modern-single.html.sample SECFILES = $(SECFILES_STATIC) $(SECFILES_GENERATED) @@ -31,6 +32,7 @@ nodist_conf_examples_DATA = $(SECFILES_GENERATED) $(PUBFILES_GENERATED) \ SPELLCHECK_SRC = $(dist_sysconf_DATA) \ upssched.conf.sample.in upsmon.conf.sample.in \ + upsstats-modern-list.html.sample.in upsstats-modern-single.html.sample.in \ upsstats.html.sample.in upsstats-single.html.sample.in # NOTE: Due to portability, we do not use a GNU percent-wildcard extension. diff --git a/conf/hosts.conf.sample b/conf/hosts.conf.sample index ef9fb8b525..3dec950898 100644 --- a/conf/hosts.conf.sample +++ b/conf/hosts.conf.sample @@ -51,6 +51,10 @@ # and contain `.htm` in the file name. # # CUSTOM_TEMPLATE_LIST +# +# Examples: +# +# CUSTOM_TEMPLATE_LIST "upsstats-modern-list.html" # ----------------------------------------------------------------------- # @@ -59,3 +63,7 @@ # configuration directory and contain `.htm` in the file name. # # CUSTOM_TEMPLATE_SINGLE +# +# Examples: +# +# CUSTOM_TEMPLATE_SINGLE "upsstats-modern-single.html" diff --git a/conf/upsstats-modern-list.html.sample.in b/conf/upsstats-modern-list.html.sample.in new file mode 100644 index 0000000000..95e1d6dcb3 --- /dev/null +++ b/conf/upsstats-modern-list.html.sample.in @@ -0,0 +1,221 @@ +@NUT_UPSSTATS_TEMPLATE default@ + + + + + + +@TEMPC@ + + + +@UPSSTATSPATH upsstats.cgi@EXEEXT@@ +@UPSIMAGEPATH upsimage.cgi@EXEEXT@@ + + + + + + + + +@REFRESH@ +Network UPS Tools: Overview + + + + + +
+
+
+

Network UPS Tools

+
System Overview
+
+
@DATE %a %b %d %X %Z %Y@
+
+ +
+ + + + + + + + + + + + + + + + +@FOREACHUPS@ + + + + + + + + + +@IFSUPP input.L2-L3.voltage@ +@IFBETWEEN input.transfer.low input.transfer.high input.L1-L2.voltage@ +@IFBETWEEN input.transfer.low input.transfer.high input.L2-L3.voltage@ +@IFBETWEEN input.transfer.low input.transfer.high input.L3-L1.voltage@ + + + + + + + + + + + + +@ENDFOR@ + +
SystemModelStatusBatteryInputOutputLoadTempRuntimeDetails
+@IFSUPP device.model@ +@VAR device.model@ +@ELSE@ +@VAR ups.model@ +@ENDIF@ +@STATUS@@IFSUPP battery.charge@@VAR battery.charge@ %@ENDIF@ +@ELSE@ +@IFSUPP input.L2-N.voltage@ +@IFBETWEEN input.transfer.low input.transfer.high input.L1-N.voltage@ +@IFBETWEEN input.transfer.low input.transfer.high input.L2-N.voltage@ +@IFBETWEEN input.transfer.low input.transfer.high input.L3-N.voltage@ + +@ELSE@ +@IFBETWEEN input.transfer.low input.transfer.high input.voltage@ + +@ELSE@ + +@ENDIF@ + +@IFSUPP input.L2-L3.voltage@ +L1-L2: @VAR input.L1-L2.voltage@ V
+L2-L3: @VAR input.L2-L3.voltage@ V
+L3-L1: @VAR input.L3-L1.voltage@ V +@ELSE@ +@IFSUPP input.L2-N.voltage@ +L1-N: @VAR input.L1-N.voltage@ V
+L2-N: @VAR input.L2-N.voltage@ V
+L3-N: @VAR input.L3-N.voltage@ V +@ELSE@ +@IFSUPP input.voltage@ +@VAR input.voltage@ V +@ENDIF@ +
+@IFSUPP output.L2-L3.voltage@ +L1-L2: @VAR output.L1-L2.voltage@ V
+L2-L3: @VAR output.L2-L3.voltage@ V
+L3-L1: @VAR output.L3-L1.voltage@ V +@ELSE@ +@IFSUPP output.L2-N.voltage@ +L1-N: @VAR output.L1-N.voltage@ V
+L2-N: @VAR output.L2-N.voltage@ V
+L3-N: @VAR output.L3-N.voltage@ V +@ELSE@ +@IFSUPP output.voltage@ +@VAR output.voltage@ V +@ENDIF@ +
+@IFSUPP output.L2.power.percent@ +L1: @VAR output.L1.power.percent@%
+L2: @VAR output.L2.power.percent@%
+L3: @VAR output.L3.power.percent@% +@ELSE@ +@IFSUPP output.L2.realpower.percent@ +L1: @VAR output.L1.realpower.percent@%
+L2: @VAR output.L2.realpower.percent@%
+L3: @VAR output.L3.realpower.percent@% +@ELSE@ +@IFSUPP ups.load@ +@VAR ups.load@ % +@ENDIF@ +
+@IFSUPP ups.temperature@ +@UPSTEMP@ @DEGREES@ +@ELSE@ +@IFSUPP battery.temperature@ +@BATTTEMP@ @DEGREES@ +@ENDIF@ +@IFSUPP battery.runtime@@RUNTIME@@ENDIF@
+ +
+JSON +Valid CSS +Valid HTML 4.01 Strict +

Network UPS Tools upsstats @ESCAPED_TEMPLATE_VERSION@

+
+ +
+
+ + diff --git a/conf/upsstats-modern-single.html.sample.in b/conf/upsstats-modern-single.html.sample.in new file mode 100644 index 0000000000..54261e89e3 --- /dev/null +++ b/conf/upsstats-modern-single.html.sample.in @@ -0,0 +1,1052 @@ +@NUT_UPSSTATS_TEMPLATE single@ + + + + + + +@TEMPC@ + + + +@UPSSTATSPATH upsstats.cgi@EXEEXT@@ +@UPSIMAGEPATH upsimage.cgi@EXEEXT@@ + + + + + + + + +@REFRESH@ +@HOSTDESC@ : @VAR ups.model@ + + + + + +
+
+
+

Network UPS Tools

+
@HOSTDESC@ - +@IFSUPP device.model@ +@VAR device.model@ +@ELSE@ +@VAR ups.model@ +@ENDIF@ +on @HOST@
+
+
@DATE %a %b %d %X %Z %Y@
+
+ +
+ + +
+
+
Battery
+
+@IFSUPP battery.charge@ +
+
+
+
Charge
+
+
@VAR battery.charge@ %
+
+
+
100
50
0
+
+
+@ENDIF@ + +@IFSUPP battery.voltage@ +
+
+
+
Voltage
+
+
@VAR battery.voltage@ V
+
+
+
MAX
NOM
MIN
+
+
+@ENDIF@ +
+
+ +
+
Line Voltage
+
+@IFSUPP input.L2-L3.voltage@ +
+
+ +
+
Input L1-L2
+
+
@VAR input.L1-L2.voltage@ V
+
+
+
MAX
NOM
MIN
+
+ +
+
Input L2-L3
+
+
@VAR input.L2-L3.voltage@ V
+
+
+
MAX
NOM
MIN
+
+ +
+
Input L3-L1
+
+
@VAR input.L3-L1.voltage@ V
+
+
+
MAX
NOM
MIN
+
+ +
+@ELSE@ +@IFSUPP input.L2-N.voltage@ + +
+
+ +
+
Input L1-N
+
+
@VAR input.L1-N.voltage@ V
+
+
+
MAX
NOM
MIN
+
+ +
+
Input L2-N
+
+
@VAR input.L2-N.voltage@ V
+
+
+
MAX
NOM
MIN
+
+ +
+
Input L3-N
+
+
@VAR input.L3-N.voltage@ V
+
+
+
MAX
NOM
MIN
+
+ +
+@ELSE@ +@IFSUPP input.voltage@ +
+
+
+
Input
+
+
@VAR input.voltage@ V
+
+
+
MAX
NOM
MIN
+
+
+@ENDIF@ +@IFSUPP output.L2-L3.voltage@ +
+
+ +
+
Output L1-L2
+
+
@VAR output.L1-L2.voltage@ V
+
+
+
MAX
NOM
MIN
+
+ +
+
Output L2-L3
+
+
@VAR output.L2-L3.voltage@ V
+
+
+
MAX
NOM
MIN
+
+ +
+
Output L3-L1
+
+
@VAR output.L3-L1.voltage@ V
+
+
+
MAX
NOM
MIN
+
+ +
+@ELSE@ +@IFSUPP output.L2-N.voltage@ +
+
+ +
+
Output L1-N
+
+
@VAR output.L1-N.voltage@ V
+
+
+
MAX
NOM
MIN
+
+ +
+
Output L2-N
+
+
@VAR output.L2-N.voltage@ V
+
+
+
MAX
NOM
MIN
+
+ +
+
Output L3-N
+
+
@VAR output.L3-N.voltage@ V
+
+
+
MAX
NOM
MIN
+
+ +
+@ELSE@ +@IFSUPP output.voltage@ +
+
+
+
Output
+
+
@VAR output.voltage@ V
+
+
+
MAX
NOM
MIN
+
+
+@ENDIF@ +
+
+ +
+
Load
+
+@IFSUPP output.L2.power.percent@ +
+ +
+
Load L1
+
+
@VAR output.L1.power.percent@ %
+
+
+
100
50
0
+
+ +
+
Load L2
+
+
@VAR output.L2.power.percent@ %
+
+
+
100
50
0
+
+ +
+
Load L3
+
+
@VAR output.L3.power.percent@ %
+
+
+
100
50
0
+
+ +
+@ELSE@ +@IFSUPP output.L2.realpower.percent@ +
+ +
+
Load L1
+
+
@VAR output.L1.realpower.percent@ %
+
+
+
100
50
0
+
+ +
+
Load L2
+
+
@VAR output.L2.realpower.percent@ %
+
+
+
100
50
0
+
+ +
+
Load L3
+
+
@VAR output.L3.realpower.percent@ %
+
+
+
100
50
0
+
+ +
+@ELSE@ +@IFSUPP ups.load@ +
+
+
+
@VAR ups.load@ %
+
+
+
100
50
0
+
+
+@ENDIF@ +
+
+ +@IFSUPP ambient.temperature@ +
+
Environment
+
+
+
+
Temp
+
+
@VAR ambient.temperature@ °
+
+
+
MAX
MIN
+
+
+
+
+@ENDIF@ +
+
+ +

+@TREELINK_JSON Device data as JSON@ | @TREELINK Device data as HTML table@ +Valid CSS +Valid HTML 4.01 Strict +

Network UPS Tools upsstats @ESCAPED_TEMPLATE_VERSION@

+
+ +
+ + + + + diff --git a/configure.ac b/configure.ac index da1730b8eb..f894b2b766 100644 --- a/configure.ac +++ b/configure.ac @@ -7069,6 +7069,8 @@ AC_CONFIG_FILES([ conf/upssched.conf.sample conf/upsstats.html.sample conf/upsstats-single.html.sample + conf/upsstats-modern-list.html.sample + conf/upsstats-modern-single.html.sample data/htmlcgi/header.html data/htmlcgi/Makefile data/Makefile diff --git a/data/htmlcgi/header.html.in b/data/htmlcgi/header.html.in index a1ab596bd0..496209c7b6 100644 --- a/data/htmlcgi/header.html.in +++ b/data/htmlcgi/header.html.in @@ -26,6 +26,17 @@ Network UPS Tools Statistics + + + Settings diff --git a/docs/man/upsstats.html.txt b/docs/man/upsstats.html.txt index e41aa4a948..fb02942a79 100644 --- a/docs/man/upsstats.html.txt +++ b/docs/man/upsstats.html.txt @@ -73,6 +73,9 @@ supported" messages by avoiding the label and variable call entirely. *@IFEQ* 'var' 'value'*@*:: Starts a block if the value returned from the variable 'var' matches 'value'. ++ +NOTE: You can use `@IFEQ upsstats.use_celsius (0|1)@` to check for the +current setting of *@TEMPC@* or *@TEMPF@* toggle. *@IFBETWEEN* 'varlow' 'varhigh' 'varvalue'*@*:: Starts a block if the value returned by the variable 'varvalue' is between diff --git a/docs/nut.dict b/docs/nut.dict index bd547c6438..6f295f2b46 100644 --- a/docs/nut.dict +++ b/docs/nut.dict @@ -1,4 +1,4 @@ -personal_ws-1.1 en 3660 utf-8 +personal_ws-1.1 en 3687 utf-8 AAC AAS ABI @@ -541,6 +541,7 @@ IDEN IDEs IDentifiers IFBETWEEN +IFEQ IFF IFSUPP IGN @@ -1222,6 +1223,7 @@ SRC SSD SSSS STARTTLS +STATUSCOLOR STB STDCALL STESTI @@ -1582,6 +1584,7 @@ addr addrange addvar addvars +ade adelsystem adkorte adm @@ -1719,6 +1722,7 @@ bcdDevice bcm bcmxcp bd +bdf belkin belkinunv bestfcom @@ -1792,6 +1796,7 @@ cdc cdf cee cef +celsius centos cerr certfile @@ -1890,6 +1895,7 @@ cpqpower cpsups cpu cr +createElement crestfactor crit criticality @@ -2063,6 +2069,8 @@ ef egrep ei el +elementWidth +els emacs emptor emptyDir @@ -2110,11 +2118,13 @@ extradata faa fabula facto +fafc failmode failover fallthrough fasttrack fatalx +fbbf fc fcb fcntl @@ -2141,6 +2151,7 @@ fmt fno fontconfig fopen +forEach forceshutdown forcessl formatconfig @@ -2221,6 +2232,8 @@ gpg gpgsign gpio gpiochip +graphmax +graphmin graphviz groupadd groupname @@ -2333,6 +2346,7 @@ inittime initups inline inlined +innerHTML innotech innovart innovatae @@ -2399,6 +2413,7 @@ jpeg jpg jq jre +js json kVA kadets @@ -2422,6 +2437,7 @@ ktrace kvm labcd lan +lang langid lasaine launchd @@ -2616,6 +2632,7 @@ middleware mincharge mingw minicol +minmax minruntime mins minva @@ -2688,6 +2705,7 @@ natively nb nbproject nbr +nbsp nc nd nde @@ -2755,6 +2773,7 @@ notransferoids novendor nowait nowarn +nowrap np nspr nss @@ -3042,6 +3061,7 @@ rex rexx rf rfc +rgba rh richcomm riello @@ -3320,6 +3340,7 @@ sysutils sysvinit tagname targetArchitecture +tbody tcflush tcgetattr tcl @@ -3345,6 +3366,7 @@ tgt tgtsize tgz th +thead timeframe timehead timername @@ -3365,6 +3387,8 @@ topFrame topbot tport transactional +translateX +translateY treemode tripplite tripplitesu @@ -3551,9 +3575,11 @@ verifySourceSig versa versioned versioning +vh victron victronups vid +viewport vin vio virsh @@ -3570,6 +3596,7 @@ vscode vsnprintf vsnprintfcat vt +vw wDescriptorLength waitbeforereconnect wakeup