2008年6月21日 星期六

check web service

睇下個URL係咪正常去得到.


#!/usr/bin/perl
#
# check web service
#
use strict;
use LWP::Simple;
use URI::URL;

my $url = shift;
if (! ($url) )
{
print "Usage : $0 \n";
exit(-1);
}

# make and check url
my $chkurl = URI::URL->new($url);
my @headers = head($chkurl);
if (@headers)
{
print "Host : $url\n";
print "Server : @{[pop @headers]}\n\n";
}
else
{
print "Unable to retrive @{[$chkurl->as_string]}\n\n";
}

exit(0);

2008年6月20日 星期五

apt / yum

#
# Install apt server
#

Step 1, install apt rpm (*install httpd for using web access on apt)
- from Redhat disc
i.e. rpm -Uvh apt-0.5.5cnc6-fr1

Step 2, setup RPM folders for os and updates
i.e. mkdir -p /var/www/html/apt/redhat
mkdir /var/www/html/apt/redhat/9
mkdir /var/www/html/apt/redhat/9/RPMS.os
mkdir /var/www/html/apt/redhat/9/RPMS.updates
copy redhat disc RPMS to RPMS.os
copy patch updates to RPMS.updates

Step 3, generate base folder for apt
i.e. genbasedir /var/www/html/apt/redhat/9 os updates

Step 4, start web server

Step 5, [Client side] EDIT /etc/apt/source.list
(ADD) rpm http:///apt/redhat/9 os updates

Usage :
Update rpm package list : apt-get update
Install package : apt-get install
Upgrade all package to newest version : apt-get upgrade

=======================================================
#
# Yum install (* under FC4)
#
Step 1 : install yum rpm
- from FC4 disc
i.e. rpm -Uvh yum-2.3.2-7.rpm

Step 2 : install createrepo
- from FC4 disc
i.e. rpm -Uvh createrepo-0.4.2-2.noarch.rpm

Step 3 : setup RPM folders for base and update
i.e. mkdir -p /var/www/html/yum/fc4
mkdir /var/www/html/yum/fc4/base
mkdir /var/www/html/yum/fc4/update
cp fc4 disc RPMS to base
cp fc4 patch updates to update

Step 4 : import GPG key (both server and client)
i.e. rpm --import /usr/share/rhn/RPM-GPG-KEY
rpm --import /usr/share/rhn/BETA-RPM-GPG-KEY
rpm --import /usr/share/rhn/RPM-GPG-KEY-fedora
rpm --import /usr/share/rhn/RPM-GPG-KEY-fedora-test

Step 5 : generate rpms header folder
i.e. yum-arch /var/www/html/yum/fc4/base
yum-arch /var/www/html/yum/fc4/update

Step 4 : setup repositories
i.e. createrepo /var/www/html/yum/base
createrepo /var/www/html/yum/update

Step 5 : setup repositories entry (both server and client side)
clear old .repo files(rm /etc/yum.repos.d/*.repo)
ADD new file for yum server -
/etc/yum.repos.d/fc4.repo
---------------------------------------------
[fc4-base]
name=fc4 - base
baseurl=http://YUM_SERVER/yum/fc4/base
enabled=1
[fc4-update]
name=fc4 - update
baseurl=http://YUM_SERVER/yum/fc4/update
enabled=1
---------------------------------------------

Step 6 : start web server

Usage :
Install package : yum install
Update package : yum update
Upgrade all package to newest version : yum -y update
Clean downloaded packages : yum clean packages

2008年6月19日 星期四

Network boot server


#
# Network boot server setting
#

# require package
dhcp
tftp-server
syslinux

# Setup dhcp server
EDIT /etc/dhcpd.conf
#-----------------------------------------------
ddns-update-style none;

subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.11 192.168.0.20;
default-lease-time 3600;
max-lease-time 4800;
option routers 0.0.0.0;
option subnet-mask 255.255.255.0;
filename "pxelinux.0";
}
#-----------------------------------------------

** option - filename : this is the file for pxe client download and execute

# Setup tftp server
EDIT /etc/xinet.d/tftp
#-----------------------------------------------
server_args = -v -s /tftpboot
disable = no
#-----------------------------------------------
restart xinetd
/etc/rc.d/init.d/xinetd restart

# Setup kernel for remote client
- Fedora Core
get from FC source
copy FC source : /isolinux/vmlinuz to /tftpboot/fc
copy FC source : /isolinux/initrd.img to /tftpboot/fc-initrd

# Setup pxelinux file for boot
mkdir /tftpboot (if not exists)
cp -a /usr/lib/syslinux/pxelinux.0 /tftpboot/
mkdir /tftpboot/pxelinux.cfg
EDIT /tftpboot/pxelinux.cfg/default
#-----------------------------------------------
prompt 1
default fc
timeout 150

label fc
kernel fc
append initrd=fc-initrd ramdisk_size=8192
#-----------------------------------------------

# Usage
# start dhcp server
1) /etc/rc.d/init.d/dhcpd start
2) start client machine use network boot
** default is boot from fc, press enter would continue

# nfs install for linux (optional, u may not want to install throung nfs)
EDIT /etc/exports
#-----------------------------------------------
/data/FC (ro)
#-----------------------------------------------
/etc/rc.d/init.d/nfs start

mass_ssh

經由 ssh, 呼叫一定數量機器運行特定指令.


#!/bin/sh
#
# call other machine to exec cmd by ssh
#

# function
exec_cmd()
{
LSUB=$1
IPS=$2
LCMD=$3

CHKRNG=`echo "${IPS}" | grep "-"`

if [ ${CHKRNG} ]; then
OIFS=$IFS
IFS="-"
SIP=
EIP=
for A in ${IPS}
do
if [ ! ${SIP} ]; then
SIP=${A}
else
EIP=${A}
fi
done
IFS=$OIFS

if [[ ${SIP} -gt ${EIP} ]]; then
echo "Start IP : ${SIP} greater than End IP : ${EIP}"
else
CIP=${SIP}
while [[ ${CIP} -le ${EIP} ]]
do
echo "Exec [${LCMD}] on ${LSUB}.${CIP}"
ssh ${LSUB}.${CIP} "$LCMD"
echo
CIP=$(($CIP + 1))
done
fi
else
echo "Exec [${LCMD}] on ${LSUB}.${IPS}"
ssh ${LSUB}.${IPS} "$LCMD"
echo
fi
}


if [[ $# -lt 3 ]]; then
echo "Not enough parameter."
echo "Usage : $0 "
echo "e.g. $0 192.168.0 ls 1 3 5"
exit -1
fi

ALLARGV=$@

if [[ -z ${ALLARGV} ]]; then
echo "Usage : $0 "
echo "e.g. $0 192.168.0 ls 1 3 5"
exit -1
fi

# separate Command and Machine Numbers
SUBNET=$1
CMD=$2
shift 2

if [[ -z "$@" ]]; then
echo "Please input "
echo "e.g $0 192.168.0 \"ls -l\" \"1-3\""
exit -1
fi

for A in $@
do
exec_cmd ${SUBNET} ${A} "${CMD}"
done

exit 0

2008年6月18日 星期三

disable browser : checkloaduri

為了讓 browser 可以call local program來行, 要disable 一些安全設定.

Firefox 1.0.x 或較早版本流覽器
在地址欄中鍵入 "about:config". 找到 "security.checkloaduri"一項 (你可以在過濾中鍵入 "security.check" 以快速尋找) 當前這個值顯示為 "true". 雙擊這一行內容. 這個值會轉變為 "false". 現在本機上的檔可以被正常讀取.

Firefox 1.5.x 或更新版本流覽器
尋找 Firefox 在硬碟中的使用者設定, 這是一個包含8個字的隨機字串目錄 (下例中[12341234]是隨機的8位元字串):
· Windows : "C:\Documents and Settings\username\Application Data\Mozilla\Firefox\Profiles[12341234].default\"
· Linux : "/home/username/.mozilla/firefox/[12341234].default/"
· Mac : /username/Library/Application Support/Firefox/Profiles/[12341234].default/
在這個目錄中建立一個名為 "user.js" 的文字檔案, 然後把下面幾條 rule 放進去:
user_pref("capability.policy.policynames", "localfilelinks");
user_pref("capability.policy.localfilelinks.sites", "http://www.abc.com http://www.def.com");
user_pref("capability.policy.localfilelinks.checkloaduri.enabled", "allAccess");
如此, 便可讓 www.abc.com 及 www.def.com 經網頁呼叫 user 本機的檔案.

opening page

讀書時貪得意寫的, 用類似原理, 現在用來做 console program waiting signal.


#include <stdio.h>
#include <termios.h>
#include <unistd.h>

#define COLOR "^[[%d;%dm"
#define POSITION "^[[%d;%df"
#define CLEAR "^[[2J"

struct termios save_termios;

main()
{
op();
printf(CLEAR);
}

tty_reset()
{
if (tcsetattr(STDIN_FILENO,TCSAFLUSH,&save_termios) < 0)
exit(-1);
return(0);
}

tty_cbreak(work,times)
int work;
int times;
{
int i;
char c;
struct termios buf;

if (tcgetattr(STDIN_FILENO,&save_termios)<0)
exit(0);
buf=save_termios;
buf.c_lflag &= ~(ECHO | ICANON);
buf.c_cc[VMIN] = work;
buf.c_cc[VTIME] = times;
if (tcsetattr(STDIN_FILENO,TCSAFLUSH,&buf) < 0)
exit(-1);
return(0);
}

op()
{
int work,times;
int x,y,z;
int cr=30;
int ef=1;
char c=0;

printf(CLEAR);

printf(POSITION,22,5);
printf("^[[5;37mPress any Key to continue!");

work=0;times=1;
tty_cbreak(work,times);

while (c==0)
{
read(STDIN_FILENO,&c,1);
y=1;
for (x=6;x<15;x++)
{
printf(POSITION,x,y++);
if (ef==0)ef=1;else ef=0;
if (cr==38)cr=31;
printf(COLOR,ef,cr++);
printf("VVV");
}
for (x=15;x>5;x--)
{
printf(POSITION,x,y++);
if (ef==0)ef=1;else ef=0;
if (cr==38)cr=31;
printf(COLOR,ef,cr++);
printf("VVV");
}

for (x=0;x<10000;x++)
for (y=0;y<50;y++)
;
}
tty_reset();
}

2008年6月17日 星期二

系統保安

最近 USB手指遺失和資料外洩或棄掉事件弄得沸沸盪盪, 公司還是沒甚麼警覺性. 那些所謂特權階級繼續把敏感的資料傳來傳去.
冇事由自可, 有事咪又係怪 IT.
唉。。幾時都好,保安最大漏洞都係人為疏忽。
搞保安,搞程序,用家又話你阻住做野,有事時又話 IT 唔掂,真係好得意。
部電腦要login, 都有用家會牙痛咁聲,唔知佢地屋企鎖唔鎖門,要唔要用鎖匙開門架呢?