Uit Hack42
Ga naar: navigatie, zoeken
Project: SpaceStateSwitch
Schroefje24.png
Schroefje24.png
Schroefje24.png
Schroefje24.png
NoProjectPicture.jpg

SpaceStateSwitch

Naam SpaceStateSwitch
Door RickDeckardt
Status Afgerond
Madskillz madhacks
Doel / Omschrijving
A cool switch with rudimentary API and Twitter/IRC capabilities
Alle Projecten - Project Toevoegen

Add your picture plz.

Hardware

The SpaceStateSwitch is a DPST switch connected to the second ethernet port of a Soekris accesspoint. Closing the switch connects tx+/rx+ and tx-/rx-, causing eth1 to detect link up.

Software

The Access Point runs linux. Using cron the statecheck script is executed each minute; it uses ethtool to check for eth1 link up.

statecheck.sh script in pseudocode:

IF connection_state_eth1 eq connected AND laststate eq closed;
  curl http://user@pass:host/spacestate/setstate.php?state=open
  IF curl_success; set laststate open
 
IF connection_state_eth1 eq disconnected AND laststate eq open;
  curl http://user@pass:host/spacestate/setstate.php?state=closed
  IF curl_success; set laststate closed

rudimentary 'API' for external apps

Tweets

Twittering the status change to @hack42 is done using setstate.php on the external webserver. It also modifies http://hack42.nl/spacestate/index.html , a very bare page which can be quickly and easily accessed via almost any phone with internet capabilities.

Interface to IRC

irc://irc.hack42.nl/#hack42 runs a gozerbot with rss-feed plugin. One of the feeds is http;//twitter.com/hack42, which is checked every minute and echoed into the channel

XSS in your own webpage!

Paste this code in your webpage to show the hack42 spacestate-bar

<iframe width="390" height="50" scrolling="no" style="border: none;" src="https://hack42.nl/spacestate/"></iframe>

Growlnotifier by jvhaarst

cut and paste to hack42notify.sh

#!/bin/bash
# Scriptje om een Growl notify te krijgen bij openen (en sluiten) van de space
# jvhaarst, 13/2/2011 8h47
# Aangepast door Deckardt
# Aangepast jvhaarst 13/2/2011 15h03
# Aangepast jvhaarst 13/2/2011 21h20 (datum van statuswijziging toegevoegd)
# Aangepast jvhaarst 13/2/2011 21h50 (datum van statuswijziging uit state.time)
# Nodig:
# bash
# curl
# Growl (http://growl.info/)
# growlnotify (in extras directory van de Growl dmg)
# plaatje van https://hack42.nl/wiki/index.php/Huisstijl
# Start debugging from here
#set -o xtrace
#set -o verbose
# variabelen
DEBUG=false
OLDSTATE="closed"
IMAGE=~jvhaarst/bin/code/42/Hack42_white.png

# Oneindige loop, iedere 60 sec draait ie
while TRUE; do
	# check op state, ignore 404's, but returm error state
	CURRENTSTATE=`curl -f -s http://hack42.nl/spacestate/state`
	CURL_ERROR=$?
	# debug
	$DEBUG && echo $CURRENTSTATE

	# check op verandering
	if [[ "$CURRENTSTATE" != "$OLDSTATE" && $CURL_ERROR -eq 0 ]];then
		# Haal tijd van verandering op
		TIME=`curl -s http://hack42.nl/spacestate/state.time`
		# Growl de state !
		growlnotify -s -m "#42 is $CURRENTSTATE! ("$TIME")" --image $IMAGE
		# De huidige is de oude, zodat bij we een nieuwe state dat merken (lekker cryptisch, niet ?)
		OLDSTATE=$CURRENTSTATE
	fi
	sleep 60
done

The icon is here:

Hack42 white.png

Options

Connecting tx+/rx+ and tx-/rx- can also be done using a DPST relay. This can be controlled by a SPST switch, an access system, motion sensors or simply hooked up to the room lighting.