Monday, October 24, 2011

So many things!

I did a lot last week.


The next version of the Kiosk code is up on my github now. I cleaned things up to the point where customizing it is easy thanks to configparser. Why have I never seen this library before?


Here's a sample configuration file.

# Kiosk Settings
# cycler settings...
[kiosk_cycler]

# location of where to toss things

file_location = /Users/fossrit/Desktop

# host to ping to test for a working internet connection
ping_host = www.google.com

# number of times to retry a connection. -1 for unending attempts
ping_counter = 3

# number of seconds to wait in between ping attempts
ping_timer = 30

# list of hosts for the feeds. Follows the format:
# host : /location
# candidate feeds are delimited by commas.
feed_hosts = foss.rit.edu : /files/bookmarks.rss, cs.rit.edu : /~ear7631/feed.rss



And here's the python code to parse it.


parser = SafeConfigParser()
parser.read('kiosk_config')
file_location = parser.get('kiosk_cycler', 'file_location')
ping_host = parser.get('kiosk_cycler', 'ping_host')

ping_counter = int(parser.get('kiosk_cycler', 'ping_counter'))

ping_timer = int(parser.get('kiosk_cycler', 'ping_timer'))
feed_hosts_dirty = parser.get('kiosk_cycler', 'feed_hosts')


Easy, isn't it? I was also messing around with wxWoof, too, and finally got around to tinkering with wxPython a bit more. You can look at the full code here, but I really just wanted to share how easy adding drag-and-drop functionality is. My goal was to make a button that, not only brought up a file selection if clicked, but had file recognized drag-and-drop implemented as well. All that really needs to be done is hook up a FileDropTarget to your container, which handles the magic.
self.boxButton.SetDropTarget(self.dropTarget) self.dropTarget = FileDropTarget(self.boxButton)

After that it's just a matter of hooking up the OnDropFiles function your FileDropTarget.


I've now started working with html5 forms, jquery, and the twisted web framework, so there will be posts on my experiences with these in the coming days.


Monday, October 10, 2011

Making a Simple Kiosk - Part II

The Kiosk has come a long way. A few hours of sanding, some clean up, a lot of rust removal, primer, a coat of black paint, some adventurous logo painting (which didn't work out), stencils, and posters later, I give you, the completed project. Minus a lock. Ours was too short.

Here's the front.
And the side.
Don't forget the guts.

Wednesday, October 5, 2011

Making a simple Kiosk

Today, a very different sort of project managed to find its way to me. I've been tasked with building a kiosk out of this, this, and last but not least, this. It's a pretty cool idea - make the mini run, mount the monitor, cover it with plexiglass, sand the box, and give it a nice new coat of paint. My parents had always made sure that power tools were more than an arm's length from me at all times, so I've grown up with zero experience in that realm. Needless to say, I started with the mac.

The box needed to do only one task: start up, open a browser, cycle through links. Perfect job for applescript. The script to launch a browser and loop through links is simple:



#!/usr/bin/osascript



-- argv is a list of links to loop through

on run argv
  tell application "Opera.app" to activate
    
    tell application "System Events"
      tell process "Opera"
        click menu item "New Window" of menu "File" of menu bar 1
      end tell
    end tell

    -- list of urls to cycle
    repeat

      repeat with someurl in argv
        tell application "System Events" to set browserRunning to (name of processes) contains "Opera"
        if browserRunning then
        else
          exit repeat
        end if
        
        tell application "Opera.app"
          set URL of document 1 to someurl
          delay 5
        end tell
      end repeat

      tell application "System Events" to set browserRunning to (name of processes) contains "Opera"
      if browserRunning then
      else
        exit repeat
      end if

    end repeat

end run



I made a python script that does everything else. Grabs a list of links from a feed, passes them over to the cycler:

#!/usr/bin/env python

import feedparser
import os
from subprocess import call


# this actually parses the feed as if it uses the firefox live bookmarks format
# your parsing may change on how your links are represented

applecmd = []
applecmd.append("osascript")
applecmd.append("kioskcycle.scpt")
d = feedparser.parse("http://myhost.com/somefeed.rss")
bookmarkitems = d['items']
for item in bookmarkitems:
for link in item.links:
applecmd.append(link.href)


os.chdir("/Users/someuser/Desktop")
call(applecmd)


And got it all working by turning my python script into a natively built python applet, and telling OSX to use it as a startup item. All pretty straight forward, under normal circumstances. Of course, my script initially used Safari, but things can never be that simple. RIT is its own Certification Authority, and Safari thinks some of RIT's sites (ie, my.rit.edu) are traps. Even if you forcefully allow the certificate to pass, Safari will warn you. This got on my nerves, so I went looking for another browser. Firefox dropped support for PPC a long time ago. Chrome never had it. TenFourFox, as nice as that is, doesn't work with applescript. I decided to settle on Opera 10, the last Opera release to work with PPC. It also gained Applescript support since 9.5. Nice.

I've got some major sanding, painting, drilling, and polishing to do tomorrow, so I'll be sure to post a picture of the final product of my labor. Mmmmm... power tools.

Monday, October 3, 2011

Combating selinux for the timeline

That timeline that was being worked on ended up being hosted on foss.rit.edu, but getting it there took  nothing less than an arduous battle with selinux. I first created an alias so that I could put all my work in a single directory on a separate user account on the box, and tossed it into the right /etc/httpd/conf.d/ configuration file.



Alias /timeline "/home/myusraccount/timeline"

AllowOverride All
Options Indexes
order allow,deny
Allow from all



Any work from here on out could be tossed in /home/myusraccount/timeline/. While this is convenient, this posed a slight problem. The form I had created to give me an easy way to add events to my timeline posts its information to be handled by my python cgi script. This script gets effectively run as the "apache" user, and selinux has a slight problem allowing the apache user modify files inside /home/myusraccount/timeline.

First I changed the owner of the relevant file and the timeline directory file to the apache user. No luck.

I then tried to add apache and myusraccount to the same group, giving the group full permissions of the file and directory being touched by the cgi script. No luck.

For random kicks, I turned off selinux. That did the trick. Turning it back on, I tried to change the context of the files and directories myself, but couldn't get anything to work for the life of me. My mentors in the fossbox showed me a nifty tool, audit2allow, which allows users to generate allow rulesets for specific operations. This tool parses the logs for denied permissions messages, and can automatically generate exceptions to them. Basically do what you want to do, watch it fail, run audit2allow, and apply a rule. Of course, you'll want to be careful with the rule you do apply, since selinux could very well be protecting your machine from a big security risk.

Tuesday, September 27, 2011

RIT Remix Hosting and Interactive Timeline

The spin remix is now hosted. Thank you Ralph Bean for tossing that up! I hope that I'll have a chance to tinker with it in the future and make some improvements to it later. For now, there's a different task at hand.

One of the key things that is missing from the FOSS Box @ RIT is a slick timeline that can show the world what we've been up to - something that's polished and comprehensive. Remy Decausemaker's forked version of MIT's Simile Exhibit project fit the bill perfectly. The project uses a whole bunch of javascript magic to render its visuals, but at its source, generates its content from a single contributors file.

Adding entries to the timeline is trivial. It's just a matter of going from this and this to a series of formatted entries:


{    "type" :                  "Event",
     "label" :                 "ImagineRIT 2010",
     "discipline" :            "Event",
     "date" :                  "2010-05-01",
     "relationship" :          "Event",
     "relationship-detail" :   "ImagineRIT 2010",
     "imageURL" :              "Event.png",
     "url" :                   "http://www.rit.edu/imagine/"
},

Not a difficult process, but a time-consuming one. One that I'm not so willing to do in the future, so I decided to create a pretty simply html form that would let me enter entires. The form is simple HTML and creates a little something like this. After creating the form, I whipped up a simple CGI script in python, which has a module that makes form handling easy. Lastly, this form launches a simple script that appends entries to the contributor.js file.

This should save a lot of hassle in the future. Of course, I wasn't able to host this simple web service on my CS webspace, given the restricted permissions that disallowed me to create any sort of .htaccess file without a headache. Gives me a good opportunity to check out openshift which has been getting a lot of buzz lately.

Tuesday, September 20, 2011

wxWoof

Rochester's getting colder. Autumn is here. I like that.

This past Saturday was the big Software Freedom event. I had a few people ask me about the spin, grab copies, so I pointed them to the public repo and showed them what went on in creating it (my previous post was editing for some more details regarding the process). It was good fun. And so was the hackathon. I didn't really go in with any particular project in mind, so I decided to get started on working on something that I've been meaning to work on for quite some time.

Ever hear of woof?

It's a nifty python (2.7) script that turns your computer into a single-file distribution server. Or, should you want, archive directories for you, and host the archive. It's pretty simple, but really useful. Need to toss a file over on your other box, and don't have a USB drive with you? No problem, just run the script on the file. By default, the script hosts it on port 8080. All you need to do to grab the file is open up your browser of choice, and connect at the host's ip (displayed if you don't know off hand), and selected port. Easy. (If you want -really- impressive speeds, try sharing a network connection from the host, and connecting the two via ethernet. That's some nice file transfer speeds.)

Some of my friends saw me using it, and really loved the script, but aren't familiar with the command line at all, or even the concept of a directory path. The script could also use a little python 3 makeover. So, I took the opportunity to start looking into some gui libraries to put a simple front-end on the script.

There were a few options. If you can recall, I already messed around with pygtk2, which was very simple and powerful. It is, however, getting it to work in OSX 10.5 and later is annoying. I then looked into something more current and robust, and stumbled upon PyQt, based on the mammoth Qt framework by Nokia. In the end I decided to just use the tried and true wxPython libraries.

This wasn't without it's issues, either, though, as wxPython hasn't been updated to work properly with Python 64 bit installs. I actually had to create a little launcher that appropriately ran my ui correctly. This was accomplished by using the following script:

#! /usr/bin/env python

import subprocess

subprocess.call(["arch", "-i386", "python", "window.py"])



You can check out my very simple gui at the public repo if you're interested. Right now, I got something that works, but I'll continue to add to and improve the UI (as well as clean up the script) over time and post more about it in the near future. Chances are I'll take a look at wxDesigner and wxGlade.

Wednesday, September 14, 2011

Creating a Fedora RIT Spin

The full process.

Up until now, I've only given snippets of the steps it took to create an RIT Live CD Spin of Fedora 15, so this time I'll detail every step (and issue) I took along the way, along with some of the issues I ran into. To start, there are Live CD creation tools provided to you for creating Fedora Live CDs that are pretty much automated, but setting up the configuration of the Live CD is what can be tricky. Before we can really begin, we need to install the tools needed for creating our spin. You can get these tools by grabbing the following packages.

sudo yum -y install spin-kickstarts livecd-tools


Next, we need our own kickstart file. We can start with a basic kickstart file as shown below.

%include /usr/share/spin-kickstarts/fedora-live-desktop.ks
%include /usr/share/spin-kickstarts/fedora-live-minimization.ks

%packages
%end

%post
%end



This is pretty much the most basic of kickstart files that can be used. These kickstart files effectively define how the Live CD will be created, and are the tool you use for customizing your spin. First, the %include statement is used to pull in other made kickstart files. A basic spin can get nearly all of the groundwork done by just pulling in the two kickstart files shown above, provided that you don't mind the default Live CD environment.

The next step is defining the applications you want in your spin. Add every desired package in the %packages section. For example, no RIT student can live without emacs and pidgin, so I'll toss those packages in.

%packages
emacs
pidgin
%end


Because the creation process creates a filesystem to be put on a non-rewritable media, it's important to get all your customization done in the kickstart file. There is a useful area of the file, the %post section, that allows you to run commands to customize the environment before the creation process runs mksquashfs to make things final, stuffing it all into a nice iso package. For the RIT spin, we wanted a few little features, such as having default RIT bookmarks for Firefox, and some nice RIT default wallpaper.

To tackle the bookmarks, I had to poke around a bit at the guts of Firefox 6 to see how bookmarks are stored. When firefox runs, it creates a default profile for the user, and stores bookmarks in an sqlite database. While it would have been easy to set some bookmarks, and just copy the .sqlite file for later use, I noticed that Firefox computes a random hash for the user profile folder, making it pretty much impossible to be able to predict the folder of the default profile for any given user. I then looked into how these .sqlite databases are being generated.

Firefox 6 contains an archive called omni.jar, located in /usr/lib/firefox-6 that effectively has a bookmarks.html file inside, defining the bookmarks hierarchy that is used to generate the inital sqlite database for each profile. In order to change this, it is necessary to unzip the archive, swap in the bookmarks.html file (here's mine), and finally zip it back up. To do this I put my own script into the %post section of the kickstart file. The script I use to do this can be found here.

Lastly, I had to change the default wallpaper for the spin. The first step to getting this to work was to get the wallpapers on the newly created filesystem (before mksquashfs runs) to be used. While it's possible to create your own package to include, I decided it might be easier to just look for a swapping command. Because Fedora 15 runs gnome3, it was tempting to use the gsettings command to set the background, but this won't do anything. (One approach that may work is creating a startup script to do just that, but gsettings cannot be run without the user being logged in and gnome initialized. Therefore, it won't work in the %post section of the kickstart file.)

Instead, I decided to write a script that safely tuck away the default Fedora 15 backgrounds (there are three versions of it), and swap in my own wallpapers for them. It's a bit hackish, but at least the wallpaper will appear on the the default startup, and this way, I don't have to create a whole new package and tinker with the various .xml configuration files to change the default location. Note that wget is necessary to add as a package to grab the files that I had hosted (probably the easiest way to pull in file needed by the %post scripts). Furthermore, livecd users are not added to the sudoers file, so it's easiest just to run a su -c "command" to get the job done, as the background folder contents does require root permissions to alter.

Something to note as well is that Fedora 15 has 3 default wallpapers, each with different resolutions that reside in their own folders. It's a good idea to do the same with your own.

A last feature I wished to add to the spin is a prompt to ask if the user would like to run the live cd with RPM Fusion enabled. Obviously, much of the software out there that provides a user with a normal experience is proprietary, and won't be put on the spin by default. Instead, the user should have the ability to quickly fetch and enable these packages.

I created a simple pygtk2 launcher that runs a simple fetch script for RPM Fusion (Note, the prior is a python script, and the latter is a fetch script, so simply rename the extension if you pull them from my public webspace). Adding scripts to the startup routine is trivial... if you have access to the gsettings command. My first approach was to add my script to init.d, but this approach will not work. A second approach I took was to attempt to pull a customized bash_profile which launches the prompt on login, and tosses it into the user folder. However, this will not work either, because the liveusr profile will not be created at the time of %post, and therefore, it is not possible to modify its bash_profile. This feature will require a little more exploration.

Given more time for refinement, a better approach would be to make a proper package for the wallpapers, but if you have to get it done quickly (and with the long creation process), this quick-and-dirty method should get things set just fine. Overall, however, the process is fairly straight forward, and most of the difficulties come from the fact that you don't have too much wiggle room on the temporary filesystem customization.

The final kickstart file I use for the RIT spin can be found here. If you wish to contribute to the spin project, or make your own based on what I have, feel free to fork the public repo.