Last active
August 5, 2024 09:19
-
-
Save wurin7i/74784964ef4c7db94ab9 to your computer and use it in GitHub Desktop.
Buat masukin dan menghapus daftar domain yg diblokir trust positif.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 <[email protected]> | |
[[ $# -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