Logaholic.de

Avatar

queer as code!

Reading browser history with css and javascript

This small script demonstrates how to check if a user has visited a particular url with his browser using css and javascript. Simple trick, small script, but could be dangerous – and you don’t see a damn thing.

The only protection against this of which i know is NoScript or just turning off JavaScript in your browser…

Rotating dom elements with css3 and jscript/jquery animation

If you want to rotate dom elements, webkit offers you

-webkit-transform: rotate(0deg);

and firefox offers you

-moz-transform: rotate(0deg);

I hacked together a small demo rotating dom elements with css including some animation with jscript/jquery.

Nagios: NRPE: Unable to read output error – check_apachestatus_auto.pl

Today I solved a problem I had with check_apachestatus_auto.pl executed via NRPE.

Running the command as root worked fine but, running as user “nagios” just gave no output – which translated to the error message “NRPE: Unable to read output error” on the Nagios NRPE Client.

After checking file permissions, any debug modes and logs i found… i finally got to /tmp and there was it: “127.0.0.1……”, a temporary file created by that particular check plugin. Since i tested the plugin first as root, the file had root-only permissions, and the plugin executed as nagios just stopped somewhere while not being able to use/overwrite that file.

I deleted that particular file, and everything works fine now…

OCZ Apex SSD 120GB and How to move a vista boot partition to a new drive

My newest toy arrived today: OCZ Apex SSD 120Gb – a very fast Solid State Drive. The manufacturer tags it with “230mb/s read, 160mb/s write, <0.3ms access time”.

After my six hour hassle of (trying to…) moving the boot partition from my old harddrive to the new one (see the full report/steps below), I was curious about the first performance test, which I used HD Tune for.

This is the result for my old harddrive, a Samsung HD642JJ:

hdtune_benchmark_samsung_hd642jj

Raw data:

HD Tune: SAMSUNG HD642JJ Benchmark

Transfer Rate Minimum : 55.0 MB/sec
Transfer Rate Maximum : 102.8 MB/sec
Transfer Rate Average : 83.0 MB/sec
Access Time : 13.2 ms
Burst Rate : 135.3 MB/sec
CPU Usage : 4.5%
Temperature : 25°C

And this is the result for my new SSD (OZC Apex SSD 120GB):

hdtune_benchmark_ocz_apex_ssd

Raw data:

HD Tune: OCZ APEX_SSD Benchmark

Transfer Rate Minimum : 1.4 MB/sec
Transfer Rate Maximum : 172.7 MB/sec
Transfer Rate Average : 138.1 MB/sec
Access Time : 0.2 ms
Burst Rate : 129.5 MB/sec
CPU Usage : 5.5%
Temperature : 44°C

As I said before, I moved my bootpartition to the new drive. These are my subjective feelings about the new system:

  • The Windows bootup isn’t that much faster, but I didn’t measure the startup time of the old harddrive. (Still too long…)
  • Applications start much faster now. I think this really is the point where the ridiculous low access time of the SSD kicks in. Zend Studio i.e. is down from ~30 secs to 12. (And I haven’t switched the projects/workspace to a new SSD partition yet!)

The application startup speed, and working with big filecount-intensive projects were the main reasons for me to try out a SSD. So far (this still is my impression after only 2-3 hours of usage) I am very satisfied with the results.

The temperature of the SSD is ~20° warmer, but I think even 44°C is not high enough to care about.

In about one month I will provide you with even more subjective feedback :)

The steps for the Vista bootpartition-move, using Acronis True Image, should be these:

  1. Boot from the Acronis True Image CD
  2. Backup your boot partition from the old drive
  3. Restore the backup to the new drive, mark the new partition active (Cloning didn’t work, because the SSD is much smaller, and the UI doesn’t let me clone just one partition)
  4. Reboot from your Vista Installation disc
  5. Repair the installation on your new drive (the log should show something about “missing bootmanager – fixed”)
  6. Boot from your new SSD
  7. If your bootpartition is not C, fix it this way: How to restore the system/boot drive letter in Windows
  8. Done. Finished. Hopefully.. (At least, you should have 2 layers of backups to restart if something screws up…)

Just two small things OCZ could improve:

  • Inform me as a customer, that there is no SATA cable in the retail box. Every other retail (SATA) harddrive I bought up to this day had at least one packed.
  • As most of the customers will be “switchers” imho, ship something to help with the partition migration process. I will happily pay some more bucks, if it just works.

Error #0 on AIR application installation

I got this errormessage on “some” places while trying to install an AIR application package, while other places just worked fine.

The application could not be installed. Try installing it again. If the problem persists, contact the application author. Error #0

The first step debugging this was to find out where the AIR application installer logs errors – which by default he does not. To activate installer logging, you have to put two files in your home directory (C:\Users\youraccountname\ on Vista or C:\Documents and Settings\youraccoutname\ on XP) called .airappinstall.log and .airinstall.log.

If those two files are present, the logging writes to them automagically.

The error I found there looked like this:

Installing C:\Dokumente und Einstellungen\***\Lokale Einstellungen\Temp\fla12.tmp\setup.msi
Error occurred; beginning rollback: [ErrorEvent type="error" bubbles=false cancelable=false eventPhase=2 text="1603" errorID=0]

From here on I was very sure that it has to do with privileges… (No, there is no context menu entry on AIR packages to “install as Administrator” or “run as”…)

Finally, I checked the windows event log, and found this:

Product: *** -- Error 1925. You do not have sufficient privileges to complete this installation for all users of the machine.  Log on as administrator and then retry this installation.

Why can’t they show this error at the installer instead of error #0?…

Yes, installing as Administrator solved the problem!

How to install cruisecontrol/phpUnderControl in Debian Etch

This is how I install cruisecontrol/phpUnderControl, including all dependencies, in a fresh Debian Etch machine.

# add the backport mirror for java and subversion
echo "deb http://www.backports.org/debian etch-backports main contrib non-free" >> /etc/apt/sources.list

# add the backport mirror key
gpg --keyserver hkp://pgp.mit.edu --recv-keys 16BA136C
gpg --armor --export 16BA136C | apt-key add -

apt-get update

# install backports (java and subversion)
apt-get -t etch-backports install sun-java6-bin sun-java6-jre
apt-get -t etch-backports install subversion

# install apache (mainly for phpmyadmin) and php5 + cli
apt-get install apache2-mpm-prefork
apt-get install php5 php5-cli php5-dev
apt-get install php-pear make

# install xdebug (needed for phpunit)
pecl install xdebug
echo "zend_extension=/usr/lib/php5/20060613+lfs/xdebug.so" >> /etc/php5/cli/php.ini

# install phpunit and phpundercontrol via pear
pear upgrade --force pear
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear install phpunit/phpunit
pear install --force --alldeps channel://components.ez.no/Graph
pear install --force --alldeps channel://pear.phpunit.de/phpundercontrol-0.4.7

# get and extract cruisecontrol
apt-get install unzip wget
cd ~
wget http://freefr.dl.sourceforge.net/sourceforge/cruisecontrol/cruisecontrol-bin-2.8.2.zip
unzip cruisecontrol-bin-2.8.2.zip -d /opt
cd /opt
ln -s cruisecontrol-bin-2.8.2 cruisecontrol

# run phpundercontrol modifications against cruisecontrol
phpuc install /opt/cruisecontrol

# first testrun
cd /opt/cruisecontrol
./cruisecontrol.sh

Balsamiq Mockups – impressive software with an even more impressive story

mockups_fpaSince the first time I have seen Balsamiq Mockups, it rocked my world. It is now a pleasure to create mockups. With Mockups, this is a fast and intuitive process, for everyone. Yes, I like this tool as a developer, and I am sure that any non-developer will also like it as much!

There are a lot of shapes one can choose like a browser window, iphone window, any other window, webcontrols, etc. The result can be exported as PNG or saved as XML. With XML files one can even diff/merge mockups ;)

Short overview:

  • Create software mockups in minutes
  • Collaborate with your team
  • Focus on creating your product

The guy/company behind Mockups, Giacomo ‘Peldi’ Guilizzoni, is even more impressive. There is a very good interview over at 37 signals (see Sources):

“I never really understood the concept of building a company with the goal to sell it, or why one should have an ‘exit strategy.’ I just don’t get it. If you’re doing what you love, why would you want to ‘exit’? Maybe it’s because I am Italian, but I see nothing wrong with a business staying small in the long run. As long as we do great work, are happy to do it, and make people happy with it, I see no reason to change anything.”

Thank you again for the kind response to my email, Balsamiq Team, and the chance to review this very nice (and therefore rare) piece of software.

Sources:

Moving to Feedburner

Just as a short notice, I moved my feed to feedburner. The new feed url is this: http://feeds2.feedburner.com/logaholic

I did this to “outsource” my feed traffic and improve statistics for analyzing what you like to read :)

Yes, I also moved the subscribe button/links to a more prominent position (top right, larger icon).

Update: Automagic redirection in place. You shouldn’t need to update anything ;)

Secure backups with push and pull strategies via amazon s3

Note: If you don’t want to or cannot by company-rule trust Amazon S3, this is probably not what you want to read.

I’m going to show you how one could improve the security of his production environment backups. In this setup the production environment can never harm any old backup. There is another offsite backup location if Amazon S3 should fail – for us being our office, this is also perfect for up-to-date testing/development database snapshots.

We will need two separate Amazon S3 accounts and any s3 console tool (like s3bash).

The production environment, with its own (restricted to put and get files) s3 user, will push backups to our s3 bucket. It is not allowed to delete backups there. It does not have any access to the offsite location. If someone gets access to our production environment, he can not delete our backups on s3 per their acl, and can never harm our offsite backups. This is kind of an one-way solution and represents the “push-strategy“.

The offsite location, with the second, full privileged s3 account, will pull the backups from s3 every night. There are also tools for backup verification and testing-environment updates. This is the “pull-strategy“. The offsite location has access to the production environment for maintenance task and deployment.

Small graphic:

securebackups

I wanted to mention this setup since i read a blogpost about a worst case scenario:

“A huge flight sim site was hacked and destroyed this weekend  – avsim.com. An important lesson on why off-site backups are critical! They had two servers, and had a backup of A on B, and B on A. Both were taken out.”

Downsides:

  • Access to our office network/offsite backups would be bad.
  • Bruteforcing/getting access to our administrative S3 Account would be bad.
  • you have to trust Amazon with your data

Conclusion:

Always combine different backup strategies and test your backups. One day you will need them!

Uncompressing Zip-files with subfolders in AIR applications via JavaScript

I am currently building an AIR application with JavaScript (jQuery + jQuery UI), one function downloads zipped files and has to extract the contents somewhere to the local filesystem. Since the files may contain subfolders, i didn’t find any working example supporting subfolders in the docs or via google.

I found an Adobe Tutorial for basic Zip files (see Sources), and after reading the zip specs there was just one small change to their code to get it working with subfolders.

The spec says that entries in the zip file which are directories just end with an ‘/’. Skipping them is the whole magic. (see line 48)

Thankfully, the air.FileStream autocreates director ies, so writing the files to the subfolders does not need any change to the code. I added a basepath as parameter to the outFile function, to complete the for me intuitive function unzipFile(sourceFile, targetPath).

Here is the code:

 function unzipFile(sourceFile, targetPath)
{
	var bytes = new air.ByteArray();
	var fileName = new String();
	var flNameLength;
	var xfldLength;
	var offset;
	var compSize;
	var uncompSize;
	var compMethod;
	var signature; 

	var zfile = air.File.applicationStorageDirectory.resolvePath(sourceFile);
	var zStream = new air.FileStream();
	zStream.open(zfile, air.FileMode.READ);
	bytes.endian = air.Endian.LITTLE_ENDIAN;

	while (zStream.position < zfile.size)
    {
		// read fixed metadata portion of local file header
        zStream.readBytes(bytes, 0, 30);

		bytes.position = 0;
        signature = bytes.readInt();
        // if no longer reading data files, quit
        if (signature != 0x04034b50)
        {
            break;
        }

		bytes.position = 8;
        compMethod = bytes.readByte();  // store compression method (8 == Deflate)

		offset = 0;    // stores length of variable portion of metadata
        bytes.position = 26;  // offset to file name length
        flNameLength = bytes.readShort();    // store file name
        offset += flNameLength;     // add length of file name
        bytes.position = 28;    // offset to extra field length
        xfldLength = bytes.readShort();
        offset += xfldLength;    // add length of extra field

		// read variable length bytes between fixed-length header and compressed file data
        zStream.readBytes(bytes, 30, offset);

		bytes.position = 30;
        fileName = bytes.readUTFBytes(flNameLength); // read file name 

		if (fileName.substr(fileName.length - 1, 1) != '/')
		{
			bytes.position = 18;
			compSize = bytes.readUnsignedInt(); // store size of compressed portion
			bytes.position = 22; // offset to uncompressed size
			uncompSize = bytes.readUnsignedInt(); // store uncompressed size 

			// read compressed file to offset 0 of bytes; for uncompressed files
			// the compressed and uncompressed size is the same
			zStream.readBytes(bytes, 0, compSize);

			if (compMethod == 8 ) // if file is compressed, uncompress
			{
				bytes.uncompress(air.CompressionAlgorithm.DEFLATE);
			}
			outFile(targetPath, fileName, bytes); // call outFile() to write out the file
		}
	}
}

This is the outFile function which writes the uncompressed files to the local file system.

 function outFile(baseDir, fileName, data)
{
    var outFile = air.File.applicationStorageDirectory;
    outFile = outFile.resolvePath(baseDir+air.File.separator+fileName);
    var outStream = new air.FileStream();
    outStream.open(outFile, air.FileMode.WRITE);
    outStream.writeBytes(data, 0, data.length);
    outStream.close();
}

Sources:

Next,