Wednesday, December 26, 2012

possible SYN flooding on port 80.

Issue:

possible SYN flooding on port 80.
internal dummy connection

1, original rules

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited


Canon PIXMA iX6520 Inkjet Business Printer 4895B002 (Google Affiliate Ad)
COMMIT

1, iptables rules
# Generated by iptables-save v1.4.7 on Wed Dec 26 16:40:57 2012
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [68044:6930314]
:syn_flood - [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j syn_flood
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
-A syn_flood -m limit --limit 1/sec --limit-burst 3 -j RETURN
-A syn_flood -j DROP
COMMIT

Tuesday, December 25, 2012

install cuckoo 5.0

1, install magic
Magic (Optional): for identifying files’ formats (otherwise use “file” command line utility)

2, install bottle
sudo easy_install -U bottle

bottle.py --version
Bottle 0.11.4


3, install   mongoDB
 sudo easy_install pymongo

Tuesday, December 11, 2012

get external ip

[root@ris cg]# curl http://ipecho.net/plain; echo
18.6.46.146

ssh: Could not resolve hostname note2: Name or service not known

 need to add node2.home


127.0.0.1   note1 localhost localhost.localdomain
::1         note1 localhost localhost.localdomain
192.168.1.239 node1.home  node1
192.168.1.238 node2.home  note2

hadoop tutorial

single node
http://www.michael-noll.com/tutorials/running-hadoop-on-ubuntu-linux-single-node-cluster/

Multi-Node Cluster

http://www.michael-noll.com/tutorials/running-hadoop-on-ubuntu-linux-multi-node-cluster/

Wednesday, December 5, 2012

ruby dbi error : uninitialized constant Mysql::Driver

need to install dbd-mysql

[cg@centos63 webbot]$ sudo gem install dbd-mysql

2.1 Make the file under certain folder not accessable directly




      .htaccess

We can modify the .htaccess file to achieve  this.


RewriteEngine On
Options –Indexes
RewriteRule ^(.+)$ /access_file.php [L,R]     
Make sure access_file.php is not in the same folder; otherwise it will generate a redirect loop

Tuesday, December 4, 2012

clear tomcat cache

CLEAR TOMCAT CACHE in /opt/tomcat/work/Catalina/localhost/aaa

libxml2 is missing - install nokogiri - centos

[cg@centos63 webbot]$ sudo yum install libxml2-devel libxslt-devel




[cg@centos63 webbot]$ sudo /usr/local/bin/gem install nokogiri
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.5.5
1 gem installed
Installing ri documentation for nokogiri-1.5.5...
Installing RDoc documentation for nokogiri-1.5.5...

ruby - create a resource / table

[cg@centos63 virusdepot]$ rails generate scaffold Viursdb id:integer docid:integer severity:string vname:string vtype:string discovered:string vlink:string vendor:string summary:text details:text






[cg@centos63 virusdepot]$ rake db:migrate
==  CreateViursdbs: migrating =================================================
-- create_table(:viursdbs)
   -> 0.1339s
==  CreateViursdbs: migrated (0.1342s) ========================================


mysql> desc viursdbs;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment |
| docid      | int(11)      | YES  |     | NULL    |                |
| severity   | varchar(255) | YES  |     | NULL    |                |
| vname      | varchar(255) | YES  |     | NULL    |                |
| vtype      | varchar(255) | YES  |     | NULL    |                |
| discovered | varchar(255) | YES  |     | NULL    |                |
| vlink      | varchar(255) | YES  |     | NULL    |                |
| vendor     | varchar(255) | YES  |     | NULL    |                |
| summary    | text         | YES  |     | NULL    |                |
| details    | text         | YES  |     | NULL    |                |
| created_at | datetime     | NO   |     | NULL    |                |
| updated_at | datetime     | NO   |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+
12 rows in set (0.00 sec)

Monday, December 3, 2012

how to send mail to a Gmail address using Postfix in localhost

http://souptonuts.sourceforge.net/postfix_tutorial.html

Monitoring a process using monit

[root@FSWWW cg]# vim /usr/local/etc/monitrc




check process StaticScan_files.rb with pidfile /opt/FS_QPID/StaticScan/StaticScan_files.rb.pid
    start program = "/opt/FS_QPID/StaticScan/StaticScan_files_control.rb start" with timeout 60 seconds
    stop program  = "/opt/FS_QPID/StaticScan/StaticScan_files_control.rb stop"
    if cpu > 60% for 2 cycles then alert
    if cpu > 80% for 5 cycles then restart
    if totalmem > 200.0 MB for 5 cycles then restart
    if children > 250 then restart
    if loadavg(5min) greater than 10 for 8 cycles then stop

check process query_files.rb with pidfile /opt/FS_QPID/PDF/querystatus/query_files.rb.pid
    start program = "/opt/FS_QPID/PDF/querystatus/query_files_control.rb start" with timeout 60 seconds
    stop program  = "/opt/FS_QPID/PDF/querystatus/query_files_control.rb stop"
    if cpu > 60% for 2 cycles then alert
    if cpu > 80% for 5 cycles then restart
    if totalmem > 200.0 MB for 5 cycles then restart
    if children > 250 then restart
    if loadavg(5min) greater than 10 for 8 cycles then stop

check process upload_files.rb with pidfile /opt/FS_QPID/PDF/uploadfile/upload_files.rb.pid
    start program = "/opt/FS_QPID/PDF/uploadfile/upload_files_control.rb start" with timeout 60 seconds
    stop program  = "/opt/FS_QPID/PDF/uploadfile/upload_files_control.rb stop"
    if cpu > 60% for 2 cycles then alert
    if cpu > 80% for 5 cycles then restart
    if totalmem > 200.0 MB for 5 cycles then restart
    if children > 250 then restart
    if loadavg(5min) greater than 10 for 8 cycles then stop

rake aborted!

[cg@centos63 virusdepot]$ rake db:create
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/home/cg/virusdepot/config/application.rb:7:in `<top (required)>'
/home/cg/virusdepot/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)






==============================
solution:
In your gemfile add:
gem 'execjs'
gem 'therubyracer', :platforms => :ruby

Friday, November 30, 2012

shutdown, reboot linux box

Monday, November 26, 2012

gcc

a, LAMP install
    1  yum install  httpd mysql-server php php-mysql
    2  service httpd start
    3  locate iptables
    4  yum install mlocate
    5  locate iptables
    6  updatedb
    7  locate iptables
    8  vim /etc/sysconfig/iptables
    9  service httpd restart
   10  service iptables restart
   11  ifconfig
   12  service mysqld start
   13  /usr/bin/mysqladmin -u root password 'yourpw'
   14  mysql -u root -p
   15  mysql -u root -p
   19  chkconfig httpd on
   20  chkconfig mysqld on
   21  cd /var/www/html/

b, Install development tools
 yum groupinstall "Development tools"
 yum install zlib-devel bzip2-devel openssl-devel  ncurses-devel
 yum install expat-devel gdbm-devel readline-devel sqlite-devel                              

c, Install python
yum install python-setuptools

d, install Ruby and Ruby on Rails
Download Ruby:
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
cd ../ruby-1.9.3-p327
sudo ./configure
sudo make
sudo make install

 wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz
 tar zxvf rubygems-1.8.24.tgz
 cd rubygems-1.8.24
 sudo /usr/local/bin/ruby setup.rb
 gem -v

 sudo /usr/local/bin/gem install rdoc
 sudo /usr/local/bin/gem install rails

Selenium automates browsers.

http://seleniumhq.org/

find prime number - python code

[chang@sstest python]$ cat primeno.py
#!/usr/bin/python

def if_prime_no(number_n):
    yes_p = 1
    if number_n > 2:
        for i in range(2, number_n):
            if number_n%i==0:
                    #print (str(i) + " is not a prime number ")
                    yes_p=0

        if yes_p == 1:
            #print (str(number_n) + " is a prime number")
            return 1
        else:
            #print (str(number_n) + " is not a prime number")
            return 0

def all_prime(number_n):
    p = [2]
    for i in range(2, number_n+1):
        if if_prime_no(int(i))==1:
            p.append(i)
    return p

while True:
    your_number = raw_input ("Please enter the number or 'exit' to exit:")
    if your_number == 'exit':
        break
    else:
        if if_prime_no(int(your_number))==1:
            print (your_number + " is a prime number")
        else:
            print (your_number + " is not a prime number")

        print all_prime(int(your_number))



======================================

[cng@sstest python]$ ./primeno.py
Please enter the number or 'exit' to exit:20
20 is not a prime number
[2, 3, 5, 7, 11, 13, 17, 19]
Please enter the number or 'exit' to exit:13
13 is a prime number
[2, 3, 5, 7, 11, 13]
Please enter the number or 'exit' to exit:exit

Sunday, November 25, 2012

add cucksandbox to ubuntu service

Step 1, create an file /etc/init.d/cuckoo

#!/bin/bash

## Fill in name of program here.
PROG="cuckoo"
PID_PATH="/opt/cuckoo/"

start() {
    if [ -e "$PID_PATH/$PROG.pid" ]; then
        ## Program is running, exit with error.
        echo "Error! $PROG is currently running!" 1>&2
        exit 1
    else
        cd /opt/cuckoo
        python cuckoo.py 2>&1 >/var/log/$PROG &
        echo "$PROG started"
        touch "$PID_PATH/$PROG.pid"
    fi
}

stop() {
    if [ -e "$PID_PATH/$PROG.pid" ]; then
        kill `ps aux | grep cuckoo.py | grep -v 'grep' | awk '{print $2}'`

        rm "$PID_PATH/$PROG.pid"

        echo "$PROG stopped"
    else
        ## Program is not running, exit with error.
        echo "Error! $PROG not started!" 1>&2
        exit 1
    fi
}

## Check to see if we are running as root first.
## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html
if [ "$(id -u)" != "0" ]; then
    echo "This script must be run as root" 1>&2
    exit 1
fi


case "$1" in
    start)
        start
        exit 0
    ;;
    stop)
        stop
        exit 0
    ;;
    reload|restart|force-reload)
        stop
        start
        exit 0
    ;;
    **)
        echo "Usage: $0 {start|stop|reload}" 1>&2
        exit 1
    ;;
esac
        
Step 2: start or stop service
root@cuckoodesktop32:~# /etc/init.d/cuckoo stop
root@cuckoodesktop32:~# /etc/init.d/cuckoo start

Step 3, make it start automatically
root@cuckoodesktop32:~# update-rc.d cuckoo defaults

Saturday, November 24, 2012

python restful server

http://flask.pocoo.org/docs/quickstart/

http://publish.luisrei.com/articles/flaskrest.html


https://github.com/twilio/flask-restful


ubuntu install easy_install

sudo apt-get install python-setuptools

linux check port open

cng@cuckoodesktop32:~$ netstat -ntulp
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 ::1:631                 :::*                    LISTEN      -
udp        0      0 0.0.0.0:35312           0.0.0.0:*                           -
udp        0      0 127.0.0.1:53            0.0.0.0:*                           -
udp        0      0 0.0.0.0:68              0.0.0.0:*                           -
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -
udp6       0      0 :::5353                 :::*                                -
udp6       0      0 :::35649                :::*                                -

cuckoosadbox integrate with virustotal

cng@cuckoodesktop32:/opt/cuckoo$ vim modules/processing/virustotal.py

http://www.xors.me/?p=5313

Thursday, November 22, 2012

update mysql table enum


mysql> alter  table FS_table change sengine sengine enum('PDF','Emtector','A','vast','Bd','FProt');

Tuesday, November 20, 2012

add openfire to windows services

1, run cmd as administrator

2,  run this command:
C:\ss\Openfire\bin>openfire-service.exe /install
Installed service 'Openfire'.

Monday, November 19, 2012

avira liunx installation

1, download:
http://premium.avira-update.com/package/wks_avira/unix/en/pers/antivir_workstation-pers.tar.gz

2, download key
http://dl1.avgate.net/down/windows/hbedv.key

sudo cp hbedv_key /usr/lib/AntiVir/guard/hbedv.key

you can use windows on linux system


3, restart service
sudo /etc/init.d/avguard restart

4, update database
[chang@FSWWW ~]$ sudo avupdate-guard



Tuesday, November 13, 2012

cuckoo & malware tools

1, good site

http://bsa.isoftware.nl/

http://blog.michaelboman.org/2012/06/mart-malware-analyst-research-toolkit_25.html
http://contagiodump.blogspot.com/2011/11/nov-3-cve-2011-0611-1104statmentpdf.html
http://www.selectrealsecurity.com/malware-analysis
http://fumalwareanalysis.blogspot.com/
http://fumalwareanalysis.blogspot.com/p/malware-analysis-tutorials-reverse.html

2, conf pdf scan

update this file:
vim  analyzer/windows/packages/pdf.py
        p.execute(path="C:\\Program Files\\Adobe\\Reader 11.0\\Reader\\AcroRd32.exe", args=arg, suspended=True)

Monday, November 12, 2012

good templates

http://screenhero.com/

http://www.mediafire.com/

http://www.cuckoosandbox.org/index.html

Tuesday, October 30, 2012

Tuesday, October 23, 2012

is missing psych (for YAML output).

[root@CentOS63Empty ~]# gem -v
/usr/local/rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.

solution:
1, download yaml
 [root@centos63 yaml-0.1.4]# wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz                          

2, compile and install
tar zxvf yaml-0.1.4.tar.gz
 cd yaml-0.1.4
 sudo ./configure
 sudo make
 sudo make install

centos 6 epel and yum install git

CentOS 6:

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
 

Enable the remi repository

sudo vim /etc/yum.repos.d/remi.repo
....
enabled=1
.... 

 

You may need do yum clean all if you have error:
"Requires: libcurl.so.3 "
 
Then do:
yum install git
 


Monday, October 22, 2012

best online free icon generator

http://www.chimply.com/Generator#badge

ruby daemon debug

issue: use start cannot start daemon and no error log
[root@FSWWW uploadfile]# ./upload_files_control.rb start


solution:
try to use run
[root@FSWWW uploadfile]# ./upload_files_control.rb run
upload_files.rb: process with pid 22303 started.
/opt/FS_QPID/PDF/uploadfile/upload_files.rb:16:in `initialize': No such file or
        from /opt/FS_QPID/PDF/uploadfile/upload_files.rb:16:in `open'
        from /opt/FS_QPID/PDF/uploadfile/upload_files.rb:16:in `initialize'
        from /opt/FS_QPID/PDF/uploadfile/upload_files.rb:101:in `new'
        from /opt/FS_QPID/PDF/uploadfile/upload_files.rb:101
        from /usr/lib/ruby/gems/1.8/gems/daemons-1.1.9/lib/daemons/application.r
        from /usr/lib/ruby/gems/1.8/gems/daemons-1.1.9/lib/daemons/application.r
        from /usr/lib/ruby/gems/1.8/gems/daemons-1.1.9/lib/daemons/application.r
        from /usr/lib/ruby/gems/1.8/gems/daemons-1.1.9/lib/daemons/controller.rb
        from /usr/lib/ruby/gems/1.8/gems/daemons-1.1.9/lib/daemons.rb:147:in `ru
        from /usr/lib/ruby/gems/1.8/gems/daemons-1.1.9/lib/daemons/cmdline.rb:10
        from /usr/lib/ruby/gems/1.8/gems/daemons-1.1.9/lib/daemons/cmdline.rb:10
        from /usr/lib/ruby/gems/1.8/gems/daemons-1.1.9/lib/daemons.rb:146:in `ru
        from ./upload_files_control.rb:16

Wednesday, October 3, 2012

check qpid queue

[cng@FSWWW ~]$ drain 'queue_PDF; {mode: browse}'

./consumer.rb:7: uninitialized constant Qpid::Connection (NameError)

run ruby qpid error:
ruby code
================================================
#!/usr/bin/env ruby

require "rubygems"
require "qpid"
require "socket"

conn = Qpid::Connection.new(TCPSocket.new("localhost", 5672))
conn.start(10)
#ssn = conn.session("qpid_consumer")
===================================================

error:
./consumer.rb:7: uninitialized constant Qpid::Connection (NameError)

Solution:
[cg@FSWWW ruby]$ sudo yum install ruby-qpid


install qpid in ubuntu 12

apt-get install qpidd qpid-tools qpid-doc qpid-client python-qpid-extras-
qmf python-qpid python-cqpid

Thursday, September 27, 2012

Wednesday, September 26, 2012

install qpid in centos 6

To install the Qpid Python client library:
    # yum install python-qpid
To install the Qpid broker:
    # yum install qpid-cpp-server
To start the Qpid broker:
    # service qpidd start
To have the Qpid broker started at boot time:
    # chkconfig qpidd on
Install qpid-tools
[root@FSWWW ~]# yum install qpid-tools
 

OpenVPN can connect, but no LAN Acess

I setup an openvpn, but no LAN access when I connected to VPN

Here is the steps to fix it:
1, logon to openvpn server and check this file
[root@openvpn ~]# cat /proc/sys/net/ipv4/ip_forward
0


2, if it returns 0, that's the root cause. But you cannot modify this file directly.

3, You need change ip_forward to 1 permanent
open file and change net.ipv4.ip_forward to 1 , about line 7:
[root@openvpn ~]# vim /etc/sysctl.conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 1


 4, Reboot the server or you can do this to avoid rebooting
[root@openvpn ~]# sysctl -p

[root@openvpn ~]# sysctl -w net.ipv4.route.flush=1




5, reconnect to you VPN


Tuesday, September 25, 2012

openvpn hangs forever

openvpn use 443, 943, and 1194, need to forward all these port in your router.

http://docs.openvpn.net/frequently-asked-questions/

"
Short answer: TCP 443, TCP 943, UDP 1194
Long answer: By default OpenVPN Access Server has 2 OpenVPN daemons running. One of them on UDP port 1194 and another on TCP 443. We recommend that you use the UDP port because this functions better for an OpenVPN tunnel. However, many public locations block all sorts of ports except very common ones like http, https, ftp, pop3, and so on. Therefore we also have TCP 443 as an option. TCP port 443 is the default port for https:// (SSL) traffic and so this is usually allowed through at the user’s location.
TCP port 943 is the port where the web server interface is listening by default. You can either approach this directly using a URL like https://yourserverhostnamehere:943/ or by approaching it through the standard https:// port TCP 443, since the OpenVPN daemon will automatically internally route browser traffic to TCP 943 by default. (https://yourserverhostnamehere/).
"

Monday, September 24, 2012

Saturday, September 22, 2012

Patch ESXi 5

1, download patch from VMware.com, mine is ESXi500-201207001.zip

2, Enable ESXi 5 ssh

3, scp ESXi500-201207001.zip to ESXi

4, make sure file is not broken
This file size is:
~ # ls /vmfs/volumes/datastore1/ -l
-rw-r--r--    1 root     root          594036729 Sep 23 01:54 ESXi500-201207001.zip

5, do update
~ # esxcli software vib install -d /vmfs/volumes/datastore1/ESXi500-201207001.zip

If you see the error like:
Could not download from depot at zip:/vmfs/volumes/datastore1/ESXi500-201207001.zip?index.xml, skipping (('zip::/vmfs/volumes/datastore1/ESXi500-201207001.zip?index.xml', '', "Error extracting index.xml from ::/vmfs/volumes/datastore1/ESXi500-201207001.zip: [Errno 2] No such file or directory: :/vmfs/volumes/datastore1/ESXi500-201207001.zip?index.xml'"))
url = zip:
:/vmfs/volumes/datastore1/ESXi500-201207001.zip?index.xml
Please refer to the log file for more details.

This means this zip file has some issue:
1, not exist
or 2, broken

Wednesday, July 25, 2012

curl send file with filename

Put filename in the header
curl -H "Content-type: application/octet-stream"  -H "Filename: install.log"  -X POST http://127.0.0.1:5000/messages --data-binary @install.log

Friday, June 22, 2012

first qpid ruby example

Step 1: Add Exchange, Queue, and bind them.

[root@localhost qpidclient]# qpid-config -a guest/guest@localhost add exchange topic mytopic  --durable
[root@localhost qpidclient]# qpid-config -a guest/guest@localhost add queue myqueue
[root@localhost qpidclient]# qpid-config -a guest/guest@localhost bind mytopic myqueue

Using qpid-tool to check if add exchange and queue  successfully.


[root@localhost qpidclient]# qpid-tool
qpid: list exchange
Objects of type org.apache.qpid.broker:exchange
    ID   Created   Destroyed  Index
    ===============================================
    104  13:17:03  -          103.
    111  14:36:44  -          103.mytopic
 qpid: list queue
Objects of type org.apache.qpid.broker:queue
    ID   Created   Destroyed  Index
    ==============================================================
    117  14:38:50  -          103.myqueue


Step 2: Ruby Qpid producer code / server
[root@localhost qpidclient]# vim producer.rb
#!/usr/bin/env ruby

require "rubygems"
require "qpid"
require "socket"

conn = Qpid::Connection.new(TCPSocket.new("localhost", 5672),
                                         :username => "guest",
                                         :password => "guest")
conn.start(10)

ssn = conn.session("qpid_producer")

# create a queue
ssn.queue_declare("myqueue")
ssn.exchange_declare("mytopic", :type => "topic")

dp = ssn.delivery_properties(:routing_key => "myqueue")
mp = ssn.message_properties(:content_type => "text/plain")

ssn.message_transfer(:message => Qpid::Message.new(dp, mp, "hi5"))
while line = gets.strip
  break if line =~ /^(bye)$/i
  ssn.message_transfer(:message => Qpid::Message.new(dp, mp, line.strip))
end
ssn.message_transfer(:message => Qpid::Message.new(dp, mp, "exit"))
ssn.sync

ssn.close()
conn.close()




Step 3 QPID consumer code:


[root@localhost qpidclient]# vim consumer.rb
#!/usr/bin/env ruby

require "rubygems"
require "qpid"
require "socket"

conn = Qpid::Connection.new(TCPSocket.new("localhost", 5672),
                                         :username => "guest",
                                         :password => "guest")
conn.start(10)

ssn = conn.session("qpid_consumer")

incoming = ssn.incoming("messages")
ssn.message_subscribe(
  :destination => "messages",
  :queue => "myqueue",
  :accept_mode => ssn.message_accept_mode.none
)

# start incoming message flow
incoming.start()

while true
 body = incoming.get().body
 puts body
 break if body == "bye"
end

ssn.close()
conn.close()

Step 4: run producer and consumer
[root@localhost qpidclient]# ./producer.rb
hi
hello


[root@localhost qpidclient]# ./consumer.rb
hi
hello



Thursday, June 14, 2012

mysql change root password

mysql change root password

1, To setup root password for first time, use mysqladmin command at shell prompt as follows:
$ mysqladmin -u root password NEW_PASSWORD

2, update a root password,

$mysqladmin -u root -p'oldpassword' password newpass

For example,change old password 123 to 456
$ mysqladmin -u root -p123 password '456'

Monday, June 11, 2012

centos install git - use yum install

1,  Add the EPEL repository, then install it using yum.

  wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
 
2, Install DAG's GPG key and Verify the package you have downloaded
    rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
    rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm

3, Install it
 rpm -i rpmforge-release-0.5.2-2.el5.rf.i386.rpm

4, install git using yum
  yum install git

Thursday, May 31, 2012

ESX VM - How to reset your password in Ubuntu

1, You need  hold down the Shift key during bootup.

2, From the boot menu, select recovery mode.

3, After you select recovery mode, then select "root shell prompt".

4, add user and passwd 

Tuesday, May 29, 2012

max width for image

<style type="text/css">
.my_img {
    max-width: 500px;
    /* Resize the image for IE6 */
    width: expression(this.width > 500 ? 500: true);
}
</style>

Thursday, May 24, 2012

squid add Password Authentication Using NCSA

1, generate /etc/squid/squid_passwd file

htpasswd -c /etc/squid/squid_passwd www


2, [root@localhost ~]# vim /etc/squid/squid.conf
a, Add this to the auth_param section of squid.conf
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/squid_passwd

b, add this line in the buttom of acl
acl ncsa_users proxy_auth REQUIRED

c, add this line in the top of http_access
http_access allow ncsa_users