Remote notification

I have been playing around with a way to get my Ubuntu box (that is running VLC on startup to stream our satellite TV across the network) to notify other boxes that it is awake and broadcasting. This is so that my wife can start the box up from a WOL script on the kitchen PC and then, once it is booted up, turn on the modded Xbox and run XBMC to connect to the stream and pick up TV downstairs.

Nice enough. 🙂

I managed to get it working using the following steps.

  1. On the PC that broadcasts TV, I added passwordless SSH (via this link) for the user that the kitchen PC runs under.
  2. On the kitchen PC, I created a script in the /usr/bin called notifier that has the following in it:
    export DISPLAY=:0 && export XAUTHORITY=/home/[KITCHEN COMPUTER USERNAME]/.Xauthority && sudo -u [KITCHEN COMPUTER USERNAME] /usr/bin/notify-send "TV is now broadcasting" 2>&1.

    Most of this is via this page.

  3. After adding the same user to the TV PC, I have a line in the TV PC /etc/rc.local that says
    su [KITCHEN COMPUTER USERNAME] -c notifyKitchen
    The notifyKitchen is a /usr/bin script that simply says
    ssh [KITCHEN COMPUTER USERNAME]@[KITCHEN COMPUTER] 'notifier'.

Done and done. When the TV PC boots, it calls this command and the Kitchen PC gets a pop-up notification that TV is running.

Advertisements

Shutting down via the web

One of the annoying things about Ubuntu is the fact that you need to be an admin user to shutdown the PC. This makes sense if you are running a server, but not when you have a few PCs scattered throughout the house that you’d just like to shutdown quickly.

So, I found a way to enable this through Apache. Warning: this will allow anyone who browses to your PC to shut it down without prompting. So use carefully.

Basically, what you need to do is remove the need for admin/sudo access when shutting down as the www-data (Apache) user. To do this, you use a specific command called visudo which specially edits a file containing what commands require admin access.

In short, make sure that the last line in that file is the following:

www-data ALL= NOPASSWD: SHUTDOWN_CMDS

and that there is a line further up that says Cmnd_Alias SHUTDOWN_CMDS = /sbin/shutdown, /sbin/reboot, /sbin/halt.

Then, once this is done, you can have a shutdown.php that has the following code:

<?php
echo exec('sudo shutdown -h now');
?>

Q.E.D.

Streaming PVR-150 via VLC

So, after some pretty massive renovations, I now have Cat-5E cable throughout the house. Sweet. 🙂

I also have a need to somehow get the feed from my Sky box upstairs to the TV downstairs so the younglings can watch Playhouse Disney. In the past, I’ve done this through ye ol’ UHF backfeed, but the new HD box doesn’t allow that without an RF modulator.

What to do? Oh, well I do have an Xbox softmodded with XBMC downstairs. And I do have a Shuttle running Ubuntu with a Hauppauge PVR-150 TV card beside the Sky box upstairs. How abouts a little VLC streaming? 🙂

I’ve added the following line of code to my

/etc/rc.local

file on the Shuttle:

su [A NON-ROOT USER] -c "vlc pvr:// :pvr-device=/dev/video0 :pvr-norm=0 --sout '#standard{access=http,mux=ts,dst=[IP ADDRESS OF SHUTTLE]:8080}' --daemon"

Then, on my XBMC install, I have a file called

Sky.strm

which has this one simple line in it:

http://%5BIP ADDRESS OF SHUTTLE]:8080

and is sitting under the Playlists folder in the Videos directory of my UserData folder. When I go and select it, after a couple of seconds I get full MPEG-2 streaming across my network!

I can also access the stream from any VLC player on my other machines too.

Super sweet!

EDIT: After upgrading to 10.04, I inexplicably needed to add the line :pvr-channel=2 to make this pick up more than static.

Keyless SSH entry – Ubuntu, Windows and iPhone

A great feature of SSH is the ability to log in using public/private key encryption, rather than just simple passwords.

The way this works is that each server and client creates a public and a private key. Then, you copy the public key of the client you wish to authorise into the authorized_keys file of the server you are logging on to. When you attempt to log in, your SSH client will create a signature using your private key which the server will then decrypt using the public key and you’re in. 🙂 Easy. (More details here.)

Because your keys should be encrypted, this doesn’t remove the need to enter a password when you use the key. To do that, you need to use Paegant – a free accompaniment to Putty in Windows – which will ask for your passphrase once and then use it to open sessions to your heart’s content.

To get this working, you:

  1. Generate the key pair on the client using PuttyGen. Specify a decent passphrase for your private key.
  2. Copy the public key to the clipboard or export to a file
  3. On the server, for the user you are planning to log in as, go to ~/.ssh/ and edit the authorized_keys (or authorized_keys2) file
  4. Paste in the public key RSA string
  5. In Putty, for the server connection, add the username to the Connection > Data > Auto-login username field, and the path to the private key file Connection > SSH > Auth > Private key… field.

Done. 🙂

For the iPhone iSSH app, the app has a generate public key function. With that you can follow the same instructions to authorise the key and it will work from your iPhone as well. Sweet!

New year, new tech?

Just realised how long it has been since I last posted! A few things have changed in the technology landscape in my house – not least of which is my attempts to get an Asterisk-based PBX up and running.

I’ve bought a Linksys SPA3102 which bridges the POTS Telecom line onto my LAN. I did have it all up and running on a VirtualBox image on my Ubuntu 9.10 server, but then ran into timing issues.

So, I’m following these instructions again, and starting from scratch in the server proper. Wish me luck!