<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en" xml:base="http://www.mind-it.info/wp-atom.php">
	<title type="text">Mind IT</title>
	<subtitle type="text">IT Architecture, Web Technology and Information Security</subtitle>

	<updated>2012-05-17T11:47:03Z</updated>

	<link rel="alternate" type="text/html" href="http://www.mind-it.info" />
	<id>http://www.mind-it.info/feed/</id>
	

	
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/mind-it/Aqwc" /><feedburner:info uri="mind-it/aqwc" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" /><entry>
		<author>
			<name>postme</name>
					</author>
		<title type="html"><![CDATA[A simple PHP template engine]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mind-it/Aqwc/~3/6owelB0Vghc/" />
		<id>http://www.mind-it.info/?p=391</id>
		<updated>2012-05-07T21:02:55Z</updated>
		<published>2012-01-08T15:09:50Z</published>
		<category scheme="http://www.mind-it.info" term="PHP" /><category scheme="http://www.mind-it.info" term="Webtechnology" />		<summary type="html"><![CDATA[There&#8217;s a ton of documentation available if you want to do template handling in PHP. This article is only about documenting the simple approach I use myself for a PHP template engine. I&#8217;m not going to enter the arena by &#8230; <a href="http://www.mind-it.info/2012/01/08/a-simple-template-approach-for-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></summary>
		<content type="html" xml:base="http://www.mind-it.info/2012/01/08/a-simple-template-approach-for-php/">&lt;p&gt;There&amp;#8217;s a ton of documentation available if you want to do template handling in PHP. This article is only about documenting the simple approach I use myself for a PHP template engine. I&amp;#8217;m not going to enter the arena by stating PHP is a template language itself etc &amp;#8230;, that&amp;#8217;s just plain boring.&lt;/p&gt;
&lt;p&gt;So what&amp;#8217;s the intention here? The objective is to have a plain HTML file and replace content at certain places where you want PHP driven output to show. But by and itself the HTML file is just that, plain HTML with inclusion of CSS and JS where necessary.&lt;/p&gt;
&lt;p&gt;My standard HTML file is shown below:&lt;/p&gt;
&lt;pre class="brush:html"&gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
	&amp;lt;title&amp;gt;{title}&amp;lt;/title&amp;gt;
	&amp;lt;meta http-equiv=&amp;quot;content-type&amp;quot; content=&amp;quot;text/html; charset=utf-8&amp;quot; /&amp;gt;
	&amp;lt;meta http-equiv=&amp;quot;content-language&amp;quot; content=&amp;quot;{language}&amp;quot; /&amp;gt;
	&amp;lt;meta name=&amp;quot;author&amp;quot; content=&amp;quot;M.E. Post&amp;quot; /&amp;gt;
	&amp;lt;meta name=&amp;quot;copyright&amp;quot; content=&amp;quot;Copyright (c) M.E. Post 2008&amp;quot; /&amp;gt;
	&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;{includepath}/css/include.css&amp;quot; type=&amp;quot;text/css&amp;quot; media=&amp;quot;screen&amp;quot; /&amp;gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;
        var path = '{includepath}';
        &amp;lt;/script&amp;gt;
        &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;{includepath}/js/jquery-1.3.2.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;{includepath}/js/include.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
	&amp;lt;div id=&amp;quot;rap&amp;quot;&amp;gt;
	  &amp;lt;div id=&amp;quot;headwrap&amp;quot;&amp;gt;
		  &amp;lt;div id=&amp;quot;header&amp;quot;&amp;gt;
			  &amp;lt;a href=&amp;quot;{path}/&amp;quot;&amp;gt;{title}&amp;lt;/a&amp;gt;
		  &amp;lt;/div&amp;gt;
		  &amp;lt;div id=&amp;quot;desc&amp;quot;&amp;gt;
			  &amp;lt;a href=&amp;quot;{path}/&amp;quot;&amp;gt;{subtitle}&amp;lt;/a&amp;gt;
		  &amp;lt;/div&amp;gt;
	  &amp;lt;/div&amp;gt;
	  &amp;lt;div id=&amp;quot;content&amp;quot;&amp;gt;
		  &amp;lt;div class=&amp;quot;storycontent&amp;quot;&amp;gt;
		    {replace_content}
		  &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
&lt;p&gt;As you can see it&amp;#8217;s a very minimal file and there are some elements in there like {includepath} and {replace_content} which are not regular html. These are the placeholders where content will be replaced.&lt;/p&gt;
&lt;p&gt;Replacing the content is executed by the function below. It gets the content transferred through the variable $content, if the $content variable is empty it returns FALSE and aborts the function. After that it checks whether the template has already been loaded through checking the static $template, if it&amp;#8217;s empty the template file is loaded, otherwise it will reuse the previously loaded template. All the template placeholders are replaced through a loop using mb_ereg_replace to make the text unicode compliant. The replaced template is returned as output of the function. Items like PATH et al are constants that are defined previously, you can take them out or add them to the function call if you want.&lt;/p&gt;
&lt;pre class="brush:php"&gt;
/**
* Merge the page template with the content
*
* @param string $content
* @return string
*/
function mergeContentWithTemplate($content='') {
	if (empty($content)) {
		return FALSE;
	}
	/* Static keyword is used to ensure the file is loaded only once */
	static $template = NULL;
	/* If no instance of $template has occured load the template file */
	if (is_null($template)) {
		$template_file = dirname(__FILE__) . '/../html/template.html';
		$template_file_content = file_get_contents($template_file);
	}
	mb_regex_encoding('utf-8');
	$pattern = array('{path}', '{includepath}', '{language}', '{title}', '{subtitle}', '{replace_content}');
	$replacement = array(PATH, INCLUDE_PATH, LANGUAGE, TITLE, SUBTITLE, $content);
	$pattern_size = sizeof($pattern);
	for ($i = 0; $i &amp;lt; $pattern_size; $i++) {
		$template_file_content = mb_ereg_replace($pattern[$i], $replacement[$i], $template_file_content);
	}
	return $template_file_content;
}
&lt;/pre&gt;
&lt;p&gt;So that&amp;#8217;s my simple little template thingy, hope it is of some use to you.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/mind-it/Aqwc/~4/6owelB0Vghc" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.mind-it.info/2012/01/08/a-simple-template-approach-for-php/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.mind-it.info/2012/01/08/a-simple-template-approach-for-php/feed/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://www.mind-it.info/2012/01/08/a-simple-template-approach-for-php/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>postme</name>
					</author>
		<title type="html"><![CDATA[NIST RBAC Data Model update]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mind-it/Aqwc/~3/G67NNyLSPCo/" />
		<id>http://www.mind-it.info/?p=363</id>
		<updated>2012-04-22T17:30:19Z</updated>
		<published>2011-06-11T19:03:41Z</published>
		<category scheme="http://www.mind-it.info" term="Information Security" /><category scheme="http://www.mind-it.info" term="RBAC" /><category scheme="http://www.mind-it.info" term="SQL" />		<summary type="html"><![CDATA[It&#8217;s been a while since I last posted on the NIST RBAC Data Model and there have some (small) changes that make it a good idea to do a new post on this topic. I&#8217;ve made two changes to the &#8230; <a href="http://www.mind-it.info/2011/06/11/nist-rbac-data-model-update/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></summary>
		<content type="html" xml:base="http://www.mind-it.info/2011/06/11/nist-rbac-data-model-update/">&lt;p&gt;It&amp;#8217;s been a while &lt;a href="http://www.mind-it.info/2010/01/09/nist-rbac-data-model/"&gt;since I last posted&lt;/a&gt; on the NIST RBAC Data Model and there have some (small) changes that make it a good idea to do a new post on this topic.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve made two changes to the data model:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Removed the many-to-many mapping in user/sessions and replaced it with a one-to-many mapping because each session is associated with a single user and each user is associated with one or more sessions.&lt;/li&gt;
&lt;li&gt;Renamed table &amp;#8220;user&amp;#8221; to &amp;#8220;users&amp;#8221; to avoid clashes in PostgreSQL and changed all associated references&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can find the database independent model &lt;a href='http://cdn.mind-it.info/wp-content/uploads/2011/06/rbac_nist_.zip'&gt;here&lt;/a&gt; as a &lt;a href="http://www.datanamic.com/dezign/index.html"&gt;Dezign for Databases&lt;/a&gt; file.&lt;/p&gt;
&lt;p&gt;Specific output formats for both MySQL 5 and PostgreSQL 9 are included below.&lt;/p&gt;
&lt;p&gt;&lt;a href='http://cdn.mind-it.info/wp-content/uploads/2011/06/mysql_5.txt'&gt;MySQL 5 DDL file (text based)&lt;/a&gt;&lt;br /&gt;
&lt;a href='http://cdn.mind-it.info/wp-content/uploads/2011/06/postgres_9.txt'&gt;PostgreSQL 9 DDL file (text based)&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/mind-it/Aqwc/~4/G67NNyLSPCo" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.mind-it.info/2011/06/11/nist-rbac-data-model-update/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://www.mind-it.info/2011/06/11/nist-rbac-data-model-update/feed/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://www.mind-it.info/2011/06/11/nist-rbac-data-model-update/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>postme</name>
					</author>
		<title type="html"><![CDATA[EC2 and rsync]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mind-it/Aqwc/~3/NIOmT8P4orc/" />
		<id>http://www.mind-it.info/?p=354</id>
		<updated>2012-05-17T07:31:49Z</updated>
		<published>2011-05-26T19:28:41Z</published>
		<category scheme="http://www.mind-it.info" term="Cloud" />		<summary type="html"><![CDATA[I keep forgetting this so for my own feeble memory here is the correct invocation to rsync between two EC2 instances: rsync -avz --port=22 root@&#60;privateDNS name remote server&#62;:/var/www/html/&#60;directory&#62;/ -e &#34;ssh -i /home/&#60;user&#62;/&#60;pem file&#62;&#34; /var/www/html/&#60;local directory&#62;/ Works like a charm and &#8230; <a href="http://www.mind-it.info/2011/05/26/ec2-and-rsync/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></summary>
		<content type="html" xml:base="http://www.mind-it.info/2011/05/26/ec2-and-rsync/">&lt;p&gt;I keep forgetting this so for my own feeble memory here is the correct invocation to rsync between two EC2 instances:&lt;/p&gt;
&lt;pre class="brush:bash"&gt;
rsync -avz --port=22 root@&amp;lt;privateDNS name remote server&amp;gt;:/var/www/html/&amp;lt;directory&amp;gt;/ -e &amp;quot;ssh -i /home/&amp;lt;user&amp;gt;/&amp;lt;pem file&amp;gt;&amp;quot; /var/www/html/&amp;lt;local directory&amp;gt;/
&lt;/pre&gt;
&lt;p&gt;Works like a charm and much faster than using your home workstation as an intermediary to copy stuff between server instances.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/mind-it/Aqwc/~4/NIOmT8P4orc" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.mind-it.info/2011/05/26/ec2-and-rsync/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.mind-it.info/2011/05/26/ec2-and-rsync/feed/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://www.mind-it.info/2011/05/26/ec2-and-rsync/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>postme</name>
					</author>
		<title type="html"><![CDATA[How to make WordPress very secure, very fast and very resilient]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mind-it/Aqwc/~3/2AWLmOGh2eU/" />
		<id>http://www.mind-it.info/?p=338</id>
		<updated>2012-05-17T11:47:03Z</updated>
		<published>2011-05-21T19:49:19Z</published>
		<category scheme="http://www.mind-it.info" term="Architecture" /><category scheme="http://www.mind-it.info" term="Information Security" /><category scheme="http://www.mind-it.info" term="PHP" /><category scheme="http://www.mind-it.info" term="Webtechnology" /><category scheme="http://www.mind-it.info" term="Wordpress" />		<summary type="html"><![CDATA[Now that&#8217;s a big claim but I can assure you its true for all three aspects. It doesn&#8217;t even require heavy customisation and the approach is based on standard plugins available on the WordPress plugin site. However like everything there&#8217;s &#8230; <a href="http://www.mind-it.info/2011/05/21/how-to-make-wordpress-very-secure-very-fast-and-very-resilient/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></summary>
		<content type="html" xml:base="http://www.mind-it.info/2011/05/21/how-to-make-wordpress-very-secure-very-fast-and-very-resilient/">&lt;p&gt;Now that&amp;#8217;s a big claim but I can assure you its true for all three aspects. It doesn&amp;#8217;t even require heavy customisation and the approach is based on standard plugins available on the WordPress plugin site. However like everything there&amp;#8217;s a trade off with the approach and in this case its the loss of flexibility and dynamic behaviour. This isn&amp;#8217;t an issue with static websites but if you&amp;#8217;re running a blog then this solution isn&amp;#8217;t for you (stuff like comments won&amp;#8217;t work as this requires connectivity and feedback from WordPress). It&amp;#8217;s up to you to decide whether my approach has merits for your use case. I offer no guarantees other than that I have applied the approach below to my own systems and for me it works. It&amp;#8217;s very rough around the edges, I have been hacking some files and I haven&amp;#8217;t rolled my changes into a nice shrink wrap form. Enough with the disclaimers let&amp;#8217;s get going with an actual explanation of what I&amp;#8217;m offering.&lt;/p&gt;
&lt;h2&gt;Security&lt;/h2&gt;
&lt;p&gt;WordPress suffers from the same problem that almost all Content Management Systems (CMS) suffer from, it has a unified code base for both content publication and content management. With WordPress (and similar systems) that share the same code base it is possible to hack the content management system through the content publication system. The content publication system is the aspect of the CMS that generates the pages if a visitor hits the site. The content publication system by its very nature is an open interface to the outside world and can therefor be hacked. By the fact that it shares code with the CMS system it is inevitable that also the CMS can be compromised in an attack on the content publication system. These hacks occur time and again and are endemic to the shared code approach so they will never go away. The only way of ensuring your CMS is not hacked through your content publication system is by separating the two. Now separation in a physical (code) sense is possible but requires a huge amount of effort and in effect means a different version of WordPress through a fork. This is not what I want to achieve, I have limited time and I can&amp;#8217;t maintain my own version of WordPress and keep up with all the new functionality that the WordPress team cranks out all the time. Therefore I mean separation in a logical sense and this I achieve through the use of &lt;a href="http://ocaoimh.ie/wp-super-cache/"&gt;WP SuperCache&lt;/a&gt;. WP Super Cache turns your WordPress site/blog into a collection of static pages and it uses a .htaccess mod_rewrite approach to serve customers the static pages. It also has an option to serve page components like JS, CSS and images from a Content Delivery Network (CDN). My approach to separating the CMS from content publication is that I turn the WP Super Cache cache (pardon the pun) into its own virtual host in Apache and serve content in its static form from that Virtual Host. My visitors don&amp;#8217;t need to access the WordPress installation to get to the content, the CMS and the content publication are logically separated. Now there&amp;#8217;s a couple of tricks required for getting this up and running and I&amp;#8217;ll explain these later in this post.&lt;/p&gt;
&lt;h2&gt;Speed&lt;/h2&gt;
&lt;p&gt;The approach of moving your page components into a CDN is well known and relatively straightforward to achieve with solutions like WP Super Cache or &lt;a href="http://wordpress.org/extend/plugins/w3-total-cache/"&gt;W3 Total Cache&lt;/a&gt;. Going one step further and moving your entire site, so including your html is a little less usual but that is what I have achieved. My test site (not this one) based on the standard twentyten theme &lt;a href="http://www.webpagetest.org"&gt;now loads in 1.223 seconds&lt;/a&gt; of which 0.252 seconds is spent on the DNS lookups. The html and all other page components are served through &lt;a href="http://aws.amazon.com/cloudfront/"&gt;Amazon Cloudfront&lt;/a&gt; using &lt;a href="http://knowledgelayer.softlayer.com/questions/365/How+does+Origin+Pull+work%3F"&gt;Origin Pull&lt;/a&gt; (but any other CDN can do the same, there is no Cloudfront specific trickery involved).&lt;/p&gt;
&lt;h2&gt;How it works&lt;/h2&gt;
&lt;p&gt;There&amp;#8217;s a couple of code changes involved and some Apache and DNS configuration changes. What do you need:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;LAMP platform and WordPress. I used the most recent version of WordPress (3.1.2) at the time of writing. Hosting is done on Amazon EC2 with a CentOS 5.6 based system&lt;/li&gt;
&lt;li&gt;WP Super Cache plugin installed&lt;/li&gt;
&lt;li&gt;A CDN, I used Amazon Cloudfront&lt;/li&gt;
&lt;li&gt;Access to DNS for setting CNAME records&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;#8217;m assuming you have a functioning LAMP server. The following steps need to be executed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a virtual host in Apache for the WordPress site&lt;/li&gt;
&lt;li&gt;Install WordPress and WP Super Cache plugin&lt;/li&gt;
&lt;li&gt;Configure the WP Super Cache plugin&lt;/li&gt;
&lt;li&gt;Code hacks to the WP Super Cache plugin&lt;/li&gt;
&lt;li&gt;Set up your CDN&lt;/li&gt;
&lt;li&gt;Configure your DNS&lt;/li&gt;
&lt;li&gt;Test&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We&amp;#8217;re going to put the WordPress site in a directory called &amp;#8220;wordpress&amp;#8221; located in /var/www/html (CentOS/Fedora default) and create a special virtual host called cms.example.com:&lt;/p&gt;
&lt;pre class="brush:bash"&gt;
&amp;lt;VirtualHost *:80&amp;gt;
ServerName cms.example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/html/wordpress
LogLevel info
ErrorLog logs/error_log
TransferLog logs/access_log
&amp;lt;/VirtualHost&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Install WordPress in the /var/www/html/wordpress directory and configure it with the cms.example.com home/site url. Check that the installation completed sucessfully and you can access the admin interface at http://cms.example.com/wp-admin/. Install the WP Super Cache plugin as explained by the &lt;a href="http://wordpress.org/extend/plugins/wp-super-cache/installation/"&gt;documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Configure the WP Super Cache plugin as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Advanced settings:
&lt;ul&gt;
&lt;li&gt;Cache hits to this website for quick access&lt;/li&gt;
&lt;li&gt;Use PHP to serve cache files&lt;/li&gt;
&lt;li&gt;304 Not Modified browser caching. Indicate when a page has not been modified since last requested&lt;/li&gt;
&lt;li&gt;Cache rebuild. Serve a supercache file to anonymous users while a new file is being generated&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;CDN settings:
&lt;ul&gt;
&lt;li&gt;Enable CDN Support&lt;/li&gt;
&lt;li&gt;Off-site URL: http://cdn.example.com (where example.com is your own domain)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Preload settings:
&lt;ul&gt;
&lt;li&gt;Preload mode (garbage collection only on legacy cache files)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Create a new directory in your webroot, e.g. &amp;#8220;cache&amp;#8221;:&lt;/p&gt;
&lt;p&gt;[bash]&lt;br /&gt;
mkdir /var/www/html/cache&lt;br /&gt;
[/bash]&lt;/p&gt;
&lt;p&gt;Set this up as a new virtual host in Apache, let&amp;#8217;s call this new site cache.example.com:&lt;/p&gt;
&lt;pre class="brush:bash"&gt;
&amp;lt;VirtualHost *:80&amp;gt;
ServerName cache.example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/html/cache/supercache/cms.example.com
ErrorLog logs/error_log
TransferLog logs/access_log
&amp;lt;/VirtualHost&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Restart Apache to get the new Virtual Hosts activated. Copy over the wp-content/themes/[theme-name] folder to your cache directory (/var/www/html/cache/supercache/cms.example.com) but only where it concerns css, js and images. You don&amp;#8217;t need to copy over the php files as only the web page resources are required. The same applies for the wp-includes directory if your theme uses javascript files in the js subdirectory. Check if the pages come up ok if you access http://cache.example.com. If they do you&amp;#8217;re fine, if not troubleshoot what the issue is, e.g. look at the Apache logs/error_log file.&lt;/p&gt;
&lt;p&gt;After this we need to do some small code wrangling, it&amp;#8217;s going to be ugly but small and we need the absolute path of the directory that we just created. Navigate to the plugin directory of your WordPress installation and enter the wp-super-cache directory. Open file &amp;#8220;wp-cache-phase1.php&amp;#8221; and at the top of the file just after the include( WPCACHEHOME . &amp;#8216;wp-cache-base.php&amp;#8217;); instruction add:&lt;/p&gt;
&lt;pre class="brush:php"&gt;
include( WPCACHEHOME . 'wp-cache-base.php');
$cache_path = &amp;quot;/var/www/html/cache/&amp;quot;;
&lt;/pre&gt;
&lt;p&gt;Save the file and open file &amp;#8220;wp-cache-phase2.php&amp;#8221;. At the top of the file, just after &amp;lt;?php add:&lt;/p&gt;
&lt;pre class="brush:php"&gt;
$cache_path = &amp;quot;/var/www/html/cache/&amp;quot;;
&lt;/pre&gt;
&lt;p&gt;In the same file look for function function wp_cache_get_ob(&amp;#038;$buffer) and in this function look for this sequence (around line 504):&lt;/p&gt;
&lt;pre class="brush:php"&gt;
 } else {
                $buffer = apply_filters( 'wpsupercache_buffer', $buffer );
                // Append WP Super Cache or Live page comment tag
                wp_cache_append_tag($buffer);
&lt;/pre&gt;
&lt;p&gt;After this sequence add:&lt;/p&gt;
&lt;pre class="brush:php"&gt;
$buffer = str_replace(&amp;quot;http://cms.example.com&amp;quot;, &amp;quot;http://www.example.com&amp;quot;, $buffer);
&lt;/pre&gt;
&lt;p&gt;Reason for this is that WP Super Cache will generate pages based on its own site/home url (cms.example.com) and we need to replace this url with the actual site url (www.example.com). Hence the clumsy find and replace whilst the pages are generated by the Preload section of the WP Super Cache plugin. I&amp;#8217;m sure it can be done nicer but I&amp;#8217;m just proving a concept, not winning prices for clean code.&lt;/p&gt;
&lt;p&gt;Set up your CDN so that it has two Distribution Points / Pull Zones or whatever you CDN provider calls them. One should be listening to www.example.com and have cache.example.com as its origin server and the other should be listening to cdn.example.com and also have cache.example.com as its origin server. Note the CNAME records the CDN generates for you, let&amp;#8217;s assume the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;xyz.cloudfront.net &amp;#8211;&gt; www.example.com&lt;/li&gt;
&lt;li&gt;abc.cloudfront.net &amp;#8211;&gt; cdn.example.com&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Go to your DNS setup and set up the following changes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Have the www subdomain (I&amp;#8217;m assuming you already have this set up otherwise create a www CNAME record) refer to xyz.cloudfront.net&lt;/li&gt;
&lt;li&gt;Create a CNAME record for cdn.example.com and have this point at abc.cloudfront.net&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Apply the DNS changes and wait for the changes to propagate. If you can do a successful dig on www.example.com and cdn.example.com and you get to see something like this you should be ok:&lt;/p&gt;
&lt;pre class="brush:bash"&gt;
www.example.com.         3044   IN CNAME  xyz.cloudfront.net.
xyz.cloudfront.net.      60     IN CNAME  xyz.ams1.cloudfront.net.
xyz.ams1.cloudfront.net. 60     IN A      216.137.59.28
xyz.ams1.cloudfront.net. 60     IN A      216.137.59.54
xyz.ams1.cloudfront.net. 60     IN A      216.137.59.64
xyz.ams1.cloudfront.net. 60     IN A      216.137.59.115
xyz.ams1.cloudfront.net. 60     IN A      216.137.59.207
xyz.ams1.cloudfront.net. 60     IN A      216.137.59.216
xyz.ams1.cloudfront.net. 60     IN A      216.137.59.220
xyz.ams1.cloudfront.net. 60     IN A      216.137.59.254
&lt;/pre&gt;
&lt;p&gt;Access your site at http://www.example.com/ and see if its working. If so start doing your performance tests and do some investigations with HTTP analysis tooling like HTTP Fox.&lt;/p&gt;
&lt;p&gt;After you&amp;#8217;ve established everything works fine you can make cms.example.com only accessible to yourself or your content editors, there is no real time dependency on WordPress anymore and the installation can be purely used for content management activities.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/mind-it/Aqwc/~4/2AWLmOGh2eU" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.mind-it.info/2011/05/21/how-to-make-wordpress-very-secure-very-fast-and-very-resilient/#comments" thr:count="5" />
		<link rel="replies" type="application/atom+xml" href="http://www.mind-it.info/2011/05/21/how-to-make-wordpress-very-secure-very-fast-and-very-resilient/feed/" thr:count="5" />
		<thr:total>5</thr:total>
	<feedburner:origLink>http://www.mind-it.info/2011/05/21/how-to-make-wordpress-very-secure-very-fast-and-very-resilient/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>postme</name>
					</author>
		<title type="html"><![CDATA[How to protect your site against a DDOS attack]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mind-it/Aqwc/~3/el-6UjhwCKo/" />
		<id>http://www.mind-it.info/?p=320</id>
		<updated>2011-04-09T01:16:00Z</updated>
		<published>2011-04-09T01:16:00Z</published>
		<category scheme="http://www.mind-it.info" term="Featured" />		<summary type="html"><![CDATA[A Distributed Denial Of Service (DDOS) attack is an attempt by a malicious party to prevent legitimate users of using your services. With a DDOS attack this is typically accomplished through flooding, a process whereby multiple clients generate traffic to &#8230; <a href="http://www.mind-it.info/2011/04/09/how-to-protect-your-site-against-a-ddos-attack/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></summary>
		<content type="html" xml:base="http://www.mind-it.info/2011/04/09/how-to-protect-your-site-against-a-ddos-attack/">&lt;p&gt;A Distributed Denial Of Service (DDOS) attack is an attempt by a malicious party to prevent legitimate users of using your services. With a DDOS attack this is typically accomplished through flooding, a process whereby multiple clients generate traffic to your site that takes up all capacity of your site so it stops responding to legitimate request.&lt;/p&gt;
&lt;p&gt;There&amp;#8217;s a number of solutions available against these type of attacks but they tend to be ineffective mostly because they&amp;#8217;re either dependent on your own infrastructure or they are reactive meaning that they will respond after the attack has started. If DDOS attacks need to be blocked in/on your own infrastructure you will very quickly run out of capacity as the attacker can generate more traffic than your own infrastructure (firewalls, switches, load balancers) can handle. So anytime you&amp;#8217;re dependent on blocking DDOS attacks in your environment you&amp;#8217;re already too late, it needs to be stopped before it gets to your doorstep. Now if you have deep pockets there&amp;#8217;s options available that run at the ISP level. They&amp;#8217;re basically IPS/IDS like solutions that will detect anomalous traffic and blackhole this traffic. This will avoid the traffic getting to your infrastructure but these are expensive solutions that aren&amp;#8217;t available to your run-of-the-mill website owner.&lt;/p&gt;
&lt;p&gt;So whats the solution to an attack that is capacity based? Have more capacity than the attacker. That sounds like a bad solution as you don&amp;#8217;t have infinitely deep pockets to keep adding capacity for the unlikely event you&amp;#8217;re being targetted by a DDOS attack. Fortunately there&amp;#8217;s a very easy way of getting additional capacity beyond the means of any DDOS attacker: use a Content Delivery Network. A CDN is a proxy solution that can be used to deliver content close to a target group which offloads traffic from your website. There&amp;#8217;s a number of services available like Akamai, Amazon CloudFront or MaxCDN. If you use a CDN and your site is being attacked with a DDOS attack is actually not your site being attacked but the CDN. And the CDN has tons and tons of capacity that no normal DDOS will be able to saturate. In normal circumstances the costs of using a CDN will be low enough not to give you any headaches but when a DDOS is mounted you will see a spike in traffic. This will generate costs as the CDN is responding to way more traffic than usual but your site is protected against the DDOS attack. The decision whether you want those costs is up to you but at least there is a sure fire way of countering a DDOS attack.&lt;/p&gt;
&lt;p&gt;Now setting this up for a static website is simple but things get a bit more complex with a dynamic, personalised site. Even then you can use a CDN to your advantage. Most DDOS attacks are simple scripts without the capabilities of a full browser. You could decide to host a static homepage on the CDN that loads a Javascript or Flash animation that needs to be executed before you move to the dynamic site. The DDOS script can&amp;#8217;t execute the Javascript or Flash animation and fails the test. It will not proceed to the dynamic site. The firewall of your site is configured in such way that only traffic coming from the CDN will be accepted, there is no bypass.&lt;/p&gt;
&lt;p&gt;If you&amp;#8217;re willing to pay the price of a CDN you have every chance of surviving a DDOS.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/mind-it/Aqwc/~4/el-6UjhwCKo" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.mind-it.info/2011/04/09/how-to-protect-your-site-against-a-ddos-attack/#comments" thr:count="3" />
		<link rel="replies" type="application/atom+xml" href="http://www.mind-it.info/2011/04/09/how-to-protect-your-site-against-a-ddos-attack/feed/" thr:count="3" />
		<thr:total>3</thr:total>
	<feedburner:origLink>http://www.mind-it.info/2011/04/09/how-to-protect-your-site-against-a-ddos-attack/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>postme</name>
					</author>
		<title type="html"><![CDATA[Why network firewalls, proxies and load balancers don&#8217;t matter anymore]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mind-it/Aqwc/~3/OFTYsgLIZS8/" />
		<id>http://www.mind-it.info/?p=217</id>
		<updated>2011-05-13T09:40:49Z</updated>
		<published>2011-02-18T09:46:49Z</published>
		<category scheme="http://www.mind-it.info" term="Architecture" /><category scheme="http://www.mind-it.info" term="Webtechnology" />		<summary type="html"><![CDATA[Imagine the complete global population connected to the Internet. Imagine billions of people using web and mobile applications, your web and mobile applications. That&#8217;s a staggering amount of traffic. Now visualize todays &#8220;classic&#8221; infrastructure setup with a DMZ consisting of &#8230; <a href="http://www.mind-it.info/2011/02/18/why-network-firewalls-proxies-and-load-balancers-dont-matter-anymore/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></summary>
		<content type="html" xml:base="http://www.mind-it.info/2011/02/18/why-network-firewalls-proxies-and-load-balancers-dont-matter-anymore/">&lt;p&gt;Imagine the complete global population connected to the Internet. Imagine billions of people using web and mobile applications, &lt;em&gt;your&lt;/em&gt; web and mobile applications. That&amp;#8217;s a staggering amount of traffic. Now visualize todays &amp;#8220;classic&amp;#8221; infrastructure setup with a &lt;a href="http://en.wikipedia.org/wiki/Demilitarized_zone_(computing)"&gt;DMZ&lt;/a&gt; consisting of (two brands of) firewalls (two for the security concious), load balancers, proxies and put this infrastructure between your customers and your web/mobile applications. It&amp;#8217;s like drinking water from a fire hydrant. That &amp;#8220;classic&amp;#8221; infrastructure will have a very difficult time keeping up. Sure there&amp;#8217;s solutions like wire-speed firewalls but the fact of the matter remains that any piece of infrastructure that you put between your application and your customers will have to cope with the load and therefore needs to be scaled up or out, adding costs in the process.&lt;/p&gt;
&lt;p&gt;So why not skip on them? Don&amp;#8217;t use separate physical firewalls, load balancers or proxies. Integrate those functions with the web application hosting platforms. Put your application in a multitude of data centers, set up your hosts and hook up the big Internet pipes. If you&amp;#8217;re in a &lt;a href="http://en.wikipedia.org/wiki/Cloud_computing"&gt;Public Cloud&lt;/a&gt; you probably don&amp;#8217;t have any firewalls, load balancers or proxies that you control anyway so it&amp;#8217;s better to get used to this mode of thinking.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s see if is feasible to abandon network firewalls, load balancers and proxies; implementation in this case is not left as an exercise to the reader. I&amp;#8217;ll be using open source and open standard solutions in my examples so any time I&amp;#8217;m not specifically referring to a technology assume I mean stuff like Linux, BSD etc &amp;#8230;&lt;/p&gt;
&lt;h2&gt;Remove the network firewall&lt;/h2&gt;
&lt;p&gt;There&amp;#8217;s no shortage of platform based firewalls, it&amp;#8217;s how firewalls started out in the early 90s before they became dedicated appliances. If you have a whole farm of servers serving the same application it is relatively straightforward to distribute firewall configuration files across a multitude of machines. In a web farm scenario the access ports are initially set and are very rare to change, ideally you only allow access across ports 80/443 tcp/ip (HTTP/HTTPS). Any other traffic tends to be of a more administrative nature and will be routed over different NICs with a different firewall ruleset.&lt;/p&gt;
&lt;p&gt;The concept of bringing the firewall back to the end host rather than at the network perimeter is known as a distributed firewall [&lt;a href="http://www.cs.columbia.edu/~smb/papers/ccs-df.pdf"&gt;Bellovin&lt;/a&gt;]. The important aspect of a distributed firewall is that the management of policy is still centralized, but the enforcement of the policy is distributed (to the end hosts). Bellovin lists three components to implement a distributed firewall:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Policy language: A language that states what sort of connection are permitted and prohibited (filtering rules)&lt;/li&gt;
&lt;li&gt;System management: A management tool that changes and enforces the security policy&lt;/li&gt;
&lt;li&gt;Safe distribution: A security mechanism that safely distributes the security policy&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This can be implemented in many ways but the easiest choice would be to use &lt;a href="http://en.wikipedia.org/wiki/Netfilter"&gt;netfilter&lt;/a&gt; and associated filter rules as the policy language, manage the filter rules as a text file and use &lt;a href="http://en.wikipedia.org/wiki/Rsync"&gt;rsync&lt;/a&gt; over SSH to securely distribute the policy rules. The traffic between master and slave hosts will be minimal due to the nature of rsync (only sending changed bits) and the fact that changes will hardly ever be necessary as you&amp;#8217;re only allowing traffic over 80/443 tcp/ip (HTTP/HTTPS). An alternative for rsync is a message based approach with guaranteed delivery, something like &lt;a href="http://www.amqp.org/confluence/display/AMQP/Advanced+Message+Queuing+Protocol"&gt;AMQP&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Remove the load balancers&lt;/h2&gt;
&lt;p&gt;A load balancer distributes workloads evenly across two or more hosts. Positioning this on the host level will not work as one host will be quickly overwhelmed before it can offload to other hosts (in essence become the same choke point as the load balancer) so this function needs to sit outside of the hosts serving your application. The function can&amp;#8217;t be positioned on the hosts or in front of the hosts so the only other place remaining for this function is to position it on the client. The client needs to be able to load balance requests across several hosts. This requires that the client is in some form or shape aware of the hosts. A naive implementation could be based on providing the client with a list of hosts (for instance in the form of a JSON message) and pick a host at random (round robin) or deterministic (&lt;a href="http://en.wikipedia.org/wiki/Cache_Array_Routing_Protocol"&gt;CARP&lt;/a&gt; like algorithm). However this becomes unwieldy very quickly especially when you start thinking in hundreds/thousands of servers and it doesn&amp;#8217;t offer a way to guide host selection (for example when taking hosts out of service for maintenance).&lt;/p&gt;
&lt;p&gt;A similar problem exists when determining the association between urls and IP addresses and this has been elegantly solved with a distributed computing solution: &lt;a href="http://en.wikipedia.org/wiki/Domain_Name_System"&gt;Domain Name System&lt;/a&gt;. DNS is a distributed database solution with a standardized protocol. A similar approach can be devised for our situation where we need to find a suitable host for our client. Unfortunately JavaScript can&amp;#8217;t execute DNS queries on itself and invoking a server side component defeats the purpose of this exercise so we need to come with something similar but just a bit different. We need to have a client that can execute a query to a DNS like system that returns a list of hosts that can be used in a format that can be processed by client-side JavaScript.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;From an implementation perspective this can be achieved by having the ability to query the DNS system from JavaScript. This means that the DNS server needs to support an HTTP(S) interface and can return information in a format that JavaScript interprets, for instance &lt;a href="http://en.wikipedia.org/wiki/JSON"&gt;JSON&lt;/a&gt; messages. We need a DNS server with a &lt;a href="http://en.wikipedia.org/wiki/REST"&gt;REST&lt;/a&gt;/JSON interface. Such interfaces are already available, like &lt;a href="http://restdns.net/"&gt;REST-DNS&lt;/a&gt;, &lt;a href="https://github.com/jpf/jsondns"&gt;JSON DNS&lt;/a&gt; or can be created quite easily by yourself (use an exisiting DNS server implementation and add HTTP(S)/JSON capabilities). The JavaScript logic on the client will contain a number of root servers (comparable to DNS) that may be queried. After selecting a root server the JavaScript logic can subsequently query which service it is looking for. The root server does a lookup which hosts can service the request and responds by offering the best matching hosts in the form of a JSON message (=Service Discovery). The client can then select a host and request the service. Hosts can be taken in and out of service by managing the host entries in the root servers. A difference between this implementation and regular DNS is that there is no technical limitation on the number of published root servers. With a regular DNS process the client usually can only configure two or three name servers. The JavaScript implementation doesn&amp;#8217;t pose this limitation. There is no standard for a JSON based DNS query yet but it would be relatively straightforward to take the current DNS protocol and reflect that in JSON. It would only have to cover lookups, zone transfers can still be based on normal DNS protocol.&lt;/p&gt;
&lt;p&gt;Now there&amp;#8217;s one little problem left, how do we get to the first HTML page containing the JavaScript initialization code without using load balancing to distribute these initial requests? The JavaScript is embedded in the first HTML page that the client receives when accessing the web application. This first web page contains all the (JavaScript) logic to get going. It is a static resource and it can be hosted on a Content Delivery Network (&lt;a href="http://en.wikipedia.org/wiki/Content_delivery_network"&gt;CDN&lt;/a&gt;). The CDN itself can be accessed through DNS-based request routing, making it resilient and scalable. By using a CDN it is not necessary to have a load balancing capability for servicing the initial static web page containing the JavaScript logic. &lt;ins datetime="2011-02-19T20:08:00+00:00"&gt;You can decide to use a readily available CDN service for this or roll your own if you are the size of Google or Facebook. If you decide to roll your own CDN pay attention to your &lt;a href="http://www.ripublication.com/acstv3/acstv3n2_6.pdf"&gt;client proximity issues&lt;/a&gt;.&lt;/ins&gt;&lt;/p&gt;
&lt;h2&gt;Remove the proxies&lt;/h2&gt;
&lt;p&gt;Proxies are versatile constructions and its wise to clarify what type of proxies exist (before removing them):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Forward proxy&lt;/li&gt;
&lt;li&gt;Reverse proxy:
&lt;ol&gt;
&lt;li&gt;Caching proxy&lt;/li&gt;
&lt;li&gt;Load balancing proxy&lt;/li&gt;
&lt;li&gt;SSL offloading proxy&lt;/li&gt;
&lt;li&gt;Security proxy (authentication/filtering)&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The forward proxy is within the client environment and will not be impacted by the architecture proposed in this article, we&amp;#8217;ll keep it out of scope. Reverse proxies are used in the host environment and will be examined subsequently.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The caching proxy is used to capture dynamically generated resources and turn them into (temporary) static resources through caching. This saves on host compute resources as the same page doesn&amp;#8217;t need to be generated with each and every request.&lt;/li&gt;
&lt;li&gt;The load balancing proxy basically does the same thing as a load balancer, i.e. distribute load over two or more hosts only more specifically for the HTTP protocol, sometimes using advanced features like url and content rewriting to change location and content on the fly.&lt;/li&gt;
&lt;li&gt;The SSL offloading proxy handles all SSL traffic in front of the web server and thereby offloads all SSL traffic from the webserver (SSL can be quite compute intensive). &lt;/li&gt;
&lt;li&gt;The Security proxy can carry out authentication (identifying the user) or security filtering (checking requests on anomalies like SQL injection, XSS) before allowing traffic to the web server.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All these Reverse Proxy functionalities have alternative implementations that are host based and can therefore be distributed horizontally across all hosts.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Caching proxy: By using a CDN for static resources and using application and database caching techniques for dynamically generated resources the need for a caching proxy can be removed. Semi-dynamic resources (e.g. generated at specific intervals) can be automatically uploaded to the CDN.&lt;/li&gt;
&lt;li&gt;Load balancing proxy: the functionality of load balancers has been resolved in the &amp;#8220;Remove the load balancers&amp;#8221; section.&lt;/li&gt;
&lt;li&gt;SSL offloading proxy: This function can only be carried out on the web server if there is no SSL offloading proxy. However the host can benefit significantly from hardware &lt;a href="http://en.wikipedia.org/wiki/SSL_accelerators"&gt;SSL accelerators&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Security proxy: authentication can be done at the application or web server level. Security filtering can be done through host modules like the Apache &lt;a href="http://www.modsecurity.org/"&gt;mod_security&lt;/a&gt; module.
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;All mentioned components (firewalls, load balancers and proxies) can be completely evaded with a well thought out architecture. This avoids significant upfront costs, improves scalability by orders of magnitude and reduces management complexity.&lt;/p&gt;
&lt;p&gt;All these elements, and a couple more, lead to an architecture than can process trillions of interactions per day because it is completely distributed and horizontally scalable. It is not constrained by infrastructure components requiring large upfront investments like load balancers, firewalls and proxies. I call this concept the LARG architecture, short for &amp;#8220;Linked Architecture for Resource Groups&amp;#8221; and it will be the topic of a following article.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/mind-it/Aqwc/~4/OFTYsgLIZS8" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.mind-it.info/2011/02/18/why-network-firewalls-proxies-and-load-balancers-dont-matter-anymore/#comments" thr:count="9" />
		<link rel="replies" type="application/atom+xml" href="http://www.mind-it.info/2011/02/18/why-network-firewalls-proxies-and-load-balancers-dont-matter-anymore/feed/" thr:count="9" />
		<thr:total>9</thr:total>
	<feedburner:origLink>http://www.mind-it.info/2011/02/18/why-network-firewalls-proxies-and-load-balancers-dont-matter-anymore/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>postme</name>
					</author>
		<title type="html"><![CDATA[Declaring and verifying constants in PHP]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mind-it/Aqwc/~3/A-cGnl5Q_vw/" />
		<id>http://www.mind-it.info/?p=221</id>
		<updated>2011-01-11T19:55:25Z</updated>
		<published>2011-01-11T19:55:25Z</published>
		<category scheme="http://www.mind-it.info" term="PHP" /><category scheme="http://www.mind-it.info" term="Webtechnology" />		<summary type="html"><![CDATA[After a certain while if I&#8217;ve been working on code I get a bit blinded by the nice things I&#8217;ve accomplished and tend to focus on what I&#8217;m not happy with. Lets make this posting about something simple I&#8217;m happy &#8230; <a href="http://www.mind-it.info/2011/01/11/declaring-and-verifying-constants-in-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></summary>
		<content type="html" xml:base="http://www.mind-it.info/2011/01/11/declaring-and-verifying-constants-in-php/">&lt;p&gt;After a certain while if I&amp;#8217;ve been working on code I get a bit blinded by the nice things I&amp;#8217;ve accomplished and tend to focus on what I&amp;#8217;m not happy with. Lets make this posting about something simple I&amp;#8217;m happy with and which looks very nice: declaring and verifying constants. I&amp;#8217;m a big fan of constants (not so much of magic constants but that&amp;#8217;s a different story) and I use them frequently in my code. One thing that&amp;#8217;s always important is to check whether you&amp;#8217;ve actually already set the constant otherwise you get a warning/error dependant on the strictness setting of your error reporting. So here&amp;#8217;s a nice way to set and verify whether you&amp;#8217;ve actually set the constant already:&lt;/p&gt;
&lt;p&gt;[php]&lt;br /&gt;
defined(&amp;#8216;LANGUAGE&amp;#8217;) or define(&amp;#8216;LANGUAGE&amp;#8217;, &amp;#8216;en-us&amp;#8217;);&lt;br /&gt;
[/php]&lt;/p&gt;
&lt;p&gt;If that ain&amp;#8217;t a thing of beauty I don&amp;#8217;t know what is :-)&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/mind-it/Aqwc/~4/A-cGnl5Q_vw" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.mind-it.info/2011/01/11/declaring-and-verifying-constants-in-php/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.mind-it.info/2011/01/11/declaring-and-verifying-constants-in-php/feed/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://www.mind-it.info/2011/01/11/declaring-and-verifying-constants-in-php/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>postme</name>
					</author>
		<title type="html"><![CDATA[How to connect to Amazon EC2 from Mac OS X with SSH]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mind-it/Aqwc/~3/cD5DtHEFY0I/" />
		<id>http://www.mind-it.info/?p=172</id>
		<updated>2010-08-06T20:02:26Z</updated>
		<published>2010-08-06T20:02:26Z</published>
		<category scheme="http://www.mind-it.info" term="Featured" /><category scheme="http://www.mind-it.info" term="Information Security" /><category scheme="http://www.mind-it.info" term="Webtechnology" />		<summary type="html"><![CDATA[Connecting to my Amazon EC2 image (from which this site is running) from Mac Os X took ages to find out and turned out to be relatively simple with the correct information (isn't that always the case). At first I didn't think the builtin Mac OS X ssh could cut it so I started looking into various Mac OS X ssh clients (Fugu, RBrowser, CyberDuck etc ..) but none of those could handle the Amazon public/private key encryption. Then I started looking into using Putty on Mac OS X even though thats not available for Mac OS X (but with a little help from MacPorts). That bombed on problems with GTK1. Dang, what to do? <a href="http://www.mind-it.info/2010/08/06/how-to-connect-to-amazon-ec2-from-mac-os-x/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></summary>
		<content type="html" xml:base="http://www.mind-it.info/2010/08/06/how-to-connect-to-amazon-ec2-from-mac-os-x/">&lt;p&gt;Connecting to my Amazon EC2 image (from which this site is running) from Mac Os X took ages to find out and turned out to be relatively simple with the correct information (isn&amp;#8217;t that always the case). At first I didn&amp;#8217;t think the builtin Mac OS X ssh could cut it so I started looking into various Mac OS X ssh clients (Fugu, RBrowser, CyberDuck etc ..) but none of those could handle the Amazon public/private key encryption. Then I started looking into using Putty on Mac OS X even though thats not available for Mac OS X (but with a little help from MacPorts). That bombed on problems with GTK1. Dang, what to do?&lt;/p&gt;
&lt;p&gt;&lt;span id="more-172"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Finally I found the correct information in a &lt;a href="http://www.g-roc.com/29_ssh-vs-putty-private-key-files-ppk-on-mac-os-x.html"&gt;blog post&lt;/a&gt;, you need to use Puttygen to convert the Amazon .ppk file to OpenSSH format. The OpenSSH format can be used by the Mac OS X (OpenSSH) ssh client. You also need to chmod the direcory where you store the OpenSSH key so it will only allow read access to other users.&lt;/p&gt;
&lt;p&gt;After that a simple text file with the following content:&lt;/p&gt;
&lt;p&gt;[bash]&lt;br /&gt;
ssh -2 -i /Users/xxxxx/amazon_ssh.key youruser@yourserver.com&lt;br /&gt;
[/bash]&lt;/p&gt;
&lt;p&gt;And save it in the Desktop area to have it available on your desktop (or save it elsewhere, whatever you like).&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/mind-it/Aqwc/~4/cD5DtHEFY0I" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.mind-it.info/2010/08/06/how-to-connect-to-amazon-ec2-from-mac-os-x/#comments" thr:count="3" />
		<link rel="replies" type="application/atom+xml" href="http://www.mind-it.info/2010/08/06/how-to-connect-to-amazon-ec2-from-mac-os-x/feed/" thr:count="3" />
		<thr:total>3</thr:total>
	<feedburner:origLink>http://www.mind-it.info/2010/08/06/how-to-connect-to-amazon-ec2-from-mac-os-x/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>postme</name>
					</author>
		<title type="html"><![CDATA[NIST RBAC PHP API package 0.65 released]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mind-it/Aqwc/~3/00MgzU5CBJs/" />
		<id>http://www.mind-it.info/?p=175</id>
		<updated>2010-06-02T20:22:59Z</updated>
		<published>2010-06-02T20:22:59Z</published>
		<category scheme="http://www.mind-it.info" term="Featured" />		<summary type="html"><![CDATA[I'm happy to release my first public version of the NIST RBAC PHP API library. I've blogged a number of posts on this subject and I hope that the software is of use to you. The package can be downloaded from code.google.com.

The package contains the library, the data model in the form of MySQL DDL instructions, installation documentation and PHPDoc API documentation. It comes with three applications: a management application, a demo application and a test framework. The demo application shows you how to integrate the library with your own application. <a href="http://www.mind-it.info/2010/06/02/nits-rbac-php-api-package-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></summary>
		<content type="html" xml:base="http://www.mind-it.info/2010/06/02/nits-rbac-php-api-package-released/">&lt;p&gt;I&amp;#8217;m happy to release my first public version of the NIST RBAC PHP API library. I&amp;#8217;ve blogged a number of posts on this subject and I hope that the software is of use to you. The package can be downloaded from &lt;a title="NIST RBAC PHP API library on code.google.com" href="http://code.google.com/p/nist-rbac/downloads/detail?name=NIST_RBAC_PHP_API_0_65.zip&amp;amp;can=2&amp;amp;q="&gt;code.google.com&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The package contains the library, the data model in the form of MySQL DDL instructions, installation documentation and PHPDoc API documentation. It comes with three applications: a management application, a demo application and a test framework. The demo application shows you how to integrate the library with your own application.&lt;/p&gt;
&lt;p&gt;&lt;span id="more-175"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The code is not OOP, I already had one complaint about that so if you&amp;#8217;re completely hung up on OOP being the only acceptable thing in your life you might want to pass on this one. Then again if you&amp;#8217;re a bit more mature you might still want to take a look and see how much you can salvage for your own project, or decide to take the code and go OOP bezerk on it and improve after your own tastes :-)&lt;/p&gt;
&lt;p&gt;The library doesn&amp;#8217;t contain any output other than arrays or true/false in accordance with the NIST RBAC formal API description (in &lt;a title="Z notation" href="http://en.wikipedia.org/wiki/Z_notation" target="_blank"&gt;Z notation&lt;/a&gt;). The management application follows a simple MVC pattern with the controller just passing on requests to the model and the model only respond with arrays or true/false returns. The view is based on a simple XHTML template.&lt;/p&gt;
&lt;p&gt;There&amp;#8217;s still a bit of work to do with the session management part of the management application, some sessions tend to hang around and I need to clean up the library code a bit to address this problem. Nothing serious, just annoying (at least in my opinion).&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ll do some additional posts in the coming day to clarify the code and its usage. Probably necessary as it is extremely flexible and can therefore be a bit hard to grasp at the start.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/mind-it/Aqwc/~4/00MgzU5CBJs" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.mind-it.info/2010/06/02/nits-rbac-php-api-package-released/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://www.mind-it.info/2010/06/02/nits-rbac-php-api-package-released/feed/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://www.mind-it.info/2010/06/02/nits-rbac-php-api-package-released/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>postme</name>
					</author>
		<title type="html"><![CDATA[Language based redirects using mod_rewrite]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mind-it/Aqwc/~3/wAxhs8mVidU/" />
		<id>http://www.mind-it.info/?p=140</id>
		<updated>2010-02-22T16:17:28Z</updated>
		<published>2010-02-22T16:17:28Z</published>
		<category scheme="http://www.mind-it.info" term="Webtechnology" />		<summary type="html"><![CDATA[For the website of my wife&#8217;s company, www.exportmanagement.nu, I needed a simple approach to direct traffic to the proper pages based on the language preference setting of the visiting browser. It&#8217;s a very simple approach, any browser with Dutch as &#8230; <a href="http://www.mind-it.info/2010/02/22/language-based-redirects-using-mod_rewrite/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></summary>
		<content type="html" xml:base="http://www.mind-it.info/2010/02/22/language-based-redirects-using-mod_rewrite/">&lt;p&gt;For the website of my wife&amp;#8217;s company, &lt;a href="http://www.exportmanagement.nu"&gt;www.exportmanagement.nu&lt;/a&gt;, I needed a simple approach to direct traffic to the proper pages based on the language preference setting of the visiting browser. It&amp;#8217;s a very simple approach, any browser with Dutch as its language setting will be directed to the main site and any other language will be directed to a smaller, English language based, website. Luckily the swiss army chainsaw named mod_rewrite came to the rescue and the following little code fragment will do just that (placed in an .htaccess file).&lt;/p&gt;
&lt;p&gt;&lt;span id="more-140"&gt;&lt;/span&gt;&lt;br /&gt;
[plain]&lt;br /&gt;
RewriteEngine on&lt;br /&gt;
RewriteBase /&lt;/p&gt;
&lt;p&gt;# All Dutch language browsers redirect to index.html&lt;br /&gt;
RewriteCond %{HTTP:Accept-language} ^nl [NC]&lt;br /&gt;
RewriteRule ^$ /index.html [L,R=301]&lt;/p&gt;
&lt;p&gt;# All non-Dutch browsers redirect to index_en.html&lt;br /&gt;
RewriteRule ^$ /index_en.html [L,R=301]&lt;br /&gt;
[/plain]&lt;/p&gt;
&lt;p&gt;The RewriteBase directive makes sure the rewrite rule only triggers when accessing the root of the website, any subsequent request for a specific page will not trigger the rewrite rule.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/mind-it/Aqwc/~4/wAxhs8mVidU" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.mind-it.info/2010/02/22/language-based-redirects-using-mod_rewrite/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.mind-it.info/2010/02/22/language-based-redirects-using-mod_rewrite/feed/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://www.mind-it.info/2010/02/22/language-based-redirects-using-mod_rewrite/</feedburner:origLink></entry>
	</feed><!-- Dynamic page generated in 1.254 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-05-17 12:47:20 --><!-- Compression = gzip -->

