Connect to CISCO SG300-10 Switch Using Kermit

August 3rd, 2014

Connect the switch using a standard 9-pin Serial Cable.

These are the parameters to connect CISCO SG300-10 Gigabit switch using Kermit

set speed 115200
set carrier-watch off
set flow-control none
set duplex full
set parity none

connect

 

 

Adding a Unix with Access Rights for FTP

May 30th, 2014
  • useradd hcp_ftp -d /home/www/www.xxx.com/htdocs -s /bin/false
  • usermod -a -G ftpdata xxx_ftp
  • usermod -a -G daemon xxx_ftp
  • passwd xxx_ftp
  • vi /etc/proftpd.groupowner

<Directory /home/www/www.xxx.com/htdocs>
UserOwner daemon
GroupOwner daemon
</Directory>

  • service proftpd restart

Dismount a staled NFS volume in ESXi 5.x

April 26th, 2014

esxcli storage nfs list

Screen Shot 2014-04-26 at 5.26.55 pm

esxcli storage nfs remove -v nfsvol1

REHL file system become read only in VMWare

March 29th, 2014

This become a known issue for RHEL if you are on a busy I/O storage.

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=51306

Work around is to remount the filesystem using the following command.

mount -o remount /

Advance Routing for Multi-homed Linux

March 1st, 2014

This page shows you how to configure a Multi-homed Linux Box with 2 Network Interfaces to connect to the internet properly.

 

Multi-homed Network

 

Step 1 – Update /etc/iproute2/rt_tables

echo 1 NET100 >> /etc/iproute2/rt_tables
echo 2 NET200 >> /etc/iproute2/rt_tables

 

Step 2 – Update the Routing Table

ip route add default via 192.168.100.1 dev eth1 table NET100
ip rule add from 192.168.100.0/24 table NET100

ip route add default via 192.168.200.1 dev eth0 table NET200
ip rule add from 192.168.200.0/24 table NET200

Recursively FTP all sub folders in Linux with wget

November 9th, 2013

wget -r ftp://user:pass@server.com/

in place replace a string in a directory

October 30th, 2013

grep -rl ‘xxxx’ ./ | xargs sed -i ‘s/xxx/yyy/g’

Init script for java jar

August 20th, 2013

Heres an example for starting a jar process with a single init script


#!/bin/sh
#
# init script for a Java application
#
# chkconfig: - 85 15
pid=0

# Check the application status
#
# This function checks if the application is running
check_status() {

s=`ps -e -o pid,cmd --sort cmd | grep "java -jar start.jar" | grep -v "grep " | tail -n1 | awk '{ print $1 }'`

# If somethig was returned by the ps command, this function sets the PID
if [ $s ] ; then
pid=$s
fi

# In any another case, set pid to 0
pid=0

}

# Starts the application
start() {

# At first checks if the application is already started calling the check_status
# function
check_status

if [ $pid -ne 0 ] ; then
echo "The application is already started"
exit 1
fi

# If the application isn't running, starts it
echo -n "Starting application: "

# Redirects default and error output to a log file
cd /home/www/dinhvan.vicosys.com.hk/htdocs/extension/ezfind/java
java -jar start.jar >> /var/log/ezfind.log 2>&1 &
echo "OK"
}

# Stops the application
stop() {

# Like as the start function, checks the application status
check_status

if [ $pid -eq 0 ] ; then
echo "Application is already stopped"
exit 1
fi

# Kills the application process
echo -n "Stopping application: "
kill -9 $pid &
echo "OK"
}

# Show the application status
status() {

# The check_status function, again...
check_status

# If the PID was returned means the application is running
if [ $pid -ne 0 ] ; then
echo "Application is started"
else
echo "Application is stopped"
fi

}

# Main logic, a simple case to call functions
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart|reload)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac

exit 0

Purify Function to Prevent XSS

July 13th, 2013

This is a purify function to ensure user-inputed string is sanitized and prevent XSS kind of attacks.

function purify($input){
	$result = "";
	if (isset($input) && !empty($input)) {
		$result = rawurldecode($input);
		$result = strip_tags($result);
		$result = stripcslashes($result);
		$result = htmlspecialchars($result, ENT_QUOTES); 
		$result = iconv('utf-8','utf-8//IGNORE',$result);
	}
	return $result;
}

Get Client IP Address

July 13th, 2013

The following PHP code snippet will return client IP address.

function get_client_ip() {
	$ipaddress = '';
	if (getenv('HTTP_CLIENT_IP'))
		$ipaddress = getenv('HTTP_CLIENT_IP');
	else if(getenv('HTTP_X_FORWARDED_FOR'))
		$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
	else if(getenv('HTTP_X_FORWARDED'))
		$ipaddress = getenv('HTTP_X_FORWARDED');
	else if(getenv('HTTP_FORWARDED_FOR'))
		$ipaddress = getenv('HTTP_FORWARDED_FOR');
	else if(getenv('HTTP_FORWARDED'))
	   $ipaddress = getenv('HTTP_FORWARDED');
	else if(getenv('REMOTE_ADDR'))
		$ipaddress = getenv('REMOTE_ADDR');
	else
		$ipaddress = 'UNKNOWN';

	return $ipaddress;
}