Browse Source

nut: Use quotes around filenames

Avoid potential issues with space or other strangeness by
quoting filenames through the initscripts.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
lilik-openwrt-22.03
Daniel F. Dickinson 6 years ago
parent
commit
461393810d
3 changed files with 51 additions and 52 deletions
  1. +1
    -1
      net/nut/files/nut-cgi.init
  2. +36
    -36
      net/nut/files/nut-monitor.init
  3. +14
    -15
      net/nut/files/nut-server.init

+ 1
- 1
net/nut/files/nut-cgi.init View File

@ -40,7 +40,7 @@ nut_upscgi_add() {
system="$system:$port"; system="$system:$port";
fi fi
config_get displayname "$cfg" displayname config_get displayname "$cfg" displayname
echo "MONITOR $system \"$displayname\"" >> $UPSCGI_C
echo "MONITOR $system \"$displayname\"" >> "$UPSCGI_C"
} }
service_reload() { service_reload() {


+ 36
- 36
net/nut/files/nut-monitor.init View File

@ -8,55 +8,55 @@ nut_upsmon_conf() {
local cfg="$1" local cfg="$1"
local RUNAS val optval local RUNAS val optval
echo "# Config file automatically generated from UCI config" > $UPSMON_C
echo "# Config file automatically generated from UCI config" > "$UPSMON_C"
config_get RUNAS "$cfg" runas "nutmon" config_get RUNAS "$cfg" runas "nutmon"
[ -n "$RUNAS" ] && echo "RUN_AS_USER $RUNAS" >> "$UPSMON_C" [ -n "$RUNAS" ] && echo "RUN_AS_USER $RUNAS" >> "$UPSMON_C"
runas=$RUNAS runas=$RUNAS
config_get val "$cfg" minsupplies 1 config_get val "$cfg" minsupplies 1
echo "MINSUPPLIES $val" >> $UPSMON_C
echo "MINSUPPLIES $val" >> "$UPSMON_C"
config_get val "$cfg" shutdowncmd "/usr/sbin/nutshutdown" config_get val "$cfg" shutdowncmd "/usr/sbin/nutshutdown"
echo "SHUTDOWNCMD \"$val\"" >> $UPSMON_C
echo "SHUTDOWNCMD \"$val\"" >> "$UPSMON_C"
config_get val "$cfg" notifycmd config_get val "$cfg" notifycmd
[ -n "$val" ] && echo "NOTIFYCMD \"$val\"" >> $UPSMON_C
[ -n "$val" ] && echo "NOTIFYCMD \"$val\"" >> "$UPSMON_C"
config_get val "$cfg" pollfreq 5 config_get val "$cfg" pollfreq 5
echo "POLLFREQ $val" >> $UPSMON_C
echo "POLLFREQ $val" >> "$UPSMON_C"
config_get val "$cfg" pollfreqalert 5 config_get val "$cfg" pollfreqalert 5
echo "POLLFREQALERT $val" >> $UPSMON_C
echo "POLLFREQALERT $val" >> "$UPSMON_C"
config_get val "$cfg" hostsync 15 config_get val "$cfg" hostsync 15
echo "HOSTSYNC $val" >> $UPSMON_C
echo "HOSTSYNC $val" >> "$UPSMON_C"
config_get val "$cfg" deadtime 15 config_get val "$cfg" deadtime 15
echo "DEADTIME $val" >> $UPSMON_C
echo "DEADTIME $val" >> "$UPSMON_C"
echo "POWERDOWNFLAG /var/run/killpower" >> $UPSMON_C
echo "POWERDOWNFLAG /var/run/killpower" >> "$UPSMON_C"
config_get val "$cfg" onlinemsg config_get val "$cfg" onlinemsg
[ -n "$val" ] && echo "NOTIFYMSG ONLINE \"$val\"" >> $UPSMON_C
[ -n "$val" ] && echo "NOTIFYMSG ONLINE \"$val\"" >> "$UPSMON_C"
config_get val "$cfg" onbattmsg config_get val "$cfg" onbattmsg
[ -n "$val" ] && echo "NOTIFYMSG ONBATT \"$val\"" >> $UPSMON_C
[ -n "$val" ] && echo "NOTIFYMSG ONBATT \"$val\"" >> "$UPSMON_C"
config_get val "$cfg" lowbattmsg config_get val "$cfg" lowbattmsg
[ -n "$val" ] && echo "NOTIFYMSG LOWBATT \"$val\"" >> $UPSMON_C
[ -n "$val" ] && echo "NOTIFYMSG LOWBATT \"$val\"" >> "$UPSMON_C"
config_get val "$cfg" fsdmsg config_get val "$cfg" fsdmsg
[ -n "$val" ] && echo "NOTIFYMSG FSD \"$val\"" >> $UPSMON_C
[ -n "$val" ] && echo "NOTIFYMSG FSD \"$val\"" >> "$UPSMON_C"
config_get val "$cfg" commokmsg config_get val "$cfg" commokmsg
[ -n "$val" ] && echo "NOTIFYMSG COMMOK \"$val\"" >> $UPSMON_C
[ -n "$val" ] && echo "NOTIFYMSG COMMOK \"$val\"" >> "$UPSMON_C"
config_get val "$cfg" commbadmsg config_get val "$cfg" commbadmsg
[ -n "$val" ] && echo "NOTIFYMSG COMMBAD \"$val\"" >> $UPSMON_C
[ -n "$val" ] && echo "NOTIFYMSG COMMBAD \"$val\"" >> "$UPSMON_C"
config_get val "$cfg" shutdownmsg config_get val "$cfg" shutdownmsg
[ -n "$val" ] && echo "NOTIFYMSG SHUTDOWN \"$val\"" >> $UPSMON_C
[ -n "$val" ] && echo "NOTIFYMSG SHUTDOWN \"$val\"" >> "$UPSMON_C"
config_get val "$cfg" replbattmsg config_get val "$cfg" replbattmsg
[ -n "$val" ] && echo "NOTIFYMSG REPLBATT \"$val\"" >> $UPSMON_C
[ -n "$val" ] && echo "NOTIFYMSG REPLBATT \"$val\"" >> "$UPSMON_C"
config_get val "$cfg" nocommmsg config_get val "$cfg" nocommmsg
[ -n "$val" ] && echo "NOTIFYMSG NOCOMM \"$val\"" >> $UPSMON_C
[ -n "$val" ] && echo "NOTIFYMSG NOCOMM \"$val\"" >> "$UPSMON_C"
config_get val "$cfg" noparentmsg config_get val "$cfg" noparentmsg
[ -n "$val" ] && echo "NOTIFYMSG NOPARENT \"$val\"" >> $UPSMON_C
[ -n "$val" ] && echo "NOTIFYMSG NOPARENT \"$val\"" >> "$UPSMON_C"
notifylist() { notifylist() {
local value="$1" local value="$1"
@ -86,34 +86,34 @@ nut_upsmon_conf() {
val="" val=""
config_list_foreach "$cfg" defaultnotify notifylist config_list_foreach "$cfg" defaultnotify notifylist
default="$optval" default="$optval"
echo "NOTIFYFLAG ONLINE $(setnotify "$cfg" onlinenotify)" >> $UPSMON_C
echo "NOTIFYFLAG ONBATT $(setnotify "$cfg" onbattnotify)" >> $UPSMON_C
echo "NOTIFYFLAG LOWBATT $(setnotify "$cfg" lowbatnotify)" >> $UPSMON_C
echo "NOTIFYFLAG FSD $(setnotify "$cfg" fsdnotify)" >> $UPSMON_C
echo "NOTIFYFLAG COMMOK $(setnotify "$cfg" commoknotify)" >> $UPSMON_C
echo "NOTIFYFLAG COMMBAD $(setnotify "$cfg" commbadnotify)" >> $UPSMON_C
echo "NOTIFYFLAG SHUTDOWN $(setnotify "$cfg" shutdownnotify)" >> $UPSMON_C
echo "NOTIFYFLAG REPLBATT $(setnotify "$cfg" repolbattnotify)" >> $UPSMON_C
echo "NOTIFYFLAG NOCOMM $(setnotify "$cfg" nocommnotify)" >> $UPSMON_C
echo "NOTIFYFLAG NOPARENT $(setnotify "$cfg" noparentnotify)" >> $UPSMON_C
echo "NOTIFYFLAG ONLINE $(setnotify "$cfg" onlinenotify)" >> "$UPSMON_C"
echo "NOTIFYFLAG ONBATT $(setnotify "$cfg" onbattnotify)" >> "$UPSMON_C"
echo "NOTIFYFLAG LOWBATT $(setnotify "$cfg" lowbatnotify)" >> "$UPSMON_C"
echo "NOTIFYFLAG FSD $(setnotify "$cfg" fsdnotify)" >> "$UPSMON_C"
echo "NOTIFYFLAG COMMOK $(setnotify "$cfg" commoknotify)" >> "$UPSMON_C"
echo "NOTIFYFLAG COMMBAD $(setnotify "$cfg" commbadnotify)" >> "$UPSMON_C"
echo "NOTIFYFLAG SHUTDOWN $(setnotify "$cfg" shutdownnotify)" >> "$UPSMON_C"
echo "NOTIFYFLAG REPLBATT $(setnotify "$cfg" repolbattnotify)" >> "$UPSMON_C"
echo "NOTIFYFLAG NOCOMM $(setnotify "$cfg" nocommnotify)" >> "$UPSMON_C"
echo "NOTIFYFLAG NOPARENT $(setnotify "$cfg" noparentnotify)" >> "$UPSMON_C"
config_get val "$cfg" rbwarntime 43200 config_get val "$cfg" rbwarntime 43200
echo "RBWARNTIME $val" >> $UPSMON_C
echo "RBWARNTIME $val" >> "$UPSMON_C"
config_get val "$cfg" nocommwarntime 300 config_get val "$cfg" nocommwarntime 300
echo "NOCOMMWARNTIME $val" >> $UPSMON_C
echo "NOCOMMWARNTIME $val" >> "$UPSMON_C"
config_get val "$cfg" finaldelay 5 config_get val "$cfg" finaldelay 5
echo "FINALDELAY $val" >> $UPSMON_C
echo "FINALDELAY $val" >> "$UPSMON_C"
config_get val "$cfg" certpath config_get val "$cfg" certpath
if [ -n "$val" ]; then echo "CERTPATH $val" >> $UPSMON_C; fi
if [ -n "$val" ]; then echo "CERTPATH $val" >> "$UPSMON_C"; fi
config_get_bool val "$cfg" certverify 0 config_get_bool val "$cfg" certverify 0
if [ -n "$val" ]; then echo "CERTVERIFY $val" >> $UPSMON_C; fi
if [ -n "$val" ]; then echo "CERTVERIFY $val" >> "$UPSMON_C"; fi
config_get_bool val "$cfg" forcessl 0 config_get_bool val "$cfg" forcessl 0
if [ -n "$val" ]; then echo "FORCESSL $val" >> $UPSMON_C; fi
if [ -n "$val" ]; then echo "FORCESSL $val" >> "$UPSMON_C"; fi
} }
nut_upsmon_add() { nut_upsmon_add() {
@ -137,7 +137,7 @@ nut_upsmon_add() {
if [ -n "$port" ]; then if [ -n "$port" ]; then
system="$system:$port"; system="$system:$port";
fi fi
echo "MONITOR $system $powervalue $username $password $type" >> $UPSMON_C
echo "MONITOR $system $powervalue $username $password $type" >> "$UPSMON_C"
} }
build_config() { build_config() {


+ 14
- 15
net/nut/files/nut-server.init View File

@ -43,7 +43,7 @@ listen_address() {
config_get address "$cfg" address "::1" config_get address "$cfg" address "::1"
config_get port "$cfg" port config_get port "$cfg" port
echo "LISTEN $address $port" >>$UPSD_C
echo "LISTEN $address $port" >>"$UPSD_C"
} }
upsd_config() { upsd_config() {
@ -59,17 +59,17 @@ upsd_config() {
STATEPATH="$statepath" STATEPATH="$statepath"
config_get maxage "$cfg" maxage config_get maxage "$cfg" maxage
[ -n "$maxage" ] && echo "MAXAGE $maxage" >>$UPSD_C
[ -n "$maxage" ] && echo "MAXAGE $maxage" >>"$UPSD_C"
config_get statepath "$cfg" statepath config_get statepath "$cfg" statepath
[ -n "$statepath" ] && echo "STATEPATH $statepath" >>$UPSD_C
[ -n "$statepath" ] && echo "STATEPATH $statepath" >>"$UPSD_C"
config_get maxconn "$cfg" maxconn config_get maxconn "$cfg" maxconn
[ -n "$maxconn" ] && echo "MAXCONN $maxconn" >>$UPSD_C
[ -n "$maxconn" ] && echo "MAXCONN $maxconn" >>"$UPSD_C"
#NOTE: certs only apply to SSL-enabled version #NOTE: certs only apply to SSL-enabled version
config_get certfile "$cfg" certfile config_get certfile "$cfg" certfile
[ -n "$certfile" ] && echo "CERTFILE $certfile" >>$UPSD_C
[ -n "$certfile" ] && echo "CERTFILE $certfile" >>"$UPSD_C"
} }
nut_user_add() { nut_user_add() {
@ -78,26 +78,26 @@ nut_user_add() {
local val local val
config_get val "$cfg" username "$1" config_get val "$cfg" username "$1"
echo "[$val]" >> $USERS_C
echo "[$val]" >> "$USERS_C"
config_get val "$cfg" password config_get val "$cfg" password
echo " password = $val" >> $USERS_C
echo " password = $val" >> "$USERS_C"
config_get val "$cfg" actions config_get val "$cfg" actions
for a in $val; do for a in $val; do
echo " actions = $a" >> $USERS_C
echo " actions = $a" >> "$USERS_C"
done done
instcmd() { instcmd() {
local val="$1" local val="$1"
echo " instcmds = $val" >> $USERS_C
echo " instcmds = $val" >> "$USERS_C"
} }
config_list_foreach "$cfg" instcmd instcmd config_list_foreach "$cfg" instcmd instcmd
config_get val "$cfg" upsmon config_get val "$cfg" upsmon
if [ -n "$val" ]; then if [ -n "$val" ]; then
echo " upsmon $val" >> $USERS_C
echo " upsmon $val" >> "$USERS_C"
fi fi
} }
@ -107,17 +107,16 @@ build_server_config() {
rm -f "$UPSD_C" rm -f "$UPSD_C"
rm -f /var/etc/nut/nut.conf rm -f /var/etc/nut/nut.conf
echo "# Config file automatically generated from UCI config" > $USERS_C
echo "# Config file automatically generated from UCI config" > $UPSD_C
echo "# Config file automatically generated from UCI config" > "$USERS_C"
echo "# Config file automatically generated from UCI config" > "$UPSD_C"
config_foreach nut_user_add user config_foreach nut_user_add user
config_foreach listen_address listen_address config_foreach listen_address listen_address
config_foreach upsd_config upsd config_foreach upsd_config upsd
echo "MODE=netserver" >>/var/etc/nut/nut.conf echo "MODE=netserver" >>/var/etc/nut/nut.conf
chmod 0640 $USERS_C
chmod 0640 $UPS_C
chmod 0640 $UPSD_C
chmod 0640 "$USERS_C"
chmod 0640 "$UPSD_C"
chmod 0640 /var/etc/nut/nut.conf chmod 0640 /var/etc/nut/nut.conf
[ -d "${STATEPATH}" ] || { [ -d "${STATEPATH}" ] || {


Loading…
Cancel
Save