Skip to content

Instantly share code, notes, and snippets.

@wurin7i
Last active July 15, 2022 10:00
Show Gist options
  • Save wurin7i/74784964ef4c7db94ab9 to your computer and use it in GitHub Desktop.
Save wurin7i/74784964ef4c7db94ab9 to your computer and use it in GitHub Desktop.
Buat masukin dan menghapus daftar domain yg diblokir trust positif.
#!/bin/bash
# CARA INSTALL
# salin source dan simpan dalam berkas alternamed.sh
# pindahkan alternamed.sh ke /usr/local/bin/alternamed.sh
# beri akses executable: sudo chmod a+x /usr/local/bin/alternamed.sh
# Author: Wuri Nugrahadi <w.nugrahadi@gmail.com>
[[ $# -lt 3 ]] &&
echo -e "Penggunaan: $(basename $0) block|release filename named.conf comment\nContoh:" &&
echo "$(basename $0) block tambahan-2015-04-01.txt /etc/bind/named.conf 'tambahan dari kominfo'" &&
exit 1
ACTION=$1
FILE=$2
TARGET=$3
REASON=$4
DATE="$(date +%F)"
ALTERCOUNT=0
function alterfile {
NUMOFLINES=$(($(wc -l < "$FILE")+1))
while read -r line || [[ -n "$line" ]]
do
if [[ $1 == "block" ]]; then
echo "zone \"$line\" { type master; file \"master/restric.com\"; };" >> "$TARGET"
else
sed -i -e "s/.*\"$line\".*/#& # $DATE $REASON/" "$TARGET"
fi
(( ALTERCOUNT++ ))
progress=$((($ALTERCOUNT*100)/$NUMOFLINES))
progress=$(printf "%.0f" $progress)
string=$(padstring "$line" "$progress%")
echo -ne "$string\r"
done < "$FILE"
}
function padstring {
pad=$(printf '%0.1s' " "{1..80})
padlength=80
string1=$1
string2=$2
printf '%s%*.*s%s\n' "$string1" 0 $((padlength - ${#string1} - ${#string2} )) "$pad" "$string2"
}
if [[ "$ACTION" == "block" ]]; then
echo "Menambahkan daftar blokir ke $TARGET"
echo -e "\n\n### Ditambahkan $DATE\n### $REASON\n###" >> "$TARGET"
alterfile block
echo -e "###" >> "$TARGET"
elif [[ "$ACTION" == "release" ]]; then
echo "Menghapus daftar blokir dari $TARGET"
alterfile release
else
echo -e "Penggunaan: $(basename $0) block|release filename named.conf comment" &&
exit 1
fi
echo -ne "Berhasil memproses $ALTERCOUNT baris.\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment