Showing posts with label grab'n'go. Show all posts
Showing posts with label grab'n'go. Show all posts

2008/06/28

Remote Power off the CH3WNAS

In my previous post, I found out that the CH3WNAS is shutdown by touching a /tmp/shutdown file. It is possible to use the existing web admin pages to trigger a remote shutdown from a script by using 2 wget-commands. One major drawback of this solution is that your admin-password is stored in cleartext in the script.

In this post I show how you can do a remote shutdown via the LAN, without hard coding your admin password. Since this tweak could be misused for a remote DOS attack, make sure you put the CH3WNAS behind a NAT router.

Busybox (activated with the fun_plug script) provides a powerful nc (netcat) command that also has a -l listen mode. This listen-mode is ideal for simple lightweight client/server communication.

Steps for enabling remote shutdown from a script:
  • make sure telnet (through busybox) is enabled: http://www.aroundmyroom.com/2008/01/03/ch3wnas-enabling-telnet/

  • create a shutdown_listener.sh script (e.g. with ftp) on the root of HD_a2 with following contents:
    while true
    do
      /mnt/HD_a2/busybox nc -l -p 1234 | while read line
      do
         if [ "$line" -eq "0" ]
         then
           touch /tmp/shutdown
         fi
      done
    done
    This scripts on the NAS listens in a loop on port 1234. When it reads a "0" it puts a /tmp/shutdown file that triggers the immediate poweroff.

  • add the following line to the fun_plug script and restart the CH3WNAS:
    /mnt/HD_a2/shutdown_listener.sh &

  • from the client-side it's enough to create a nc-script that sends a "0" to the NAS.
    on Ubuntu I created a Launcher on my desktop with following command :
    bash -c "echo 0 | nc 192.168.1.30 1234 -w 1"

    If you're stuck with Windows, look out for a Windows version of netcat (nc) and put similar commands in a shortcut (cmd /c "..."). Or better, upgrade to Ubuntu :-)
I finally have a script that I can put on all my laptops to trigger a remote shutdown of the NAS. Unfortunately, for powering the device back ON again, you still have to push the powerbutton.

2008/06/17

Restaging the CH3WNAS

Suddenly, after a reboot, my CH3WNAS couldn't start the wireless. It connected to a different ip address than the fixed I assigned it, and the admin-pages didn't react correctly to my actions: e.g. you couldn't see the existing users, but when adding a user I got a "User already exists" error message. Even the ftp server wasn't reacting. Through telnet, I could disable the fun_plug script, but that didn't solve the problem either.

Finally, I reset the firmware in the admin-pages, and the setup my wireless/ftp again. I re-enabled the fun_plug and everything is OK now: telnet is available and I can connect to firefly and mediatomb to access my music...

As a first prevention measure, I edited the firefly.conf file to log onto the hard drive instead of filling up /var/log:
logfile = /mnt/HD_a2/firefly/mt-daapd.log
We'll see if this helps...

2008/06/16

Tweaking the CH3WNAS Power Off

On the CH3WNAS, you have to press the power button for an endless 10s before it finally shuts down. Apparently this 10s delay is determined by the /usr/sbin/chkbutton daemon that polls the power button. There exists a replacement for this process for the dsm-g600 in http://forum.dsmg600.info/t955-chkbutton-replacement.html.
Unfortunately, I couldn't download the attachment to try it out on the CH3WNAS. I asked the author to resubmit his binaries. Maybe for a next post...

There is also shutdown-option in the web-admin pages. After logon, the shutdown is done by firing a POST /goform/sysShootDown request onto the CH3WNAS. After some searching in the sourcecode (download it from the conceptronics' site), I found out that CH3WNAS_GPL/goahead/LINUX/web_api.c handles the shutdown:
void sysShootDown(webs_t wp, char_t *path, char_t *query)
{
if( checkIdleTime(wp) == WEB_IDLE_TIMEOUT )
{
websRedirect(wp, T("web/login.asp"));
return;
}
system("touch /tmp/shutdown");
websRedirect(wp, T("web/tools/shutdown.asp"));
}
--> A simple (but unconventional) touch /tmp/shutdown triggers the shutdown. I suppose it's the same chkbutton daemon process that monitors and picks up the /tmp/shutdown file.


If you need to do a fast remote shutdown, you can exercise the existing web-interface from command line (the wget is standard under linux; under windows, have a look at wget for windows):
wget -o /tmp/test "http://192.168.1.30/goform/formLogin?f_LOGIN_NAME=admin&f_LOGIN_PASSWD=xxx&f_login_type=0"
wget -o /tmp/test2 "http://192.168.1.30/goform/sysShootDown"
Replace the ip & password according to your local setup. Put those commands in a script and you get a simple way to shutdown the unit remotely with a simple double-click. The problem with this code is that you have to put your admin-password in cleartext on your pc. I haven't figured out yet how to circumvent the logon page to remove this security-issue.

2008/06/05

Running Mediatomb on CH3WNAS natively!

I managed to get MediaTomb running on the Grab'n'Go CH3WNAS without gentoo! There is no need to follow the gentoo steps in http://forum.dsmg600.info/t916-Installing-mediatomb.html since the MediaTomb project itself provides binaries for the PPC cpu with no dependencies. MediaTomb provides you a better uPnP Server than the original upnp in the firmware.

Since uPnP has no authentication, make sure you run the CH3WNAS behind a NAT router!

Those are the steps to setup MediaTomb on the CH3WNAS:
  • Download the mediatomb build for the ppc-platform:
    http://downloads.sourceforge.net/mediatomb/mediatomb-static-0.11.0-r1-linux-uclibc-ppce300c2.tar.gz
    (or, to get the latest version, surf to http://mediatomb.cc/pages/download#static and then click on the latest mediatomb-static*-ppc*tar.gz file)

  • unzip the tar.gz and ftp (e.g. with gftp) the full mediatomb-directory to the CH3WNAS under HD_a2 (= /mnt/HD_a2/ on the device)

  • telnet to the device (scroll down in my previous post for fun_plug'in and enabling telnet)

  • make executable:
    chmod 775 /mnt/HD_a2/mediatomb/usr/bin/mediatomb

  • chmod mediatomb.sh for easier ftp(*):
    chmod 777 /mnt/HD_a2/mediatomb/mediatomb.sh

  • edit (e.g. with ftp mediatomb.sh to start mediatomb as daemon +fix LAUNCHDIR bug):
    #!/bin/sh

    # if you want to launch this script from a different directory (for example
    # from an another init script or similar, set the LAUNCHDIR variable below
    # to the absolute path of the mediatomb.sh script

    #LAUNCHDIR=`pwd`
    LAUNCHDIR=/mnt/HD_a2/mediatomb

    rm -f $LAUNCHDIR/mediatomb.log

    export MEDIATOMB_DATADIR="$LAUNCHDIR/usr/share/mediatomb"
    export MEDIATOMB_MAGIC_FILE="$LAUNCHDIR/usr/share/file/magic"
    $LAUNCHDIR/usr/bin/mediatomb -m $LAUNCHDIR -f config -d -l $LAUNCHDIR/mediatomb.log

    !! Remark: Make sure the script is Unix-encoded (single \n for line-breaks), otherwise you'll get a "-ash /mnt/hd_a2/mediatomb/mediatomb.sh" error. try this command to translate the linebreaks:
    /mnt/HD_a2/busybox dos2unix /mnt/HD_a2/mediatomb/mediatomb.sh > /mnt/HD_a2/mediatomb/mediatomb.sh.new
    mv /mnt/HD_a2/mediatomb/mediatomb.sh.new /mnt/HD_a2/mediatomb/mediatomb.sh
  • a first run will create the config.xml:
    /mnt/HD_a2/mediatomb/mediatomb.sh
    then run kill `pidof mediatomb` to stop the daemon

  • for easier editing of the config.xml (*):
    chmod 666 /mnt/HD_a2/mediatomb/config/config.xml

  • now modify (ftp) the newly created /mnt/HD_a2/mediatomb/config/config.xml in order to add a fixed ipadres or interface and optional port.

    <server>
    ...
    <name>Michael's MediaTomb</name>
    <udn>...</udn>
    <ip>192.168.1.30</ip>
    <port>50505</port>
    <!-- or define port <interface>br0</interface> -->
    <home>/mnt/HD_a2/mediatomb/config</home>
    ...
    <protocolInfo extend="yes"/>
    ...
    <!-- add extra mappings for jpeg / mpeg -->
    <map from="JPG" to="image/jpeg"/>
    <map from="jpg" to="image/jpeg"/>
    <map from="mpg" to="video/mpeg"/>
    <map from="m4a" to="audio/mpeg"/>
    ...
    The config.xml is well-documented at http://mediatomb.cc/pages/documentation#id2536421. Check out the docs in order to support for example PS3 connections.
  • for auto-startup, you can add the following lines your fun_plug:
    ...
    #kill legacy upnp
    kill -9 `pidof upnp`

    #start mediatomb
    /mnt/HD_a2/mediatomb/mediatomb.sh

    As you can see, I still run firefly, because I couldn't get a uPnP client working in Ubuntu (Rhythmbox).

  • after startup, connect to MediaTomb for configuring the directories to watch: (e.g.) http://192.168.1.30:50505/
I'm not 100% sure that my config is OK, because I couldn't get Rhythmbox (+python-coherence) connecting to MediaTomb. I can see the uPnP broadcast messages from MediaTomb in WireShark and the Cidero java client can connect to MediaTomb and show a tree of media files. Cidero has no playback capabilities, so it's still possible I'll have to tweak the config a bit.

update 9/7/2008: fixed the config for serving jpeg (see comments below) / using correct 'magic' files. If you used a previous version of this post, delete the bogus config.xml and mediatomb.db* files and follow the steps starting with fixing mediatomb.sh.

(*) Close this small security hole: revert to the original protection with a chmod 440 or 550 afterwards. Of course, with telnet and upnp enabled, you'd better keep the CH3WNAS behind a NAT router.

2008/06/01

CH3WNAS and FireFly

I managed to get FireFly running om my CH3WNAS. It's fairly easy if you're not afraid of the command line :-). I was wrong in my post yesterday: you do NOT need Gentoo in order to run firefly! Gentoo is apparently only needed if you want to build FireFly from the sources.

The info in http://dsmg600.info/howto:firefly contains too much steps for the CH3WNAS.

This is the 'real' way to setup firefly on CH3WNAS:
  • enable telnet in fun_plug: http://www.aroundmyroom.com/2008/01/03/ch3wnas-enabling-telnet/
  • download the latest build of FireFly for the CH3WNAS: http://willie-wortel.nl/ch3wnas/ch3wnas-ff-1696.tgz. Unzip the build onto the NAS. (/mnt/HD_a2)
  • I renamed the main directory from /mnt/HD_a2/firefly-1696 to /mnt/HD_a2/firefly. This is consequent with the config.
  • edit the following line in /mnt/HD_a2/firefly/mtdaapd.conf file (e.g. with ftp):
    mp3_dir = /mnt/HD_a2/media
    --> replace media with the root-directory to your mp3s.
    --> check out the other options like default admin password if you wish.
  • add the following lines to your fun_plug:
    #kill legacy upnp (if you don't use the upnp ;-)
    kill -9 `pidof upnp`

    #start firefly
    rm -f /mnt/HD_a2/firefly/var/cache/mt-daapd/*
    /mnt/HD_a2/firefly/sbin/mt-daapd -c /mnt/HD_a2/firefly/mt-daapd.conf
    As you can see, I completely remove the DB before starting FireFly up. This is because while I was testing, the DB went corrupt after a reboot. The indexing at startup is very fast (4000 mp3s in 64 seconds) so this isn't really a problem, I think. Maybe there are more elegant ways to prevent corruption of the DB?
I tested it with Rhythmbox under Ubuntu 8.04 & it works like a charm :-). Make sure the "Multicast DNS service discovery" service (= mDNS) is running in Ubuntu (System/Administration/services) and that the "daap plugin" is checked in rhythmbox (edit/plugins). I'm seriously considering buying the Roku (Pinnacle) Soundbridge now...

Other tips:
  • check out the FireFly admin pages in your browser: go to port 3689 of your CH3WNAS:
    e.g. http://192.168.1.30:3689/ user: admin; password: mt-daapd (default)
  • you can follow the logs in /var/log/mt-daapd.log (maybe not the best location :-/):
    tail -f /var/log/mt-daapd.log
thanks to http://forums.fireflymediaserver.org/viewtopic.php?p=20282&sid=5b52a2902da3f5b3462bed5e1bc826fd and http://willie-wortel.nl/ch3wnas/!

(updated: 12/6/2008: corrected willie-wortel links)

2008/05/29

CH3WNAS: Grab'n'Go Wireless Media Store


One month ago, I bought a Conceptronic WiFi 500 GB Grab'n'Go Wireless Media Store (CH3WNAS) at about 130 EUR. This is cheap if you look at the features and compare it with other NAS-devices.

Check out the Conceptronic's website for more info.

I found a few minor glitches in the device. Those are not blocking in my case:
  • There is no way to turn the device automatically on after a power-cut. You have to press 'power on' button manually for starting the device up. The FAQ states this is hardware-related and can not be fixed. This is unfortunate if you want to reach your NAS while you're on holiday, or, if you want to routinely cut off the power to remove latent power consumption.
  • For a 'clean' shutdown, you have to keep the power-button pressed during 5s. At first, this gives the impression the device hangs and you have to force the shutdown -- at least that's how I shutdown a laptop when it hangs. This is also documented in the FAQ. I couldn't find any 'chkfs' recommendations in the manual to make sure the data is save.

    There is also a 'shutdown' button in the web-interface that performs a clean remote shutdown. This looks more like a regular 'shutdown' command.

  • I was planning to use the CH3WNAS to replace my wifi router. Unfortunately, it has no support for NAT (and similar standard router-functionalities). Particularly with the built-in UPnP server, it's wise to keep the device behind your NAT. --> I'll keep my router in place to protect my home network; since the router itself has wifi (like almost any router nowadays), the Wifi server feature of the CH3WNAS is less appealing. Of course, the CH3WNAS could still act as a range extender if I install a long LAN-cable.

  • I connected a USB drive into the CH3WNAS to perform automatic backups. The web-interface has nice provisions for backing up. This is called 'scheduled downloads'. Not very intuitive, but after selecting 'folder' and clicking on 'local', the device does what it's expected to do: backup.

    Unfortunately, the support for NTFS is very limited: the NTFS drive in the USB port is mounted as readonly and all folders/filenames are in uppercase. I reformatted the drive to FAT32 and now the device is supported correctly. A bit disappointing when you're used to Ubuntu and its out-of-the box ntfs-3g support, but I suppose the Linux-version on the device is a bit too old for NTFS (or the resources are too limited?).

  • There are reports that the built-in UPnP Server is primitive, but I couldn't verify this. I couldn't get the UPnP to work correctly from within Ubuntu.
The good news is that the CH3WNAS is a linux-device! There are a lot of tweaks out there:
The DSM-G600 appears to be a very similar device to the CH3WNAS. That's a good start for interesting hacks:
I'm considering installing gentoo (under chroot) and Firefly, or better(?) MediaTomb. Those look like a killer-solution. --> next blog :-)