mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-04-24 08:10:14 +00:00
Remove ${SUDO} usages and root checks from scripts called by pihole
command as they should not be called directly.
This commit is contained in:
parent
461de48625
commit
090fbd04af
5 changed files with 51 additions and 95 deletions
|
@ -10,22 +10,8 @@
|
|||
# the Free Software Foundation, either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
#rootcheck
|
||||
if [[ $EUID -eq 0 ]];then
|
||||
echo "::: You are root."
|
||||
else
|
||||
echo "::: sudo will be used."
|
||||
# Check if it is actually installed
|
||||
# If it isn't, exit because the install cannot complete
|
||||
if [ -x "$(command -v sudo)" ];then
|
||||
export SUDO="sudo"
|
||||
else
|
||||
echo "::: Please install sudo or run this script as root."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
function helpFunc()
|
||||
helpFunc()
|
||||
{
|
||||
echo "::: Immediately whitelists one or more domains in the hosts file"
|
||||
echo ":::"
|
||||
|
@ -85,7 +71,7 @@ if [[ -f ${piholeIPv6file} ]];then
|
|||
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
|
||||
fi
|
||||
|
||||
function HandleOther(){
|
||||
HandleOther(){
|
||||
#check validity of domain
|
||||
validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/')
|
||||
if [ -z "$validDomain" ]; then
|
||||
|
@ -95,7 +81,7 @@ function HandleOther(){
|
|||
fi
|
||||
}
|
||||
|
||||
function PopWhitelistFile(){
|
||||
PopWhitelistFile(){
|
||||
#check whitelist file exists, and if not, create it
|
||||
if [[ ! -f ${whitelist} ]];then
|
||||
touch ${whitelist}
|
||||
|
@ -110,7 +96,7 @@ function PopWhitelistFile(){
|
|||
done
|
||||
}
|
||||
|
||||
function AddDomain(){
|
||||
AddDomain(){
|
||||
#| sed 's/\./\\./g'
|
||||
bool=false
|
||||
|
||||
|
@ -132,7 +118,7 @@ function AddDomain(){
|
|||
fi
|
||||
}
|
||||
|
||||
function RemoveDomain(){
|
||||
RemoveDomain(){
|
||||
|
||||
bool=false
|
||||
grep -Ex -q "$1" ${whitelist} || bool=true
|
||||
|
@ -151,7 +137,7 @@ function RemoveDomain(){
|
|||
fi
|
||||
}
|
||||
|
||||
function ModifyHostFile(){
|
||||
ModifyHostFile(){
|
||||
if ${addmode}; then
|
||||
#remove domains in from hosts file
|
||||
if [[ -r ${whitelist} ]];then
|
||||
|
@ -195,7 +181,7 @@ function ModifyHostFile(){
|
|||
fi
|
||||
}
|
||||
|
||||
function Reload() {
|
||||
Reload() {
|
||||
# Reload hosts file
|
||||
echo ":::"
|
||||
echo -n "::: Refresh lists in dnsmasq..."
|
||||
|
@ -203,15 +189,15 @@ function Reload() {
|
|||
|
||||
if [[ ${dnsmasqPid} ]]; then
|
||||
# service already running - reload config
|
||||
${SUDO} killall -s HUP dnsmasq
|
||||
killall -s HUP dnsmasq
|
||||
else
|
||||
# service not running, start it up
|
||||
${SUDO} service dnsmasq start
|
||||
service dnsmasq start
|
||||
fi
|
||||
echo " done!"
|
||||
}
|
||||
|
||||
function DisplayWlist() {
|
||||
DisplayWlist() {
|
||||
verbose=false
|
||||
echo -e " Displaying Gravity Resistant Domains \n"
|
||||
count=1
|
||||
|
@ -251,4 +237,4 @@ fi
|
|||
|
||||
if ${reload}; then
|
||||
Reload
|
||||
fi
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue