Friday, February 10, 2012

cURL Library


cURL (Client URL Library Functions)
  • Translated as the description of the author when Daniel Stenberg 
    curl is a comand line tool for transferring files with URL syntax from the command line using URL syntax file transfer program
  • I want the address of the page that I put an arbitrary value of the values ​​and return values ​​from page retrieving plays a role.
  • Most people want to use cURL in PHP probably be due to an HTTPS connection. 
    socket or other connection method, which many bother to use cURL thing in terms of speed even faster and easier to access because HTTPS.
  • cURL module must be installed on the server (Linux - curl.so, Windows - php_curl.dll expansion module required)

Available as a cURL
  • HTTPS certificates
  • HTTP POST
  • HTTP PUT
  • FTP upload
  • HTTP Form
  • cookie
  • authentication

cURL, Client URL Library Functions
  1. curl_init  : session initiation, return haendeulgap
  2. curl_setopt  : option settings
  3. curl_exec  : Run the curl
  4. curl_errno  : retrieve the error number.
  5. curl_error  : produces an error message.
  6. curl_getinfo  : Status information is returned.
  7. curl_close  : Close the curl session

[Example 1: POST data in a way (simple)]

$ post_data = array ( 
      "name" => "John Doe", 
      "Birthday" => "1980-08-20" 
      ); 
$ ch = curl_init (); 
curl_setopt ($ ch, CURLOPT_URL, http://www. example.com ); curl_setopt ($ ch, CURLOPT_POST, an); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_data); curl_exec ($ ch); ?> 
 
[Example 2: POST data in a way (function)]

function fetch_page ($ url, $ param, $ cookies, $ referer_url) { 
    if (strlen (Trim ($ referer_url)) == 0) $ referer_url = $ url;  
    $ curlsession = curl_init (); 
    curl_setopt ($ curlsession, CURLOPT_URL, \ "$ url \"); 
    curl_setopt ($ curlsession, CURLOPT_POST, an); 
    curl_setopt ($ curlsession, CURLOPT_POSTFIELDS, \ "$ param \"); 
    curl_setopt ($ curlsession, CURLOPT_POSTFIELDSIZE, 0); 
    curl_setopt ($ curlsession, CURLOPT_TIMEOUT, sixty); 
    if ($ && $ cookies cookies! = \ "\") { 
        curl_setopt ($ curlsession, CURLOPT_COOKIE, \ "$ cookies \"); 
    } 
    curl_setopt ($ curlsession, CURLOPT_HEADER, one); / / hedeogap is used to import. To get a cookie calm. 
    curl_setopt ($ curlsession, CURLOPT_USERAGENT, \ "Mozilla/4.0 (Compatible; MSIE 5.01; Windows NT 5.0) \"); 
    curl_setopt ($ curlsession, CURLOPT_REFERER, \ "$ referer_url \");  
    ob_start () ; 
    $ res = curl_exec ($ curlsession); 
    $ buffer = ob_get_contents (); 
    ob_end_clean (); 
    if (! $ buffer) { 
        $ returnVal = \ "Curl Fetch Error: \". curl_error ($ curlsession); 
    } else { 
        $ returnVal = $ buffer; 
    }  
    curl_close ($ curlsession);  
    Return $ returnVal; 
}  
?>
 [Example 3: Transfer Files

$ post_data ['Data [0]'] = "@ image/img_01.jpg"; 
$ post_data ['Data [0]'] = "@ image/img_02.jpg"; 
$ ch = curl_init (); 
curl_setopt ($ ch, CURLOPT_URL, http://www.example.com/upload.php ); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_data); $ postResult = curl_exec ($ ch) ; ?> 

[Example 4: https connection]

$ ch = curl_init (); 
curl_setopt ($ ch, CURLOPT_URL, " https://www.test.com "); / / access the URL address 
curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE); / / Check the certificate looks like true dll, a lot of time. 
/ / default value is true, be careful, because this part (https connection required at the time) 
curl_setopt ($ ch, CURLOPT_SSLVERSION, three); / / SSL version (https connection required at the time) 
curl_setopt ($ ch , CURLOPT_HEADER, 0); / / the header output or 
curl_setopt ($ ch, CURLOPT_POST, 1); / / Post Get Access or 
curl_setopt ($ ch, CURLOPT_POSTFIELDS, "var1 = str1 & var2 = str2"); / / Post Value Get like the way Write. 
curl_setopt ($ ch, CURLOPT_TIMEOUT, 30); / / TimeOut value 
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); / / Get result is 
$ result = curl_exec ($ ch); 
curl_close ($ ch); 
echo $ result; 
?>

[Example 5: curl using the Gmail login]
$ Src = " https:// ". $ gmailId.": ". $ gmailPw." @ mail.google.com / mail / feed / atom "; 
$ ch = curl_init (); 
curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, TRUE ); 
curl_setopt ($ ch, CURLOPT_TIMEOUT, 10); 
curl_setopt ($ ch, CURLOPT_HEADER, 0); 
curl_setopt ($ ch, CURLOPT_POST, true); 
curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ ch, CURLOPT_URL, $ url); 
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt ($ ch, CURLOPT_USERAGENT, 'My Agent Name'); 
curl_setopt ($ ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 
curl_setopt ($ ch, CURLOPT_COOKIEFILE, 'cookie . txt '); 
$ res = curl_exec ($ ch); 
curl_close ($ ch); 
/ ** The result is an Atom xml format. Using DOM or xml parsing function is to parse. ** / 
echo $ res; 
?>

[Example 6: cURL web page using the Import

function get_content ($ url) { 
    $ Agent = 'Mozilla/4.0 (Compatible; MSIE 6.0; Windows NT 5.0)'; 
    $ curlsession = curl_init (); 
    curl_setopt ($ curlsession, CURLOPT_URL, $ url); 
    curl_setopt ($ curlsession, CURLOPT_HEADER, 0); 
    curl_setopt ($ curlsession, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($ curlsession, CURLOPT_POST, 0); 
    curl_setopt ($ curlsession, CURLOPT_USERAGENT, $ Agent); 
    curl_setopt ($ curlsession, CURLOPT_REFERER, ""); 
    curl_setopt ($ curlsession, CURLOPT_TIMEOUT, 3); 
    $ buffer = curl_exec ($ curlsession); 
    $ Cinfo = curl_getinfo ($ curlsession); 
    curl_close ($ curlsession); 
    if ($ Cinfo ['http_code']! = two hundred) 
    { 
        Return "" ; 
    } 
    Return $ buffer; 

?>

ULTEO OPEN VIRTUAL DESKTOP

ULTEO OPEN VIRTUAL DESKTOP:
AN OPEN AND SECURE APPLICATION DELIVERY SOLUTION & PROFESSIONAL SERVICES.




4 reasons to use the OVD:
Supports both Windows and/or Linux apps.
Can be customized to your needs.
No upfront license fee.
Affordable subscription plans.


http://www.ulteo.com/home/en/home

Saturday, February 4, 2012

Common NFS errors & solutions

Common NFS errors & solutions:

1."Server Not Responding" Message
2.  "Access Denied" Message
3."Permission Denied" Message
4.  "Device Busy" Message

Error 1: If You Receive an NFS "Server Not Responding" Message

ping the nfs server from client

1.ping "nfs serer name or ip"

2./usr/bin/rpcinfo -p servername

The rpcinfo command should display the following processes:

    * portmap
    * nfs
    * mountd
    * status
    * nlockmgr
    * llockmgr

If any of these processes is not running, follow the below steps:


a.Make sure the /etc/rc.config.d/nfsconf file on the NFS server contains the following lines:

NFS_SERVER=1
START_MOUNTD=1

b.Make sure that the /etc/inetd.conf file on the NFS server does not contain a line to start rpc.mountd.
If it does, make sure the START_MOUNTD variable in /etc/rc.config.d/nfsconf is set to 0.

c.Issue the following command on the NFS server to start all the necessary NFS processes:

#/sbin/init.d/nfs.server start

Error 2: If You Receive an "Access Denied" Message

a.check the FS is exported or not

#/usr/sbin/showmount -e server_name

(If it is not exported means u have to edit /etc/exports file in NFS server and put the necessary entry and
then run the command
/usr/sbin/exportfs -a)

Error 3 :If You Receive a "Permission Denied" Message

a.Check the mount options in the /etc/fstab file on the NFS client. A directory you are attempting to write to may have
been mounted read-only.

b.Issue the ls -l command to check the HP-UX permissions on the server directory and on the client directory
that is the mount point. You may not be allowed access to the directory.

c.Issue the following command on the NFS server:

/usr/sbin/exportfs

Or, issue the following command on the NFS client:

/usr/sbin/showmount -e server_name

d. Check the export permissions on the exported directory. The directory may have been exported read-only to your client.
The system administrator of the NFS server can use the remount mount
option to mount the directory read/write without unmounting it

Error 4 : If You Receive a "Device Busy" Message

a.If you received the "device busy" message while attempting to mount a directory, try to access the mounted directory.
  If you can access it, then it is already mounted.
 
b.If you received the "device busy" message while attempting to unmount a directory, a user or process is currently using the directory. Wait until the process completes, or follow these steps:

 1.Issue the following command to determine who is using the mounted directory:

       /usr/sbin/fuser -cu local_mount_point

   The fuser(1M) command will return a list of process IDs and user names that are currently using the directory
   mounted under local_mount_point. This will help you decide whether to kill the processes or wait for them to complete.

 2. To kill all processes using the mounted directory, issue the following command:

            /usr/sbin/fuser -ck local_mount_point

 3. Try again to unmount the directory.

Short cut keys : Helpfull to every one


Different types of shell in UNIX and Linux


Unix Shell
A shell is  command interpreter between user and Unix kernel as well as provides a strong scripting language in UNIX
Following are the different types of Unix shells:
B shell - /bin/sh – This is the default Unix shell for many Unix operating systems .
Bourne shell was written by S. R. Bourne and its more emphasis is to use it as a scripting language rather than an interactive shell .
Some of the features are :
Provided support for environment variables using parameters and exportable variables.
Redirection of program output and error .
Command substitution using back quotes: `command`.
embed a file/commands using input redirector <<
“for ~ do ~ done” loops
“case ~ in ~ esac” for selecting and responding to a data value .
C-shell /bin/csh was designed to provide the interactive features lacking in b shell such as job control and aliasing .
K shell /bin/ksh – was created by David Korn and has features of both B shell and C shell along with some additional features .
Bash – the Bourne again shell was developed by GNU project .It is based on B shell language and has features of C and K shells.
tcsh is the default shell of FreeBSD and its descendants. Essentially it is C shell with programmable command line completion, command-line editing, and a few other features.
Zsh is a shell designed for interactive use and it has many of the useful features of bash, ksh, and tcsh along with many new features.

Unix Shell configuration files :


b shell
—————————————————–
shell prompt : $
executable file : /bin/sh
Read on interactive/non interactive login to bash
/etc/profile
~/.profile

bash shell
—————————————————–
shell prompt : $
executable file : /bin/bash
Read on interactive/non interactive login to bash
/etc/profile
~/.profile
~/.bash_profile
~/.bash_login
Always read on invoking bash
~/.bashrc
/etc/profile login login login
~/.profile login login

csh shell
——————————————————
shell prompt : %
executable file : /bin/csh
Read on csh shell invocation .
/etc/csh.cshrc
~/.cshrc
Read on interactive/non interactive login to tcsh shell
/etc/.login
~/.login
~/.logout
/etc/csh.login

ksh
—————————————————–
shell prompt : $
executable file : /bin/ksh
Read on interactive/non interactive login to bash
/etc/profile
~/.profile

tcsh shell
——————————————————
shell prompt : &
executable file : /bin/tcsh
Read on tcsh shell invocation .
~/.tcshrc
/etc/csh.cshrc
~/.cshrc
Read on interactive/non interactive login to tcsh shell
/etc/.login
~/.login
~/.logout
/etc/csh.login

zsh
—————————————————–
shell prompt : $
executable file : zsh
Configuration files :
Always read on invoking zsh
~/.zshenv always
/etc/zshenv always
only read on interactive login to zsh.
~/.zshrc
/etc/zshrc
Read on interactive/non interactive login to zsh
/etc/zprofile login
/etc/zlogin login
/etc/zlogout login
/.zprofile login
~/.zlogin login
~/.zlogout login

Repair Outlook PST File - Quick HOWTO

We need to Run the Inbox Repair Tool (scanpst.exe)  to repair the outlook PST file.
  1. Go to  "C:\Program Files\Microsoft Office\Office12"
  2. Double click the scanpst.exe file to open the program.
  3. Type the path and file name of the PST file, or Click Browse to locate the file.
  4. Click on the option which says Repair. (Ensure that backup check box is checked)
  5. This might take sometime depending on the size of the Outlook PST file.
You are done. This will repair most of the errors in PST file. Enjoy..!

Understanding VMSTAT Output - Explained

vmstat is a nice tool, to analyze the Linux / UNIX server performance.

 procs            memory                        swap        io       system    cpu
 r  b   swpd   free   buff  cache         si   so    bi    bo     in    cs       us sy id wa
 2  5 375912  19548  17556 477472    0    1     0     0      1     1        1  0  0  1
 0  4 375912  18700  17556 478264    0    0  1044   0     774  1329   8  1   0  91
 0  5 375912  17664  17556 479168    0    0  1160   0     764  1110   8  1   0  91
 1  8 375912  15836  17568 479796    0    0  1144   840  751  1622  16 7   0  78
 0  7 375912  19340  17576 480224    0    0  1224   148  587  1958  17 18  0  65
 2  0 375912  18288  17588 481036    0    0   812    0     845  1732  18 3  21  59
 0  2 375912  15868  17588 481528    0    0  1012   0     588   941   4   1  5   90 

Proc: 
-------
r: How many processes are waiting for CPU time.
b: Wait Queue - Process which are waiting for I/O (disk, network, user 
    input,etc..) 

Memory: 
-----------
swpd: shows how many blocks are swapped out to disk (paged). Total Virtual  
          memory usage. 
            
Note: you can see the swap area configured in server using "cat proc/swaps"

free: Idle Memory 
buff: Memory used as buffers, like before/after I/O operations
cache: Memory used as cache by the Operating System

Swap: 
---------
si: How many blocks per second the operating system is swapping in. i.e 
    Memory swapped in from the disk (Read from swap area to Memory)
so: How many blocks per second the operating system is swaped Out. i.e 
     Memory swapped to the disk (Written to swap area and cleared from 
     Memory)

In Ideal condition, We like to see si and so at 0 most of the time, and we definitely don’t like to see more than 10 blocks per second.

IO: 
------
bi: Blocks received from block device - Read (like a hard disk) 
bo: Blocks sent to a block device - Write

System: 
-------------
in: The number of interrupts per second, including the clock. 
cs: The number of context switches per second. 

CPU: 
--------
us: percentage of cpu used for running non-kernel code. (user time, including 
     nice time) 
sy: percentage of cpu used for running kernel code. (system time - network, IO 
     interrupts, etc) 
id: cpu idle time in percentage.
wa: percentage of time spent by cpu for waiting to IO.

If you used to monitor this data, you can understand how is your server doing during peak usage times. 

Note: the memory, swap, and I/O statistics are in blocks, not in bytes. In Linux, blocks are usually 1,024 bytes (1 KB).

What is SSL? - Quick Overview



What is SSL?

  • SSL (Secure Sockets Layer) is the standard security technology for establishing an encrypted link between a web server and a browser. This link ensures that all data passed between the web server and browsers remain private and integral.
  • SSL is an industry standard and is used by millions of websites for the protection of their online transactions.
  • Founded by Netscape initially. Current version of SSL is 3.0


How it Works?

To create an SSL connection a web server requires an SSL Certificate. SSL Connection uses public key/private key to encrypt and decrypt the data transferred between the server and browser. The following are the step by step communications happens during a SSL connection:
  • A browser requests a secure page (https://)
  • The web server responds and sends its public key with its SSL Certificate.
  • The browser checks the following:


              Is the certificate was issued by a trusted party (trusted root CA)
              Is the certificate is still valid?
              Is the certificate is related to the site contacted?

  •  The Browser maintains the list of Certification Authority whom it trusts, if it fails on any one of these checks the browser will display a warning to the end user letting them know that the site is not secured by SSL.
  • The browser then encrypts the URL required as well as other http data using random symmetric encryption key and encrypts that random symmetric encryption key using the public key. Then sends it to the server with the encrypted.
  •  The web server decrypts the symmetric encryption key using its private key and uses that symmetric key to decrypt the URL and http data.
  • The web server sends back the requested html document and http data encrypted with the same symmetric key.
  • The browser decrypts the http data and html document using the symmetric key and displays the information.


How to obtain a SSL Certificate to use with Web Server?


You can obtain the certificate for your domain from the Trusted Certificate Providers like VeriSign, Comodo, GoDaddy. You may get charged for the certificate issuance. Alternatively, you can create and use a self-signed certificate with your web server.

What are the details a certificate holds?

Typically an SSL Certificate will contain,
  •            Your domain name
  •            Your company name
  •            Your address
  •           Your city
  •           Your state and your country
  •          The expiration date of the Certificate
  •          Details of the Certification Authority responsible for the issuance of the Certificate.


 How do you know whether the browser is using SSL?
  • The browsers provide users with a key indicator to let users know they are currently protected by an SSL encrypted session.
  • A lock icon in the lower right-hand corner or in the left-most side of the address bar indicating that, the server is using SSL connection.
  • Clicking on the lock icon displays your SSL Certificate and the details about it.
  • All SSL Certificates are issued to either companies or legally accountable individuals.

Friday, February 3, 2012

Understanding TOP command ouput in Linux


Top command provides a real-time look at what is happening with your system. Top produces so much output that a new user may get over whelmed with all that’s presented and what it means.
Let’s take a look at TOP one line at a time.

The first line in top:
top - 22:09:08 up 14 min,  1 user,  load average: 0.21, 0.23, 0.30
“22:09:08″ is the current time; “up 14 min” shows how long the system has been up for; “1 user” how many users are logged in; “load average: 0.21, 0.23, 0.30″ the load average of the system (1minute, 5 minutes, 15 minutes).
Load average is an extensive topic and to understand its inner workings can be daunting. The simplest of definitions states that load average is the cpu utilization over a period of time. A load average of 1 means your cpu is being fully utilized and processes are not having to wait to use a CPU. A load average above 1 indicates that processes need to wait and your system will be less responsive. If your load average is consistently above 3 and your system is running slow you may want to upgrade to more CPU’s or a faster CPU.
The second line in top:
Tasks:  82 total,   1 running,  81 sleeping,   0 stopped,   0 zombie
Shows the number of processes and their current state.
The third line in top:
Cpu(s):  9.5%us, 31.2%sy,  0.0%ni, 27.0%id,  7.6%wa,  1.0%hi, 23.7%si,  0.0%st
Shows CPU utilization details. “9.5%us” user processes are using 9.5%; “31.2%sy” system processes are using 31.2%; “27.0%id” percentage of available cpu; “7.6%wa” time CPU is waiting for IO.
When first analyzing the Cpu(s) line in top look at the %id to see how much cpu is available. If %id is low then focus on %us, %sy, and %wa to determine what is using the CPU.
The fourth and fifth lines in top:
Mem:    255592k total,   167568k used,    88024k free,    25068k buffers
Swap:   524280k total,        0k used,   524280k free,    85724k cached
Describes the memory usage. These numbers can be misleading. “255592k total” is total memory in the system; “167568K used” is the part of the RAM that currently contains information; “88024k free” is the part of RAM that contains no information; “25068K buffers and 85724k cached” is the buffered and cached data for IO.
So what is the actual amount of free RAM available for programs to use ?
The answer is: free + (buffers + cached)
88024k + (25068k + 85724k) = 198816k
How much RAM is being used by progams ?
The answer is: used – (buffers + cached)
167568k – (25068k + 85724k) = 56776k
The processes information:
Top will display the process using the most CPU usage in descending order. Lets describe each column that represents a process.
 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
3166 apache    15   0 29444 6112 1524 S  6.6  2.4   0:00.79 httpd
PID – process ID of the process
USER – User who is running the process
PR – The priority of the process
NI – Nice value of the process (higher value indicates lower priority)
VIRT – The total amount of virtual memory used
RES – Resident task size
SHR – Amount of shared memory used
S – State of the task. Values are S (sleeping), D (uninterruptible sleep), R (running), Z(zombies), or (stopped or traced)
%CPU – Percentage of CPU used
%MEM – Percentage of Memory used
TIME+ – Total CPU time used
COMMAND – Command issued
Interacting with TOP
Now that we are able to understand the output from TOP lets learn how to change the way the output is displayed.
Just press the following key while running top and the output will be sorted in real time.

M – Sort by memory usage
P – Sort by CPU usage
T – Sort by cumulative time
z – Color display
k – Kill a process
q – quit
If we want to kill the process with PID 3161, then press “k” and a prompt will ask you for the PID number, and enter 3161.
Command Line Parameters with TOP
You can control what top displays by issuing parameters when you run top.
- d – Controls the delay between refreshes
- p – Specify the process by PID that you want to monitor
-n – Update the display this number of times and then exit
If we want to only monitor the http process with a PID of 3166
$ top -p 3166
If we want to change the delay between refreshes to 5 seconds
$ top -d 5