<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eXpand yOur cReativity</title>
	<atom:link href="http://blog.bhushangahire.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bhushangahire.net</link>
	<description>by Bhushan G Ahire</description>
	<lastBuildDate>Wed, 17 Feb 2010 06:22:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setup Capistrano to deploy Rails application on Amazon EC2 with Git</title>
		<link>http://blog.bhushangahire.net/2010/02/17/setup-capistrano-to-deploy-rails-application-on-amazon-ec2-with-git/</link>
		<comments>http://blog.bhushangahire.net/2010/02/17/setup-capistrano-to-deploy-rails-application-on-amazon-ec2-with-git/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 06:22:49 +0000</pubDate>
		<dc:creator>Bhushan G Ahire</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://blog.bhushangahire.net/?p=155</guid>
		<description><![CDATA[1: Create a new Rails app - we'll call is 'deploytest'
$ rails deploytest
$ cd deploytest
2: Create a local Git repository for it
$ git init
$ git add *
$ git commit -a -m 'initial commit'
$ git status
3: Create a couple of Capistrano files
$ capify .
4: Edit config/deploy.rb
# The name of your app
set :application, "deploytest"
# The directory on [...]]]></description>
			<content:encoded><![CDATA[<div class="post-body entry-content">1: Create a new Rails app - we'll call is 'deploytest'</p>
<pre class="prettyprint"><span class="pln">$ rails deploytest
$ cd deploytest</span></pre>
<p>2: Create a local Git repository for it</p>
<pre class="prettyprint"><span class="pln">$ git init
$ git add </span><span class="pun">*</span><span class="pln">
$ git commit </span><span class="pun">-</span><span class="pln">a </span><span class="pun">-</span><span class="pln">m </span><span class="str">'initial commit'</span><span class="pln">
$ git status</span></pre>
<p>3: Create a couple of Capistrano files</p>
<pre class="prettyprint"><span class="pln">$ capify </span><span class="pun">.</span></pre>
<p>4: Edit config/deploy.rb</p>
<pre class="prettyprint"><span class="com"># The name of your app</span><span class="pln">
</span><span class="kwd">set</span><span class="pln"> </span><span class="pun">:</span><span class="pln">application</span><span class="pun">,</span><span class="pln"> </span><span class="str">"deploytest"</span><span class="pln">
</span><span class="com"># The directory on the EC2 node that will be deployed to</span><span class="pln">
</span><span class="kwd">set</span><span class="pln"> </span><span class="pun">:</span><span class="pln">deploy_to</span><span class="pun">,</span><span class="pln"> </span><span class="str">"/var/www/apps/#{application}"</span><span class="pln">
</span><span class="com"># The type of Source Code Management system you are using</span><span class="pln">
</span><span class="kwd">set</span><span class="pln"> </span><span class="pun">:</span><span class="pln">scm</span><span class="pun">,</span><span class="pln"> </span><span class="pun">:</span><span class="pln">git
</span><span class="com"># The location of the LOCAL repository relative to the current app</span><span class="pln">
</span><span class="kwd">set</span><span class="pln"> </span><span class="pun">:</span><span class="pln">repository</span><span class="pun">,</span><span class="pln">  </span><span class="str">"."</span><span class="pln">
</span><span class="com"># The way in which files will be transferred from repository to remote host</span><span class="pln">
</span><span class="com"># If you were using a hosted github repository this would be slightly different</span><span class="pln">
</span><span class="kwd">set</span><span class="pln"> </span><span class="pun">:</span><span class="pln">deploy_via</span><span class="pun">,</span><span class="pln"> </span><span class="pun">:</span><span class="pln">copy

</span><span class="com"># The address of the remote host on EC2 (the Public DNS address)</span><span class="pln">
</span><span class="kwd">set</span><span class="pln"> </span><span class="pun">:</span><span class="pln">location</span><span class="pun">,</span><span class="pln"> </span><span class="str">"ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com"</span><span class="pln">
</span><span class="com"># setup some Capistrano roles</span><span class="pln">
role </span><span class="pun">:</span><span class="pln">app</span><span class="pun">,</span><span class="pln"> location
role </span><span class="pun">:</span><span class="pln">web</span><span class="pun">,</span><span class="pln"> location
role </span><span class="pun">:</span><span class="pln">db</span><span class="pun">,</span><span class="pln">  location</span><span class="pun">,</span><span class="pln"> </span><span class="pun">:</span><span class="pln">primary </span><span class="pun">=&gt;</span><span class="pln"> </span><span class="kwd">true</span><span class="pln">

</span><span class="com"># Set up SSH so it can connect to the EC2 node - assumes your SSH key is in ~/.ssh/id_rsa</span><span class="pln">
</span><span class="kwd">set</span><span class="pln"> </span><span class="pun">:</span><span class="pln">user</span><span class="pun">,</span><span class="pln"> </span><span class="str">"root"</span><span class="pln">
ssh_options</span><span class="pun">[:</span><span class="pln">keys</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="typ">File</span><span class="pun">.</span><span class="pln">join</span><span class="pun">(</span><span class="pln">ENV</span><span class="pun">[</span><span class="str">"HOME"</span><span class="pun">],</span><span class="pln"> </span><span class="str">".ssh"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"id_rsa"</span><span class="pun">)]</span><span class="pln">
</span></pre>
<p>The only account on a default EC2 instance is root. You probably want to create a second user that is responsible for your application.</p>
<p>5: Copy your SSH public key to your EC2 node</p>
<pre class="prettyprint"><span class="pln">$ scp </span><span class="pun">-</span><span class="pln">i </span><span class="pun">~</span><span class="str">/my-ec2-keypair ~/</span><span class="pun">.</span><span class="pln">ssh</span><span class="pun">/</span><span class="pln">id_rsa</span><span class="pun">.</span><span class="pln">pub root@ec2</span><span class="pun">-</span><span class="lit">xxx</span><span class="pun">-</span><span class="lit">xxx</span><span class="pun">-</span><span class="lit">xxx</span><span class="pun">-xxx</span><span class="lit">.compute</span><span class="pun">-</span><span class="lit">1.amazonaws</span><span class="pun">.</span><span class="pln">com</span><span class="pun">:</span><span class="str">/root/</span><span class="pun">.</span><span class="pln">ssh</span><span class="pun">/</span><span class="pln">authorized_keys2</span></pre>
<p>NOTE the filename authorized_keys2 - not authorized_keys!!</p>
<p>6: Setup the EC2 node for Capistrano deployment.<br />
From your LOCAL machine, not the EC2 node:</p>
<pre class="prettyprint"><span class="pln">$ cap deploy</span><span class="pun">:</span><span class="pln">setup</span></pre>
<p>7: Finally, deploy your application</p>
<pre class="prettyprint"><span class="pln">$ cap deploy</span></pre>
<p>You will see lots of output and with this dummy application some of those will report errors/warnings. Don't worry about that for now.</p>
<p>8: Check that the Deployment was successful<br />
Connect to the EC2 node with SSH the regular way, cd to the app directory and check that everything is there. If that is all working then you are ready to deploy a real application and add custom tasks for managing the database, restarting the server etc.</p>
<p>Bear in mind that Capistrano add new 'releases' of your software in separate directories and symlinks the 'current' directory to the latest. So the root of your deployed application is the 'current' subdirectory.</p>
<p>Hope this will help you setting up your ec2 instance with capistrano.</p></div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://blog.bhushangahire.net/2010/02/17/setup-capistrano-to-deploy-rails-application-on-amazon-ec2-with-git/&amp;title=Setup+Capistrano+to+deploy+Rails+application+on+Amazon+EC2+with+Git" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.bhushangahire.net/2010/02/17/setup-capistrano-to-deploy-rails-application-on-amazon-ec2-with-git/&amp;title=Setup+Capistrano+to+deploy+Rails+application+on+Amazon+EC2+with+Git" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.bhushangahire.net/2010/02/17/setup-capistrano-to-deploy-rails-application-on-amazon-ec2-with-git/&amp;title=Setup+Capistrano+to+deploy+Rails+application+on+Amazon+EC2+with+Git" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://blog.bhushangahire.net/2010/02/17/setup-capistrano-to-deploy-rails-application-on-amazon-ec2-with-git/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.bhushangahire.net/2010/02/17/setup-capistrano-to-deploy-rails-application-on-amazon-ec2-with-git/&amp;t=Setup+Capistrano+to+deploy+Rails+application+on+Amazon+EC2+with+Git" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Setup+Capistrano+to+deploy+Rails+application+on+Amazon+EC2+with+Git+-+http://blog.bhushangahire.net/2010/02/17/setup-capistrano-to-deploy-rails-application-on-amazon-ec2-with-git/+(via+@bhushangahire)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://blog.bhushangahire.net/2010/02/17/setup-capistrano-to-deploy-rails-application-on-amazon-ec2-with-git/&amp;title=Setup+Capistrano+to+deploy+Rails+application+on+Amazon+EC2+with+Git&amp;summary=1%3A%20Create%20a%20new%20Rails%20app%20-%20we%27ll%20call%20is%20%27deploytest%27%0D%0A%24%20rails%20deploytest%0D%0A%24%20cd%20deploytest%0D%0A2%3A%20Create%20a%20local%20Git%20repository%20for%20it%0D%0A%24%20git%20init%0D%0A%24%20git%20add%20%2A%0D%0A%24%20git%20commit%20-a%20-m%20%27initial%20commit%27%0D%0A%24%20git%20status%0D%0A3%3A%20Create%20a%20couple%20of%20Capistrano%20files%0D%0A%24%20capify%20.%0D%0A4%3A%20Edit%20config%2Fdeploy.rb%0D%0A%23%20The%20name%20o&amp;source=eXpand yOur cReativity" rel="nofollow" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=Setup+Capistrano+to+deploy+Rails+application+on+Amazon+EC2+with+Git&amp;du=http://blog.bhushangahire.net/2010/02/17/setup-capistrano-to-deploy-rails-application-on-amazon-ec2-with-git/&amp;cn=1%3A%20Create%20a%20new%20Rails%20app%20-%20we%27ll%20call%20is%20%27deploytest%27%0D%0A%24%20rails%20deploytest%0D%0A%24%20cd%20deploytest%0D%0A2%3A%20Create%20a%20local%20Git%20repository%20for%20it%0D%0A%24%20git%20init%0D%0A%24%20git%20add%20%2A%0D%0A%24%20git%20commit%20-a%20-m%20%27initial%20commit%27%0D%0A%24%20git%20status%0D%0A3%3A%20Create%20a%20couple%20of%20Capistrano%20files%0D%0A%24%20capify%20.%0D%0A4%3A%20Edit%20config%2Fdeploy.rb%0D%0A%23%20The%20name%20o" rel="nofollow" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="sexy-tumblr">
			<a href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fblog.bhushangahire.net%2F2010%2F02%2F17%2Fsetup-capistrano-to-deploy-rails-application-on-amazon-ec2-with-git%2F&amp;t=Setup+Capistrano+to+deploy+Rails+application+on+Amazon+EC2+with+Git" rel="nofollow" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://blog.bhushangahire.net/2010/02/17/setup-capistrano-to-deploy-rails-application-on-amazon-ec2-with-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing PostgreSQL on Snow Leopard 10.6</title>
		<link>http://blog.bhushangahire.net/2010/02/15/installing-postgresql-on-snow-leopard-10-6/</link>
		<comments>http://blog.bhushangahire.net/2010/02/15/installing-postgresql-on-snow-leopard-10-6/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 08:41:59 +0000</pubDate>
		<dc:creator>Bhushan G Ahire</dc:creator>
				<category><![CDATA[MAC Tiger]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">http://blog.bhushangahire.net/?p=152</guid>
		<description><![CDATA[
Installing PostgreSQL 8.3
First, you’ll need to install Xcode if you haven’t already. This is available on the Snow Leopard DVD in the Optional Installs directory.
Second, if you aren’t already using it, download Mac Ports for Snow Leopard and install it. Mac Ports has come a long way in the last few years and will make [...]]]></description>
			<content:encoded><![CDATA[<div class="entry">
<h2>Installing PostgreSQL 8.3</h2>
<p>First, you’ll need to install Xcode if you haven’t already. This is available on the Snow Leopard DVD in the Optional Installs directory.</p>
<p>Second, if you aren’t already using it, download <a href="http://distfiles.macports.org/MacPorts/MacPorts-1.8.0-10.6-SnowLeopard.dmg">Mac Ports for Snow Leopard</a> and install it. Mac Ports has come a long way in the last few years and will make your life much easier.</p>
<p>Once those are installed, run the following command:<br />
<code>sudo port install postgresql83 postgresql83-server</code></p>
<h2>Setup Your First Database</h2>
<p>At the very end of the install it tells you how to setup your first database:</p>
<p><code>sudo mkdir -p /opt/local/var/db/postgresql83/defaultdb</code><br />
<code>sudo chown postgres:postgres /opt/local/var/db/postgresql83/defaultdb</code><br />
<code>sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb'</code></p>
<p>You’ll also want to setup Postgres to auto-run as a server on start up.</p>
<p><code>sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist</code></p>
<p>If you want to start it right now, you can either reboot or do the following:</p>
<p><code>sudo su postgres -c '/opt/local/lib/postgresql83/bin/postgres -D /opt/local/var/db/postgresql83/defaultdb'</code></p>
<h2>Make psql Available from the Command Line</h2>
<p>The executable files for PostgreSQL get shoved into a non-standard place (just like MySQL), so you’ll need to edit the default profile.</p>
<p><code>sudo vi /etc/profile</code></p>
<p>You can also do this using <code>sudo mate /etc/profile</code> if you aren’t comfortable in VI.</p>
<p>The <code>PATH=</code> line needs to be changed to include the PostgreSQL bin directory.</p>
<p>Mine was <code>PATH="/opt/local/bin:$PATH"</code> and is now:</p>
<p><code>PATH="/opt/local/bin:/opt/local/sbin:/opt/local/lib/postgresql83/bin:$PATH"</code></p>
<p>If you open a new terminal window you can now type <code>psql</code> and it will find it.</p>
<h2>Create a New User and Database</h2>
<p>By default, PostgreSQL creates a <em>postgres</em> user for you. However, it’s not good practice to use the default and it’s a pain in the ass. Let’s just create a new database user to make it easier.</p>
<p><code>createuser --superuser macusername -U postgres</code></p>
<p>You need to change <code>macusername</code> to your mac username. This will make your life ALOT easier. Trust me here.</p>
<p>Next, create your database:</p>
<p><code>createdb my_database</code></p>
<h2>Installing the PostgreSQL Ruby Gem</h2>
<p>Unlike the MySQL driver, we don’t need to pass the ARCHFLAGS variable as 64 bit. PostgreSQL comes with both 32 and 64-bit versions. Yeah!</p>
<p><code>sudo gem install postgres-pr</code></p>
<p>Per Tom’s comment below, we should be using the native driver for better performance.</p>
<p><code>sudo env ARCHFLAGS="-arch x86_64" gem install pg</code></p>
<h2>Configuring your Rails Application</h2>
<p>Inside your Ruby on Rails application, open up config/database.yml and change your development adapter to be similar to the following:</p>
<p><code>development:<br />
  adapter: postgresql<br />
  database: defaultdb<br />
  username: defaultdb<br />
</code></p>
<p>You can change <code>defaultdb</code> to the name you need for your application.</p>
</p></div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://blog.bhushangahire.net/2010/02/15/installing-postgresql-on-snow-leopard-10-6/&amp;title=Installing+PostgreSQL+on+Snow+Leopard+10.6" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.bhushangahire.net/2010/02/15/installing-postgresql-on-snow-leopard-10-6/&amp;title=Installing+PostgreSQL+on+Snow+Leopard+10.6" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.bhushangahire.net/2010/02/15/installing-postgresql-on-snow-leopard-10-6/&amp;title=Installing+PostgreSQL+on+Snow+Leopard+10.6" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://blog.bhushangahire.net/2010/02/15/installing-postgresql-on-snow-leopard-10-6/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.bhushangahire.net/2010/02/15/installing-postgresql-on-snow-leopard-10-6/&amp;t=Installing+PostgreSQL+on+Snow+Leopard+10.6" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Installing+PostgreSQL+on+Snow+Leopard+10.6+-+http://blog.bhushangahire.net/2010/02/15/installing-postgresql-on-snow-leopard-10-6/+(via+@bhushangahire)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://blog.bhushangahire.net/2010/02/15/installing-postgresql-on-snow-leopard-10-6/&amp;title=Installing+PostgreSQL+on+Snow+Leopard+10.6&amp;summary=%0D%0AInstalling%20PostgreSQL%208.3%0D%0AFirst%2C%20you%E2%80%99ll%20need%20to%20install%20Xcode%20if%20you%20haven%E2%80%99t%20already.%20This%20is%20available%20on%20the%20Snow%20Leopard%20DVD%20in%20the%20Optional%20Installs%20directory.%0D%0ASecond%2C%20if%20you%20aren%E2%80%99t%20already%20using%20it%2C%20download%20Mac%20Ports%20for%20Snow%20Leopard%20and%20install%20it.%20Mac%20Ports%20has%20come%20a%20long%20way%20in%20t&amp;source=eXpand yOur cReativity" rel="nofollow" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=Installing+PostgreSQL+on+Snow+Leopard+10.6&amp;du=http://blog.bhushangahire.net/2010/02/15/installing-postgresql-on-snow-leopard-10-6/&amp;cn=%0D%0AInstalling%20PostgreSQL%208.3%0D%0AFirst%2C%20you%E2%80%99ll%20need%20to%20install%20Xcode%20if%20you%20haven%E2%80%99t%20already.%20This%20is%20available%20on%20the%20Snow%20Leopard%20DVD%20in%20the%20Optional%20Installs%20directory.%0D%0ASecond%2C%20if%20you%20aren%E2%80%99t%20already%20using%20it%2C%20download%20Mac%20Ports%20for%20Snow%20Leopard%20and%20install%20it.%20Mac%20Ports%20has%20come%20a%20long%20way%20in%20t" rel="nofollow" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="sexy-tumblr">
			<a href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fblog.bhushangahire.net%2F2010%2F02%2F15%2Finstalling-postgresql-on-snow-leopard-10-6%2F&amp;t=Installing+PostgreSQL+on+Snow+Leopard+10.6" rel="nofollow" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://blog.bhushangahire.net/2010/02/15/installing-postgresql-on-snow-leopard-10-6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Send SMS from Ruby On Rails application using web service, SOAP API</title>
		<link>http://blog.bhushangahire.net/2010/01/15/send-sms-from-ruby-on-rails-application-using-web-service-soap-api/</link>
		<comments>http://blog.bhushangahire.net/2010/01/15/send-sms-from-ruby-on-rails-application-using-web-service-soap-api/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 11:09:19 +0000</pubDate>
		<dc:creator>Bhushan G Ahire</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[mailserve]]></category>
		<category><![CDATA[sms]]></category>
		<category><![CDATA[soap]]></category>

		<guid isPermaLink="false">http://blog.bhushangahire.net/2010/01/15/send-sms-from-ruby-on-rails-application-using-web-service-soap-api/</guid>
		<description><![CDATA[SOAP4R is a Ruby library for accessing Web Services via SOAP. Recently I had a chance to explore SOAP4R. Here's how to get started with it.

Installation
Although Ruby 1.8.x comes with SOAP4R in its standard library, it is an old, buggy version. I highly recommend using the latest gem (1.5.8 as of the this update). It [...]]]></description>
			<content:encoded><![CDATA[<p class="entry">SOAP4R is a Ruby library for accessing Web Services via SOAP. Recently I had a chance to explore SOAP4R. Here's how to get started with it.</p>
<p class="entry"><span id="more-3"></span></p>
<h3 class="entry">Installation</h3>
<p class="entry">Although Ruby 1.8.x comes with SOAP4R in its standard library, it is an old, buggy version. I <strong>highly</strong> recommend using the latest gem (1.5.8 as of the this update). It has one dependency, httpclient.</p>
<p class="entry"><code>gem install soap4r --include-dependencies</code></p>
<h3 class="entry">Service</h3>
<p class="entry">There are many services available to send SMS but I prefer to use,</p>
<h4 class="entry">MailServe-SMS</h4>
<p class="entry"><a href="http://qlc.in/ms/overview.htm" target="_blank">MailServe-SMS</a>, text messaging service, is everything you need for fast, no-frills, no-fuss text messaging. A quick and easy way to send SMS.</p>
<p class="entry">Let’s explore these further.</p>
<h3 class="entry">Method 1: Read the WSDL at run-time</h3>
<p class="entry">&#160;</p>
<div class="entry">
<pre class="ruby"><span style="font-weight: bold; color: rgb(204,0,102)">require</span> <span style="color: rgb(153,102,0)">&quot;soap/wsdlDriver&quot;</span>
wsdl = <span style="color: rgb(153,102,0)">&quot;http://sms.qlc.co.in/smsapi.wsdl&quot;</span>
driver = <span style="font-weight: bold; color: rgb(102,102,255)">SOAP::WSDLDriverFactory</span>.<span style="color: rgb(153,0,204)">new</span><span style="font-weight: bold; color: rgb(0,102,0)">(</span>wsdl<span style="font-weight: bold; color: rgb(0,102,0)">)</span>.<span style="color: rgb(153,0,204)">create_rpc_drive</span></pre>
</div>
<p class="entry">&#160;</p>
<p class="entry">A single call to a driver factory reads the WSDL file, and creates a driver class for you to use, complete with the methods defined by the service. What if your service requires authentication? The driver inherits methods from httpclient, so you can specify its options as you would for httpclient:</p>
<p class="entry">Once driver is get initialised you need to call SMS sending API i.e. <b>SendSMSRequest</b>.</p>
<div class="entry">
<pre class="ruby">driver.<span style="color: rgb(153,0,204)">SendSMSRequest</span><span style="font-weight: bold; color: rgb(0,102,0)">(</span><span style="color: rgb(153,102,0)">&quot;username&quot;, <span style="color: rgb(153,102,0)">&quot;password&quot;</span>, <span style="color: rgb(153,102,0)">&quot;sender_no&quot;</span>, <span style="color: rgb(153,102,0)">&quot;from_no&quot;</span>, <span style="color: rgb(153,102,0)">&quot;message&quot;</span></span><span style="font-weight: bold; color: rgb(0,102,0)">)</span></pre>
</div>
<p class="entry">&#160;</p>
<p class="entry">Once This will return you response <strong>200 SMS sent successfully </strong>on success else if the information submitted was wrong then <strong>500 Information submitted was incomplete</strong>.</p>
<p class="entry">&#160;</p>
<h3 class="entry">Method 2: Generate classes from WSDL</h3>
<p class="entry">SOAP4R installs a command-line utility called 'wsdl2ruby' which can generate a client or server.</p>
<p class="entry"><strong>Coming soon…..</strong></p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://blog.bhushangahire.net/2010/01/15/send-sms-from-ruby-on-rails-application-using-web-service-soap-api/&amp;title=Send+SMS+from+Ruby+On+Rails+application+using+web+service%2C+SOAP+API" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.bhushangahire.net/2010/01/15/send-sms-from-ruby-on-rails-application-using-web-service-soap-api/&amp;title=Send+SMS+from+Ruby+On+Rails+application+using+web+service%2C+SOAP+API" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.bhushangahire.net/2010/01/15/send-sms-from-ruby-on-rails-application-using-web-service-soap-api/&amp;title=Send+SMS+from+Ruby+On+Rails+application+using+web+service%2C+SOAP+API" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://blog.bhushangahire.net/2010/01/15/send-sms-from-ruby-on-rails-application-using-web-service-soap-api/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.bhushangahire.net/2010/01/15/send-sms-from-ruby-on-rails-application-using-web-service-soap-api/&amp;t=Send+SMS+from+Ruby+On+Rails+application+using+web+service%2C+SOAP+API" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Send+SMS+from+Ruby+On+Rails+application+using+web+service%2C+SOAP+API+-+http://blog.bhushangahire.net/2010/01/15/send-sms-from-ruby-on-rails-application-using-web-service-soap-api/+(via+@bhushangahire)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://blog.bhushangahire.net/2010/01/15/send-sms-from-ruby-on-rails-application-using-web-service-soap-api/&amp;title=Send+SMS+from+Ruby+On+Rails+application+using+web+service%2C+SOAP+API&amp;summary=SOAP4R%20is%20a%20Ruby%20library%20for%20accessing%20Web%20Services%20via%20SOAP.%20Recently%20I%20had%20a%20chance%20to%20explore%20SOAP4R.%20Here%27s%20how%20to%20get%20started%20with%20it.%20%20%20%20Installation%20%20Although%20Ruby%201.8.x%20comes%20with%20SOAP4R%20in%20its%20standard%20library%2C%20it%20is%20an%20old%2C%20buggy%20version.%20I%20highly%20recommend%20using%20the%20latest%20gem%20%281.5.8%20as%20o&amp;source=eXpand yOur cReativity" rel="nofollow" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=Send+SMS+from+Ruby+On+Rails+application+using+web+service%2C+SOAP+API&amp;du=http://blog.bhushangahire.net/2010/01/15/send-sms-from-ruby-on-rails-application-using-web-service-soap-api/&amp;cn=SOAP4R%20is%20a%20Ruby%20library%20for%20accessing%20Web%20Services%20via%20SOAP.%20Recently%20I%20had%20a%20chance%20to%20explore%20SOAP4R.%20Here%27s%20how%20to%20get%20started%20with%20it.%20%20%20%20Installation%20%20Although%20Ruby%201.8.x%20comes%20with%20SOAP4R%20in%20its%20standard%20library%2C%20it%20is%20an%20old%2C%20buggy%20version.%20I%20highly%20recommend%20using%20the%20latest%20gem%20%281.5.8%20as%20o" rel="nofollow" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="sexy-tumblr">
			<a href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fblog.bhushangahire.net%2F2010%2F01%2F15%2Fsend-sms-from-ruby-on-rails-application-using-web-service-soap-api%2F&amp;t=Send+SMS+from+Ruby+On+Rails+application+using+web+service%2C+SOAP+API" rel="nofollow" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://blog.bhushangahire.net/2010/01/15/send-sms-from-ruby-on-rails-application-using-web-service-soap-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Paypal Instant Payment Notification in Rails with Active Merchant</title>
		<link>http://blog.bhushangahire.net/2009/08/05/paypal-instant-payment-notification-in-rails-with-active-merchant/</link>
		<comments>http://blog.bhushangahire.net/2009/08/05/paypal-instant-payment-notification-in-rails-with-active-merchant/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 08:56:04 +0000</pubDate>
		<dc:creator>Bhushan Ahire</dc:creator>
				<category><![CDATA[Amazon EC2]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[active merchant]]></category>
		<category><![CDATA[payment]]></category>

		<guid isPermaLink="false">http://blog.bhushangahire.net/?p=139</guid>
		<description><![CDATA[Active Merchant makes it extremely simple to use Paypal IPN. Here is a simple guide for getting IPN up and running.
Sign up for a Paypal sandbox account
Paypal provides a sandbox environment that mimics their production environment, with the exception that it doesn’t actually process the transactions.  This is extremely useful for development and testing. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://home.leetsoft.com/am/">Active Merchant</a> makes it extremely simple to use Paypal <abbr title="Instant Payment Notification"><span class="caps">IPN</span></abbr>. Here is a simple guide for getting <span class="caps">IPN</span> up and running.</p>
<h3>Sign up for a <a href="https://developer.paypal.com/">Paypal sandbox account</a></h3>
<p>Paypal provides a sandbox environment that mimics their production environment, with the exception that it doesn’t actually process the transactions.  This is extremely useful for development and testing.  It allows you to create multiple fake accounts and generate bank accounts and credit cards. More information can be found on Paypal’s <a href="http://www.paypal.com/cgi-bin/webscr?cmd=_ipn-test-about-outside">Testing Instant Payment Notification</a> page.</p>
<p>Unfortunately, I’ve signed up for two different developer accounts and I’ve had trouble logging in with both of them.  I’ve tried resetting my password, but I still can’t log in.  Fortunately, I already have my sandbox accounts set up and don’t really have a need for it (except to write this guide).</p>
<h3>Create a Personal account and add a credit card</h3>
<p>After you sign up for your developer account, create a personal sandbox account and add a credit card.</p>
<h3>Create a Business account and add a checking</h3>
<p>Next, create a business sandbox account and add a checking account.</p>
<h3>Install the money gem</h3>
<pre>sudo gem install money</pre>
<h3>Install the Active Merchant plugin</h3>
<pre>script/plugin install http://activemerchant.googlecode.com/svn/trunk/active_merchant</pre>
<h3>Create a form that submits to Paypal</h3>
<p>Include <code>ActiveMerchant::Billing::Integrations</code> in a controller to add Active Merchant’s helpers.</p>
<pre><code class="ruby"><span class="keywords">class</span> <span class="constants">PaymentsController</span> &lt; <span class="constants">ApplicationController</span>
  include <span class="constants">ActiveMerchant</span>:<span class="symbol">:Billing</span>:<span class="symbol">:Integrations</span>

  <span class="keywords">def</span> create
    <span class="instance">@enrollment</span> = current_user<span class="method">.enrollments</span><span class="method">.find</span><span class="brackets">(</span>params<span class="brackets">[</span><span class="symbol">:id</span><span class="brackets">]</span><span class="brackets">)</span>
  <span class="keywords">end</span>
<span class="keywords">end</span></code></pre>
<p>In the view, use <code>payment_service_for</code> to create a form that submits to Paypal to process the payment.</p>
<pre><code class="erb"><span class="tag">&lt;%</span> payment_service_for <span class="instance">@enrollment</span><span class="method">.id</span>, <span class="constants">PAYPAL_ACCOUNT</span>,
        <span class="symbol">:amount</span> =&gt; <span class="instance">@enrollment</span><span class="method">.course</span><span class="method">.deposit</span>, <span class="symbol">:currency</span> =&gt; <span class="string">'USD'</span>,
        <span class="symbol">:service</span> =&gt; <span class="symbol">:paypal</span> <span class="keywords">do</span> |service|

    service<span class="method">.customer</span> <span class="symbol">:first_name</span> =&gt; <span class="instance">@enrollment</span><span class="method">.student</span><span class="method">.first_name</span>,
        <span class="symbol">:last_name</span> =&gt; <span class="instance">@enrollment</span><span class="method">.student</span><span class="method">.last_name</span>,
        <span class="symbol">:phone</span> =&gt; <span class="instance">@enrollment</span><span class="method">.student</span><span class="method">.phone</span>,
        <span class="symbol">:email</span> =&gt; <span class="instance">@enrollment</span><span class="method">.student</span><span class="method">.email</span>
    service<span class="method">.billing_address</span> <span class="symbol">:city</span> =&gt; <span class="instance">@enrollment</span><span class="method">.student</span><span class="method">.city</span>,
        <span class="symbol">:address1</span> =&gt; <span class="instance">@enrollment</span><span class="method">.student</span><span class="method">.street</span>,
        <span class="symbol">:state</span> =&gt; <span class="instance">@enrollment</span><span class="method">.student</span><span class="method">.state</span>,
        <span class="symbol">:country</span> =&gt; <span class="string">'USA'</span>,
        <span class="symbol">:zip</span> =&gt; <span class="instance">@enrollment</span><span class="method">.student</span><span class="method">.zip</span>
    service<span class="method">.item_name</span> <span class="string">"#{@enrollment.course.program} Deposit"</span>
    service<span class="method">.invoice</span> <span class="instance">@enrollment</span><span class="method">.invoice</span><span class="method">.id</span>
    service<span class="method">.tax</span> <span class="string">'0.00'</span>

    service<span class="method">.notify_url</span> url_for<span class="brackets">(</span><span class="symbol"> <img src='http://blog.bhushangahire.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly_path</span> =&gt; <span class="constants">false</span>, <span class="symbol">:action</span> =&gt; <span class="string">'notify'</span><span class="brackets">)</span>
    service<span class="method">.return_url</span> url_for<span class="brackets">(</span><span class="symbol"> <img src='http://blog.bhushangahire.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly_path</span> =&gt; <span class="constants">false</span>,
        <span class="symbol">:controller</span> =&gt; <span class="string">'account'</span>, <span class="symbol">:action</span> =&gt; <span class="string">'show'</span><span class="brackets">)</span>
    service<span class="method">.cancel_return_url</span> url_for<span class="brackets">(</span><span class="symbol"> <img src='http://blog.bhushangahire.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly_path</span> =&gt; <span class="constants">false</span>,
        <span class="symbol">:controller</span> =&gt; <span class="string">'account'</span>, <span class="symbol">:action</span> =&gt; <span class="string">'show'</span><span class="brackets">)</span> <span class="tag">%&gt;</span>

    &lt;!-- display payment summary here --&gt;

    <span class="tag">&lt;%=</span> submit_tag <span class="string">'Make Payment'</span> <span class="tag">%&gt;</span>
<span class="tag">&lt;%</span> <span class="keywords">end</span> <span class="tag">%&gt;</span></code></pre>
<p>The code above refers to the constant <code>PAYPAL_ACCOUNT</code>, which I define in <code>environment.rb</code>.  I also set Active Merchant to use test mode, which directs it to use Paypal’s sandbox:</p>
<pre><code class="ruby"><span class="keywords">unless</span> <span class="constants">RAILS_ENV</span> == <span class="string">'production'</span>
  <span class="constants">PAYPAL_ACCOUNT</span> = <span class="string">'sandboxaccount@example.com'</span>
  <span class="constants">ActiveMerchant</span>:<span class="symbol">:Billing</span>:<span class="symbol">:Base</span><span class="method">.mode</span> = <span class="symbol">:test</span>
<span class="keywords">else</span>
  <span class="constants">PAYPAL_ACCOUNT</span> = <span class="string">'paypalaccount@example.com'</span>
<span class="keywords">end</span></code></pre>
<h3>Create an action that processes the <span class="caps">IPN</span></h3>
<p>After the above form submits to Paypal and the user makes a payment, Paypal will post data about the transaction to your server.  Set up an action to receive the post:</p>
<pre><code class="ruby">  <span class="keywords">def</span> notify
    notify = <span class="constants">Paypal</span>:<span class="symbol">:Notification</span><span class="method">.new</span><span class="brackets">(</span>request<span class="method">.raw_post</span><span class="brackets">)</span>
    enrollment = <span class="constants">Enrollment</span><span class="method">.find</span><span class="brackets">(</span>notify<span class="method">.item_id</span><span class="brackets">)</span>

    <span class="keywords">if</span> notify<span class="method">.acknowledge</span>
      <span class="instance">@payment</span> = <span class="constants">Payment</span><span class="method">.find_by_confirmation</span><span class="brackets">(</span>notify<span class="method">.transaction_id</span><span class="brackets">)</span> ||
        enrollment<span class="method">.invoice</span><span class="method">.payments</span><span class="method">.create</span><span class="brackets">(</span><span class="symbol">:amount</span> =&gt; notify<span class="method">.amount</span>,
          <span class="symbol">:payment_method</span> =&gt; <span class="string">'paypal'</span>, <span class="symbol">:confirmation</span> =&gt; notify<span class="method">.transaction_id</span>,
          <span class="symbol">:description</span> =&gt; notify<span class="method">.params</span><span class="brackets">[</span><span class="string">'item_name'</span><span class="brackets">]</span>, <span class="symbol">:status</span> =&gt; notify<span class="method">.status</span>,
          <span class="symbol">:test</span> =&gt; notify<span class="method">.test?</span><span class="brackets">)</span>
      begin
        <span class="keywords">if</span> notify<span class="method">.complete?</span>
          <span class="instance">@payment</span><span class="method">.status</span> = notify<span class="method">.status</span>
        <span class="keywords">else</span>
          logger<span class="method">.error</span><span class="brackets">(</span><span class="string">"Failed to verify Paypal's notification, please investigate"</span><span class="brackets">)</span>
        <span class="keywords">end</span>
      <span class="keywords">rescue</span> =&gt; e
        <span class="instance">@payment</span><span class="method">.status</span> = <span class="string">'Error'</span>
        <span class="keywords">raise</span>
      ensure
        <span class="instance">@payment</span><span class="method">.save</span>
      <span class="keywords">end</span>
    <span class="keywords">end</span>
    render <span class="symbol">:nothing</span> =&gt; <span class="constants">true</span>
  <span class="keywords">end</span></code></pre>
<p>Depending on the model for your application, this action will obviously look different. The important part is that you pass the raw post data from the request to <code>Paypal::Notification.new</code>, and call <code>notify.acknowledge</code> to connect back to Paypal to verify the data.</p>
<h3>Enable <span class="caps">IPN</span></h3>
<p>Lastly, log into the business account that you created above, go to <em>“Instant Payment Notification Preferences”</em> in your profile, and set the <span class="caps">URL</span> that Paypal should post back to after payments. (Note: this needs to be a publicly accessible <span class="caps">URL</span>.)</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://blog.bhushangahire.net/2009/08/05/paypal-instant-payment-notification-in-rails-with-active-merchant/&amp;title=Paypal+Instant+Payment+Notification+in+Rails+with+Active+Merchant" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.bhushangahire.net/2009/08/05/paypal-instant-payment-notification-in-rails-with-active-merchant/&amp;title=Paypal+Instant+Payment+Notification+in+Rails+with+Active+Merchant" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.bhushangahire.net/2009/08/05/paypal-instant-payment-notification-in-rails-with-active-merchant/&amp;title=Paypal+Instant+Payment+Notification+in+Rails+with+Active+Merchant" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://blog.bhushangahire.net/2009/08/05/paypal-instant-payment-notification-in-rails-with-active-merchant/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.bhushangahire.net/2009/08/05/paypal-instant-payment-notification-in-rails-with-active-merchant/&amp;t=Paypal+Instant+Payment+Notification+in+Rails+with+Active+Merchant" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Paypal+Instant+Payment+Notification+in+Rails+with+Active+Merchant+-+http://blog.bhushangahire.net/2009/08/05/paypal-instant-payment-notification-in-rails-with-active-merchant/+(via+@bhushangahire)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://blog.bhushangahire.net/2009/08/05/paypal-instant-payment-notification-in-rails-with-active-merchant/&amp;title=Paypal+Instant+Payment+Notification+in+Rails+with+Active+Merchant&amp;summary=Active%20Merchant%20makes%20it%20extremely%20simple%20to%20use%20Paypal%20IPN.%20Here%20is%20a%20simple%20guide%20for%20getting%20IPN%20up%20and%20running.%0A%0ASign%20up%20for%20a%20Paypal%20sandbox%20account%0APaypal%20provides%20a%20sandbox%20environment%20that%20mimics%20their%20production%20environment%2C%20with%20the%20exception%20that%20it%20doesn%E2%80%99t%20actually%20process%20the%20transact&amp;source=eXpand yOur cReativity" rel="nofollow" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=Paypal+Instant+Payment+Notification+in+Rails+with+Active+Merchant&amp;du=http://blog.bhushangahire.net/2009/08/05/paypal-instant-payment-notification-in-rails-with-active-merchant/&amp;cn=Active%20Merchant%20makes%20it%20extremely%20simple%20to%20use%20Paypal%20IPN.%20Here%20is%20a%20simple%20guide%20for%20getting%20IPN%20up%20and%20running.%0A%0ASign%20up%20for%20a%20Paypal%20sandbox%20account%0APaypal%20provides%20a%20sandbox%20environment%20that%20mimics%20their%20production%20environment%2C%20with%20the%20exception%20that%20it%20doesn%E2%80%99t%20actually%20process%20the%20transact" rel="nofollow" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="sexy-tumblr">
			<a href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fblog.bhushangahire.net%2F2009%2F08%2F05%2Fpaypal-instant-payment-notification-in-rails-with-active-merchant%2F&amp;t=Paypal+Instant+Payment+Notification+in+Rails+with+Active+Merchant" rel="nofollow" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://blog.bhushangahire.net/2009/08/05/paypal-instant-payment-notification-in-rails-with-active-merchant/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Step-By-Step setup slicehost server (fedora) for rails application.</title>
		<link>http://blog.bhushangahire.net/2009/07/22/step-by-step-setup-slicehost-server-fedora-for-rails-application/</link>
		<comments>http://blog.bhushangahire.net/2009/07/22/step-by-step-setup-slicehost-server-fedora-for-rails-application/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 10:11:00 +0000</pubDate>
		<dc:creator>Bhushan Ahire</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[setup]]></category>

		<guid isPermaLink="false">http://blog.bhushangahire.net/?p=136</guid>
		<description><![CDATA[





Hi all as I worked on setting up 4 to 5 servers, I thought its better to document the stuff so that I/developers can refer it, So I am documenting the step-by-step process for setting up the slicehost server for rails application work with nginx as a web server and mongrel as a rails application [...]]]></description>
			<content:encoded><![CDATA[<div id="content"><!--single.php--></p>
<p><!--loop--></p>
<p><!--post title--></p>
<div class="post-meta-top">
<div class="clearboth"></div>
<p><!--content with more link--></p>
<div>Hi all as I worked on setting up 4 to 5 servers, I thought its better to document the stuff so that I/developers can refer it, So I am documenting the step-by-step process for setting up the slicehost server for rails application work with <strong>nginx</strong> as a web server and <strong>mongrel</strong> as a rails application server.</div>
<div>
<h2>Update</h2>
<div class="level2">
<p>To update your system:</p>
<blockquote><p>yum update</p></blockquote>
</div>
<h2>MySQL</h2>
<div class="level2">
<p>to install mysql client and server apps</p>
<blockquote><p>yum install mysql-server</p></blockquote>
<p>The client package “mysql” will automatically be installed as a dependency.</p></div>
<h2>Apache</h2>
<div class="level2">
<blockquote><p>yum install httpd</p></blockquote>
</div>
<h2>PHP5</h2>
<div class="level2">
<p>To install php with soap, xml and mysql plugins:</p>
<blockquote><p>yum install php php-soap php-xml php-mysql</p></blockquote>
<p>some other php plugin utilities that are common:</p>
<blockquote><p>yum install php-mbstring php-gd</p></blockquote>
</div>
<h2>Ruby</h2>
<div class="level2">
<blockquote><p>yum install ruby</p></blockquote>
</div>
<h2>Utilities</h2>
<div class="level2">
<p>other useful utilities:</p>
<blockquote><p>yum install nano wget elinks subversion vi</p></blockquote>
</div>
</div>
<div>
<h2>Nginx</h2>
<div class="level2">
<p>install nginx web server:</p>
<blockquote><p>yum install nginx</p></blockquote>
</div>
<h2>Mongrel Cluster</h2>
<div class="level2">
<p>install mongrel_cluster:</p>
<blockquote><p>gem install mongrel_cluster –include-dependencies</p></blockquote>
</div>
<p>Setup your nginx configuration for your rails application and mongrel_cluster (proxy).</p>
<p>Below you found sample config file for nginx.conf (normally located in “/etc/nginx/conf/nginx.conf”)</p>
<blockquote>
<pre>user  deploy;
worker_processes  1;
error_log   logs/error.log debug;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
  include        conf/mime.types;
  default_type   application/octet-stream;
  sendfile        on;
  #tcp_nopush     on;
  keepalive_timeout  65;
  tcp_nodelay        on;
  gzip  on;
  gzip_min_length  1100;
  gzip_buffers     4 8k;
  gzip_types       text/plain;
  upstream mongrel {
    server 127.0.0.1:8000;
    server 127.0.0.1:8001;
  }
  server {
    listen       80;
    server_name  example.com;
    root /var/www/apps/example/current/public;
    index  index.html index.htm;
    location / {
      proxy_set_header  X-Real-IP  $remote_addr;
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect false;
      if (-f $request_filename/index.html) {
        rewrite (.*) $1/index.html break;
      }
      if (-f $request_filename.html) {
        rewrite (.*) $1.html break;
      }
      if (!-f $request_filename) {
        proxy_pass http://mongrel;
        break;
      }
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
  }
}</pre>
</blockquote>
</div>
<p>Restart the nginx server:</p>
<blockquote><p>/etc/init.d/nginx restart</p></blockquote>
<div>
<h2>Mongrel Configuration:</h2>
<p>Now Go to the application directory and create a configuration for Mongrel:</p>
<blockquote><p>mongrel_rails cluster::configure -e production -p 8000 -a 127.0.0.1 -N 2 -c /home/APP/production/APP/current</p></blockquote>
<p>it will create the config/mongrel_cluster.yml file; basically you do not need to edit it.</p>
<p>You can test cluster with</p>
<p>To Start:</p>
<blockquote><p>mongrel_rails cluster::start</p></blockquote>
<p>To Stop:</p>
<blockquote><p>mongrel_rails cluster::stop</p></blockquote>
<p>To Restart:</p>
<blockquote><p>mongrel_rails cluster::restart</p></blockquote>
</div>
<div>
<h2>Capistrano Configuration:</h2>
<p>Then create a configuration for Capistrano:</p>
<blockquote><p>cap –apply-to .</p></blockquote>
<p>we need to modify the generated file config/deploy.rb:</p>
<blockquote>
<pre>require 'mongrel_cluster/recipes'

#you set the APP name with the cap command
set :application, "APP"
#a path to your repository
set :repository, "svn+ssh://USERNAME@SVN_SERVER/projects/#{application}/trunk"

role :web, "SERVER"
role :app, "SERVER"
role :db, "SERVER", :primary =&gt; true

#where to deploy (copy the files) on the server; I created a special user APP for the</pre>
<pre>application (if you do not like it, replace the /home/#{application} part with your path
set :deploy_to, "/home/#{application}/production/#{application}"
set :mongrel_conf, "#{current_path}/config/mongrel_cluster.yml"
#if the server login name is different to the development computer login name; in my case</pre>
<pre>the user name is the APP nameset :user, "APP"</pre>
</blockquote>
<p>Make necessary changes to the config/database.yml file.</p></div>
<div>
<h2>Capistrano Deployment:</h2>
<p>Create the basic structure on the server:</p>
<blockquote><p>cap deploy:setup</p></blockquote>
<p>For the first deployment you can use cold deploy:</p>
<blockquote><p>cap cold_deploy</p></blockquote>
<p>After that for next deployments you have to use:</p>
<blockquote><p>cap deploy</p></blockquote>
<p>You can also run migration from capistrano with:</p>
<blockquote><p>cap deploy:migrate<sup>*</sup></p></blockquote>
<p><sup>*</sup> Note: It wont work for me, it migrating to the previous release available in the releses folder, So I suggest you manually run migration on server.</div>
<div>
<p>That’s it, your server is ready to run.</p>
<p>Hope this documentation will be helpful to you, Enjoy <img src='http://blog.bhushangahire.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</div>
<p><!--for paginate posts--></p>
<p><!--Post Meta--></div>
</div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://blog.bhushangahire.net/2009/07/22/step-by-step-setup-slicehost-server-fedora-for-rails-application/&amp;title=Step-By-Step+setup+slicehost+server+%28fedora%29+for+rails+application." rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.bhushangahire.net/2009/07/22/step-by-step-setup-slicehost-server-fedora-for-rails-application/&amp;title=Step-By-Step+setup+slicehost+server+%28fedora%29+for+rails+application." rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.bhushangahire.net/2009/07/22/step-by-step-setup-slicehost-server-fedora-for-rails-application/&amp;title=Step-By-Step+setup+slicehost+server+%28fedora%29+for+rails+application." rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://blog.bhushangahire.net/2009/07/22/step-by-step-setup-slicehost-server-fedora-for-rails-application/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.bhushangahire.net/2009/07/22/step-by-step-setup-slicehost-server-fedora-for-rails-application/&amp;t=Step-By-Step+setup+slicehost+server+%28fedora%29+for+rails+application." rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Step-By-Step+setup+slicehost+server+%28fedora%29+for+rails+application.+-+http://blog.bhushangahire.net/2009/07/22/step-by-step-setup-slicehost-server-fedora-for-rails-application/+(via+@bhushangahire)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://blog.bhushangahire.net/2009/07/22/step-by-step-setup-slicehost-server-fedora-for-rails-application/&amp;title=Step-By-Step+setup+slicehost+server+%28fedora%29+for+rails+application.&amp;summary=%0A%0A%0A%0A%0A%0A%0A%0AHi%20all%20as%20I%20worked%20on%20setting%20up%204%20to%205%20servers%2C%20I%20thought%20its%20better%20to%20document%20the%20stuff%20so%20that%20I%2Fdevelopers%20can%20refer%20it%2C%20So%20I%20am%20documenting%20the%20step-by-step%20process%20for%20setting%20up%20the%20slicehost%20server%20for%20rails%20application%20work%20with%20nginx%20as%20a%20web%20server%20and%20mongrel%20as%20a%20rails%20applica&amp;source=eXpand yOur cReativity" rel="nofollow" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=Step-By-Step+setup+slicehost+server+%28fedora%29+for+rails+application.&amp;du=http://blog.bhushangahire.net/2009/07/22/step-by-step-setup-slicehost-server-fedora-for-rails-application/&amp;cn=%0A%0A%0A%0A%0A%0A%0A%0AHi%20all%20as%20I%20worked%20on%20setting%20up%204%20to%205%20servers%2C%20I%20thought%20its%20better%20to%20document%20the%20stuff%20so%20that%20I%2Fdevelopers%20can%20refer%20it%2C%20So%20I%20am%20documenting%20the%20step-by-step%20process%20for%20setting%20up%20the%20slicehost%20server%20for%20rails%20application%20work%20with%20nginx%20as%20a%20web%20server%20and%20mongrel%20as%20a%20rails%20applica" rel="nofollow" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="sexy-tumblr">
			<a href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fblog.bhushangahire.net%2F2009%2F07%2F22%2Fstep-by-step-setup-slicehost-server-fedora-for-rails-application%2F&amp;t=Step-By-Step+setup+slicehost+server+%28fedora%29+for+rails+application." rel="nofollow" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://blog.bhushangahire.net/2009/07/22/step-by-step-setup-slicehost-server-fedora-for-rails-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to use Google Apps mail configuration with rails application.</title>
		<link>http://blog.bhushangahire.net/2009/07/22/how-to-use-google-apps-mail-configuration-with-rails-application/</link>
		<comments>http://blog.bhushangahire.net/2009/07/22/how-to-use-google-apps-mail-configuration-with-rails-application/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 10:05:21 +0000</pubDate>
		<dc:creator>Bhushan Ahire</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[google apps]]></category>
		<category><![CDATA[setup]]></category>

		<guid isPermaLink="false">http://blog.bhushangahire.net/?p=134</guid>
		<description><![CDATA[





I am using google apps for my domain www.bhushangahire.com
For one of my rails application I am using this domain mail account setup for sending mails.
But I am not able to send the mail with the default smtp setings we use for sending mail.
So I search on net and I found the Goggle Apps consider its [...]]]></description>
			<content:encoded><![CDATA[<div id="content"><!--single.php--></p>
<p><!--loop--></p>
<p><!--post title--></p>
<div class="post-meta-top">
<div class="clearboth"></div>
<p><!--content with more link--></p>
<p>I am using google apps for my domain <strong>www.bhushangahire.com</strong></p>
<p>For one of my rails application I am using this domain mail account setup for sending mails.</p>
<p>But I am not able to send the mail with the default smtp setings we use for sending mail.</p>
<p>So I search on net and I found the Goggle Apps consider its in different way. Which is TLS ans SSH service, which is not by default comes with the Action mailler.</p>
<p class="vspace"><span class="wikiword">ActionMailer</span> can’t send emails using <span class="wikiword">GMail</span> out of the box. To add this functionality do the following configuration in your rails application:</p>
<ol>
<li>Create the file <strong><code>lib/smtp_tls.rb</code></strong>
<div class="code">
<pre>require "openssl"
require "net/smtp"

Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
check_auth_args user, secret, authtype if user or secret

sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
@socket = Net::InternetMessageIO.new(sock)
@socket.read_timeout = 60 #@read_timeout

check_response(critical { recv_response() })
do_helo(helodomain)

raise 'openssl library not installed' unless defined?(OpenSSL)
starttls
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.sync_close = true
ssl.connect
@socket = Net::InternetMessageIO.new(ssl)
@socket.read_timeout = 60 #@read_timeout
do_helo(helodomain)

authenticate user, secret, authtype if user
@started = true
ensure
unless @started
# authentication failed, cancel connection.
@socket.close if not @started and @socket and not @socket.closed?
@socket = nil
end
end

def do_helo(helodomain)
begin
if @esmtp
ehlo helodomain
else
helo helodomain
end
rescue Net::ProtocolError
if @esmtp
@esmtp = false
@error_occured = false
retry
end
raise
end
end

def starttls
getok('STARTTLS')
end

def quit
begin
getok('QUIT')
rescue EOFError
rescue OpenSSL::SSL::SSLError
end
end
end</pre>
</div>
</li>
<li>Add the following lines to <strong><code>config/environment.rb</code></strong> and replace the values with the appropriate username and password:
<div class="code">
<pre>require 'smtp_tls'
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.server_settings = {
:address =&gt; "smtp.gmail.com",
:port =&gt; 587,
:domain =&gt; "mydomain.com",
:authentication =&gt; :plain,
:user_name =&gt; "username@mydomain.com",
:password =&gt; "password"
}</pre>
</div>
<p><strong><sup>*</sup>Note:</strong>To work your domain with <strong>“mydomain.com”</strong> you have to configure your <strong>MX records</strong> to work Gmail mail sending functionality out of box.</p>
<p>Else you can use a temporary address <strong>@mydomain.com.test-google-a.com</strong>, I have not tested with this as I have already configure my <strong>MX records</strong>.</p>
<p>You can get more information on changing <strong><a href="http://www.google.com/support/a/bin/answer.py?answer=33352">http://www.google.com/support/a/bin/answer.py?answer=33352</a></strong>.</p>
<p>Hope this information is useful to you. <img class="wp-smiley" src="http://blogs.circlesource.com/wp-includes/images/smilies/icon_wink.gif" alt=";-)" /></li>
</ol>
<p><!--for paginate posts--></p>
<p><!--Post Meta--></div>
</div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://blog.bhushangahire.net/2009/07/22/how-to-use-google-apps-mail-configuration-with-rails-application/&amp;title=How+to+use+Google+Apps+mail+configuration+with+rails+application." rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.bhushangahire.net/2009/07/22/how-to-use-google-apps-mail-configuration-with-rails-application/&amp;title=How+to+use+Google+Apps+mail+configuration+with+rails+application." rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.bhushangahire.net/2009/07/22/how-to-use-google-apps-mail-configuration-with-rails-application/&amp;title=How+to+use+Google+Apps+mail+configuration+with+rails+application." rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://blog.bhushangahire.net/2009/07/22/how-to-use-google-apps-mail-configuration-with-rails-application/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.bhushangahire.net/2009/07/22/how-to-use-google-apps-mail-configuration-with-rails-application/&amp;t=How+to+use+Google+Apps+mail+configuration+with+rails+application." rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=How+to+use+Google+Apps+mail+configuration+with+rails+application.+-+http://blog.bhushangahire.net/2009/07/22/how-to-use-google-apps-mail-configuration-with-rails-application/+(via+@bhushangahire)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://blog.bhushangahire.net/2009/07/22/how-to-use-google-apps-mail-configuration-with-rails-application/&amp;title=How+to+use+Google+Apps+mail+configuration+with+rails+application.&amp;summary=%0A%0A%0A%0A%0A%0A%0A%0A%0AI%20am%20using%20google%20apps%20for%20my%20domain%20www.bhushangahire.com%0A%0AFor%20one%20of%20my%20rails%20application%20I%20am%20using%20this%20domain%20mail%20account%20setup%20for%20sending%20mails.%0A%0ABut%20I%20am%20not%20able%20to%20send%20the%20mail%20with%20the%20default%20smtp%20setings%20we%20use%20for%20sending%20mail.%0A%0ASo%20I%20search%20on%20net%20and%20I%20found%20the%20Goggle%20Apps&amp;source=eXpand yOur cReativity" rel="nofollow" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=How+to+use+Google+Apps+mail+configuration+with+rails+application.&amp;du=http://blog.bhushangahire.net/2009/07/22/how-to-use-google-apps-mail-configuration-with-rails-application/&amp;cn=%0A%0A%0A%0A%0A%0A%0A%0A%0AI%20am%20using%20google%20apps%20for%20my%20domain%20www.bhushangahire.com%0A%0AFor%20one%20of%20my%20rails%20application%20I%20am%20using%20this%20domain%20mail%20account%20setup%20for%20sending%20mails.%0A%0ABut%20I%20am%20not%20able%20to%20send%20the%20mail%20with%20the%20default%20smtp%20setings%20we%20use%20for%20sending%20mail.%0A%0ASo%20I%20search%20on%20net%20and%20I%20found%20the%20Goggle%20Apps" rel="nofollow" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="sexy-tumblr">
			<a href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fblog.bhushangahire.net%2F2009%2F07%2F22%2Fhow-to-use-google-apps-mail-configuration-with-rails-application%2F&amp;t=How+to+use+Google+Apps+mail+configuration+with+rails+application." rel="nofollow" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://blog.bhushangahire.net/2009/07/22/how-to-use-google-apps-mail-configuration-with-rails-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grant privileges to all tables in a database for postgresql</title>
		<link>http://blog.bhushangahire.net/2009/06/17/grant-privileges-to-all-tables-in-a-database-for-postgresql/</link>
		<comments>http://blog.bhushangahire.net/2009/06/17/grant-privileges-to-all-tables-in-a-database-for-postgresql/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 11:50:08 +0000</pubDate>
		<dc:creator>Bhushan Ahire</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[grant]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">http://blog.bhushangahire.net/?p=127</guid>
		<description><![CDATA[
Grant privileges to all tables in a database (select, update, insert, delete)
Eg:( Creating a read-only user in postgres)
–Function to grant access(select,insert,update,delete) to users

CREATE FUNCTION pg_grant(TEXT, TEXT, TEXT, TEXT)
RETURNS integer AS '
DECLARE obj record;
num integer;
BEGIN
num:=0;
FOR obj IN SELECT relname FROM pg_class c
JOIN pg_namespace ns ON (c.relnamespace = ns.oid) WHERE
relkind in (''r'',''v'',''S'') AND
nspname = $4 AND
relname LIKE [...]]]></description>
			<content:encoded><![CDATA[<div class="snap_preview">
<p>Grant privileges to all tables in a database (select, update, insert, delete)</p>
<p>Eg:( Creating a read-only user in postgres)</p>
<p>–Function to grant access(select,insert,update,delete) to users<br />
<code><br />
CREATE FUNCTION pg_grant(TEXT, TEXT, TEXT, TEXT)<br />
RETURNS integer AS '<br />
DECLARE obj record;<br />
num integer;<br />
BEGIN<br />
num:=0;<br />
FOR obj IN SELECT relname FROM pg_class c<br />
JOIN pg_namespace ns ON (c.relnamespace = ns.oid) WHERE<br />
relkind in (''r'',''v'',''S'') AND<br />
nspname = $4 AND<br />
relname LIKE $3<br />
LOOP<br />
EXECUTE ''GRANT '' || $2 || '' ON '' || obj.relname || '' TO '' || $1;<br />
num := num + 1;<br />
END LOOP;<br />
RETURN num;<br />
END;<br />
' LANGUAGE plpgsql SECURITY DEFINER;<br />
</code><br />
–Function to revoke access(select,insert,update,delete) from users<br />
<code><br />
CREATE FUNCTION pg_revoke(TEXT, TEXT, TEXT, TEXT)<br />
RETURNS integer AS '<br />
DECLARE obj record;<br />
num integer;<br />
BEGIN<br />
num:=0;<br />
FOR obj IN SELECT relname FROM pg_class c<br />
JOIN pg_namespace ns ON (c.relnamespace = ns.oid) WHERE<br />
relkind in (''r'',''v'',''S'') AND<br />
nspname = $4 AND<br />
relname LIKE $3<br />
LOOP<br />
EXECUTE ''REVOKE '' || $2 || '' ON '' || obj.relname || '' FROM '' || $1;<br />
num := num + 1;<br />
END LOOP;<br />
RETURN num;<br />
END;<br />
' LANGUAGE plpgsql SECURITY DEFINER;<br />
</code><br />
–Create users for your database<br />
<code><br />
CREATE USER userreadonly WITH PASSWORD 'userr3ad0nly';<br />
CREATE USER userall WITH PASSWORD 'usersh0pa11';<br />
</code><br />
–Grant respective access to users<br />
<code><br />
select pg_grant('</code><code>userreadonly </code><code>','select','%','public');<br />
select pg_grant('</code><code>userall </code><code>','select,insert,update,delete','%','public');<br />
</code></p>
<p>You might need to create lang for plpgsql if you had not done so<br />
<code><br />
createlang plpgsql yrdatabasename</code></p>
</div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://blog.bhushangahire.net/2009/06/17/grant-privileges-to-all-tables-in-a-database-for-postgresql/&amp;title=Grant+privileges+to+all+tables+in+a+database+for+postgresql" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.bhushangahire.net/2009/06/17/grant-privileges-to-all-tables-in-a-database-for-postgresql/&amp;title=Grant+privileges+to+all+tables+in+a+database+for+postgresql" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.bhushangahire.net/2009/06/17/grant-privileges-to-all-tables-in-a-database-for-postgresql/&amp;title=Grant+privileges+to+all+tables+in+a+database+for+postgresql" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://blog.bhushangahire.net/2009/06/17/grant-privileges-to-all-tables-in-a-database-for-postgresql/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.bhushangahire.net/2009/06/17/grant-privileges-to-all-tables-in-a-database-for-postgresql/&amp;t=Grant+privileges+to+all+tables+in+a+database+for+postgresql" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Grant+privileges+to+all+tables+in+a+database+for+postgresql+-+http://blog.bhushangahire.net/2009/06/17/grant-privileges-to-all-tables-in-a-database-for-postgresql/+(via+@bhushangahire)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://blog.bhushangahire.net/2009/06/17/grant-privileges-to-all-tables-in-a-database-for-postgresql/&amp;title=Grant+privileges+to+all+tables+in+a+database+for+postgresql&amp;summary=Grant%20privileges%20to%20all%20tables%20in%20a%20database%20%28select%2C%20update%2C%20insert%2C%20delete%29%0AEg%3A%28%20Creating%20a%20read-only%20user%20in%20postgres%29%0A%E2%80%93Function%20to%20grant%20access%28select%2Cinsert%2Cupdate%2Cdelete%29%20to%20users%0A%0ACREATE%20FUNCTION%20pg_grant%28TEXT%2C%20TEXT%2C%20TEXT%2C%20TEXT%29%0ARETURNS%20integer%20AS%20%27%0ADECLARE%20obj%20record%3B%0Anum%20integer%3B%0ABEGIN%0Anu&amp;source=eXpand yOur cReativity" rel="nofollow" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=Grant+privileges+to+all+tables+in+a+database+for+postgresql&amp;du=http://blog.bhushangahire.net/2009/06/17/grant-privileges-to-all-tables-in-a-database-for-postgresql/&amp;cn=Grant%20privileges%20to%20all%20tables%20in%20a%20database%20%28select%2C%20update%2C%20insert%2C%20delete%29%0AEg%3A%28%20Creating%20a%20read-only%20user%20in%20postgres%29%0A%E2%80%93Function%20to%20grant%20access%28select%2Cinsert%2Cupdate%2Cdelete%29%20to%20users%0A%0ACREATE%20FUNCTION%20pg_grant%28TEXT%2C%20TEXT%2C%20TEXT%2C%20TEXT%29%0ARETURNS%20integer%20AS%20%27%0ADECLARE%20obj%20record%3B%0Anum%20integer%3B%0ABEGIN%0Anu" rel="nofollow" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="sexy-tumblr">
			<a href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fblog.bhushangahire.net%2F2009%2F06%2F17%2Fgrant-privileges-to-all-tables-in-a-database-for-postgresql%2F&amp;t=Grant+privileges+to+all+tables+in+a+database+for+postgresql" rel="nofollow" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://blog.bhushangahire.net/2009/06/17/grant-privileges-to-all-tables-in-a-database-for-postgresql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transperent div for all browser</title>
		<link>http://blog.bhushangahire.net/2009/05/26/transperent-div-for-all-browser/</link>
		<comments>http://blog.bhushangahire.net/2009/05/26/transperent-div-for-all-browser/#comments</comments>
		<pubDate>Tue, 26 May 2009 13:36:21 +0000</pubDate>
		<dc:creator>Bhushan Ahire</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[safari]]></category>
		<category><![CDATA[transperent]]></category>

		<guid isPermaLink="false">http://blog.bhushangahire.net/2009/05/26/transperent-div-for-all-browser/</guid>
		<description><![CDATA[if (b.ie)
 {
  var filter = this.element.style.filter.replace(/alpha\s*\(\s*opacity\s*=\s*[0-9\.]{1,3}\)/, '');
  this.element.style.filter = filter + 'alpha(opacity=' + parseInt(ht * 100, 10) + ')';
 }
 else
 {
  this.element.style.opacity = ht;
 }
 this.element.style.visibility = 'visible';
 this.element.style.display = 'block'
}





		
			Share this on del.icio.us
		
		
			Digg this!
		
		
			Stumble upon something good? Share it on StumbleUpon
		
		
			Share this on Technorati
		
		
			Share this on Facebook
		
		
			Tweet This!
		
		
			Share this [...]]]></description>
			<content:encoded><![CDATA[<p>if (b.ie)<br />
 {<br />
  var filter = this.element.style.filter.replace(/alpha\s*\(\s*opacity\s*=\s*[0-9\.]{1,3}\)/, '');<br />
  this.element.style.filter = filter + 'alpha(opacity=' + parseInt(ht * 100, 10) + ')';<br />
 }<br />
 else<br />
 {<br />
  this.element.style.opacity = ht;<br />
 }<br />
 this.element.style.visibility = 'visible';<br />
 this.element.style.display = 'block'<br />
}</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://blog.bhushangahire.net/2009/05/26/transperent-div-for-all-browser/&amp;title=Transperent+div+for+all+browser" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.bhushangahire.net/2009/05/26/transperent-div-for-all-browser/&amp;title=Transperent+div+for+all+browser" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.bhushangahire.net/2009/05/26/transperent-div-for-all-browser/&amp;title=Transperent+div+for+all+browser" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://blog.bhushangahire.net/2009/05/26/transperent-div-for-all-browser/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.bhushangahire.net/2009/05/26/transperent-div-for-all-browser/&amp;t=Transperent+div+for+all+browser" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Transperent+div+for+all+browser+-+http://blog.bhushangahire.net/2009/05/26/transperent-div-for-all-browser/+(via+@bhushangahire)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://blog.bhushangahire.net/2009/05/26/transperent-div-for-all-browser/&amp;title=Transperent+div+for+all+browser&amp;summary=if%20%28b.ie%29%0A%20%7B%0A%20%20var%20filter%20%3D%20this.element.style.filter.replace%28%2Falpha%5Cs%2A%5C%28%5Cs%2Aopacity%5Cs%2A%3D%5Cs%2A%5B0-9%5C.%5D%7B1%2C3%7D%5C%29%2F%2C%20%27%27%29%3B%0A%20%20this.element.style.filter%20%3D%20filter%20%2B%20%27alpha%28opacity%3D%27%20%2B%20parseInt%28ht%20%2A%20100%2C%2010%29%20%2B%20%27%29%27%3B%0A%20%7D%0A%20else%0A%20%7B%0A%20%20this.element.style.opacity%20%3D%20ht%3B%0A%20%7D%0A%20this.element.style.visibility%20%3D%20%27visible%27%3B%0A%20this.&amp;source=eXpand yOur cReativity" rel="nofollow" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=Transperent+div+for+all+browser&amp;du=http://blog.bhushangahire.net/2009/05/26/transperent-div-for-all-browser/&amp;cn=if%20%28b.ie%29%0A%20%7B%0A%20%20var%20filter%20%3D%20this.element.style.filter.replace%28%2Falpha%5Cs%2A%5C%28%5Cs%2Aopacity%5Cs%2A%3D%5Cs%2A%5B0-9%5C.%5D%7B1%2C3%7D%5C%29%2F%2C%20%27%27%29%3B%0A%20%20this.element.style.filter%20%3D%20filter%20%2B%20%27alpha%28opacity%3D%27%20%2B%20parseInt%28ht%20%2A%20100%2C%2010%29%20%2B%20%27%29%27%3B%0A%20%7D%0A%20else%0A%20%7B%0A%20%20this.element.style.opacity%20%3D%20ht%3B%0A%20%7D%0A%20this.element.style.visibility%20%3D%20%27visible%27%3B%0A%20this." rel="nofollow" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="sexy-tumblr">
			<a href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fblog.bhushangahire.net%2F2009%2F05%2F26%2Ftransperent-div-for-all-browser%2F&amp;t=Transperent+div+for+all+browser" rel="nofollow" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://blog.bhushangahire.net/2009/05/26/transperent-div-for-all-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get location from IP address in Ruby On Rails for free&#8230;.</title>
		<link>http://blog.bhushangahire.net/2009/05/20/get-location-from-ip-address-in-ruby-on-rails-for-free/</link>
		<comments>http://blog.bhushangahire.net/2009/05/20/get-location-from-ip-address-in-ruby-on-rails-for-free/#comments</comments>
		<pubDate>Wed, 20 May 2009 09:42:07 +0000</pubDate>
		<dc:creator>Bhushan Ahire</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ip address]]></category>
		<category><![CDATA[location]]></category>

		<guid isPermaLink="false">http://blog.bhushangahire.net/?p=116</guid>
		<description><![CDATA[
Find below the code for finding location from IP address using IP location tools.
require 'net/http'
require 'rexml/document'
include REXML

class MapsController < ApplicationController
	def index
		@location = locateIp()

	end

	def locateIp
		ip = request.remote_ip
		ips = ip.to_s
		url = "http://iplocationtools.com/ip_query.php?ip="+ips

		xml_data = Net::HTTP.get_response(URI.parse(url)).body

                xmldoc = REXML::Document.new(xml_data)

		# Now get the root element
		root [...]]]></description>
			<content:encoded><![CDATA[<div class="snap_preview">
<p>Find below the code for finding location from IP address using <a href="http://www.iplocationtools.com/">IP location tools</a>.</p>
<pre>require 'net/http'
require 'rexml/document'
include REXML

class MapsController < ApplicationController
	def index
		@location = locateIp()

	end

	def locateIp
		ip = request.remote_ip
		ips = ip.to_s
		url = "http://iplocationtools.com/ip_query.php?ip="+ips

		xml_data = Net::HTTP.get_response(URI.parse(url)).body

                xmldoc = REXML::Document.new(xml_data)

		# Now get the root element
		root = xmldoc.root
		city = ""
		regionName = ""
		countryName = ""

		# This will take country name...
		xmldoc.elements.each("Response/CountryName") {
		|e| countryName << e.text
	    }

		# Now get city name...
		xmldoc.elements.each("Response/City") {
   		|e| city << e.text
	    }

		# This will take regionName...
		xmldoc.elements.each("Response/RegionName") {
   		|e| regionName << e.text
	    }

     	ipLocation = city +", "+regionName+", "+countryName

	 return ipLocation
   end #end of method locateIp

end</pre>
</div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://blog.bhushangahire.net/2009/05/20/get-location-from-ip-address-in-ruby-on-rails-for-free/&amp;title=Get+location+from+IP+address+in+Ruby+On+Rails+for+free...." rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.bhushangahire.net/2009/05/20/get-location-from-ip-address-in-ruby-on-rails-for-free/&amp;title=Get+location+from+IP+address+in+Ruby+On+Rails+for+free...." rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.bhushangahire.net/2009/05/20/get-location-from-ip-address-in-ruby-on-rails-for-free/&amp;title=Get+location+from+IP+address+in+Ruby+On+Rails+for+free...." rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://blog.bhushangahire.net/2009/05/20/get-location-from-ip-address-in-ruby-on-rails-for-free/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.bhushangahire.net/2009/05/20/get-location-from-ip-address-in-ruby-on-rails-for-free/&amp;t=Get+location+from+IP+address+in+Ruby+On+Rails+for+free...." rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Get+location+from+IP+address+in+Ruby+On+Rails+for+free....+-+http://blog.bhushangahire.net/2009/05/20/get-location-from-ip-address-in-ruby-on-rails-for-free/+(via+@bhushangahire)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://blog.bhushangahire.net/2009/05/20/get-location-from-ip-address-in-ruby-on-rails-for-free/&amp;title=Get+location+from+IP+address+in+Ruby+On+Rails+for+free....&amp;summary=Find%20below%20the%20code%20for%20finding%20location%20from%20IP%20address%20using%20IP%20location%20tools.%0Arequire%20%27net%2Fhttp%27%0Arequire%20%27rexml%2Fdocument%27%0Ainclude%20REXML%0A%0Aclass%20MapsController%20%3C%20ApplicationController%0A%09def%20index%0A%09%09%40location%20%3D%20locateIp%28%29%0A%0A%09end%0A%0A%09def%20locateIp%0A%09%09ip%20%3D%20request.remote_ip%0A%09%09ips%20%3D%20ip.to_s%0A%09%09url%20%3D%20%22http%3A%2F%2F&amp;source=eXpand yOur cReativity" rel="nofollow" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=Get+location+from+IP+address+in+Ruby+On+Rails+for+free....&amp;du=http://blog.bhushangahire.net/2009/05/20/get-location-from-ip-address-in-ruby-on-rails-for-free/&amp;cn=Find%20below%20the%20code%20for%20finding%20location%20from%20IP%20address%20using%20IP%20location%20tools.%0Arequire%20%27net%2Fhttp%27%0Arequire%20%27rexml%2Fdocument%27%0Ainclude%20REXML%0A%0Aclass%20MapsController%20%3C%20ApplicationController%0A%09def%20index%0A%09%09%40location%20%3D%20locateIp%28%29%0A%0A%09end%0A%0A%09def%20locateIp%0A%09%09ip%20%3D%20request.remote_ip%0A%09%09ips%20%3D%20ip.to_s%0A%09%09url%20%3D%20%22http%3A%2F%2F" rel="nofollow" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="sexy-tumblr">
			<a href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fblog.bhushangahire.net%2F2009%2F05%2F20%2Fget-location-from-ip-address-in-ruby-on-rails-for-free%2F&amp;t=Get+location+from+IP+address+in+Ruby+On+Rails+for+free...." rel="nofollow" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://blog.bhushangahire.net/2009/05/20/get-location-from-ip-address-in-ruby-on-rails-for-free/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install and Configure FTP Server in Amazon EC2 instance</title>
		<link>http://blog.bhushangahire.net/2009/04/15/install-and-configure-ftp-server-in-amazon-ec2-instance/</link>
		<comments>http://blog.bhushangahire.net/2009/04/15/install-and-configure-ftp-server-in-amazon-ec2-instance/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 14:17:51 +0000</pubDate>
		<dc:creator>Bhushan Ahire</dc:creator>
				<category><![CDATA[Amazon EC2]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[live]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[setup]]></category>

		<guid isPermaLink="false">http://blog.bhushangahire.net/?p=97</guid>
		<description><![CDATA[For many users, running FTP Sever in Amazon EC2 instance is headache at the first time. You need to experiment before being able to transfer data. The main problems are Ingress firewall in Amazon environment and NAT traversal.
Here I’m using vsftp (vsfptd) Server, which is one of the most popular and easy to configure. The [...]]]></description>
			<content:encoded><![CDATA[<p>For many users, running FTP Sever in Amazon EC2 instance is headache at the first time. You need to experiment before being able to transfer data. The main problems are Ingress firewall in Amazon environment and NAT traversal.</p>
<p>Here I’m using vsftp (vsfptd) Server, which is one of the most popular and easy to configure. The instance is running from base Fedora 4 AMI but the setup should be identical to other Red Hat based distros.</p>
<p>Install vsftpd FTP server, if not installed earlier: </p>
<p><code># yum install vsfptd</code></p>
<p>Its upto you which FTP method i.e. Active or Passive you want to use. The problem with active mode is that your computer is sending a request out of port 21 when all of a sudden, the server attempts to initiate a request with your computer on port 20.  Since communication on port 21 does not imply communication on port 20, it appears as if some unauthorized host has attempted to initiate a new connection with your computer.  Kind of sounds like a hack right?  Your firewall may think so too (or your NAT router may have no idea to which computer to route the request). Active mode is not used as default method of ftp transfer in many clients these days. </p>
<p>On the other hand, as the Ingress firewall is running in AWS, from the firewall’s standpoint, to support passive mode FTP the following communication channels need to be opened:</p>
<p>FTP server’s port 21 from anywhere (Client initiates connection).<br />
FTP server’s port 21 to ports &gt; 1023 (Server responds to client’s control port).<br />
FTP server’s ports &gt; 1023 from anywhere (Client initiates data connection to random port specified by server).<br />
FTP server’s ports &gt; 1023 to remote ports &gt; 1023 (Server sends ACKs (and data) to client’s data port).</p>
<p>That second part is the problem: FTP server listens on a random port and hands that back to the client, so the client initiates a connection to a random server port, which you must allow.</p>
<p>Opening up all ports &gt; 1023 isn’t so good for security. But what you can do is allow the ports through the distributed firewall and then setup your own filtering inside your instance. Instead, you would better open a fixed number of ports (such as 1024 to 1048) and configure your FTP Server to only use that ports.</p>
<p>Check whether required ports are open or not in your EC2 security group. (if you are unaware about security group, it should be ‘defaul’ unless you created a new one). </p>
<p><code># ec2-describe-group</code></p>
<p>This command will print all ports which are currently open. If you dont find port 20,21,1024-1048 then you need to open these ports but if you dont find the command itself i.e.<br />
<code># ec2-describe-group<br />
-bash: ec2-describe-group: command not found</code></p>
<p>You need to install ec2 command line tools. You can find them <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&amp;categoryID=88" onclick="javascript:urchinTracker('/outbound/developer.amazonwebservices.com/connect/entry.jspa?externalID=351_038_categoryID=88?ref=http_//www.google.co.in/search?hl=en_client=firefox-a_rls=org.mozilla_3Aen-US_3Aofficial_q=how+to+connect+amazon+ec2+instance+with+sftp_btnG=Search_meta=_aq=o_oq=');">here</a>  and the instructions to setup/configure can be found <a href="http://docs.amazonwebservices.com/AWSEC2/2008-02-01/GettingStartedGuide/?ref=get-started" onclick="javascript:urchinTracker('/outbound/docs.amazonwebservices.com/AWSEC2/2008-02-01/GettingStartedGuide/?ref=get-started?ref=http_//www.google.co.in/search?hl=en_client=firefox-a_rls=org.mozilla_3Aen-US_3Aofficial_q=how+to+connect+amazon+ec2+instance+with+sftp_btnG=Search_meta=_aq=o_oq=');">here.</a> </p>
<p>Open the ports now: </p>
<p><code># ec2-authorize default -p 20-21<br />
# ec2-authorize default -p 1024-1048</code></p>
<p>Here, ‘default’ is the name of security group. You can also open ports for specific IPs. For ease of use, you better install ElasticFox, a firefox extension to manage EC2 stuff. you can find more about it <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=609" onclick="javascript:urchinTracker('/outbound/developer.amazonwebservices.com/connect/entry.jspa?externalID=609?ref=http_//www.google.co.in/search?hl=en_client=firefox-a_rls=org.mozilla_3Aen-US_3Aofficial_q=how+to+connect+amazon+ec2+instance+with+sftp_btnG=Search_meta=_aq=o_oq=');">here.</a> </p>
<p>At this moment, you can start your FTP server and if you try to connect it, the process will get failed. By checking logs, you should find something like:</p>
<p><code>Status: Connected<br />
Status: Retrieving directory listing...<br />
Command: PWD<br />
Response: 257 "/" is current directory.<br />
Command: TYPE A<br />
Response: 200 Type set to A<br />
Command: PASV<br />
Response: 227 Entering Passive Mode (216,182,238,73,129,75).<br />
Command: LIST<br />
Error: Transfer channel can't be opened. Reason: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.<br />
Error: Could not retrieve directory listing<br />
</code></p>
<p>Time to configure vsftpd.conf file:<br />
<code># vi /etc/vsftpd/vsftpd.conf<br />
---Add following lines at the end of file---<br />
	pasv_enable=YES<br />
	pasv_min_port=1024<br />
	pasv_max_port=1048<br />
	pasv_address=<strong>Public IP of your instance</strong></code></p>
<p>Put public IP of your EC2 instance and then Save the file. Now restart the server: </p>
<p><code># /etc/init.d/vsftpd restart</code></p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://blog.bhushangahire.net/2009/04/15/install-and-configure-ftp-server-in-amazon-ec2-instance/&amp;title=Install+and+Configure+FTP+Server+in+Amazon+EC2+instance" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.bhushangahire.net/2009/04/15/install-and-configure-ftp-server-in-amazon-ec2-instance/&amp;title=Install+and+Configure+FTP+Server+in+Amazon+EC2+instance" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.bhushangahire.net/2009/04/15/install-and-configure-ftp-server-in-amazon-ec2-instance/&amp;title=Install+and+Configure+FTP+Server+in+Amazon+EC2+instance" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://blog.bhushangahire.net/2009/04/15/install-and-configure-ftp-server-in-amazon-ec2-instance/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.bhushangahire.net/2009/04/15/install-and-configure-ftp-server-in-amazon-ec2-instance/&amp;t=Install+and+Configure+FTP+Server+in+Amazon+EC2+instance" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Install+and+Configure+FTP+Server+in+Amazon+EC2+instance+-+http://blog.bhushangahire.net/2009/04/15/install-and-configure-ftp-server-in-amazon-ec2-instance/+(via+@bhushangahire)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://blog.bhushangahire.net/2009/04/15/install-and-configure-ftp-server-in-amazon-ec2-instance/&amp;title=Install+and+Configure+FTP+Server+in+Amazon+EC2+instance&amp;summary=For%20many%20users%2C%20running%20FTP%20Sever%20in%20Amazon%20EC2%20instance%20is%20headache%20at%20the%20first%20time.%20You%20need%20to%20experiment%20before%20being%20able%20to%20transfer%20data.%20The%20main%20problems%20are%20Ingress%20firewall%20in%20Amazon%20environment%20and%20NAT%20traversal.%0AHere%20I%E2%80%99m%20using%20vsftp%20%28vsfptd%29%20Server%2C%20which%20is%20one%20of%20the%20most%20popular%20&amp;source=eXpand yOur cReativity" rel="nofollow" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=Install+and+Configure+FTP+Server+in+Amazon+EC2+instance&amp;du=http://blog.bhushangahire.net/2009/04/15/install-and-configure-ftp-server-in-amazon-ec2-instance/&amp;cn=For%20many%20users%2C%20running%20FTP%20Sever%20in%20Amazon%20EC2%20instance%20is%20headache%20at%20the%20first%20time.%20You%20need%20to%20experiment%20before%20being%20able%20to%20transfer%20data.%20The%20main%20problems%20are%20Ingress%20firewall%20in%20Amazon%20environment%20and%20NAT%20traversal.%0AHere%20I%E2%80%99m%20using%20vsftp%20%28vsfptd%29%20Server%2C%20which%20is%20one%20of%20the%20most%20popular%20" rel="nofollow" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="sexy-tumblr">
			<a href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fblog.bhushangahire.net%2F2009%2F04%2F15%2Finstall-and-configure-ftp-server-in-amazon-ec2-instance%2F&amp;t=Install+and+Configure+FTP+Server+in+Amazon+EC2+instance" rel="nofollow" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://blog.bhushangahire.net/2009/04/15/install-and-configure-ftp-server-in-amazon-ec2-instance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
