Daniel Tillett http://www.tillett.info Just my blog Tue, 16 Feb 2010 15:14:33 +0000 http://wordpress.org/?v=2.9.2 en hourly 1 Root privilege scripts from Apache http://www.tillett.info/2010/02/17/root-privilege-scripts-from-apache/ http://www.tillett.info/2010/02/17/root-privilege-scripts-from-apache/#comments Tue, 16 Feb 2010 15:14:33 +0000 Daniel http://www.tillett.info/?p=62 If you have a script that needs to access functions that can only be run as root (e.g. chmod, chgrp, mkdir, etc) you will find that you can’t call these directly since the Apache user is not root (at least it should not be root). There is no perfect solution around this as all solutions involve some security risk, but the least bad seems to be to use sudoer to grant root privileges to the script and then lock down the script so nobody other than root can modify the script.

First chmod the script so that anyone can execute it, but nobody other than root can modify it (I am assuming here that you are logged in as root, otherwise sudo).

chmod 111 /home/path_to_script

Next modify sudoer using visudo. It is a good idea to use visudo so that any change you make are updated without having to restart sudo.

# visudo

Add the following line after the root entry in sudoer

apache_user ALL = NOPASSWD: /home/path_to_script

Change the apache_user to whatever your apache user is (e.g. nobody) and then add the path to your script. You might want to add your favorite editor (mine is nano) to your export in .bashrc. You should now be able to call your script from apache without problem.

]]>
http://www.tillett.info/2010/02/17/root-privilege-scripts-from-apache/feed/ 0
Mac OS X compatible external web camera http://www.tillett.info/2010/02/16/mac-os-x-compatible-external-web-camera/ http://www.tillett.info/2010/02/16/mac-os-x-compatible-external-web-camera/#comments Tue, 16 Feb 2010 03:32:56 +0000 Daniel http://www.tillett.info/?p=59 I use my macbook with an Apple 23 inch monitor at work and so I can’t use the inbuilt iSight camera. Since Apple stopped selling the external iSight camera there is not much choice for Apple compatible web cams since most of the web cameras on the market don’t come with Mac OS X drivers.

One surprisingly option is the xbox360 web cam. This external usb camera works without any drivers and just plugs straight in and works. I managed to pick up a brand new one on eBay for A$35. The quality is pretty good and it sits without any problems on top of my monitor. Nice work microsoft.

]]>
http://www.tillett.info/2010/02/16/mac-os-x-compatible-external-web-camera/feed/ 0
Adding iso repository under XenServer 5.5 http://www.tillett.info/2009/09/23/adding-iso-repository-under-xenserver-5-5/ http://www.tillett.info/2009/09/23/adding-iso-repository-under-xenserver-5-5/#comments Wed, 23 Sep 2009 08:14:21 +0000 Daniel http://www.tillett.info/?p=51 If you want to install an OS from a local repository under XenServer 5.5 then you need to do the following. The documentation on how to do this in the xenserver manual is incomplete.

first ssh into the xenserver
mkdir -p /var/opt/xen/iso_import
Copy your ISO images to the /var/opt/xen/iso_import directory using scp.
Create a repository with this command:
xe sr-create name-label=ISOs type=iso device-config:location=/var/opt/xen/iso_import device-config:legacy_mode=true content-type=iso
You then need to attach the ISO library with this command (nicely not mentioned in the citrix documentation)
xe-mount-iso-sr /var/opt/xen/iso_import

You should then be able to create a VM using the .iso

]]>
http://www.tillett.info/2009/09/23/adding-iso-repository-under-xenserver-5-5/feed/ 1
Apple Bootcamp 2.1 and Windows XP SP3 http://www.tillett.info/2009/08/26/apple-bootcamp-2-1-and-windows-xp-sp3/ http://www.tillett.info/2009/08/26/apple-bootcamp-2-1-and-windows-xp-sp3/#comments Wed, 26 Aug 2009 07:17:07 +0000 Daniel http://www.tillett.info/?p=46 There is a problem with Bootcamp 2.1 in that you can’t install the Apple drivers under Windows XP SP3. I recently bought a new MacBook Pro and installed Windows XP SP3 from an image and then tried to update the XP hardware drivers using bootcamp 2.1. This didn’t work an instead gave a nice cryptic error 2762. It seems it is not possible to install the drivers manually either as windows can’t install the drivers for the wireless network, iSight camera, and trackpad.

The solution is to install XP from a SP2 image (luckily I had kept one), then install the drivers, and then upgrade to SP3. I hope this saves someone a bit of time.

Update. This has apparently been fixed in snow leopard. I guess another reason to update.

]]>
http://www.tillett.info/2009/08/26/apple-bootcamp-2-1-and-windows-xp-sp3/feed/ 0
How to get total folder / directory size with Linux http://www.tillett.info/2009/05/16/how-to-get-total-folder-directory-size-in-linux/ http://www.tillett.info/2009/05/16/how-to-get-total-folder-directory-size-in-linux/#comments Fri, 15 May 2009 23:28:30 +0000 Daniel http://www.tillett.info/?p=39 If you want to know how much disk space is being used by a directory (including all the sub-directories) then you can use the following command. It will output a single number in human readable form (eg 8.2G). I have found this very useful for finding where all my disk space has gone.

du -h | grep -v '/' | awk '{print $1}'

]]>
http://www.tillett.info/2009/05/16/how-to-get-total-folder-directory-size-in-linux/feed/ 2
X11 ssh-forwarding of a gnome-session to Mac OS X 10.5 http://www.tillett.info/2008/09/17/x11-ssh-forwarding-of-a-gnome-session-from-mac-os-x-105/ http://www.tillett.info/2008/09/17/x11-ssh-forwarding-of-a-gnome-session-from-mac-os-x-105/#comments Wed, 17 Sep 2008 07:32:47 +0000 Daniel http://www.tillett.info/?p=15 If you want to X11 ssh-forward a gnome-session on a remote linux server to MacOS X Leopard there seems to be some bug in the 10.5 X11 that causes the gnome desktop to take over the whole screen and you can’t access the session. The solution is to open the gnome-session using Xnest instead. This opens the session in a small X11 window (1024×768 in the example below).

Xnest -geometry 1024x768 :1& DISPLAY=:1 ssh -X <HOST> gnome-session
]]>
http://www.tillett.info/2008/09/17/x11-ssh-forwarding-of-a-gnome-session-from-mac-os-x-105/feed/ 0
Random PHP string http://www.tillett.info/2008/02/14/random-php-string/ http://www.tillett.info/2008/02/14/random-php-string/#comments Thu, 14 Feb 2008 00:04:52 +0000 Daniel http://www.tillett.info/2008/02/14/random-php-string/ I needed to generate a random string in php that did not repeat. This little snippet will generate a random non-repeating 32 character string.

// Generate random 32 character string
$string = md5(time());

]]>
http://www.tillett.info/2008/02/14/random-php-string/feed/ 0
IE 6 javascript onchange() problem http://www.tillett.info/2008/02/06/work-around-for-ir-6-javascript-onchange-bug/ http://www.tillett.info/2008/02/06/work-around-for-ir-6-javascript-onchange-bug/#comments Wed, 06 Feb 2008 05:01:37 +0000 Daniel http://www.tillett.info/2008/02/06/work-around-for-ir-6-javascript-onchange-bug/ I really hate IE6, but as it is still so common it is important to support it. I recently ran into a problem with the javascript onchange function. I was using onchange to update a text box on the page when the check box was selected. I was using “…onchange(this.checked)…” This worked fine for everything except IE6. It turns out that IE doesn’t fire the onchange state until the checkbox loses focus and so my update was not occurring.

The simple way around for this problem was to change onchange() to onclick(). The function now works in all browsers.

]]>
http://www.tillett.info/2008/02/06/work-around-for-ir-6-javascript-onchange-bug/feed/ 9
PHP number_format function problem http://www.tillett.info/2008/02/05/php-number_format-function-problem/ http://www.tillett.info/2008/02/05/php-number_format-function-problem/#comments Mon, 04 Feb 2008 23:46:26 +0000 Daniel http://www.tillett.info/2008/02/05/php-number_format-function-problem/ I have been using the php number_function() to format currency values in my code and was recently caught by the thousand separator comma. If you use the function and just specify the the number of decimal places (ie $x = number_format ($y,2) ) then you will get a comma introduced for all numbers above 999.99. This comma will break any maths functions that you might use downstream.

The solution is to specify the decimal point but remove the comma. The format to use to achieve this is $x = $number_format ($y,2,”.”,”") – the empty double quotes tell the number format function to not include the thousand separator comma.

]]>
http://www.tillett.info/2008/02/05/php-number_format-function-problem/feed/ 2
Best Javascript compressor to use http://www.tillett.info/2007/12/18/best-javascript-compressor-to-use/ http://www.tillett.info/2007/12/18/best-javascript-compressor-to-use/#comments Tue, 18 Dec 2007 04:51:44 +0000 Daniel http://www.tillett.info/2007/12/18/best-javascript-compressor-to-use/ I recently had a relatively large javascript (14KB) that I want to compress down. There are a lot of online JS compressors out there unfortunately not all of them actually work. After testing around a dozen of them I found the best two are JavaScript Utility and Javascript Compressor. JavaScript Utility was able to compress down my code to 5.0KB while Javascript Compressor compressed down to 6.3KB.

While both are good I would recommend using Javascript Utility, not only because it achieved a better compression ratio, but it also has a large number of other JS utilities that are worth using (especially JSLint). The only problem I found is I was only able to get the UTF-8 encoding option to actually run.

]]>
http://www.tillett.info/2007/12/18/best-javascript-compressor-to-use/feed/ 0