# Simple web interface for tellstickController # jonelf¤gmail.com 2008-10-16 # Ruby require 'cgi' require 'open-uri' require 'rubygems' cgi = CGI.new app = "/usr/local/bin/tellstickcontroller/tellstickController" scriptname = $0.split('/')[-1] print "Content-type: text/html; charset=utf-8\r\n\r\n" print '' print "" print '' print "" print '' devices=%x[#{app} -l].gsub!("Device ","").split("\n") dev=cgi['device'] status=cgi['set'] if (devices.include? dev + " = " + (status=="on" ? "off" : "on")) && (status=="on" || status=="off") then %x[#{app} -s #{dev} #{status}] end devices.each {|device| a=device.split() status = a[2] if dev==a[0] then newstatus = status status = status=="on" ? "off" : "on" else newstatus = status=="on" ? "off" : "on" end link='' + '' + '' + a[0] + '
' print link } print "\r\n"