Saturday, July 3, 2010

Freenas Transmission Tweaks

Blatantly liberated from http://code.google.com/p/freenas-rss-extension/wiki/MyTweaks.

** FOR THOSE SEARCHING FOR ERRORS RELATED TO "BLOCKLIST_UPDATE: Config directory not set"

The script below searches through FreeNAS' configurtion files to find the torrents 'Config' directory as per the below screenshot. This option is in the WebUI -> Services -> Torrents



You really really shouldnt need to, but if your still haveing huge problems you could try replacing the code:
config_dir=`/usr/local/bin/xml sel -t -m "//bittorrent" -v configdir /cf/conf/config.xml | /usr/local/bin/xml unesc`
With:
config_dir="/path/to/torrent/config/directory/"
Note: Make sure you put the torrent config directory in a location that allows write (i.e. dont put it willy nilly somewhere in the root filesystem - put it in your RAID or on the spare bit of your OS drive)

1) Fix for file permissions when using samba for windozer file sharing.
Why? Well, basically when you log in Anonymously in windows via SMB protocol, it forces your computer to work under FreeNAS's 'ftp' user. Which is fine, untill...
When Tranmission saves a file, it does so under the 'transmission' user. Also fine.
But when you browse to your NAS from windows (being forced to work as the 'ftp' user) and you try and move or whatnot a torrent file (which has been saved as the 'transmission' user) FreeNAS cracks a wobbly and tells you that you dont have permission to do that (as all it sees is one user trying to fiddle with anothers files)

So we can baindaid her up, with the below additions to the 'Auxiliary paramaters' section

This forces the windows client to pretend to be the 'transmission' user, not the 'ftp' user. So it all plays nice!

2) Blocklist updater.
By default, FreeNAS doesnt use a blocklist (in fact, it disables it quite semi-permantly). We can fixxer that up however.

The script below is also taken from the above wiki - I prefer this one because of the location it gets its blocklists from (Bluetack) and the felxibility of lists.

(Big note: If you copy this into notepad and save it onto the NAS, youll encounter one big problem: Windows uses CF+LF to dictate end of line (return). *NIX uses just LF. This confuses the bash interpreter and it will not run. Download and use Notepad2 and when you save the file select 'File->Line encoding-> Unix (LF)' to avoid those problems)

First off: youll have to stop FreeNAS from diabling blocklist. Do so by editing the rc.conf variables via System -> Advanced -> RC.CONF in the WebUI


Either way, before running the file, youll have to log into the NAS via SSH (Enable the SSH service, setup a user in the webUI with 'bash' as its shell, and point Putty to your NAS) and run some commands on the file.


Bonus geek points if you noticed the nethack.alt.org telnet settings!

First, use the SU command (and enter admin password to NAS) to gain 'superuser' privelages, browse to the direcrory using the CD command, and CHMOD +x the file. Then you can run it directly to ensure it works. Like ive done below.

(Note the LS -Gl [this lists the directory in colour mode] - the permissions list to the far left of blocklist.sh is -rwxrwxrwx. The x's mean its eXecutable, which is what we need to run the script (this is what CHMOD +x has done to the file - CHange MODe eXecute)



CODE: blocklist.sh
#! /bin/bash

###
# Select the blacklists you would like to download & use, all available lists
# (except exemptions) are listed below
#LISTS="ads-trackers-and-bad-pr0n bogon dshield edu fornonlancomputers hijacked iana-multicast iana-private iana-reserved level1 level2 Microsoft proxy spider spyware"
#
LISTS
="bogon dshield hijacked iana-multicast iana-private iana-reserved level1 level2 Microsoft"

###
# YOU SHOULD NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
#
url
="http://www.bluetack.co.uk/config/"
config_dir
=`/usr/local/bin/xml sel -t -m "//bittorrent" -v configdir /cf/conf/config.xml | /usr/local/bin/xml unesc`
updated
=0

if [ "$config_dir" == "" ]; then
logger
-t blocklist_update -- Config directory not set
exit 1
fi

if [ ! -d "$config_dir/gzblocklists" ]; then
mkdir
"$config_dir/gzblocklists"
fi

for list in $LISTS; do
file
="$config_dir/gzblocklists/$list.gz"
lsize
=`stat -qf %z "$file" || echo 0`
rsize
=`fetch -apsw 5 $url$list.gz || exit 1`
if [ "$lsize" -ne "$rsize" ]; then
logger
-t blocklist_update -- Updated $list

# need to download to different folder than $config_dir/blocklists
# transmission seems to have trouble at times starting possibly by trying to parse
# gz'd files
fetch
-qapw 5 -o "$file" $url$list.gz
gunzip
-kqf "$file"
mv
"$config_dir/gzblocklists/$list" "$config_dir/blocklists/"
updated
=1
fi
done

if [ "$updated" -eq "1" ]; then
/etc/rc.d/transmission restart &> /dev/null
else
logger
-t blocklist_updater -- All lists up-to-date
fi

Then its a simple matter of setting up a cron job to run it on a schedule. Below is my settings for midnight every Wednesday.

Note: Your path to the script will differ.

5 comments:

  1. Thanks for this. I had a cron job (chmod -R a+wrx path/for/torrents) set to run every minute to deal with the permissions issue, but your solution is much more elegant.

    ReplyDelete
  2. Thanks so much for the permissions solution, it was driving me crazy.

    ReplyDelete
  3. I get error: blocklist_update: Config directory not set

    Where do I set the directory? Yes I am new.

    ReplyDelete
  4. Hey, I think there is another good option to use with FTP. Since all transmission-created files have transmisson:wheel ownership, it is eaasier to simply login via FTP with the same transmisson user and then u can also access everything. Transmission user is already a member of the FTP group, so logging in should be easy.

    Not sure what's the default password is for transmission user tho... I vary of changing it for the moment ...

    ReplyDelete
  5. I get a "fetch: service unavailable" error
    also I had to remove the second = from $config_dir" == "" I was getting an "unexpected operator" error, I googled the answer but now I am stuck with the current error and no solution. I can ping out so i know that my nas is connected to the internet.

    ReplyDelete