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.


19
Apr 10

The Practicality Of Freedom

The various philosophies behind how software is developed is a popular topic among geeks. However, the vast majority of non-geeks have absolutely no interest in the topic, if they have even heard of the issue at all. I think that the reason for this is that these users see no practical connection between these issues and their daily life. However, there certainly is a practical connection, even if most people never think of it in these terms. The goal of this post is to use a less technical analogy to illustrate why ordinary computer users should care about these issues.

Comparing computer software to cars

Most people own and operate their own car. Even if they are not mechanics, car owners understand the advantage of being able to decide who is allowed to repair or modify their vehicle. This analogy will use three different types of cars (two of which are thankfully fictional) to illustrate the types of software users can have on their own computer.

The normal, open car

The first kind of car is the type that exists today. When someone buys a car, the car comes with a hood that can be easily opened. The technically savvy owner can save lots of money by performing routine maintenance and repairs themselves. When they open the hood, they find an easily accessible engine, with parts (more or less) that are easy to reach. These parts usually follow certain types of standards, so they can often be replaced by parts from other manufacturers.

A vehicle owner benefits from owning this type of car, even if they don’t know enough to change their own oil, much less replace an engine. Since the inner workings of this car are accessible, there is a thriving market of mechanics, from mechanically savvy family members to professional operations, who compete on price to make repairs.

The car with a secret engine

Now imagine a new type of car. This car has a hood that can be opened, but it cannot be opened by the owner or a person of their choosing. A key is required to open this hood, and the only person with the key is the company that sold the car. They are the only company with permission to work on that engine. Of course, all locks can be picked with enough effort. If the user were to pick the lock on this hood, they would find an engine that is incredibly difficult to work with for anyone without special knowledge (the original manufacturer). Few of the parts are standardized and interchangeable, and all of the parts are placed in positions that make them hard to access.

There might still be third parties that actually work on this kind of car. Routine maintenance and repairs would be more costly, both because of the added effort it takes to work on the engine and because of the lack of people capable or willing to work on it. Many repairs would be impossible for anyone but the original manufacturer. This manufacturer would have close to a de facto monopoly on the vehicle’s maintenance, therefore driving up costs.

The car controlled by the manufacturer

The third kind of car looks a lot like the previous kind with the locked hood, but takes it to it’s logical conclusion. This car has technology designed to try to detect if it’s owner has tampered with the lock. If the car detects any unauthorized tampering, it destroys the engine. Furthermore, if the manufacturer discovers a mechanic telling others how to pick the lock without the car noticing, the manufacturer takes that mechanic to court. Lastly, this car will only drive to business and restaurants that it’s manufacturer puts on the approved list. If the “owner” of this car wants to go somewhere not on the list, they must ether borrow a friend’s car, or pick the lock and hope that their car does not self destruct. Fans and owners of this type of car defend these restrictions by saying that the establishments on the approved list are really high quality places, and that the restrictions are for the driver’s safety. In the end however, the only logical conclusion is that the restrictions are there to protect the manufacturer’s business model by preventing a truly free market.

The different types of software

Thankfully the second two types of cars do not exist today. Unfortunately, something similar does exist in the world of computer software, and most customers do not know that they are being effected by it.

The normal and open car, the one with the open and accessible engine, is similar to a type of software known by the names Open Source and Free Software (think free as in freedom, not free as in without price). Open Source software is created both by large companies such as IBM and individual enthusiasts working in their spare time. This software gives users the freedom to use the software however they want, to understand how it works, to make any changes they want and to share those changes with anyone. Users with knowledge of computer programing can fix any bugs they want or add any features they want, just like mechanics can with cars. Users who are not technologically savvy can pay the original developer for support and maintenance, or can pay anyone else who offers a competing price.

The car with the secret engine is very similar to the commonly used operating systems Windows and OSX. The inner workings of those systems are secrets, and while third parties have been able to figure out how to fix many smaller problems, only their creators can make more substantial changes.

The car controlled by the manfacturer represents a disturbing new trend in computer software. With the Apple iPhone, and now the iPad, not only are the “owners” not allowed to know how these computers work, but if you try to tamper with them and don’t do it correctly, your device will be “bricked,” and become the world’s most expensive paperweight. “Why would I want to mess with a device that works so well” many people ask. As with the third car in the analogy, there are things the user is not allowed to do with an iPhone or iPad. They can only install applications on Apple’s approved list, and many wonderful and innovative applications are forbidden. Also, Apple does it’s best to use the legal system to prevent others from learning how to gain control over their devices.

Many “owners” of the iPhone and iPad argue that it does not matter, as they can “jailbreak” their devices, aka gain access to forbidden apps. However, as explained above, these restrictions still have a very practical effect on the people who posses these devices. Also, if the person who sold the user the phone has more control over it than the user themselves, who truly owns the device in the first place?

Another objection that many owners of these devices use is that it is “just a phone” or “just a tablet,” and so the existence of these restrictions are not important. Is this really the case? The new iPad has a processor, storage and memory, just like any other computer does. It is also much more capable than my first computer was. Finally, what do users use it for? They watch movies and videos, listen to music, read articles and books, browse the web, communicate via email and instant message and use social media. That is the majority of things that most people use their traditional computers for. First these restrictions were on a phone. With the introduction of the iPad, which was advertised as something being “somewhere in between a smartphone and a laptop,” it has moved closer to what people traditionally think of as a computer. The App Store has proven to be a very popular and successful way for people to discover new apps. The logical conclusion is to use a similar model on Apple desktops and laptops, and of course Microsoft will try to compete with a similar system inside Windows. What sort of restrictions on our personal computers will then be demanded, in the name of copyright protection and quality assurance?

Closing thoughts: What about free speech?

So far this post has discussed the practical implications that these types of control have on the users of computer software. However, the discussion would not be complete without mentioning the free speech implications of this type of technology. Computers and the Internet are now the primary way people express their thoughts and opinions. We have already seen that Apple is willing to censor free speech on the iPhone. Last December, Apple decided to reject an application from Pulitzer prize winning political cartoonist Mark Fiore, because Apple deemed some of his work was not politically correct. Apple relented after it’s decision turned into a PR nightmare, but most publishers do not have enough notoriety to cause that kind of reaction.

I’m not saying that Apple is the corporate equivalent to Hitler or Stalin. However, large companies are very susceptible to pressure from national governments. Imagine if the iPad had been the primary communication platform in Iran during it’s recent election and subsequent protests and oppression. Would people outside of Iran have even heard about it?

Control used for the best of intentions can also be used for the worst of intentions.


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.