Virtual servers have become quite cheap these days, to the point where I can justify paying the monthly charge on one when I’m not sure how much I’ll use it.
One of the things I have been running on my VM is a TCP-over-DNS server; it will allow you access to the Internet through some access points where you’re forced to login, though it relies on the network administrator neglecting to block certain types of DNS query. The author has posted a good how-to and overview of how it works so I’m not going to go into that here.
Now, I don’t anticipate using this tunneller very often so it’d be nice to not run the daemon all the time, but I obviously can’t enable myself unless I know in advance that I won’t have Internet access. Therefore, ideally I want the server to run only when I want to use it. Fortunately Linux has long had a means of doing this with the inetd daemon.
The inetd daemon will monitor a network socket, waiting for incoming traffic, and launch your daemon only when it is needed. It then passes the daemon process the existing sockets and waits for it to finish, at which point it’ll go back to watching for traffic again.
The config line you’ll need for inetd is as follows (you may need to highlight it and copy it elsewhere, as it doesn’t show up well in this theme):
domain dgram udp wait root /usr/bin/java java -jar /path/to/tcp-over-dns-server.jar --domain delegated.domain.com --forward-port 22 --forward-address 127.0.0.1 --mtu 1500 --log-level 1 --idle-timeout 10 --log-file /var/log/tcp-over-dns
Aside from modifying the server to support inherited channels I have:
- Added an idle time limit (so the program can exit if it sees no clients after a set number of seconds, and let inetd monitor the port again)
- Added a log file option (programs launched by inetd can’t log to the standard output or error channels as inetd will pipe them into the inherited connection.)
- Changed the default behaviour (If a channel is inherited the server will no longer try to bind on its default port)
If you’re interested you can download the source code or just the pre-compiled jar file.
Posted: August 28th, 2010
Categories:
Linux
Tags:
Java,
Linux,
Networking
Comments:
No Comments.
The other day I was looking into a problem someone was reporting with an Apache RewriteRule, only to conclude that it was using features of the Regex library which weren’t available in their version of Apache.
I found a means of detecting the different versions of Apache using the mod_version module. This allows you to write htaccess files which can fall back to other rules for older versions of Apache.
Unfortunately it’s only been available since version 2.0.56, but given that this was before the first release of version 2 it’s fairly safe to assume that anything without mod_version will be running Apache 1.
I will concede that this sounds very obvious, but there was a surprising lack of results in google for any of the keywords that I thought to try. For the benefit of anyone searching for this; below is an example of how you can use mod_version in practice:
<IfModule !mod_version.c>
# Earlier than version 2.0.56, so almost certainly 1.x
# as 2.0.63 was the first release of version 2.
</IfModule>
<IfModule mod_version.c>
# Version 2.0.56 or later
<IfVersion < 2.2>
# Before version 2.2
</IfVersion>
<IfVersion >= 2.2>
# Version 2.2 or later
</IfVersion>
</IfModule>
Posted: June 3rd, 2010
Categories:
Programming,
World Wide Web
Tags:
.htaccess,
Apache,
Web
Comments:
No Comments.
With some pointers from friends I’ve beaten applescript into submission and coded up a script to automate the bluetooth iSync syncing with my phone.
The script opens up System Preferences and enables Bluetooth, then launches iSync and instructs it to sync. It will then leave Bluetooth in the state that it found it in.
The code is below for anyone who might find it handy :) Oh and for the record this is written to run on Mac OS X Leopard.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
| display dialog "Sync?" buttons {"Ok", "Cancel"} default button 2
if the button returned of the result is "Cancel" then
stop
end if
tell application "System Preferences"
activate
set current pane to pane "com.apple.preferences.Bluetooth"
tell application "System Events" to tell window "Bluetooth" of process "System Preferences"
set was_on to the value of checkbox "On"
if value of checkbox "On" is equal to 0 then
tell checkbox "On" to click
end if
end tell
end tell
tell application "iSync"
synchronize
repeat while (syncing is true)
delay 5
end repeat
set syncStatus to sync status
if syncStatus is not 2 then
if syncStatus = 3 then
set syncStatus to "completed with warnings"
else if syncStatus = 4 then
set syncStatus to "completed with errors"
else if syncStatus = 5 then
set syncStatus to "last sync cancelled"
else if syncStatus = 6 then
set syncStatus to "last sync failed to complete"
else if syncStatus = 7 then
set syncStatus to "never synced"
end if
display dialog "syncStatus: " & syncStatus
end if
quit
end tell
if was_on is equal to 0 then
tell application "System Preferences"
set current pane to pane "com.apple.preferences.Bluetooth"
tell application "System Events" to tell window "Bluetooth" of process "System Preferences"
if value of checkbox "On" is 1 then
tell checkbox "On" to click
end if
end tell
quit
end tell
end if |
At work I have 3 Operating systems installed on my PC; Ubuntu Linux, Vista and XP. Originally I only had Ubuntu and Vista, and a big empty portion of the disk intended for XP if I needed it.
Due to these existing partitions, and a USB media card reader, the Windows XP installer would decide label it’s system partition “H:”, instead of the usual “C:”. I’m not sure how much this would have broken, but it annoyed me to the point that I found a hack to fix it.
I found that grub (the linux boot-loader) on my Linux partition allows you to edit the partition table and set the Vista NTFS partition to ‘hidden’. The XP installer could still see there was a partition there, but it didn’t understand it, and thus labelled it’s new partition “C:”. XP will of course then proceed to clobber your existing bootloader, but that’s a common occurrence, and fixable from a LiveCD, google is your friend here.
You should also be able to use a copy of grub on a LiveCD to mark the partition as (un)hidden if you don’t have Linux on your system normally.
Apologies for any vagueness and lack of technical details, this post has been on the back burner for a few months now, and I’ve actually forgotten most of the details.
I’ve only ever owned one graphical calculator, a TI-83, which was bought for me around when I started Secondary School. It was the device on which I broke my programming teeth, making crummy games and utilities to make maths exercises less tedious.
The other week I was experimenting with the HTML Canvas element for another little side-project of mine when I was reminded of the Graph Plot screen which my old calculator has. Essentially it lets you enter a Cartesian equation which it will then plot on the screen.
Subsequently, over a couple of days I put together a Javascript powered equation plotter, with much the same functionality as my TI-83. Oh and in the process I found a bug in the WebKit nightly, which they swiftly fixed.
You’re free to use the source to the how you wish, if you’re that way inclined (it’s a client-side web script so it’s practically open source off the bat). Under the hood it makes use of the MooTools javascript framework, though I’ve not made use of its features extensively, so It would only be a matter of an evening’s work to remove this dependancy.
Posted: November 4th, 2008
Categories:
Programming
Tags:
Bugs,
Canvas,
Graph,
HTML,
HTML5,
Javascript,
Programming,
Web
Comments:
No Comments.
Recently, by pure chance, I’ve been working for two different research projects which both have involved Java Applets.
The first project ran afoul of bug #6669818 which prevented the applet from connecting back to the originating server during LiveConnect calls, in Mozilla Firefox on a Windows XP platform.
Fortunately there is a workaround for this; by passing the task off to another thread which was started in a non-LiveConnect part of the Applet’s lifecycle, the task is then executed in another thread which is not subject to the same malfunctioning security check.
If you’d rather not have to create a thread just for this, a quick hack is to pass the event off to the applet rendering thread using the SwingUtilities.invokeLater(Runnable); function.
In the second project I’ve now encountered another platform-specific Applet quirk, this time with Mac OSX.
Using Javascript it is possible to change the size of an Applet on the page in the same way you would any other DOM element, however on Mac OSX any browser using the Java Embedding Plugin (Firefox, Opera and others) will fail to resize Java Applets correctly.
I’ve knocked up a simple test page which allows this to be tested, and shows a potential workaround.
There appear to be two problems cropping up; the first is that the Browser does not notify the Applet that it ought to resize. If you leave the “Notify Java” check-box un-checked when submitting the form, the browser expands the area the Applet ought to be using, but the applet continues to draw in it’s original position.
The second issue is that when axis are changed and Java is manually notified the behaviour still does not perform as it ought to. The clipping region of the Java applet rendering is not updated correctly, and thus only part of the applet is correctly rendered.
There is a temperamental workaround for this, by programatically resizing one axis and then the other in quick succession, but this seems to fail as often as it works, depending on whether the page is being loaded from nothing, refreshed, no-cache refreshed or returned to via the browser ‘Back’ action.
In the interest of getting this bug fixed the code to the Applet resize test page is linked from the test page and free for all to use.
Bugs:
Posted: August 23rd, 2008
Categories:
Programming
Tags:
Applet,
Bugs,
Java,
Javascript,
Programming
Comments:
No Comments.
As long as I can remember, the BBC’s online music streaming service has restricted the control you have on playback streams, restricting the embedded realplayer controls to allow you pause, skip 5 minutes or skip 15 and change the volume. I can understand the legal obligations they may have, but from a piracy perspective stopping people skipping tracks is irrelevant, its only use is as a measure to stop people re-listening to the same track without having to go back to the start each time.
The controls on Mac OS X are less restrictive, but still restrict you to pause, fast forward or stop, however some simple javascript manipulation of the page can enable the regular RealPlayer controls, complete with a seek-bar.
Bookmark either download the source file or view the bookmarklet source. Unfortunately blogger won’t let me create an actual bookmarklet link, so you will manually have to save the bookmarklet into a bookmark in your browser.
Posted: April 1st, 2008
Categories:
Programming
Tags:
BBC,
Hack,
Javascript,
Programming,
Radio
Comments:
2 Comments.
This post has been sitting for quite a while now, pending me having time to sit down and write some text to go alongside the code.
It would appear that I now have the time to write it up.
Back when
I was writing my Google Maps property finder I was using Google’s Geocoding API to get a set of co-ordinates based on a search string.
Specifically I was using the getLocations method of the GClientGeocoder object.
This would return a number of Placemark objects with a bunch of information about the potential matches.
They don’t really document this object, but to be honest they don’t really need to, below is an example Placemark expressed in JSON-ish notation.
{ "id": "p1",
"address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
"AddressDetails": {
"Country": {
"CountryNameCode": "US",
"AdministrativeArea": {
"AdministrativeAreaName": "CA",
"SubAdministrativeArea": {
"SubAdministrativeAreaName": "Santa Clara",
"Locality": {
"LocalityName": "Mountain View",
"Thoroughfare": {
"ThoroughfareName": "1600 Amphitheatre Pkwy"},
"PostalCode": {
"PostalCodeNumber": "94043"
}
}
}
}
},
"Accuracy": 8
},
"Point": {
"coordinates": [-122.081783,37.423111,0]
}
}
The only thing is, if you want to get a specific element, the tree will not necessarily be the same each time, so traversal is a pain.
The code below will condense all this into the root level of an object, so you can pick out the key/value pairs you want, and easily tell if some aren’t there.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| var Placemark = new Class({
initialize: function(placemark){
this.traverse(placemark);
},
traverse: function(item, key) {
for (var key in item) {
if (key == 'prototype')
continue;
if(typeof(item[key]) != 'object')
this[key] = item[key];
else
this.traverse(item[key]);
}
}
}); |
One thing to note is that this was written for to use the Mootools class system, though it shouldn’t be very hard to remove this dependancy.
Posted: March 1st, 2008
Categories:
Programming
Tags:
Google Maps,
Hack,
Javascript,
Programming
Comments:
1 Comment.
I’ve been building a JSP based website for a course module titled “Technologies for Electronic Commerce”. It’s finished now, but I’ve only just got round to writing up this post.
As part of this I was trying to make a multi-page form, using Spring‘s AbstractWizardFormController and spent an hour or so trying to make the form submission change the form page. My problem was that it wasn’t immediately obvious how to use the form taglib with the Wizard architecture.
The docs mentioned using request parameters, which was a bit confusing as I was using a POST form submission, however all you actually need to do is add one of these parameters to the form data (usually using a button).
Finish and cancel actions can be triggered by request parameters, named PARAM_FINISH (“_finish”) and PARAM_CANCEL (“_cancel”), ignoring parameter values to allow for HTML buttons. The target page for page changes can be specified by PARAM_TARGET, appending the page number to the parameter name (e.g. “_target1″). The action parameters are recognized when triggered by image buttons too (via “_finish.x”, “_abort.x”, or “_target1.x”).
For example:
<input value="Submit" name="_target1" type="submit"/>
This will request to change to page 2 of the form (remember Array base is 0).
Because of the way forms work, you can have a number of these (either as clickable images or buttons) and only the one the user eventually selects will be submitted with the request.
Posted: January 26th, 2008
Categories:
Programming
Tags:
Forms,
Java,
JSP,
Programming,
Spring,
Spring Framework
Comments:
3 Comments.
Pandora.com is pretty cool, it’s been around for a while now but I just went back to it for some easy listening background music to work to.
Supposedly they’ve begun to use IP filtering to limit the audience to the US. Either this is no longer in place or they’ve made a mistake in a regex somewhere, as this is definitely not the US.
I’d forgotten about the limit to the unpaid service, which stops playback after so many songs, but it was quite a while before I actually encountered it.
This may be a Mac OS X bug in the flash implementation, but it seems that if you keep the Firefox window containing the player minimised in the Dock, the music doesn’t stop playing!
Of course this does get in the way of the whole feedback system slightly, but I’m sure there are those who won’t mind too much.
Once I did encounter the limit I couldn’t just refresh the page and go back to listening again as they’re smart enough to stop you doing that.
But not that smart.
To completely stop this you would require either some heinous DRM-spawn system describable as cookies which you can’t delete, or some kind of unique client ID, effectively voiding all browser privacy. So to be fair, from the technologies they had to work with, they’ve done the best they could. ;)
So once you’ve been shut out of the Pandora player try the following:
- Delete your cookies from their domains.
- Delete any data stored within Adobe Flash for their domain.
The latter can be achieved by opening the Adobe Flash client settings and changing the data limit for the domain to 0KB, which will take effect upon refreshing the page, upon which the flash applet will request to store data in your browser again, and you’re back listening, but without any of your stations.
Update:
It appears that the region filtering will go live on January 15th, not quite yet.
Posted: January 5th, 2008
Categories:
World Wide Web
Tags:
Cookies,
Flash,
Hack,
Web
Comments:
No Comments.