marian78
Patron
- Joined
- Jun 30, 2011
- Messages
- 210
Hi, i want use some IP-bloklists with Transmission in Jail instaled as plugin from Freenas UI.
I started search on internet
and done some learning
. Here is what i did:
Instaled Transmission to Jail as plugin (standard install) with number "4" (if you dont know your number, type "jls" from freenas SSH) and mounted transmission configuration folder (if you dont know where is it, look at Transmission plugin settings in freensUI) to "/mnt/volume2/Transmission".
In my freenas server, script is saved in "/mnt/volume1/"blocklist_v4.sh".
What happend when i started script:
Download ip blocklists from "iblocklist.com". Next, all are merged and unpacked, moved to folder for blocklist. Restart Transmission and send mail about update.
Script "blocklist_v4.sh" before use, must be edited :) : set your paths, jail number, mail server settings...
For periodic starting of script i used "cron task" ;) from freenas GUI with this settings:
user: root, command: /mnt/volume1/blocklist_v4.sh, hour: 18, minute: 0, day of month: 1, month: all selected, day of week: all selected, Redirect Stdout: true, Redirect Stderr: true, Enabled: true.
Now script:
If you want to tray and if it work for you, i will be lucky. If there is something wrong, please post here.
Marian.
EDIT: change "restart" Transmission service to "start/stop", add delete all ".bin" files in blocklists folder before upload new, add mail notify if nothing downloaded.
I started search on internet
Instaled Transmission to Jail as plugin (standard install) with number "4" (if you dont know your number, type "jls" from freenas SSH) and mounted transmission configuration folder (if you dont know where is it, look at Transmission plugin settings in freensUI) to "/mnt/volume2/Transmission".
In my freenas server, script is saved in "/mnt/volume1/"blocklist_v4.sh".
What happend when i started script:
Download ip blocklists from "iblocklist.com". Next, all are merged and unpacked, moved to folder for blocklist. Restart Transmission and send mail about update.
Script "blocklist_v4.sh" before use, must be edited :) : set your paths, jail number, mail server settings...
For periodic starting of script i used "cron task" ;) from freenas GUI with this settings:
user: root, command: /mnt/volume1/blocklist_v4.sh, hour: 18, minute: 0, day of month: 1, month: all selected, day of week: all selected, Redirect Stdout: true, Redirect Stderr: true, Enabled: true.
Now script:
Code:
#!/bin/sh
# path to Transmission configuration folder (default is "/mnt/xxxx/Transmission/home")
CONFIGPATH="/mnt/volume2/Transmission"
#blocklist folder in Transmission configuration folder (default is "blocklists")
BLOCKLISTPATH="blocklists"
#blocklist file
BLOCKLISTFILE="blocklist.p2p"
#NUMBER of Transmission Jail - jls
JAILNUMBER="4"
#mail settings
#account
EMAIL="yourmail@gmail.com"
#freenas server name
SERVER="yourservername"
# create work folders
if [ ! -d "$CONFIGPATH"/"$BLOCKLISTPATH" ]; then
mkdir "$CONFIGPATH"/"$BLOCKLISTPATH"
fi
if [ ! -d "$CONFIGPATH"/tmp ]; then
mkdir "$CONFIGPATH"/tmp
fi
# set variables
BLOCKLIST="$CONFIGPATH"/"$BLOCKLISTPATH"/"$BLOCKLISTFILE"
TMPFLDR="$CONFIGPATH"/tmp
# echo "$BLOCKLIST" a "$TMPFLDR"
# test internet connection
host "list.iblocklist.com" >/dev/null
if [ $? -ne 0 ]; then
exit 0
fi
# get ip blocklists from internet
wget -q "http://list.iblocklist.com/?list=bt_bogon" -O "$TMPFLDR"/bl-bogon.gz
wget -q "http://list.iblocklist.com/?list=bt_hijacked" -O "$TMPFLDR"/bl-hijacked.gz
wget -q "http://list.iblocklist.com/?list=bcoepfyewziejvcqyhqo" -O "$TMPFLDR"/bl-iana-reserved.gz
wget -q "http://list.iblocklist.com/?list=bt_ads" -O "$TMPFLDR"/bl-ads.gz
wget -q "http://list.iblocklist.com/?list=bt_dshield" -O "$TMPFLDR"/bl-dshield.gz
wget -q "http://list.iblocklist.com/?list=bt_level1" -O "$TMPFLDR"/bl-level1.gz
wget -q "http://list.iblocklist.com/?list=bt_level2" -O "$TMPFLDR"/bl-level2.gz
wget -q "http://list.iblocklist.com/?list=bt_microsoft" -O "$TMPFLDR"/bl-microsoft.gz
wget -q "http://list.iblocklist.com/?list=bt_spyware" -O "$TMPFLDR"/bl-spyware.gz
wget -q "http://list.iblocklist.com/?list=bt_templist" -O "$TMPFLDR"/bl-badpeers.gz
# test if something is downloaded
if [ ! -f "$TMPFLDR"/bl-*.gz ]; then
# send mail if no file downloaded
echo "To: $EMAIL" >> "$TMPFLDR"/badconfig.txt
echo "Subject: IP-BLOCKLIST NO update on server $SERVER" >> "$TMPFLDR"/badconfig.txt
echo "Your server, $SERVER, dont download any IP-BLOCKLIST file" >> "$TMPFLDR"/badconfig.txt
sendmail -t < "$TMPFLDR"/badconfig.txt
rm "$TMPFLDR"/badconfig.txt
exit 1
fi
# chenge permissions
chmod 777 "$BLOCKLIST"
# backup old ip blocklist
if [ -f "$BLOCKLIST" ]; then
mv -f "$BLOCKLIST" "$CONFIGPATH"/"$BLOCKLISTFILE".old
fi
# merge all downloaded ip blocklists to one
cat "${TMPFLDR}"/bl-*.gz > "${BLOCKLIST}".gz
# stop transmission
jexec "$JAILNUMBER" service transmission stop
# remove all .bin files in blocklists folder
rm "$CONFIGPATH"/"$BLOCKLISTPATH"/*.bin
# unzip merged ip blocklist
gunzip "$BLOCKLIST".gz
# remove comments, empty lines in ip blocklist
sed -i .orig -e '/^\#/d' -e '/^$/d' "$BLOCKLIST"
# remove old working ip blocklist
rm "$BLOCKLIST".orig
# sort ip blocklist ang get it ready
sort "$BLOCKLIST" > "${TMPFLDR}"/blocklist.p2p.tmp && mv -f "${TMPFLDR}"/blocklist.p2p.tmp "$BLOCKLIST"
# remove working files
rm -f "$TMPFLDR"/bl-*.gz
# set permissions
chmod 664 "$BLOCKLIST"
chown 921:921 "$BLOCKLIST"
# start transmission
jexec "$JAILNUMBER" service transmission start
# send mail
echo "To: $EMAIL" >> "$TMPFLDR"/badconfig.txt
echo "Subject: IP-BLOCKLIST update OK on server $SERVER" >> "$TMPFLDR"/badconfig.txt
echo "Your server, $SERVER, has updated IP-BLOCKLIST file" >> "$TMPFLDR"/badconfig.txt
sendmail -t < "$TMPFLDR"/badconfig.txt
rm "$TMPFLDR"/badconfig.txt
exit 2
If you want to tray and if it work for you, i will be lucky. If there is something wrong, please post here.
Marian.
EDIT: change "restart" Transmission service to "start/stop", add delete all ".bin" files in blocklists folder before upload new, add mail notify if nothing downloaded.