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.