@@ -26,7 +26,7 @@ typeId=""
2626colfile=" /opt/pihole/COL_TABLE"
2727source ${colfile}
2828
29- getListnameFromTypeId () {
29+ GetListnameFromTypeId () {
3030 if [[ " $1 " == " 0" ]]; then
3131 echo " whitelist"
3232 elif [[ " $1 " == " 1" ]]; then
@@ -38,43 +38,44 @@ getListnameFromTypeId() {
3838 fi
3939}
4040
41- helpFunc () {
41+ GetListParamFromTypeId () {
4242 if [[ " ${typeId} " == " 0" ]]; then
43- param=" w"
44- type=" whitelist"
45- elif [[ " ${typeId} " == " 3" && " ${wildcard} " == true ]]; then
46- param=" -wild"
47- type=" wildcard blacklist"
48- elif [[ " ${typeId} " == " 3" ]]; then
49- param=" -regex"
50- type=" regex blacklist filter"
51- elif [[ " ${typeId} " == " 2" && " ${wildcard} " == true ]]; then
52- param=" -white-wild"
53- type=" wildcard whitelist"
54- elif [[ " ${typeId} " == " 2" ]]; then
55- param=" -white-regex"
56- type=" regex whitelist filter"
57- else
58- param=" b"
59- type=" blacklist"
43+ echo " w"
44+ elif [[ " ${typeId} " == " 1" ]]; then
45+ echo " b"
46+ elif [[ " ${typeId} " == " 2" && " ${wildcard} " == true ]]; then
47+ echo " -white-wild"
48+ elif [[ " ${typeId} " == " 2" ]]; then
49+ echo " regex_blacklist"
50+ elif [[ " ${typeId} " == " 3" && " ${wildcard} " == true ]]; then
51+ echo " -regex"
52+ elif [[ " ${typeId} " == " 3" ]]; then
53+ echo " -wild"
6054 fi
55+ }
56+
57+ helpFunc () {
58+ local listname param
59+
60+ listname=" $( GetListnameFromTypeId " ${typeId} " ) "
61+ param=" $( GetListParamFromTypeId) "
6162
6263 echo " Usage: pihole -${param} [options] <domain> <domain2 ...>
6364Example: 'pihole -${param} site.com', or 'pihole -${param} site1.com site2.com'
64- ${type ^} one or more domains
65+ ${listname ^} one or more domains
6566
6667Options:
67- -d, --delmode Remove domain(s) from the ${type }
68- -nr, --noreload Update ${type } without reloading the DNS server
68+ -d, --delmode Remove domain(s) from the ${listname }
69+ -nr, --noreload Update ${listname } without reloading the DNS server
6970 -q, --quiet Make output less verbose
7071 -h, --help Show this help dialog
71- -l, --list Display all your ${type } listed domains
72+ -l, --list Display all your ${listname } listed domains
7273 --nuke Removes all entries in a list"
7374
7475 exit 0
7576}
7677
77- HandleOther () {
78+ ValidateDomain () {
7879 # Convert to lowercase
7980 domain=" ${1,,} "
8081
@@ -118,7 +119,7 @@ AddDomain() {
118119
119120 # Is the domain in the list we want to add it to?
120121 num=" $( sqlite3 " ${gravityDBfile} " " SELECT COUNT(*) FROM domainlist WHERE domain = '${domain} ';" ) "
121- requestedListname=" $( getListnameFromTypeId " ${typeId} " ) "
122+ requestedListname=" $( GetListnameFromTypeId " ${typeId} " ) "
122123
123124 if [[ " ${num} " -ne 0 ]]; then
124125 existingTypeId=" $( sqlite3 " ${gravityDBfile} " " SELECT type FROM domainlist WHERE domain = '${domain} ';" ) "
@@ -127,7 +128,7 @@ AddDomain() {
127128 echo -e " ${INFO} ${1} already exists in ${requestedListname} , no need to add!"
128129 fi
129130 else
130- existingListname=" $( getListnameFromTypeId " ${existingTypeId} " ) "
131+ existingListname=" $( GetListnameFromTypeId " ${existingTypeId} " ) "
131132 sqlite3 " ${gravityDBfile} " " UPDATE domainlist SET type = ${typeId} WHERE domain='${domain} ';"
132133 if [[ " ${verbose} " == true ]]; then
133134 echo -e " ${INFO} ${1} already exists in ${existingListname} , it has been moved to ${requestedListname} !"
@@ -153,7 +154,7 @@ RemoveDomain() {
153154 # Is the domain in the list we want to remove it from?
154155 num=" $( sqlite3 " ${gravityDBfile} " " SELECT COUNT(*) FROM domainlist WHERE domain = '${domain} ' AND type = ${typeId} ;" ) "
155156
156- requestedListname=" $( getListnameFromTypeId " ${typeId} " ) "
157+ requestedListname=" $( GetListnameFromTypeId " ${typeId} " ) "
157158
158159 if [[ " ${num} " -eq 0 ]]; then
159160 if [[ " ${verbose} " == true ]]; then
@@ -174,7 +175,7 @@ RemoveDomain() {
174175Displaylist () {
175176 local count num_pipes domain enabled status nicedate requestedListname
176177
177- requestedListname=" $( getListnameFromTypeId " ${typeId} " ) "
178+ requestedListname=" $( GetListnameFromTypeId " ${typeId} " ) "
178179 data=" $( sqlite3 " ${gravityDBfile} " " SELECT domain,enabled,date_modified FROM domainlist WHERE type = ${typeId} ;" 2> /dev/null) "
179180
180181 if [[ -z $data ]]; then
@@ -231,7 +232,7 @@ for var in "$@"; do
231232 " -l" | " --list" ) Displaylist;;
232233 " --nuke" ) NukeList;;
233234 " --web" ) web=true;;
234- * ) HandleOther " ${var} " ;;
235+ * ) ValidateDomain " ${var} " ;;
235236 esac
236237done
237238
0 commit comments