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

<channel>
	<title>SoftLayer Blog &#187; Development</title>
	<atom:link href="http://blog.softlayer.com/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.softlayer.com</link>
	<description>A Behind the Scenes Look at the Best Hosting Provider in the World</description>
	<lastBuildDate>Wed, 22 May 2013 17:40:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>Understanding and Implementing Coding Standards</title>
		<link>http://blog.softlayer.com/2013/understanding-and-implementing-coding-standards/</link>
		<comments>http://blog.softlayer.com/2013/understanding-and-implementing-coding-standards/#comments</comments>
		<pubDate>Fri, 10 May 2013 20:10:16 +0000</pubDate>
		<dc:creator>Phil Jackson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[code base]]></category>
		<category><![CDATA[coders]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[rules]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[team]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=11314</guid>
		<description><![CDATA[Coding standards provide a consistent framework for development within a project and across projects in an organization. A dozen programmers can complete a simple project in a dozen different ways by using unique coding methodologies and styles, so I like to think of coding standards as the &#8220;rules of the road&#8221; for developers. When you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>Coding standards provide a consistent framework for development within a project and across projects in an organization. A dozen programmers can complete a simple project in a dozen different ways by using unique coding methodologies and styles, so I like to think of coding standards as the &#8220;rules of the road&#8221; for developers.</p>
<p>When you&#8217;re driving in a car, traffic is controlled by &#8220;standards&#8221; such as lanes, stoplights, yield signs and laws that set expectations around how you should drive. When you take a road trip to a different state, the stoplights might be hung horizontally instead of vertically or you&#8217;ll see subtle variations in signage, but because you&#8217;re familiar with the rules of the road, you&#8217;re comfortable with the mechanics of driving in this new place. Coding standards help control development traffic and provide the consistency programmers need to work comfortably with a team across projects. The problem with allowing developers to apply their own unique coding styles to a project is the same as allowing drivers to drive as they wish &#8230; Confusion about lane usage, safe passage through intersections and speed would result in collisions and bottlenecks.</p>
<p>Coding standards often seem restrictive or laborious when a development team starts considering their adoption, but they don&#8217;t have to be &#8230; They can be implemented methodically to improve the team&#8217;s efficiency and consistency over time, and they can be as simple as establishing that all instantiations of an object must be referenced with a variable name that begins with a capital letter:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$User</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>While that example may seem overly simplistic, it actually makes life a lot easier for all of the developers on a given project. Regardless of who created that variable, every other developer can see the difference between a variable that holds data and one that are instantiates an object. Think about the shapes of signs you encounter while driving &#8230; You know what a stop sign looks like without reading the word &#8220;STOP&#8221; on it, so when you see a red octagon (in the United States, at least), you know what to do when you approach it in your car. Seeing a capitalized variable name would tell us about its function.</p>
<p>The example I gave of capitalizing instantiated objects is just an example. When it comes to coding standards, the most effective rules your team can incorporate are the ones that make the most sense to you. While there are a few best practices in terms of formatting and commenting in code, the most important characteristics of coding standards for a given team is consistency and clarity.</p>
<p>So how do you go about creating a coding standard? Most developers dislike doing unnecessary work, so the easiest way to create a coding standard is to use an already-existing one. Take a look at any libraries or frameworks you are using in your current project. Do they use any coding standards? Are those coding standards something you can live with or use as a starting point? You are free to make any changes to it you wish in order to best facilitate your team&#8217;s needs, and you can even set how strict specific coding standards must be adhered to. Take for example left-hand comparisons:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> $a <span style="color: #002200;">==</span> <span style="color: #2400d9;">12</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span> … <span style="color: #002200;">&#125;</span> <span style="color: #11740a; font-style: italic;">// right-hand comparison</span>
<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #2400d9;">12</span> <span style="color: #002200;">==</span> $a <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span> … <span style="color: #002200;">&#125;</span> <span style="color: #11740a; font-style: italic;">// left-hand comparison</span></pre></div></div>

<p>Both of these statements are valid but one may be preferred over the other. Consider the following statements:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> $a <span style="color: #002200;">=</span> <span style="color: #2400d9;">12</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span> … <span style="color: #002200;">&#125;</span> <span style="color: #11740a; font-style: italic;">// supposed to be a right-hand comparison but is now an assignment</span>
<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #2400d9;">12</span> <span style="color: #002200;">=</span> $a <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span> … <span style="color: #002200;">&#125;</span> <span style="color: #11740a; font-style: italic;">// supposed to be a left-hand comparison but is now an assignment</span></pre></div></div>

<p>The first statement will now evaluate to true due to <code>$a</code> being assigned the value of 12 which will then cause the code within the if-statement to execute (which is not the desired result). The second statement will cause an error, therefore making it obvious a mistake in the code has occurred. Because our team couldn&#8217;t come to a consensus, we decided to allow both of these standards &#8230; Either of these two formats are acceptable and they&#8217;ll both pass code review, but they are the only two acceptable variants. Code that deviates from those two formats would fail code review and would not be allowed in the code base.</p>
<p>Coding standards play an important role in efficient development of a project when you have several programmers working on the same code. By adopting coding standards and following them, you&#8217;ll avoid a free-for-all in your code base, and you&#8217;ll be able to look at every line of code and know more about what that line is telling you than what the literal code is telling you &#8230; just like seeing a red octagon posted on the side of the road at an intersection.</p>
<p>-<a href="https://twitter.com/SoftLayerDevs">@SoftLayerDevs</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/understanding-and-implementing-coding-standards/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Development &#8211; Installing mod_security with OWASP</title>
		<link>http://blog.softlayer.com/2013/web-development-installing-mod_security-with-owasp/</link>
		<comments>http://blog.softlayer.com/2013/web-development-installing-mod_security-with-owasp/#comments</comments>
		<pubDate>Mon, 29 Apr 2013 20:45:39 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[modsecurity]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[OWASP]]></category>
		<category><![CDATA[rules]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[traffic]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=11229</guid>
		<description><![CDATA[You want to secure your web application, but you don&#8217;t know where to start. A number of open-source resources and modules exist, but that variety is more intimidating than it is liberating. If you&#8217;re going to take the time to implement application security, you don&#8217;t want to put your eggs in the wrong basket, so [...]]]></description>
			<content:encoded><![CDATA[<p>You want to secure your web application, but you don&#8217;t know where to start. A number of open-source resources and modules exist, but that variety is more intimidating than it is liberating. If you&#8217;re going to take the time to implement application security, you don&#8217;t want to put your eggs in the wrong basket, so you wind up suffering from analysis paralysis as you compare all of the options. You want a powerful, flexible security solution that isn&#8217;t overly complex, so to save you the headache of making the decision, I&#8217;ll make it for you: Start with mod_security and OWASP.</p>
<p><a href="http://www.modsecurity.org/">ModSecurity</a> (mod_security) is an open-source Apache module that acts as a web application firewall. It is used to help protect your server (and websites) from several methods of attack, most common being brute force. You can think of mod_security as an invisible layer that separates users and the content on your server, quietly monitoring HTTP traffic and other interactions. It&#8217;s easy to understand and simple to implement.</p>
<p>The challenge is that without some advanced configuration, mod_security isn&#8217;t very functional, and that advanced configuration can get complex pretty quickly. You need to determine and set additional rules so that mod_security knows how to respond when approached with a potential threat. That&#8217;s where <a href="https://www.owasp.org/index.php/Main_Page">Open Web Application Security Project</a> (OWASP) comes in. You can think of the OWASP as an enhanced core ruleset that the mod_security module will follow to prevent attacks on your server.</p>
<p>The process of getting started with mod_security and OWASP might seem like a lot of work, but it&#8217;s actually quite simple. Let&#8217;s look at the installation and configuration process in a CentOS environment. First, we want to install the dependencies that mod_security needs:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Install the GCC compiler and mod_security dependencies ##</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> yum <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #c20cb9; font-weight: bold;">make</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> yum <span style="color: #c20cb9; font-weight: bold;">install</span> libxml2 libxml2-devel httpd-devel pcre-devel curl-devel</pre></div></div>

<p>Now that we have the dependencies in place, let&#8217;s install mod_security. Unfortunately, there is no yum for mod_security because it is not a maintained package, so you&#8217;ll have to install it directly from the source:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Get mod_security from its source ##</span>
$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src
$ <span style="color: #c20cb9; font-weight: bold;">git</span> clone https:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>SpiderLabs<span style="color: #000000; font-weight: bold;">/</span>ModSecurity.git</pre></div></div>

<p>Now that we have mod_security on our server, we&#8217;ll install it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Install mod_security ##</span>
$ <span style="color: #7a0874; font-weight: bold;">cd</span> ModSecurity
$ .<span style="color: #000000; font-weight: bold;">/</span>configure
$ <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>And we&#8217;ll copy over the default mod_security configuration file into the necessary Apache directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Copy configuration file ##</span>
$ <span style="color: #c20cb9; font-weight: bold;">cp</span> modsecurity.conf-recommended <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>conf.d<span style="color: #000000; font-weight: bold;">/</span>modsecurity.conf</pre></div></div>

<p>We&#8217;ve got mod_security installed now, so we need to tell Apache about it &#8230; It&#8217;s no use having mod_security installed if our server doesn&#8217;t know it&#8217;s supposed to be using it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Apache configuration for mod_security ##</span>
$ <span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>httpd.conf</pre></div></div>

<p>We&#8217;ll need to load our Apache config file to include our dependencies (BEFORE the mod_security module) and the mod_security file module itself:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Load dependencies ##</span>
LoadFile <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>libxml2.so
LoadFile <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>liblua5.1.so
<span style="color: #666666; font-style: italic;">## Load mod_security ##</span>
LoadModule security2_module modules<span style="color: #000000; font-weight: bold;">/</span>mod_security2.so</pre></div></div>

<p>We&#8217;ll save our configuration changes and restart Apache:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Restart Apache! ##</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>httpd restart</pre></div></div>

<p>As I mentioned at the top of this post, our installation of mod_security is good, but we want to enhance our ruleset with the help of OWASP. If you&#8217;ve made it this far, you won&#8217;t have a problem following a similar process to install OWASP:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## OWASP ##</span>
$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>
$ <span style="color: #c20cb9; font-weight: bold;">git</span> clone https:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>SpiderLabs<span style="color: #000000; font-weight: bold;">/</span>owasp-modsecurity-crs.git
$ <span style="color: #c20cb9; font-weight: bold;">mv</span> owasp-modsecurity-crs modsecurity-crs</pre></div></div>

<p>Just like with mod_security, we&#8217;ll set up our configuration file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## OWASP configuration file ##</span>
$ <span style="color: #7a0874; font-weight: bold;">cd</span> modsecurity-crs
$ <span style="color: #c20cb9; font-weight: bold;">cp</span> modsecurity_crs_10_setup.conf.example modsecurity_crs10_config.conf</pre></div></div>

<p>Now we have mod_security and the OWASP core ruleset ready to go! The last step we need to take is to update the Apache config file to set up our basic ruleset:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Apache configuration ##</span>
$ <span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>httpd.conf</pre></div></div>

<p>We&#8217;ll add an IfModule and point it to our new OWASP rule set at the end of the file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>IfModule security2_module<span style="color: #000000; font-weight: bold;">&gt;</span>
    Include modsecurity-crs<span style="color: #000000; font-weight: bold;">/</span>modsecurity_crs_10_config.conf
    Include modsecurity-crs<span style="color: #000000; font-weight: bold;">/</span>base_rules<span style="color: #000000; font-weight: bold;">/*</span>.conf
<span style="color: #000000; font-weight: bold;">&lt;/</span>IfModule<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>And to complete the installation, we save the config file and restart Apache:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Restart Apache! ##</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>httpd restart</pre></div></div>

<p>And we&#8217;ve got mod_security installed with the OWASP core ruleset! With this default installation, we&#8217;re leveraging the rules the OWASP open source community has come up with, and we have the flexibility to tweak and enhance those rules as our needs dictate. If you have any questions about this installation or you have any other technical blog topics you&#8217;d like to hear from us about, please let us know!</p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/web-development-installing-mod_security-with-owasp/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>iptables Tips and Tricks &#8211; Track Bandwidth with iptables</title>
		<link>http://blog.softlayer.com/2013/iptables-tips-and-tricks-track-bandwidth-with-iptables/</link>
		<comments>http://blog.softlayer.com/2013/iptables-tips-and-tricks-track-bandwidth-with-iptables/#comments</comments>
		<pubDate>Tue, 16 Apr 2013 21:30:29 +0000</pubDate>
		<dc:creator>Mark Ridlen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[bandwidth]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[cPanel]]></category>
		<category><![CDATA[CSF]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[tracking]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=11025</guid>
		<description><![CDATA[As I mentioned in my last post about CSF configuration in iptables, I&#8217;m working on a follow-up post about integrating CSF into cPanel, but I thought I&#8217;d inject a simple iptables use-case for bandwidth tracking. You probably think about iptables in terms of firewalls and security, but it also includes a great diagnostic tool for [...]]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my last post about <a href="http://blog.softlayer.com/2013/iptables-tips-and-tricks-csf-configuration/">CSF configuration in iptables</a>, I&#8217;m working on a follow-up post about integrating CSF into cPanel, but I thought I&#8217;d inject a simple iptables use-case for bandwidth tracking. You probably think about iptables in terms of firewalls and security, but it also includes a great diagnostic tool for counting bandwidth for individual rules or set of rules. If you can block it, you can track it! </p>
<p>The best part about using iptables to track bandwidth is that the tracking is enabled by default. To see this feature in action, add the &#8220;-v&#8221; into the command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables <span style="color: #660033;">-vnL</span>
Chain INPUT <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy ACCEPT <span style="color: #000000;">2495</span> packets, 104K bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>The output includes counters for both the policies and the rules. To track the rules, you can create a new chain for <code>tracking</code> bandwidth:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables <span style="color: #660033;">-N</span> tracking
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables <span style="color: #660033;">-vnL</span>
...
Chain tracking <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span> references<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 pkts bytes target 	prot opt <span style="color: #000000; font-weight: bold;">in</span> 	out 	<span style="color: #7a0874; font-weight: bold;">source</span>           	destination</pre></div></div>

<p>Then you need to set up new rules to match the traffic that you wish to track. In this scenario, let&#8217;s look at inbound http traffic on port 80:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables <span style="color: #660033;">-I</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> tracking
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables <span style="color: #660033;">-vnL</span>
Chain INPUT <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy ACCEPT <span style="color: #000000;">35111</span> packets, 1490K bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 pkts bytes target 	prot opt <span style="color: #000000; font-weight: bold;">in</span> 	out 	<span style="color: #7a0874; font-weight: bold;">source</span>           	destination
    <span style="color: #000000;">0</span> 	  <span style="color: #000000;">0</span> tracking    tcp  <span style="color: #660033;">--</span>  <span style="color: #000000; font-weight: bold;">*</span>  	<span style="color: #000000; font-weight: bold;">*</span>   	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>       	tcp dpt:<span style="color: #000000;">80</span></pre></div></div>

<p>Now let&#8217;s generate some traffic and check it again:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables <span style="color: #660033;">-vnL</span>
Chain INPUT <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy ACCEPT <span style="color: #000000;">35216</span> packets, 1500K bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 pkts bytes target 	prot opt <span style="color: #000000; font-weight: bold;">in</span> 	out 	<span style="color: #7a0874; font-weight: bold;">source</span>           	destination
  <span style="color: #000000;">101</span>  <span style="color: #000000;">9013</span> tracking    tcp  <span style="color: #660033;">--</span>  <span style="color: #000000; font-weight: bold;">*</span>  	<span style="color: #000000; font-weight: bold;">*</span>   	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>       	tcp dpt:<span style="color: #000000;">80</span></pre></div></div>

<p>You can see the packet and byte transfer amounts to track the INPUT &mdash; traffic to a <strong>destination</strong> port on your server. If you want track the amount of data that the server is generating, you&#8217;d look for OUTPUT from the <strong>source</strong> port on your server:</p>
<p><span id="more-11025"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables <span style="color: #660033;">-I</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> tracking
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables <span style="color: #660033;">-vnL</span>
...
Chain OUTPUT <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy ACCEPT <span style="color: #000000;">26149</span> packets, 174M bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 pkts bytes target 	prot opt <span style="color: #000000; font-weight: bold;">in</span> 	out 	<span style="color: #7a0874; font-weight: bold;">source</span>           	destination
  <span style="color: #000000;">488</span> 3367K tracking    tcp  <span style="color: #660033;">--</span>  <span style="color: #000000; font-weight: bold;">*</span>  	<span style="color: #000000; font-weight: bold;">*</span>   	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>       	tcp spt:<span style="color: #000000;">80</span></pre></div></div>

<p>Now that we know how the tracking chain works, we can add in a few different layers to get even more information. That way you can keep your INPUT and OUTPUT chains looking clean.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables –N tracking
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables –N tracking2
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables –I INPUT –j tracking
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables –I OUTPUT –j tracking
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables –A tracking –p tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> –j tracking2
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables –A tracking –p tcp <span style="color: #660033;">--sport</span> <span style="color: #000000;">80</span> –j tracking2
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables <span style="color: #660033;">-vnL</span>
&nbsp;
Chain INPUT <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy ACCEPT <span style="color: #000000;">96265</span> packets, 4131K bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 pkts bytes target 	prot opt <span style="color: #000000; font-weight: bold;">in</span> 	out 	<span style="color: #7a0874; font-weight: bold;">source</span>           	destination
 <span style="color: #000000;">4002</span>  184K tracking    all  <span style="color: #660033;">--</span>  <span style="color: #000000; font-weight: bold;">*</span>  	<span style="color: #000000; font-weight: bold;">*</span>   	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>
&nbsp;
Chain FORWARD <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy ACCEPT <span style="color: #000000;">0</span> packets, <span style="color: #000000;">0</span> bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 pkts bytes target 	prot opt <span style="color: #000000; font-weight: bold;">in</span> 	out 	<span style="color: #7a0874; font-weight: bold;">source</span>           	destination
&nbsp;
Chain OUTPUT <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy ACCEPT <span style="color: #000000;">33751</span> packets, 231M bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 pkts bytes target 	prot opt <span style="color: #000000; font-weight: bold;">in</span> 	out 	<span style="color: #7a0874; font-weight: bold;">source</span>           	destination
 <span style="color: #000000;">1399</span> 9068K tracking    all  <span style="color: #660033;">--</span>  <span style="color: #000000; font-weight: bold;">*</span>  	<span style="color: #000000; font-weight: bold;">*</span>   	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>
&nbsp;
Chain tracking <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span> references<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 pkts bytes target 	prot opt <span style="color: #000000; font-weight: bold;">in</span> 	out 	<span style="color: #7a0874; font-weight: bold;">source</span>           	destination
 <span style="color: #000000;">1208</span> <span style="color: #000000;">59626</span> tracking2   tcp  <span style="color: #660033;">--</span>  <span style="color: #000000; font-weight: bold;">*</span>  	<span style="color: #000000; font-weight: bold;">*</span>   	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>       	tcp dpt:<span style="color: #000000;">80</span>
  <span style="color: #000000;">224</span> 1643K tracking2   tcp  <span style="color: #660033;">--</span>  <span style="color: #000000; font-weight: bold;">*</span>  	<span style="color: #000000; font-weight: bold;">*</span>   	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>       	tcp spt:<span style="color: #000000;">80</span>
&nbsp;
Chain tracking2 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span> references<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 pkts bytes target 	prot opt <span style="color: #000000; font-weight: bold;">in</span> 	out 	<span style="color: #7a0874; font-weight: bold;">source</span>           	destination</pre></div></div>

<p>Keep in mind that every time a packet passes through one of your rules, it will eat CPU cycles. Diverting all your traffic through 100 rules that track bandwidth may not be the best idea, so it&#8217;s important to have an efficient ruleset. If your server has eight processor cores and tons of overhead available, that concern might be inconsequential, but if you&#8217;re running lean, you could conceivably run into issues. </p>
<p>The easiest way to think about making efficient rulesets is to think about eating the largest slice of pie first. Understand <a href="http://blog.softlayer.com/2012/iptables-tips-and-tricks-rule-processing/">iptables rule processing</a> and put the rules that get more traffic higher in your list. Conversely, save the tiniest pieces of your pie for last. If you run all of your traffic by a rule that only applies to a tiny segment before you screen out larger segments, you&#8217;re wasting processing power.</p>
<p>Another thing to keep in mind is that you do not need to specify a target (in our examples above, we established <code>tracking</code> and <code>tracking2</code> as our targets). If you&#8217;re used to each rule having a specific purpose of either blocking, allowing, or diverting traffic, this simple tidbit might seem revolutionary. For example, we could use this rule:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables <span style="color: #660033;">-A</span> INPUT</pre></div></div>

<p>If that seems a little bare to you, don&#8217;t worry &#8230; It is! The output will show that it is a rule that tracks all traffic in the chain at that point. We&#8217;re appending the data to the end of the chain in this example (&#8220;<code>-A</code>&#8220;) but we could also insert it (&#8220;<code>-I</code>&#8220;) at the top of the chain instead. This command could be helpful if you are using a number of different chains and you want to see the exact volume of packets that are filtered at any given point. Additionally, this strategy could show how much traffic a potential rule would filter before you run it on your production system. Because having several of these kinds of commands can get a little messy, it&#8217;s also helpful to add comments to help sort things out:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> comment <span style="color: #660033;">--comment</span> <span style="color: #ff0000;">&quot;track all data&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ iptables <span style="color: #660033;">-vnL</span>
Chain INPUT <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy ACCEPT 11M packets, 5280M bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 pkts bytes target 	prot opt <span style="color: #000000; font-weight: bold;">in</span> 	out 	<span style="color: #7a0874; font-weight: bold;">source</span>           	destination
   <span style="color: #000000;">98</span>  <span style="color: #000000;">9352</span>        	all  <span style="color: #660033;">--</span>  <span style="color: #000000; font-weight: bold;">*</span>  	<span style="color: #000000; font-weight: bold;">*</span>   	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        	0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>       	<span style="color: #000000; font-weight: bold;">/*</span> track all data <span style="color: #000000; font-weight: bold;">*/</span></pre></div></div>

<p>Nothing terribly complicated about using iptables to count bandwidth, right? If you have iptables rulesets and you want to get a glimpse at how your traffic is being affected, this little trick could be useful. You can rely on the information iptables gives you about your bandwidth usage, and you won&#8217;t be the only one &#8230; cPanel actually uses iptables to track bandwidth.</p>
<p>-Mark</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/iptables-tips-and-tricks-track-bandwidth-with-iptables/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Catalyst at SXSW 2013: Mentorship and Meaningfulness</title>
		<link>http://blog.softlayer.com/2013/catalyst-at-sxsw-2013-mentorship-and-meaningfulness/</link>
		<comments>http://blog.softlayer.com/2013/catalyst-at-sxsw-2013-mentorship-and-meaningfulness/#comments</comments>
		<pubDate>Fri, 12 Apr 2013 22:15:16 +0000</pubDate>
		<dc:creator>Joshua Krammes</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Startup Series]]></category>
		<category><![CDATA[Catalyst]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[George Karidis]]></category>
		<category><![CDATA[growth]]></category>
		<category><![CDATA[incubator program]]></category>
		<category><![CDATA[interviews]]></category>
		<category><![CDATA[mentorship]]></category>
		<category><![CDATA[startups]]></category>
		<category><![CDATA[SxSW]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=11061</guid>
		<description><![CDATA[In the Community Development group, our mission is simple: Create the industry&#8217;s most substantially helpful startup program that assists participants in a MEANINGFUL way. Meaningfulness is a subjective goal, but when it comes to fueling new businesses, numbers and statistics can&#8217;t tell the whole story. Sure, we could run Catalyst like some of the other [...]]]></description>
			<content:encoded><![CDATA[<p>In the Community Development group, our mission is simple: Create the industry&#8217;s most substantially helpful startup program that assists participants in a <strong>MEANINGFUL</strong> way. Meaningfulness is a subjective goal, but when it comes to fueling new businesses, numbers and statistics can&#8217;t tell the whole story. Sure, we could run <a href="http://www.softlayer.com/partners/catalyst">Catalyst</a> like some of the other startup programs in the infrastructure world and gauge our success off of the number of partners using the hosting credits we provide, but if we only focused on hosting credits, we&#8217;d be leaving a significant opportunity on the table.</p>
<p>SoftLayer is able to offer the entrepreneurial community so much more than <a href="http://www.softlayer.com/cloudlayer/computing/">cloud computing instances</a> and <a href="http://www.softlayer.com/dedicated-servers/">powerful servers</a>. As a startup ourselves not so long ago, our team knows all about the difficulties of being an entrepreneur, and now that we&#8217;re able to give back to the startup community, we want to share battle stories and lessons learned. Mentorship is one of the most valuable commodities for entrepreneurs and business founders, and SoftLayer&#8217;s mentors are in a unique position to provide feedback about everything from infrastructure planning to hiring your first employees to engaging with your board of advisors to negotiating better terms on a round of funding. </p>
<p>The Catalyst team engages in these kinds discussions with our clients every day, and we&#8217;ve had some pretty remarkable success. When we better understand a client&#8217;s business, we can provide better feedback and insight into the infrastructure that will help that business succeed. In other words, we build meaningful relationships with our Catalyst clients, and as a result, those clients are able to more efficiently leverage the hosting credits we provide them.</p>
<p>The distinction between Catalyst and other startup programs in the hosting industry has never been so apparent than after <a href="http://sxsw.com/">South by Southwest</a> (SXSW) in Austin this year. I had the opportunity to meet with entrepreneurs, investors, and industry experts who have been thirsting for a program like Catalyst for years, and when they hear about what we&#8217;re doing, they know they&#8217;ve found their oasis. I had a chance to sit down with <a href="https://twitter.com/PaulFord">Paul Ford</a> in the Catalyst Startup Lounge at SXSW to talk about the program and some of the insights and feedback we&#8217;d gotten at the show:</p>
<div class="yt560"><iframe width="560" height="315" src="http://www.youtube.com/embed/B4cwi3vDI0g" frameborder="0" allowfullscreen></iframe></div>
<p>Paul was quick to point out that being a leader in the startup community has more impact when you provide the best technology and pair that with a team that can deliver for startups what they need: meaningful support. </p>
<p>Later, I had an impromptu coffee with one of the world&#8217;s largest, most prestigious Silicon Valley-based venture capital firms &mdash; probably THE most respected venture capital firm in the world, actually. As we chatted about the firm&#8217;s seed-funding practices, the investment partner told me, &#8220;There is no better insurance policy for an infrastructure company than what SoftLayer is doing to ensure success for its startup clients.&#8221; And I thought that was a pretty telling insight.</p>
<p>That simple sentence drove home the point that success in a program like Catalyst is not guaranteed by a particular technology, no matter how innovative or industry-leading that technology may be. Success comes from creating value BEYOND that technology, and when I sat down with <a href="https://twitter.com/gkdog">George Karidis</a>, he shared a few insights how the Catalyst vision came to be along with how the program has evolved to what it is today: </p>
<div class="yt560"><iframe width="560" height="315" src="http://www.youtube.com/embed/WNnOawf4zYs" frameborder="0" allowfullscreen></iframe></div>
<p>Catalyst is special. The relationships we build with entrepreneurs are meaningful. We&#8217;ve made commitments to have the talented brainpower within our own walls to be accessible to the community already. After SXSW, I knew I didn&#8217;t have to compare what we were doing from what other programs are doing because that would be like comparing apples and some other fruit that doesn&#8217;t do nearly as much for you as apples do.</p>
<p>I was told once on the campaign trail for President Clinton in &#8217;96 that so long as you have a rock-solid strategy, you cannot be beaten if you continue to execute on that strategy. Execute, Execute, Execute. If you waiver and react to the competition, you&#8217;re dead in the water. With that in mind, we&#8217;re going to keep executing on our strategy of being available to our Catalyst clients and actively helping them solve their problems. The only question that remains is this: </p>
<p>How can we help you?</p>
<p>-<a href="https://twitter.com/joshuakrammes">@JoshuaKrammes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/catalyst-at-sxsw-2013-mentorship-and-meaningfulness/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SoftLayer Mobile: Now a Universal iOS Application</title>
		<link>http://blog.softlayer.com/2013/softlayer-mobile-now-a-universal-ios-application/</link>
		<comments>http://blog.softlayer.com/2013/softlayer-mobile-now-a-universal-ios-application/#comments</comments>
		<pubDate>Mon, 01 Apr 2013 20:45:56 +0000</pubDate>
		<dc:creator>Pawel Kijowski</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[mobile applications]]></category>
		<category><![CDATA[SoftLayer Mobile]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=10714</guid>
		<description><![CDATA[Last month, we put SoftLayer Mobile HD out to pasture. That iPad-specific application performed amazingly, and we got a lot of great feedback from our customers, so we doubled-down on our efforts to support iPad users by merging SoftLayer Mobile HD functionality with our standard SoftLayer Mobile app to provide a singular, universal application for [...]]]></description>
			<content:encoded><![CDATA[<p>Last month, we put <a href="https://itunes.apple.com/us/app/softlayer-mobile-hd/id460377057?mt=8">SoftLayer Mobile HD</a> out to pasture. That iPad-specific application performed amazingly, and we got a lot of great feedback from our customers, so we doubled-down on our efforts to support iPad users by merging SoftLayer Mobile HD functionality with our standard <a href="https://itunes.apple.com/us/app/softlayer-mobile/id373786244?mt=8">SoftLayer Mobile</a> app to provide a singular, universal application for all iOS devices.</p>
<p>By merging our two iOS applications into a single, universal app, we can provide better feature parity, maintain coherent architecture and increase code reuse and maintainability because we&#8217;re only working with a single feature-rich binary app that provides a consistent user experience on the iPhone and the iPad at the same. Obviously, this meant we had to retool much of the legacy iPhone-specific SoftLayer Mobile app in order to provide the same device-specific functionality we had for the iPad in SoftLayer Mobile HD, but I was surprised at how straightforward that process ended up being. I thought I&#8217;d share a few of the resources iOS includes that simplify the process of creating a universal iOS application.</p>
<p>iOS <a href="http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/AdvancedAppTricks/AdvancedAppTricks.html">supports</a> development of universal applications via device-specific resource loading and device-specific runtime checks, and we leveraged those tools based on particular situations in our code base. </p>
<p><a href="http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/LoadingResources/Introduction/Introduction.html">Device-specific resource loading</a> allows iOS to choose the appropriate resource for the device being used. For example, if we have two different versions of an image called <code>SoftLayerOnBlack.png</code> to fit either an iPhone or an iPad, we simply call one <code>SoftLayerOnBlack~iphone.png</code> and call the other one <code>SoftLayerOnBlack~ipad.png</code>. With those two images in our application bundle, we let the system choose which image to use with a simple line of code:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIImage<span style="color: #002200;">*</span> image <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SoftLayerOnBlack.png&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>In addition to device-specific resource loading, iOS also included device-specific runtime checks. With these runtime checks, we&#8217;re able to create conditional code paths depending on the underlying device type:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>UI_USER_INTERFACE_IDIOM<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> UIUserInterfaceIdiomPad<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// The device is an iPad running iOS 3.2 or later.</span>
<span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// The device is an iPhone or iPod touch.</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>These building blocks allow for a great deal of flexibility when it comes to creating a universal iOS application. Both techniques enable simple support based on what device is running the application, but they&#8217;re used in subtly different ways. With those device-specific tools, developers are able to approach their universal applications in a couple of distinct ways: </p>
<p><strong>Device-Dependent View Controller:</strong><br />
If we want users on the iPhone and iPad applications to have the same functionality but have the presentation tailored to their specific devices, we would create separate iPhone and iPad view controllers. For example, let&#8217;s look at how our <a href="http://www.softlayer.com/cloudlayer/storage/">Object Storage</a> browser appears on the iPhone and the iPad in SoftLayer Mobile: </p>
<div class="centered" style="width:620px;"><img style="float:left; display:block;" src="http://cdn.softlayer.com/innerlayer/objstoiphone.png" alt="Object Storage - iPhone"/><img style="display:block;" src="http://cdn.softlayer.com/innerlayer/objstoipad.png" alt="Object Storage - iPad"/></div>
<p>We want to take advantage of the additional real estate the iPad provides, so at runtime, the appropriate view controller is be selected based on the devices&#8217; UI context. The technique would look a little like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@implementation</span> SLMenuController
...
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> navigateToStorageModule<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender <span style="color: #002200;">&#123;</span>
	UIViewController&lt;SLApplicationModule&gt; <span style="color: #002200;">*</span>storageModule <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>UI_USER_INTERFACE_IDIOM<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> UIUserInterfaceIdiomPad<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        storageModule <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>SLStorageModule_iPad storageModule<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        storageModule <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>SLStorageModule storageModule<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#91;</span>self navigateToModule<span style="color: #002200;">:</span> storageModule<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>	
...
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>&#8220;Universal&#8221; View Controller</strong><br />
In other situations, we didn&#8217;t need for the viewing experience to differ between the iPhone and the iPad, so we used a single view controller for all devices. We don&#8217;t compromise the user experience or presentation of data because the view controller either re-scales or reconfigures the layout at runtime based on screen size. Take a look at the &#8220;About&#8221; module on the iPhone and iPad:</p>
<div class="centered" style="width:620px;"><img style="float:left; display:block;" src="http://cdn.softlayer.com/innerlayer/aboutiphone.png" alt="About Module - iPhone"/><img style="display:block;" src="http://cdn.softlayer.com/innerlayer/aboutipad.png" alt="About Module - iPad"/></div>
<p>The code for the universal view controller of the &#8220;About&#8221; module looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@implementation</span> SLAboutModuleNavigationViewController
…
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init <span style="color: #002200;">&#123;</span>
    self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
      _navigationHidden <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
		_navigationWidth <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> bounds<span style="color: #002200;">&#93;</span>.size.width <span style="color: #002200;">*</span> <span style="color: #2400d9;">0.5</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
…
<span style="color: #a61390;">@end</span></pre></div></div>

<p>There are plenty of other iOS features and tricks in the universal <a href="https://itunes.apple.com/us/app/softlayer-mobile/id373786244?mt=8">SoftLayer Mobile</a> app. If you&#8217;ve got a SoftLayer account and an iOS devices, download the app to try it out and let us know what you think. If you were a SoftLayer Mobile HD user, do you notice any significant changes in the new app from the legacy app? </p>
<p>-Pawel</p>
<p>P.S. If you&#8217;re not on iOS but you still want some SoftLayer love on your mobile device, check out the other <a href="http://www.softlayer.com/about/automation/mobile-apps">SoftLayer Mobile Apps</a> on Android and Windows Phone.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/softlayer-mobile-now-a-universal-ios-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Social Media for Brands: Monitor Twitter Search via Email</title>
		<link>http://blog.softlayer.com/2013/social-media-for-brands-monitor-twitter-search-via-email/</link>
		<comments>http://blog.softlayer.com/2013/social-media-for-brands-monitor-twitter-search-via-email/#comments</comments>
		<pubDate>Fri, 22 Mar 2013 21:50:30 +0000</pubDate>
		<dc:creator>Phil Jackson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Social Media]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[brand monitoring]]></category>
		<category><![CDATA[email digest]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[marketing]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Twitter alert]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=10928</guid>
		<description><![CDATA[If you&#8217;re responsible for monitoring Twitter for conversations about your brand, you&#8217;re faced with a challenge: You need to know what people are saying about your brand at all times AND you don&#8217;t want to live your entire life in front of Twitter Search. Over the years, a number of social media applications have been [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re responsible for monitoring Twitter for conversations about your brand, you&#8217;re faced with a challenge: You need to know what people are saying about your brand at all times <strong>AND</strong> you don&#8217;t want to live your entire life in front of <a href="https://twitter.com/search">Twitter Search</a>. </p>
<p>Over the years, a number of social media applications have been released specifically for brand managers and social media teams, but most of those applications (especially the free/inexpensive ones) differentiate themselves only by the quality of their analytics and how real-time their data is reported. If that&#8217;s what you need, you have plenty of fantastic options. Those differentiators don&#8217;t really help you if you want to take a more passive role in monitoring Twitter search &#8230; You still have to log into the application to see your fancy dashboards with all of the information. Why can&#8217;t the data come to you?</p>
<p>About three weeks ago, <a href="http://blog.softlayer.com/author/khazard/">Hazzy</a> stopped by my desk and asked if I&#8217;d help build a tool that uses the <a href="https://dev.twitter.com/docs/using-search">Twitter Search API</a> to collect brand keywords mentions and send an email alert with those mentions in digest form every 30 minutes. The social media team had been using <a href="http://www.twilert.com/">Twilert</a> for these types of alerts since February 2012, but over the last few months, messages have been delayed due to issues connecting to Twitter search &#8230; It seems that the service is so popular that it hits Twitter&#8217;s limits on API calls. An email digest scheduled to be sent every thirty minutes ends up going out ten hours late, and ten hours is an eternity in social media time. We needed something a little more timely and reliable, so I got to work on a simple &#8220;Twitter Monitor&#8221; script to find all mentions of our keyword(s) on Twitter, email those results in a simple digest format, and repeat the process every 30 minutes when new mentions are found.</p>
<p>With Bear&#8217;s <a href="https://github.com/bear/python-twitter">Python-Twitter library</a> on GitHub, connecting to the Twitter API is a breeze. Why did we use Bear&#8217;s library in particular? Just look at his <a a href="https://secure.gravatar.com/avatar/1d1d1c010659cc824304b9a35ea33a14?s=400&#038;d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png">profile picture</a>. Yeah &#8230; &#8217;nuff said. So with that Python wrapper to the Twitter API in place, I just had to figure out how to use the tools Twitter provided to get the job done. For the most part, the process was very clear, and Twitter actually made querying the search service much easier than we expected. The Search API finds all mentions of whatever string of characters you designate, so instead of creating an elaborate Boolean search for &#8220;SoftLayer OR #SoftLayer OR @SoftLayer &#8230;&#8221; or any number of combinations of arbitrary strings, we could simply search for &#8220;SoftLayer&#8221; and have all of those results included. If you want to see <em>only</em> @ replies or hashtags, you can limit your search to those alone, but because &#8220;SoftLayer&#8221; isn&#8217;t a word that gets thrown around much without referencing us, we wanted to see every instance. This is the code we ended up working with for the search functionality:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> status_by_search<span style="color: black;">&#40;</span>search<span style="color: black;">&#41;</span>:
    statuses = api.<span style="color: black;">GetSearch</span><span style="color: black;">&#40;</span>term=search<span style="color: black;">&#41;</span>
    results = <span style="color: #008000;">filter</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> x: x.<span style="color: #008000;">id</span> <span style="color: #66cc66;">&gt;</span> get_log_value<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>, statuses<span style="color: black;">&#41;</span>
    returns = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>results<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> result <span style="color: #ff7700;font-weight:bold;">in</span> results:
            returns.<span style="color: black;">append</span><span style="color: black;">&#40;</span>format_status<span style="color: black;">&#40;</span>result<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
        new_tweets<span style="color: black;">&#40;</span>results<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> returns, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>returns<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        exit<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>If you walk through the script, you&#8217;ll notice that we want to return only unseen Tweets to our email recipients. Shortly after got the Twitter Monitor up and running, we noticed how easy it would be to get spammed with the same messages every time the script ran, so we had to filter our results accordingly. Twitter&#8217;s API allows you to request tweets with a Tweet ID greater than one that you specify, however when I tried designating that &#8220;oldest&#8221; Tweet ID, we had mixed results &#8230; Whether due to my ignorance or a fault in the implementation, we were getting fewer results than we should. Tweet IDs are unique and numerically sequential, so they can be relied upon as much as datetime (and far easier to boot), so I decided to use the highest Tweet ID from each batch of processed messages to filter the next set of results. The script stores that Tweet ID and uses a little bit of logic to determine which Tweets are newer than the last Tweet reported.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> new_tweets<span style="color: black;">&#40;</span>results<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> get_log_value<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>result.<span style="color: #008000;">id</span> <span style="color: #ff7700;font-weight:bold;">for</span> result <span style="color: #ff7700;font-weight:bold;">in</span> results<span style="color: black;">&#41;</span>:
        set_log_value<span style="color: black;">&#40;</span><span style="color: #008000;">max</span><span style="color: black;">&#40;</span>result.<span style="color: #008000;">id</span> <span style="color: #ff7700;font-weight:bold;">for</span> result <span style="color: #ff7700;font-weight:bold;">in</span> results<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_log_value<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'tweet.id'</span>, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">as</span> f:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>f.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> set_log_value<span style="color: black;">&#40;</span>messageId<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'tweet.id'</span>, <span style="color: #483d8b;">'w+'</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">as</span> f:
        f.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>messageId<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Once we culled out our new Tweets, we needed our script to email those results to our social media team. Luckily, we didn&#8217;t have to reinvent the wheel here, and we added a few lines that enabled us to send an HTML-formatted email over any SMTP server. One of the downsides of the script is that login credentials for your SMTP server are stored in plaintext, so if you can come up with another alternative that adds a layer of security to those credentials (or lets you send with different kinds of credentials) we&#8217;d love for you to share it.</p>
<p>From that point, we could run the script manually from the server (or a laptop for that matter), and an email digest would be sent with new Tweets. Because we wanted to automate that process, I added a cron job that would run the script at the desired interval. As a bonus, if the script doesn&#8217;t find any new Tweets since the last time it was run, it doesn&#8217;t send an email, so you won&#8217;t get spammed by &#8220;0 Results&#8221; messages overnight.</p>
<p>The script has been in action for a couple of weeks now, and it has gotten our social media team&#8217;s seal of approval. We&#8217;ve added a few features here and there (like adding the number of Tweets in an email to the email&#8217;s subject line), and I&#8217;ve enlisted the help of <a href="https://github.com/crackerjackmack">Kevin Landreth</a> to clean up the code a little. Now, we&#8217;re ready to share the <a href="http://sftlyr.com/sltm">SoftLayer Twitter Monitor</a> script with the world via GitHub!</p>
<p><a href="http://sftlyr.com/sltm"><img class="centered" style="border:1px solid #BBB;" src="http://cdn.softlayer.com/innerlayer/sltm.jpg" alt="SoftLayer Twitter Monitor on GitHub"/></a></p>
<p>The script should work well right out of the box in any Python environment with the required libraries after a few simple configuration changes:</p>
<ul>
<li>Get your Twitter Customer Secret, Access Token and Access Secret from <a href="https://dev.twitter.com/">https://dev.twitter.com/</a></li>
<li>Copy/paste that information where noted in the script.</li>
<li>Update your search term(s).</li>
<li>Enter your mailserver address and port.</li>
<li>Enter your email account credentials if you aren&#8217;t working with an open relay.</li>
<li>Set the <code>self.from_</code> and <code>self.to</code> values to your preference.</li>
<li>Ensure all of the Python requirements are met.</li>
<li>Configure a cron job to run the script your desired interval. For example, if you want to send emails every 10 minutes: <code>*/10 * * * * &lt;path to python> &lt;path to script&gt; 2&gt;&amp;1 /dev/null</code></li>
</ul>
<p>As soon as you add your information, you should be in business. You&#8217;ll have an in-house Twitter Monitor that delivers a simple email digest of your new Twitter mentions at whatever interval you specify! </p>
<p>Like any good open source project, we want the community&#8217;s feedback on how it can be improved or other features we could incorporate. This script uses the Search API, but we&#8217;re also starting to play around with the Stream API and <a href="http://www.softlayer.com/services/additional/message-queue">SoftLayer Message Queue</a> to make some even cooler tools to automate brand monitoring on Twitter. </p>
<p>If you end up using the script and liking it, send SoftLayer a shout-out via Twitter and share it with your friends!</p>
<p>-<a href="http://twitter.com/softlayerdevs">@SoftLayerDevs</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/social-media-for-brands-monitor-twitter-search-via-email/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iptables Tips and Tricks: CSF Configuration</title>
		<link>http://blog.softlayer.com/2013/iptables-tips-and-tricks-csf-configuration/</link>
		<comments>http://blog.softlayer.com/2013/iptables-tips-and-tricks-csf-configuration/#comments</comments>
		<pubDate>Tue, 19 Mar 2013 18:10:39 +0000</pubDate>
		<dc:creator>Mark Ridlen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[APF]]></category>
		<category><![CDATA[blocking]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[CSF]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[iptab]]></category>
		<category><![CDATA[management]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[tips and tricks]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=10812</guid>
		<description><![CDATA[In our last &#8220;iptables Tips and Tricks&#8221; installment, we talked about Advanced Policy Firewall (APF) configuration, so it should come as no surprise that in this installment, we&#8217;re turning our attention to ConfigServer Security &#38; Firewall (CSF). Before we get started, you should probably run through the list of warnings I include at the top [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://blog.softlayer.com/2013/iptables-tips-and-tricks-apf-advanced-policy-firewall-configuration/">our last &#8220;iptables Tips and Tricks&#8221; installment</a>, we talked about Advanced Policy Firewall (APF) configuration, so it should come as no surprise that in this installment, we&#8217;re turning our attention to <a href="http://configserver.com/cp/csf.html">ConfigServer Security &amp; Firewall</a> (CSF). Before we get started, you should probably run through the list of warnings I include at the top of the APF blog post and make sure you have your Band-Aid ready in case you need it.</p>
<p>To get the ball rolling, we need to download CSF and install it on our server. In this post, we&#8217;re working with a CentOS 6.0 32-bit server, so our (root) terminal commands would look like this to download and install CSF:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.configserver.com<span style="color: #000000; font-weight: bold;">/</span>free<span style="color: #000000; font-weight: bold;">/</span>csf.tgz <span style="color: #666666; font-style: italic;">#Download CSF using wget.</span>
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> zxvf csf.tgz <span style="color: #666666; font-style: italic;">#Unpack it.</span>
$ yum <span style="color: #c20cb9; font-weight: bold;">install</span> perl-libwww-perl <span style="color: #666666; font-style: italic;">#Make sure perl modules are installed ...</span>
$ yum <span style="color: #c20cb9; font-weight: bold;">install</span> perl-Time-HiRes  <span style="color: #666666; font-style: italic;">#Otherwise it will generate an error.</span>
$ <span style="color: #7a0874; font-weight: bold;">cd</span> csf
$ .<span style="color: #000000; font-weight: bold;">/</span>install.sh <span style="color: #666666; font-style: italic;">#Install CSF.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#MAKE SURE YOU HAVE YOUR BAND-AID READY</span>
&nbsp;
$ <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>csf start <span style="color: #666666; font-style: italic;">#Start CSF. (Note: You can also use '$ service csf start')</span></pre></div></div>

<p>Once you start CSF, you can see a list of the default rules that load at startup. CSF defaults to a DROP policy:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ iptables <span style="color: #660033;">-nL</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> policy
Chain INPUT <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy DROP<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Chain FORWARD <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy DROP<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Chain OUTPUT <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy DROP<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Don&#8217;t ever run &#8220;<code>iptables -F</code>&#8221; unless you want to lock yourself out. In fact, you might want to add &#8220;This server is running CSF &#8211; do not run &#8216;iptables -F&#8217;&#8221;  to your <code>/etc/motd</code>, just as a reminder/warning to others.</p>
<p>CSF loads on startup by default. This means that if you get locked out, a simple reboot probably won&#8217;t fix the problem. Runlevels 2, 3, 4, and 5 are all on:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ chkconfig <span style="color: #660033;">--list</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> csf
csf             <span style="color: #000000;">0</span>:off   <span style="color: #000000;">1</span>:off   <span style="color: #000000;">2</span>:on    <span style="color: #000000;">3</span>:on    <span style="color: #000000;">4</span>:on    <span style="color: #000000;">5</span>:on    <span style="color: #000000;">6</span>:off</pre></div></div>

<p>Some features of CSF will not work unless you have certain iptables modules installed. I believe they are installed by default in CentOS, but if you custom-built your iptables, they might not all be installed. Run this script to see if all modules are installed:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf<span style="color: #000000; font-weight: bold;">/</span>csftest.pl
Testing ip_tables<span style="color: #000000; font-weight: bold;">/</span>iptable_filter...OK
Testing ipt_LOG...OK
Testing ipt_multiport<span style="color: #000000; font-weight: bold;">/</span>xt_multiport...OK
Testing ipt_REJECT...OK
Testing ipt_state<span style="color: #000000; font-weight: bold;">/</span>xt_state...OK
Testing ipt_limit<span style="color: #000000; font-weight: bold;">/</span>xt_limit...OK
Testing ipt_recent...OK
Testing xt_connlimit...OK
Testing ipt_owner<span style="color: #000000; font-weight: bold;">/</span>xt_owner...OK
Testing iptable_nat<span style="color: #000000; font-weight: bold;">/</span>ipt_REDIRECT...OK
Testing iptable_nat<span style="color: #000000; font-weight: bold;">/</span>ipt_DNAT...OK
&nbsp;
RESULT: csf should <span style="color: #000000; font-weight: bold;">function</span> on this server</pre></div></div>

<p>As I mentioned, this is the default iptables installation on a minimal CentOS 6.0 image, so chances are good that these modules are already installed on your system. It never hurts to check, though.</p>
<h3>The CSF Configuration File</h3>
<p>The primary CSF configuration is stored in the well-documented <code>/etc/csf/csf.conf</code> file. CSF is <em>extremely</em> configurable, so there are a lot of options to read over. Let&#8217;s take a look over some of the more important features:</p>
<p><span id="more-10812"></span></p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Testing</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">TESTING = <span style="color: #ff0000;">&quot;1&quot;</span>
TESTING_INTERVAL = <span style="color: #ff0000;">&quot;5&quot;</span></pre></div></div>

<p>This TESTING cron job runs every &#8220;5&#8243; minutes so you don&#8217;t lock yourself out when you&#8217;re testing your rules. When you are satisfied with your rules (and confident that you won&#8217;t lock yourself out), you can set TESTING to &#8220;0&#8243;.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Globally Allowed Ports</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Allow incoming TCP ports</span>
TCP_IN = <span style="color: #ff0000;">&quot;20,21,22,25,53,80,110,143,443,465,587,993,995&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Allow outgoing TCP ports</span>
TCP_OUT = <span style="color: #ff0000;">&quot;20,21,22,25,53,80,110,113,443&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Allow incoming UDP ports</span>
UDP_IN = <span style="color: #ff0000;">&quot;20,21,53&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Allow outgoing UDP ports</span>
<span style="color: #666666; font-style: italic;"># To allow outgoing traceroute add 33434:33523 to this list</span>
UDP_OUT = <span style="color: #ff0000;">&quot;20,21,53,113,123&quot;</span></pre></div></div>

<p style="margin-bottom:0; padding-bottom:5px;"><strong>Incoming Ping Requests</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Allow incoming PING</span>
ICMP_IN = <span style="color: #ff0000;">&quot;1&quot;</span></pre></div></div>

<p>Allowing ping is usually a good option for diagnostic purposes, so I don&#8217;t recommend turning it off. Disallowing ping is an example of &#8220;security through obscurity,&#8221; and it will not typically dissuade your attackers.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Ethernet Device</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ETH_DEVICE = <span style="color: #ff0000;">&quot;&quot;</span>
ETH6_DEVICE = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>Here, you can configure iptables to ONLY use one Ethernet adapter. You might want to only guard your public network adapter in some situations.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>IP Limit in Permanent &#8220;Deny&#8221; File</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">DENY_IP_LIMIT = <span style="color: #ff0000;">&quot;200&quot;</span></pre></div></div>

<p>A higher number here will obviously screen out more IP addresses in <code>csf.deny</code>, but higher numbers also may cause slowdowns.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>IP Limit in Temporary &#8220;Deny&#8221; File</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">DENY_TEMP_IP_LIMIT = <span style="color: #ff0000;">&quot;100&quot;</span></pre></div></div>

<p>Similar to DENY_IP_LIMIT, the DENY_TEMP_IP_LIMIT represents the maximum number of IPs that can be stored in the temporary ban list.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>SMTP Blocking</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SMTP_BLOCK = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>When set to &#8220;1&#8243;, SMTP_BLOCK does not completely block outbound SMTP, but it does block it for most users. This will prevent malicious scripts and compromised users from making outbound connections from unauthorized mail clients on the server. SMTP_BLOCK doesn&#8217;t stop those scripts from running, but it does stop them from functioning. Mail sent through the proper channels will still be delivered normally.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Allowing SMTP on localhost</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SMTP_ALLOWLOCAL = <span style="color: #ff0000;">&quot;1&quot;</span></pre></div></div>

<p style="margin-bottom:0; padding-bottom:5px;"><strong>Custom Mail Port Designation</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SMTP_PORTS = <span style="color: #ff0000;">&quot;25,465,587&quot;</span></pre></div></div>

<p style="margin-bottom:0; padding-bottom:5px;"><strong>Allowing SMTP Access to Users/Groups</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SMTP_ALLOWUSER = <span style="color: #ff0000;">&quot;&quot;</span>
SMTP_ALLOWGROUP = <span style="color: #ff0000;">&quot;mail,mailman&quot;</span></pre></div></div>

<p style="margin-bottom:0; padding-bottom:5px;"><strong>SYN Flood Protection</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SYNFLOOD = <span style="color: #ff0000;">&quot;0&quot;</span>
SYNFLOOD_RATE = <span style="color: #ff0000;">&quot;100/s&quot;</span>
SYNFLOOD_BURST = <span style="color: #ff0000;">&quot;150&quot;</span></pre></div></div>

<p>Per the documentation, you should only enable SYN flood protection (SYNFLOOD= &#8220;1&#8243;) if you are currently under a SYN flood attack.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Concurrent Connections Limit</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">CONNLIMIT = <span style="color: #ff0000;">&quot;22;5,80;20&quot;</span>
PORTFLOOD = <span style="color: #ff0000;">&quot;22;tcp;5;300,80;tcp;20;5</span></pre></div></div>

<p>These options allow you to add customized DoS protection. CONNLIMIT handles the number of concurrent connections, and in this example, we&#8217;re limiting port 22 to 5 connections and port 80 to 20 connections.</p>
<p>PORTFLOOD on deals with connections per second. In this example, we&#8217;re limiting the TCP connection on port 22 to 5 connections/second with a quiet period of 300 seconds before the connection is unblocked. Additonally, we&#8217;re limiting the TCP connection on port 80 to 20 connections/second with a quiet period of 5 seconds before the connection is unblocked.</p>
<p>Check the <code>readme.txt</code> file for more information about the syntax.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Logging to Syslog</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SYSLOG = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>When enabled, this option logs lfd (Login Failure Daemon) messages to syslog as well as to <code>/var/log/lfd.log</code>.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Dropping v. Rejecting Packets</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">DROP = <span style="color: #ff0000;">&quot;DROP&quot;</span></pre></div></div>

<p>This configuration allows you to either DROP or REJECT packets. REJECT tells the sender that the packet has been blocked by the firewall. DROP just drops the packet and does not send a response. I like DROP better for regular use, but REJECT might be more helpful if you need to diagnose a connectivity issue.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Logging Dropped Connections</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">DROP_LOGGING = <span style="color: #ff0000;">&quot;1&quot;</span></pre></div></div>

<p>This option logs dropped connections to syslog. I don&#8217;t see any reason to turn this off unless your hard drive is getting full.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Port Exceptions When Logging Dropped Connections</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">DROP_NOLOG = <span style="color: #ff0000;">&quot;67,68,111,113,135:139,445,500,513,520&quot;</span></pre></div></div>

<p>These ports are specifically blocked from being logged either to conserve hard drive space or make the log file easier to read.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>&#8220;Watch Mode&#8221;</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">WATCH_MODE = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>If you are ever stuck trying to troubleshoot a large ruleset, you might consider turning this option on. You can use it to track the actions to watched IP addresses to see where they are getting blocked or accepted.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Login Failure Daemon Alert</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_ALERT_TO = <span style="color: #ff0000;">&quot;&quot;</span>
LF_ALERT_FROM = <span style="color: #ff0000;">&quot;&quot;</span>
LF_ALERT_SMTP = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>You can specify an email address to report errors from the Login Failure Daemon, which tracks and automatically blocks brute force login attempts.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Permanent Blocks and NetBlocks</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_PERMBLOCK = <span style="color: #ff0000;">&quot;1&quot;</span>
LF_PERMBLOCK_INTERVAL = <span style="color: #ff0000;">&quot;86400&quot;</span>
LF_PERMBLOCK_COUNT = <span style="color: #ff0000;">&quot;4&quot;</span>
LF_PERMBLOCK_ALERT = <span style="color: #ff0000;">&quot;1&quot;</span>
LF_NETBLOCK = <span style="color: #ff0000;">&quot;0&quot;</span>
LF_NETBLOCK_INTERVAL = <span style="color: #ff0000;">&quot;86400&quot;</span>
LF_NETBLOCK_COUNT = <span style="color: #ff0000;">&quot;4&quot;</span>
LF_NETBLOCK_CLASS = <span style="color: #ff0000;">&quot;C&quot;</span>
LF_NETBLOCK_ALERT = <span style="color: #ff0000;">&quot;1&quot;</span></pre></div></div>

<p>These settings control the permanent block and netblock blocking. You probably don&#8217;t need to touch these settings, but you might want some additional security or less security depending on your company needs. If something gets permablocked, it will require your intervention to clear it, which might create downtime for your clients. Likewise, if a legitimate IP address happens to be part of a netblock which has an attacking IP address on it, it will get blocked if you have that feature turned on. A class C network encompasses 256 IP addresses. You can set this to class B or A, but that could block thousands or millions of IP addresses, respectively. Unless you find yourself under constant attack, I would advise you to leave that LF_NETBLOCK off.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Additional Protection During Updates</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Safe Chain Update. If enabled, all dynamic update chains (GALLOW*, GDENY*,</span>
<span style="color: #666666; font-style: italic;"># SPAMHAUS, DSHIELD, BOGON, CC_ALLOW, CC_DENY, ALLOWDYN*) will create a new</span>
<span style="color: #666666; font-style: italic;"># chain when updating, and insert it into the relevant LOCALINPUT/LOCALOUTPUT</span>
<span style="color: #666666; font-style: italic;"># chain, then flush and delete the old dynamic chain and rename the new chain.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This prevents a small window of opportunity opening when an update occurs and</span>
<span style="color: #666666; font-style: italic;"># the dynamic chain is flushed for the new rules.</span>
SAFECHAINUPDATE = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>Activating this option will increase your system resource usage and will require more rules to be running at one time, but it provides an additional layer of protection during updates. Without this option turned on, your rules will be flushed for a short amount of time, leaving your server vulnerable.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Multi-Server Deployment Options</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_GLOBAL = <span style="color: #ff0000;">&quot;0&quot;</span>
GLOBAL_ALLOW = <span style="color: #ff0000;">&quot;&quot;</span>
GLOBAL_DENY = <span style="color: #ff0000;">&quot;&quot;</span>
GLOBAL_IGNORE = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>Like APF, you can configure global lists for multiple server deployments. You&#8217;ll need to specify a URL of the text file with the IP addresses for the global lists.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>SPAMHAUSE Blocklist</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_SPAMHAUS = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>This option enables the SPAMHAUS blocklist. Specify the number of seconds between refreshes. Recommended setting is 86400 (1 day).</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Blocking TOR Exit IP Addresses</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_TOR = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>Enabling this option will block TOR exit IP addresses. If you are not familiar with <a href="https://www.torproject.org/">TOR</a>, it is a completely anonymous proxy network. This could block some legitimate users who are trying to protect their anonymity, so I would recommend only turning this on if you are already under attack from a TOR exit address.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Blocking Bogon Addresses</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_BOGON = <span style="color: #ff0000;">&quot;0&quot;</span>
LF_BOGON_URL = <span style="color: #ff0000;">&quot;http://www.cymru.com/Documents/bogon-bn-agg.txt&quot;</span>
LF_BOGON_SKIP = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>Blocking bogon addresses (addresses that should not be possible) is usually a good decision. To enable, set the number of seconds between refreshes. I recommend enabling this option and setting the refresh at 86400 (1 day). If you do so, be sure to add your private network adapters to the skip list.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Country-Specific Access to Your Server</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">CC_DENY = <span style="color: #ff0000;">&quot;&quot;</span>
CC_ALLOW = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>With these options, you can block or allow entire countries from accessing your server. To do so, enter the country codes in a comma separated list. Even though this generates a lot of additional rules, it&#8217;s valuable to some sysadmins.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">CC_ALLOW_FILTER = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>Alternatively, you can set your server to exclusively accept traffic from a list of country codes. All other countries not listed will have their traffic dropped. There are many other settings related to these options that I don&#8217;t have time to cover in this blog.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Blocking Login Failures</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_TRIGGER = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>This enables blocking of login failures (per service). There are a lot of great customization options in this section.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Scanning Directories for Malicious Files</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_DIRWATCH = <span style="color: #ff0000;">&quot;300&quot;</span></pre></div></div>

<p>This feature scans <code>/tmp</code> and <code>/dev/shm</code> for potentially malicious files and alerts you to their presence based on the interval you designate. You can also have CSF automatically quarantine malicious files with this option:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_DIRWATCH_DISABLE = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p style="margin-bottom:0; padding-bottom:5px;"><strong>Distributed Attack Protection</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_DISTATTACK = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>By enabling this option, you activate additional protection against distributed attacks.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Blocking Based on Abusive Email Usage</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LT_POP3D = <span style="color: #ff0000;">&quot;0&quot;</span>
LT_IMAPD = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>If a user checks email too many times per hour (more than the non-zero value specified), the user&#8217;s IP address is blocked.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Email Alert Following Block</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LT_EMAIL_ALERT = <span style="color: #ff0000;">&quot;1&quot;</span></pre></div></div>

<p>This will send you email when something is blocked. I&#8217;d recommend leaving it on.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Blocking IP Addresses Based on Number of Connections</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">CT_LIMIT = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>This feature tracks connections and blocks the IP if the number of connections is too high. Use caution because if you enable this option and set this value too low, it will block legitimate traffic.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Application-Level Protection</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">PT_LIMIT = <span style="color: #ff0000;">&quot;60&quot;</span></pre></div></div>

<p>This feature provides application level protection against malicious scripts that take a long time to execute.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Blocking Port Scanners</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">PS_INTERVAL = <span style="color: #ff0000;">&quot;300&quot;</span>
PS_LIMIT = <span style="color: #ff0000;">&quot;10&quot;</span></pre></div></div>

<p style="margin-bottom:0; padding-bottom:5px;"><strong>Enabling HTML User Interface for CSF</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">UI = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>CSF has a built-in HTML user interface. You can enable this by setting UI = &#8220;1&#8243;. There are a list of prerequisites for this option in the <code>readme.txt</code>.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Notifying Blocked IP Addresses</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">MESSENGER = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>This option will notify blocked IP addresses when they have been blocked by the firewall.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Port Knocking</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">PORTKNOCKING = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>CSF supports port knocking, which is a technique that provides an additional layer of security. See <a href="http://www.portknocking.org/">http://www.portknocking.org/</a> for details. </p>
<h3>Allow and Deny Lists</h3>
<p>As we walked through the CSF configuration file, you saw that I referenced the <code>csf.deny</code> file, so it should come as no surprise that CSF also includes <code>csf.allow</code> to customize &#8220;allow&#8221; rules as well. If you are familiar with APF, these files have a very similar syntax &#8230; Each entry is made up of the same four components: <code>protocol|flow|port|IP</code>. The only real difference being that APF uses the colon as a delimiter while CSF uses the pipe:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#APF Version</span>
tcp:<span style="color: #000000; font-weight: bold;">in</span>:<span style="color: #007800;">d</span>=<span style="color: #000000;">48000</span>_48020:<span style="color: #007800;">s</span>=10.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#CSF Version</span>
tcp<span style="color: #000000; font-weight: bold;">|</span><span style="color: #000000; font-weight: bold;">in</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #007800;">d</span>=<span style="color: #000000;">48000</span>_48020<span style="color: #000000; font-weight: bold;">|</span><span style="color: #007800;">s</span>=10.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span></pre></div></div>

<p>Fortunately, replacing your colon with a pipe is a minimally invasive procedure that can be automated with a tool like vi.</p>
<h3>CSF Command Line Tool</h3>
<p>The command line tool for CSF is much more robust than the one for APF:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ csf <span style="color: #660033;">--help</span>
csf: v5.79 <span style="color: #7a0874; font-weight: bold;">&#40;</span>cPanel<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
ConfigServer Security <span style="color: #000000; font-weight: bold;">&amp;</span> Firewall
<span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000;">2006</span>-<span style="color: #000000;">2013</span>, Way to the Web Limited <span style="color: #7a0874; font-weight: bold;">&#40;</span>http:<span style="color: #000000; font-weight: bold;">//</span>www.configserver.com<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
Usage: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>csf <span style="color: #7a0874; font-weight: bold;">&#91;</span>option<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>value<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Option              Meaning
-h, <span style="color: #660033;">--help</span>          Show this message
-l, <span style="color: #660033;">--status</span>        List<span style="color: #000000; font-weight: bold;">/</span>Show iptables configuration
-l6, <span style="color: #660033;">--status6</span>      List<span style="color: #000000; font-weight: bold;">/</span>Show ip6tables configuration
-s, <span style="color: #660033;">--start</span>         Start firewall rules
-f, <span style="color: #660033;">--stop</span>          Flush<span style="color: #000000; font-weight: bold;">/</span>Stop firewall rules <span style="color: #7a0874; font-weight: bold;">&#40;</span>Note: lfd may restart csf<span style="color: #7a0874; font-weight: bold;">&#41;</span>
-r, <span style="color: #660033;">--restart</span>       Restart firewall rules
-q, <span style="color: #660033;">--startq</span>        Quick restart <span style="color: #7a0874; font-weight: bold;">&#40;</span>csf restarted by lfd<span style="color: #7a0874; font-weight: bold;">&#41;</span>
-sf, <span style="color: #660033;">--startf</span>       Force CLI restart regardless of LF_QUICKSTART setting
-a, <span style="color: #660033;">--add</span> ip        Allow an IP and add to <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.allow
-ar, <span style="color: #660033;">--addrm</span> ip     Remove an IP from <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.allow and delete rule
-d, <span style="color: #660033;">--deny</span> ip       Deny an IP and add to <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.deny
-dr, <span style="color: #660033;">--denyrm</span> ip    Unblock an IP and remove from <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.deny
-df, <span style="color: #660033;">--denyf</span>        Remove and unblock all entries <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.deny
-g, <span style="color: #660033;">--grep</span> ip       Search the iptables rules <span style="color: #000000; font-weight: bold;">for</span> an IP match <span style="color: #7a0874; font-weight: bold;">&#40;</span>incl. CIDR<span style="color: #7a0874; font-weight: bold;">&#41;</span>
-t, <span style="color: #660033;">--temp</span>          Displays the current list of temp IP entries and their TTL
-tr, <span style="color: #660033;">--temprm</span> ip    Remove an IPs from the temp IP ban and allow list
-td, <span style="color: #660033;">--tempdeny</span> ip ttl <span style="color: #7a0874; font-weight: bold;">&#91;</span>-p port<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>-d direction<span style="color: #7a0874; font-weight: bold;">&#93;</span>
                    Add an IP to the temp IP ban list. ttl is how long to
                    blocks <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>default:seconds, can use one suffix of h<span style="color: #000000; font-weight: bold;">/</span>m<span style="color: #000000; font-weight: bold;">/</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.
                    Optional port. Optional direction of block can be one of:
                    <span style="color: #000000; font-weight: bold;">in</span>, out or inout <span style="color: #7a0874; font-weight: bold;">&#40;</span>default:<span style="color: #000000; font-weight: bold;">in</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
-ta, <span style="color: #660033;">--tempallow</span> ip ttl <span style="color: #7a0874; font-weight: bold;">&#91;</span>-p port<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>-d direction<span style="color: #7a0874; font-weight: bold;">&#93;</span>
                    Add an IP to the temp IP allow list <span style="color: #7a0874; font-weight: bold;">&#40;</span>default:inout<span style="color: #7a0874; font-weight: bold;">&#41;</span>
-tf, <span style="color: #660033;">--tempf</span>        Flush all IPs from the temp IP entries
-cp, <span style="color: #660033;">--cping</span>        PING all members <span style="color: #000000; font-weight: bold;">in</span> an lfd Cluster
-cd, <span style="color: #660033;">--cdeny</span> ip     Deny an IP <span style="color: #000000; font-weight: bold;">in</span> a Cluster and add to <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.deny
-ca, <span style="color: #660033;">--callow</span> ip    Allow an IP <span style="color: #000000; font-weight: bold;">in</span> a Cluster and add to <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.allow
-cr, <span style="color: #660033;">--crm</span> ip       Unblock an IP <span style="color: #000000; font-weight: bold;">in</span> a Cluster and remove from <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.deny
-cc, <span style="color: #660033;">--cconfig</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>name<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>value<span style="color: #7a0874; font-weight: bold;">&#93;</span>
                    Change configuration option <span style="color: #7a0874; font-weight: bold;">&#91;</span>name<span style="color: #7a0874; font-weight: bold;">&#93;</span> to <span style="color: #7a0874; font-weight: bold;">&#91;</span>value<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">in</span> a Cluster
-cf, <span style="color: #660033;">--cfile</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Send <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">in</span> a Cluster to <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf<span style="color: #000000; font-weight: bold;">/</span>
-crs, <span style="color: #660033;">--crestart</span>    Cluster restart csf and lfd
-w, <span style="color: #660033;">--watch</span> ip      Log SYN packets <span style="color: #000000; font-weight: bold;">for</span> an IP across iptables chains
-m, <span style="color: #660033;">--mail</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>addr<span style="color: #7a0874; font-weight: bold;">&#93;</span>   Display Server Check <span style="color: #000000; font-weight: bold;">in</span> HTML or email to <span style="color: #7a0874; font-weight: bold;">&#91;</span>addr<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">if</span> present
-lr, <span style="color: #660033;">--logrun</span>       Initiate Log Scanner report via lfd
-c, <span style="color: #660033;">--check</span>         Check <span style="color: #000000; font-weight: bold;">for</span> updates to csf but <span style="color: #000000; font-weight: bold;">do</span> not upgrade
-u, <span style="color: #660033;">--update</span>        Check <span style="color: #000000; font-weight: bold;">for</span> updates to csf and upgrade <span style="color: #000000; font-weight: bold;">if</span> available
<span style="color: #660033;">-uf</span>                 Force an update of csf
-x, <span style="color: #660033;">--disable</span>       Disable csf and lfd
-e, <span style="color: #660033;">--enable</span>        Enable csf and lfd <span style="color: #000000; font-weight: bold;">if</span> previously disabled
-v, <span style="color: #660033;">--version</span>       Show csf version</pre></div></div>

<p>The command line tool will also tell you if the testing mode is enabled (which is a very useful feature). If TESTING were enabled, we&#8217;d see this line at the bottom of the output:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">*</span>WARNING<span style="color: #000000; font-weight: bold;">*</span> TESTING mode is enabled - <span style="color: #000000; font-weight: bold;">do</span> not forget to disable it <span style="color: #000000; font-weight: bold;">in</span> the configuration</pre></div></div>

<p>Did you make it all the way through?! Great! I know it&#8217;s a lot to take in, but it&#8217;s not terribly complicated when we break it down and understand how each piece works. Next time, I&#8217;ll be back with some tips on integrating CSF into cPanel. </p>
<p>-Mark</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/iptables-tips-and-tricks-csf-configuration/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Script Clip: HTML5 Audio Player with jQuery Controls</title>
		<link>http://blog.softlayer.com/2013/script-clip-html5-audio-player-with-jquery-controls/</link>
		<comments>http://blog.softlayer.com/2013/script-clip-html5-audio-player-with-jquery-controls/#comments</comments>
		<pubDate>Thu, 07 Mar 2013 21:05:19 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[audio player]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[creating]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=10633</guid>
		<description><![CDATA[HTML5 and jQuery provide mind-blowing functionality. Projects that would have taken hours of development and hundreds of lines of code a few years ago can now be completed in about the time it&#8217;ll take you to read this paragraph. If you wanted to add your own audio player on a web page in the past, [...]]]></description>
			<content:encoded><![CDATA[<p>HTML5 and jQuery provide mind-blowing functionality. Projects that would have taken hours of development and hundreds of lines of code a few years ago can now be completed in about the time it&#8217;ll take you to read this paragraph. If you wanted to add your own audio player on a web page in the past, what would it have involved? Complicated elements? Flash (*shudders*)? It was so complicated that most developers just linked to the audio file, and the user just downloaded the file to play it locally. With HTML5, an embedded, cross-browser audio player can be added to a page with five lines of code, and if you want to get really fancy, you can easily use jQuery to add some custom controls.</p>
<p>If you&#8217;ve read any of my <a href="http://blog.softlayer.com/author/cwolff/">previous blogs</a>, you know that I love when I find little code snippets that make life as a web developer easier. My go-to tools in that pursuit are HTML5 and jQuery, so when I came across this audio player, I knew I had to share. There are some great jQuery plugins to play music files on a web page, but they can be major overkill for a simple application if you have to include comprehensive controls and themes. Sometimes you just want something simple without all of that overhead:  </p>
<p><audio style="width:550px; margin: 0 auto; display:block;" controls><br />
  <source src="http://cdn.softlayer.com/innerlayer/Interrante-PopBounce.ogg" type="audio/ogg"><br />
  <source src="http://cdn.softlayer.com/innerlayer/Interrante-PopBounce.mp3" type="audio/mpeg"><br />
Your browser does not support the audio element.<br />
</audio></p>
<p>Oooh&#8230; Ahhh&#8230;</p>
<p>That song &mdash; Pop Bounce by SoftLayer&#8217;s very own <a href="http://www.reverbnation.com/chrisinterrante">Chris Interrante</a> &mdash; is written in five simple lines of HTML5 code:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;audio <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;width:550px; margin: 0 auto; display:block;&quot;</span> controls&gt;</span>
  <span style="color: #009900;">&lt;source <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://cdn.softlayer.com/innerlayer/Interrante-PopBounce.ogg&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;audio/ogg&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;source <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://cdn.softlayer.com/innerlayer/Interrante-PopBounce.mp3&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;audio/mpeg&quot;</span>&gt;</span>
Your browser does not support the audio element.
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>audio&gt;</span></pre></div></div>

<p>If IE 9+, Chrome 6+, Firefox 3.6+, Safari 5+ and Opera 10+ would all agree on supported file formats for the <code>&lt;audio&gt;</code> tag, the code snippet would be even smaller. I completely geek out over it every time I look at it and remember the days of yore. As you can see, the HTML5 application has some simple default controls: Play, Pause, Scan to Time, etc. As a developers, I couldn&#8217;t help but look for a to spice it up a little &#8230; What if we want to fire an event when the user plays, pauses, stops or takes any other action with the audio file? jQuery!</p>
<p>Make sure your jQuery include is in the <code>&lt;head&gt;</code> of your page:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>Now let&#8217;s use jQuery to script separate &#8220;Play&#8221; and &#8220;Pause&#8221; links &#8230; And let&#8217;s have those links fire off an alert when they are pressed:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#play-button&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#audioplayer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'You have played the audio file!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>    
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#pause-button&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#audioplayer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">pause</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'You have paused the audio file!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>    
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>With that script in the <code>&lt;head&gt;</code> as well, the HTML on our page will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span>:<span style="color: #ff0000;">&quot;audioplayer&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;audio <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;audioplayer&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;audioplayer&quot;</span> controls loop&gt;</span>
    <span style="color: #009900;">&lt;source <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://cdn.softlayer.com/innerlayer/Interrante-PopBounce.ogg&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;audio/ogg&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;source <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://cdn.softlayer.com/innerlayer/Interrante-PopBounce.mp3&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;audio/mpeg&quot;</span>&gt;</span>
  Your browser does not support the audio element.
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>audio&gt;</span>
&nbsp;
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;play-button&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Play!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pause-button&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Pause!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Want proof that it works that simply? <a href="http://cdn.softlayer.com/innerlayer/audioSL.html">Boom.</a></p>
<p>You can theme it any way you like; you can add icons instead of the text &#8230; The world is your oyster. The bonus is that you&#8217;re using one of the lightest media players on the Internet! If you decide to get brave (or just <em>more awesome</em>), you can explore additional features. You&#8217;re using jQuery, so your possibilities are nearly limitless. If you want to implement a &#8220;Stop&#8221; feature (which returns the audio back to the beginning when &#8220;Stop&#8221; is pressed), you can get creative:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#stop-button&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#audioplayer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">currentTime</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// return the audio file back to the beginning</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you want to include some volume controls, those can be added in a snap as well:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#volumeUp&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#audioplayer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">volume</span> <span style="color: #339933;">+=</span><span style="color: #CC0000;">0.1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#volumeDown&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#audioplayer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">volume</span> <span style="color: #339933;">-=</span><span style="color: #CC0000;">0.1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Try it out and let me know what you think. Your homework is to come up with some unique audio player functionality and share it here!</p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/script-clip-html5-audio-player-with-jquery-controls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
<enclosure url="http://cdn.softlayer.com/innerlayer/Interrante-PopBounce.ogg" length="4222877" type="audio/ogg" />
<enclosure url="http://cdn.softlayer.com/innerlayer/Interrante-PopBounce.mp3" length="2680757" type="audio/mpeg" />
		</item>
		<item>
		<title>Global Game Jam: Build a Video Game in 48 Hours</title>
		<link>http://blog.softlayer.com/2013/global-game-jam-build-a-video-game-in-48-hours/</link>
		<comments>http://blog.softlayer.com/2013/global-game-jam-build-a-video-game-in-48-hours/#comments</comments>
		<pubDate>Wed, 20 Feb 2013 22:00:35 +0000</pubDate>
		<dc:creator>Andy Mui</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[International]]></category>
		<category><![CDATA[Canada]]></category>
		<category><![CDATA[challenge]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[game developers]]></category>
		<category><![CDATA[gamers]]></category>
		<category><![CDATA[Global Game Jam]]></category>
		<category><![CDATA[hackathon]]></category>
		<category><![CDATA[startups]]></category>
		<category><![CDATA[Vancouver]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=10658</guid>
		<description><![CDATA[You&#8217;re a conflicted zombie that yearns to be human again. Now you&#8217;ve got to dodge grandma and babies in an 8-bit side-scroller. Now you&#8217;re Vimberly Koll, and you have to stop Poseidon from raining down on the Global Game Jam. At the end of Global Game Jam Vancouver, teams of developers, 3D artists, level designers [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;re a conflicted zombie that yearns to be human again. Now you&#8217;ve got to dodge grandma and babies in an 8-bit side-scroller. Now you&#8217;re Vimberly Koll, and you have to <a href="http://globalgamejam.org/2013/poseidon-vs-game-jam">stop Poseidon from raining down on the Global Game Jam</a>. At the end of <a href="http://www.ggjvancouver.com/">Global Game Jam Vancouver</a>, teams of developers, 3D artists, level designers and sound engineers conceptualized and created these games (along with a number of others) in less than 48 hours. Building a game in a weekend is no small task, so only the best and brightest game developers in the world converge on over 300 sites in 63 countries to show off their skills. </p>
<p>For the fifth annual <a href="http://globalgamejam.org/">Global Game Jam</a>, more than 16,000 participants committed a weekend to learning from and collaborating with their peers in a worldwide game development hackathon. I was lucky enough to get to sit in on the action in Vancouver, and I thought I&#8217;d give you a glimpse into how participants make game development magic happen in such a short period of time.</p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/gamejam2.jpg" alt="Vancouver Global Game Jam"/></p>
<p><strong>Day 1 (Friday Night): The Brainstorm</strong><br />
More than 260 participants poured into an open study area of the Life Sciences building at the Univerity of British Columbia to build the next best distraction &#8230; er, video game. The event kicked off with a keynote from Brian Proviciano, a game development prodigy, who shared his history and offered sage advice for those interested in the industry. Following a comical 20-second idea pitch session, the caffeine began to flow and the brainstorm commenced. </p>
<p>Inspiration could come from anywhere, and a perfect example is the &#8220;Poseidon&#8221; game I mentioned above: GGJVancouver organizer Kimberly Voll had sprinklers rain on her office a few days prior to the event, so someone decided to make a game out of that situation. This year, the Global Game Jam introduced an interesting twist that they called &#8220;diversifiers.&#8221; Diversifiers are side-challenges for extra credit, and two of my favorites were &#8220;Atari Age&#8221; &mdash; the game has to be smaller than 4kb &mdash; and &#8220;May the (Web) Force be With You&#8221; &mdash; the game has to run in a browser.</p>
<p>Fast-forward two hours, and as you look around, you see storyboards and scripts being written, characters being born, and a few intrepid developers starting to experiment with APIs, game engines , and external controllers to find some additional flair for their final products. You wouldn&#8217;t expect a game made in 48 hours to incorporate an iOS Eye Tracking API or the Leap Motion gesture controller, but these developers are ambitious!</p>
<p>As the concepts are finalized, team members rotate in and out for sleep, and some even go home to get some rest &mdash; a good idea on the first night since everyone usually pulls an all-nighter on Saturday.</p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/gamejam1.jpg" alt="Vancouver Global Game Jam"/></p>
<p><strong>Day 2 (Saturday): Laying the Foundation</strong><br />
It was cool to walk the aisles and peer over peoples&#8217; shoulders as musical scores, wrangled code and character models were coming together. However, the scene wasn&#8217;t all smiles and hugs; a few groups were wrestling quirky bugs and integration issues, and in some cases, they ended up having to completely reboot their approach. Day 2 set the course for all of the teams. A few teams disbanded due to disagreements or unfixable bugs, and some developers peeled off from their teams to follow an untamed passion. In the Global Game Jam, there are no rules &#8230; only games.  </p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/gamejam3.jpg" alt="Vancouver Global Game Jam"/></p>
<p><strong>Day 3 (Sunday): Sleep, What&#8217;s That?</strong><br />
By Day 3, the building starts feeling like a college dorm during finals week when everyone is staying up all night to study or finish their comp-sci assignments (I know it wasn&#8217;t just me&#8230;). Running on various vehicles of caffeine, teams worked heads-down all day to meet their 3pm deadline. Sighs of relief and high fives were exchanged when the games were submitted, and the event concluded with a pizza party and demo session where everyone could see and share the fruits of their labor.  </p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/gamejam4.jpg" alt="Vancouver Global Game Jam"/></p>
<p>As I left the conference, teams were given the opportunity to showcase their games on the big screen to a chorus of laughter and applause. It was an awesome experience, and I&#8217;m glad SoftLayer sponsored it so that I could attend, take it all in and meet a ton of outstanding up-and-coming game developers. If you&#8217;re into making games (or you&#8217;ve thought about it), check out the Global Game Jam one of these years.</p>
<p>Just don&#8217;t forget to bring deodorant &#8230; for your neighbor&#8217;s sake.</p>
<p>-<a href="https://twitter.com/andy_mui">@andy_mui</a></p>
<p class="attribution">Photo Credit Shout-Outs: <a href="https://twitter.com/Exal_online">Alex Larente</a>, <a href="https://twitter.com/ligiagb">Ligia Brosch</a>, <a href="http://www.linkedin.com/in/nazmadani">Naz Madani.</a> Great shots!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/global-game-jam-build-a-video-game-in-48-hours/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips and Tricks – Building a jQuery Plugin (Part 2)</title>
		<link>http://blog.softlayer.com/2013/tips-and-tricks-building-a-jquery-plugin-part-2/</link>
		<comments>http://blog.softlayer.com/2013/tips-and-tricks-building-a-jquery-plugin-part-2/#comments</comments>
		<pubDate>Thu, 14 Feb 2013 15:25:43 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[exercise]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=10619</guid>
		<description><![CDATA[jQuery plugins don&#8217;t have to be complicated to create. If you&#8217;ve stumbled upon this blog in pursuit of a guide to show you how to make a jQuery plugin, you might not believe me &#8230; It seems like there&#8217;s a chasm between the &#8220;haves&#8221; of jQuery plugin developers and the &#8220;have nots&#8221; of future jQuery [...]]]></description>
			<content:encoded><![CDATA[<p>jQuery plugins don&#8217;t have to be complicated to create. If you&#8217;ve stumbled upon this blog in pursuit of a guide to show you how to make a jQuery plugin, you might not believe me &#8230; It seems like there&#8217;s a chasm between the &#8220;haves&#8221; of jQuery plugin developers and the &#8220;have nots&#8221; of future jQuery developers, and there aren&#8217;t very many bridges to get from one side to the other. In <a href="http://blog.softlayer.com/2012/tips-and-tricks-building-a-jquery-plugin-part-1/">Part 1</a> of our &#8220;Building a jQuery Plugin&#8221; series, we broke down how to build the basic structure of a plugin, and in this installment, we&#8217;ll be adding some usable functionality to our plugin. </p>
<p>Let&#8217;s start with the jQuery code block we created in Part 1:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">slPlugin</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                myVar<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;This is&quot;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// this will be the default value of this var</span>
                anotherVar<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;our awesome&quot;</span><span style="color: #339933;">,</span>
                coolVar<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;plugin!&quot;</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>defaults<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                ourString <span style="color: #339933;">=</span> myVar <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; &quot;</span> <span style="color: #339933;">+</span> anotherVar <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; &quot;</span> <span style="color: #339933;">+</span> coolVar<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">return</span> ourString<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We want our plugin to do a little more than return, &#8220;This is our awesome plugin!&#8221; so let&#8217;s come up with some functionality to build. For this exercise, let&#8217;s create a simple plugin that allows truncates a blob of text to a specified length while providing the user an option show/hide the rest of the text. Since the most common character length limitation on the Internet these days is Twitter&#8217;s 140 characters, we&#8217;ll use that mark in our example.</p>
<p>Taking what we know about the basic jQuery plugin structure, let&#8217;s create the foundation for our new plugin &mdash; <code>slPlugin2</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">slPlugin2</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            length<span style="color: #339933;">:</span> <span style="color: #CC0000;">140</span><span style="color: #339933;">,</span>
            moreLink<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;read more&quot;</span><span style="color: #339933;">,</span>
            lessLink<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;collapse&quot;</span><span style="color: #339933;">,</span>
            trailingText<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;...&quot;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>defaults<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As you can see, we&#8217;ve established four default variables:</p>
<ul>
<li><code>length</code>: The length of the paragraph we want before we truncate the rest.</li>
<li><code>moreLength</code>: What we append to the paragraph when it is truncated. This will be the link the user clicks to expand the rest of the text.</li>
<li><code>lessLink</code>: What we append to the paragraph when it is expanded. This will be the link the user clicks to collapse the rest of the text.</li>
<li><code>trailingText</code>: The typical ellipses to append to the truncation.</li>
</ul>
<p>In our jQuery plugin example from Part 1, we started our function with <code>this.each(function() {</code>, and for this example, we&#8217;re going to add a return for <code>this</code> to maintain chainability. By doing so, we&#8217;re able to manipulate the segment with methods. For example, if we started our function with <code>this.each(function() {</code>, we&#8217;d call it with this line:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#ourParagraph'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slPlugin2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If we start the function with <code>return this.each(function() {</code>, we have the freedom to add further manipulation:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#ourParagraph'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slPlugin2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>With such a simple change, we&#8217;re able to add method calls to make one massive dynamic function. </p>
<p>Let&#8217;s flesh out the actual function a little more. We&#8217;ll add a substantial bit of code in this step, but you should be able to follow along with the changes via the comments:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">slPlugin2</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            length<span style="color: #339933;">:</span> <span style="color: #CC0000;">140</span><span style="color: #339933;">,</span> 
            moreLink<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;read more&quot;</span><span style="color: #339933;">,</span>
            lessLink<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;collapse&quot;</span><span style="color: #339933;">,</span>
            trailingText<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;...&quot;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>defaults<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// return this keyword for chainability</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> ourText <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// the element we want to manipulate</span>
            <span style="color: #003366; font-weight: bold;">var</span> ourHtml <span style="color: #339933;">=</span> ourText.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//get the contents of ourText!</span>
            <span style="color: #006600; font-style: italic;">// let's check if the contents are longer than we want</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ourHtml.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> options.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003366; font-weight: bold;">var</span> truncSpot <span style="color: #339933;">=</span> ourHtml.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color: #339933;">,</span> options.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// the location of the first space (so we don't truncate mid-word) where we will end our truncation.</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">// make sure to ignore the first space IF the text starts with a space</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>truncSpot <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #006600; font-style: italic;">// the part of the text that will not be truncated, starting from the beginning</span>
       <span style="color: #003366; font-weight: bold;">var</span> firstText <span style="color: #339933;">=</span> ourHtml.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> truncSpot<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #006600; font-style: italic;">// the part of the text that will be truncated, minus the trailing space</span>
       <span style="color: #003366; font-weight: bold;">var</span> secondText <span style="color: #339933;">=</span> ourHtml.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>truncSpot<span style="color: #339933;">,</span> ourHtml.<span style="color: #660066;">legnth</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Are you still with us? I know it seems like a lot to take in, but each piece is very straightforward. The <code>firstText</code> is the chunk of text that will be shown: The first 140 characters (or whatever <code>length</code> you define). The <code>secondText</code> is what <em>will</em> be truncated. We have two blobs of text, and now we need to make them work together:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">slPlugin2</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            length<span style="color: #339933;">:</span> <span style="color: #CC0000;">140</span><span style="color: #339933;">,</span> 
            moreLink<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;read more&quot;</span><span style="color: #339933;">,</span>
            lessLink<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;read less&quot;</span><span style="color: #339933;">,</span>
            trailingText<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;...&quot;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>defaults<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// return this keyword for chainability</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> ourText <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// the element we want to manipulate</span>
            <span style="color: #003366; font-weight: bold;">var</span> ourHtml <span style="color: #339933;">=</span> ourText.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//get the contents of ourText!</span>
            <span style="color: #006600; font-style: italic;">// let's check if the contents are longer than we want</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ourHtml.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> options.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003366; font-weight: bold;">var</span> truncSpot <span style="color: #339933;">=</span> ourHtml.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color: #339933;">,</span> options.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// the location of the first space (so we don't truncate mid-word) where we will end our truncation.</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">// make sure to ignore the first space IF the text starts with a space</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>truncSpot <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #006600; font-style: italic;">// the part of the text that will not be truncated, starting from the beginning</span>
       <span style="color: #003366; font-weight: bold;">var</span> firstText <span style="color: #339933;">=</span> ourHtml.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> truncSpot<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #006600; font-style: italic;">// the part of the text that will be truncated, minus the trailing space</span>
       <span style="color: #003366; font-weight: bold;">var</span> secondText <span style="color: #339933;">=</span> ourHtml.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>truncSpot<span style="color: #339933;">,</span> ourHtml.<span style="color: #660066;">legnth</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #006600; font-style: italic;">// perform our truncation on our container ourText, which is technically more of a &quot;rewrite&quot; of our paragraph, to our liking so we can modify how we please. It's basically saying: display the first blob then add our trailing text, then add our truncated part wrapped in span tags (to further modify)</span>
       ourText.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>firstText <span style="color: #339933;">+</span> options.<span style="color: #660066;">trailingText</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;span class=&quot;slPlugin2&quot;&gt;'</span> <span style="color: #339933;">+</span> secondText <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/span&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #006600; font-style: italic;">// but wait! The secondText isn't supposed to show until the user clicks &quot;read more&quot;, right? Right! Hide it using the span tags we wrapped it in above.</span>
       ourText.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.slPlugin2'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;display&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;none&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Our function now truncates text to the specified length, and we can call it from our page simply:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.slPlugin2.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
$(document).ready(function() {  
    $('#slText').slPlugin2();  
});
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>Out of all the ways to truncate text via jQuery, this has to be my favorite. It&#8217;s feature-rich while still being fairly easy to understand. As you might have noticed, we haven&#8217;t touched on the &#8220;read more&#8221; and &#8220;read less&#8221; links or the expanding/collapsing animations yet, but we&#8217;ll be covering those in Part 3 of this series. Between now and when Part 3 is published, I challenge you to think up how you&#8217;d add those features to this plugin as homework. </p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/tips-and-tricks-building-a-jquery-plugin-part-2/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
