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
Justin Reichardt 2021-08-24 10:26:16 -05:00
parent 24e04c58dd
commit 4996513636
7 changed files with 46 additions and 101 deletions

View File

@ -1,29 +1,42 @@
dir: dir:
if [ ! -d /usr/local/share/removeadhosts ];then mkdir -p /usr/local/share/removeadhosts;fi 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/removeadhosts ];then mkdir /etc/removeadhosts;fi if [ ! -d /etc/rhosts ];then mkdir /etc/rhosts;else echo "/etc/rhosts already exists";fi
install: dir if [ ! -d build ];then mkdir build;else echo "build already exists";fi
touch /etc/removeadhosts/{adlist.txt,adlistings.txt build: dir
cp src/* /usr/local/share/removeadhosts/ gcc src/rhosts.c -o build/rhosts
chown -R root:root /usr/local/share/removeadhosts clean:
chmod +x /usr/local/share/removeadhosts/removeadhosts.sh - rm -rf build
ln -s /usr/local/share/removeadhosts/removeadhosts.service /etc/systemd/system/ install: build
ln -s /usr/local/share/removeadhosts/removeadhosts.timer /etc/systemd/system/ if [ ! -e /etc/rhosts/rhosts.cfg ];then touch /etc/rhosts/rhosts.cfg;else echo "/etc/rhosts/rhosts.cfg exists";fi
ln -s /usr/local/share/removeadhosts/removeadhosts.path /etc/systemd/system/ 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 systemctl daemon-reload
activate: install activate: install
systemctl enable removeadhosts.timer systemctl enable rhosts.timer
systemctl start removeadhosts.timer systemctl start rhosts.timer
systemctl enable removeadhosts.path systemctl enable rhosts.path
systemctl start removeadhosts.path systemctl start rhosts.path
deactivate: deactivate:
systemctl disable removeadhosts.timer - systemctl disable rhosts.timer
systemctl stop removeadhosts.timer - systemctl stop rhosts.timer
systemctl disable removeadhosts.path - systemctl disable rhosts.path
systemctl stop removeadhosts.path - systemctl stop rhosts.path
remove: deactivate remove: deactivate
rm -f /etc/systemd/system/removeadhosts* rm -f /etc/systemd/system/rhosts*
rm -fr /usr/local/share/removeadhosts/ rm -fr /usr/local/share/rhosts/
rm -f /usr/local/bin/rhosts
purge: remove purge: remove
rm -fr /etc/removeadhosts rm -fr /etc/rhosts
reinstall: remove activate reinstall: remove activate

View File

@ -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 ## Requirements to install and run
- make - make
- curl
## Install ## Install
sudo make install sudo make install

View File

@ -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

View File

@ -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

9
src/systemd/rhosts.path Normal file
View File

@ -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

View File

@ -5,7 +5,7 @@ After=network.target network-online.target
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/usr/local/share/removeadhosts/removeadhosts.sh ExecStart=/usr/local/bin/rhosts
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target