Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace superseded netstat command #1676

Merged
merged 2 commits into from Aug 31, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+36 −35
Diff settings

Always

Just for now

Copy path View file
71 pihole
@@ -1,4 +1,5 @@
#!/bin/bash

# Pi-hole: A black hole for Internet advertisements
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware.
@@ -8,11 +9,11 @@
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.

colfile="/opt/pihole/COL_TABLE"
source ${colfile}

readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf"
readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"

source ${colfile}

# Must be root to use this tool
if [[ ! $EUID -eq 0 ]];then
@@ -481,41 +482,41 @@ Options:
echo -e "${OVER} ${TICK} ${str}"
}

piholeStatus() {
if [[ "$(netstat -plnt | grep -c ':53 ')" -gt "0" ]]; then
if [[ "${1}" != "web" ]]; then
echo -e " ${TICK} DNS service is running"
fi
statusFunc() {
local addnConfigs

# Determine if service is running on port 53
if nc -z 127.0.0.1 53; then

This comment has been minimized.

Copy link
@dschaper

dschaper Aug 31, 2017

Member

if [[ nc -z 127.0.0.1 53 ]]; then

But I'm not sure if this is just goal post stuff, nc isn't stock on a lot of systems. Some have BSD netcat and some don't have anything installed at all. Will have to check a few systems to make sure this is available.

This comment has been minimized.

Copy link
@WaLLy3K

WaLLy3K Aug 31, 2017

Author Collaborator

I'll be happy to sort the style issue out once there's more word on this. It'll also mean this code will need to be changed.

[[ "${1}" != "web" ]] && echo -e " ${TICK} DNS service is running"

This comment has been minimized.

Copy link
@dschaper

dschaper Aug 31, 2017

Member

Just for style this would be better in an if [[ ]]; then; else in either a multi line statement or if you want to keep it oneliner then in that format.

else
if [[ "${1}" == "web" ]]; then
echo "-1";
else
echo -e " ${CROSS} DNS service is NOT running"
fi
return
case "${1}" in
"web") echo "-1";;
*) echo -e " ${CROSS} DNS service is NOT running";;
esac
return 0
fi

if [[ "$(grep -i "^#addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)" ]]; then
# List is commented out
if [[ "${1}" == "web" ]]; then
echo 0;
else
echo -e " ${CROSS} Pi-hole blocking is Disabled";
fi
elif [[ "$(grep -i "^addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)" ]]; then
# List set
if [[ "${1}" == "web" ]]; then
echo 1;
else
echo -e " ${TICK} Pi-hole blocking is Enabled";
fi
# Determine if any of Pi-hole's addn-hosts configs are commented out
addnConfigs=$(grep -i "addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)

if [[ "${addnConfigs}" =~ "#" ]]; then
# A config is commented out
case "${1}" in
"web") echo 0;;
*) echo -e " ${CROSS} Pi-hole blocking is Disabled";;
esac
elif [[ -n "${addnConfigs}" ]]; then
# Configs are set
case "${1}" in
"web") echo 1;;
*) echo -e " ${TICK} Pi-hole blocking is Enabled";;
esac
else
# Addn-host not found
if [[ "${1}" == "web" ]]; then
echo 99
else
echo -e " ${INFO} No hosts file linked to dnsmasq, adding it in enabled state"
fi
# No configs were found
case "${1}" in
"web") echo 99;;
*) echo -e " ${INFO} No hosts file linked to dnsmasq, adding it in enabled state";;
esac
# Add addn-host= to dnsmasq
echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf
restartDNS
@@ -651,7 +652,7 @@ case "${1}" in
"uninstall" ) uninstallFunc;;
"enable" ) piholeEnable 1;;
"disable" ) piholeEnable 0 "$2";;
"status" ) piholeStatus "$2";;
"status" ) statusFunc "$2";;
"restartdns" ) restartDNS;;
"-a" | "admin" ) webpageFunc "$@";;
"-t" | "tail" ) tailFunc;;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.