functionise parameter discovery
Rename HandleOther to ValidateDomain Capital letters on the new functions Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
parent
edaee4e962
commit
4b8a72fda7
|
@ -26,7 +26,7 @@ typeId=""
|
||||||
colfile="/opt/pihole/COL_TABLE"
|
colfile="/opt/pihole/COL_TABLE"
|
||||||
source ${colfile}
|
source ${colfile}
|
||||||
|
|
||||||
getListnameFromTypeId() {
|
GetListnameFromTypeId() {
|
||||||
if [[ "$1" == "0" ]]; then
|
if [[ "$1" == "0" ]]; then
|
||||||
echo "whitelist"
|
echo "whitelist"
|
||||||
elif [[ "$1" == "1" ]]; then
|
elif [[ "$1" == "1" ]]; then
|
||||||
|
@ -38,43 +38,44 @@ getListnameFromTypeId() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
helpFunc() {
|
GetListParamFromTypeId() {
|
||||||
if [[ "${typeId}" == "0" ]]; then
|
if [[ "${typeId}" == "0" ]]; then
|
||||||
param="w"
|
echo "w"
|
||||||
type="whitelist"
|
elif [[ "${typeId}" == "1" ]]; then
|
||||||
elif [[ "${typeId}" == "3" && "${wildcard}" == true ]]; then
|
echo "b"
|
||||||
param="-wild"
|
elif [[ "${typeId}" == "2" && "${wildcard}" == true ]]; then
|
||||||
type="wildcard blacklist"
|
echo "-white-wild"
|
||||||
elif [[ "${typeId}" == "3" ]]; then
|
elif [[ "${typeId}" == "2" ]]; then
|
||||||
param="-regex"
|
echo "regex_blacklist"
|
||||||
type="regex blacklist filter"
|
elif [[ "${typeId}" == "3" && "${wildcard}" == true ]]; then
|
||||||
elif [[ "${typeId}" == "2" && "${wildcard}" == true ]]; then
|
echo "-regex"
|
||||||
param="-white-wild"
|
elif [[ "${typeId}" == "3" ]]; then
|
||||||
type="wildcard whitelist"
|
echo "-wild"
|
||||||
elif [[ "${typeId}" == "2" ]]; then
|
|
||||||
param="-white-regex"
|
|
||||||
type="regex whitelist filter"
|
|
||||||
else
|
|
||||||
param="b"
|
|
||||||
type="blacklist"
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
helpFunc() {
|
||||||
|
local listname param
|
||||||
|
|
||||||
|
listname="$(GetListnameFromTypeId "${typeId}")"
|
||||||
|
param="$(GetListParamFromTypeId)"
|
||||||
|
|
||||||
echo "Usage: pihole -${param} [options] <domain> <domain2 ...>
|
echo "Usage: pihole -${param} [options] <domain> <domain2 ...>
|
||||||
Example: 'pihole -${param} site.com', or 'pihole -${param} site1.com site2.com'
|
Example: 'pihole -${param} site.com', or 'pihole -${param} site1.com site2.com'
|
||||||
${type^} one or more domains
|
${listname^} one or more domains
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-d, --delmode Remove domain(s) from the ${type}
|
-d, --delmode Remove domain(s) from the ${listname}
|
||||||
-nr, --noreload Update ${type} without reloading the DNS server
|
-nr, --noreload Update ${listname} without reloading the DNS server
|
||||||
-q, --quiet Make output less verbose
|
-q, --quiet Make output less verbose
|
||||||
-h, --help Show this help dialog
|
-h, --help Show this help dialog
|
||||||
-l, --list Display all your ${type}listed domains
|
-l, --list Display all your ${listname}listed domains
|
||||||
--nuke Removes all entries in a list"
|
--nuke Removes all entries in a list"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleOther() {
|
ValidateDomain() {
|
||||||
# Convert to lowercase
|
# Convert to lowercase
|
||||||
domain="${1,,}"
|
domain="${1,,}"
|
||||||
|
|
||||||
|
@ -118,7 +119,7 @@ AddDomain() {
|
||||||
|
|
||||||
# Is the domain in the list we want to add it to?
|
# Is the domain in the list we want to add it to?
|
||||||
num="$(sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}';")"
|
num="$(sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}';")"
|
||||||
requestedListname="$(getListnameFromTypeId "${typeId}")"
|
requestedListname="$(GetListnameFromTypeId "${typeId}")"
|
||||||
|
|
||||||
if [[ "${num}" -ne 0 ]]; then
|
if [[ "${num}" -ne 0 ]]; then
|
||||||
existingTypeId="$(sqlite3 "${gravityDBfile}" "SELECT type FROM domainlist WHERE domain = '${domain}';")"
|
existingTypeId="$(sqlite3 "${gravityDBfile}" "SELECT type FROM domainlist WHERE domain = '${domain}';")"
|
||||||
|
@ -127,7 +128,7 @@ AddDomain() {
|
||||||
echo -e " ${INFO} ${1} already exists in ${requestedListname}, no need to add!"
|
echo -e " ${INFO} ${1} already exists in ${requestedListname}, no need to add!"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
existingListname="$(getListnameFromTypeId "${existingTypeId}")"
|
existingListname="$(GetListnameFromTypeId "${existingTypeId}")"
|
||||||
sqlite3 "${gravityDBfile}" "UPDATE domainlist SET type = ${typeId} WHERE domain='${domain}';"
|
sqlite3 "${gravityDBfile}" "UPDATE domainlist SET type = ${typeId} WHERE domain='${domain}';"
|
||||||
if [[ "${verbose}" == true ]]; then
|
if [[ "${verbose}" == true ]]; then
|
||||||
echo -e " ${INFO} ${1} already exists in ${existingListname}, it has been moved to ${requestedListname}!"
|
echo -e " ${INFO} ${1} already exists in ${existingListname}, it has been moved to ${requestedListname}!"
|
||||||
|
@ -153,7 +154,7 @@ RemoveDomain() {
|
||||||
# Is the domain in the list we want to remove it from?
|
# Is the domain in the list we want to remove it from?
|
||||||
num="$(sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}' AND type = ${typeId};")"
|
num="$(sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}' AND type = ${typeId};")"
|
||||||
|
|
||||||
requestedListname="$(getListnameFromTypeId "${typeId}")"
|
requestedListname="$(GetListnameFromTypeId "${typeId}")"
|
||||||
|
|
||||||
if [[ "${num}" -eq 0 ]]; then
|
if [[ "${num}" -eq 0 ]]; then
|
||||||
if [[ "${verbose}" == true ]]; then
|
if [[ "${verbose}" == true ]]; then
|
||||||
|
@ -174,7 +175,7 @@ RemoveDomain() {
|
||||||
Displaylist() {
|
Displaylist() {
|
||||||
local count num_pipes domain enabled status nicedate requestedListname
|
local count num_pipes domain enabled status nicedate requestedListname
|
||||||
|
|
||||||
requestedListname="$(getListnameFromTypeId "${typeId}")"
|
requestedListname="$(GetListnameFromTypeId "${typeId}")"
|
||||||
data="$(sqlite3 "${gravityDBfile}" "SELECT domain,enabled,date_modified FROM domainlist WHERE type = ${typeId};" 2> /dev/null)"
|
data="$(sqlite3 "${gravityDBfile}" "SELECT domain,enabled,date_modified FROM domainlist WHERE type = ${typeId};" 2> /dev/null)"
|
||||||
|
|
||||||
if [[ -z $data ]]; then
|
if [[ -z $data ]]; then
|
||||||
|
@ -231,7 +232,7 @@ for var in "$@"; do
|
||||||
"-l" | "--list" ) Displaylist;;
|
"-l" | "--list" ) Displaylist;;
|
||||||
"--nuke" ) NukeList;;
|
"--nuke" ) NukeList;;
|
||||||
"--web" ) web=true;;
|
"--web" ) web=true;;
|
||||||
* ) HandleOther "${var}";;
|
* ) ValidateDomain "${var}";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue