Changed project to rhosts
rhosts is the new c implementation of the project. It is suppose to be compilable for GNU/Linux and Windows minimum.stable
parent
24e04c58dd
commit
4996513636
55
Makefile
55
Makefile
|
|
@ -1,29 +1,42 @@
|
|||
dir:
|
||||
if [ ! -d /usr/local/share/removeadhosts ];then mkdir -p /usr/local/share/removeadhosts;fi
|
||||
if [ ! -d /etc/removeadhosts ];then mkdir /etc/removeadhosts;fi
|
||||
install: dir
|
||||
touch /etc/removeadhosts/{adlist.txt,adlistings.txt
|
||||
cp src/* /usr/local/share/removeadhosts/
|
||||
chown -R root:root /usr/local/share/removeadhosts
|
||||
chmod +x /usr/local/share/removeadhosts/removeadhosts.sh
|
||||
ln -s /usr/local/share/removeadhosts/removeadhosts.service /etc/systemd/system/
|
||||
ln -s /usr/local/share/removeadhosts/removeadhosts.timer /etc/systemd/system/
|
||||
ln -s /usr/local/share/removeadhosts/removeadhosts.path /etc/systemd/system/
|
||||
if [ ! -d /usr/local/share/rhosts ];then mkdir -p /usr/local/share/rhosts;else echo "/usr/local/share/rhosts already exists";fi
|
||||
if [ ! -d /etc/rhosts ];then mkdir /etc/rhosts;else echo "/etc/rhosts already exists";fi
|
||||
if [ ! -d build ];then mkdir build;else echo "build already exists";fi
|
||||
build: dir
|
||||
gcc src/rhosts.c -o build/rhosts
|
||||
clean:
|
||||
- rm -rf build
|
||||
install: build
|
||||
if [ ! -e /etc/rhosts/rhosts.cfg ];then touch /etc/rhosts/rhosts.cfg;else echo "/etc/rhosts/rhosts.cfg exists";fi
|
||||
cp -r src/systemd /usr/local/share/rhosts/
|
||||
cp build/rhosts /usr/local/bin/
|
||||
chown -R root:root /usr/local/bin/rhosts
|
||||
chmod +x /usr/local/bin/rhosts
|
||||
if [ ! -e /etc/systemd/system/rhosts.service ];then \
|
||||
ln -s /usr/local/share/rhosts/systemd/rhosts.service /etc/systemd/system/;else \
|
||||
echo "/etc/systemd/system/rhosts.service already exist";fi
|
||||
if [ ! -e /etc/systemd/system/rhosts.timer ];then \
|
||||
ln -s /usr/local/share/rhosts/systemd/rhosts.timer /etc/systemd/system/;else \
|
||||
echo "/etc/systemd/system/rhosts.timer already exist";fi
|
||||
if [ ! -e /etc/systemd/system/rhosts.path ];then \
|
||||
ln -s /usr/local/share/rhosts/systemd/rhosts.path /etc/systemd/system/;else \
|
||||
echo "/etc/systemd/system/rhosts.path already exist";fi
|
||||
systemctl daemon-reload
|
||||
activate: install
|
||||
systemctl enable removeadhosts.timer
|
||||
systemctl start removeadhosts.timer
|
||||
systemctl enable removeadhosts.path
|
||||
systemctl start removeadhosts.path
|
||||
systemctl enable rhosts.timer
|
||||
systemctl start rhosts.timer
|
||||
systemctl enable rhosts.path
|
||||
systemctl start rhosts.path
|
||||
deactivate:
|
||||
systemctl disable removeadhosts.timer
|
||||
systemctl stop removeadhosts.timer
|
||||
systemctl disable removeadhosts.path
|
||||
systemctl stop removeadhosts.path
|
||||
- systemctl disable rhosts.timer
|
||||
- systemctl stop rhosts.timer
|
||||
- systemctl disable rhosts.path
|
||||
- systemctl stop rhosts.path
|
||||
remove: deactivate
|
||||
rm -f /etc/systemd/system/removeadhosts*
|
||||
rm -fr /usr/local/share/removeadhosts/
|
||||
rm -f /etc/systemd/system/rhosts*
|
||||
rm -fr /usr/local/share/rhosts/
|
||||
rm -f /usr/local/bin/rhosts
|
||||
purge: remove
|
||||
rm -fr /etc/removeadhosts
|
||||
rm -fr /etc/rhosts
|
||||
|
||||
reinstall: remove activate
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
# Removeadhosts
|
||||
# rhosts
|
||||
|
||||
This reroutes sites to 0.0.0.0 in order to block them from being reached by adding them automatically to the hosts file. This was designed off of how Pihole works to block ads but this functions at a local level instead of the entire network.
|
||||
This reroutes sites to 0.0.0.0 in order to block them from being reached by adding them automatically to the hosts file.
|
||||
|
||||
## Requirements to install and run
|
||||
|
||||
- make
|
||||
|
||||
- curl
|
||||
|
||||
## Install
|
||||
|
||||
sudo make install
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
[Unit]
|
||||
Description="Monitor the /etc/passwd file for changes"
|
||||
|
||||
[Path]
|
||||
PathModified=/etc/removeadhosts/adlist.txt
|
||||
PathModified=/etc/removeadhosts/adlistings.txt
|
||||
Unit=removeadhosts.service
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Create temporary files to hold the old configs
|
||||
sed -n '1,/# start of removeadhosts/p' /etc/hosts > /tmp/removeadhosts-head
|
||||
sed -n '/# start of removeadhosts/,/# Custom ad list/p' /etc/hosts | sed -e '/# Custom ad list/d' -e '1d' > /tmp/removeadhosts-curl
|
||||
|
||||
# Copy back all the custom entries
|
||||
cat /tmp/removeadhosts-head | tee /etc/hosts >/dev/null
|
||||
rm /tmp/removeadhosts-head
|
||||
echo "Appended old hosts"
|
||||
if grep -qinE '# start of removeadhosts' /etc/hosts
|
||||
then
|
||||
echo "This has been run before"
|
||||
else
|
||||
echo "First Run"
|
||||
echo '# start of removeadhosts' >> /etc/hosts
|
||||
fi
|
||||
|
||||
|
||||
# Download entries from the listings list
|
||||
echo 'Downloading ad list'
|
||||
if [ -e /etc/removeadhosts/adlistings.txt ]
|
||||
then
|
||||
cat /etc/removeadhosts/adlistings.txt | \
|
||||
while read SITE; do
|
||||
ESC_SITE=$(printf '%s\n' "$SITE" | sed -e 's/[\/&]/\\&/g')
|
||||
echo "# removeadhosts site - $SITE" >> /tmp/removeadhosts-curlbuff
|
||||
RC=0 ; curl $SITE >> /tmp/removeadhosts-curlbuff 2>/dev/null || RC=$?
|
||||
echo "# removeadhosts site - $SITE - end" >> /tmp/removeadhosts-curlbuff
|
||||
if [ $(cat /tmp/removeadhosts-curlbuff | wc -l) -lt 3 ] || [ ! $RC -eq 0 ]
|
||||
then
|
||||
if [ $(sed -n "/removeadhosts site - $ESC_SITE/,/removeadhosts site - $ESC_SITE - end/p" /tmp/removeadhosts-curl | wc -l) -gt 2 ]
|
||||
then
|
||||
echo "Keeping old version of $SITE"
|
||||
if [ $(cat /tmp/removeadhosts-curlbuff | wc -l) -eq 2 ]
|
||||
then
|
||||
echo "Nothing was downloaded"
|
||||
else
|
||||
echo "New version is $(cat /tmp/removeadhosts-curlbuff | wc -l) lines long"
|
||||
fi
|
||||
sed -n "/removeadhosts site - $ESC_SITE/,/removeadhosts site - $EXC_SITE - end/p" /tmp/removeadhosts-curl | tee -a /etc/hosts > /dev/null
|
||||
else
|
||||
echo "Unable to add $SITE"
|
||||
|
||||
fi
|
||||
else
|
||||
echo "Updating $(cat /tmp/removeadhosts-curlbuff | wc -l) lines from $SITE"
|
||||
cat /tmp/removeadhosts-curlbuff | tee -a /etc/hosts >/dev/null
|
||||
fi
|
||||
done
|
||||
fi
|
||||
rm /tmp/removeadhosts-curl
|
||||
rm /tmp/removeadhosts-curlbuff
|
||||
|
||||
|
||||
# Add entries from adlist
|
||||
echo 'Adding custom items from /etc/removeadhosts'
|
||||
if [ -e /etc/removeadhosts/adlist.txt ]
|
||||
then
|
||||
echo "# Custom ad list" >> /etc/hosts
|
||||
cat /etc/removeadhosts/adlist.txt | \
|
||||
while read CMD; do
|
||||
echo "0.0.0.0 $CMD" >> /etc/hosts
|
||||
done
|
||||
fi
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description="Monitor the /etc/passwd file for changes"
|
||||
|
||||
[Path]
|
||||
PathModified=/etc/rhosts.cfg
|
||||
Unit=rhosts.service
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
@ -5,7 +5,7 @@ After=network.target network-online.target
|
|||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/share/removeadhosts/removeadhosts.sh
|
||||
ExecStart=/usr/local/bin/rhosts
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Loading…
Reference in New Issue