<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Suman Srinivasan&#039;s Code Blog</title>
	<atom:link href="http://sumanrs.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sumanrs.wordpress.com</link>
	<description>Code samples and tutorials during my work/school</description>
	<lastBuildDate>Thu, 12 Jan 2012 22:45:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sumanrs.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Suman Srinivasan&#039;s Code Blog</title>
		<link>http://sumanrs.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sumanrs.wordpress.com/osd.xml" title="Suman Srinivasan&#039;s Code Blog" />
	<atom:link rel='hub' href='http://sumanrs.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Getting Whirr running on EC2 with Cloudera&#8217;s script</title>
		<link>http://sumanrs.wordpress.com/2012/01/12/getting-whirr-running-on-ec2-with-clouderas-script/</link>
		<comments>http://sumanrs.wordpress.com/2012/01/12/getting-whirr-running-on-ec2-with-clouderas-script/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 22:30:06 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Hadoop]]></category>
		<category><![CDATA[Whirr]]></category>

		<guid isPermaLink="false">https://sumanrs.wordpress.com/?p=109</guid>
		<description><![CDATA[I haven&#8217;t fully used Hadoop yet, but it looks like a pretty amazing tool for crunching large datasets. Combine Hadoop and Amazon EC2, and it should be possible to crunch large datasets with ephemeral EC2 instances fast. But I had problems getting Hadoop up and running on EC2… I followed Cloudera&#8217;s instructions for setting up [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=109&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t fully used Hadoop yet, but it looks like a pretty amazing tool for crunching large datasets. Combine Hadoop and Amazon EC2, and it should be possible to crunch large datasets with ephemeral EC2 instances fast. But I had problems getting Hadoop up and running on EC2…</p>
<p><span id="more-109"></span>
<p>I followed Cloudera&#8217;s instructions for <a href="https://ccp.cloudera.com/display/CDHDOC/CDH3+Documentation">setting up CDH3 scripts on the Amazon EC2 instances</a> I was testing.</p>
<p>Everything went great. Until I got to the Whirr installation (which seems the easiest way to start up a number of nodes at once and have them auto-magically configured.)</p>
<p>Following<a href="https://ccp.cloudera.com/display/CDHDOC/CDH3+Documentation"> these instructions</a> gave me this error: &#8220;Non-Windows AMIs with a virtualization type of &#8216;hvm&#8217; currently may only be used with Cluster Compute instance types.&#8221;</p>
<p>Luckily a search for this error message lead to these helpful links:</p>
<ul>
<li><a href="http://mail-archives.apache.org/mod_mbox/incubator-whirr-user/201103.mbox/%3CD890DBF7-9434-47AD-BA1E-E492099473A6@daltonclark.com%3E">http://mail-archives.apache.org/mod_mbox/incubator-whirr-user/201103.mbox/%3CD890DBF7-9434-47AD-BA1E-E492099473A6@daltonclark.com%3E</a></li>
<li><a href="http://mail-archives.apache.org/mod_mbox/whirr-user/201112.mbox/%3CCAHZL8y8OncJ3tkWYfgwTnPP_6ziW8D02Z0s8u5-XST+1rv79yw@mail.gmail.com%3E">http://mail-archives.apache.org/mod_mbox/whirr-user/201112.mbox/%3CCAHZL8y8OncJ3tkWYfgwTnPP_6ziW8D02Z0s8u5-XST+1rv79yw@mail.gmail.com%3E</a></li>
</ul>
<p>After some trial and error, I added these lines to my hadoop.properties which worked:</p>
<p>========== <br />whirr.hardware-id=m1.large <br />whirr.image-id=us-east-1/ami-da0cf8b3 <br />whirr.location-id=us-east-1 <br />==========</p>
<p>Once there, everything worked great. One small thing is that when the whirr script completes setting up the instances, it will say that the web-based interfaces are live, but you will have to edit the security groups in AWS to accept incoming traffic from any IP address: <br />50030	0.0.0.0/0 <br />50070	0.0.0.0/0 <br />in order to actually see the web-based interface.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sumanrs.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sumanrs.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sumanrs.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sumanrs.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=109&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2012/01/12/getting-whirr-running-on-ec2-with-clouderas-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating an Amazon EC2 instance using the PHP SDK</title>
		<link>http://sumanrs.wordpress.com/2012/01/11/creating-an-amazon-ec2-instance-using-the-php-sdk/</link>
		<comments>http://sumanrs.wordpress.com/2012/01/11/creating-an-amazon-ec2-instance-using-the-php-sdk/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 18:57:51 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[aws]]></category>

		<guid isPermaLink="false">https://sumanrs.wordpress.com/?p=106</guid>
		<description><![CDATA[Recently I had to write a script in PHP to start up a EC2 instance and then return its hostname. I used the AWS PHP SDK for this.The AWS SDK in PHP was of great help. The documentation was enough, but I had to do some testing and debugging in order to get my script [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=106&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I had to write a script in PHP to start up a EC2 instance and then return its hostname. I used the AWS PHP SDK for this.<span id="more-106"></span>The AWS SDK in PHP was of great help. The documentation was enough, but I had to do some testing and debugging in order to get my script to completely work. </p>
<p>So without much ado, here is the PHP script to set up an instance and get its hostname, as well as output these as messages using the AWS PHP SDK.</p>
<p><pre class="brush: php;">
	// Sleep time to allow EC2 instance to start up
	$sleeptime = 15;
	$username = &quot;ec2-user&quot;;

	// For AWS PHP SDK
	putenv('HOME=/home/ec2-user/');
	require_once 'AWSSDKforPHP/sdk.class.php';

	// Get data from HTTP POST
	$ami = $_POST['amis'];
	$instancetype = $_POST['instancetype'];
	$keyname = $_POST['key'];
	$securitygroup = $_POST['securitygroups'];

	// Instantiate the AmazonEC2 class
	$ec2 = new AmazonEC2();

	// Boot an instance of the image
	$response = $ec2-&gt;run_instances($ami, 1, 1, array(
	    'KeyName' =&gt; $keyname,
	    'InstanceType' =&gt; $instancetype,
	    'SecurityGroupId' =&gt; $securitygroup,
	));
	if (!($response-&gt;isOK())) {
		echo &quot;&lt;p class='error'&gt;ERROR! Could not create new instance!&lt;/p&gt;&quot;;
		return;	
	}
	$instance = $response-&gt;body-&gt;instancesSet-&gt;item-&gt;instanceId;
	$message = &quot;&lt;p&gt;Your instance has been successfully created.&lt;/p&gt;&quot;;
	$message .= (&quot;&lt;p&gt;Instance ID is: &lt;b&gt;$instance&lt;/b&gt;&lt;/p&gt;&quot;);

	// Give instance some time to start up
	sleep ($sleeptime);

	// Get the hostname from a call to the DescribeImages operation.
	$response = $ec2-&gt;describe_instances(array(
		'Filter' =&gt; array(
        array('Name' =&gt; 'instance-id', 'Value' =&gt; &quot;$instance&quot;),
		)
	));
	if (!($response-&gt;isOK())) {
		echo &quot;&lt;p class='error'&gt;ERROR! Could not retrieve hostname for instance!&lt;/p&gt;&quot;;
		return;	
	}
	$hostname = $response-&gt;body-&gt;reservationSet-&gt;item-&gt;instancesSet-&gt;item-&gt;dnsName;

	// Output the message
	$message .= &quot;&lt;p&gt;Your instance hostname is: &lt;b&gt;$hostname&lt;/b&gt;&lt;/p&gt;&quot;;
	$message .= &quot;&lt;p&gt;You can connect to your instance using this command:&lt;br&gt;&quot; .
		&quot;&lt;b&gt;ssh -i $keyname.pem $username@&quot; . $hostname .  &quot;&lt;/b&gt;&lt;/p&gt;&quot;;

	echo $message;
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sumanrs.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sumanrs.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sumanrs.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sumanrs.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/106/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=106&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2012/01/11/creating-an-amazon-ec2-instance-using-the-php-sdk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>CakePHP user/password/authentication manager: the missing guide</title>
		<link>http://sumanrs.wordpress.com/2011/10/01/cakephp-user-password-manager-authentication-missing-guide/</link>
		<comments>http://sumanrs.wordpress.com/2011/10/01/cakephp-user-password-manager-authentication-missing-guide/#comments</comments>
		<pubDate>Sat, 01 Oct 2011 23:16:21 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[cakephp]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=99</guid>
		<description><![CDATA[CakePHP has excellent documentation on its site on how to do authentication &#8211; its actually quite complete, you can just copy-paste and drop in the code into your build and get a working authentication system. The problem is: it doesn&#8217;t quite tell you how to handle adding/editing users and particularly their passwords from a UI [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=99&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>CakePHP has excellent documentation on its site on <a href="http://book.cakephp.org/view/1250/Authentication" target="_blank">how to do authentication</a> &#8211; its actually quite complete, you can just copy-paste and drop in the code into your build and get a working authentication system. The problem is: it doesn&#8217;t quite tell you how to handle adding/editing users and particularly their passwords from a UI perspective. There are plugins out there, like <a href="https://github.com/CakeDC/users" target="_blank">CakeDC&#8217;s Users</a> plugin, which I haven&#8217;t tried, but if you want to stay lightweight and write your own code, here&#8217;s a guide.</p>
<p><span id="more-99"></span></p>
<p>I wanted to have a UI system on the backend that allowed me to create and edit users, and set/reset their passwords in a manner similar to how its done with most professional sites these days:</p>
<ul>
<li>Enter the password twice for creating a user</li>
<li>Enter password twice for editing a user, but blank password means password is unchanged</li>
</ul>
<p>With this in mind, I made a few changes to the users models, controllers and views.</p>
<p><strong>1. MODEL VALIDATION</strong></p>
<p>First of all, I changed the validation code for the users.php model to the following:</p>
<p><pre class="brush: php;">
	var $validate = array(
// other validation code
		'password1' =&gt; array(
			'notempty' =&gt; array(
				'rule' =&gt; array('notempty'),
			),
		),
		'password2' =&gt; array(
			'notempty' =&gt; array(
				'rule' =&gt; array('notempty'),
			),
		),
	);
</pre></p>
<p>Basically removing all hints of the &#8220;password&#8221; field. Why? As you will see later, I&#8217;ve removed any sort of &#8220;view&#8221; or direct access to the password in the views and controller.</p>
<p><strong>2. VIEWS CHANGE FOR ADD/EDIT</strong></p>
<p>Next for the views, I made these changes to the add and edit views.</p>
<p>I replaced<br />
<pre class="brush: php;">
		echo $this-&gt;Form-&gt;input('password');
</pre><br />
on both of them with these lines:</p>
<p><em>add.ctp</em><br />
<pre class="brush: php;">
		echo $this-&gt;Form-&gt;input('password1', 
			array('label' =&gt; 'Password',
				'type' =&gt; 'password')
		);
		echo $this-&gt;Form-&gt;input('password2', 
			array('label' =&gt; 'Password (again)',
				'type' =&gt; 'password')
		);
</pre></p>
<p><em>edit.ctp</em><br />
<pre class="brush: php;">
		echo $this-&gt;Form-&gt;input('password3', 
			array('label' =&gt; 'Password',
				'type' =&gt; 'password')
		);
		echo $this-&gt;Form-&gt;input('password4', 
			array('label' =&gt; 'Password (again)',
				'type' =&gt; 'password')
		);
</pre></p>
<p>Why password1 and password2 for add.ctp, and password3 and password4 for edit.ctp ? Because as you might remember from the model, password1 and password2 are validated &#8211; which means anyone using the UI MUST enter the password for the field. Changing the fieldnames makes it easy for the edit view &#8211; so people can leave those fields blank.</p>
<p><strong>3. CONTROLLER CHECKS FOR PASSWORD</strong></p>
<p>Finally, the controller. Here is how to handle the add() method. Between these lines:</p>
<p><pre class="brush: php;">
	function add() {
		if (!empty($this-&gt;data)) {
			// add following code here
			$this-&gt;User-&gt;create();
</pre></p>
<p>add these lines:</p>
<p><pre class="brush: php;">
			if (!($this-&gt;data['User']['password1'] === 
				$this-&gt;data['User']['password2'])) {
				$this-&gt;Session-&gt;setFlash(__('Passwords do not match.', true));				
				return;
			}
			$this-&gt;data['User']['password'] = 
				$this-&gt;Auth-&gt;password($this-&gt;data['User']['password1']);
</pre></p>
<p>For edit(), its a little trickier since you want to check for blank passwords, and if so, leave the user password unchanged.</p>
<p><pre class="brush: php;">
	function edit($id = null) {
		... ...
		if (!empty($this-&gt;data)) {
			// add following code here
			if ($this-&gt;User-&gt;save($this-&gt;data)) {
</pre></p>
<p>add these lines:</p>
<p><pre class="brush: php;">
			// Passwords do not match
			if (!($this-&gt;data['User']['password3'] === 
				$this-&gt;data['User']['password4'])) {
				$this-&gt;Session-&gt;setFlash(__('Passwords do not match.', true));				
				return;
			}
			// If the password is left blank, 
			// just reuse the existing password
			if (strlen($this-&gt;data['User']['password3']) == 0) {
				$User = $this-&gt;User-&gt;read(null, $id);
				$this-&gt;data['User']['password'] = $User['User']['password'];
			} else {
				$this-&gt;data['User']['password'] = 
					$this-&gt;Auth-&gt;password($this-&gt;data['User']['password3']);
			}
</pre></p>
<p>And that&#8217;s it!!! A professional UI for adding users, combined with CakePHP&#8217;s great in-built authentication system!</p>
<p>UPDATE: Oct 1, 1930 EST: In order to view the username and provide a logoff option add this to app_controller.php to provide the variable to all your views:</p>
<p><pre class="brush: php;">
	function beforeRender() { 
		$this-&gt;set('trUsername', $this-&gt;Auth-&gt;user(&quot;username&quot;)); 
	} 
</pre></p>
<p>and this line to somewhere in your views:</p>
<p><pre class="brush: php;">
	&lt;p class=&quot;login&quot;&gt;Logged in as &lt;b&gt;&lt;? echo $trUsername ?&gt;&lt;/b&gt;
	[&lt;?php echo $this-&gt;Html-&gt;link(__('logout', true), array('controller' =&gt; 'users', 'action' =&gt; 'logout')); ?&gt;]
	&lt;/p&gt;
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sumanrs.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sumanrs.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sumanrs.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sumanrs.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/99/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=99&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2011/10/01/cakephp-user-password-manager-authentication-missing-guide/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>Dokuwiki users: generating from a list</title>
		<link>http://sumanrs.wordpress.com/2011/09/24/dokuwiki-users-generating-from-a-list/</link>
		<comments>http://sumanrs.wordpress.com/2011/09/24/dokuwiki-users-generating-from-a-list/#comments</comments>
		<pubDate>Sun, 25 Sep 2011 00:06:11 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[dokuwiki]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=94</guid>
		<description><![CDATA[Recently, I had to create a whole bunch of Dokuwiki users from a list. Here is a script I used for the same. Dokuwiki stores its user info in conf/users.auth.php file. You can generate a list of users from a plain text or other file in this format: john.doe jane.doe john1.doe jane2.doe and then run [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=94&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently, I had to create a whole bunch of Dokuwiki users from a list. Here is a script I used for the same.</p>
<p><span id="more-94"></span></p>
<p>Dokuwiki stores its user info in conf/users.auth.php file. You can generate a list of users from a plain text or other file in this format:</p>
<p><code><br />
john.doe<br />
jane.doe<br />
john1.doe<br />
jane2.doe<br />
</code></p>
<p>and then run the following PHP script (say, name it, dokuusers.php) and output the result to a text file, and move the files as below:<br />
<code><br />
$ php dokuusers.php &gt; users.txt<br />
(copy-paste the user list here)<br />
$ cat users.txt users.auth.php &gt; users2.auth.php<br />
$ mv users2.auth.php users.auth.php<br />
</code></p>
<p>The dokuusers.php file is below.</p>
<p><pre class="brush: php;">
&lt;?
/* Customize these lines */
// Company e-mail domain
$companyDomain = &quot;company.com&quot;;
// Group(s) to add users to
$groups = &quot;user&quot;;
// Function that returns password string
// First example: john.doe has password john11111
function passwd ($string) {
        return $string . &quot;11111&quot;;
}

$f = fopen('php://stdin', 'r');
while ($line = fgets($f)) {
        $line = trim($line);
        list($first, $last) = explode(&quot;.&quot;, $line);
        $passwd = md5(passwd($first));
        $name = ucfirst ($first) . &quot; &quot; . ucfirst ($last);
        $email = $line . &quot;@&quot; . $companyDomain;

        echo &quot;$line:$passwd:$name:$email:$groups\n&quot;;
}
?&gt;
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sumanrs.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sumanrs.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sumanrs.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sumanrs.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=94&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2011/09/24/dokuwiki-users-generating-from-a-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>Joomla plugin upgrade/migration from 1.0 to 1.5</title>
		<link>http://sumanrs.wordpress.com/2011/08/06/joomla-plugin-upgrademigration-from-1-0-to-1-5/</link>
		<comments>http://sumanrs.wordpress.com/2011/08/06/joomla-plugin-upgrademigration-from-1-0-to-1-5/#comments</comments>
		<pubDate>Sat, 06 Aug 2011 21:09:15 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[joomla]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=83</guid>
		<description><![CDATA[Recently I had to migrate some custom Joomla plugins on an old 1.0.x Joomla website to a 1.5 based Joomla website. I am noting down how I did this since there doesn&#8217;t seem to be a similar document out there. Installation XML You can keep the name (plugin.xml). Make sure to change the first two [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=83&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I had to migrate some custom Joomla plugins on an old 1.0.x Joomla website to a 1.5 based Joomla website. I am noting down how I did this since there doesn&#8217;t seem to be a similar document out there.</p>
<p><span id="more-83"></span></p>
<h2>Installation XML</h2>
<p>You can keep the name (plugin.xml).<br />
Make sure to change the first two lines and the last line:</p>
<p><pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;
&lt;mosinstall version=&quot;1.0&quot; type=&quot;mambots&quot; group=&quot;content&quot;&gt;
...
&lt;/mosinstall&gt;
</pre></p>
<p>to:</p>
<p><pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;install version=&quot;1.5&quot; type=&quot;plugin&quot; group=&quot;content&quot;&gt;
...
&lt;/install&gt;
</pre></p>
<p>Add an author e-mail as well:</p>
<p><pre class="brush: xml;">
&lt;authorEmail&gt;aaa@aaa.com&lt;/authorEmail&gt;
</pre></p>
<p>Change the attribute from &#8220;mambot&#8221; to &#8220;plugin&#8221;:</p>
<p><pre class="brush: xml;">
&lt;filename mambot=&quot;etplugin&quot;&gt;etplugin.php&lt;/filename&gt;
</pre></p>
<p>&nbsp;</p>
<p><pre class="brush: xml;">
&lt;filename plugin=&quot;etplugin&quot;&gt;etplugin.php&lt;/filename&gt;
</pre></p>
<h2>Plugin code</h2>
<p>Keep the same file name : plugin.php</p>
<p>Change the first line from:</p>
<p><pre class="brush: php;">
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
</pre></p>
<p>to</p>
<p><pre class="brush: php;">
defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );
</pre></p>
<p>Change registerFunction() to registerEvent():</p>
<p><pre class="brush: php;">
$_MAMBOTS-&gt;registerFunction( 'onPrepareContent', 'botFnCall' );
</pre><br />
to<br />
<pre class="brush: php;">
$mainframe-&gt;registerEvent( 'onPrepareContent', 'plgFnCall' );
</pre></p>
<p>Make sure to <a href="http://www.theartofjoomla.com/converting-old-extensions.html">change references for variables such as $mosConfig_live_site, $mosConfig_absolute_path, $database, etc</a> as specified here.</p>
<p>The function call construct no longer has four arguments:</p>
<p><pre class="brush: php;">
function botFnCall( $published, &amp;$row, $mask=0, $page=0  ) {
</pre></p>
<p>Instead it has three:</p>
<p><pre class="brush: php;">
function plgFnCall( &amp;$row, &amp;$params, $page=0 ) {
</pre></p>
<p>Add a performance check for good measure:</p>
<p><pre class="brush: php;">
	// simple performance check to determine whether bot should process further
	if ( JString::strpos( $row-&gt;text, 'pluginTag' ) === false ) {
		return true;
	}
</pre></p>
<p>Change the published check:</p>
<p><pre class="brush: php;">
	if (!$published) {
		return true;
	}
</pre></p>
<p>to:</p>
<p><pre class="brush: php;">
	if ( !$params-&gt;get( 'enabled', 1 ) ) {
		return true;
	}
</pre></p>
<p>Change any references to the &#8220;/mambots/&#8221; directory to &#8220;/plugins/&#8221; (if you&#8217;re including custom CSS, JS, and the like.)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sumanrs.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sumanrs.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sumanrs.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sumanrs.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/83/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=83&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2011/08/06/joomla-plugin-upgrademigration-from-1-0-to-1-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>Lazy loading of images (jquery) without scrolling</title>
		<link>http://sumanrs.wordpress.com/2011/02/08/jquery-lazy-loading-images-no-scrolling/</link>
		<comments>http://sumanrs.wordpress.com/2011/02/08/jquery-lazy-loading-images-no-scrolling/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 05:27:33 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[jquery]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[lazy loading]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=69</guid>
		<description><![CDATA[Lazy loading of images is an awesome idea. But while the current jQuery lazy loading plugin requires one to scroll, this one doesn&#8217;t! And in only 4 lines of jQuery code! Lazy loading of images is great. And there&#8217;s even a jQuery plugin for lazy loading. The one problem is: I don&#8217;t want my images [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=69&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Lazy loading of images is an awesome idea. But while the current jQuery lazy loading plugin requires one to scroll, this one doesn&#8217;t! And in only 4 lines of jQuery code!</p>
<p><span id="more-69"></span></p>
<p>Lazy loading of images is great. And there&#8217;s even a <a href="http://www.appelsiini.net/projects/lazyload">jQuery plugin for lazy loading</a>.</p>
<p>The one problem is: I don&#8217;t want my images to load only during a scroll &#8211; I want lazy loading, but want the images loaded right after the Javascript kicks in.</p>
<p>So I did some experimenting, and was able to replace:</p>
<p><pre class="brush: jscript;">
$(&quot;img.lazyload&quot;).lazyload();
</pre></p>
<p>with this:</p>
<p><pre class="brush: jscript;">
$(&quot;img.lazyload&quot;).each(function() {
    $(this).attr(&quot;src&quot;, $(this).attr(&quot;original&quot;));
    $(this).removeAttr(&quot;original&quot;);
});
</pre></p>
<p>And that&#8217;s it! Lazy loading of images on your website, but without requiring the scroll. (You can delete the removeAttr() line if you want, I just like my rendered HTML to be clean.)</p>
<p>And best of all, you don&#8217;t need a jQuery plugin to achieve this &#8211; it can be done with just the basic jQuery library.</p>
<p>Note that the above requires the patched version of lazy-loading, which only works when your original HTML code for images looks like this:</p>
<p><pre class="brush: xml;">
&lt;img src=&quot;maybe_1x1_image_placeholder.png&quot; original=&quot;original_image.jpg&quot; alt=&quot;&quot; /&gt;
</pre></p>
<p>Yes, it breaks HTML semantics, but is probably the only way to achieve lazy loading on modern browsers. More info below.</p>
<h2>More on Lazy Loading</h2>
<p><a href="http://www.appelsiini.net/projects/lazyload">Lazy loading of images is an awesome idea</a>. The idea behind lazy loading of images is to load images for a website after the page is fully loading, thus enabling the browser to fully load the page even without all images completely loaded. And lazy loading loads the images when required.</p>
<p>Problem is, it doesn&#8217;t work on modern browsers. This is a pity, since I think that plugin is really cool, and is well written.</p>
<p>There are some patches that work, but this <a href="http://www.appelsiini.net/2009/12/tuning-lazy-loader">requires one to swap the original &#8220;src&#8221; attribute of the image with another fake one</a> (called &#8220;original&#8221;) and then let the Javascript work its magic during load time.</p>
<p>While this breaks webpage semantics, its apparently the only way to get things to work on current browsers, particularly Webkit-based ones (Safari, Chrome). (And it may break SEO functionality, since you are replacing img src and pointing to a fake image, and the replacement/load is done in Javascript.)</p>
<p>But that didn&#8217;t stop me, since it works well and loads my site faster. :)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sumanrs.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sumanrs.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sumanrs.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sumanrs.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=69&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2011/02/08/jquery-lazy-loading-images-no-scrolling/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP script to download sequence of files from website</title>
		<link>http://sumanrs.wordpress.com/2010/12/24/php-script-to-download-sequence-of-files-from-website/</link>
		<comments>http://sumanrs.wordpress.com/2010/12/24/php-script-to-download-sequence-of-files-from-website/#comments</comments>
		<pubDate>Fri, 24 Dec 2010 21:18:16 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=64</guid>
		<description><![CDATA[I often find myself having to read documents split into multiple files, and it becomes a pain to bookmark and go back to them later. I prefer downloading them (if I can) to my local hard drive and place them into a folder. Sometimes the documents are numbered sequentially, which is really helpful since I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=64&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I often find myself having to read documents split into multiple files, and it becomes a pain to bookmark and go back to them later. I prefer downloading them (if I can) to my local hard drive and place them into a folder. Sometimes the documents are numbered sequentially, which is really helpful since I can use a PHP script to just automate the download.</p>
<p><span id="more-64"></span></p>
<p>This is the PHP script that I wrote recently to automate some of my downloads. Note that there are two pre-requisites to be able to run this script:</p>
<ul>
<li>PHP command-line program (php5-cli) has to be installed</li>
<li>file_get_contents() has to allow remote URL fetches</li>
</ul>
<p>Without much ado, here is the script.</p>
<p><pre class="brush: php;">
&lt;?
/*
 * THIS SCRIPT DOWNLOADS A SEQUENCE OF FILES FROM THE WEB
 * TO THE LOCAL DRIVE.
 * Released under GPL.
 * Author: Suman Srinivasan, Dec 24, 2010
 */

/* Replace the parameters below with the names you need.
 * The &quot;{x}&quot; part of the string pattern will be replaced by the 
 * number in the script. */

/* The initial parameters */
// Source URL pattern
$sourceURLOriginal = &quot;http://www.somewebsite.com/document{x}.pdf&quot;;
// Destination folder
$destinationFolder = &quot;.&quot;;
// Destination file name pattern
$destinationFileNameOriginal = &quot;doc{x}.pdf&quot;;
// Start number
$start = 1;
// End number
$end = 10;

// From start to end
for ($i=$start; $i&lt;=$end; $i++) {
	// Replace source URL parameter with number
	$sourceURL = str_replace(&quot;{x}&quot;, $i, $sourceURLOriginal);
	// Destination file name
	$destinationFile = $destinationFolder . &quot;/&quot; . 
		str_replace(&quot;{x}&quot;, $i, $destinationFileNameOriginal);
	// Read from URL, write to file
	file_put_contents($destinationFile, 
		file_get_contents($sourceURL)
	);
	// Output progress
	echo &quot;File #$i complete\n&quot;;
}
?&gt;
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sumanrs.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sumanrs.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sumanrs.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sumanrs.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=64&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2010/12/24/php-script-to-download-sequence-of-files-from-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>DokuWiki: Redirect users on logout to front/start page</title>
		<link>http://sumanrs.wordpress.com/2010/12/21/dokuwiki-redirect-users-logout-front-start-page/</link>
		<comments>http://sumanrs.wordpress.com/2010/12/21/dokuwiki-redirect-users-logout-front-start-page/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 20:59:19 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[dokuwiki]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=57</guid>
		<description><![CDATA[I have a DokuWiki site for some documentation, and I needed to have it so that users who are logging off and then logging back in are always redirected to the home page. (DokuWiki, by default, redirects them to the page that they were on when the logged out.) I was able to find the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=57&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have a DokuWiki site for some documentation, and I needed to have it so that users who are logging off and then logging back in are always redirected to the home page. (DokuWiki, by default, redirects them to the page that they were on when the logged out.)</p>
<p><span id="more-57"></span></p>
<p>I was able to find the code to handle this in actions.php in the root of my Dokuwiki install. In that file, there is a function called function act_auth($act). In that function, look for this piece of code:<br />
<pre class="brush: php;">
  //handle logout
  if($act=='logout'){
</pre></p>
<p>That&#8217;s the one that handles the action when users log out.</p>
<p>The last line of that control sequence is:<br />
<pre class="brush: php;">
    act_redirect($ID,'login');
</pre></p>
<p>You just need to replace $ID with &#8220;&#8221;, and that redirects all users who are logging off to the front/home page. So when they log back in, they are on the start page.</p>
<p>New code:<br />
<pre class="brush: php;">
    act_redirect(&quot;&quot;,'login');
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sumanrs.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sumanrs.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sumanrs.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sumanrs.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=57&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2010/12/21/dokuwiki-redirect-users-logout-front-start-page/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>Network Experiment with Three VMWare Nodes on One Machine</title>
		<link>http://sumanrs.wordpress.com/2010/09/21/network-three-vmware-one-machine/</link>
		<comments>http://sumanrs.wordpress.com/2010/09/21/network-three-vmware-one-machine/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 16:28:24 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[Network]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[topology]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=46</guid>
		<description><![CDATA[Recently I had to set up a network experiment using three nodes, and I had only one machine, and I was able to successfully set this up using three VMs on VMWare Workstation. This is how I did it.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=46&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I had to set up a network experiment using three nodes, and I had only one machine, and I was able to successfully set this up using three VMs on VMWare Workstation. This is how I did it.</p>
<p><span id="more-46"></span></p>
<div id="attachment_47" class="wp-caption aligncenter" style="width: 490px"><a href="http://sumanrs.files.wordpress.com/2010/09/three_nodes_vmware.png"><img class="size-full wp-image-47 " title="Three VMWare Nodes" src="http://sumanrs.files.wordpress.com/2010/09/three_nodes_vmware.png?w=600" alt=""   /></a><p class="wp-caption-text">Three VMWare nodes running on one machine. This is the network topology to configure.</p></div>
<p>I had to set up the following:</p>
<ul>
<li><strong>Content server:</strong> public IP address with Apache installed</li>
<li><strong>NetServ node:</strong> a router with one public IP and one private IP</li>
<li><strong>Client:</strong> Private IP, connected through the NetServ node gateway</li>
</ul>
<p>I need the client to access the outside world only through the NetServ router.</p>
<p>First, I downloaded a Fedora 10 VMWare image from thoughtpolice.co.uk and configured it as I needed. Then I made three copies of it.</p>
<p><em>[<strong>Note about clean-start:</strong> When copying the VMWare images to create clones, make sure to shutdown the images first before copying. The reason is that when you copy and start the clone, VMWare changes the MAC address and other settings, and you need to clean-start the VM to get the new MAC address and other settings to apply.]</em></p>
<p>I then created a few virtual network configurations to get my network topology right. A screenshot of the Virtual Network Editor is below.</p>
<div id="attachment_45" class="wp-caption aligncenter" style="width: 490px"><a href="http://sumanrs.files.wordpress.com/2010/09/vm_editor.png"><img class="size-full wp-image-45" title="Virtual Network Editor" src="http://sumanrs.files.wordpress.com/2010/09/vm_editor.png?w=600" alt=""   /></a><p class="wp-caption-text">The Virtual Network Editor showing the three VMNets used in the experiment.</p></div>
<ul>
<li>I have three physical network adapters. I configured each of them to map to one particular VMNet. VMNet0 is bridged to the first physical adapter (that is my host machine).
<ul>
<li>The two other VMNets &#8211; which are bridged to the physical adapters &#8211; are the ones used by the public network adapters for the Content Server and the NetServ node.</li>
</ul>
</li>
<li>For the private network, I created host-only VMNet with DHCP service, which basically provides a private network.
<ul>
<li>The private network adapter for the NetServ node and the Client are mapped to this VMNet.</li>
</ul>
</li>
</ul>
<div id="attachment_50" class="wp-caption aligncenter" style="width: 490px"><a href="http://sumanrs.files.wordpress.com/2010/09/client_privateip_setting.png"><img class="size-full wp-image-50" title="client_privateip_setting" src="http://sumanrs.files.wordpress.com/2010/09/client_privateip_setting.png?w=600" alt=""   /></a><p class="wp-caption-text">Settings for Client VMWare network adapter.</p></div>
<p>So far, so good. Boot up the nodes and they should get correct IP addresses and:</p>
<ul>
<li>Content Server and Netserv Node can connect to the public Internet.</li>
<li>Client can only ping the Netserv node&#8217;s private IP address.</li>
</ul>
<p>Now to get the full network topology working.</p>
<p>For this, we need to allow NetServ node to run as a router and a DNS server. Here is how to do so (all as root):</p>
<ul>
<li>
<pre>/etc/init.d/dnsmasq start</pre>
</li>
<li>
<pre><a href="http://www.ducea.com/2006/08/01/how-to-enable-ip-forwarding-in-linux/">echo 1 &gt; /proc/sys/net/ipv4/ip_forward</a></pre>
</li>
<li><a href="http://billauer.co.il/ipmasq-html.html" target="_blank">Several iptables rules</a></li>
</ul>
<p>Now, on the client machine, you need to set up the default gateway to be the NetServ router:</p>
<ul>
<li>
<pre>route add default gw NETSERV_IP_ADDR eth0</pre>
</li>
</ul>
<p>[UPDATE Sep 24 2010] On the client machine, you also need to:</p>
<ul>
<li>
<pre>sudo vi /etc/resolv.conf</pre>
</li>
</ul>
<p>and add the NetServ/gateway machine as the default DNS server.</p>
<p>And that&#8217;s it : you should have a complete network topology up and running! Try a few pings and opening a few websites, and it should all work!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sumanrs.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sumanrs.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sumanrs.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sumanrs.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/46/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=46&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2010/09/21/network-three-vmware-one-machine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>

		<media:content url="http://sumanrs.files.wordpress.com/2010/09/three_nodes_vmware.png" medium="image">
			<media:title type="html">Three VMWare Nodes</media:title>
		</media:content>

		<media:content url="http://sumanrs.files.wordpress.com/2010/09/vm_editor.png" medium="image">
			<media:title type="html">Virtual Network Editor</media:title>
		</media:content>

		<media:content url="http://sumanrs.files.wordpress.com/2010/09/client_privateip_setting.png" medium="image">
			<media:title type="html">client_privateip_setting</media:title>
		</media:content>
	</item>
		<item>
		<title>Simple PHP Persistent Storage</title>
		<link>http://sumanrs.wordpress.com/2010/07/13/simple-php-persistent-storage/</link>
		<comments>http://sumanrs.wordpress.com/2010/07/13/simple-php-persistent-storage/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 21:02:21 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=37</guid>
		<description><![CDATA[For a project I am working on, I had to put together a demo using PHP. One of the aspects of this demo is that it needed a simple persistent storage: it has to keep a count of the number of times a particular URL is passed as an argument, and do something relevant. Instead [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=37&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For a project I am working on, I had to put together a demo using PHP. One of the aspects of this demo is that it needed a simple persistent storage: it has to keep a count of the number of times a particular URL is passed as an argument, and do something relevant.</p>
<p>Instead of using a MySQL database, I simply used an associative array and serialize() and unserialize().</p>
<p><span id="more-37"></span>So my code basically looked something like this:</p>
<p><pre class="brush: php;">
if (numberOfUrl ($url) == 0)
  do_something_for_first_request();
else
  do_something_for_subsequent_requests();
</pre></p>
<p>But the function numberOfUrl($url) needs persistent storage &#8211; and MySQL would have been overkill.</p>
<p>So I used a simple associative array and serialize() and unserialize() to a file.</p>
<p><pre class="brush: php;">
/**
* Returns the number of times this URL has been requested
*/
function numberOfUrl ($url) {
  // The file name
  $arrayFile = &quot;urls.db&quot;;

  // Read the file, unserialize it to an array
  $urlArray = unserialize (file_get_contents($arrayFile));

  // If this URL exists in the array, just increment it
  if (isset ($urlArray[$url]))
    $urlArray[$url]++;
  // Otherwise add a new entry and set it to 1
  else
    $urlArray[$url] = 1;

  // Write out the serialized array back to disk
  file_put_contents ($arrayFile, serialize($urlArray));

  // Return the number of accesses
  return $urlArray[$url] - 1;
}
</pre></p>
<p>Of course, you will have to implement some form of mutual exclusion or locks to ensure that the whole thing happens as a transaction, especially if this PHP code can be accessed by multiple clients at the same time.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sumanrs.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sumanrs.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sumanrs.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sumanrs.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&amp;blog=3501934&amp;post=37&amp;subd=sumanrs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2010/07/13/simple-php-persistent-storage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
	</channel>
</rss>
