Wednesday, October 7, 2009

PERL SOAP Programming Tutorial

http://www.webmonkey.com/tutorial/Get_Your_Feet_Wet_With_SOAP

http://www.perl.com/pub/a/2001/01/soap.html

What Is SOAP?

SOAP, or the Simple Object Access Protocol, is a protocol designed to help web applications send messages to each other. It's got a very simple, portable structure, based on XML, and it can travel via HTTP, so it's lightweight and easy to implement, plus it's independent of language and platform. And thus the "Simple" part of the acronym, without which we'd now be learning about "OAP," which isn't nearly as puntastic.

Say this application you're writing needs to convert any European Economic Community currency to euros, and vice versa, at the current market rate. Your application can send a brief SOAP request to a server that does the calculation and returns a response, also in SOAP.

Why is this neat? Well, maybe your application is written in Java, and the server's doing its calculation in Perl. As long as they both use SOAP, the transaction is perfectly clean and simple. Also, if your application is running on a computer with web access, the SOAP messages can be sent via HTTP, through port 80. Using port 80 is nice because it doesn't require any extra setup, and any firewall sitting in the way assumes it's just more web traffic, and lets it through, without the long lines and cavity searches that often crop up if you set aside a dedicated port. Three, SOAP is an open protocol (consult the W3C's spec for SOAP 1.2 for more). There are a number of freely downloadable SOAP client and server tools and libraries that can be bent to your needs.


SOAPing Up

A SOAP message is no more and no less than an XML document, sent via some sort of transport protocol. HTTP is the most common way of sending SOAP messages, although SOAP is flexible enough to work with pretty much any transmission protocol you like.

In this tutorial, we're going to use SOAP::Lite, a set of Perl modules that makes dealing with SOAP a breeze. If you happen to dislike Perl, there are plenty of other implementations:Axis, which runs on Apache, Microsoft .NET SOAP, if you like Visual Basic or C#, or any of a hudred more. Or write your own. But here, today, we are using Perl.

So download and install SOAP::Lite. You can get SOAP::Lite from the developer's site, soaplite.com, or use CPAN to grab it automatically and take care of any dependency issues. You'll want to put it on your Web server as well as on the machine you're going to write a client application on. To install it from a command line, you can type ...

 perl -MCPAN -e

... which will give you a CPAN shell, then ...

 install SOAP::Lite

Follow the prompts, and soon enough you're all lathered up and ready to go.

SOAP::Lite requires MD5, XML::Parser, MIME::Lite, and MIME::Parser, which you probably have already if you have a relatively modern working Perl install. If not, CPAN's got 'em.

I'll wait here, blowing bubbles, until you've done that.


Carving A Quick SOAP Server

All set? Now we're going to put together a real quick SOAP server that will generate a (pseudo)random number between 1 and 10. All together now, in Perl:

  #!/usr/bin/perl -w
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI
->dispatch_to('Random')
->handle;
package Random;
sub choose {
$random = int(rand(9))+1;
return $random;
}

The second half of that script generates and returns a random number - the first half, with dispatch_to and handle, wraps the procedure in a SOAP bubble. In essence, it's telling the HTTP server that any calls that come in for Random should be sent to SOAP::Lite, via this script.

Save this script in your web server's cgi-bin directory, set its permissions so it's executable, and it's ready to go. Now let's write a corresponding client script to use it.

#!/usr/bin/perl -w
use SOAP::Lite;
print SOAP::Lite
-> uri('http://myserver.com/Random')
-> proxy('http://myserver.com/cgi-bin/random.cgi')
-> Random()
-> result;

Quick, update your resume. You've built a complete web service using SOAP. Run that script, and voila! A random number, requested and delivered via SOAP, just for you. Let's take a quick look at how it does what it does.

What's Happening?

When the client is run, it contacts the server via SOAP, gets a random number freshly generated for it, and outputs that number. The Perl modules are handling all the nasty behind-the-scenes work of creating HTTP headers and encoding XML schemas.

The proxy() method points to the URL of the actual procedure you want to run on the server -- in this case, the script we just wrote.

It's not to be confused with uri(), which is where the namespace of the server-side SOAP code is defined. The argument to the uri() method looks like a URL, but it's not. The "http://" part of uri()'s argument specifies the transport protocol; the server name is the server name, right; and then the class to be invoked is last. There isn't a directory called Random on the server.

What's happening behind the scenes is this:The client script sends a SOAP payload to the server via HTTP. This message consists of an HTTP header followed by a SOAP envelope generated by the Perl module.

What the client sends to the server actually looks something like this:

  POST /random.cgi HTTP/1.1
Content-Type:text/xml; charset="utf-8"
Content-Length:124







The "xmlns" lines declare default namespaces, whose purpose is to ensure that there's no conflict between the envelope we're creating and another one somewhere that might use the same name. We're referring to predefined namespaces for our schema and envelope, ones that are just sitting there on the W3C's machines waiting to be used. But this is the aspect that SOAP::Lite takes care of for you, so understanding it is secondary for the time being. Again, the W3C specification explains it all in great detail.

Seeing the SOAP Light

SOAP::Lite has a lot of tricks up its sleeve. For example, if you're going to be making a whole bunch of remote function calls, there's an easier way than sending each one on its way with
dispatch_to()
. If you initialize the module in your script with ...
  use SOAP::Lite +autodispatch =>
uri => 'http://myserver.com/Random'
proxy => 'http://myserver.com/cgi-bin/random.cgi'

... then any time your script calls an undefined method, the call will be autodispatched via SOAP to the proxy you specify.

There is a lot more to SOAP, and SOAP::Lite, but you're on your way, so I won't slow you down. For information about error handling techniques, passing complex information and objects back and forth, and suchlike, there is a bunch of useful documentation to be found at cookbook.soaplite.com.

If you need ideas or inspiration, XMethods.com has a useful and entertaining collection of web services you can check out and use.

Network Security Scan

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

Friday, September 4, 2009

Thursday, July 16, 2009

Problems && Solutions

  1. Problem: ssh login to one of the server was taking a long time (almost minutes).
  • Solution: The problem was solved by adding following lines at /etc/ssh/sshd_config:
UseDNS no

Friday, June 12, 2009

Monday, June 8, 2009

View actual physical memory usage on Linux

free

free command displays amount of total, free and used physical memory (RAM) in the system, as well as shoing information on shared memory, buffers, cached memory and swap space used by the Linux kernel.

Syntax of free

free -[options]

Example usage of free

free -m

The command will display information about physical memory in MB.

free -m -s 5

The command will activate continuous polling delay at 5 seconds apart, and then display memory status in megabytes on terminal. Any floating point number for delay can be specified.

free -t -m

Same with “free -m”, but -t switch will display a line containing the totals of physical memory and swap space.

Friday, June 5, 2009

Passwordless ssh login

1 Generate keys

Type:

   ssh-keygen -t rsa

And do not enter a passphrase unless you wanted to be prompted for one during file copying.

Here is what you will see:

   $ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/User/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/User/.ssh/id_rsa.
Your public key has been saved in /home/User/.ssh/id_rsa.pub.
The key fingerprint is:
5a:cd:2b:0a:cd:d9:15:85:26:79:40:0c:55:2a:f4:23 User@JEFF-CPU
2 Copy public to machines you want to upload to

id_rsa.pub is your public key. Copy it to ~/.ssh on target machine.

Put a copy of the public key file on each machine you want to log into. Name the copy authorized_keys (some implementations name this file authorized_keys2)

Then type:

     chmod 600 authorized_keys

Then make sure your home dir on the remote machine is not group or world writeable.

Wednesday, June 3, 2009

Keeping a Log Of Daily Network Traffic for ADSL or Dedicated Remote Linux Server

Almost a year ago, I wrote about Linux MRTG configuration how-to. However, some user seems to confused with MRTG, most users would like to know - how much traffic actually generated by ADSL/Cable service provider on daily and monthly basis.

MRTG is for network monitoring and it can be use to see how much traffic your server or ADSL router actually generated, however it will not tell you how much megabytes or gigabytes the daily traffic was. For all such home user and people having dedicated single Linux box hosted somewhere remote at IDC/ISP there is a tool called vnStat:

  • It is a console-base network traffic monitor for Linux (perfect tool for remote Linux box hosted at ISP)
  • It keeps a log of daily and monthly network traffic for the selected network interface(s).
  • It collects all data from /proc file system it means normal user can monitor traffic (no need to run vnstat as a root user)
  • Easy to setup & configure
  • Ease of use

Step # 1: Install vnstat

Debian / Ubuntu Linux user can install vnstat using apt-get command, enter:

# apt-get install vnstat 

Step # 2: Enable vnstat

Once installed, you need to create a database with the following command:

# vnstat -u -i eth0

Where,

  • -u :forces a database update for interface or creates the database if it doesn’t exist
  • -i eth0 : use to specify interface

Please note that it will start to collect data via cronjob:

0-55/5 * * * *   root    /usr/bin/vnstat -u

You do not have to install cronjob yourself; it should be automatically configure by apt-get.

Step # 3 View statistics

Display default traffic statistics

$ vnstat

Display daily traffic statistics

$ vnstat -d


Display monthly traffic statistics:

$ vnstat -m

Display all time top10 traffic days:

$ vnstat -t 


Try help option to get all query options:

$ vnstat --help


Source:- http://www.cyberciti.biz/tips/keeping-a-log-of-daily-network-traffic-for-adsl-or-dedicated-remote-linux-box.html

Linux display bandwidth usage on network interface by host

iftop command listens to network traffic on a named network interface, or on the first interface it can find which looks like an external interface if none is specified, and displays a table of current bandwidth usage by pairs of hosts. iftop is a perfect tool for remote Linux server over ssh session.

iftop must be run by the root or the user who has sufficient permissions to monitor all network traffic on the network interface.

Type iftop command at tge shell prompt to display traffic:
# iftop

However, iftop works best when you use filters. For example, if you want to find out how much bandwidth users are wasting or trying to figure out why the network is slow,
# iftop -f icmp
You can display or analyses packet flowing in and out of the 192.168.1.0/24 network:
# iftop -F 192.168.1.0/24
Disable output for DNS traffic by using filter code such as:
# iftop -f 'not port domain'

iftop has many options read man page for further information.

Source: http://www.cyberciti.biz/tips/linux-display-bandwidth-usage-on-network-interface-by-host.html

Restricting Weak SSL Ciphers, F5 BigIP

v9.x Software

SSL functions are performed and configured using SSL client and server profiles. Replace the clientssl parameter to serverssl to configure server SSL profiles.

Image:Applications-internet2-small.png Using the GUI

Assuming you use it as the parent profile, modify the built in clientssl profile cipher list as follows;
  1. Browse to Local TrafficProfilesSSLClient
  2. Select the clientssl profile
  3. Select ConfigurationAdvanced
  4. Enter the following in the Ciphers text box: -ALL:!ADH:!LOW:!EXP:!SSLv2:!NULL:RC4:RSA:HIGH:MEDIUM
  5. Click Update

All profiles using the clientssl parent profile are automatically updated.

Profiles not using this parent profile will have to be manually updated, selecting the relevant profile at step 2.

Image:Utilities-terminal-small.png Using the CLI

bigpipe profile clientssl clientssl \{ ciphers \-ALL:\!ADH:\!LOW:\!EXP:\!SSLv2:RC4:RSA:HIGH:MEDIUM\ \}


Source:- http://www.routerzone.eu/wiki/index.php/Restricting_Weak_SSL_Ciphers,_F5_BigIP

Tuesday, May 12, 2009

Monday, May 4, 2009

To test packet lost

#mtr -r -c 10 myhost.mydomain.com
HOST: xxxxx.xxx.xxx Loss% Snt Last Avg Best Wrst StDev
1. xxxxxxxx 0.0% 10 0.2 0.2 0.2 0.3 0.0
2. xxxxxxxx 0.0% 10 0.6 1.4 0.5 9.2 2.8
3. xxxxxxxx 0.0% 10 2.6 1.2 0.6 3.1 1.0

Sunday, April 5, 2009

Generating a syslog message

#logger -i -t yourname "This is a test"

=> Message should appear at /var/log/messages.

Thursday, April 2, 2009

MySQL: show disk space occupied by database

#mysql -uroot -p -D -e "show table status\G"| egrep "(Index|Data)_length" | awk 'BEGIN { rsum = 0 } { rsum += $2 } END { print rsum/1024/1024 "M"}'

Tuesday, February 3, 2009

rpmdb: Lock table is out of available locker entries

rpmdb: Lock table is out of available locker entries

If up2date throws some horrible Python errors and rpm says “rpmdb: Lock table is out of available locker entries”, you can restore your system to normality with the following:

The errors:
rpmdb: Lock table is out of available locker entries
error: db4 error(22) from db->close: Invalid argument
error: cannot open Packages index using db3 - Cannot allocate memory (12)
error: cannot open Packages database in /var/lib/rpm

Make a backup of /var/lib/rpm in case you break something:
tar cvzf rpmdb-backup.tar.gz /var/lib/rpm

Remove the Berkeley databases that rpm uses:
rm /var/lib/rpm/__db.00*

Make rpm rebuild the databases from scratch (may take a short while):
rpm --rebuilddb

Now, check rpm to make sure everything is okay:
rpm -qa | sort

Why does this happen?
When rpm accesses the Berkeley database files, it makes temporary locker entries within the tables while it searches for data. If you control-c your rpm processes often, this issue will occur much sooner because the locks are never cleared.

Saturday, January 24, 2009

Monday, January 12, 2009

Installing kernel-debuginfo on RHEL 5.2

#yum --enablerepo=rhel-debuginfo install kernel-debuginfo

Thursday, January 8, 2009

Finding Version of linux installed

#cat /etc/*release

Starting virtual server in a single user mode

From root domain:
#xm create {domain-name} -c
Example:- xm create rhel5b2-pv2 -c

-> follow the same steps to boot in single user mode as usual.