Posts Tagged: Technology


13
May 10

Telling Students Linux != Windows with pyinotify and pynotify

While doing pro bono Ubuntu system administration for a local private school, something that has always annoyed me is that students frequently download installer files for Windows programs (games, iTunes etc). The computers obviously don’t look like they run Windows, and they’ve been told on many occasions that Linux != Windows. So today, I decided to automate this explanation:

#!/usr/bin/python
 
import pyinotify, pynotify
from subprocess import Popen
from os.path import expanduser
 
pynotify.init('Windows program notifier') # Not sure what this does
 
PATH = expanduser('~')
NAUGHTY_EXTENSIONS = ['exe','bat', 'com', 'dll', 'msi', 'ocx', 'reg', 'scr']
MESSAGE = "You just tried to download a Windows program. This is Linux. Bugger off!"
 
def notifyAndDelete(path, showNotification):
    """Delete any file with the forbben extensions."""
    if path.split('.')[-1].lower() in NAUGHTY_EXTENSIONS:
        print 'Deleting ' + path
        Popen(['rm', path])
        if showNotification == True:
            n = pynotify.Notification("Windows Program Fail", MESSAGE)
            n.show()
 
class HandleEvents(pyinotify.ProcessEvent):
    def process_IN_CREATE(self, event):
        notifyAndDelete(event.pathname, True)
    def process_IN_MOVED_TO(self, event):
        notifyAndDelete(event.pathname, False)
 
if __name__ == '__main__':
    wm = pyinotify.WatchManager()  # Watch Manager
    mask = pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO  # watched events
 
    p = HandleEvents()
    notifier = pyinotify.Notifier(wm, p)
    wdd = wm.add_watch(PATH, mask, rec=True)
 
    notifier.loop()

When a user tries to download a program with an extension found in NAUGHTY_EXTENSIONS, They will get a Notify OSD popup informing them that they are not using Windows, and Windows programs won’t work on school computers. Of course, when I go to deploy this code, MESSAGE will be a little more appropriately worded.

This program is a combination of code I found from this pyinotify tutorial and a Notify OSD snippet I found in Acire.

Edit June 8 2010

Thanks to the anonymous commenter that pointed out the bug that allowed arbitrary code execution, and to Michael Hall for explaining it in more detail. The problem has been fixed.


24
Apr 10

Changing Plymouth Themes In Ubuntu 10.04

One of the major changes in Ubuntu 10.04 is that Plymouth is now managing the fancy boot graphics, instead of xsplash. While the default Plymouth theme is decent, I wanted something different. Fortunately, changing the Plymouth theme only takes a few lines on the CLI.

If you run apt-cache search plymouth-theme, you’ll see which themes are available in the default repositories. This Youtube search has some videos of what is available. I chose the plymouth-theme-solar package, which has a nice solar flare animation. Next, run the following code, which I found here. Keep in mind that you need to change it to point to the plymouth theme you want to use.

sudo update-alternatives --install \
/lib/plymouth/themes/default.plymouth default.plymouth \
/lib/plymouth/themes/solar/solar.plymouth 100

(note: Line warping was only used to make it look pretty on a blog post.)

Next run sudo update-alternatives –config default.plymouth. You’ll see a numbered menu of the themes currently installed. Type the number for the one you want and hit enter. Finally, use sudo update-initramfs -u to apply your changes.

Here is the result:

There are not many themes available currently. However, once 10.04 is released and has been out for a little while, I think there will be many more options.


12
Apr 10

Creating DIY mobile reception with Google Voice and VOIP

Like many people in the USA who live in rural communities, I have no cellular reception at home. My mobile provider, T-Mobile, does not have enough economic incentive to build a tower close to my home. Also, they have not yet seen fit to give me the privilege of paying to compensate for their lack of service via a Femtocell.

Fortunately I have found a solution: Google Voice + Gizmo5 + Sipdroid. Google Voice is a free service which lets it’s users unify all their phones under one number. Simply give friends, family and coworkers that one number, and calls will ring through to whatever phones the user chooses, based upon rules they define. Gizmo5 is a SIP provider that can connect to Google Voice and allow users to make phone calls over the Internet. Gizmo5 has been bought by Google, so registration is currently closed. However, everyone expects that it will eventually be integrated with Google Voice. Finally, Sipdroid is a nice, Open Source SIP client for Android that can connect to services like Gizmo5.

I’ve played with this combination before, when I was using a G1 Android phone from HTC. The reasons I did not stick with it then were because the G1′s battery life was pretty bad, and the G1 struggled enough with performance that it was not feasible to keep Sipdroid running in the background.

Now that I have the amazing Nexus One though, all this has changed. The battery life on the N1 is pretty good by smart phone standards, and it’s performance is high enough that I can easily run Sipdroid in the background all the time without any noticeable performance impact.

I’m using my home WiFi for Sipdroid. I have always been told that WiFi eats battery life rather quickly. However, I’ve been surprised at how much this has not been the case. After a full day of being connected to wireless almost all the time, WiFi only used up about 2% of my phone’s battery (this is with moderate use of the connection). I’ve come to the conclusion that simply having wireless connected does not use much power, but actually transferring data does.

This solution has been working great, but has not been completely without problems. When I receive calls, both parties (the person I talk with and I) have excellent sound quality. However, when I initiate the call via my phone, the person on the receiving end gets tons of latency and a lot of static. I have worked around this issue by initiating the calls via the Google Voice web interface. This hack is slightly annoying, but it is not too bad since I almost always have my laptop on.

After a few days of use, I am quite happy with this solution, and am looking forward to hopefully seeing VOIP kill off traditional telephone providers in the future. AT&T, T-Mobile and others should be very afraid, especially if municipal WiFi becomes more common.


2
Feb 10

WordPress for Android

WordPress for Android just released 1.0. This is a test post, but so far it is quite nice! You can download it here.


4
Jan 10

Using x2x on Linux for KVM like goodness

Recently I purchased one of those little “nettop” computers to plug into my HDTV and act as my multimedia center (more on that when it arrives). I also purchased a IR remote, but I wanted a way to be able to use a keyboard and mouse on it as well, as it is more than just a movie player. However, I didn’t want a physical keyboard/mouse, as that would look out of place.

After reading up on the subject, I decided to give Synergy a try. Synergy lets you use use your keyboard and mouse on another computer over a network, just as if it was a second screen attached. Synergy looked promising, but several things about it did not work out for me.

Being a network application, Synergy consists of both a client app and a server app. It turns out that with Synergy the “server” is the computer with the keyboard and mouse you want to use on multiple machines. I’m sure this works fine for most people, but it does not make sense for my multimedia system. This computer will be on most of the time, being controlled by several different machines For my setup, the logical place for the “server” would be the multimedia system. I probably could have hacked it to make the client (running on my server) act more like a server, except each time the client app fails to connect to the server (running on my laptops), the time it waits for another connection increments.

When looking for Synergy alternatives, I found x2x. x2x is only designed for Linux, so it would not be usable for someone who needs to use a keyboard and mouse on multiple operating systems. I only use Ubuntu Linux at home, so this was not a problem for me. An advantage of x2x is that setup is very simple. First, install the x2x package (“x2x” in Ubuntu) on both machines, and openssh-server on the computer you want to control remotely. Then, from the computer with the keyboard and mouse you want to use on another system, run:

ssh -X user@server x2x -south -to :0

With this, you can now move your cursor beyond the bottom of your screen, onto the remote system. If you want to use a different edge of your screen, replace -south with -north, -east or -west. If you have key based authentication set up for ssh, you could stick this into the applications menu.

Updated 08 January 2010

It seems there is a bit of an issue with x2x in Ubuntu 9.10. Some people are seeing the following error when they try to run x2x:

No protocol specified
x2x - error: can not open display :0

To work around this issue until it is fixed, SSH into the box you want to remotely control, then run the following command:

xauth merge /var/run/gdm/auth-for-$USER-*/database

AWSOM Powered