<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
  <title>Development Cycle</title>
  <link>https://www.development-cycle.com/</link>
  <description>Notes on Linux, sysadmin, PHP, security and the web — the working notes of Anthony Mills.</description>
  <language>en</language>
  <lastBuildDate>Fri, 29 Jan 2016 00:00:00 GMT</lastBuildDate>
  <atom:link href="https://www.development-cycle.com/feed/index.xml" rel="self" type="application/rss+xml"/>
  <item>
    <title>Changing the Linux Mint Login Screen Background Images</title>
    <link>https://www.development-cycle.com/blog/changing-the-linux-mint-login-screen-background-images/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/changing-the-linux-mint-login-screen-background-images/</guid>
    <pubDate>Fri, 29 Jan 2016 00:00:00 GMT</pubDate>
    <description>Newer versions of Linux Mint use MintX as the default login screen greeter. By default it comes with a predefined collection of images that display in the background that change periodically in a…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2016/01/mintx_login.webp" alt="mintx_login" class="alignright" width="300" height="207">Newer versions of Linux Mint use MintX as the default login screen greeter. By default it comes with a predefined collection of images that display in the background that change periodically in a slide show type format. The default images are great but I wanted to add a personal touch to my system and change them to my own photos.</p>
<p>Here I will run you through the process of changing MintX to use images of your choosing. First create a directory for the new images to live in:</p>
<p><em><strong>sudo mkdir /usr/share/backgrounds/custom/</strong></em></p>
<p>Now using sudo, copy some images on the systems that you would like to use as backgrounds into the newly created directory i.e</p>
<p><em><strong>sudo cp ~/Documents/Pictures/my_photo.jpg /usr/share/backgrounds/custom/</strong></em></p>
<p>Edit the MintX slide show configuration file:</p>
<p><em><strong>sudo nano /usr/share/mdm/html-themes/Mint-X/slideshow.conf</strong></em></p>
<p>Scroll down past the heading [backgrounds] and delete all of the default entries. Then add in some pointing to the images you copied over i.e</p>
<p><strong>file:///usr/share/backgrounds/custom/my_photo.jpg</strong><br>
<strong>file:///usr/share/backgrounds/custom/another_photo.jpg</strong><br>
<strong>file:///usr/share/backgrounds/custom/swesome_background.jpg</strong></p>
<p>When your done save your changes, logout and you should now see your custom images being used as the background at the login prompt.</p>
]]></content:encoded>
    <category>Cinnamon</category>
    <category>Linux Mint</category>
    <category>MintX</category>
  </item>
  <item>
    <title>Raspberry Pi 2 Bitcoin Node</title>
    <link>https://www.development-cycle.com/blog/raspberry-pi-2-bitcoin-node/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/raspberry-pi-2-bitcoin-node/</guid>
    <pubDate>Tue, 26 May 2015 00:00:00 GMT</pubDate>
    <description>Not long ago I setup up a Bitcoin node on a Debian Wheezy VPS to teach myself about Bitcoin and the blockchain in general. It was a great learning experience but the memory requirements of the…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2015/05/raspberry_pi.webp" alt="raspberry_pi" class="alignright" width="237" height="300">Not long ago I setup up a Bitcoin node on a Debian Wheezy VPS to teach myself about Bitcoin and the blockchain in general. It was a great learning experience but the memory requirements of the Bitcoin software kept causing my VPS instance to run out of memory so the kernel would constantly be killing off the bitcoind process.</p>
<p>A growing blockchain also meant the node was getting close to the limit of its available disk space as well. Simply increasing the amount of diskspace available to the VPS instance with the plans offered by the hosting provider was going to be prohibitive for the purpose so I decided to assess other solutions.</p>
<p>Luckily I had a spare Raspberry Pi 2 that I had yet to do anything with at home. So I made the decision to try and install a Bitcoin node on that instead to save some money.</p>
<p>The main expense with using the Raspberry Pi was going to be finding enough storage for the block chain. I didn’t have an SD card that was big enough at home to accommodate the operating system image and the block chain.</p>
<p>So I opted to buy a cheap external USB flash drive to keep it seperate from the root filesystem. After formatting with ext4 the flash drive has 57Gb of available space, at the time of writing the blockchain takes up 40Gb of space so that leaves a further 17Gb for future growth.</p>
<h2>Hardware Used</h2>
<p><em>RaspberryPi 2</em><br>
<em>Clear plastic case</em><br>
<em>Kingston 64GB USB Flash Drive</em><br>
<em>16GB Micro SD card with the default Raspbian distro image</em><br>
<em>Standard power supply with micro USB connector</em></p>
<h2>Increasing the Swap</h2>
<p>As I mentioned before I was originally running a Bitcoin node on a SolusVM based VPS with 1GB of ram and no swap. The Bitcoin process after running for a while would consume all the available memory and kept getting killed off by the Kernel.</p>
<p>The Raspberry Pi 2 also has 1GB of RAM so I wanted to give it a fairly big swap file to hopefully act as a buffer to avoid exhausting the memory again. Raspbian uses dphys-swapfile to manage a swapfile on the Pi so increasing the size of the allocated space is very simple:</p>
<pre><code class="language-bash">nano /etc/dphys-swapfile
</code></pre>
<p>By default Raspbian has a 100mb allocated to swap so I changed this to 1024 for 1gb of swap space.</p>
<pre><code class="language-bash">CONF_SWAPSIZE=1024
</code></pre>
<p>After saving the changes the dphys-swapfile service needs to be restarted for the changes to take effect.</p>
<pre><code class="language-bash">/etc/init.d/dphys-swapfile stop

/etc/init.d/dphys-swapfile start
</code></pre>
<h2>Preparing the USB Stick</h2>
<pre><code class="language-bash">fdisk -l
</code></pre>
<p>This should list your USB drive so you can find its device identifier. In my case it was /dev/sda, so with this information I then used fdisk to delete the current partition on the device and create a new one.</p>
<pre><code class="language-bash">fdisk /dev/sda
</code></pre>
<p>After writing the new partition to the device, the mkfs command was used to format the newly created partition with an ext4 file system.</p>
<pre><code class="language-bash">mkfs -t ext4 /dev/sda1
</code></pre>
<p>After formatting the USB drive I created a new mount point for the drive to be mounted on the root filesytem.</p>
<pre><code class="language-bash">mkdir /media/external
</code></pre>
<p>Then mounted the drive to the newly created mount point:</p>
<pre><code class="language-bash">mount /dev/sda1 external/
</code></pre>
<h2>Cleaning The System</h2>
<p>Raspbian is a great distro, but out of the box I feel alot of excess software comes pre installed for the purpose of running a Bitcoin node. <a href="http://blog.samat.org/2015/02/05/slimming-an-existing-raspbian-install/">Samat Jain has some good pointers on his blog</a>  for removing some of the bloat. He has even been nice enough to put up a script on github to remove the uneeded packages automatically by simply running the following command:</p>
<pre><code class="language-bash">wget https://gist.githubusercontent.com/samatjain/4dda24e14a5b73481e2a/raw/5d9bac8ec40b94833b4e9938121945be252fdee1/Slim-Raspbian.sh -O Slim-Raspbian.sh
</code></pre>
<h2>Building The Bitcoin Software</h2>
<p>First up the package list on the systems need to be updated then upgraded to the latest versions available.</p>
<pre><code class="language-bash">apt-get update

apt-get upgrade
</code></pre>
<p>Some important packages ten need to be installed that are required by to build and run the Bitcoin software on the Raspberry Pi.</p>
<pre><code class="language-bash">apt-get install dpkg-dev qt4-qmake libdb5.1++-dev libqt4-dev libqrencode-dev libminiupnpc-dev libboost-test1.49-dev zlib1g lib32z1 libc6-i386 debhelper devscripts bash-completion libboost-system-dev libssl-dev pkg-config libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libboost-test-dev dh-autoreconf libboost-chrono1.49.0 libboost-chrono-dev libboost-all-dev libprotobuf-dev protobuf-compiler libc6-dev libz1
git clone https://github.com/bitcoin/bitcoin.git v0.10.2

cd v0.10.2

./autogen.sh

./configure –with-incompatible-bdb
</code></pre>
<p>With the configure prcess finished its time to run make. Be forewarned this command is going to take a long time to complete so find yourself something to do in the interim. The Raspberry Pi 2 has a quad core processor but the build process will only use one core by default. So you may want to try speeding things up by appending the compiler flag ” -j 4″ after the make command to spawn 4 processes that can keep each of the processor cores busy.</p>
<pre><code class="language-bash">make

make install
</code></pre>
<h2>Create Bitcoind User</h2>
<p>Up until now you have probably been logged into your machine as root either natively or using sudo to elevate your system privileges. For the sake of security its not a great ideato run the Bitcoin process as a user with elevated privileges. So I then added a dedicated user account called bitcoin for this purpose:</p>
<pre><code class="language-bash">adduser bitcoin
</code></pre>
<p>After this I then logged in as the newly created bitcoin user to complete the rest of the setup process.</p>
<pre><code class="language-bash">su bitcoin
</code></pre>
<p>B<strong>itcoin Configuration</strong></p>
<p>A new configuration file was then created for the Bitcoin service.</p>
<pre><code class="language-bash">pico /home/bitcoin/.bitcoin/bitcoin.conf
</code></pre>
<p>In this file at a minimum add two lines ( see below for example ) defining a user and password for the JSON RPC web service that allows you to interact with the node.</p>
<pre><code class="language-bash">rpcuser=bitcoinrpc

rpcpassword=D5vrfdZUeQpeF3GCSp5nUofdsJgs5fojgdpB81ZmwVeSmz2
</code></pre>
<p>For an example file config file showing some of the other possible parameters I recommend taking a look at the Bitcoin Wiki to see all of the options available.</p>
<h2>Start the Bitcoind Process</h2>
<p>At this point all the bit steps have been taken care of its simply a matter of starting the bitcoind process:</p>
<pre><code class="language-bash">bitcoind –daemon
</code></pre>
<p>Looking in the same directory as the .bitcoin config file a file named debug.log will now exist. The tail command can be used to follow the log file ( i.e tail -f debug.log ) and check what the node is up to. After first starting the Bitcoin node the software will sync with the network by downloading the blockchain. Due to the size of the Blockchain this will take a long time depending on your network speed and other factors. In my case over an ADSL2 connection this step took around 4 days to complete.</p>
<h2>Checking on Bitcoind</h2>
<p>After getting the Bitcoin software installed and running I wanted to ensure it would restart if it occasionally crashed / or got killed off by the Kernel like on the VPS. So I wrote a small shell script to check the process is running and if its not to start it.</p>
<pre><code class="language-bash">#!/bin/bash
x=`pgrep bitcoind `

if [ $x &gt; 0 ];
then
echo &quot;Bitcoind Running&quot;
else
echo &quot;Starting Bitcoind&quot;
/usr/local/bin/bitcoind --deamon &amp;
fi
</code></pre>
<p>The file was then made executable and a line added to the bitcoin users crontab for to run the script every 15 minutes.</p>
<pre><code class="language-bash">*/15 * * * * /media/external/bitcoin/.bitcoin/service_check.sh &gt;/dev/null 2&gt;&amp;1
</code></pre>
<h2>Beer money?</h2>
<p>Are you still awake after reading all that? Are you feeling rich? Beer money is always greatly appreciated!</p>
<p>Send BTC to <a href="https://blockchain.info/address/1HYtEBszMQZwFNomhD78h7UWE9aeY7Kru1" title="Donate BTC">1HYtEBszMQZwFNomhD78h7UWE9aeY7Kru1</a></p>
<img src="https://www.development-cycle.com/assets/images/2015/01/wallet_address.webp" alt="Bitcoin Donations" class="aligncenter" width="250" height="250">
<h2>Related Links:</h2>
<p><a href="https://www.development-cycle.com/blog/running-a-bitcoin-node-on-debian-wheezy/">Running a Bitcoin Node on a Debian Wheezy VPS</a></p>
<h2>Further Reading:</h2>
<p><a href="https://bitcoin.org/en/">Bitcoin Project</a></p>
<p><a href="https://github.com/bitcoin/bitcoin">Bitcoin @ Github</a></p>
<p><a href="https://www.raspbian.org/">Raspbian – Debian based distro optimised for the Raspberry Pi</a></p>
]]></content:encoded>
    <category>bitcoin</category>
    <category>blockchain</category>
    <category>cryptocurrency</category>
    <category>Debian</category>
    <category>Raspberry Pi</category>
  </item>
  <item>
    <title>Running a Bitcoin Node on Debian Wheezy</title>
    <link>https://www.development-cycle.com/blog/running-a-bitcoin-node-on-debian-wheezy/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/running-a-bitcoin-node-on-debian-wheezy/</guid>
    <pubDate>Thu, 22 Jan 2015 00:00:00 GMT</pubDate>
    <description>Over the last few years I have keenly followed the rise of Bitcoin from its early days trading at around $8USD. I watched with interest when it made its sharp rise to $1200USD and then felt a bit of…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2015/01/BC_Logo_.webp" alt="Bitcoin Logo" class="alignright" width="256" height="256">Over the last few years I have keenly followed the rise of Bitcoin from its early days trading at around $8USD. I watched with interest when it made its sharp rise to $1200USD and then felt a bit of dismay with more recent decline back to around the $200USD mark.</p>
<p>As a whole I think Bitcoin and the Blockchain are both game changing technologies that are yet to see their full potential. So over the last few months rather than just watching the Bitcoin exchange rate bounce around the place. I sought to get a deeper understanding of how the underlying technology works and how it can be extended further.</p>
<p>As part of this learning process I decided to set up a Bitcoin node both to act as learning resource for myself and to help contribute something to the larger Bitcoin network. In this article I am going to run through the process of turning a VPS running Debian Wheezy into a fully fledged Bitcoin node.</p>
<p>Unfortunately at the time of writing the Bitcoin software is not available for Debian Wheezy in the standard repositories. So we are going to use a Ubuntu PPA to get the source code and build a package from that instead. Before we get started though please be aware the Blockchain is huge, will use upwards of 30GB of storage and it will only continue to grow. So keep this in mind if you are going to run your node on a VPS or similar to get one with enough disk space.</p>
<p>Okay now that the initial warnings out of the way lets get started. Login to your system an add the following line to the <em>/etc/apt/sources.list file</em> and then save the changes.</p>
<pre><code class="language-bash">deb-src http://ppa.launchpad.net/bitcoin/bitcoin/ubuntu precise main
</code></pre>
<p>First we need to add the key for the new repository you added to the sources.list. Then its time to update the package list and upgrade the existing libraries and packages that are installed on the system.</p>
<pre><code class="language-bash">apt-key adv –keyserver keyserver.ubuntu.com –recv-keys 8842CE5E
apt-get update
apt-get upgrade
</code></pre>
<p>Before we get too carried away though we need to install some supporting packages that the Bitcoin software requires to function.</p>
<pre><code class="language-bash">apt-get install dpkg-dev qt4-qmake libdb5.1++-dev libqt4-dev libqrencode-dev libminiupnpc-dev libboost-test1.49-dev zlib1g lib32z1 libc6-i386 debhelper devscripts bash-completion libboost-system-dev libssl-dev pkg-config libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libboost-test-dev dh-autoreconf libboost-chrono1.49.0 libboost-chrono-dev libboost-all-dev libprotobuf-dev protobuf-compiler
</code></pre>
<p>Next we grab the source code for the Bitcoin project and get it ready to compile into a .deb package.</p>
<pre><code class="language-bash">cd /usr/src
apt-get source bitcoin
cd bitcoin-0.9.4/
</code></pre>
<p><strong>NOTE:</strong> The exact name of the Bitcoin directory will of course change over time as newer versions of the project are released.</p>
<p>Open the file <em>debian/changelog</em> with a text editor and add the following lines to the top of the file:</p>
<pre><code class="language-bash">bitcoin (0.9.4-wheezy1) wheezy; urgency=low
* Mark for wheezy.
— Matt Corallo &lt;matt@bluematt.me&gt;
</code></pre>
<p>Then close the changelog saving the changes. Now clean the source tree by running the command below from the root of the project code base.</p>
<pre><code class="language-bash">./debian/rules clean
</code></pre>
<p><strong><img src="https://www.development-cycle.com/assets/images/2015/01/exclaim.webp" alt="exclaim" class="alignleft" width="41" height="36">Side Note:</strong> If your system is like mine you may get some complaints back from the cleaning process about the locale not being set. To fix this issue run the commands below to regenerate the system locales. Selecting the appropriate locales that you want on the system for your location then run the clean process again.</p>
<pre><code class="language-bash">locale-gen en_AU en_AU.UTF-8 hu_HU hu_HU.UTF-8

dpkg-reconfigure locales
./debian/rules clean
</code></pre>
<p>If you run the build script as it stands you will get an error from the build process complaining about the version of Berkeley DB installed on the system.</p>
<p>You can find out what version you have installed on your system by executing the following snippet.</p>
<pre><code class="language-bash">cat /usr/include/db.h | grep DB_VERSION_STRING
</code></pre>
<p>This will display something similar to the output below.</p>
<pre><code class="language-bash">#define DB_VERSION_STRING “Berkeley DB 5.1.29: (October 25, 2011)”
</code></pre>
<p>My system had version 5.1.29 which is newer than the build process is requesting so I am just going to get it to ignore the issue. If you really want to use Berkeley DB v4.8 you will have to compile it as well which is outside of the cope of this article.</p>
<p>Continuing on, lets add a parameter for the build process to just use the newer version of Berkeley DB we already have. Edit the <em>debian/rules</em> file go down to line 21 and append the flag to the configure command, so it looks like the following.</p>
<pre><code class="language-bash">./configure –with-incompatible-bdb
</code></pre>
<p>The flag above will allow the binary to compile but any wallets created on the system will not be portable.</p>
<p>If you are not planning on using the wallet functionality and simply want to run a P2P node. You can go one step further and simply disable the functionality altogether by appending the flag below instead.</p>
<pre><code class="language-bash">./configure –disable-wallet
</code></pre>
<p>With the Berkeley DB issue fixed its time to run the actual build process. This step can be time consuming depending on the speed of your system taking anywhere from 10 – 30+ minutes to complete.</p>
<pre><code class="language-bash">./debian/rules binary
</code></pre>
<p>On completion of the build process you should have a freshly made .deb file that can be easily installed with the Debian package manager.</p>
<pre><code class="language-bash">cd ../

dpkg -i bitcoind_0.9.4-precise1_amd64.deb
</code></pre>
<p>Up to this point you have probably been logged into your machine as root either natively or using sudo to elevate you privileges for the build process. For the sake of security you obviously don’t want to run the Bitcoin node under a user with so many systems privileges. So lets add dedicated user account to run the service under so its not running with root privileges:</p>
<pre><code class="language-bash">adduser bitcoin
</code></pre>
<p>Create a new configuration file for the Bitcoin service.</p>
<pre><code class="language-bash">pico /home/bitcoin/.bitcoin/bitcoin.conf
</code></pre>
<p>In this file at a minimum add two lines ( see below for example ) defining a user and password for the JSON RPC web service that allows you to interact with the node.</p>
<pre><code class="language-bash">rpcuser=bitcoinrpc

rpcpassword=D5vrfdZUeQpeF3GCSp5nUMf9DTuYsmdpB81ZmwVeSmz2
</code></pre>
<p>For an example file config file showing some of the other possible parameters <a href="https://en.bitcoin.it/wiki/Running_Bitcoin#Bitcoin.conf_Configuration_File" title="Bitcoin configuration parameters">I recommend taking a look at the Bitcoin Wiki</a> to see all of the options available.</p>
<p>Finally you are ready to start the service.</p>
<pre><code class="language-bash">bitcoind –daemon
</code></pre>
<p>If you look in the same directory as the config file you created for the service you should also see a log file named debug.log. If you use the tail command to follow the log file ( <em>i.e tail -f debug.log</em> ) now that the node is running. The log will show your node syncing with the blockchain, running through all the old blocks to bring itself up to speed with where things are now. This is a slow process and could take up to a few days to fully sync with the network depending on the connection speed.</p>
<h2>Next Steps:</h2>
<p>Hardening your new node with some firewall rules is also a pretty good idea to help things secure. Create yourself a script in an editor, with some iptables rules similar to below. If you are not planning on running a web server on the node then I recommend removing the two rules that allow http traffic through on port 80.</p>
<pre><code class="language-bash">#! /bin/sh
# Flushing all rules

iptables -F

iptables -X
# Setting default filter policy

iptables -P INPUT DROP

iptables -P OUTPUT DROP

iptables -P FORWARD DROP
# Allow unlimited traffic on loopback

iptables -A INPUT -i lo -j ACCEPT

iptables -A OUTPUT -o lo -j ACCEPT
# Allow incoming SSH

iptables -A INPUT -p tcp –dport 22 -m state –state NEW,ESTABLISHED -j ACCEPT

iptables -A OUTPUT -p tcp –sport 22 -m state –state ESTABLISHED -j ACCEPT
# Allow incoming http

iptables -A INPUT -p tcp –dport 80 -m state –state NEW,ESTABLISHED -j ACCEPT

iptables -A OUTPUT -p tcp –sport 80 -m state –state ESTABLISHED -j ACCEPT
# Allow incoming 8333

iptables -A INPUT -p tcp –dport 8333 -m state –state NEW,ESTABLISHED -j ACCEPT

iptables -A OUTPUT -p tcp –sport 8333 -m state –state ESTABLISHED -j ACCEPT
# Allow outgoing 8333

iptables -A OUTPUT -p tcp –dport 8333 -m state –state NEW,ESTABLISHED -j ACCEPT

iptables -A INPUT -p tcp –sport 8333 -m state –state ESTABLISHED -j ACCEPT
</code></pre>
<p>After entering your firewall rules save the file, add change the file permissions so it can be executed. Then simply run to activate your firewall rules.</p>
<p>If you want to see how much bandwidth your node is using I also recommend installing the vnstat package. This will give you some basic information on the amount of traffic your node is consuming on a daily, weekly, monthly basis. Replace eth0 with the interface you would like to track on your machine. The last command will just display a brief summary of what is happening traffic wise, but you can pull this information in a number of different formations for the full options run <em>vnstat –help</em>.</p>
<pre><code class="language-bash">apt-get install vnstat

vnstat -i eth0

vnstat -u -i eth0
</code></pre>
<h2>Beer money?</h2>
<p>Are you still awake after reading all that? Are you feeling rich? Any spare BTC for beer is always greatly appreciated!</p>
<p>Send BTC to <a href="https://blockchain.info/address/1HYtEBszMQZwFNomhD78h7UWE9aeY7Kru1" title="Donate BTC">1HYtEBszMQZwFNomhD78h7UWE9aeY7Kru1</a></p>
<img src="https://www.development-cycle.com/assets/images/2015/01/wallet_address.webp" alt="wallet_address" class="aligncenter" width="250" height="250">
<h2>Further Reading:</h2>
<p><a href="https://bitcoin.org/en/" title="The official home of the Bitcoin project">The Offical home of Bitcoin</a></p>
<p><a href="https://en.bitcoin.it/wiki/Main_Page" title="The Bitcoin Wiki">The Bitcoin Wiki</a></p>
<p><a href="https://github.com/bitcoin/bitcoin" title="The Bitcoin Project on Github">The Bitcoin project on GitHub</a></p>
<p><a href="https://www.bitcoinbook.info/" title="Mastering Bitcoin Book">Mastering Bitcoin</a> a solid book containing most of the things you need to know about Bitcoin and the Blockchain while still remaining easy enough to read.</p>
<p>A <a href="https://getaddr.bitnodes.io/" title="Map Of Worldwide Bitcoin Nodes">map of the Bitcoin</a> nodes across the globe</p>
]]></content:encoded>
    <category>bitcoin</category>
    <category>blockchain</category>
    <category>cryptocurrency</category>
    <category>Debian</category>
    <category>Wheezy</category>
  </item>
  <item>
    <title>Android Debug Bridge Tricks</title>
    <link>https://www.development-cycle.com/blog/android-debug-bridge-tricks/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/android-debug-bridge-tricks/</guid>
    <pubDate>Sat, 06 Dec 2014 00:00:00 GMT</pubDate>
    <description>Over the last couple of months I have been doing a lot of work with Cordova and the Ionic Framework creating my own field guide.</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2014/12/android.webp" alt="Google Android Logo" class="alignright" width="225" height="224">Over the last couple of months I have been doing a lot of work with <a href="http://cordova.apache.org/" title="Apache Cordova">Cordova</a> and the <a href="http://ionicframework.com/" title="HTML5 Ionic Framework">Ionic Framework</a> creating my own field guide.</p>
<p>When I started out working with Android my work flow was pretty simple:</p>
<ul>
<li>Make the required changes to the application code</li>
<li>Test in a browser using the simple web server provided with Python package</li>
<li>Use Cordova build command to build an apk package for testing on an actual Android device</li>
<li>Push the compiled package to the test device using adb to install the package on a device with developer model enable</li>
</ul>
<p>Over time as my familiarity with the Android tool chain progressed. I found the Android Debug Bridge ( adb ) tool that makes up part of the Android SDK has a lot more to offer. Below are some of handy tips I have found with adb that can make a developers life a little bit easier.</p>
<h2>Wake / Unlock / Lock a Device</h2>
<p>Using adb you can wake a device from a sleep state without touching the device.</p>
<pre><code class="language-bash">adb shell input keyevent 82
</code></pre>
<p>Alternately you can also send an awake device to sleep with the command.</p>
<pre><code class="language-bash">adb shell input keyevent 26
</code></pre>
<h2>Packages &amp; Performance</h2>
<p>The android debug bridge can also return a list of the installed packages installed on the connected device.</p>
<pre><code class="language-bash">adb shell pm list packages -f
</code></pre>
<p>To see the CPU usage of the processes running on the device the following command can be used.</p>
<pre><code class="language-bash">adb shell dumpsys cpuinfo
</code></pre>
<p>Since adb shell is essentially just executing shell commands on the device you can run a lot of common UNIX commands.</p>
<h2>Capture a Screenshot</h2>
<p>Still not impressed? You can export a screen shot from a device to the current directory if your using Linux.</p>
<pre><code class="language-bash">adb shell screencap -p | perl -pe ‘s/x0Dx0A/x0A/g’ &gt; screen.png
</code></pre>
<p>This feature is pretty handy when taking screen shots for use in the Google Play store. As it saves taking the screen shot manually and then transferring to a computer for use with the device art generator.</p>
<h2>Record a Screencast</h2>
<p>On devices running Android Kit Kat (4.4+) and above we can even take things a step further and record a screen-cast from the device! This function is extremely useful for creating promotional videos and tutorials for an application.</p>
<p>To get started simply execute:</p>
<pre><code class="language-bash">adb shell screenrecord /sdcard/example.mp4 –time-limit 5
</code></pre>
<p>This will record 5 seconds of video from the device and save to the file example.mp4 in /sdcard/. Using adb we can now pull the video off the device to the current directory on the computer.</p>
<pre><code class="language-bash">adb pull /sdcard/example.mp4
</code></pre>
<p>The video file can then be deleted on the device by using adb shell with the rm command.</p>
<pre><code class="language-bash">adb shell “rm /sdcard/example.mp4″
</code></pre>
<p>Some other options available for use with the screen recording functionality are:</p>
<p><strong>–size</strong> The dimensions of the recorded video, by default this will mimic the display resolution of the device. Using this feature to make low res videos in conjunction the “show touches” option enabled in the developer settings on the device for super helpful bug reports.</p>
<p><strong>–bit-rate</strong> The bit rate of the video in bits per second (bps). When not specified the default video bit rate is 4Mbps.</p>
<p><strong>–time-limit</strong> The length of the video in time to record in seconds. The maximum length video that can be recorded is 3 minutes.</p>
<p><strong>–verbose</strong> By default the screen recording process will not display any information when recording. To see any information output by the process in the terminal you need to use this option.</p>
<p><strong>–rotate</strong> Rotates the screen 90 degrees.</p>
<p><strong>WARNING:</strong> At the time of writing the documentation for the Android Debug Bridge have the rotate function marked as experimental. So you mileage may vary with this feature.</p>
<h2>Related Reading:</h2>
<p><a href="http://developer.android.com/tools/help/adb.html" title="ADB Official Google documentation">Google Documentation for the Android Debug Bridge</a></p>
]]></content:encoded>
    <category>adb</category>
    <category>Android</category>
    <category>Debugging</category>
    <category>Mobile</category>
    <category>Mobile Development</category>
  </item>
  <item>
    <title>Simple Iptables Blacklist</title>
    <link>https://www.development-cycle.com/blog/simple-iptables-blacklist/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/simple-iptables-blacklist/</guid>
    <pubDate>Mon, 16 Jun 2014 00:00:00 GMT</pubDate>
    <description>Anyone that has run a server for any length of time quickly learns that the Internet is full of spammers, bots and other characters you would prefer didn’t exist. A firewall is key to keeping these…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2014/06/firewall.webp" alt="firewall" class="alignright" width="200" height="137">Anyone that has run a server for any length of time quickly learns that the Internet is full of spammers, bots and other characters you would prefer didn’t exist. A firewall is key to keeping these guys out and Linux comes with a Kernel level firewall called iptables that can be employed for this purpose. The only downside of iptables is that people who don’t deal with it on a regular basis tend to find its syntax a little bit daunting.</p>
<p>In this post I am going to run you through the process of setting up a basic firewall IP blacklist. Using a bash script to read an blacklist of IP addresses and feeding these to iptables so they can no longer access your server.</p>
<p>First up create decide where you would like the script to live. for this example I am just going to put it in /root/scripts. i.e</p>
<p><em>mkdir /root/scripts</em></p>
<p><em>nano firewall.sh</em></p>
<p>Then copy in the following shell code into the file and save.</p>
<pre><code class="language-bash">#!/bin/bash
# ---------------------------
_input=/root/scripts/blocked_ips.txt
_pub_if=&quot;eth0&quot;
IPT=/sbin/iptables

[ ! -f &quot;$_input&quot; ] &amp;&amp; { echo &quot;$0: File $_input not found.&quot;; exit 1; }

# Unlimited lo access
$IPT -A INPUT -i lo -j ACCEPT
$IPT -A OUTPUT -o lo -j ACCEPT

### Setup our black list ###
$IPT -N droplist

# Filter out comments and blank lines
# store each ip or subnet in $ip
egrep -v &quot;^#|^$&quot; x | while IFS= read -r ip
do
        # Append everything to droplist
	$IPT -A droplist -i ${_pub_if} -s $ip -j LOG --log-prefix &quot;IP found on blacklist&quot;
	$IPT -A droplist -i ${_pub_if} -s $ip -j DROP
done &lt;&quot;${_input}&quot;

# Finally, insert or append our black list
$IPT -I INPUT -j droplist
$IPT -I OUTPUT -j droplist
$IPT -I FORWARD -j droplist
</code></pre>
<p>Now you simply need to create a file to store the blocked IP addresses, for the purposes of this example I am calling mine mine blocked_ips.txt. But you can call your blacklist whatever you would like just be sure to change the file set as _input on line 3 of the script.</p>
<p>Into your blacklist file simply add each individual IP addresses or address range in CIDR format on a new line then save e.g</p>
<p><em>220.33.0.123</em><br>
<em>37.187.71.0/24</em><br>
<em>27.16.0.0/12</em><br>
<em>27.128.0.0/15</em></p>
<p>No simply run the firewall.sh script to create the iptables rules to block these hosts. To check the rules are in place type the command:</p>
<p><em>iptables –list</em></p>
<p>This should show display rules similar to:</p>
<p><em>Chain droplist (3 references)</em><br>
<em>target     prot opt source               destination</em>         <br>
<em>LOG        all  —  37.187.71.0/24       anywhere             LOG level warning prefix “IP found on blacklist”</em><br>
<em>DROP       all  —  37.187.71.0/24       anywhere</em>            <br>
<em>LOG        all  —  27.16.0.0/12         anywhere             LOG level warning prefix “IP found on blacklist”</em><br>
<em>DROP       all  —  27.16.0.0/12         anywhere</em>            </p>
<p>With time you will also be able to see lines in your machines syslog showing hosts blocked by the firewall:</p>
<p><em>Jun 14 16:51:35 mx10292 kernel: [305613.135767] IP found on blacklistIN=eth0 OUT= MAC=56:2d:a2:c3:88:78:90:e2:ba:6d:fd:92:08:00 SRC=183.60.212.157 DST=112.63.21.142 LEN=60 TOS=0x00 PREC=0x00 TTL=42 ID=55301 DF PROTO=TCP SPT=47473 DPT=80 WINDOW=14600 RES=0x00 SYN URGP=0</em></p>
<p>This approach will give you a quick and dirty firewall, but be forewarned the rules will not persist after a reboot. To make the rules persist after a reboot I recommend you install the iptables-persistent package. To use simply install</p>
<p><em>apt-get update</em><br>
<em>apt-get install iptables-persistent</em></p>
<p>Then hit yes when it asks if you would like to save the currently active rules. If you choose to use the iptables-persistent package when you update your blacklist be sure to flush the current rules, run the firewall script then use the iptables-save command so the rules are updated and persist i.e</p>
<p><em>iptables –flush</em><br>
<em>/root/scripts/firewall.sh</em><br>
<em>iptables-save &gt; /etc/iptables/rules.v4</em></p>
<h2>Related Posts:</h2>
<p><a href="https://www.development-cycle.com/blog/learning-linux-iptables/" title="Linux Iptables">Video tutorial showing the creation of simple iptables rules</a></p>
<p><a href="https://www.development-cycle.com/blog/blocking-vocuspr-spam-with-iptables/" title="Blocking VocusPR Spam With Iptables">Blocking VocusPR spam with iptables</a></p>
<h2>Further Reading:</h2>
<p><a href="http://www.netfilter.org/" title="Netfilter project home">Netfilter homepage</a></p>
]]></content:encoded>
    <category>Debian</category>
    <category>iptables</category>
  </item>
  <item>
    <title>Creating a Tor Relay on Debian</title>
    <link>https://www.development-cycle.com/blog/creating-a-tor-relay-on-debian/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/creating-a-tor-relay-on-debian/</guid>
    <pubDate>Thu, 12 Jun 2014 00:00:00 GMT</pubDate>
    <description>The TOR project has proven itself an important tool in the fight to protect the anonymity of people online. The project obviously needs servers to route traffic through for the project to achieve its…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2014/06/tor_logo.webp" alt="tor_logo" class="alignright" width="200" height="112">The TOR project has proven itself an important tool in the fight to protect the anonymity of people online. The project obviously needs servers to route traffic through for the project to achieve its goals though. So contributors are needed to donate relays nodes ensuring a free Internet for all.</p>
<p>In this post I am going to run you though the process of installing TOR and configuring a relay service for use by the network on a Debian system.</p>
<p>First up login to your machine via a terminal, update the package library and install the Tor server:</p>
<p><em>apt-get update</em><br>
<em>apt-get install tor</em></p>
<p>Then change into the Tor config directory</p>
<p><em>cd /etc/tor</em></p>
<p>Scroll down to around line 35 and decide how and where you would like the TOR to store its logs if any. For the basis of this eample I am going to just uncomment line 37</p>
<p><em>Log notice file /var/log/tor/notices.log</em></p>
<p>Uncomment line 83</p>
<p><em>#ORPort 9001</em></p>
<p>Go down to Line 93 and you can remove the comment and add in your server name or IP address. This is an optional step though if its left commented out Tor will attempt to try and figure out the address on its own which will work in most cases.</p>
<p>On line 100 uncomment the nickname line and give the node a handle that people can refer to.</p>
<p>Then go down to lines 107 &amp; 108 uncomment and set any speed restrictions you would like to put in place. You may also want to look at line 116 &amp; 118 if you would like to put an actual cap on the total amount of bandwidth TOR can consume in a given period.</p>
<p>On line 126 uncomment and add you name and email address. This can be used in case someone from the Tor project needs to get in touch with you due to a misconfiguration or similar.</p>
<p>Then go down to line 175 and set an appropriate exit policy for your server. I recommend just using the line:</p>
<p><em>ExitPolicy reject *:* # no exits allowed</em></p>
<p>Reason being running a TOR exit node requires extra considerations to handle complaints to your service provider etc. If you are interested in acting as an exit node be sure to take a look at the Tor site for some guidelines and tips that will help keep issues to minimum.</p>
<p>Once you have finished making your changes to the config file, save and restart the tor service</p>
<p><em>service tor restart</em></p>
<p>Watch the start up proccess by following the Tor log file and look to look for any issues.</p>
<p><em>tail -f /var/log/tor/notices.log</em></p>
<p>Congratulations you are now running an active TOR relay and helping to keep people everywhere safe from online snooping.</p>
<h2>Further Reading:</h2>
<p><a href="https://www.eff.org/torchallenge/" title="EFF Tor Challenge">EFF Tor Challenge</a></p>
<p><a href="https://www.torproject.org/" title="The Tor Project Home">The Tor Project</a></p>
<h2>Related Posts:</h2>
<p><a href="https://www.development-cycle.com/blog/anonymizing-curl-scripts-with-tor-polipo/" title="Anonymizing PHP CURL scripts with TOR ">Anonymizing CURL Scripts With TOR &amp; Polipo</a></p>
]]></content:encoded>
    <category>anonymity</category>
    <category>Debian</category>
    <category>netsec</category>
    <category>privacy</category>
    <category>TOR</category>
  </item>
  <item>
    <title>PHP FPM Errors After Upgrade</title>
    <link>https://www.development-cycle.com/blog/php-fpm-errors-after-upgrade/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/php-fpm-errors-after-upgrade/</guid>
    <pubDate>Tue, 10 Jun 2014 00:00:00 GMT</pubDate>
    <description>Recently I noticed a few of my servers had stopped serving my sites, with 502 errors being to visitors. I took a look at my site logs and noticed that they were full of the “Permission Denied” errors…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2012/08/php.webp" alt="PHP Logo" class="alignright" width="250" height="132">Recently I noticed a few of my servers had stopped serving my sites, with  502 errors being to visitors. I took a look at my site logs and noticed that they were full of the “Permission Denied” errors below:</p>
<p><em>2014/06/09 09:45:17 [crit] 11453#0: *22 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream</em></p>
<p>A little more investigation and I found that a privilege escalation issue in the PHP default fpm configuration had been found. This had consequently been fixed in the latest releases. But unless a systems administrator is paying attention and knows that changes to the config are required, upgrading the PHP instance leads to a broken web server.</p>
<p>After some looking around the place I found a solution. To fix simply edit the file:</p>
<p><em>/etc/php5/fpm/pool.d/www.conf</em></p>
<p>Go down to around line 44 and you will see a section that looks similar to the following:</p>
<p><em>; Set permissions for unix socket, if one is used. In Linux, read/write</em><br>
<em>; permissions must be set in order to allow connections from a web server. Many</em><br>
<em>; BSD-derived systems allow connections regardless of permissions.</em><br>
<em>; Default Values: user and group are set as the running user</em><br>
<em>;                 mode is set to 0666</em><br>
<em>;listen.owner = www-data</em><br>
<em>;listen.group = www-data</em><br>
<em>;listen.mode = 0666</em></p>
<p>Then uncomment the listen.owner and listen.group declarations save the file and then restart the php5 service.</p>
<p><em>service php5-fpm restart</em></p>
<p>Visit you site in a browser an with any luck your website should be working properly again!</p>
<h2>Further Reading:</h2>
<p><a href="https://bugs.php.net/bug.php?id=67060" title="PHP security issue #67060">Original PHP security issue</a></p>
<p><a href="http://stackoverflow.com/questions/23443398/nginx-error-connect-to-php5-fpm-sock-failed-13-permission-denied" title="Stackoverflow PHP FPM Discussion">Discussion about the issue on StackOverflow</a></p>
]]></content:encoded>
    <category>Debian</category>
    <category>FPM</category>
    <category>nginx</category>
    <category>PHP</category>
  </item>
  <item>
    <title>Quick Intro To Memcached Stats</title>
    <link>https://www.development-cycle.com/blog/quick-intro-to-memcached-stats/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/quick-intro-to-memcached-stats/</guid>
    <pubDate>Mon, 19 May 2014 00:00:00 GMT</pubDate>
    <description>A few days ago I was given the job of changing the caching engine used in a Zend Framework based application from a simple flat file system based caching system to a memcached based object store that…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2014/05/memcached_logo.webp" alt="memcached_logo" class="alignright" width="192" height="60">A few days ago I was given the job of changing the caching engine used in a Zend Framework based application from a simple flat file system based caching system to a memcached based object store that could be used by multiple servers.</p>
<p>After extending the existing application bootstrap file to support the new cache mechanism. I started to wonder how I can get information on object store and the items it contains, with a filesystem cache you only have to look in the cache directory to see any cached items. A Memcached instance is not a closed system though stats can be requested on demand, so I hope to cover off some basic methods of interacting with a memcached instance here.</p>
<h2>Telnet</h2>
<p>The easiest way to interact with your memcached instance is by using telnet. You can simply connect to the port that memcached is running on. This will give you a prompt that can be used to execute commands    to retrieve information about the service.</p>
<p>For example to connect to a local memcached instance running on the default port 11211 you would execute at the command line:</p>
<p><em>telnet localhost 11211</em></p>
<h2>Telnet Commands</h2>
<p>After connecting to the memcached instance over telnet. There are a number of commands which can be executed to find out more about the object cache.</p>
<p>To display general purpose statistic like the uptime, number of connections, version etc of the memcached instance simply type “stats” at the prompt and hit enter.</p>
<p>For more information about the items stored in the cache you can execute the command “stats items”. This will give you things like the item count, age, eviction etc. One entry returned by this command that is wise to watch is evictions. In an ideal world the number of evictions reported for your object cache should be zero. If this is higher at your cache is probably running out of memory to store objects.</p>
<p>For more detailed information on memory usage of the instance you can also use command “stats slabs”.</p>
<p>The whole process of gathering stats can even be automated a little with the use of netcat and watch. To give a kind of “top” like output from memcached with the command:</p>
<p><em>watch “echo stats | nc 127.0.0.1 11211”</em></p>
<h2>Further Reading:</h2>
<p><a href="http://memcached.org/" title="Memcached project">Memcached project site</a></p>
<p><a href="https://github.com/mhwest13/Memcached-Munin-Plugin" title="Munin plugin for memcache">Memcached Munin Plugin</a></p>
]]></content:encoded>
    <category>Memcached</category>
    <category>Performance</category>
    <category>Zend Framework</category>
  </item>
  <item>
    <title>PNG Crush: PNG image optimisation script</title>
    <link>https://www.development-cycle.com/blog/png-crush-png-image-optimisation-script/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/png-crush-png-image-optimisation-script/</guid>
    <pubDate>Thu, 27 Mar 2014 00:00:00 GMT</pubDate>
    <description>Building a Cordova based mobile application recently at work we were facing an issue with an application size that was literally growing by the day. The project leveraged a lot of PNG templates sent…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2014/03/tiny.webp" alt="tiny" class="alignright" width="178" height="61">Building a <a href="https://cordova.apache.org/" title="Cordova Mobile Apllication">Cordova based mobile application</a> recently at work we were facing an issue with an application size that was literally growing by the day. The project leveraged a lot of PNG templates sent to us by the design department and these template files were contributing about 50mb to the total size of the application.</p>
<p>So the search was on to reduce the size of the project. One of the front end developers on the project ran a few of the PNG templates through the compression service at <a href="https://tinypng.com/" title="PNG Optimisation Service">tinypng.com</a> and was pleased to find the size reduction was around 75%. But with a deadline looming he just didn’t have the time to compress all of the images as there was a few hundred images spread across multiple directories.</p>
<p>I got told about the size improvement and took at the service, to see if I could help out and was pleased to find they had an API available allowing you to optimize up to 500 images per month for free. The documentation and API examples were pretty comprehensive and showed the process to be very straightforward. Simply POST the contents of an image along with your API key to a web service and it will return the location of an optimised copy of the image for you to download.</p>
<p>One of the API examples from the website I took then expanded into a simple PHP shell script. Given a directory to search it will go find all to the PNG files recursively underneath the location. Then post the images to the tinypng.com web service for optimisation and then overwriting the original file with the new copy. The <a href="https://github.com/anthony-mills/png_crush" title="PNG Crush - PNG Optimisation tool">code has been put up on Github so hopefully</a> it can help save others time on their projects in future. So next time you have to optimise the PNG files in your web project feel free to give it a try. With our files we found the service managed to reduces the file sizes on average between 70 – 75%.</p>
<h2>Further Reading:</h2>
<p><a href="https://tinypng.com/" title="Tinypng - PNG image optimisation">Tinypng.com homepage</a></p>
<p><a href="https://github.com/anthony-mills/png_crush" title="PHP script for reducing the size of PNG images">PNG Crush github repository</a></p>
<p><a href="http://www.smashingmagazine.com/2009/07/15/clever-png-optimization-techniques/" title="PNG optimisation techniques">Article on PNG optimisation techniques</a></p>
]]></content:encoded>
    <category>optimisation</category>
    <category>PHP</category>
    <category>PNG</category>
  </item>
  <item>
    <title>Linux CLI: File Text Search &amp;amp; Replace</title>
    <link>https://www.development-cycle.com/blog/linux-cli-file-text-search-replace/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/linux-cli-file-text-search-replace/</guid>
    <pubDate>Thu, 19 Dec 2013 00:00:00 GMT</pubDate>
    <description>Occasionally you need to change the contents of some files easily to save a lot of manual work. In my case it was a server migration, the old IP address of a server was referred to from numerous DNS…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2013/12/magnifying_glass.webp" alt="magnifying glass" class="alignright" width="130" height="130">Occasionally you need to change the contents of some files easily to save a lot of manual work. In my case it was a server migration, the old IP address of a server was referred to from numerous DNS records. This meant the contents of a couple of hundred Bind zone files would also have to change so that they would reflect the new server address.</p>
<p>This is task that would take way too long to do manually, luckily grep and sed can automate the process. In this post I will show you how to recursively search for and change a string in all files that exist below a directory.</p>
<p>The format for doing a recursive search / replace looks like:</p>
<p><em>grep -rl ‘search_term’ ./ | xargs sed -i ‘s/search_term/replacement_text/g’</em></p>
<p>Here we are telling grep to get a list of all the filenames containing the search term contained in files below the current directory. The xargs command then feeds this list to search which will open the files and replace all occurrences of the string with the replacement text provide.</p>
<p>So in my use case where I needed to change all instances of a servers IP address (220.233.0.5) to reflect the IP address of the new server (61.85.66.100) in my existing Bind zone files, I would use:</p>
<p><em>grep -rl ‘220.233.0.5’ /etc/bind/zones | xargs sed -i ‘s/220.233.0.5/61.85.66.100/g’</em></p>
<p>That gets the job done, but if your in a production environment another trick is to add an extension after the sed -i flag and a backup will be made of the file with that extension before making the changes i.e</p>
<p><em>grep -rl ‘220.233.0.5’ /etc/bind/zones | xargs sed -i_backup ‘s/220.233.0.5/61.85.66.100/g’</em></p>
]]></content:encoded>
    <category>CLI</category>
    <category>grep</category>
    <category>sed</category>
  </item>
  <item>
    <title>Tunnelling data over SSH with Putty</title>
    <link>https://www.development-cycle.com/blog/tunnelling-data-over-ssh-with-putty/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/tunnelling-data-over-ssh-with-putty/</guid>
    <pubDate>Mon, 16 Dec 2013 00:00:00 GMT</pubDate>
    <description>An SSH tunnel is used to route unencrypted traffic through an encrypted SSH channel. Its comes in handy for routing traffic over untrusted or hostile networks as the data is encrypted to maintain…</description>
    <content:encoded><![CDATA[<p>An SSH tunnel is used to route unencrypted traffic through an encrypted SSH channel. Its comes in handy for routing traffic over untrusted or hostile networks as the data is encrypted to maintain privacy and prevent eavesdropping. It is also very handy in for bypassing firewall restrictions where the usage of certain services are restricted.</p>
<h2>Creating an SSH tunnel with Putty</h2>
<p>SSH tunnels may sound complex, but in reality they are very simple to configure on a Windows box using Putty. In this post I am going to run through the process of setting up a SSH tunnel with Putty, and then configuring Firefox to use the SSH tunnel as a SOCKS proxy to securely transfer web traffic over a network.</p>
<p>First open up Putty and enter the connection details for the remote SSH host we are going to tunnel the data too.</p>
<p>  <img src="https://www.development-cycle.com/assets/images/2013/12/putty_1.png" alt="Create SSH connection with Putty" class="aligncenter" width="458" height="445"></p>
<p>Next expand the SSH option in the side bar on the right under the “Connection” parent node and you should see a section labelled “Tunnels”.</p>
<p>Enter the port you would like to create the tunnel on. This is a port on the local machine which will act as a SOCKS proxy forwarding the data sent to the remote host over via SSH. For the purposes of this demonstration I am going to use port 8080. Also click the radio button labelled “Dynamic”, leaving the destination box above blank.</p>
<img src="https://www.development-cycle.com/assets/images/2013/12/putty_dynamic_tunnel_port8080.png" alt="Creating a dynamic SSH tunnel on port 8080" class="aligncenter" width="461" height="445">
<p>Now click the “Open” button down the bottom of the application and log in to the remote server via terminal using your new credentials as per usual.</p>
<p>To confirm the tunnel is working you can open a DOS command prompt and execute the command:</p>
<p><em>netstat -ano</em></p>
<p>In the results returned you should find a line showing that the local machine is listening for connections on port 8080:</p>
<p><em>TCP    127.0.0.1:8080         0.0.0.0:0              LISTENING       2680</em></p>
<p>Now there is an active tunnel, we need to configure a web browser to take advantage of the tunnel. In this example I am going to use Mozilla Firefox, so although the process will be very similar in other browsers, it will vary slightly.</p>
<p>Open up Firefox on your machine, press (<em>ALT + T</em>) to bring up the tools menu and click on the “Options” entry. Click on the entry labelled “Advanced” up the top of the entries page. Then bring up the “Network” tab and click the “Settings” button next to the label “Configure how Firefox connects to the Internet”.</p>
<img src="https://www.development-cycle.com/assets/images/2013/12/firefox_options.webp" alt="Firefox options page" class="aligncenter" width="500" height="493">
<p>On this page select the radio button labelled “Manual proxy configuration”. Then next to the “SOCKS Host” heading enter localhost and port 8080 (or the port you setup your tunnel on). After clicking okay to leave this page your browser will now be sending all web requests via the remote host by use of the SSH tunnel.</p>
<img src="https://www.development-cycle.com/assets/images/2013/12/firefox_socks_proxy.png" alt="Configuring Firefox to use local SOCKS proxy" class="aligncenter" width="458" height="535">
<p>To confirm this is the case search “What is my IP” using Google and it will return the IP address of the remote host you are connected to via SSH.</p>
]]></content:encoded>
    <category>encryption</category>
    <category>Proxy</category>
    <category>security</category>
    <category>windows</category>
  </item>
  <item>
    <title>Encypting Diectories With eCryptfs</title>
    <link>https://www.development-cycle.com/blog/encypting-diectories-with-ecryptfs/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/encypting-diectories-with-ecryptfs/</guid>
    <pubDate>Sat, 14 Dec 2013 00:00:00 GMT</pubDate>
    <description>eCryptfs is an encrypted file system that works at the file system level. In this post I am going to cover the basic usage of eCryptfs and some of the situations you may want to think about using a…</description>
    <content:encoded><![CDATA[<p>eCryptfs is an encrypted file system that works at the file system level. In this post I am going to cover the basic usage of eCryptfs and some of the situations you may want to think about using a encrypted file system.</p>
<h2>What is an encrypted file system?</h2>
<p>File system encryption protects information by converting files and directories that exist on a file system into an unreadable format. To access the files and decipher the information afterward a passphrase is required.</p>
<p>Another related technology is full disk encryption which can be implemented <a href="http://www.arg0.net/encfs" title="encfs homepage">using encfs</a> on Linux. This differs from file system level encryption by encrypting the full disk or partition that the file system containing data resides.</p>
<h2>Why would I care about this?</h2>
<p>Everyone has some data that they would prefer is kept confidential such electronic receipts, account information, banking information etc. Devices do get lost and stolen at times so encryption so its best confidential data is protected.</p>
<h2>Using eCryptfs with Debian</h2>
<p>I use Debian on a RaspberryPi powered system at home which is connected to a removable hard drive to which my important information is backed up to using rsync &amp; ssh. So in this post I am going to cover off the process of encrypting the backups with eCryptfs on a system running Debian. The general process is going to be the same in other distributions but the exact steps may vary.</p>
<p>To get started open a terminal and elevate your privileges to root and make sure the package list available to the system is up to date.</p>
<p><em>sudo su</em><br>
 <br>
<em>apt-get update</em></p>
<p>Install the utilities for working with eCryptfs.</p>
<p><em>apt-get install ecryptfs-utils</em></p>
<img src="https://www.development-cycle.com/assets/images/2013/12/install_ecryptfs_utils.webp" alt="installing ecryptfs utils" class="aligncenter" width="500" height="349">
<p>You then need to ensure the eCryptfs kernel module is loaded with lsmod.</p>
<img src="https://www.development-cycle.com/assets/images/2013/12/list_loaded_modules.webp" alt="Display loaded kernel modules" class="aligncenter" width="500" height="349">
<p>Note: On the RaspberryPi I was using the module was not loaded by default so I had to execute first:</p>
<p><em>cd /lib/modules/$(uname -r)</em><br>
<em>modprobe ./kernel/fs/ecryptfs</em></p>
<p>Now to encrypt a directory on the file system for an example. First create a directory that you would like to contain your encrypted data:</p>
<p><em>mkdir notes</em></p>
<p>Then we need to mount mount the newly created directory as a eCryptfs so the files are encrypted.</p>
<p><em>mount -t ecryptfs notes notes</em></p>
<p>Then you will be run though a few questions about the setup.<br>
 <br>
<em>Select key type to use for newly created files:</em>  <br>
 <em>1) passphrase</em><br>
 <em>2) tspi</em><br>
<em>Selection: 1</em><br>
<em>Passphrase:</em>  <br>
<em>Select cipher:</em>  <br>
 <em>1) aes: blocksize = 16; min keysize = 16; max keysize = 32</em><br>
 <em>2) blowfish: blocksize = 8; min keysize = 16; max keysize = 56</em><br>
 <em>3) des3_ede: blocksize = 8; min keysize = 24; max keysize = 24</em><br>
 <em>4) twofish: blocksize = 16; min keysize = 16; max keysize = 32</em><br>
 <em>5) cast6: blocksize = 16; min keysize = 16; max keysize = 32</em><br>
 <em>6) cast5: blocksize = 8; min keysize = 5; max keysize = 16</em><br>
<em>Selection [aes]:</em>  <br>
<em>Select key bytes:</em>  <br>
 <em>1) 16</em><br>
 <em>2) 32</em><br>
 <em>3) 24</em><br>
<em>Selection [16]: 2</em><br>
<em>Enable plaintext passthrough (y/n) [n]: n</em><br>
<em>Enable filename encryption (y/n) [n]:</em>  <br>
<em>Attempting to mount with the following options:</em><br>
  <em>ecryptfs_unlink_sigs</em><br>
  <em>ecryptfs_key_bytes=32</em><br>
  <em>ecryptfs_cipher=aes</em><br>
  <em>ecryptfs_sig=9b8bcea9e0a5ce7c</em><br>
<em>WARNING: Based on the contents of [/root/.ecryptfs/sig-cache.txt],</em><br>
<em>it looks like you have never mounted with this key</em>  <br>
<em>before. This could mean that you have typed your</em>  <br>
<em>passphrase wrong.</em><br>
 <br>
<em>Would you like to proceed with the mount (yes/no)? : y</em><br>
<em>Would you like to proceed with the mount (yes/no)? : yes</em><br>
<em>Would you like to append sig [9b8bcea9e0a5ce71] to</em><br>
<em>[/root/.ecryptfs/sig-cache.txt]</em>  <br>
<em>in order to avoid this warning in the future (yes/no)? : yes</em><br>
<em>Successfully appended new sig to user sig cache file</em><br>
<em>Mounted eCryptfs</em></p>
<p>Now if the mount command is execute we should the directory we executed against mounted as a ecrypt file system.</p>
<h2>Further Reading:</h2>
<p><a href="http://ecryptfs.org/" title="home of ecryptfs">The home of eCryptfs</a></p>
]]></content:encoded>
    <category>Debian</category>
    <category>encryption</category>
    <category>security</category>
  </item>
  <item>
    <title>Installing SVN support in Aptana Studio 3</title>
    <link>https://www.development-cycle.com/blog/installing-svn-support-in-aptana-studio-3/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/installing-svn-support-in-aptana-studio-3/</guid>
    <pubDate>Thu, 05 Sep 2013 00:00:00 GMT</pubDate>
    <description>Its been a few years since I have worked anywhere that still uses Subversion as their day to day version control system. But the other day at work I needed to check out some old legacy code which was…</description>
    <content:encoded><![CDATA[<p>Its been a few years since I have worked anywhere that still uses Subversion as their day to day version control system. But the other day at work I needed to check out some old legacy code which was stored in a svn repository on an old development server. Then it struck me I didn’t even have subversion available on my work machine!</p>
<p>I could have simply installed it from the command line but I use to like have the ability to compare code across multiple revisions directly within my IDE. Here I am going to cover off the required steps to getting support for Subversion installed into Aptana Studio 3.</p>
<p>First go to the menu up near the top of the application window – <em><strong>help -&gt; Install new software</strong></em>.</p>
<img src="https://www.development-cycle.com/assets/images/2013/09/1.webp" alt="Aptana Studio: Install New Software" class="aligncenter" width="500" height="503">
<p>Click the link near the top <em><strong>“Available Software Sites”</strong></em>. Select the entry <em><strong>“Eclipse Indigo Update Site”</strong></em> then click the OK button.</p>
<img src="https://www.development-cycle.com/assets/images/2013/09/2.webp" alt="Aptana Studio: Activate Ecplise Software Repository" class="aligncenter" width="500" height="326">
<p>Select the Eclipse Indigo site from the drop down after a moment the area below will populate with a collection of eclipse packages that can be installed from the selected location.</p>
<img src="https://www.development-cycle.com/assets/images/2013/09/aptana_svn2-5.webp" alt="Apatana Studio: Available software packages" class="aligncenter" width="500" height="221">
<p>Expand the <em><strong>“collaboration”</strong></em> section then scroll down through through the selections within and select all of the subversive options.</p>
<img src="https://www.development-cycle.com/assets/images/2013/09/aptana_svn7-5.webp" alt="Aptana Studio: Subversive Packages" class="aligncenter" width="500" height="128">
<p>Click the next button down the bottom of the page then accept the required licenses for the packages.</p>
<img src="https://www.development-cycle.com/assets/images/2013/09/aptana_svn_4.webp" alt="Aptana Studio: Software package licences" class="aligncenter" width="500" height="507">
<p>Wait for the the packages to download and install.</p>
<img src="https://www.development-cycle.com/assets/images/2013/09/aptana_svn_5.webp" alt="Aptana Studio: Installing new software" class="aligncenter" width="523" height="234">
<p>When prompted restart Aptana Studio 3.</p>
<img src="https://www.development-cycle.com/assets/images/2013/09/aptana_svn_6.webp" alt="Aptana Studio: Restart Required" class="aligncenter" width="500" height="145">
<p>Upon restart you will need to select an SVN connector for Subversive to use. I selected SVN Kit 1.3.5. Then click finish and the it will compute the required dependencies that need to be installed and then show another software installation page, simply press “next” to continue.</p>
<img src="https://www.development-cycle.com/assets/images/2013/09/aptana_svn_7.webp" alt="Apatana Studio: Selecting SVN coinnector" class="aligncenter" width="500" height="601">
<p>As before a page reviewing the packages to be installed will be displayed, click next again. Accept the legal licenses for the connector and its dependencies. As before the connector its dependencies will then download install, and you will then be prompted to restart Aptana Studio again.</p>
<p>After restarting Aptana go <em><strong>file -&gt; new -&gt; project</strong></em>. In the new project wizard you will now see and option for and SVN project. Simply select this and click the next button. You will then see a page to enter the details of your Subversion repository and check out the code base.</p>
<img src="https://www.development-cycle.com/assets/images/2013/09/aptana_svn_10.webp" alt="Aptana Studio: New Project from SVN " class="aligncenter" width="500" height="562">
<h2>Further Reading:</h2>
<p><a href="https://www.development-cycle.com/blog/useful-aptana-keyboard-shortcuts/" title="Useful Keyboard Shortcuts For Aptana Studio">Useful shortcuts for Aptana Studio</a></p>
]]></content:encoded>
    <category>Aptana</category>
    <category>Subversion</category>
    <category>SVN</category>
  </item>
  <item>
    <title>Debugging Web Applications With Fiddler On Linux</title>
    <link>https://www.development-cycle.com/blog/debugging-web-applications-with-fiddler-on-linux/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/debugging-web-applications-with-fiddler-on-linux/</guid>
    <pubDate>Wed, 28 Aug 2013 00:00:00 GMT</pubDate>
    <description>Fiddler is by far one of the most popular web debugging proxies available. It allows you to capture, examine, save, edit and replay all HTTP / HTTPS requests made by a web based application. For many…</description>
    <content:encoded><![CDATA[<p>Fiddler is by far one of the most popular web debugging proxies available. It allows you to capture, examine, save, edit and replay all HTTP / HTTPS  requests made by a web based application. For many years it was available only on Windows systems. But recently the creator of Fiddler, Eric Lawrence has released a version of Fiddler that runs using the <a href="http://www.mono-project.com/" title="Homepage of the mono runtime">mono runtime</a> allowing it to run successfully on MacOS and Linux platforms.</p>
<p>In this post I am going to run through the basic setup and usage of fiddler under Linux (I am using Linux Mint 15 the process should not vary too for other Debian based variants though).</p>
<p>First up visit the fiddler site and <a href="http://fiddler.wikidot.com/mono" title="Fiddler mono runtime version">download the alpha mono version</a> of the application. After downloading unzip the package and copy the mono version of fiddler to the directory where you would like it to live on your system (I am simply using a folder named Software in my home directory).</p>
<h2>Getting Fiddler Running</h2>
<p>The process to get Fiddler running is not very complex but it does require the mono runtime along with functionality from the mono-winforms package. So first up open a terminal window and check that they are installed on your system with:</p>
<p><em>sudo apt-get update</em><br>
<em>sudo apt-get install mono-runtime mono-winforms</em></p>
<p>After installing the required dependencies for Fiddler navigate to the folder you unzipped earlier and enter the “app” folder contained within.</p>
<p><em>cd app</em></p>
<p>In this folder is a few files and Fiddler executable to get the application running simply use mono to run as follows:</p>
<p><em>mono Fiddler.exe</em></p>
<p>With any luck you should now have a functioning copy of fiddler running on your local machine.</p>
<img src="https://www.development-cycle.com/assets/images/2013/08/fiddler1.webp" alt="Fiddler running with mom runtime" class="aligncenter" width="550" height="261">  
**Browser Configuration**
<p>Fiddler is running and acting as a proxy server on the local system. But until a browser is configured to communicate through the proxy server, you will not be able to capture any requests. Setting a browser to use a proxy server is very simple process you will most likely find the required settings underneath a heading called network or similar in the browser preferences.</p>
<p>Since I mainly use <a href="http://www.mozilla.org/en-US/firefox/" title="Mozilla Firefox Homepage">Firefox</a> when doing web development, I will run through the process of setting Firefox to send all requests through the Fiddler proxy.</p>
<p>First open up the Firefox preferences:</p>
<p><em>Edit -&gt; Preferences</em></p>
<p>Click the advanced tab then highlight the network tab. Then click the settings button on the right up near the top.</p>
<img src="https://www.development-cycle.com/assets/images/2013/08/fiddler2.webp" alt="Firefox network settings" class="aligncenter" width="450" height="462">  
Select the radio button labeled “Manual Proxy Configuration” and enter into the boxes:
<p><em>HTTP Proxy: 127.0.0.1</em><br>
<em>Port: 8888</em></p>
<img src="https://www.development-cycle.com/assets/images/2013/08/fiddler3.webp" alt="Firefox Proxy Settings" class="aligncenter" width="450" height="525">  
Press the OK button and go to a new site in the browser and you should now see the requests appearing over in the fiddler window.
<img src="https://www.development-cycle.com/assets/images/2013/08/fiddler4.webp" alt="Intercepted requests" class="aligncenter" width="450" height="64">
<p>This is an approach that works but you need to to change the browse r proxy settings back when you are not running fiddler otherwise you will not be able to access any sites. If your only going to be using Fiddler occasionally I would recommend getting a proper proxy manager extension for Firefox like <a href="http://getfoxyproxy.org/">Foxyproxy</a>. With Foxyproxy simply use the plug in configuration page to “Add New Proxy”.</p>
<img src="https://www.development-cycle.com/assets/images/2013/08/foxy_proxy_config1.webp" alt="Foxyproxy Config" class="aligncenter" width="450" height="312">  
Enter the same loop back IP address and port as you proxy server as you did before, then click OK.
<img src="https://www.development-cycle.com/assets/images/2013/08/foxy_proxy_config2.webp" alt="foxy_proxy_config2" class="aligncenter" width="450" height="298">
<p>In your browser to the right of the address bar you should now see a Foxyproxy button. If you right click on this you will be able to easily turn on and off the interception of your browser requests with fiddler.</p>
<h2>Further Info:</h2>
<p><a href="http://fiddler2.com/" title="Fiddler proxy homepage">Fiddler Homepage</a><br>
<a href="http://www.youtube.com/playlist?list=PLvmaC-XMqeBbw72l2G7FG7CntDTErjbHc" title="Video tutorials on the use of fiddler">Fiddler Video Tutorials</a><br>
<a href="http://getfoxyproxy.org/" title="Firefox Foxyproxy extension">Foxyproxy Homepage</a></p>
]]></content:encoded>
    <category>Debugging</category>
    <category>Fiddler</category>
    <category>mono</category>
    <category>Proxy</category>
  </item>
  <item>
    <title>Adding MP3 Support To K3b</title>
    <link>https://www.development-cycle.com/blog/adding-mp3-support-to-k3b/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/adding-mp3-support-to-k3b/</guid>
    <pubDate>Thu, 22 Aug 2013 00:00:00 GMT</pubDate>
    <description>Being sick of the music selection in my car the other day I decided I needed for fresh blood. But not being motivated enough to replace the car stereo with one that has an auxiliary input. I tried to…</description>
    <content:encoded><![CDATA[<p>Being sick of the music selection in my car the other day I decided I needed for fresh blood. But not being motivated enough to replace the car stereo with one that has an auxiliary input. I tried to simply burn a few mp3 files onto a blank CD. Dragging the files into K3b instead resulted in the error below:</p>
<img src="https://www.development-cycle.com/assets/images/2013/08/k3b_1.webp" alt="k3b erorr" class="aligncenter" width="396" height="233">
<p>Clicking on the details button gave me the message <strong>“Unable to handle the following files due to unsupported format”</strong>. This struck me as fairly strange since I could play .mp3 files without issue.</p>
<p>After a bit of a search around I found the solution for me using Linux Mint 15, but the solution should be similar for people using Ubuntu, Debian or similar systems.</p>
<p>When installing K3b from the software manager the base application is installed, but the runtime libraries for mp3 support are separated out into the <a href="http://packages.ubuntu.com/raring/libk3b6-extracodecs" title="libk3b6-extracodecs - mp3 support for k3b">libk3b6-extracodecs package</a>. So to get everything working this package needs to be installed as well. To do so simply open up a terminal window:</p>
<p><em><strong>sudo apt-get update</strong></em><br>
<em><strong>sudo apt-get install libk3b6-extracodecs</strong></em></p>
<p>Close K3b if an instance of the program is still running. Now start K3b again and you should now be able to add mp3 files to your audio project without issue.</p>
]]></content:encoded>
    <category>Audio</category>
    <category>Linux Mint</category>
  </item>
  <item>
    <title>Installing Safari on Linux Mint 15</title>
    <link>https://www.development-cycle.com/blog/installing-safari-on-linux-mint-15/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/installing-safari-on-linux-mint-15/</guid>
    <pubDate>Tue, 13 Aug 2013 00:00:00 GMT</pubDate>
    <description>Cross browser testing your sites is unfortunately a necessary evil. Installing virtual machines with the required browsers installed is one way to test your code. But a lot of the time I don’t want…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2013/08/safari.jpeg" alt="safari logo" class="alignright" width="225" height="225">Cross browser testing your sites is unfortunately a necessary evil. Installing virtual machines with the required browsers installed is one way to test your code. But a lot of the time I don’t want to wait for a VM to boot just to quickly test something.</p>
<p>In this article I will run you through the process of getting the Windows version of Safari running under Wine on Linux Mint 15. Which will hopefully save some time waiting for virtual machines to boot up. To get started simply open a terminal and execute:</p>
<p>*sudo apt-get update<br>
sudo apt-get install playonlinux</p>
<p>Then run PlayOnLinux, it may complain about a few programs missing (in my case it was xterm and 7z) just press “ok” to continue.</p>
<p>The main interface will then open up with the main window area blank. You will need to press the “install” button to continue.</p>
<img src="https://www.development-cycle.com/assets/images/2013/08/safari2.webp" alt="PlayOnLinux Interface" class="aligncenter" width="350" height="322">
<p>This will open a new window look under the category “Internet” and select Safari.</p>
<img src="https://www.development-cycle.com/assets/images/2013/08/safari3.webp" alt="PlayonLinux Propgram Selection" class="aligncenter" width="400" height="307">
<p>Press “install” to continue and the program will then go off and get the required libraries.</p>
<img src="https://www.development-cycle.com/assets/images/2013/08/safari4.webp" alt="getiing Safari depencies" class="aligncenter" width="350" height="286">
<p>PlayOnLinux will then ask you the installation method Safari, select the option “download the program”.</p>
<p><img src="https://www.development-cycle.com/assets/images/2013/08/safari5.webp" alt="Safari select install method"></p>
<p>Safari select install method</p>
<p>This will then go and download the Safari installer.</p>
<p><img src="https://www.development-cycle.com/assets/images/2013/08/safari6.webp" alt="Downloading Safari"></p>
<p>Downloading Safari</p>
<p>After the download is complete a notice will appear telling you to unselect the options <strong>“Install Bonjour for Windows”</strong> and <strong>“Automatically update Safari”</strong> during the installation.</p>
<img src="https://www.development-cycle.com/assets/images/2013/08/safari7.webp" alt="PlayOnLinux Safari Instructions" class="aligncenter" width="350" height="279">
<p>Click next and after a few moments the actual installation of Safari should start.</p>
<img src="https://www.development-cycle.com/assets/images/2013/08/safari8.webp" alt="Safari Installation" class="aligncenter" width="350" height="266">
<p>Accept the EULA.</p>
<img src="https://www.development-cycle.com/assets/images/2013/08/safari9.webp" alt="Safari EULA" class="aligncenter" width="350" height="266">
<p>At minimum unselect the options you were told about before. In my install I simply unticked all of the options. Now click the “install” button to continue.</p>
<img src="https://www.development-cycle.com/assets/images/2013/08/safari10.webp" alt="Safari Installation Options" class="aligncenter" width="350" height="262">
<p>The install process should take a few moments to complete and then you should be presented with a screen informing you that install is now complete. Simply press finish and your done! Congratulations you should now have a working copy of Safari running under Wine on Linux Mint.</p>
<img src="https://www.development-cycle.com/assets/images/2013/08/safari11.webp" alt="Safari install complete" class="aligncenter" width="350" height="265">
]]></content:encoded>
    <category>Cross Browsr Testing</category>
    <category>Safari</category>
    <category>Wine</category>
  </item>
  <item>
    <title>Tracing Email Sending PHP Scripts On Servers</title>
    <link>https://www.development-cycle.com/blog/tracing-email-sending-php-scripts-on-servers/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/tracing-email-sending-php-scripts-on-servers/</guid>
    <pubDate>Tue, 09 Jul 2013 00:00:00 GMT</pubDate>
    <description>It happens sometimes, a server you are responsible for seems to be sending out spammy emails, and its normally caused by legacy or insecure code. The mail log indicates there are plenty of potential…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2012/08/php.webp" alt="PHP Logo" class="alignright" width="250" height="132">It happens sometimes, a server you are responsible for seems to be sending out spammy emails, and its normally caused by legacy or insecure code. The mail log indicates there are plenty of potential spam messages going out that are originating locally but most Linux servers host a lot of sites. So the question then becomes, how do I find the script thats responsible for sending all of the emails?</p>
<p><strong>The mail.log directive</strong></p>
<p>One useful tool when tracing the origin of an email is the <a href="http://www.php.net/manual/en/mail.configuration.php#ini.mail.log" title="PHP mail.log directive">mail.log parameter</a> which is available in PHP installs running version 5.3.0 and above. This parameter is simply set to the location of a log file and all calls to the PHP mail() function will be recorded. Including the originating script, line number, the destination address and the email headers used.</p>
<h2>Getting it working</h2>
<p>From the command line as root (<strong>NOTE:</strong> The examples below are based around a Debian server so the location and layout of your configuration files may vary with other distributions ) first create an empty log file for the calls to the PHP mail function to be logged to:</p>
<p><em>&gt;/var/log/phpmail.log</em></p>
<p><strong>NOTE:</strong> The mail log file needs to be writable by the PHP process. So in my case after creating the log file I then had to give ownership of the log to the www-data user to get it logging correctly.</p>
<p>Then create a global PHP mail config file containing the mail.log PHP directive:</p>
<p><em>echo “mail.log = /var/log/phpmail.log” &gt; /etc/php5/conf.d/mail.ini</em></p>
<p>After making the change either restart Apache if PHP is running as an Apache module. Otherwise restart the PHP CGI process and then send an email from a PHP script on your server. Then use the cat command to output the contents of the PHP mail log file you just created:</p>
<p><em>cat /var/log/phpmail.log</em></p>
<p>Which should display you a record of your mail being sent and its particulars, something similar to:</p>
<p><em>mail() on [/var/www/testsite/www/assets/class-phpmailer.php:769]: To: me@myemail.net — Headers: Date: Sun, 7 Jul 2013 03:39:42 +0000 Return-Path: test@testemail.net From: Jim Davis <a href="mailto:test@testemail.net">test@testemail.net</a> Message-ID: <a href="mailto:4b93ad6efbb68c59a33e5085647fdac1@testsite.com">4b93ad6efbb68c59a33e5085647fdac1@testsite.com</a> X-Priority: 3 X-Mailer: PHPMailer 5.2.1 (http://code.google.com/a/apache-extras.org/p/phpmailer/) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=”UTF-8″</em></p>
<h2>The mail.add_x_header directive</h2>
<p>A second way to gain some insight into the origin of emails being sent from PHP is the <a href="http://www.php.net/manual/en/mail.configuration.php#ini.mail.add-x-header" title="mail add x header directive">mail.add_x_header parameter</a>. This adds a line to the header of the outbound emails, containing the UID of the web server or PHP process and the name of the script that sent the email i.e</p>
<p><em>X-PHP-Originating-Script: 33:mailer.php</em></p>
<p>To enable the feature place the mail.add_x_header directive or echo it into the global mail configuration created earlier when discussing the mail.log configuration option:</p>
<p><em>echo “mail.add_x_header = True” &gt;&gt; /etc/php5/conf.d/mail.ini</em></p>
<p>Then restart Apache or the PHP service for the change to take effect.</p>
<p><strong>NOTE:</strong> This approach while useful for debugging emails being sent from a development or staging environment. This approach is not recommended for use in an production environment due to security considerations though. As it involves exposing information about your server and the scripts on it to potentially external parties. This feature also simply reports the script name without the path which also reduces its usefulness in environments hosting numerous sites.</p>
]]></content:encoded>
    <category>email</category>
    <category>Hosting</category>
    <category>PHP</category>
    <category>Spam</category>
  </item>
  <item>
    <title>A Quick Look At Animate.css</title>
    <link>https://www.development-cycle.com/blog/a-quick-look-at-animate-css/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/a-quick-look-at-animate-css/</guid>
    <pubDate>Wed, 03 Jul 2013 00:00:00 GMT</pubDate>
    <description>I was browsing github today when I came across the very interesting Animate.css repository . Animate.css provides a bunch of cool cross browser CSS3 based animations under an MIT licence that you can…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2013/07/css3.webp" alt="css3" class="alignright" width="200" height="281">I was browsing github today when I came across the very <a href="https://github.com/daneden/animate.css" title="Animate.css Github">interesting Animate.css repository</a>. Animate.css provides a bunch of cool cross browser CSS3 based  animations under an <a href="http://opensource.org/licenses/MIT" title="MIT Open Source Licence">MIT licence</a> that you can use in your own projects with minimal effort.</p>
<p>First things first you need to get a copy and depending how you want to use it, you can either <a href="http://daneden.me/animate/build/" title="Animate.css build custom download">build a custom package here</a>, that only contains the effects you are after (hover over the text titles to see each effect in action!). Or if size isn’t an issue and you just want to play around simply clone a copy of the complete code base from github repository. From here its pretty easy to get started, just include the Animate.css style sheet into your page and then add the desired classes to your elements as you require.</p>
<p>Below I have created a basic html document to demonstrate a provided “hinge” effect on an element containing some text. The Animate.css style sheet has simply been added in the head of the document. I am also loading jQuery so that when a visitor clicks the hingeElement the animate and hinge classes are then dynamically added to the element:</p>
<pre><code class="language-html4strict">&lt;!doctype html&gt;
&lt;html lang=&quot;en&quot;&gt;

	&lt;head&gt;
		&lt;link rel=&quot;stylesheet&quot; href=&quot;css/animate-custom.css&quot; /&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js&quot;&gt;&lt;/script&gt;
                &lt;title&gt;Animate.css: Hinge element example&lt;/title&gt;
		&lt;style type=&quot;text/css&quot;&gt;
			#hingeElement {
				width: 300px;
				margin: auto;
			}

			#hingeElement:hover {
				text-decoration: underline;
			}
		&lt;/style&gt;
	&lt;/head&gt;

	&lt;body&gt;
		&lt;h2&gt;Animated Hinge&lt;/h2&gt;
		&lt;div id=&quot;hingeElement&quot;&gt;
			&lt;p&gt;This is some test text for the page.&lt;/p&gt;
		&lt;/div&gt;

		&lt;script type=&quot;text/javascript&quot;&gt;
			$(&quot;#hingeElement&quot;).click(function() {
				$('#hingeElement').addClass('animated hinge');
			});
		&lt;/script&gt;
	&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>You can see a <a href="http://web.archive.org/web/20130830061546/http://www.development-cycle.com:80/examples/css_animate/flip.html" title="Animate.css flip animation example">proper demo of the code in action here</a>.</p>
<p>In the next one I attached a handler to the click event same as before but I have put an image into the element and am using the flip animation instead.</p>
<pre><code class="language-html4strict">&lt;!doctype html&gt;
&lt;html lang=&quot;en&quot;&gt;

	&lt;head&gt;
		&lt;link rel=&quot;stylesheet&quot; href=&quot;css/animate-custom.css&quot; /&gt;

		&lt;title&gt;Animate.css: Flip image example&lt;/title&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js&quot;&gt;&lt;/script&gt;

		&lt;style type=&quot;text/css&quot;&gt;
			#flipElement {
				width: 650px;
				margin: auto;
			}

			#flipElement:hover {
				text-decoration: underline;
			}
		&lt;/style&gt;
	&lt;/head&gt;

	&lt;body&gt;
		&lt;h2&gt;Animated Flip&lt;/h2&gt;
		&lt;div id=&quot;flipElement&quot;&gt;
			&lt;img src=&quot;/assets/images/sydney_sunset.jpg&quot; alt=&quot;Picture of Sydney sunset&quot; /&gt;
		&lt;/div&gt;

		&lt;script type=&quot;text/javascript&quot;&gt;
			$(&quot;#flipElement&quot;).click(function() {
				$('#flipElement').addClass('animated flip');

			});
		&lt;/script&gt;
	&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>A demonstration of <a href="http://web.archive.org/web/20130830061546/http://www.development-cycle.com:80/examples/css_animate/flip.html" title="Animate.css hinge animation example">this example can also be seen here</a>.</p>
<p>With 53 different effects, you can use Animate.css is a great way to quickly and easily add some eye candy to your sites with CSS3 animations.</p>
<h2>Further Reading:</h2>
<ul>
<li><a href="http://daneden.me/animate/" title="Animate.css Homepage">Animate.css homepage</a></li>
<li><a href="https://github.com/daneden/animate.css" title="Animate.css github repository">Animate.css github repository</a></li>
<li>There is also Ruby Gem available to add animate.css to <a href="https://github.com/camelmasa/animate-rails" title="Animate Rails github repository">Rails called “Animate Rails”</a></li>
<li><a href="http://www.w3schools.com/css3/css3_animations.asp" title="W3schools CSS3 animations">CSS3 animations</a></li>
</ul>
]]></content:encoded>
    <category>animate</category>
    <category>CSS3</category>
  </item>
  <item>
    <title>Command Line Tips: Program Execution</title>
    <link>https://www.development-cycle.com/blog/command-line-tips-program-execution/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/command-line-tips-program-execution/</guid>
    <pubDate>Tue, 02 Jul 2013 00:00:00 GMT</pubDate>
    <description>Executing commands is an integral part of using any Linux system. To follow up on my post about navigating file systems from the command line ( Linux Tips: File &amp;amp; Directory Handling ) more…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2013/07/small_gnu_logo.webp" alt="small GNU logo" class="alignright" width="203" height="100">Executing commands is an integral part of using any Linux system. To follow up on my post about navigating file systems from the command line ( <a href="https://www.development-cycle.com/blog/linux-tips-file-directory-handling/" title="Linux Tips: File &amp; Directory Handling">Linux Tips: File &amp; Directory Handling</a> ) more effectively, I am I have picked up over the years.</p>
<h2>Discovering What Shell You Are In</h2>
<p>Finding exactly out what shell you are currently using in a terminal can be determined using a variety of different techniques. Some of which are:</p>
<p>Using the ps command to display the name of the shell process ( $ is a shell variable that reflects the pid of the current shell ).</p>
<p><em>ps -o command $$</em></p>
<p>You can echo the $0 variable which will display the name of the shell script.</p>
<p><em>echo $0</em></p>
<p>Or you can also echo the $SHELL environment variable which will display your shell script</p>
<p><em>echo $SHELL</em></p>
<h2>Process Handling</h2>
<p>Sometimes for various reasons you want like to exit a program before it has a chance to run to completion. This can be achieved by pressing the “CTRL + C” keys on the keyboard to send a TERM signal to the running process. Since the TERM signal can be blocked or ignored by a process you may want to terminate a process by pressing the “CTRL + ” keys which will send a QUIT signal to the running process instead.</p>
<p>If you don’t want to end the process completely you can press the “CTRL + Z” keys this will simply suspend the programs execution. You can then resume execution of the program again but in the background by typing bg. Or resume running the last suspended process in the foreground with fg. To see any suspended processes you can use the jobs command which will display something similar to:</p>
<p><em>[1]- Stopped tar cjvf file.tar.bz2 video/</em><br>
<em>[2]+ Stopped tar cjvf file2.tar.bz2 music/</em></p>
<p>We can see from the output from the jobs command above that I currently have two jobs which I have suspended. The number at the start of each line is the job number for the suspended proces. This job number can then be used in conjunction with the bg or fg commands to control a particular job, rather than just the last suspended job. For example to resume my job compressing the video/ folder in the foreground I could execute:</p>
<p><em>fg %1</em></p>
<p>or simply</p>
<p><em>%1</em></p>
<h2>Command History</h2>
<p>Learning how to effectively navigate commands you have executed in the past saves alot of typing. The BASH shell helps by maintaining a history file that contains a list of commands you have run in the past. The terminal history is stored in RAM during a session and written to the history file after a user logs out of their session. You can find the location of the history file by looking at the shell variable HISTFILE i.e</p>
<p><em>echo $HISTFILE</em></p>
<p>In this case my history file is shown as being located at /home/anthony/.bash_history.</p>
<p>If you would like to see your command history, simply use the history command without any arguments to output the contents of your history file with your commands ordered from oldest to newest. If for some reason you would like to clear your command history you simply add the -c flag to the history command i.e</p>
<p><em>history -c</em></p>
<p>At the command prompt one effective way of saving yourself some typing is pressing the “CTRL + R” keys. This will trigger a reverse command search of your history simply start typing the command you want to narrow your search down to the command you want and then simply press enter to execute.</p>
<p>Which brings us to the BASH bang operator (!), this allows you to run previously executed commands. Its very flexible and allows you to specify a command that was previously run within the terminal in a variety of ways for example:</p>
<p>Following the bang with a dash and a number will execute a command, X number of commands back in the terminal history. To execute the second last command you would run:</p>
<p><em>!-2</em></p>
<p>The bang operator will also let you to specify a particular line number in your history file to run. Tou run the command on line 478 of your terminal history enter:</p>
<p><em>!487</em></p>
<p>Run the most recent command in history that starts with a command. For example to reconnect to a server you were previously logged into:</p>
<p><em>!slogin</em></p>
<p>If you are using the above format to rerun a the slogin by name again but are not sure what arguments you used with the command. You can use the “:p” extension first this will print the complete command and arguments that would be executed:</p>
<p><em>!slogin:p</em></p>
<p>To simply repeat the last command executed you can press the up arrow key on the keyboard or use the “!!” (otherwise known as bang bang).</p>
<p><strong>TIP:</strong> The double bang ( !! ) is extremely handy when you are logged in as a normal user, you have typed a command that requires root privileges, but forgotten to use sudo. To simply run the command again using sudo simply enter “sudo !!” at the command prompt.</p>
<h2>Argument Reuse</h2>
<p>The bang operator can also be used in conjunction with a dollar sign ($) as a handy way to reuse the arguments provided to the previously executed command. For example if you executed:</p>
<p><em>ls /var/log/</em></p>
<p>You could then change into the /var/log directory with minimal typing by executing:</p>
<p><em>cd !$</em></p>
<p>If you like you can also check the arguments before using them with a command you can use the “:p” again with the bang operator to simply print the value i.e</p>
<p>Executing !$ after the previous example will output to the terminal:</p>
<p><em>/var/log</em></p>
<h2>Your Top 100</h2>
<p>Not really that useful, but interesting regardless. Running the snippet below will give you a list of your 100 most used commands from the terminal history:</p>
<pre><code>history | sed &quot;s/^[0-9 ]*//&quot; | sed &quot;s/ *| */n/g&quot; | awk '{print $1}' | sort | uniq -c | sort -rn | head -n 100
</code></pre>
<p>With the number in front of each command being a count of how many times the command appears in the terminal history.</p>
<h2>Further Reading</h2>
<ul>
<li>
<p><a href="https://www.development-cycle.com/blog/linux-tips-file-directory-handling/" title="Linux Tips: File &amp; Directory Handling">Linux Tips: File &amp; Directory Handling</a></p>
</li>
<li>
<p>Manpage for history</p>
</li>
<li>
<p><a href="http://www.symkat.com/understanding-bash-history" title="Understanding BASH histtory">Understanding BASH history</a></p>
</li>
<li>
<p><a href="http://www.deadman.org/bash.php" title="More information on the bash bang">BASH bang</a></p>
</li>
</ul>
]]></content:encoded>
    <category>Bash</category>
    <category>CLI</category>
    <category>history</category>
    <category>Tips</category>
  </item>
  <item>
    <title>Linux Tips: File &amp;amp; Directory Handling</title>
    <link>https://www.development-cycle.com/blog/linux-tips-file-directory-handling/</link>
    <guid isPermaLink="true">https://www.development-cycle.com/blog/linux-tips-file-directory-handling/</guid>
    <pubDate>Tue, 25 Jun 2013 00:00:00 GMT</pubDate>
    <description>My desktop and all of the servers I own are Linux or Unix based. So as a result I tend to find myself in a terminal navigating file systems and working with files more often than not. Command line…</description>
    <content:encoded><![CDATA[<p><img src="https://www.development-cycle.com/assets/images/2013/06/flash_drive.webp" alt="drive" class="alignright" width="200" height="118">My desktop and all of the servers I own are Linux or Unix based. So as a result I tend to find myself in a terminal navigating file systems and working with files more often than not.<br>
Command line file management allows you to wield crazy amounts of power but it doesn’t have to be all hard work. Here I am going to run you through some of my favorite simple file and directory related tips for working at the command line.</p>
<h3><strong>Directory Navigation</strong></h3>
<p>When in a directory you can navigate to the last directory you were in with the command:</p>
<p><em>cd –</em></p>
<p>The location of your last directory location is also stored in the <em>$OLDPWD</em> variable. This is pretty handy and can be used in conjunction with other commands. For example to delete the directory you were last in and all its contents you would use:</p>
<p><em>rm -rf $OLDPWD</em></p>
<p>The cd dash trick is handy when just switching between two directories but the method tends to come unstuck if you need to add another directory to the mix. In this situation its easier to use the pushd and popd commands. pushd allows you to push the current working directory on a stack for later retrieval. The popd then allows you to switch back to a path stored on the stack earlier with the pushed command i.e</p>
<pre><code class="language-bash">pwd
/etc/apache2
pushd .
cd /usr/local
cd /etc
popd
pwd
/etc/apache2
</code></pre>
<p>If you find the stack is too limiting for your needs you can also assign paths to BASH variables to help simplify navigation around the file system. i.e</p>
<pre><code class="language-bash">DIR1=’/etc/apache2/sites-enabled/’

DIR2=’/var/log/apache2/’

cd $DIR1

pwd

/etc/apache2/sites-enabled/

cd $DIR2

pwd

/var/log/apache2/
</code></pre>
<p>Assigning BASH variables when performing complex operations also has the added benefit of allowing you to couple the locations with commands ie to output the contents of the mail log with cat</p>
<p><em>LOGDIR=’/var/log/’</em><br>
<em>cat $LOGDIR/mail.log</em></p>
<h3><strong>File Handling</strong></h3>
<h2>Removing Files</h2>
<p>Sometimes you will come across a directory that contains a huge number of files executing rm *, results in an ” Argument list too long” error. To resolve this files need to be fed into remove in batches that the command can handle, one of the quickest ways to achieve this is is by using the find command to feed the rm program with input:</p>
<p><em>find * -xdev -exec rm -f ‘{}’ ‘;’</em></p>
<h2>Emptying Files</h2>
<p>Sometimes its handy to quickly wipe the contents of file while not deleting the file altogether, for example logfiles. Most people simply use rm to remove the file and then create a new file using the touch command with the same name. The same thing can be achieved alot easier by simply using the &gt; operator eg</p>
<p>&gt;mylogfile.log</p>
<p>Will completely clear the contents of the file mylogfile.log if a file by that name actually exists. If it doesnt an empty file with that name will be created for you.</p>
<h2>Comma Operator</h2>
<p>The comma operator can make your life alot easier when performing multiple file operations. For example to create two empty files with different extensions:</p>
<p><em>touch newfile.{txt,xml}</em></p>
<p>The extension for the xml file can then easily be changed to html by combining the comma operator with the mv command i.e</p>
<p><em>mv newfile.{xml,html}</em></p>
<h2>Delete With Exceptions</h2>
<p>Some times you would like to delete all of the files within a directory except a certain type of file. For example you have a directory full of miscellanous images and you would like to delete all of them except those in JPEG and PNG format.</p>
<p><em>rm !(*.jpg|*.png)</em></p>
<p>This will delete all of the images in the directory that do not possess a .jpg or .png.</p>
<p><strong>NOTE:</strong> Of course the command above would still delete jpeg files with the extension .JPG so some care must still be taken.</p>
<h2>Further Reading:</h2>
<p><a href="http://www.gnu.org/software/bash/manual/bashref.html" title="The GNU Bash Reference Guide">The GNU Bash Reference Guide</a></p>
]]></content:encoded>
    <category>Bash</category>
    <category>CLI</category>
  </item>
</channel>
</rss>
