mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 14:58:08 +00:00
Make utils.sh posix compatible per request
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
parent
48138d32b6
commit
59fc3804be
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env sh
|
||||||
# Pi-hole: A black hole for Internet advertisements
|
# Pi-hole: A black hole for Internet advertisements
|
||||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||||
# Network-wide ad blocking via your own hardware.
|
# Network-wide ad blocking via your own hardware.
|
||||||
@ -39,7 +39,7 @@ addOrEditKeyValPair() {
|
|||||||
file="${3}"
|
file="${3}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${value}" != "" ]]; then
|
if [ "${value}" != "" ]; then
|
||||||
# value has a value, so it is a key pair
|
# value has a value, so it is a key pair
|
||||||
if grep -q "^${key}=" "${file}"; then
|
if grep -q "^${key}=" "${file}"; then
|
||||||
# Key already exists in file, modify the value
|
# Key already exists in file, modify the value
|
||||||
@ -74,23 +74,23 @@ removeKey() {
|
|||||||
# returns FTL's current telnet API port
|
# returns FTL's current telnet API port
|
||||||
#######################
|
#######################
|
||||||
getFTLAPIPort(){
|
getFTLAPIPort(){
|
||||||
local -r FTLCONFFILE="/etc/pihole/pihole-FTL.conf"
|
local FTLCONFFILE="/etc/pihole/pihole-FTL.conf"
|
||||||
local -r DEFAULT_PORT_FILE="/run/pihole-FTL.port"
|
local DEFAULT_PORT_FILE="/run/pihole-FTL.port"
|
||||||
local -r DEFAULT_FTL_PORT=4711
|
local DEFAULT_FTL_PORT=4711
|
||||||
local PORTFILE
|
local PORTFILE
|
||||||
local ftl_api_port
|
local ftl_api_port
|
||||||
|
|
||||||
if [[ -f "$FTLCONFFILE" ]]; then
|
if [ -f "$FTLCONFFILE" ]; then
|
||||||
# if PORTFILE is not set in pihole-FTL.conf, use the default path
|
# if PORTFILE is not set in pihole-FTL.conf, use the default path
|
||||||
PORTFILE="$( (grep "^PORTFILE=" $FTLCONFFILE || echo "$DEFAULT_PORT_FILE") | cut -d"=" -f2-)"
|
PORTFILE="$( (grep "^PORTFILE=" $FTLCONFFILE || echo "$DEFAULT_PORT_FILE") | cut -d"=" -f2-)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -s "$PORTFILE" ]]; then
|
if [ -s "$PORTFILE" ]; then
|
||||||
# -s: FILE exists and has a size greater than zero
|
# -s: FILE exists and has a size greater than zero
|
||||||
ftl_api_port=$(<"$PORTFILE")
|
ftl_api_port=$(cat "${PORTFILE}")
|
||||||
# Exploit prevention: unset the variable if there is malicious content
|
# Exploit prevention: unset the variable if there is malicious content
|
||||||
# Verify that the value read from the file is numeric
|
# Verify that the value read from the file is numeric
|
||||||
[[ "$ftl_api_port" =~ [^[:digit:]] ]] && unset ftl_api_port
|
expr "$ftl_api_port" : "[^[:digit:]]" > /dev/null && unset ftl_api_port
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# echo the port found in the portfile or default to the default port
|
# echo the port found in the portfile or default to the default port
|
||||||
|
Loading…
Reference in New Issue
Block a user