Xdsl: Using an Original Xbox as a Network Attached Storage Device (NAS), SSH server, BitTorrent client, and more

X-DSL is a Linux distribution for the original Xbox. The old Xbox sells for about $35 on eBay and can be used as an NAS for both IDE and SATA hard drives and can be used as a BitTorrent client.

For the sake of brevity, I will assume the Xbox already has XBMC installed and the ability to FTP files to the Xbox and execute xbe files.

Software used: Xdsl iso, and use 7-zip to extract the iso SSH/Putty FileZilla or any FTP client RealVNC

Part 1: Uploading Xdsl via FTP Extract the files in the the Xdsl iso. Create an FTP session with the Xbox. Copy the KNOPPIX folder from the extracted iso to the Xbox’s E: drive. Open the KNOPPIX folder on the Xbox and copy minirt24.gz and linux24 to this folder. E:\KNOPPIX should now have three files, one of which is named KNOPPIX, and no further subdirectories. Also copy README-FTP\linuxboot.cfg to E:\linuxboot.cfg. Now make a folder in the E:\Apps directory called simply Linux and copy the default.xbe file to E:\Apps\Linux\default.xbe.

In total, four files are copied and the overall structure is: E:\linuxboot.cfg E:\Apps\Linux\default.xbe E:\KNOPPIX\KNOPPIX E:\KNOPPIX\linux24 E:\KNOPPIX\minirt24.gz

In XBMC run the Linux default.xbe. The Xromwell blue screen will appear. Select the hard drive and press A. It should boot directly into Xdsl.

Part 2: Installing Xdsl The D-pad and left joystick move the mouse. Press Y to right-click the desktop and go to System > Daemons > ssh > start. Open putty/ssh and connect to the Xbox with username admin and password xbox. Then run the command xbox-loopbackinstall.

ssh root@192.168.1.101
root@192.168.1.101's password: xbox
xbox-loopbackinstall

Go through the menus and when it asks for the size of the loopback filesystem, change it from 200 to 600. Continue through selecting for the defaults. After it’s finished, reboot the Xbox:

reboot

Part 3: Configuring Xdsl for SSH and VNC After the Xbox is done rebooting, go back in Xbmc and run Xromwell again and select the hard drive. This time a menu will appear. Choose XDSL Loopback, the second choice. Start the ssh daemon again (right-click the desktop and go to System > Daemons > ssh > start). Connect to the Xbox using Putty/ssh again. Users who are using ssh will need to remove the key from their system:

ssh-keygen -R 192.168.1.101

To set the ssh daemon to start when Xdsl boots, enter the following. If you are using Putty on Windows, copy it to the clipboard then right-click the Putty window to paste.

ln /etc/init.d/ssh /etc/rc5.d/S20ssh -sfn

Now on the Xbox go right-click the desktop and go to MyDSL > MyDSL Browser. In the left panel expand + net and scroll down and select vnc4x-1.4.6.dsl. Click the Install Selected button. Close out of the MyDSL Browser and right-click the desktop and go to MyDsl > vncserver > vnc4x0. Start up the RealVNC client and enter the Xbox’s IP and click connect.

Part 4: Installing BitTorrent Now, using RealVNC, right-click the desktop XDSL Upgrades > Upgrade to GNU Utils, then XDSL Upgrades > Enable Apt. Right-click desktop, MyDSL > MyDSL Browser. Install net > bittorrent-cli.dsl.

Now in the ssh session enter:

ln -sfn /usr/bin/python2.2 /usr/bin/python

Mount the E: drive, then open a screen session and su to the regular user (dsl):

mount /dev/hda50
mkdir /mnt/hda50/torrents
apt-get install screen
screen
su dsl

BitTorrent can be run using the following command.

$ btdownloadcurses --saveas /mnt/hda50/torrents --minport 52130 --maxport 52140 CompletelyLegalLinuxDistribution.torrent

Note: VNC uses about 70% of the CPU. Only run it when you have to; use SSH.

To start more than one torrent, press [Ctrl]+[A], then [C] and type the command with the next torrent. [Ctrl]+[A],[P] and [Ctrl]+[A],[N] go back and forth between the two buffers.

That’s all for now. You can use SFTP to access the hard drive, SSH, VNC, and BitTorrent. Let me know in the comments if you enjoyed this tutorial. Comments are always appreciated.

Part 5: Serving files using Samba Per a request in the comments, here’s how to have the Xbox serve files using Samba.

In Xdsl, right-click the desktop and go to MyDSL > MyDSL Browser. In the left pane, click the [+] net, and then find samba.dsl and click it. Click the Install Selected button at the top of the window.

Open up an SSH session to Xdsl. Enter the following commands, but you may need to change WORKGROUP to MSHOME. These commands backup your Samba configuration file, then change the workgroup, and finally add the E, F, and G partitions as shares. Copy the entire contents of the following, then right-click in Putty to paste them.

cp /opt/samba/smb.conf /opt/samba/smb.conf.bak
sed -i -e 's/^\tworkgroup = .*$/\tworkgroup = WORKGROUP/' /opt/samba/smb.conf
sed -i -e 's/;  encrypt passwords/encrypt passwords/' /opt/samba/smb.conf
printf "[E]\n   path = /mnt/hda50\n   public = yes\n   writable = yes\n\n[F]\n   path = /mnt/hda55\n   public = yes\n   writable = yes\n\n[G]\n   path = /mnt/hda56\n   public = yes\n   writable = yes\n\n" >> /opt/samba/smb.conf
printf "mount /dev/hda55\nmount /dev/hda56\nnmbd -D -s /opt/samba/smb.conf\nsmbd -D -s /opt/samba/smb.conf\n" >> /opt/bootlocal.sh

Now you need to mount the other partitions, restart Samba, and set a new Samba password for root. Just hit enter twice when it asks for a password to use a blank password.

mount /dev/hda55
mount /dev/hda56
nmbd -D -s /opt/samba/smb.conf
smbd -D -s /opt/samba/smb.conf
sudo smbpasswd -a root

Wiki Parser v0.1 – Read Wikipedia Offline

Wiki Parser is a Python program which takes a Wikipedia dump and hosts it locally, offline. To save disk space, Wiki Parser keeps the dump compressed and serves articles to a web browser without decompressing the entire file. I originally created it to serve up Wikipedia articles from a compressed version, but seek times on the compressed file were too great and the program really only works on smaller Wikipedias such as the Simple English Wikipedia.

Download the latest dump of Simple English Wikipedia here Download Wiki Parser v0.1 here

microdc2 for Windows/Cygwin

microdc2 (http://corsair626.no-ip.org/microdc/) is a command-line Direct Connect client originally developed for flavors of Linux. This is a version compiled for Windows/Cygwin and requires a Cygwin environment to run. This program provides a command line version of Direct Connect on Windows which is especially useful if you run an SSHd server with GNU Screen on Windows and want to be able to remotely manage a Direct Connect client. Read the README.WIN.TXT for installation instructions and read the README for usage instructions.

Download microdc2 v0.15.6 for Windows/Cygwin here

microdc2

Using Twisted Python library to replicate packets

Most of the programming I do is packet replication and automation. My workflow is to first analyze the handshakes and protocols in FireFox with the Tamper Data add-on. I use WireShark to nail down the interaction details. Finally, I recreate everything using the Twisted library in Python.

Here’s a boilerplate to quickly recreate packets using Twisted. It requests and saves a copy of Google.com. Simply replace with your favorite URL, or un-comment the two lines and comment the other getPage to send a POST request.

from twisted.web import client
from twisted.internet import reactor
 
agent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12 (.NET CLR 3.5.30729)"
headers = {'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language':'en-us,en;q=0.5', 'Accept-Charset':'ISO-8859-1,utf-8;q=0.7'}
headers_post = headers.copy()
headers_post['Content-Type'] = 'application/x-www-form-urlencoded'
 
def success(data):
    print "Success!"
    f = open('save.html','w')
    f.write(data)
    f.close()
    reactor.stop()
 
def failure(fail):
    print fail.getErrorMessage()
    reactor.stop()
 
def request():
    url = "http://google.com/"
    d = client.getPage(url, headers=headers, agent=agent)
    #post_data = ""
    #d = client.getPage(url, postdata=post_data, method="POST", headers=headers_post, agent=agent)
    d.addCallback(success).addErrback(failure)
 
request()
reactor.run()

To make it continually request the same page, change the success method to this:

def success(data):
    print "Success!"
    f = open('save.html','w')
    f.write(data)
    f.close()
    reactor.callLater(0.5, request)

Rewind

I got an email today:

Hello,

Unfortunately but your data is damaged un-fixable

Thank you, www.000webhost.com

Data damaged un-fixable! But I’m smart; I make backups. I found the file in my backup folder, extracted the SQL, then opened it to verify everything was fine. I only make backups every few months, but I had made one this month on the July 7th. When I do backups I backup all my websites and carefully label them and file them away on one of my hard drives, then I burn a copy of my entire backup folder to a DVD, just in case my backup hard drive dies. Sadly, this past month when I was making backups, I mislabeled one. Wouldn’t you know it had to be the one with data damaged un-fixable. The SQL file belonged to a different site, and my blog’s data really is gone.

Google cache has some of the old posts and I’ll work on moving the ones that matter which are really only two posts. This backup is from November 2008. Not much lost since I haven’t been active lately, but data loss is never fun.

Async Download with Curl in Irssi Perl Scripting

When downloading a file from Perl, there’s many ways to go about it. You can use LWP, libcurl, wget, curl the program, etc. My shell hoster doesn’t include many perl bindings so I can’t use LWP or libcurl. I use curl -s $url to download urls. The only problem with using any of the above mentioned methods is that they all block Irssi until the page is downloaded. That means the client freezes and doesn’t respond to pings during this time. To remedy this, fork can be used. But fork is rather screwy in Irssi; if you use it wrong, it will create 2 instances of Irssi.

The fix? Use someone else’s code that works. Here’s mine, released under the GNU GPL. It can easily be adapted, and should be, to use LWP or libcurl if your client supports those.

use strict;
use Irssi;
use POSIX;
 
sub async_curl ($$$) {
        my ($geturl, $callback, $argref) = @_;
        my ($reader, $writer);
        pipe($reader, $writer);
        my $pid = fork();
        if ($pid > 0) {
                close($writer);
                Irssi::pidwait_add($pid);
                my $pipetag;
                my @pargs = ($reader, \$pipetag, $callback, $argref);
                $pipetag = Irssi::input_add(fileno($reader), INPUT_READ, \&pipe_input, \@pargs);
        } else {
          my $content;
          eval {
                my $data = `curl -s "$geturl"`;
                print($writer $data);
                close($writer);
          };
          POSIX::_exit(1);
        }
}
 
sub pipe_input ($$$$) {
        my ($reader, $pipetag, $callback, $argref) = @{$_[0]};
        my @lines = <$reader>;
        close($reader);
        Irssi::input_remove($$pipetag);
        my $text = join("", @lines);
        $callback->($text, $argref);
}

Using this code is very simple. Here’s a quick example:

sub callback_method {
        my ($content, $argref) = @_;
        my ($arg1, $arg2) = @{$argref};
        # Here we have the $content from the url
        # and the two args we wanted back
}
 
# Gather up any arguments we want to piggy-back onto the callback
my @args = ('test1', 'test2');
# Call async_curl with a reference to our callback method
# and a reference to our piggy-back args
async_curl("http://www.google.com/", \&callback_method, \@args);

Python FTP upload using Twisted

Here’s a snippet for uploading a file via FTP using the Twisted Python library available from TwistedMatrix.

from twisted.protocols.basic import FileSender
from twisted.protocols.ftp import FTPClient
from twisted.internet.protocol import ClientCreator
from twisted.internet import reactor
 
def fileTransferFail(failure):
    failure.printTraceback()
    reactor.stop()
 
def cbStore(consumer, filename):
    fs = FileSender()
    d = fs.beginFileTransfer(open(filename, 'r'), consumer)
    d.addCallback(lambda _: consumer.finish()).addErrback(fileTransferFail)
    return d
 
def connectionMade(ftpClient, filename, uploadpath = None):
    if uploadpath is None:
        uploadpath = filename
    d1, d2 = ftpClient.storeFile(uploadpath)
    d1.addCallback(cbStore, filename).addErrback(fileTransferFail)
    d2.addCallback(lambda _: reactor.stop())
    return d2
 
def sendFile(host, port, username, password, filename, uploadpath):
    creator = ClientCreator(reactor, FTPClient, username, password)
    d = creator.connectTCP(host, port)
    d.addCallback(connectionMade, filename, uploadpath).addErrback(fileTransferFail)
    return d
 
if __name__ == '__main__':
    username = 'GoogleUser'
    password = 'GoogleSuperSecretPassword'
    host = 'google.com'
    port = 21
    filename = 'index.html'
    uploadto = '/public_html/index.html'
    sendFile(host, port, username, password, filename, uploadto)
    reactor.run()

HaloHBF v0.1

I get so many hits to my site every day from people looking for it, so here it is.

HaloHBF v0.1

Download HaloHBF v0.1

A quick look at Chromium development

I’ve been using the latest trunk builds of Chromium for about a week now. One feature I’ve noticed is the Bookmark Manager, which alone should be enough reason to try out the latest snapshot.

Chromium Bookmark Manager

So what else has changed? Take a look at the issues list and see for yourself. There’s also the code review site where you can take a look at some of the actual chunks of code that changed along with a description of what was changed. And finally, there’s the ViewVC site where you can see the svn check ins and their descriptions.

So what are you waiting for? Dump your Google Chrome beta, grab the latest trunk, and post your thoughts on it below!

Google Chrome Dev Channel? Weak.

Is Google Chrome Dev Channel not bleeding edge enough for you either? Time to start using Chromium snapshots. These builds are released multiple times daily and contain the latest bug fixes and patches the Chromium team has been working on. While technically they can introduce new and worse bugs, using these can at least assuage the old ones.

To get started, head to http://build.chromium.org/buildbot/snapshots/chromium-rel-xp/ and grab the latest build at the bottom. Download and install the mini_installer.exe. Now close all your copies of Chrome/Chromium. Copy C:\Documents and Settings\YOUR USERNAME\Local Settings\Application Data\Google\Chrome\User Data over into C:\Documents and Settings\YOUR USERNAME\Local Settings\Application Data\Chromium\User Data

Now goto Start > Programs > Chromium and run Chromium. Click the little wrench in the corner and goto Options and ‘Make chromium your default browser’.

Enjoy your bleeding edge copy of Chromium and be sure to report any bugs to the Google Code Chromium project.

Image and video hosting by TinyPic

Chromium