Suspend NAS when idle

My NAS with 4TB RAID-5 storage consumes round about 40-45 Watt. Not very much for a "full featured" Athlon X2 4600+ Linux systems, but running 24/7 it produces around 70 EUR per year on energy costs, so I would like to suspend it to ram when idleing. But since I don't want to press a button or running wake-on-lan manually when watching a video, my HTPCs (a Mac Mini running Ubuntu and a Raspberry Pi running XBian) should wake it automatically when accessing the media directory.

Custom dyndns service

Since stopped it's free service, and didn't work on my Fritz!Box, I've created a custom dyndns service with very little overhead. If you want to use it, you have to run your own DNS server for a zone that will be updated. Tested with Bind 9, might work with other named's, too.

It can be used to assign any hostname under DOMAIN to an IP address.

JasperReports: Append an In-Report ToC without Scriptlets

Whenever you want to add a Table of Contents to your Jasper Report you have a problem, because there is no build-in function to do this. Most solutions suggest to derive an own Scriptlet class, use subreports or provide a custom data source.

Let me add another quick & dirty solution that requires no external resources, not even the Groovy library. It works with pure embedded Java code, at least as long you're ok with the very simplified layout of this solution, and do not require to have the ToC at the beginning of your report. And furthermore, it is pretty simple.

First, create a new parameter of type java.lang.StringBuilder:

<parameter name="toc" class="java.lang.StringBuilder" isForPrompting="false">
	<defaultValueExpression><![CDATA[new StringBuilder()]]></defaultValueExpression>

This parameter called toc will be filled with the table of content during the rendering of the detail sections. You may add markup if you want to.

Next, on the summary page, print the content of this parameter. I'll use HTML formated strings, here:

	<reportElement x="0" y="0" width="540" height="20"/>
	<textElement verticalAlignment="Middle">
		<font size="14" isBold="true" isItalic="true"/>
	<text><![CDATA[Table of Contents]]>
<textField isStretchWithOverflow="true">
	<reportElement x="28" y="30" width="471" height="20"/>
	<textElement markup="html">
		<font fontName="Monospaced" size="8"/>

Maybe you noticed that I use a monospace font here. This will be explained later.

Whereever you want to have a new entry (e.g. in the detail band or within a group header) add a new text field and put the following expression into it:

	$F{section}.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;")
		+ "<font color='#999999'>"
			/* Fill the string with up to 80 dots */
			+ new String(new char[80 - Math.min($F{section}.length(), 80)]).replaceAll(".", ".")
		+ "</font>"
		+ "<br>"
) == null ? "" : ""

This works since StringBuilder.append returns an object (itself). It won't be visible since the expression will result in an empty string in any case.

In this example, I want to use the field "section" as an index. Because the resulting string will be formatted using html markup we have to escape "<" as "&lt;", ">" as "&gt;" and "&" as "&amp;". In the next lines, you see the reason why I decided to use a monospace font for the ToC: the section name should be followed by up to 80 grey dots and the page number.

Since you cannot use loops within JasperReport's expressions (at least not without Groovy) I used the trick to create a new String containing the required number of 0x0 characters and replace all characters (the first parameter of String.replaceAll is a regular expression) with dots.

suphp: distinguish between script owner and process owner

This is a re-post of my mail to the suphp mailing list. Although the behaviour described here is a serious design issue, I've never got any feedback.

The attached patch is some kind of "proof of concept" to solve a security related problem I have with suPHP.

Problem: Run script with file/directory owner threatens the user's files.

Logout from HTTP auth using Apache

Since there is no mechanism defined to log the user out of a HTTP authenticated session you have to use a workaround. Most browsers forget their login data once they received a 403 response. The problem is, that the user have to return to the normal starting page manually.

Update 2017-02-22: It seems that this technique doesn't work anymore in recent Firefox and Chrome browsers.