Friday, May 16, 2008

Logging in Shell Scripts

This post describe two methods of setting up logger when doing shell scripts. First method is useful when your script has permission to write in system log.
# setup
log='logger -t logger-id'
# usage
$log "log message..."
Second method use redirect of standard output to your log file.
# setup
function log() {
echo "`date +'%Y-%m-%d %H:%M:%S'` [$$] $1" >> script.log
}
# usage
log "log message..."

Dynamic TinyMCE / TinyMCE and AJAX

Quick note about adding and removing TinyMCE editor when working with AJAX style pages. Standard initialization tinyMCE.init() is not accepatable but we can use another function to add/remove editor dynamically.

// add editor
tinyMCE.execCommand("mceAddControl", true, elementId);

// remove editor
tinyMCE.execCommand("mceRemoveControl", true, elementId);

Problem with AJAX upload in Safari

There is good example which shows how to make AJAX style upload via hidden IFRAME. But Safari and Konqueror browsers open new window. This happen because of CSS property display: none; used to hide IFRAME.

Just remove this property and use different method of hiding - move IFRAME object outside of your window:

left:-100px;
top:-100px;
width:1px;
height:1px;

Wednesday, May 14, 2008

How to force download file in IE

IE open files inside itself by default, if it knows the file type, for example: images, word documents. To make it download instead of open file, you need to send additional HTTP header in response: Content-disposition: attachment; filename=my_file.ico Additionally you need to send some headers to prevent caching of content in browser.

Short example for PHP:

$fp = fopen($icoFile, 'r');

// cache control headers
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// send the right headers
header("Content-Type: text/plain");
header("Content-Length: " . filesize($icoFile));
header("Content-disposition: attachment; filename=" . basename($icoFile));

fpassthru($fp);
fclose($fp);

Mapping 12 hours time format (am/pm) in 24 hours

Java SSLHandshakeException

Sometime you get SSLHandshakeException in Java when sending HTTPS requests. Most likely your JVM can not verify SSL certificate because it was given by unknown authority. You can install this authority public key, first download it here. Now install it in your keystore, for example:

x29:~ # /opt/jdk/bin/keytool -keystore /opt/jdk/jre/lib/security/cacerts -import -alias usertrust -file /home/yura/UTN-USERFirst-Hardware.crt -trustcacerts
Enter keystore password: changeit
Owner: CN=UTN-USERFirst-Hardware, OU=http://www.usertrust.com, O=The USERTRUST Network, L=Salt Lake City, ST=UT, C=US
Issuer: CN=UTN-USERFirst-Hardware, OU=http://www.usertrust.com, O=The USERTRUST Network, L=Salt Lake City, ST=UT, C=US
Serial number: 44be0c8b500024b411d3362afe650afd
Valid from: Sat Jul 10 01:10:42 NOVST 1999 until: Wed Jul 10 01:19:22 NOVST 2019
Certificate fingerprints:
MD5: 4C:56:41:E5:0D:BB:2B:E8:CA:A3:ED:18:08:AD:43:39
SHA1: 04:83:ED:33:99:AC:36:08:05:87:22:ED:BC:5E:46:00:E3:BE:F9:D7
Trust this certificate? [no]: yes
Certificate was added to keystore


Check webapper.net blog for additional details.

How to check web site in Safari (Mac OS) and other browsers

There is a couple of nice web services which render your web site in different browsers and return simple image. It's not ideal testing method but better than nothing :)

SSH public key authentication

Continue knowledgebase posts...


There are two great articles describing process of configuring SSH public key authentication: in Russian and in English.