Skip to content

Commit

Permalink
treehouses blocker (fixes #657) (fixes #157) (#658)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <dogi@users.noreply.github.com>
  • Loading branch information
LordJashin32 and dogi authored Feb 13, 2020
1 parent 29304aa commit 4fcfd27
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 3 deletions.
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
engines:
shellcheck:
enabled: true
shell: bash
checks:
SC1090:
enabled: false
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ install:
- auto-changelog
- ls -al
- cat CHANGELOG.md
script:
- ./templates/blocker/blocker.sh
- ls -al ./templates/blocker/
deploy:
provider: npm
edge: true
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ cron [list|add|delete|deleteall] adds, deletes a custom cron job or del
usb [on|off] turns usb ports on or off
remote [status|upgrade|services] helps with treehouses remote android app
log <0|1|2|3|4|show|max> gets/sets log level and shows log
blocker <0|1|2|3|4||max> website blocking levels using /etc/hosts
```
8 changes: 6 additions & 2 deletions _treehouses
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ _treehouses_complete()
local cur prev

# Valid top-level completions
commands="ap aphidden apchannel bluetooth bluetoothid bootoption bridge burn button camera clone \
commands="ap aphidden apchannel blocker bluetooth bluetoothid bootoption bridge burn button camera clone \
container coralenv cron default detect detectrpi discover ethernet expandfs \
feedback help image internet led locale log memory networkmode ntp openvpn password \
rebootneeded reboots rename restore rtc services speedtest ssh sshkey sshtunnel \
staticwifi temperature timezone tor upgrade usb verbose version vnc wifi wificountry wifihidden wifistatus"
ap_cmdas="local internet"
aphidden_cmds="local internet"
apchannel_cmds="1 2 3 4 5 6 7 8 9 10 11"
blocker_cmds="0 1 2 3 4 max"
bluetooth_cmds="on off pause mac id"
bootoption_cmds="console desktop"
bootoption_second_cmds="autologin"
Expand All @@ -33,7 +34,7 @@ _treehouses_complete()
rtc_on_cmds="ds3231 rasclock"
services_cmds="available installed running ports"
cron_cmds="list 0W tor timestamp add delete deleteall"
sshkey_cmds="add list delete deleteal addgithubusername deletegithubusername addgithubgroup"
sshkey_cmds="add list delete deleteall addgithubusername deletegithubusername addgithubgroup"
ssh_cmds="on off"
sshtunnel_cmds="add remove list key notice"
temperature_cmds="celsius fahrenheit"
Expand Down Expand Up @@ -64,6 +65,9 @@ _treehouses_complete()
"apchannel")
COMPREPLY=( $(compgen -W "$apchannel_cmds" -- $cur) ) #cannot ascending order
;;
"blocker")
COMPREPLY=( $(compgen -W "$blocker_cmds" -- $cur) )
;;
"bluetooth")
COMPREPLY=( $(compgen -W "$bluetooth_cmds" -- $cur) )
;;
Expand Down
5 changes: 5 additions & 0 deletions cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ source "$SCRIPTFOLDER/modules/discover.sh"
source "$SCRIPTFOLDER/modules/camera.sh"
source "$SCRIPTFOLDER/modules/usb.sh"
source "$SCRIPTFOLDER/modules/remote.sh"
source "$SCRIPTFOLDER/modules/blocker.sh"

case $1 in
expandfs)
Expand Down Expand Up @@ -308,6 +309,10 @@ case $1 in
checkroot
log "$2" "$3"
;;
blocker)
checkroot
blocker "$2"
;;
help)
help "$2"
;;
Expand Down
119 changes: 119 additions & 0 deletions modules/blocker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
function apply_blocker {
local file_nh folder_nh hostn
if [ ! -f $TEMPLATES/blocker/1_hosts ]; then
($TEMPLATES/blocker/blocker.sh)
fi
folder_nh="$TEMPLATES/blocker"
case "$BLOCKER" in
"1")
file_nh=$(<$folder_nh/1_hosts)
;;
"2")
file_nh=$(<$folder_nh/2_hosts)
;;
"3")
file_nh=$(<$folder_nh/3_hosts)
;;
"4")
file_nh=$(<$folder_nh/4_hosts)
;;
"max")
file_nh=$(<$folder_nh/5_hosts)
;;
esac
hostn=$(hostname)
cp "$TEMPLATES/hosts" "$TEMPLATES/hosts1"
sed -i "s/HOSTNAME/$hostn/g" "$TEMPLATES/hosts1"
sync;sync;sync;
cp "$TEMPLATES/hosts1" /etc/hosts
rm -f "$TEMPLATES/hosts1"
if [ ! $BLOCKER = "0" ]; then
echo "$file_nh" >> /etc/hosts
fi
sync;sync;sync;
logit "$1"
}

function blocker {
case "$1" in
"")
case "$BLOCKER" in
"0")
logit "blocker 0: blocker is disabled"
;;
"1")
logit "blocker 1: level is set to ads (adware + malware)"
;;
"2")
logit "blocker 2: level is set to ads + porn"
;;
"3")
logit "blocker 3: level is set to ads + gambling + porn"
;;
"4")
logit "blocker 4: level is set to ads + fakenews + gambling + porn"
;;
"max")
logit "blocker X: level is set to ads + fakenews + gambling + porn + social"
;;
esac
exit 0;
;;
"0")
BLOCKER=0
apply_blocker "blocker 0: blocker disabled"
;;
"1")
BLOCKER=1
apply_blocker "blocker 1: level set to ads (adware + malware)"
;;
"2")
BLOCKER=2
apply_blocker "blocker 2: level set to ads + porn"
;;
"3")
BLOCKER=3
apply_blocker "blocker 3: level set to ads + gambling + porn"
;;
"4")
BLOCKER=4
apply_blocker "blocker 4: level set to ads + fakenews + gambling + porn"
;;
"max")
BLOCKER=max
apply_blocker "blocker X: level set to ads + fakenews + gambling + porn + social"
;;
*)
log_and_exit1 "Error: only '0' '1' '2' '3' '4' 'max' options are supported"
;;
esac
conf_var_update "BLOCKER" "$BLOCKER"
}

function blocker_help {
echo
echo "Usage: $BASENAME blocker <0|1|2|3|4|max>"
echo
echo "Example:"
echo " $BASENAME blocker"
echo " blocker 0: blocker is disabled"
echo
echo " $BASENAME blocker 0"
echo " blocker 0: blocker disabled"
echo
echo " $BASENAME blocker 1"
echo " blocker 1: level set to ads (adware + malware)"
echo
echo " $BASENAME blocker 2"
echo " blocker 2: level set to ads + porn"
echo
echo " $BASENAME blocker 3"
echo " blocker 3: level set to ads + gambling + porn"
echo
echo " $BASENAME blocker 4"
echo " blocker 4: level set to ads + fakenews + gambling + porn"
echo
echo " $BASENAME blocker max"
echo " blocker X: level set to ads + fakenews + gambling + porn + social"
echo
}
1 change: 1 addition & 0 deletions modules/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ NC='\033[0m'
# global config variables (defaults)
LOGFILE=/dev/null
LOG=0
BLOCKER=0

if [[ -f "$CONFIGFILE" ]]; then
source "$CONFIGFILE"
Expand Down
1 change: 1 addition & 0 deletions modules/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function help_default {
echo " usb [on|off] turns usb ports on or off"
echo " remote [status|upgrade|services] helps with treehouses remote android app"
echo " log <0|1|2|3|4|show|max> gets/sets log level and shows log"
echo " blocker <0|1|2|3|4||max> website blocking levels using /etc/hosts"
echo
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@treehouses/cli",
"version": "1.13.15",
"version": "1.13.16",
"description": "Thin command-line interface for Raspberry Pi low level configuration.",
"main": "cli.sh",
"bin": {
Expand Down
11 changes: 11 additions & 0 deletions templates/blocker/blocker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# this file needs to be excuted on the base of the repo with `./templates/blocker/blocker.sh`

# Credits: https://github.com/StevenBlack/hosts
# The MIT License (MIT) Copyright © 2020 Steven Black
# https://github.com/StevenBlack/hosts/blob/master/license.txt
wget -q -O ./templates/blocker/1_hosts https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
wget -q -O ./templates/blocker/2_hosts https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts
wget -q -O ./templates/blocker/3_hosts https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-porn/hosts
wget -q -O ./templates/blocker/4_hosts https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn/hosts
wget -q -O ./templates/blocker/5_hosts https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts

0 comments on commit 4fcfd27

Please sign in to comment.