Why I love HTTP
posted 2010-04-25 13:01:16, link to this article
A few years ago, I worked at a company whose webservers were hosted at
a dedicated web-hosting company.
The question rose whether their website could be reached at foo.bar as well as at www.foo.bar.
Well, no problem you'd say, nothing that a simple A or CNAME record in DNS couldn't fix.
Not so, foo.bar had an A record assigned already for a host in the company's DMZ that used to do a *lot* of stuff.
You can imagine adding a webserver to foo.bar, just to serve 301 moved permanently status codes seemed like a bit of overkill to me.
And apart from that, I was too lazy to have another $many_lines_of_code to keep up to date for such a trivial task.
Thanks to the wonders of HTTP the solution was almost as simple as the problem.
I whipped up a small text file containing a static HTTP 301, and used the almighty inetd and cat to glue this to a socket.
It worked like a charm. It was also great to see sites like Netcraft list the webserver of foo.bar as cat/0.9. :-)
I thought of this today, when I was playing a bit with my Nintendo DS running DSLinux.
I could find various MP3 decoders, but nothing to do streaming. So I kludged together the other side of the hack that I explained above:
#!/bin/sh
(nc mp3.streampower.be 80 <<_GETREQ
GET /stubru-low.mp3 HTTP/1.0
_GETREQ
) | sed -n '/^$/,$p' |\
madplay -
Et voila. Streaming audio. (In this case the Belgian music station Studio Brussel.)
Thank you, sir Tim.
Sitecom WL-340 shell commands via HTTP
posted 2010-04-18 16:40:26, link to this article
My local Media Markt (a large German chain of electronics stores) had some cheap NAT routers for sale. Out of curiosity I bought one.
This router (the Sitecom WL-340) runs Linux and the internal console port is nicely labeled and that alone made me buy two more as you can never have too much hardware to play with. ;)
When poking around in these boxes I found that they have a nice hidden web page to run commands on these boxes.
You can access this page as /system_command.htm on your routers webinterface.
I thought it might be useful to access this command shell from scripts, so that you can use stock WL-340s for various "unintended" purposes. ;)
With the help of the amazing Firebug extension for Firefox I managed to use the remote command facility of these routers from the shell.
Like so:
hessch@kirchhoff:~$ curl -s -o- -u admin -d command='cat /proc/cpuinfo' \
-d next_file=system_command.htm -d todo=system_command \
http://192.168.11.128:8080/setup.cgi | \
sed -n '/outlog_Display/,/\/textarea/{/textarea/d;p}'
Enter host password for user 'admin':
system type : Ralink SoC
processor : 0
cpu model : MIPS 24K V4.12
BogoMIPS : 212.99
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes
ASEs implemented : mips16 dsp
VCED exceptions : not available
VCEI exceptions : not available
Now, this only needs a small wrapper shell script and it's ready for (ab)use.
I'll probably post some more hacks based on these boxes later on.
Fix for Thinkpad T400 WWAN on Ubuntu 9.10
posted 2010-02-25 19:51:08, link to this article
The builtin WWAN modem of Lenovo ThinkPad T400 laptops does not seem to wake properly when the laptop is suspended on Ubuntu.
I have written a small Power Manager script to fix this problem, it seems that Ubuntu 9.10 (Karmic Koala) does not support wakeup scripts in /etc/acpi/resume.d anymore.
Although it tires me a bit how much Ubuntu seems to break in new releases lately, it was worthwhile to search for the mechanism "du jour".
It seems that scripts need to be placed in /etc/pm/sleep.d nowadays.
Add the script below to a new file, /etc/pm/sleep.d/10_thinkpad_wwan, and it should be called upon suspend and resume to revive your modem on resume.
#!/bin/sh
# Action script to reinitialize built-in WWAN of Lenovo ThinkPads
# on resume
#
# Hessel Schut, hessel@isquared.nl, 2010-02-25
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin
case "${1}" in
hibernate)
# unload cdc_wdm module
rmmod cdc_wdm
;;
resume|thaw)
# revive RF and reload cdc_wdm module
echo 1 > /sys/devices/platform/thinkpad_acpi/rfkill/rfkill1/state
modprobe cdc_wdm
;;
esac
New version of Squa.sh
posted 2009-04-20 22:57:28, link to this article
I've made some changes to squa.sh, my Bash script Pong clone.
The first version made extensivce use of tput(1) to update
the terminal cursor position.
I compared the resulting control sequences sent to various terminal
versions, and all seemed to be in the format:
^[${row};${column}H
Therefore this new version uses pre cooked control sequences instead of forking tput like mad. dd(1) is still spawned each iteration of the main loop to capture user input, read(1) smallest timeout is 1 second, so this is no option, or the game would be no much fun. ;)
Also terminal size detection is fixed for NetBSD now, which means that the new version of squa.sh runs on all hardware in my house right now!
You can grab a copy of the new version at http://isquared.nl/src/squa.sh-ng/squa.sh.
squa.sh
posted 2009-04-19 19:37:58,
link to this article
Read full article
Squa.sh is a litte squash game in a Bash shell script that I wrote this evening.
Follow the read link for more information or you can download the complete script from here.
isquared.nl rss (atom)