XP-rience

Something that I'd like to share with you!

Thursday, October 28, 2010

Open DNS : Alternate DNS

No comments :
If you are experiencing problems with your ISP DNS, you might want to try OpenDNS.

Below is how to check whether your ISP DNS availability by using nslookup command

I purposely change the DNS to 202.188.0.133 (TMNET DNS) which is the one that having a problem tonight. Timeout!


No problem when using OpenDNS.


You can set this DNS to your network card setting if you don't want to change your ADSL modem setting.

Easier to revert back to the ISP DNS when it recovers.



More information on OpenDNS? please google for OpenDNS

* Your might also consider Google Public DNS

Thursday, August 05, 2010

YUI Compressor with GUI

No comments :
Minification is the process of removing all unnecessary characters from source code such as
white space characters, new line characters, comments and block delimiters
without changing its functionality. [read more...]

Minified code reduces the amount of data that needs to be transferred through the web server (bandwidth saving).
It may also be used as a kind of obfuscation.

My favorite minification tool is YUI Compressor.
Mostly for CSS (Cascading Style Sheets) and JS (JavaScript).

Let us taka a look what happen when a simple code get minified.

JavaScript - Original Code

function startTime(){
    var today=new Date();
    var h=today.getHours();
    var m=today.getMinutes();
    var s=today.getSeconds();
    // add a zero in front of numbers<10
    m=checkTime(m);
    s=checkTime(s);
    document.getElementById('txt').innerHTML=h+":"+m+":"+s;
    t=setTimeout('startTime()',500);
}

function checkTime(i){
    if (i<10){
        i="0" + i;
    }
    return i;
}
JavaScript - Minified
function startTime(){var b=new Date();var d=b.getHours();
var a=b.getMinutes();var c=b.getSeconds();a=checkTime(a);
c=checkTime(c);document.getElementById("txt").innerHTML=d+":"+a+":"+c;
t=setTimeout("startTime()",500)}function checkTime(a){if(a<10){a="0"+a
}return a};
CSS - Original Code
body
{
    background-color:#d0e4fe;
}
h1
{
    color:orange;
    text-align:center;
}
p
{
    font-family:"Times New Roman";
    font-size:20px;
}
CSS - Minfied
body{background-color:#d0e4fe;}h1{color:orange;text-align:center;}
p{font-family:"Times New Roman";font-size:20px;}
Just to share here, since YUI Compressor don't provide any GUI, I've created one with Java Swing. It has been compiled together with yuicompressor-2.4.2.jar.
You need to have Java installed in order to run this executable JAR.


Download (MD5 : 210176c93d331c50dc19a2dda0ae1c89 JsCssMin.jar)

Using logrotate to rotate and archive log

No comments :
Previously I found out that rotatelogs cannot replace the rotated logs, I try to find other option.

I always come across logrotate whenever trying to search for rotatelogs.

So I give them a try.

1st step is to find it. BTW, I'm on SuSE Linux Enterprise 10.

$ logrotate
-ksh: logrotate: not found [No such file or directory]

Since it is not in the path, try to find it by doing this.

$ whereis logrotate
logrotate: /usr/sbin/logrotate /etc/logrotate.d /etc/logrotate.conf /usr/share/man/man8/logrotate.8.gz

Now try to run it with full path.

$ /usr/sbin/logrotate

Again, an error occurs.

error: error creating state file /var/lib/logrotate.status: Permission denied

This is because the user that we are currently on don't have write access /var/lib/logrotate.status.

-rw-r--r--  1 root   root  1246 2010-07-28 09:30 logrotate.status

Ask help from system root to change it...

# chmod 666 logrotate.status

...to

-rw-rw-rw-  1 root   root  1246 2010-07-28 09:30 logrotate.status

So, now try again.

$ /usr/sbin/logrotate
logrotate 3.7.3 - Copyright (C) 1995-2001 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License

Usage: logrotate [-dfv?] [-d|--debug] [-f|--force] [-m|--mail command]
[-s|--state statefile] [-v|--verbose] [-?|--help] [--usage]
[OPTION...] 

At last. Now create a simple conf like below.

$ cat ./logrotate.conf
/home/username/test/mylog {
rotate 5
daily
copytruncate
notifempty
compress
}


From my observation by triggering it manually (based on configuration above), I found out that it start by compressing the log file and name it mylog.1.gz.
When I trigger it again, it will rename the mylog.1.gz to mylog.2.gz and create a new mylog.1.gz. It will continue to do that but will not exceed mylog.5.gz (rotate 5 from conf file).

-rw-r--r-- 1 user group  348 2010-07-28 15:32 mylog
-rw-r--r-- 1 user group   54 2010-07-28 15:32 mylog.1.gz
-rw-r--r-- 1 user group   59 2010-07-28 15:32 mylog.2.gz
-rw-r--r-- 1 user group   58 2010-07-28 15:32 mylog.3.gz
-rw-r--r-- 1 user group   51 2010-07-28 15:32 mylog.4.gz
-rw-r--r-- 1 user group   57 2010-07-28 15:32 mylog.5.gz

This is just like what I wanted. It will keep only 5 gz files. Now you can schedule (cron) them accordingly.

Wednesday, July 28, 2010

Using rotatelogs to rotate nohup.out

No comments :
Extending my focus on rotatelogs, I was thinking of to use them with other software. This might help me to on how to rotate nohup.out without using cronjob. First, I need something to throw STDOUT. Something simple as below;

#!/bin/sh
while [ 1 ]
do
echo `date`
sleep 2
done

Script above will run in infinite loop and echo date output to STDOUT every 2 secs. Next is to test it with nohup so it could survive logout.

username@myserver:/mydir $ nohup ./test.sh
nohup: appending output to `nohup.out'

Let it run for a couple of seconds and kill it by CTRL-C. Then verify that the nohup.out contains couple lines of date in it. Next step is to pipe it with rotatelogs and observe what happen

username@myserver:/mydir $ nohup ./test.sh | ./rotatelogs nohup.out.%S 10 &
[1] 24828

Command line above will pipe the STDOUT from the simple test.sh and send them to rotatelogs to be rotated accordingly. nohup.out.%S will cause the nohup.out filename to rotate as below (%S: 2-digit second from rotatelogs)

-rw-r--r-- 1 username usergrp 1479 2010-07-28 10:32 nohup.out.40
-rw-r--r-- 1 username usergrp 1595 2010-07-28 10:32 nohup.out.50
-rw-r--r-- 1 username usergrp 1711 2010-07-28 10:33 nohup.out.00
-rw-r--r-- 1 username usergrp 1682 2010-07-28 10:33 nohup.out.10
-rw-r--r-- 1 username usergrp 1653 2010-07-28 10:33 nohup.out.20
-rw-r--r-- 1 username usergrp 1566 2010-07-28 10:33 nohup.out.30

Oops! Now I relize that the output file will never be replaced. It keep on appending to an old file. Meaning that it will grow and need to be manually archive. :-(

Looking forward to try logrotate and it will be my next post, soon.

Tuesday, July 27, 2010

Using rotatelogs to manage Logs in Apache (xampp)

No comments :
While performing a routine XAMPP (under Linux) healthy check, I've found out some log files had grown up to about 8GB. This might cause the system to slow down. Searching for a solution from the net lead me to this, rotatelogs. To use this rotatelogs it needs to be piped in the XAMPP httpd.conf which is located at /opt/lampp/etc/httpd.conf. So I comment out the 2 original lines and add 2 lines with rotatelogs piped to them like below;

#ErrorLog logs/error_log
ErrorLog "|bin/rotatelogs logs/error_log 5M"
...
#CustomLog logs/access_log common
CustomLog "|bin/rotatelogs logs/access_log 5M" common

Next is to restart the XAMPP by doing ./lampp restart (XAMPP for Linux). Unfortunately it failed and when I observed the error.log it shows;

piped log program 'bin/rotatelogs... failed unexpectedly

Maybe the path is wrong. Next try is to use full path by replace those rotatelogs piped lines with below;

#ErrorLog logs/error_log
ErrorLog "|/opt/lampp/bin/rotatelogs /opt/lampp/logs/error_log 5M"
...
#CustomLog logs/access_log common
CustomLog "|/opt/lampp/bin/rotatelogs /opt/lampp/logs/access_log 5M" common

Finally it works. No error in error_log found. New log file will be created whenever it reach 5MB size. Whenever it switch to the new log file, a unixtime will be appended to the log file name like below;

-rw-r--r-- 1 root root 22713 Jul 27 10:10 access_log.1280196529
-rw-r--r-- 1 root root 4989 Jul 27 10:21 access_log.1280197231
-rw-r--r-- 1 root root 725 Jul 27 10:20 error_log.1280197229

Log file size above is not 5MB yet but when I restart XAMPP, new log file is created. But I'm thinking, what if I don't want to keep all logs, just rotate them weekly. So I try this;

#ErrorLog logs/error_log
ErrorLog "|/opt/lampp/bin/rotatelogs /opt/lampp/logs/error_log.%a 86400"
...
#CustomLog logs/access_log common
CustomLog "|/opt/lampp/bin/rotatelogs /opt/lampp/logs/access_log.%a 86400" common

The new log file name now looks something like below.

-rw-r--r-- 1 root root 625 Jul 27 12:04 error_log.Tue
-rw-r--r-- 1 root root 1941 Jul 27 12:04 access_log.Tue

They will rotate in 24 hours (86400 secs) with a 3-character weekday name appended to them. I assume they will rotate and replace just like I plan in 1 week time, I hope so. :-)

Thursday, April 01, 2010

HTTPS traffic on port 8080 is dropped by SecuRemote

No comments :
After installing VPN-1 SecuRemote/SecureClient NGX R60, my PC is unable to connect to https websites through a port 8080 proxy. Some googling around lead me to this.

Can't view HTTPS web pages
I have installed Securemote on a XP (Pro) PC so that it can access a remotely hosted server/application which works OK. However, since the Securemote software has been loaded, the user is not able to view HTTPS web pages, he can view HTTP pages OK.

If I uncheck the Securemote client in the network options in XP, the HTTPS pages are able to be viewed, but then the Securemote can not be used.

Is there any configuration change that can be made to Securemote to stop it interfering with the HTTPS traffic?

Thanks for your help.
Simon.

Digging through brought me to below solution;

Re: Securemote blocking access to https pages through proxy.

Hi,

try this:


1. Navigate to HKLM\System\CurrentControlSet\Services\FW1\parameters.
2. Add a new key called "Globals."

3. Under the "Globals" key, add a DWORD parameter called "asm_http_allow_connect," and set its value to 14. Reboot the computer

i got this from my support, and they say that Securemote does not acceppt "CONNECT" per default.

CP says this is no failure, and won't change the behaviour.

regards,
stefan

I've tried it and it works. Just create a new dword regsitry entry as below;



Or you can open your notepad, copy & paste contents below, save it as fix.reg, right click and select Merge.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\FW1\Parameters\Globals]
"asm_http_allow_connect"=dword:00000014